made entire accounts section dynamic

This commit is contained in:
flash 2016-12-09 19:09:33 +01:00
parent f00d546a0b
commit 19c4740ada
9 changed files with 141 additions and 66 deletions

View file

@ -245,29 +245,26 @@ class AccountController extends Controller
]; ];
if (session_check() && $rank && $mode) { if (session_check() && $rank && $mode) {
$redirect = route('settings.account.ranks');
// Check if user has this rank // Check if user has this rank
if (!CurrentSession::$user->hasRanks([$rank])) { if (!CurrentSession::$user->hasRanks([$rank])) {
$message = "You aren't a part of this rank!"; return $this->json(['error' => "You aren't a part of this rank!"]);
return view('global/information', compact('redirect', 'message'));
} }
if ($mode == 'remove') { switch ($mode) {
case 'remove':
if (in_array($rank, $locked)) { if (in_array($rank, $locked)) {
$message = "You aren't allowed to remove this rank from your account!"; return $this->json(['error' => "You aren't allowed to remove this rank from your account!"]);
return view('global/information', compact('redirect', 'message'));
} }
CurrentSession::$user->removeRanks([$rank]); CurrentSession::$user->removeRanks([$rank]);
break;
$message = "Removed the rank from your account!"; case 'main':
return view('global/information', compact('redirect', 'message')); CurrentSession::$user->setMainRank($rank);
break;
} }
CurrentSession::$user->setMainRank($rank); return $this->json(['error' => null]);
return redirect($redirect);
} }
return view('settings/account/ranks', compact('locked')); return view('settings/account/ranks', compact('locked'));
@ -287,21 +284,17 @@ class AccountController extends Controller
$maxLength = config('user.page_max'); $maxLength = config('user.page_max');
if (session_check() && $userpage) { if (session_check() && $userpage) {
$redirect = route('settings.account.userpage');
if (strlen($userpage) > $maxLength) { if (strlen($userpage) > $maxLength) {
$message = 'Your userpage is too long, shorten it a little!'; return $this->json(['error' => 'Your userpage is too long, shorten it a little!']);
} else { }
DB::table('users') DB::table('users')
->where('user_id', CurrentSession::$user->id) ->where('user_id', CurrentSession::$user->id)
->update([ ->update([
'user_page' => $userpage, 'user_page' => $userpage,
]); ]);
$message = 'Updated your userpage!'; return $this->json(['error' => null]);
}
return view('global/information', compact('message', 'redirect'));
} }
return view('settings/account/userpage', compact('maxLength')); return view('settings/account/userpage', compact('maxLength'));
@ -322,21 +315,17 @@ class AccountController extends Controller
$maxLength = config('user.signature_max'); $maxLength = config('user.signature_max');
if (session_check() && $signature) { if (session_check() && $signature) {
$redirect = route('settings.account.signature');
if (strlen($signature) > $maxLength) { if (strlen($signature) > $maxLength) {
$message = 'Your signature is too long, shorten it a little!'; return $this->json(['error' => 'Your signature is too long, shorten it a little!']);
} else { }
DB::table('users') DB::table('users')
->where('user_id', CurrentSession::$user->id) ->where('user_id', CurrentSession::$user->id)
->update([ ->update([
'user_signature' => $signature, 'user_signature' => $signature,
]); ]);
$message = 'Updated your signature!'; return $this->json(['error' => null]);
}
return view('global/information', compact('message', 'redirect'));
} }
return view('settings/account/signature', compact('maxLength')); return view('settings/account/signature', compact('maxLength'));

View file

