From e611a8174eadafe27320cc9dd22392d79f5dadf5 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Wed, 12 Mar 2014 16:21:19 -0400 Subject: [PATCH] linting setting.js again and abstracting out saveField --- public/src/forum/admin/settings.js | 128 ++++++++++++++--------------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/public/src/forum/admin/settings.js b/public/src/forum/admin/settings.js index 1c05462a80..5e51caac8f 100644 --- a/public/src/forum/admin/settings.js +++ b/public/src/forum/admin/settings.js @@ -30,16 +30,16 @@ define(['uploader'], function(uploader) { if (field.is('input')) { if (app.config[key]) { switch (inputType) { - case 'text': - case 'password': - case 'textarea': - case 'number': - field.val(app.config[key]); - break; - - case 'checkbox': - field.prop('checked', parseInt(app.config[key], 10) === 1); - break; + case 'text': + case 'password': + case 'textarea': + case 'number': + field.val(app.config[key]); + break; + + case 'checkbox': + field.prop('checked', parseInt(app.config[key], 10) === 1); + break; } } } else if (field.is('textarea')) { @@ -61,60 +61,6 @@ define(['uploader'], function(uploader) { } }); - function saveField(field) { - field = $(field); - var key = field.attr('data-field'), - value; - - if (field.is('input')) { - inputType = field.attr('type'); - switch (inputType) { - case 'text': - case 'password': - case 'textarea': - case 'number': - value = field.val(); - break; - - case 'checkbox': - value = field.prop('checked') ? '1' : '0'; - break; - } - } else if (field.is('textarea')) { - value = field.val(); - } else if (field.is('select')) { - value = field.val(); - } - - 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' - }); - } - - 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) { $('#logoUrl').val(image); @@ -146,5 +92,59 @@ define(['uploader'], function(uploader) { socket.emit('admin.config.remove', key); }; + function saveField(field) { + field = $(field); + var key = field.attr('data-field'), + value, inputType; + + if (field.is('input')) { + inputType = field.attr('type'); + switch (inputType) { + case 'text': + case 'password': + case 'textarea': + case 'number': + value = field.val(); + break; + + case 'checkbox': + value = field.prop('checked') ? '1' : '0'; + break; + } + } else if (field.is('textarea')) { + value = field.val(); + } else if (field.is('select')) { + value = field.val(); + } + + 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' + }); + } + + 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' + }); + + }); + }; + return Settings; }); \ No newline at end of file