linting setting.js again and abstracting out saveField

v1.18.x
Julian Lam 11 years ago
parent 0a293be823
commit e611a8174e

@ -30,16 +30,16 @@ define(['uploader'], function(uploader) {
if (field.is('input')) { if (field.is('input')) {
if (app.config[key]) { if (app.config[key]) {
switch (inputType) { switch (inputType) {
case 'text': case 'text':
case 'password': case 'password':
case 'textarea': case 'textarea':
case 'number': case 'number':
field.val(app.config[key]); field.val(app.config[key]);
break; break;
case 'checkbox': case 'checkbox':
field.prop('checked', parseInt(app.config[key], 10) === 1); field.prop('checked', parseInt(app.config[key], 10) === 1);
break; break;
} }
} }
} else if (field.is('textarea')) { } 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() { $('#uploadLogoBtn').on('click', function() {
uploader.open(RELATIVE_PATH + '/admin/uploadlogo', {}, 0, function(image) { uploader.open(RELATIVE_PATH + '/admin/uploadlogo', {}, 0, function(image) {
$('#logoUrl').val(image); $('#logoUrl').val(image);
@ -146,5 +92,59 @@ define(['uploader'], function(uploader) {
socket.emit('admin.config.remove', key); 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; return Settings;
}); });
Loading…
Cancel
Save