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

41 lines
1.2 KiB
JavaScript
Executable File

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