diff --git a/src/sunstone/public/app/tabs/vms-tab.js b/src/sunstone/public/app/tabs/vms-tab.js index e09dd667a0..733a1ac067 100644 --- a/src/sunstone/public/app/tabs/vms-tab.js +++ b/src/sunstone/public/app/tabs/vms-tab.js @@ -7,10 +7,10 @@ define(function(require) { var TAB_ID = require('./vms-tab/tabId'); var DATATABLE_ID = "dataTableVms"; - //var _dialogs = [ - // require('./vms-tab/dialogs/clone'), + var _dialogs = [ + require('./vms-tab/dialogs/deploy'), // require('./vms-tab/dialogs/instantiate') - //]; + ]; var _panels = [ require('./vms-tab/panels/info'), @@ -39,7 +39,7 @@ define(function(require) { dataTable: new Table(DATATABLE_ID, {actions: true, info: true}), panels: _panels, formPanels: _formPanels, - //dialogs: _dialogs + dialogs: _dialogs }; return Tab; diff --git a/src/sunstone/public/app/tabs/vms-tab/actions.js b/src/sunstone/public/app/tabs/vms-tab/actions.js index a12f9d3503..ccdd40ef3e 100644 --- a/src/sunstone/public/app/tabs/vms-tab/actions.js +++ b/src/sunstone/public/app/tabs/vms-tab/actions.js @@ -7,7 +7,7 @@ define(function(require) { var TAB_ID = require('./tabId'); var CREATE_DIALOG_ID = require('./form-panels/create/formPanelId'); - //var CLONE_DIALOG_ID = require('./dialogs/clone/dialogId'); + var DEPLOY_DIALOG_ID = require('./dialogs/deploy/dialogId'); //var INSTANTIATE_DIALOG_ID = require('./dialogs/instantiate/dialogId'); var XML_ROOT = "VM"; var RESOURCE = "VM"; @@ -62,6 +62,12 @@ define(function(require) { Sunstone.showFormPanel(TAB_ID, CREATE_DIALOG_ID, "create"); } }, + "VM.deploy" : { + type: "custom", + call: function(){ + Sunstone.getDialog(DEPLOY_DIALOG_ID).show(); + } + }, /*"VM.create" : { type: "custom", call: function(id, name) { diff --git a/src/sunstone/public/app/tabs/vms-tab/dialogs/deploy.js b/src/sunstone/public/app/tabs/vms-tab/dialogs/deploy.js new file mode 100644 index 0000000000..e0a015c298 --- /dev/null +++ b/src/sunstone/public/app/tabs/vms-tab/dialogs/deploy.js @@ -0,0 +1,99 @@ +define(function(require) { + /* + DEPENDENCIES + */ + + var BaseDialog = require('utils/dialogs/dialog'); + var TemplateHTML = require('hbs!./deploy/html'); + var Sunstone = require('sunstone'); + var DatastoresTable = require('tabs/datastores-tab/datatable'); + var HostsTable = require('tabs/hosts-tab/datatable'); + var Notifier = require('utils/notifier'); + var Tips = require('utils/tips'); + + /* + CONSTANTS + */ + + var DIALOG_ID = require('./deploy/dialogId'); + var TAB_ID = require('../tabId') + + /* + CONSTRUCTOR + */ + + function Dialog() { + this.dialogId = DIALOG_ID; + + this.hostsTable = new HostsTable('deploy_vm', {'select': true}); + this.datastoresTable = new DatastoresTable('deploy_vm_ds', { + 'select': true, + 'selectOptions': { + 'filter_fn': function(ds) { return ds.TYPE == 1; } // Show system DS only + } + }); + + 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; + + return Dialog; + + /* + FUNCTION DEFINITIONS + */ + + function _html() { + return TemplateHTML({ + 'dialogId': this.dialogId, + 'hostsTableHTML': this.hostsTable.dataTableHTML, + 'datastoresTableHTML': this.datastoresTable.dataTableHTML + }); + } + + function _setup(context) { + var that = this; + + that.hostsTable.initialize(); + that.datastoresTable.initialize(); + + Tips.setup(context); + + $('#' + DIALOG_ID + 'Form', context).submit(function() { + var extra_info = {}; + + if ($("#selected_resource_id_deploy_vm", context).val()) { + extra_info['host_id'] = $("#selected_resource_id_deploy_vm", context).val(); + } else { + Notifier.notifyError(tr("You have not selected a host")); + return false; + } + + extra_info['ds_id'] = $("#selected_resource_id_deploy_vm_ds", context).val() || -1 + extra_info['enforce'] = $("#enforce", this).is(":checked") ? true : false + + $.each(Sunstone.getDataTable(TAB_ID).elements(), function(index, elem) { + Sunstone.runAction("VM.deploy_action", elem, extra_info); + }); + + Sunstone.getDialog(DIALOG_ID).hide(); + Sunstone.getDialog(DIALOG_ID).reset(); + return false; + }); + + return false; + } + + function _onShow(dialog) { + this.datastoresTable.resetResourceTableSelect(); + this.hostsTable.resetResourceTableSelect(); + + return false; + } +}); diff --git a/src/sunstone/public/app/tabs/vms-tab/dialogs/deploy/dialogId.js b/src/sunstone/public/app/tabs/vms-tab/dialogs/deploy/dialogId.js new file mode 100644 index 0000000000..a9ebbb6c01 --- /dev/null +++ b/src/sunstone/public/app/tabs/vms-tab/dialogs/deploy/dialogId.js @@ -0,0 +1,3 @@ +define(function(require){ + return 'deployVMDialog'; +}) \ No newline at end of file diff --git a/src/sunstone/public/app/tabs/vms-tab/dialogs/deploy/html.hbs b/src/sunstone/public/app/tabs/vms-tab/dialogs/deploy/html.hbs new file mode 100644 index 0000000000..4a16c60e1d --- /dev/null +++ b/src/sunstone/public/app/tabs/vms-tab/dialogs/deploy/html.hbs @@ -0,0 +1,41 @@ +