diff --git a/src/sunstone/public/app/tabs/vms-tab.js b/src/sunstone/public/app/tabs/vms-tab.js index 7b96c7dd1a..56d5d10d72 100644 --- a/src/sunstone/public/app/tabs/vms-tab.js +++ b/src/sunstone/public/app/tabs/vms-tab.js @@ -16,6 +16,7 @@ define(function(require) { var _panels = [ require('./vms-tab/panels/info'), require('./vms-tab/panels/capacity'), + require('./vms-tab/panels/storage'), // require('./vms-tab/panels/template') ]; diff --git a/src/sunstone/public/app/tabs/vms-tab/panels/storage.js b/src/sunstone/public/app/tabs/vms-tab/panels/storage.js new file mode 100644 index 0000000000..328f40ea48 --- /dev/null +++ b/src/sunstone/public/app/tabs/vms-tab/panels/storage.js @@ -0,0 +1,237 @@ +define(function(require) { + /* + DEPENDENCIES + */ + + var Locale = require('utils/locale'); + var Config = require('sunstone-config'); + var Sunstone = require('sunstone'); + var Humanize = require('utils/humanize'); + var StateActions = require('../utils/state-actions'); + + /* + CONSTANTS + */ + + var TAB_ID = require('../tabId'); + var PANEL_ID = require('./storage/panelId'); + var ATTACH_DISK_DIALOG_ID = require('../dialogs/attach-disk/dialogId'); + var RESOURCE = "VM" + var XML_ROOT = "VM" + + /* + CONSTRUCTOR + */ + + function Panel(info) { + this.panelId = PANEL_ID; + this.title = Locale.tr("Storage"); + this.icon = "fa-tasks"; + + this.element = info[XML_ROOT]; + + return this; + }; + + Panel.PANEL_ID = PANEL_ID; + Panel.prototype.html = _html; + Panel.prototype.setup = _setup; + + return Panel; + + /* + FUNCTION DEFINITIONS + */ + + function _html() { + var that = this; + var html = '
\ +
\ +
\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + '; + + var disks = [] + if ($.isArray(that.element.TEMPLATE.DISK)) + disks = that.element.TEMPLATE.DISK + else if (!$.isEmptyObject(that.element.TEMPLATE.DISK)) + disks = [that.element.TEMPLATE.DISK] + + if (!$.isEmptyObject(that.element.TEMPLATE.CONTEXT)) { + var context_disk = that.element.TEMPLATE.CONTEXT; + + context_disk["IMAGE"] = Locale.tr("Context"); + context_disk["CONTEXT"] = true; + + disks.push(context_disk); + } + + if (!disks.length) { + html += '\ + \ + \ + '; + } else { + + for (var i = 0; i < disks.length; i++) { + var disk = disks[i]; + + var save_as; + // Snapshot deferred + if ( + (// ACTIVE + that.element.STATE == "3") && + (// HOTPLUG_SAVEAS HOTPLUG_SAVEAS_POWEROFF HOTPLUG_SAVEAS_SUSPENDED + that.element.LCM_STATE == "26" || that.element.LCM_STATE == "27" || that.element.LCM_STATE == "28") && + (// + disk.SAVE_AS_ACTIVE == "YES") + ) { + save_as = Locale.tr("in progress"); + actions = Locale.tr('deferred snapshot in progress'); + } + // Snapshot Hot + else if ( + (// ACTIVE + that.element.STATE == "3") && + (// HOTPLUG_SAVEAS HOTPLUG_SAVEAS_POWEROFF HOTPLUG_SAVEAS_SUSPENDED + that.element.LCM_STATE == "26" || that.element.LCM_STATE == "27" || that.element.LCM_STATE == "28") && + (// + disk.HOTPLUG_SAVE_AS_ACTIVE == "YES") + ) { + save_as = (disk.SAVE_AS ? disk.SAVE_AS : '-'); + actions = Locale.tr('hot snapshot in progress'); + } + // Attach / Detach + else if ( + (// ACTIVE + that.element.STATE == "3") && + (// HOTPLUG_SAVEAS HOTPLUG_SAVEAS_POWEROFF HOTPLUG_SAVEAS_SUSPENDED + that.element.LCM_STATE == "17") && + (// + disk.ATTACH = "YES") + ) { + save_as = (disk.SAVE_AS ? disk.SAVE_AS : '-'); + actions = Locale.tr('attach/detach in progress'); + } else { + save_as = (disk.SAVE_AS ? disk.SAVE_AS : '-'); + + actions = ''; + + if (disk.SAVE == "YES") { + /* TODO if (Config.isTabActionEnabled("vms-tab", "VM.disk_snapshot_cancel")) { + if (StateActions.enabledStateAction("VM.disk_snapshot_cancel", that.element.STATE, that.element.LCM_STATE)) { + actions += '\ + ' + Locale.tr("Cancel Snapshot") + '  ' + } + } */ + } else { + /* TODO if (Config.isTabActionEnabled("vms-tab", "VM.saveas")) { + // Check if it's volatile + if (disk.IMAGE_ID && + StateActions.enabledStateAction("VM.saveas", that.element.STATE, that.element.LCM_STATE)) { + actions += '' + Locale.tr("Snapshot") + '  ' + } + } */ + } + + if (Config.isTabActionEnabled("vms-tab", "VM.detachdisk")) { + if (StateActions.enabledStateAction("VM.detachdisk", that.element.STATE, that.element.LCM_STATE) && !disk.CONTEXT) { + actions += '' + Locale.tr("Detach") + '' + } + } + } + + html += '\ + \ + \ + \ + \ + \ + \ + \ + '; + } + } + + html += '\ + \ +
' + Locale.tr("ID") + '' + Locale.tr("Target") + '' + Locale.tr("Image / Format-Size") + '' + Locale.tr("Persistent") + '' + Locale.tr("Save as") + '' + Locale.tr("Actions") + ''; + + if (Config.isTabActionEnabled("vms-tab", "VM.attachdisk")) { + if (StateActions.enabledStateAction("VM.attachdisk", that.element.STATE, that.element.LCM_STATE)) { + html += '\ + ' + } else { + html += '\ + ' + } + } + + html += '
' + Locale.tr("No disks to show") + '
' + disk.DISK_ID + '' + disk.TARGET + '' + (disk.IMAGE ? disk.IMAGE : (Humanize.sizeFromMB(disk.SIZE) + (disk.FORMAT ? (' - ' + disk.FORMAT) : ''))) + '' + ((disk.SAVE && disk.SAVE == 'YES') ? Locale.tr('YES') : Locale.tr('NO')) + '' + save_as + '' + actions + '
\ +
\ +
\ + '; + + return html; + } + + function _setup(context) { + var that = this; + /* TODO if (Config.isTabActionEnabled("vms-tab", "VM.saveas")) { + setupSaveAsDialog(); + + $('a.saveas').live('click', function(){ + var b = $(this); + var vm_id = b.parents('form').attr('vmid'); + var disk_id = b.parents('tr').attr('disk_id'); + + popUpSaveAsDialog(vm_id, disk_id); + + //b.html(spinner); + return false; + }); + } */ + + /* TODO if (Config.isTabActionEnabled("vms-tab", "VM.disk_snapshot_cancel")) { + $('a.disk_snapshot_cancel').live('click', function(){ + var b = $(this); + var vm_id = b.parents('form').attr('vmid'); + var disk_id = b.parents('tr').attr('disk_id'); + + Sunstone.runAction('VM.disk_snapshot_cancel', vm_id, disk_id); + + return false; + }); + } */ + + if (Config.isTabActionEnabled("vms-tab", "VM.attachdisk")) { + context.off('click', '#attach_disk'); + context.on('click', '#attach_disk', function() { + var dialog = Sunstone.getDialog(ATTACH_DISK_DIALOG_ID); + dialog.setElement(that.element); + dialog.show(); + return false; + }); + } + + if (Config.isTabActionEnabled("vms-tab", "VM.detachdisk")) { + context.off('click', '.detachdisk'); + context.on('click', '.detachdisk', function() { + var disk_id = $(this).parents('tr').attr('disk_id'); + Sunstone.runAction('VM.detachdisk', that.element.ID, disk_id); + return false; + }); + } + } +}); diff --git a/src/sunstone/public/app/tabs/vms-tab/panels/storage/panelId.js b/src/sunstone/public/app/tabs/vms-tab/panels/storage/panelId.js new file mode 100644 index 0000000000..ba4488619b --- /dev/null +++ b/src/sunstone/public/app/tabs/vms-tab/panels/storage/panelId.js @@ -0,0 +1,3 @@ +define(function(require){ + return 'vm_hotplugging_tab'; +}); \ No newline at end of file