|
|
|
@ -61,38 +61,25 @@ define('forum/admin/settings', ['uploader', 'sounds'], function(uploader, sounds
|
|
|
|
|
|
|
|
|
|
saveBtn.off('click').on('click', function(e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
var done = 0,
|
|
|
|
|
error;
|
|
|
|
|
|
|
|
|
|
for (x = 0; x < numFields; x++) {
|
|
|
|
|
saveField(fields[x], onFieldSaved);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onFieldSaved(err) {
|
|
|
|
|
if (!error && err) {
|
|
|
|
|
error = err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
done++;
|
|
|
|
|
if (done === numFields) {
|
|
|
|
|
if (error) {
|
|
|
|
|
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({
|
|
|
|
|
saveFields(fields, function onFieldsSaved(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'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
app.alert({
|
|
|
|
|
alert_id: 'config_status',
|
|
|
|
|
timeout: 2500,
|
|
|
|
|
title: 'Changes Saved',
|
|
|
|
|
message: 'Your changes to the NodeBB configuration have been saved.',
|
|
|
|
|
type: 'success'
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
handleUploads();
|
|
|
|
@ -131,38 +118,50 @@ define('forum/admin/settings', ['uploader', 'sounds'], function(uploader, sounds
|
|
|
|
|
socket.emit('admin.config.remove', key);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function saveField(field, callback) {
|
|
|
|
|
field = $(field);
|
|
|
|
|
var key = field.attr('data-field'),
|
|
|
|
|
value, inputType;
|
|
|
|
|
function saveFields(fields, callback) {
|
|
|
|
|
var data = {};
|
|
|
|
|
|
|
|
|
|
if (field.is('input')) {
|
|
|
|
|
inputType = field.attr('type');
|
|
|
|
|
switch (inputType) {
|
|
|
|
|
case 'text':
|
|
|
|
|
case 'password':
|
|
|
|
|
case 'hidden':
|
|
|
|
|
case 'textarea':
|
|
|
|
|
case 'number':
|
|
|
|
|
fields.each(function() {
|
|
|
|
|
var field = $(this);
|
|
|
|
|
var key = field.attr('data-field'),
|
|
|
|
|
value, inputType;
|
|
|
|
|
|
|
|
|
|
if (field.is('input')) {
|
|
|
|
|
inputType = field.attr('type');
|
|
|
|
|
switch (inputType) {
|
|
|
|
|
case 'text':
|
|
|
|
|
case 'password':
|
|
|
|
|
case 'hidden':
|
|
|
|
|
case 'textarea':
|
|
|
|
|
case 'number':
|
|
|
|
|
value = field.val();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'checkbox':
|
|
|
|
|
value = field.prop('checked') ? '1' : '0';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else if (field.is('textarea') || field.is('select')) {
|
|
|
|
|
value = field.val();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data[key] = value;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
case 'checkbox':
|
|
|
|
|
value = field.prop('checked') ? '1' : '0';
|
|
|
|
|
break;
|
|
|
|
|
socket.emit('admin.config.setMultiple', data, function(err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
} else if (field.is('textarea') || field.is('select')) {
|
|
|
|
|
value = field.val();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
socket.emit('admin.config.set', {
|
|
|
|
|
key: key,
|
|
|
|
|
value: value
|
|
|
|
|
}, function(err) {
|
|
|
|
|
if(!err && app.config[key] !== undefined) {
|
|
|
|
|
app.config[key] = value;
|
|
|
|
|
if (app.config) {
|
|
|
|
|
for(var field in data) {
|
|
|
|
|
if (data.hasOwnProperty(field)) {
|
|
|
|
|
app.config[field] = data[field];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
callback(err);
|
|
|
|
|
|
|
|
|
|
callback();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|