cartodb-4.42/lib/assets/javascripts/builder/components/table/operations/table-rename-column.js
2024-04-06 05:25:13 +00:00

51 lines
1.4 KiB
JavaScript
Executable File

var Notifier = require('builder/components/notifier/notifier');
var errorParser = require('builder/helpers/error-parser');
module.exports = function (opts) {
if (!opts.columnModel) { throw new Error('columnModel is required'); }
if (!opts.newName) { throw new Error('newName is required'); }
var columnModel = opts.columnModel;
var oldName = columnModel.get('name');
var newName = opts.newName;
var successCallback = opts.onSuccess;
var errorCallback = opts.onError;
var notification = Notifier.addNotification({
status: 'loading',
info: _t('components.table.columns.rename.loading', { oldName: oldName, newName: newName }),
closable: false
});
columnModel.save({
new_name: newName,
old_name: columnModel.get('name')
}, {
wait: true,
success: function (model, attrs) {
successCallback && successCallback(model, attrs);
notification.set({
status: 'success',
info: _t('components.table.columns.rename.success', {
columnName: oldName,
newName: newName
}),
closable: true
});
},
error: function (model, err) {
errorCallback && errorCallback(model, err);
notification.set({
status: 'error',
info: _t('components.table.columns.rename.error', {
columnName: oldName,
newName: newName,
error: errorParser(err)
}),
closable: true
});
}
});
};