+
+ assemble_field_data: function(values, data) {
+ if (Ext.isObject(data)) {
+ Ext.Object.each(data, function(name, val) {
+ if (values.hasOwnProperty(name)) {
+ var bucket = values[name];
+ if (!Ext.isArray(bucket)) {
+ bucket = values[name] = [bucket];
+ }
+ if (Ext.isArray(val)) {
+ values[name] = bucket.concat(val);
+ } else {
+ bucket.push(val);
+ }
+ } else {
+ values[name] = val;
+ }
+ });
+ }
+ },
+
+ dialog_title: function(subject, create, isAdd) {
+ if (create) {
+ if (isAdd) {
+ return gettext('Add') + ': ' + subject;
+ } else {
+ return gettext('Create') + ': ' + subject;
+ }
+ } else {
+ return gettext('Edit') + ': ' + subject;
+ }
+ },
+
+ network_iface_types: {
+ eth: gettext("Network Device"),
+ bridge: 'Linux Bridge',
+ bond: 'Linux Bond',
+ vlan: 'Linux VLAN',
+ OVSBridge: 'OVS Bridge',
+ OVSBond: 'OVS Bond',
+ OVSPort: 'OVS Port',
+ OVSIntPort: 'OVS IntPort'
+ },
+
+ render_network_iface_type: function(value) {
+ return Proxmox.Utils.network_iface_types[value] ||
+ Proxmox.Utils.unknownText;
+ },
+
+ task_desc_table: {
+ acmenewcert: [ 'SRV', gettext('Order Certificate') ],
+ acmeregister: [ 'ACME Account', gettext('Register') ],
+ acmedeactivate: [ 'ACME Account', gettext('Deactivate') ],
+ acmeupdate: [ 'ACME Account', gettext('Update') ],
+ acmerefresh: [ 'ACME Account', gettext('Refresh') ],
+ acmerenew: [ 'SRV', gettext('Renew Certificate') ],
+ acmerevoke: [ 'SRV', gettext('Revoke Certificate') ],
+ 'move_volume': [ 'CT', gettext('Move Volume') ],
+ clustercreate: [ '', gettext('Create Cluster') ],
+ clusterjoin: [ '', gettext('Join Cluster') ],
+ diskinit: [ 'Disk', gettext('Initialize Disk with GPT') ],
+ vncproxy: [ 'VM/CT', gettext('Console') ],
+ spiceproxy: [ 'VM/CT', gettext('Console') + ' (Spice)' ],
+ vncshell: [ '', gettext('Shell') ],
+ spiceshell: [ '', gettext('Shell') + ' (Spice)' ],
+ qmsnapshot: [ 'VM', gettext('Snapshot') ],
+ qmrollback: [ 'VM', gettext('Rollback') ],
+ qmdelsnapshot: [ 'VM', gettext('Delete Snapshot') ],
+ qmcreate: [ 'VM', gettext('Create') ],
+ qmrestore: [ 'VM', gettext('Restore') ],
+ qmdestroy: [ 'VM', gettext('Destroy') ],
+ qmigrate: [ 'VM', gettext('Migrate') ],
+ qmclone: [ 'VM', gettext('Clone') ],
+ qmmove: [ 'VM', gettext('Move disk') ],
+ qmtemplate: [ 'VM', gettext('Convert to template') ],
+ qmstart: [ 'VM', gettext('Start') ],
+ qmstop: [ 'VM', gettext('Stop') ],
+ qmreset: [ 'VM', gettext('Reset') ],
+ qmshutdown: [ 'VM', gettext('Shutdown') ],
+ qmsuspend: [ 'VM', gettext('Hibernate') ],
+ qmpause: [ 'VM', gettext('Pause') ],
+ qmresume: [ 'VM', gettext('Resume') ],
+ qmconfig: [ 'VM', gettext('Configure') ],
+ vzsnapshot: [ 'CT', gettext('Snapshot') ],
+ vzrollback: [ 'CT', gettext('Rollback') ],
+ vzdelsnapshot: [ 'CT', gettext('Delete Snapshot') ],
+ vzcreate: ['CT', gettext('Create') ],
+ vzrestore: ['CT', gettext('Restore') ],
+ vzdestroy: ['CT', gettext('Destroy') ],
+ vzmigrate: [ 'CT', gettext('Migrate') ],
+ vzclone: [ 'CT', gettext('Clone') ],
+ vztemplate: [ 'CT', gettext('Convert to template') ],
+ vzstart: ['CT', gettext('Start') ],
+ vzstop: ['CT', gettext('Stop') ],
+ vzmount: ['CT', gettext('Mount') ],
+ vzumount: ['CT', gettext('Unmount') ],
+ vzshutdown: ['CT', gettext('Shutdown') ],
+ vzsuspend: [ 'CT', gettext('Suspend') ],
+ vzresume: [ 'CT', gettext('Resume') ],
+ hamigrate: [ 'HA', gettext('Migrate') ],
+ hastart: [ 'HA', gettext('Start') ],
+ hastop: [ 'HA', gettext('Stop') ],
+ srvstart: ['SRV', gettext('Start') ],
+ srvstop: ['SRV', gettext('Stop') ],
+ srvrestart: ['SRV', gettext('Restart') ],
+ srvreload: ['SRV', gettext('Reload') ],
+ cephcreatemgr: ['Ceph Manager', gettext('Create') ],
+ cephdestroymgr: ['Ceph Manager', gettext('Destroy') ],
+ cephcreatemon: ['Ceph Monitor', gettext('Create') ],
+ cephdestroymon: ['Ceph Monitor', gettext('Destroy') ],
+ cephcreateosd: ['Ceph OSD', gettext('Create') ],
+ cephdestroyosd: ['Ceph OSD', gettext('Destroy') ],
+ cephcreatepool: ['Ceph Pool', gettext('Create') ],
+ cephdestroypool: ['Ceph Pool', gettext('Destroy') ],
+ cephfscreate: ['CephFS', gettext('Create') ],
+ cephcreatemds: ['Ceph Metadata Server', gettext('Create') ],
+ cephdestroymds: ['Ceph Metadata Server', gettext('Destroy') ],
+ imgcopy: ['', gettext('Copy data') ],
+ imgdel: ['', gettext('Erase data') ],
+ unknownimgdel: ['', gettext('Destroy image from unknown guest') ],
+ download: ['', gettext('Download') ],
+ vzdump: ['VM/CT', gettext('Backup') ],
+ aptupdate: ['', gettext('Update package database') ],
+ startall: [ '', gettext('Start all VMs and Containers') ],
+ stopall: [ '', gettext('Stop all VMs and Containers') ],
+ migrateall: [ '', gettext('Migrate all VMs and Containers') ],
+ dircreate: [ gettext('Directory Storage'), gettext('Create') ],
+ lvmcreate: [ gettext('LVM Storage'), gettext('Create') ],
+ lvmthincreate: [ gettext('LVM-Thin Storage'), gettext('Create') ],
+ zfscreate: [ gettext('ZFS Storage'), gettext('Create') ]
+ },
+
+ format_task_description: function(type, id) {
+ var farray = Proxmox.Utils.task_desc_table[type];
+ var text;
+ if (!farray) {
+ text = type;
+ if (id) {
+ type += ' ' + id;
+ }
+ return text;
+ }
+ var prefix = farray[0];
+ text = farray[1];
+ if (prefix) {
+ return prefix + ' ' + id + ' - ' + text;
+ }
+ return text;
+ },
+
+ format_size: function(size) {
+ /*jslint confusion: true */
+
+ var units = ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi'];
+ var num = 0;
+
+ while (size >= 1024 && ((num++)+1) < units.length) {
+ size = size / 1024;
+ }
+
+ return size.toFixed((num > 0)?2:0) + " " + units[num] + "B";
+ },
+
+ render_upid: function(value, metaData, record) {
+ var type = record.data.type;
+ var id = record.data.id;
+
+ return Proxmox.Utils.format_task_description(type, id);
+ },
+
+ render_uptime: function(value) {
+
+ var uptime = value;
+
+ if (uptime === undefined) {
+ return '';
+ }
+
+ if (uptime <= 0) {
+ return '-';
+ }
+
+ return Proxmox.Utils.format_duration_long(uptime);
+ },
+
+ parse_task_upid: function(upid) {
+ var task = {};
+
+ var res = upid.match(/^UPID:(\S+):([0-9A-Fa-f]{8}):([0-9A-Fa-f]{8,9}):([0-9A-Fa-f]{8}):([^:\s]+):([^:\s]*):([^:\s]+):$/);
+ if (!res) {
+ throw "unable to parse upid '" + upid + "'";
+ }
+ task.node = res[1];
+ task.pid = parseInt(res[2], 16);
+ task.pstart = parseInt(res[3], 16);
+ task.starttime = parseInt(res[4], 16);
+ task.type = res[5];
+ task.id = res[6];
+ task.user = res[7];
+
+ task.desc = Proxmox.Utils.format_task_description(task.type, task.id);
+
+ return task;
+ },
+
+ render_timestamp: function(value, metaData, record, rowIndex, colIndex, store) {
+ var servertime = new Date(value * 1000);
+ return Ext.Date.format(servertime, 'Y-m-d H:i:s');
+ },
+
+ get_help_info: function(section) {
+ var helpMap;
+ if (typeof proxmoxOnlineHelpInfo !== 'undefined') {
+ helpMap = proxmoxOnlineHelpInfo;
+ } else if (typeof pveOnlineHelpInfo !== 'undefined') {
+ // be backward compatible with older pve-doc-generators
+ helpMap = pveOnlineHelpInfo;
+ } else {
+ throw "no global OnlineHelpInfo map declared";
+ }
+
+ return helpMap[section];
+ },
+
+ get_help_link: function(section) {
+ var info = Proxmox.Utils.get_help_info(section);
+ if (!info) {
+ return;
+ }
+
+ return window.location.origin + info.link;
+ },
+
+ openXtermJsViewer: function(vmtype, vmid, nodename, vmname, cmd) {
+ var url = Ext.Object.toQueryString({
+ console: vmtype, // kvm, lxc, upgrade or shell
+ xtermjs: 1,
+ vmid: vmid,
+ vmname: vmname,
+ node: nodename,
+ cmd: cmd,
+
+ });
+ var nw = window.open("?" + url, '_blank', 'toolbar=no,location=no,status=no,menubar=no,resizable=yes,width=800,height=420');
+ if (nw) {
+ nw.focus();
+ }
+ }
+
+},
+