From 34ddbf25fe671360d7c2604839ab037a0adea66b Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Tue, 10 Sep 2019 21:29:01 -0400 Subject: Implement profile order changing --- ext/bg/js/settings-profiles.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'ext') 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) { -- cgit v1.2.3