proxmox-backup/www/Utils.js
Thomas Lamprecht 06c3dc8a8e ui: task: improve rendering of backup/prune worker entries
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-05-26 13:37:57 +02:00

53 lines
1.5 KiB
JavaScript

/*global Proxmox */
Ext.ns('PBS');
console.log("Starting Backup Server GUI");
Ext.define('PBS.Utils', {
singleton: true,
updateLoginData: function(data) {
Proxmox.CSRFPreventionToken = data.CSRFPreventionToken;
Proxmox.UserName = data.username;
//console.log(data.ticket);
// fixme: use secure flag once we have TLS
//Ext.util.Cookies.set('PBSAuthCookie', data.ticket, null, '/', null, true );
Ext.util.Cookies.set('PBSAuthCookie', data.ticket, null, '/', null, false);
},
dataStorePrefix: 'DataStore-',
getDataStoreFromPath: function(path) {
return path.slice(PBS.Utils.dataStorePrefix.length);
},
isDataStorePath: function(path) {
return path.indexOf(PBS.Utils.dataStorePrefix) === 0;
},
render_datastore_worker_id: function(id, what) {
const result = id.match(/^(\S+)_([^_\s]+)_([^_\s]+)$/);
if (result) {
let datastore = result[1], type = result[2], id = result[3];
return `Datastore ${datastore} - ${what} ${type}/${id}`;
}
return what;
},
constructor: function() {
var me = this;
// do whatever you want here
Proxmox.Utils.override_task_descriptions({
garbage_collection: ['Datastore', gettext('Garbage collect') ],
prune: (type, id) => {
return PBS.Utils.render_datastore_worker_id(id, gettext('Prune'));
},
backup: (type, id) => {
return PBS.Utils.render_datastore_worker_id(id, gettext('Backup'));
},
reader: [ '', gettext('Read datastore objects') ], // FIXME: better one
});
}
});