aboutsummaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-09-10 21:29:01 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-09-15 15:58:19 -0400
commit34ddbf25fe671360d7c2604839ab037a0adea66b (patch)
tree4ccdecef341ad4a0cb3f906f1ccc80fb0ff6d6bd /ext
parent1f77506f43607c6d3c9c87fbf82b993d87039526 (diff)
Implement profile order changing
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/js/settings-profiles.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/ext/bg/js/settings-profiles.js b/ext/bg/js/settings-profiles.js
index fa06203e..6e0e9953 100644
--- a/ext/bg/js/settings-profiles.js
+++ b/ext/bg/js/settings-profiles.js
@@ -41,6 +41,8 @@ function profileOptionsSetupEventListeners() {
$('#profile-remove-confirm').click(utilAsync(onProfileRemoveConfirm));
$('#profile-copy').click(utilAsync(onProfileCopy));
$('#profile-copy-confirm').click(utilAsync(onProfileCopyConfirm));
+ $('#profile-move-up').click(() => onProfileMove(-1));
+ $('#profile-move-down').click(() => onProfileMove(1));
$('.profile-form').find('input, select, textarea').not('.profile-form-manual').change(utilAsync(onProfileOptionsChanged));
}
@@ -75,6 +77,8 @@ async function profileFormWrite(optionsFull) {
profileOptionsPopulateSelect($('#profile-target'), optionsFull.profiles, currentProfileIndex, null);
$('#profile-remove').prop('disabled', optionsFull.profiles.length <= 1);
$('#profile-copy').prop('disabled', optionsFull.profiles.length <= 1);
+ $('#profile-move-up').prop('disabled', currentProfileIndex <= 0);
+ $('#profile-move-down').prop('disabled', currentProfileIndex >= optionsFull.profiles.length - 1);
$('#profile-name').val(profile.name);
}
@@ -207,6 +211,27 @@ function onProfileNameChanged() {
$('#profile-active, #profile-target').find(`[value="${currentProfileIndex}"]`).text(this.value);
}
+async function onProfileMove(offset) {
+ const optionsFull = await apiOptionsGetFull();
+ const index = currentProfileIndex + offset;
+ if (index < 0 || index >= optionsFull.profiles.length) {
+ return;
+ }
+
+ const profile = optionsFull.profiles[currentProfileIndex];
+ optionsFull.profiles.splice(currentProfileIndex, 1);
+ optionsFull.profiles.splice(index, 0, profile);
+
+ if (optionsFull.profileCurrent === currentProfileIndex) {
+ optionsFull.profileCurrent = index;
+ }
+
+ currentProfileIndex = index;
+
+ await profileOptionsUpdateTarget(optionsFull);
+ await settingsSaveOptions();
+}
+
async function onProfileCopy() {
const optionsFull = await apiOptionsGetFull();
if (optionsFull.profiles.length <= 1) {