From 7f8a1fa910a09fa188cdd7131d75c736aec80a5a Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Wed, 27 May 2015 11:11:40 +0200 Subject: [PATCH] feature #3748: Add template creation form --- src/sunstone/public/app/tabs/templates-tab.js | 6 +- .../public/app/tabs/templates-tab/actions.js | 12 +- .../tabs/templates-tab/form-panels/create.js | 118 ++++++++++++++++++ .../form-panels/create/advanced.hbs | 12 ++ .../form-panels/create/formPanelId.js | 3 + .../form-panels/create/wizard.hbs | 19 +++ 6 files changed, 161 insertions(+), 9 deletions(-) create mode 100644 src/sunstone/public/app/tabs/templates-tab/form-panels/create.js create mode 100644 src/sunstone/public/app/tabs/templates-tab/form-panels/create/advanced.hbs create mode 100644 src/sunstone/public/app/tabs/templates-tab/form-panels/create/formPanelId.js create mode 100644 src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard.hbs diff --git a/src/sunstone/public/app/tabs/templates-tab.js b/src/sunstone/public/app/tabs/templates-tab.js index 42c37594c2..38e0c49f81 100644 --- a/src/sunstone/public/app/tabs/templates-tab.js +++ b/src/sunstone/public/app/tabs/templates-tab.js @@ -16,9 +16,9 @@ define(function(require) { require('./templates-tab/panels/template') ]; - /*var _formPanels = [ + var _formPanels = [ require('./templates-tab/form-panels/create') - ]*/ + ] var Tab = { tabId: TAB_ID, @@ -33,7 +33,7 @@ define(function(require) { actions: Actions, dataTable: new Table(DATATABLE_ID, {actions: true, info: true}), panels: _panels, - //formPanels: _formPanels, + formPanels: _formPanels, //dialogs: _dialogs }; diff --git a/src/sunstone/public/app/tabs/templates-tab/actions.js b/src/sunstone/public/app/tabs/templates-tab/actions.js index b50023b8cb..b17c8556d3 100644 --- a/src/sunstone/public/app/tabs/templates-tab/actions.js +++ b/src/sunstone/public/app/tabs/templates-tab/actions.js @@ -6,19 +6,19 @@ define(function(require) { var OpenNebulaTemplate = require('opennebula/template'); var TAB_ID = require('./tabId'); - // TODO var CREATE_DIALOG_ID = require('./form-panels/create/formPanelId'); + var CREATE_DIALOG_ID = require('./form-panels/create/formPanelId'); var _actions = { "Template.create" : { type: "create", call: OpenNebulaTemplate.create, callback: function(request, response) { - // TODO Sunstone.resetFormPanel(TAB_ID, CREATE_DIALOG_ID); - // TODO Sunstone.hideFormPanel(TAB_ID); - // TODO Sunstone.getDataTable(TAB_ID).addElement(request, response); + Sunstone.resetFormPanel(TAB_ID, CREATE_DIALOG_ID); + Sunstone.hideFormPanel(TAB_ID); + Sunstone.getDataTable(TAB_ID).addElement(request, response); }, error: function(request, response) { - // TODO Sunstone.hideFormPanelLoading(TAB_ID); + Sunstone.hideFormPanelLoading(TAB_ID); Notifier.onError(request, response); }, notify: true @@ -26,7 +26,7 @@ define(function(require) { "Template.create_dialog" : { type: "custom", call: function() { - // TODO Sunstone.showFormPanel(TAB_ID, CREATE_DIALOG_ID, "create"); + Sunstone.showFormPanel(TAB_ID, CREATE_DIALOG_ID, "create"); } }, "Template.import_dialog" : { diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/create.js new file mode 100644 index 0000000000..2ba551e1b0 --- /dev/null +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create.js @@ -0,0 +1,118 @@ +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'); + + /* + TEMPLATES + */ + + var TemplateWizardHTML = require('hbs!./create/wizard'); + var TemplateAdvancedHTML = require('hbs!./create/advanced'); + + /* + CONSTANTS + */ + + var FORM_PANEL_ID = require('./create/formPanelId'); + var TAB_ID = require('../tabId'); + var WIZARD_TABS = [ + require('./create/wizard-tabs/general') + ] + + /* + CONSTRUCTOR + */ + + function FormPanel() { + this.formPanelId = FORM_PANEL_ID; + this.tabId = TAB_ID; + this.actions = { + 'create': { + 'title': Locale.tr("Create VM Template"), + 'buttonText': Locale.tr("Create"), + 'resetButton': true + }, + 'update': { + 'title': Locale.tr("Update VM Template"), + 'buttonText': Locale.tr("Update"), + 'resetButton': false + } + }; + + var that = this; + that.wizardTabs = []; + var wizardTabInstance; + $.each(WIZARD_TABS, function(index, wizardTab) { + try { + wizardTabInstance = new wizardTab(); + wizardTabInstance.contentHTML = wizardTabInstance.html(); + that.wizardTabs.push(wizardTabInstance); + } catch (err) { + console.log(err); + } + }) + + BaseFormPanel.call(this); + } + + FormPanel.FORM_PANEL_ID = FORM_PANEL_ID; + FormPanel.prototype = Object.create(BaseFormPanel.prototype); + FormPanel.prototype.constructor = FormPanel; + FormPanel.prototype.htmlWizard = _htmlWizard; + FormPanel.prototype.htmlAdvanced = _htmlAdvanced; + FormPanel.prototype.setup = _setup; + FormPanel.prototype.onShow = _onShow; + FormPanel.prototype.submitWizard = _submitWizard; + FormPanel.prototype.submitAdvanced = _submitAdvanced; + FormPanel.prototype.fill = _fill; + + return FormPanel; + + /* + FUNCTION DEFINITIONS + */ + + function _htmlWizard() { + + return TemplateWizardHTML({ + 'formPanelId': this.formPanelId, + 'wizardTabs': this.wizardTabs + }); + } + + function _htmlAdvanced() { + return TemplateAdvancedHTML({formPanelId: this.formPanelId}); + } + + function _setup(context) { + $.each(this.wizardTabs, function(index, wizardTab) { + wizardTab.setup(); + }); + + context.foundation('reflow', 'tab'); + Tips.setup(context); + } + + function _onShow() { + + } + + function _submitWizard() { + + } + + function _submitAdvanced() { + + } + + function _fill() { + + } +}); diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/advanced.hbs b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/advanced.hbs new file mode 100644 index 0000000000..1c7330a5f1 --- /dev/null +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/advanced.hbs @@ -0,0 +1,12 @@ +
+
+
+

{{tr "Write the Virtual Machine template here"}}

+
+
+
+
+ +
+
+
\ No newline at end of file diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/formPanelId.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/formPanelId.js new file mode 100644 index 0000000000..8eee27f298 --- /dev/null +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/formPanelId.js @@ -0,0 +1,3 @@ +define(function(require){ + return 'createVMTemplateForm'; +}) \ No newline at end of file diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard.hbs b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard.hbs new file mode 100644 index 0000000000..32fb5ff594 --- /dev/null +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard.hbs @@ -0,0 +1,19 @@ +
+
+
+ {{#each wizardTabs}} +
+ +
{{title}}
+
+ {{/each}} +
+
+ {{#each wizardTabs}} +
+ {{{contentHTML}}} +
+ {{/each}} +
+
+
\ No newline at end of file