diff --git a/src/sunstone/public/app/tabs/oneflow-templates-tab.js b/src/sunstone/public/app/tabs/oneflow-templates-tab.js index b59f418a1f..229012b76c 100644 --- a/src/sunstone/public/app/tabs/oneflow-templates-tab.js +++ b/src/sunstone/public/app/tabs/oneflow-templates-tab.js @@ -18,7 +18,8 @@ define(function(require) { ]; var _formPanels = [ - require('./oneflow-templates-tab/form-panels/create') + require('./oneflow-templates-tab/form-panels/create'), + require('./oneflow-templates-tab/form-panels/instantiate') ]; var Tab = { diff --git a/src/sunstone/public/app/tabs/oneflow-templates-tab/actions.js b/src/sunstone/public/app/tabs/oneflow-templates-tab/actions.js index b9c99b83e3..4ab46aec67 100644 --- a/src/sunstone/public/app/tabs/oneflow-templates-tab/actions.js +++ b/src/sunstone/public/app/tabs/oneflow-templates-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 INSTANTIATE_DIALOG_ID = require('./dialogs/instantiate/dialogId'); + var INSTANTIATE_DIALOG_ID = require('./form-panels/instantiate/formPanelId'); var XML_ROOT = "DOCUMENT"; var RESOURCE = "ServiceTemplate"; @@ -93,26 +93,39 @@ define(function(require) { } }, - /* TODO - "ServiceTemplate.instantiate" : { - type: "multiple", - call: OpenNebula.ServiceTemplate.instantiate, - callback: function(req){ - OpenNebula.Helper.clear_cache("SERVICE"); - }, - elements: serviceTemplateElements, - error: onError, - notify: true + type: "multiple", + call: OpenNebulaResource.instantiate, + callback: function(request, response){ + Sunstone.hideFormPanel(TAB_ID); + + // TODO + //OpenNebulaHelper.clear_cache("SERVICE"); + }, + elements: function() { + return Sunstone.getDataTable(TAB_ID).elements(); + }, + error: function(request, response){ + Sunstone.hideFormPanelLoading(TAB_ID); + Notifier.onError(request, response); + }, + notify: true }, "ServiceTemplate.instantiate_dialog" : { - type: "custom", - call: function(){ - popUpInstantiateServiceTemplateDialog(); + type: "custom", + call: function() { + var selected_nodes = Sunstone.getDataTable(TAB_ID).elements(); + if (selected_nodes.length != 1) { + Notifier.notifyMessage("Please select one (and just one) template to instantiate."); + return false; } + + Sunstone.resetFormPanel(TAB_ID, INSTANTIATE_DIALOG_ID); + Sunstone.showFormPanel(TAB_ID, INSTANTIATE_DIALOG_ID, "instantiate"); + } }, - */ + }; return _actions; diff --git a/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/instantiate.js b/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/instantiate.js new file mode 100644 index 0000000000..e43726aba3 --- /dev/null +++ b/src/sunstone/public/app/tabs/oneflow-templates-tab/form-panels/instantiate.js @@ -0,0 +1,232 @@ +define(function(require) { + /* + DEPENDENCIES + */ + + require('foundation.tab'); + var BaseFormPanel = require('utils/form-panels/form-panel'); + var Sunstone = require('sunstone'); + var Locale = require('utils/locale'); + var Tips = require('utils/tips'); + var OpenNebulaServiceTemplate = require('opennebula/servicetemplate'); + var OpenNebulaTemplate = require('opennebula/template'); + var Notifier = require('utils/notifier'); + var WizardFields = require('utils/wizard-fields'); + var TemplateUtils = require('utils/template-utils'); + var UserInputs = require('utils/user-inputs'); + + /* + TEMPLATES + */ + + var TemplateHTML = require('hbs!./instantiate/html'); + + /* + CONSTANTS + */ + + var FORM_PANEL_ID = require('./instantiate/formPanelId'); + var TAB_ID = require('../tabId'); + + /* + CONSTRUCTOR + */ + + function FormPanel() { + this.formPanelId = FORM_PANEL_ID; + this.tabId = TAB_ID; + this.actions = { + 'instantiate': { + 'title': Locale.tr("Instantiate Service Template"), + 'buttonText': Locale.tr("Instantiate"), + 'resetButton': false + } + }; + + BaseFormPanel.call(this); + } + + FormPanel.FORM_PANEL_ID = FORM_PANEL_ID; + FormPanel.prototype = Object.create(BaseFormPanel.prototype); + FormPanel.prototype.constructor = FormPanel; + FormPanel.prototype.htmlWizard = _html; + FormPanel.prototype.submitWizard = _submitWizard; + FormPanel.prototype.onShow = _onShow; + FormPanel.prototype.fill = _fill; + FormPanel.prototype.setup = _setup; + + return FormPanel; + + /* + FUNCTION DEFINITIONS + */ + + function _html() { + return TemplateHTML({ + 'formPanelId': this.formPanelId + }); + } + + function _setup(context) { + var that = this; + + Tips.setup(context); + return false; + } + + function _onShow(context) { + var that = this; + + Sunstone.disableFormPanelSubmit(TAB_ID); + + var selected_nodes = Sunstone.getDataTable(TAB_ID).elements(); + var template_id = ""+selected_nodes[0]; + + this.service_template_json = {}; + + OpenNebulaServiceTemplate.show({ + data : { + id: template_id + }, + timeout: true, + success: function (request, template_json){ + + that.service_template_json = template_json; + + $("#instantiate_service_user_inputs", context).empty(); + + UserInputs.serviceTemplateInsert( + $("#instantiate_service_user_inputs", context), + template_json); + + n_roles = template_json.DOCUMENT.TEMPLATE.BODY.roles.length; + n_roles_done = 0; + + $.each(template_json.DOCUMENT.TEMPLATE.BODY.roles, function(index, role){ + var div_id = "user_input_role_"+index; + + $("#instantiate_service_role_user_inputs", context).append( + '