From dec4ac7b5711885fd50cc187e89d190937bd7933 Mon Sep 17 00:00:00 2001 From: Abel Coronado Date: Wed, 22 Mar 2017 13:31:09 +0100 Subject: [PATCH] Added dialog in Revert Snapshots (#228) --- src/sunstone/public/app/tabs/vms-tab.js | 1 + .../public/app/tabs/vms-tab/dialogs/revert.js | 92 +++++++++++++++++++ .../tabs/vms-tab/dialogs/revert/dialogId.js | 19 ++++ .../app/tabs/vms-tab/dialogs/revert/html.hbs | 40 ++++++++ .../app/tabs/vms-tab/panels/snapshots.js | 6 +- 5 files changed, 156 insertions(+), 2 deletions(-) create mode 100644 src/sunstone/public/app/tabs/vms-tab/dialogs/revert.js create mode 100644 src/sunstone/public/app/tabs/vms-tab/dialogs/revert/dialogId.js create mode 100644 src/sunstone/public/app/tabs/vms-tab/dialogs/revert/html.hbs diff --git a/src/sunstone/public/app/tabs/vms-tab.js b/src/sunstone/public/app/tabs/vms-tab.js index f8c62025f0..2264fbce52 100644 --- a/src/sunstone/public/app/tabs/vms-tab.js +++ b/src/sunstone/public/app/tabs/vms-tab.js @@ -33,6 +33,7 @@ define(function(require) { require('./vms-tab/dialogs/disk-resize'), require('./vms-tab/dialogs/attach-nic'), require('./vms-tab/dialogs/snapshot'), + require('./vms-tab/dialogs/revert'), require('./vms-tab/dialogs/vnc'), require('./vms-tab/dialogs/spice'), require('./vms-tab/dialogs/saveas-template') diff --git a/src/sunstone/public/app/tabs/vms-tab/dialogs/revert.js b/src/sunstone/public/app/tabs/vms-tab/dialogs/revert.js new file mode 100644 index 0000000000..19805bcb63 --- /dev/null +++ b/src/sunstone/public/app/tabs/vms-tab/dialogs/revert.js @@ -0,0 +1,92 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2016, OpenNebula Project, OpenNebula Systems */ +/* */ +/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ +/* not use this file except in compliance with the License. You may obtain */ +/* a copy of the License at */ +/* */ +/* http://www.apache.org/licenses/LICENSE-2.0 */ +/* */ +/* Unless required by applicable law or agreed to in writing, software */ +/* distributed under the License is distributed on an "AS IS" BASIS, */ +/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ +/* See the License for the specific language governing permissions and */ +/* limitations under the License. */ +/* -------------------------------------------------------------------------- */ + +define(function(require) { + /* + DEPENDENCIES + */ + + var BaseDialog = require('utils/dialogs/dialog'); + var TemplateHTML = require('hbs!./revert/html'); + var Sunstone = require('sunstone'); + var Tips = require('utils/tips'); + + /* + CONSTANTS + */ + + var DIALOG_ID = require('./revert/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_id = $(this).parents('tr').attr('snapshot_id'); + Sunstone.runAction('VM.snapshot_revert', that.element.ID, {"snapshot_id": snapshot_id}); + + Sunstone.getDialog(DIALOG_ID).hide(); + Sunstone.getDialog(DIALOG_ID).reset(); + return false; + }); + + return false; + } + + function _onShow(context) { + this.setNames( {tabId: TAB_ID} ); + return false; + } + + function _setElement(element) { + this.element = element + } + +}); diff --git a/src/sunstone/public/app/tabs/vms-tab/dialogs/revert/dialogId.js b/src/sunstone/public/app/tabs/vms-tab/dialogs/revert/dialogId.js new file mode 100644 index 0000000000..14a82c35cd --- /dev/null +++ b/src/sunstone/public/app/tabs/vms-tab/dialogs/revert/dialogId.js @@ -0,0 +1,19 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2016, OpenNebula Project, OpenNebula Systems */ +/* */ +/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ +/* not use this file except in compliance with the License. You may obtain */ +/* a copy of the License at */ +/* */ +/* http://www.apache.org/licenses/LICENSE-2.0 */ +/* */ +/* Unless required by applicable law or agreed to in writing, software */ +/* distributed under the License is distributed on an "AS IS" BASIS, */ +/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ +/* See the License for the specific language governing permissions and */ +/* limitations under the License. */ +/* -------------------------------------------------------------------------- */ + +define(function(require) { + return 'revertVMDialog'; +}); diff --git a/src/sunstone/public/app/tabs/vms-tab/dialogs/revert/html.hbs b/src/sunstone/public/app/tabs/vms-tab/dialogs/revert/html.hbs new file mode 100644 index 0000000000..1aa1649b9c --- /dev/null +++ b/src/sunstone/public/app/tabs/vms-tab/dialogs/revert/html.hbs @@ -0,0 +1,40 @@ +{{! -------------------------------------------------------------------------- }} +{{! Copyright 2002-2016, OpenNebula Project, OpenNebula Systems }} +{{! }} +{{! Licensed under the Apache License, Version 2.0 (the "License"); you may }} +{{! not use this file except in compliance with the License. You may obtain }} +{{! a copy of the License at }} +{{! }} +{{! http://www.apache.org/licenses/LICENSE-2.0 }} +{{! }} +{{! Unless required by applicable law or agreed to in writing, software }} +{{! distributed under the License is distributed on an "AS IS" BASIS, }} +{{! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. }} +{{! See the License for the specific language governing permissions and }} +{{! limitations under the License. }} +{{! -------------------------------------------------------------------------- }} + +
+
+

+ {{tr "Revert"}} +

+
+
+
+
+
+
{{tr "You have to confirm this action."}}
+
+
{{tr "Do you want to proceed?"}}
+
+
+
+ +
+ +
+
+
diff --git a/src/sunstone/public/app/tabs/vms-tab/panels/snapshots.js b/src/sunstone/public/app/tabs/vms-tab/panels/snapshots.js index 369dea7c9f..ba6d083e11 100644 --- a/src/sunstone/public/app/tabs/vms-tab/panels/snapshots.js +++ b/src/sunstone/public/app/tabs/vms-tab/panels/snapshots.js @@ -34,6 +34,7 @@ define(function(require) { var TAB_ID = require('../tabId'); var PANEL_ID = require('./snapshots/panelId'); var SNAPSHOT_DIALOG_ID = require('../dialogs/snapshot/dialogId'); + var REVERT_DIALOG_ID = require('../dialogs/revert/dialogId'); var RESOURCE = "VM" var XML_ROOT = "VM" @@ -165,8 +166,9 @@ define(function(require) { 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}); + var dialog = Sunstone.getDialog(REVERT_DIALOG_ID); + dialog.setElement(that.element); + dialog.show(); return false; }); }