@ -13,11 +13,14 @@
&__container { &__container {
display: block; display: block;
width: 100%;
height: 100%;
text-decoration: none !important; text-decoration: none !important;
color: #000; color: #000;
margin: 5px auto; margin: 5px auto;
background-color: transparent; background-color: transparent;
border: 0; border: 0;
cursor: pointer;
&:active { &:active {
color: inherit; color: inherit;
@ -61,6 +64,7 @@
background-color: transparent; background-color: transparent;
border: 0; border: 0;
transition: color .2s; transition: color .2s;
cursor: pointer;
&:hover { &:hover {
color: #333; color: #333;

View file

@ -5,7 +5,7 @@
preview = document.getElementById("settingsPreview"); preview = document.getElementById("settingsPreview");
parser.SetUrl("{{ route('helper.bbcode.parse') }}"); parser.SetUrl("{{ route('helper.bbcode.parse') }}");
parser.ContentType("application/x-www-form-urlencoded"); parser.Form();
function settingsPreview() { function settingsPreview() {
var text = form.value; var text = form.value;

View file

@ -8,6 +8,7 @@
{% block settingsContent %} {% block settingsContent %}
<form enctype="multipart/form-data" method="post" action="javascript:;" onsubmit="updateSettingsConfirm(this, '{{ route('settings.account.details') }}');"> <form enctype="multipart/form-data" method="post" action="javascript:;" onsubmit="updateSettingsConfirm(this, '{{ route('settings.account.details') }}');">
<input type="hidden" name="session" value="{{ session_id() }}">
<div class="profile-field"> <div class="profile-field">
<div><h2>E-mail address</h2></div> <div><h2>E-mail address</h2></div>
<div><input type="text" name="email" placeholder="{{ user.email }}" class="input__text"></div> <div><input type="text" name="email" placeholder="{{ user.email }}" class="input__text"></div>
@ -28,7 +29,7 @@
<div><h2>Password</h2></div> <div><h2>Password</h2></div>
<div><input type="password" name="password" placeholder="Must be at least decently strong, size doesn't matter" class="input__text"></div> <div><input type="password" name="password" placeholder="Must be at least decently strong, size doesn't matter" class="input__text"></div>
</div> </div>
<button value="{{ session_id() }}" name="session" class="input__button">Save</button> <button class="input__button">Save</button>
<button type="reset" class="input__button">Reset</button> <button type="reset" class="input__button">Reset</button>
</form> </form>
{% endblock %} {% endblock %}

View file

@ -91,6 +91,7 @@
{% block settingsContent %} {% block settingsContent %}
<form enctype="multipart/form-data" method="post" action="javascript:;" onsubmit="updateSettings(this, '{{ route('settings.account.profile') }}');"> <form enctype="multipart/form-data" method="post" action="javascript:;" onsubmit="updateSettings(this, '{{ route('settings.account.profile') }}');">
<input type="hidden" name="session" value="{{ session_id() }}">
{% for id, vars in fields %} {% for id, vars in fields %}
<div class="profile-field {{ id }}"> <div class="profile-field {{ id }}">
<div> <div>
@ -141,7 +142,7 @@
</label> </label>
</div> </div>
</div> </div>
<button name="session" value="{{ session_id() }}" class="input__button">Save</button> <button class="input__button">Save</button>
<button type="reset" class="input__button">Reset</button> <button type="reset" class="input__button">Reset</button>
</form> </form>
{% endblock %} {% endblock %}

View file

@ -6,19 +6,100 @@
<p>Manage what ranks you're in and what is set as your main rank. Your main rank is highlighted. You get the permissions of all of the ranks you're in combined.</p> <p>Manage what ranks you're in and what is set as your main rank. Your main rank is highlighted. You get the permissions of all of the ranks you're in combined.</p>
{% endblock %} {% endblock %}
{% block js %}
<script>
function yuunoRankProtected() {
var confirm = new Sakura.Dialogue;
confirm.Title = "Ranks";
confirm.Text = "You aren't allowed to remove this rank from your account!";
confirm.AddCallback(Sakura.DialogueButton.Ok, function () {
this.Close();
});
confirm.Display();
}
function yuunoRankSwitch(id, csrf) {
// not really that much of an impactful action so just proxy
yuunoRankDo(id, csrf, 'main');
}
function yuunoRankRemove(id, csrf, name) {
var confirm = new Sakura.Dialogue;
confirm.SetType(Sakura.DialogueType.ConfirmNegative);
confirm.Title = "Ranks";
confirm.Text = "You are about to remove the rank '" + name + "' from your account. Are you sure about this?";
confirm.AddCallback(Sakura.DialogueButton.No, function () {
this.Close();
});
confirm.AddCallback(Sakura.DialogueButton.Yes, function () {
this.Close();
yuunoRankDo(id, csrf, 'remove');
});
confirm.Display();
}
function yuunoRankDo(id, csrf, mode) {
var ajax = new Sakura.AJAX,
formData = new FormData;
formData.append('rank', id);
formData.append('mode', mode);
formData.append('session', csrf);
ajax.SetUrl("{{ route('settings.account.ranks') }}");
ajax.SetFormData(formData);
ajax.AddCallback(200, function () {
var result = ajax.JSON();
if (result.error) {
var error = new Sakura.Dialogue;
error.Title = "Ranks";
error.Text = result.error;
error.SetType(Sakura.DialogueType.Info);
error.AddCallback(Sakura.DialogueButton.Ok, function () {
this.Close();
});
error.Display();
} else if (mode === 'remove') {
Sakura.DOM.Remove(Sakura.DOM.ID('rank-' + id));
} else if (mode === 'main') {
Sakura.DOM.RemoveClass(document.querySelector('.friend-box--active'), ['friend-box--active']);
Sakura.DOM.AddClass(Sakura.DOM.ID('rank-' + id), ['friend-box--active']);
}
});
ajax.Start(Sakura.HTTPMethod.POST);
}
</script>
{% endblock %}
{% block settingsContent %} {% block settingsContent %}
<div style="text-align: center"> <div style="text-align: center">
{% for rank in user.ranks %} {% for rank in user.ranks %}
<form method="post" action="{{ route('settings.account.ranks') }}" class="friend-box {% if rank.id == user.mainRankId %}friend-box--active{% endif %}"> <div class="friend-box {% if rank.id == user.mainRankId %}friend-box--active{% endif %}" id="rank-{{ rank.id }}">
<input type="hidden" name="session" value="{{ session_id() }}"> <button class="friend-box__container" onclick="yuunoRankSwitch({{ rank.id }}, '{{ session_id() }}')">
<input type="hidden" name="rank" value="{{ rank.id }}">
<button class="friend-box__container" name="mode" value="main">
<div class="friend-box__name" style="color: {{ rank.colour }}">{{ rank.name }}</div> <div class="friend-box__name" style="color: {{ rank.colour }}">{{ rank.name }}</div>
</button> </button>
<div class="friend-box__actions"> <div class="friend-box__actions">
<button title="{% if rank.id in locked %}You can't leave this rank{% else %}Leave rank{% endif %}" class="friend-box__action friend-box__action--red fa fa-{% if rank.id in locked %}shield{% else %}remove{% endif %}" name="mode" value="remove" {% if rank.id in locked %}disabled{% endif %}></button> <button
title="{% if rank.id in locked %}You can't leave this rank{% else %}Leave rank{% endif %}"
class="friend-box__action friend-box__action--red fa fa-{% if rank.id in locked %}shield{% else %}remove{% endif %}"
name="mode"
value="remove"
onclick="{% if rank.id in locked %}yuunoRankProtected(){% else %}yuunoRankRemove({{ rank.id }}, '{{ session_id() }}', '{{ rank.name }}'){% endif %}"
></button>
</div>
</div> </div>
</form>
{% endfor %} {% endfor %}
</div> </div>
{% endblock %} {% endblock %}

View file

@ -9,13 +9,14 @@
{% block settingsContent %} {% block settingsContent %}
<div class="bbcode" id="settingsPreview" style="max-height: 500px; overflow-y: auto; background: #C2AEEE; box-shadow: inset 0 0 1em 1em #D3BFFF;">{{ user.signature()|raw|nl2br }}</div> <div class="bbcode" id="settingsPreview" style="max-height: 500px; overflow-y: auto; background: #C2AEEE; box-shadow: inset 0 0 1em 1em #D3BFFF;">{{ user.signature()|raw|nl2br }}</div>
<hr> <hr>
<form enctype="multipart/form-data" method="post" action="{{ route('settings.account.signature') }}"> <form enctype="multipart/form-data" method="post" action="javascript:;" onsubmit="updateSettings(this, '{{ route('settings.account.signature') }}');">
<input type="hidden" name="session" value="{{ session_id() }}">
<div> <div>
<textarea name="signature" id="settingsEditor" class="input__text" style="height: 400px;">{{ user.signature }}</textarea> <textarea name="signature" id="settingsEditor" class="input__text" style="height: 400px;">{{ user.signature }}</textarea>
</div> </div>
<button value="{{ session_id() }}" name="session" class="input__button">Save</button> <button class="input__button">Save</button>
<button type="reset" class="input__button">Reset</button> <button type="reset" class="input__button">Reset</button>
<button type="button" class="input__button" onclick="settingsPreview();">Preview</button> <button type="button" class="input__button" onclick="settingsPreview()">Preview</button>
</form> </form>
{% include 'settings/account/_preview.twig' %} {% include 'settings/account/_preview.twig' %}
{% endblock %} {% endblock %}

View file

@ -9,13 +9,14 @@
{% block settingsContent %} {% block settingsContent %}
<div class="bbcode" id="settingsPreview" style="max-height: 500px; overflow-y: auto; background: #C2AEEE; box-shadow: inset 0 0 1em 1em #D3BFFF;">{{ user.userPage()|raw|nl2br }}</div> <div class="bbcode" id="settingsPreview" style="max-height: 500px; overflow-y: auto; background: #C2AEEE; box-shadow: inset 0 0 1em 1em #D3BFFF;">{{ user.userPage()|raw|nl2br }}</div>
<hr> <hr>
<form enctype="multipart/form-data" method="post" action="{{ route('settings.account.userpage') }}"> <form enctype="multipart/form-data" method="post" action="javascript:;" onsubmit="updateSettings(this, '{{ route('settings.account.userpage') }}');">
<input type="hidden" name="session" value="{{ session_id() }}">
<div> <div>
<textarea name="userpage" id="settingsEditor" class="input__text" style="height: 400px;">{% if user.page %}{{ user.page }}{% else %}[header]Welcome to my userpage![/header]{% endif %}</textarea> <textarea name="userpage" id="settingsEditor" class="input__text" style="height: 400px;">{% if user.page %}{{ user.page }}{% else %}[header]Welcome to my userpage![/header]{% endif %}</textarea>
</div> </div>
<button value="{{ session_id() }}" name="session" class="input__button">Save</button> <button class="input__button">Save</button>
<button type="reset" class="input__button">Reset</button> <button type="reset" class="input__button">Reset</button>
<button type="button" class="input__button" onclick="settingsPreview();">Preview</button> <button type="button" class="input__button" onclick="settingsPreview()">Preview</button>
</form> </form>
{% include 'settings/account/_preview.twig' %} {% include 'settings/account/_preview.twig' %}
{% endblock %} {% endblock %}

View file

@ -5,25 +5,22 @@
{% block js %} {% block js %}
<script> <script>
function updateSettings(form, action, text) { function updateSettings(form, action, text) {
var forms = {}, var dialogue = new Sakura.Dialogue,
dialogue = new Sakura.Dialogue,
updater = new Sakura.AJAX; updater = new Sakura.AJAX;
dialogue.AddCallback(Sakura.DialogueButton.Ok, function () {
this.Close();
});
for (var a = 0; a < form.elements.length; a++) {
forms[form.elements.item(a).name] = form.elements.item(a).value;
}
updater.SetUrl(action); updater.SetUrl(action);
updater.Form(); updater.SetFormData(new FormData(form));
updater.SetSend(forms);
updater.AddCallback(0, function () { updater.AddCallback(0, function () {
var resp = updater.JSON(); var resp = updater.JSON();
dialogue.Title = resp.error ? "Error" : "Information"; dialogue.Title = resp.error ? "Error" : "Information";
dialogue.Text = resp.error || text || 'Updated!'; dialogue.Text = resp.error || text || 'Updated!';
dialogue.AddCallback(Sakura.DialogueButton.Ok, function () {
if (resp.go) {
window.location.assign(resp.go);
}
this.Close();
});
dialogue.Display(); dialogue.Display();
}); });
updater.Start(Sakura.HTTPMethod.POST); updater.Start(Sakura.HTTPMethod.POST);