From 858678fd4abe986a6ddfc1b5362fedf9f529d27d Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Tue, 9 Jun 2015 16:12:02 +0200 Subject: [PATCH] feature #3748: Add snapshots panel --- src/sunstone/public/app/tabs/vms-tab.js | 1 + .../app/tabs/vms-tab/panels/snapshots.js | 163 ++++++++++++++++++ .../tabs/vms-tab/panels/snapshots/panelId.js | 3 + 3 files changed, 167 insertions(+) create mode 100644 src/sunstone/public/app/tabs/vms-tab/panels/snapshots.js create mode 100644 src/sunstone/public/app/tabs/vms-tab/panels/snapshots/panelId.js diff --git a/src/sunstone/public/app/tabs/vms-tab.js b/src/sunstone/public/app/tabs/vms-tab.js index c2765832b6..2039fd5e67 100644 --- a/src/sunstone/public/app/tabs/vms-tab.js +++ b/src/sunstone/public/app/tabs/vms-tab.js @@ -20,6 +20,7 @@ define(function(require) { require('./vms-tab/panels/capacity'), require('./vms-tab/panels/storage'), require('./vms-tab/panels/network'), + require('./vms-tab/panels/snapshots'), // require('./vms-tab/panels/template') ]; diff --git a/src/sunstone/public/app/tabs/vms-tab/panels/snapshots.js b/src/sunstone/public/app/tabs/vms-tab/panels/snapshots.js new file mode 100644 index 0000000000..011f6ed290 --- /dev/null +++ b/src/sunstone/public/app/tabs/vms-tab/panels/snapshots.js @@ -0,0 +1,163 @@ +define(function(require) { + /* + DEPENDENCIES + */ + + var Locale = require('utils/locale'); + var Config = require('sunstone-config'); + var Sunstone = require('sunstone'); + var Humanize = require('utils/humanize'); + var Notifier = require('utils/notifier'); + + /* + CONSTANTS + */ + + var TAB_ID = require('../tabId'); + var PANEL_ID = require('./snapshots/panelId'); + var SNAPSHOT_DIALOG_ID = require('../dialogs/snapshot/dialogId'); + var RESOURCE = "VM" + var XML_ROOT = "VM" + + /* + CONSTRUCTOR + */ + + function Panel(info) { + this.panelId = PANEL_ID; + this.title = Locale.tr("Snapshots"); + this.icon = "fa-laptop"; + + 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 snapshots = [] + if ($.isArray(that.element.TEMPLATE.SNAPSHOT)) + snapshots = that.element.TEMPLATE.SNAPSHOT + else if (!$.isEmptyObject(that.element.TEMPLATE.SNAPSHOT)) + snapshots = [that.element.TEMPLATE.SNAPSHOT] + + if (!snapshots.length) { + html += '\ + \ + \ + ' ; + } else { + + for (var i = 0; i < snapshots.length; i++) { + var snapshot = snapshots[i]; + + if ( + (// ACTIVE + that.element.STATE == "3") && + (// HOTPLUG_SNAPSHOT + that.element.LCM_STATE == "24")) { + actions = 'snapshot in progress' + } else { + actions = ''; + + if ((that.element.STATE == "3" && that.element.LCM_STATE == "3")) { + if (Config.isTabActionEnabled("vms-tab", "VM.snapshot_revert")) { + actions += '' + Locale.tr("Revert") + '  ' + } + + if (Config.isTabActionEnabled("vms-tab", "VM.snapshot_delete")) { + actions += '' + Locale.tr("Delete") + '' + } + } + } + + html += '\ + \ + \ + \ + \ + \ + ' ; + } + } + + html += '\ + \ +
' + Locale.tr("ID") + '' + Locale.tr("Name") + '' + Locale.tr("Timestamp") + '' + Locale.tr("Actions") + '' + + if (Config.isTabActionEnabled("vms-tab", "VM.snapshot_create")) { + // If VM is not RUNNING, then we forget about the attach disk form. + if (that.element.STATE == "3" && that.element.LCM_STATE == "3") { + html += '\ + ' + } else { + html += '\ + ' + } + } + + html += '
' + Locale.tr("No snapshots to show") + '
' + snapshot.SNAPSHOT_ID + '' + snapshot.NAME + '' + Humanize.prettyTime(snapshot.TIME) + '' + actions + '
\ +
\ +
\ + '; + + return html; + } + + function _setup(context) { + var that = this; + + if (Config.isTabActionEnabled("vms-tab", "VM.snapshot_create")) { + context.off('click', '#take_snapshot'); + context.on('click', '#take_snapshot', function() { + var dialog = Sunstone.getDialog(SNAPSHOT_DIALOG_ID); + dialog.setElement(that.element); + dialog.show(); + return false; + }); + } + + if (Config.isTabActionEnabled("vms-tab", "VM.snapshot_revert")) { + context.off('click', '.snapshot_revert'); + context.on('click', '.snapshot_revert', function() { + var snapshot_id = $(this).parents('tr').attr('snapshot_id'); + Sunstone.runAction('VM.snapshot_revert', that.element.ID, {"snapshot_id": snapshot_id}); + return false; + }); + } + + if (Config.isTabActionEnabled("vms-tab", "VM.snapshot_delete")) { + context.off('click', '.snapshot_delete'); + context.on('click', '.snapshot_delete', function() { + var snapshot_id = $(this).parents('tr').attr('snapshot_id'); + Sunstone.runAction('VM.snapshot_delete', that.element.ID, {"snapshot_id": snapshot_id}); + return false; + }); + } + } +}); diff --git a/src/sunstone/public/app/tabs/vms-tab/panels/snapshots/panelId.js b/src/sunstone/public/app/tabs/vms-tab/panels/snapshots/panelId.js new file mode 100644 index 0000000000..5a6b12177d --- /dev/null +++ b/src/sunstone/public/app/tabs/vms-tab/panels/snapshots/panelId.js @@ -0,0 +1,3 @@ +define(function(require) { + return 'vm_snapshot_tab'; +});