side_menu/src/admin.js

79 lines
2.2 KiB
JavaScript

/**
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
let elements = []
const selector = '#side-menu-message';
const userConfig = (name, value, callbacks) => {
const url = OC.generateUrl('/apps/side_menu/personalSetting/valueSet')
$.post(url, {name: name, value: value}, callbacks.success)
.fail(callbacks.error)
}
const appConfig = (name, value, callbacks) => {
OCP.AppConfig.setValue('side_menu', name, value, callbacks)
}
const saveSettings = (key) => {
const element = elements.get(key)
const name = $(element).attr('name')
let value = $(element).val()
const size = elements.length
if (element === 'side-menu-cache') {
value++
}
const callbacks = {
success: () => {
OC.msg.finishedSuccess(
selector,
t('side_menu', (key + 1) + '/' + size)
)
if (key < size - 1) {
saveSettings(++key)
} else {
OC.msg.finishedSuccess(selector, t('side_menu', 'Saved'))
}
},
error: () => {
OC.msg.finishedError(selector, t('side_menu', 'Error while saving "' + element + '"'))
}
}
if ($(element).is('[data-personal]')) {
userConfig(name, value, callbacks)
} else {
appConfig(name, value, callbacks)
}
}
$(document).ready(() => {
elements = $('.side-menu-setting')
$('#side-menu-save').on('click', (event) => {
event.preventDefault()
OC.msg.startSaving(selector)
saveSettings(0)
});
});