From 893efa5f2ac1ea17ca9c921dbe2cc9b2aad00b95 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Fri, 14 Feb 2014 15:08:56 -0500 Subject: [PATCH] closes #1004 --- public/src/forum/admin/settings.js | 89 +++++++++++++++++------------- 1 file changed, 50 insertions(+), 39 deletions(-) diff --git a/public/src/forum/admin/settings.js b/public/src/forum/admin/settings.js index c70dcc0828..44f0e22cc2 100644 --- a/public/src/forum/admin/settings.js +++ b/public/src/forum/admin/settings.js @@ -19,6 +19,7 @@ define(['uploader'], function(uploader) { numFields = fields.length, saveBtn = document.getElementById('save'), x, key, inputType; + for (x = 0; x < numFields; x++) { key = fields[x].getAttribute('data-field'); inputType = fields[x].getAttribute('type'); @@ -45,56 +46,66 @@ define(['uploader'], function(uploader) { } saveBtn.addEventListener('click', function(e) { - var key, value; + e.preventDefault(); for (x = 0; x < numFields; x++) { - key = fields[x].getAttribute('data-field'); - if (fields[x].nodeName === 'INPUT') { - inputType = fields[x].getAttribute('type'); - switch (inputType) { - case 'text': - case 'password': - case 'textarea': - case 'number': - value = fields[x].value; - break; + saveField(fields[x]); + } + }); - case 'checkbox': - value = fields[x].checked ? '1' : '0'; - break; - } - } else if (fields[x].nodeName === 'TEXTAREA') { - value = fields[x].value; - } else if (fields[x].nodeName === 'SELECT') { - value = fields[x].value; + function saveField(field) { + var key = field.getAttribute('data-field'), + value; + + if (field.nodeName === 'INPUT') { + inputType = field.getAttribute('type'); + switch (inputType) { + case 'text': + case 'password': + case 'textarea': + case 'number': + value = field.value; + break; + + case 'checkbox': + value = field.checked ? '1' : '0'; + break; } + } else if (field.nodeName === 'TEXTAREA') { + value = field.value; + } else if (field.nodeName === 'SELECT') { + value = field.value; + } - socket.emit('admin.config.set', { - key: key, - value: value - }, function(err) { - if(err) { - return app.alert({ - alert_id: 'config_status', - timeout: 2500, - title: 'Changes Not Saved', - message: 'NodeBB encountered a problem saving your changes', - type: 'danger' - }); - } - - app.alert({ + socket.emit('admin.config.set', { + key: key, + value: value + }, function(err) { + if(err) { + return app.alert({ alert_id: 'config_status', timeout: 2500, - title: 'Changes Saved', - message: 'Your changes to the NodeBB configuration have been saved.', - type: 'success' + title: 'Changes Not Saved', + message: 'NodeBB encountered a problem saving your changes', + type: 'danger' }); + } + + if(app.config[key] !== undefined) { + app.config[key] = value; + } + app.alert({ + alert_id: 'config_status', + timeout: 2500, + title: 'Changes Saved', + message: 'Your changes to the NodeBB configuration have been saved.', + type: 'success' }); - } - }); + + }); + } $('#uploadLogoBtn').on('click', function() { uploader.open(RELATIVE_PATH + '/admin/uploadlogo', {}, 0, function(image) {