diff --git a/src/sunstone/public/app/tabs/templates-tab.js b/src/sunstone/public/app/tabs/templates-tab.js index 38e0c49f81..08f60302a7 100644 --- a/src/sunstone/public/app/tabs/templates-tab.js +++ b/src/sunstone/public/app/tabs/templates-tab.js @@ -7,9 +7,9 @@ define(function(require) { var TAB_ID = require('./templates-tab/tabId'); var DATATABLE_ID = "dataTableTemplates"; - //var _dialogs = [ - // require('./templates-tab/dialogs/create') - //]; + var _dialogs = [ + require('./templates-tab/dialogs/clone') + ]; var _panels = [ require('./templates-tab/panels/info'), @@ -34,7 +34,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/templates-tab/actions.js b/src/sunstone/public/app/tabs/templates-tab/actions.js index ad3959af09..dfdf8ec369 100644 --- a/src/sunstone/public/app/tabs/templates-tab/actions.js +++ b/src/sunstone/public/app/tabs/templates-tab/actions.js @@ -7,6 +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 XML_ROOT = "VMTEMPLATE" var _actions = { @@ -153,7 +154,9 @@ define(function(require) { }, "Template.clone_dialog" : { type: "custom", - // TODO call: popUpTemplateCloneDialog + call: function(){ + Sunstone.getDialog(CLONE_DIALOG_ID).show(); + } }, "Template.clone" : { type: "single", diff --git a/src/sunstone/public/app/tabs/templates-tab/dialogs/clone.js b/src/sunstone/public/app/tabs/templates-tab/dialogs/clone.js new file mode 100644 index 0000000000..4646fb1c04 --- /dev/null +++ b/src/sunstone/public/app/tabs/templates-tab/dialogs/clone.js @@ -0,0 +1,98 @@ +define(function(require) { + /* + DEPENDENCIES + */ + + var BaseDialog = require('utils/dialogs/dialog'); + var TemplateHTML = require('hbs!./clone/html'); + var Sunstone = require('sunstone'); + var Notifier = require('utils/notifier'); + + /* + CONSTANTS + */ + + var DIALOG_ID = require('./clone/dialogId'); + var TEMPLATES_TAB_ID = require('tabs/templates-tab/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; + + return Dialog; + + /* + FUNCTION DEFINITIONS + */ + + function _html() { + return TemplateHTML({ + 'dialogId': this.dialogId + }); + } + + function _setup(context) { + var that = this; + + $('#' + DIALOG_ID + 'Form', context).submit(function() { + var extra_info; + var name = $('input[name="name"]', this).val(); + var sel_elems = Sunstone.getDataTable(TEMPLATES_TAB_ID).elements(); + + if (!name || !sel_elems.length) + Notifier.notifyError('A name or prefix is needed!'); + + if (sel_elems.length > 1) { + for (var i = 0; i < sel_elems.length; i++) { + //If we are cloning several images we + //use the name as prefix + extra_info = name + Sunstone.getDataTable(TEMPLATES_TAB_ID).getName(sel_elems[i]); + Sunstone.runAction('Template.clone', sel_elems[i], extra_info); + } + } else { + extra_info = name; + Sunstone.runAction('Template.clone', sel_elems[0], extra_info) + } + + Sunstone.getDialog(DIALOG_ID).hide(); + Sunstone.getDialog(DIALOG_ID).reset(); + setTimeout(function() { + Sunstone.runAction('Template.refresh'); + }, 1500); + return false; + }); + + return false; + } + + function _onShow(context) { + var sel_elems = Sunstone.getDataTable(TEMPLATES_TAB_ID).elements(); + //show different text depending on how many elements are selected + if (sel_elems.length > 1) { + $('.clone_one', context).hide(); + $('.clone_several', context).show(); + $('input[name="name"]',context).val('Copy of '); + } else { + $('.clone_one', context).show(); + $('.clone_several', context).hide(); + $('input[name="name"]', context).val('Copy of ' + Sunstone.getDataTable(TEMPLATES_TAB_ID).getName(sel_elems[0])); + }; + + $("input[name='name']", context).focus(); + + return false; + } +}); diff --git a/src/sunstone/public/app/tabs/templates-tab/dialogs/clone/dialogId.js b/src/sunstone/public/app/tabs/templates-tab/dialogs/clone/dialogId.js new file mode 100644 index 0000000000..d9d4d1d106 --- /dev/null +++ b/src/sunstone/public/app/tabs/templates-tab/dialogs/clone/dialogId.js @@ -0,0 +1,3 @@ +define(function(require){ + return 'cloneTemplateDialog'; +}) \ No newline at end of file diff --git a/src/sunstone/public/app/tabs/templates-tab/dialogs/clone/html.hbs b/src/sunstone/public/app/tabs/templates-tab/dialogs/clone/html.hbs new file mode 100644 index 0000000000..ff2c5ca635 --- /dev/null +++ b/src/sunstone/public/app/tabs/templates-tab/dialogs/clone/html.hbs @@ -0,0 +1,26 @@ + \ No newline at end of file