From c15c0912bc8e1e6dc15b6c22fc1c6b1c83d4c15d Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Tue, 9 Jun 2015 16:12:23 +0200 Subject: [PATCH] feature #3748: Add take snapshot dialog --- src/sunstone/public/app/tabs/vms-tab.js | 3 +- .../app/tabs/vms-tab/dialogs/snapshot.js | 78 +++++++++++++++++++ .../tabs/vms-tab/dialogs/snapshot/dialogId.js | 3 + .../tabs/vms-tab/dialogs/snapshot/html.hbs | 27 +++++++ 4 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 src/sunstone/public/app/tabs/vms-tab/dialogs/snapshot.js create mode 100644 src/sunstone/public/app/tabs/vms-tab/dialogs/snapshot/dialogId.js create mode 100644 src/sunstone/public/app/tabs/vms-tab/dialogs/snapshot/html.hbs diff --git a/src/sunstone/public/app/tabs/vms-tab.js b/src/sunstone/public/app/tabs/vms-tab.js index 2039fd5e67..f218b90ba0 100644 --- a/src/sunstone/public/app/tabs/vms-tab.js +++ b/src/sunstone/public/app/tabs/vms-tab.js @@ -12,7 +12,8 @@ define(function(require) { require('./vms-tab/dialogs/migrate'), require('./vms-tab/dialogs/resize'), require('./vms-tab/dialogs/attach-disk'), - require('./vms-tab/dialogs/attach-nic') + require('./vms-tab/dialogs/attach-nic'), + require('./vms-tab/dialogs/snapshot') ]; var _panels = [ diff --git a/src/sunstone/public/app/tabs/vms-tab/dialogs/snapshot.js b/src/sunstone/public/app/tabs/vms-tab/dialogs/snapshot.js new file mode 100644 index 0000000000..4be53cc617 --- /dev/null +++ b/src/sunstone/public/app/tabs/vms-tab/dialogs/snapshot.js @@ -0,0 +1,78 @@ +define(function(require) { + /* + DEPENDENCIES + */ + + var BaseDialog = require('utils/dialogs/dialog'); + var TemplateHTML = require('hbs!./snapshot/html'); + var Sunstone = require('sunstone'); + var Tips = require('utils/tips'); + + /* + CONSTANTS + */ + + var DIALOG_ID = require('./snapshot/dialogId'); + var TAB_ID = require('../tabId') + + /* + CONSTRUCTOR + */ + + function Dialog() { + this.dialogId = DIALOG_ID; + + BaseDialog.call(this); + }; + + Dialog.DIALOG_ID = DIALOG_ID; + Dialog.prototype = Object.create(BaseDialog.prototype); + Dialog.prototype.constructor = Dialog; + Dialog.prototype.html = _html; + Dialog.prototype.onShow = _onShow; + Dialog.prototype.setup = _setup; + Dialog.prototype.setElement = _setElement; + + return Dialog; + + /* + FUNCTION DEFINITIONS + */ + + function _html() { + return TemplateHTML({ + 'dialogId': this.dialogId + }); + } + + function _setup(context) { + var that = this; + + Tips.setup(context); + + $('#' + DIALOG_ID + 'Form', context).submit(function() { + var snapshot_name = $('#snapshot_name', this).val(); + var obj = { + "snapshot_name": snapshot_name + } + + Sunstone.runAction('VM.snapshot_create', that.element.ID, obj); + + Sunstone.getDialog(DIALOG_ID).hide(); + Sunstone.getDialog(DIALOG_ID).reset(); + return false; + }); + + return false; + } + + function _onShow(context) { + $("#vm_id", context).val(this.element.ID); + $("#snapshot_name", context).focus(); + return false; + } + + function _setElement(element) { + this.element = element + } +}); diff --git a/src/sunstone/public/app/tabs/vms-tab/dialogs/snapshot/dialogId.js b/src/sunstone/public/app/tabs/vms-tab/dialogs/snapshot/dialogId.js new file mode 100644 index 0000000000..74134f7393 --- /dev/null +++ b/src/sunstone/public/app/tabs/vms-tab/dialogs/snapshot/dialogId.js @@ -0,0 +1,3 @@ +define(function(require) { + return 'snapshotVMDialog'; +}); diff --git a/src/sunstone/public/app/tabs/vms-tab/dialogs/snapshot/html.hbs b/src/sunstone/public/app/tabs/vms-tab/dialogs/snapshot/html.hbs new file mode 100644 index 0000000000..1f41c10132 --- /dev/null +++ b/src/sunstone/public/app/tabs/vms-tab/dialogs/snapshot/html.hbs @@ -0,0 +1,27 @@ + \ No newline at end of file