diff --git a/src/sunstone/public/app/tabs/hosts-tab/form-panels/create.js b/src/sunstone/public/app/tabs/hosts-tab/form-panels/create.js
index 98cf0ed0b9..d5c0b01c0f 100644
--- a/src/sunstone/public/app/tabs/hosts-tab/form-panels/create.js
+++ b/src/sunstone/public/app/tabs/hosts-tab/form-panels/create.js
@@ -11,8 +11,8 @@ define(function(require) {
var ResourceSelect = require('utils/resource-select');
var OpenNebulaError = require('opennebula/error');
var OpenNebulaHost = require('opennebula/host');
- var OpenNebulaTemplate = require('opennebula/template');
var OpenNebulaVM = require('opennebula/vm');
+ var VCenterTemplates = require('utils/vcenter/templates');
var VCenterNetworks = require('utils/vcenter/networks');
/*
@@ -44,6 +44,7 @@ define(function(require) {
}
this.vCenterNetworks = new VCenterNetworks();
+ this.vCenterTemplates = new VCenterTemplates();
BaseFormPanel.call(this);
};
@@ -65,7 +66,8 @@ define(function(require) {
function _htmlWizard() {
return TemplateWizardHTML({
'formPanelId': this.formPanelId,
- 'vcenterNetworksHTML': this.vCenterNetworks.html()
+ 'vCenterTemplatesHTML': this.vCenterTemplates.html(),
+ 'vCenterNetworksHTML': this.vCenterNetworks.html()
});
}
@@ -174,19 +176,18 @@ define(function(require) {
}
});
- var templates_container = $(".vcenter_templates", context);
var vms_container = $(".vcenter_vms", context);
var vcenter_user = $("#vcenter_user", context).val();
var vcenter_password = $("#vcenter_password", context).val();
var vcenter_host = $("#vcenter_host", context).val();
- fillVCenterTemplates({
- container: templates_container,
- vcenter_user: vcenter_user,
- vcenter_password: vcenter_password,
- vcenter_host: vcenter_host
- });
+ that.vCenterTemplates.insert({
+ container: context,
+ vcenter_user: vcenter_user,
+ vcenter_password: vcenter_password,
+ vcenter_host: vcenter_host
+ });
that.vCenterNetworks.insert({
container: context,
@@ -262,48 +263,6 @@ define(function(require) {
});
});
- $.each($(".template_name:checked", context), function() {
- var template_context = $(this).closest(".vcenter_template");
-
- $(".vcenter_template_result:not(.success)", template_context).html(
- '' +
- '' +
- '' +
- '');
-
- var template_json = {
- "vmtemplate": {
- "template_raw": $(this).data("one_template")
- }
- };
-
- OpenNebulaTemplate.create({
- timeout: true,
- data: template_json,
- success: function(request, response) {
- $(".vcenter_template_result", template_context).addClass("success").html(
- '' +
- '' +
- '' +
- '');
-
- $(".vcenter_template_response", template_context).html('
' +
- Locale.tr("Template created successfully") + ' ID:' + response.VMTEMPLATE.ID +
- '
');
- },
- error: function (request, error_json) {
- $(".vcenter_template_result", template_context).html('' +
- (error_json.error.message || Locale.tr("Cannot contact server: is it running and reachable?")) +
- '
');
- }
- });
- });
-
$.each($(".vm_name:checked", context), function() {
var vm_context = $(this).closest(".vcenter_vm");
@@ -356,6 +315,8 @@ define(function(require) {
});
});
+ that.vCenterTemplates.import();
+
that.vCenterNetworks.import();
return false;
@@ -442,91 +403,4 @@ define(function(require) {
ResourceSelect.insert('#host_cluster_id', context, "Cluster", cluster_id, false);
return false;
}
-
- /*
- Retrieve the list of templates from vCenter and fill the container with them
-
- opts = {
- datacenter: "Datacenter Name",
- cluster: "Cluster Name",
- container: Jquery div to inject the html,
- vcenter_user: vCenter Username,
- vcenter_password: vCenter Password,
- vcenter_host: vCenter Host
- }
- */
- function fillVCenterTemplates(opts) {
- var path = '/vcenter/templates';
-
- opts.container.show();
-
- $(".accordion_advanced_toggle", opts.container).trigger("click");
-
- $.ajax({
- url: path,
- type: "GET",
- data: {timeout: false},
- dataType: "json",
- headers: {
- "X_VCENTER_USER": opts.vcenter_user,
- "X_VCENTER_PASSWORD": opts.vcenter_password,
- "X_VCENTER_HOST": opts.vcenter_host
- },
- success: function(response){
- $(".content", opts.container).html("");
-
- $('
- {{#advancedSection (tr "Templates") }}
-
-
-
-
- {{/advancedSection}}
+
+ {{{vCenterTemplatesHTML}}}
- {{{vcenterNetworksHTML}}}
+ {{{vCenterNetworksHTML}}}
diff --git a/src/sunstone/public/app/tabs/templates-tab.js b/src/sunstone/public/app/tabs/templates-tab.js
index 7f536c81df..4008ea309e 100644
--- a/src/sunstone/public/app/tabs/templates-tab.js
+++ b/src/sunstone/public/app/tabs/templates-tab.js
@@ -18,7 +18,8 @@ define(function(require) {
];
var _formPanels = [
- require('./templates-tab/form-panels/create')
+ require('./templates-tab/form-panels/create'),
+ require('./templates-tab/form-panels/import')
]
var Tab = {
diff --git a/src/sunstone/public/app/tabs/templates-tab/actions.js b/src/sunstone/public/app/tabs/templates-tab/actions.js
index ce52e6e8b2..5ff31f1d94 100644
--- a/src/sunstone/public/app/tabs/templates-tab/actions.js
+++ b/src/sunstone/public/app/tabs/templates-tab/actions.js
@@ -10,6 +10,8 @@ define(function(require) {
var CREATE_DIALOG_ID = require('./form-panels/create/formPanelId');
var CLONE_DIALOG_ID = require('./dialogs/clone/dialogId');
var INSTANTIATE_DIALOG_ID = require('./dialogs/instantiate/dialogId');
+ var IMPORT_DIALOG_ID = require('./form-panels/import/formPanelId');
+
var XML_ROOT = "VMTEMPLATE"
var RESOURCE = "Template"
@@ -41,10 +43,10 @@ define(function(require) {
}
},
"Template.import_dialog" : {
- type: "create",
+ type: "custom",
call: function() {
- // TODO popUpTemplateImportDialog();
- }
+ Sunstone.showFormPanel(TAB_ID, IMPORT_DIALOG_ID, "import");
+ }
},
"Template.update_dialog" : {
type: "custom",
diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/import.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/import.js
new file mode 100644
index 0000000000..8047a4d930
--- /dev/null
+++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/import.js
@@ -0,0 +1,104 @@
+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 VCenterTemplates = require('utils/vcenter/templates');
+
+ /*
+ TEMPLATES
+ */
+
+ var TemplateHTML = require('hbs!./import/html');
+
+ /*
+ CONSTANTS
+ */
+
+ var FORM_PANEL_ID = require('./import/formPanelId');
+ var TAB_ID = require('../tabId');
+
+ /*
+ CONSTRUCTOR
+ */
+
+ function FormPanel() {
+ this.formPanelId = FORM_PANEL_ID;
+ this.tabId = TAB_ID;
+ this.actions = {
+ 'import': {
+ 'title': Locale.tr("Import vCenter VM Templates"),
+ 'buttonText': Locale.tr("Import"),
+ 'resetButton': true
+ }
+ };
+
+ this.vCenterTemplates = new VCenterTemplates();
+
+ 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.submitWizard = _submitWizard;
+ FormPanel.prototype.onShow = _onShow;
+ FormPanel.prototype.setup = _setup;
+
+ return FormPanel;
+
+ /*
+ FUNCTION DEFINITIONS
+ */
+
+ function _htmlWizard() {
+ return TemplateHTML({
+ 'formPanelId': this.formPanelId,
+ 'vCenterTemplatesHTML': this.vCenterTemplates.html()
+ });
+ }
+
+ function _setup(context) {
+ var that = this;
+
+ Sunstone.disableFormPanelSubmit(TAB_ID);
+
+ $("#get_vcenter_templates", context).on("click", function(){
+ Sunstone.enableFormPanelSubmit(TAB_ID);
+
+ var vcenter_user = $("#vcenter_user", context).val();
+ var vcenter_password = $("#vcenter_password", context).val();
+ var vcenter_host = $("#vcenter_host", context).val();
+
+ that.vCenterTemplates.insert({
+ container: context,
+ vcenter_user: vcenter_user,
+ vcenter_password: vcenter_password,
+ vcenter_host: vcenter_host
+ });
+
+ return false;
+ });
+
+ return false;
+ }
+
+ function _submitWizard(context) {
+ var that = this;
+
+ Sunstone.hideFormPanelLoading(TAB_ID);
+ Sunstone.disableFormPanelSubmit(TAB_ID);
+
+ this.vCenterTemplates.import();
+
+ return false;
+ }
+
+ function _onShow(context) {
+ }
+});
diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/import/formPanelId.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/import/formPanelId.js
new file mode 100644
index 0000000000..804a218b65
--- /dev/null
+++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/import/formPanelId.js
@@ -0,0 +1,3 @@
+define(function(require){
+ return 'importTemplateForm';
+});
\ No newline at end of file
diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/import/html.hbs b/src/sunstone/public/app/tabs/templates-tab/form-panels/import/html.hbs
new file mode 100644
index 0000000000..240ad3f776
--- /dev/null
+++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/import/html.hbs
@@ -0,0 +1,29 @@
+
\ No newline at end of file
diff --git a/src/sunstone/public/app/tabs/vnets-tab/form-panels/import.js b/src/sunstone/public/app/tabs/vnets-tab/form-panels/import.js
index 79bc71d47f..89b159f613 100644
--- a/src/sunstone/public/app/tabs/vnets-tab/form-panels/import.js
+++ b/src/sunstone/public/app/tabs/vnets-tab/form-panels/import.js
@@ -59,7 +59,7 @@ define(function(require) {
function _htmlWizard() {
return TemplateHTML({
'formPanelId': this.formPanelId,
- 'vcenterNetworksHTML': this.vCenterNetworks.html()
+ 'vCenterNetworksHTML': this.vCenterNetworks.html()
});
}
diff --git a/src/sunstone/public/app/tabs/vnets-tab/form-panels/import/advanced.hbs b/src/sunstone/public/app/tabs/vnets-tab/form-panels/import/advanced.hbs
deleted file mode 100644
index 451477cf0b..0000000000
--- a/src/sunstone/public/app/tabs/vnets-tab/form-panels/import/advanced.hbs
+++ /dev/null
@@ -1,12 +0,0 @@
-
\ No newline at end of file
diff --git a/src/sunstone/public/app/tabs/vnets-tab/form-panels/import/html.hbs b/src/sunstone/public/app/tabs/vnets-tab/form-panels/import/html.hbs
index b39c57a89f..5c4bc9a00c 100644
--- a/src/sunstone/public/app/tabs/vnets-tab/form-panels/import/html.hbs
+++ b/src/sunstone/public/app/tabs/vnets-tab/form-panels/import/html.hbs
@@ -24,6 +24,6 @@
- {{{vcenterNetworksHTML}}}
+ {{{vCenterNetworksHTML}}}
\ No newline at end of file
diff --git a/src/sunstone/public/app/utils/vcenter/templates.js b/src/sunstone/public/app/utils/vcenter/templates.js
new file mode 100644
index 0000000000..7edf87ece6
--- /dev/null
+++ b/src/sunstone/public/app/utils/vcenter/templates.js
@@ -0,0 +1,158 @@
+define(function(require) {
+ // Dependencies
+ var Locale = require('utils/locale');
+ var OpenNebulaTemplate = require('opennebula/template');
+ var OpenNebulaError = require('opennebula/error');
+
+ var TemplateHTML = require('hbs!./templates/html');
+
+ function VCenterTemplates() {
+ return this;
+ }
+
+ VCenterTemplates.prototype = {
+ 'html': _html,
+ 'insert': _fillVCenterTemplates,
+ 'import': _import
+ };
+ VCenterTemplates.prototype.constructor = VCenterTemplates;
+
+ return VCenterTemplates;
+
+ function _html() {
+ return '
';
+ }
+
+ /*
+ Retrieve the list of templates from vCenter and fill the container with them
+
+ opts = {
+ datacenter: "Datacenter Name",
+ cluster: "Cluster Name",
+ container: Jquery div to inject the html,
+ vcenter_user: vCenter Username,
+ vcenter_password: vCenter Password,
+ vcenter_host: vCenter Host
+ }
+ */
+ function _fillVCenterTemplates(opts) {
+ var path = '/vcenter/templates';
+
+ var context = $(".vcenter_templates", opts.container);
+
+ context.html( TemplateHTML({}) );
+
+ context.show();
+
+ $(".accordion_advanced_toggle", context).trigger("click");
+
+ $.ajax({
+ url: path,
+ type: "GET",
+ data: {timeout: false},
+ dataType: "json",
+ headers: {
+ "X_VCENTER_USER": opts.vcenter_user,
+ "X_VCENTER_PASSWORD": opts.vcenter_password,
+ "X_VCENTER_HOST": opts.vcenter_host
+ },
+ success: function(response){
+ $(".content", context).html("");
+
+ $('
' +
+ '
' +
+ '
' + Locale.tr("Please select the vCenter Templates to be imported to OpenNebula.") + '
' +
+ '
' +
+ '
').appendTo($(".content", context))
+
+ $.each(response, function(datacenter_name, templates){
+ $('
' +
+ '
' +
+ '
' +
+ datacenter_name + ' ' + Locale.tr("DataCenter") +
+ '
' +
+ '' +
+ '
').appendTo($(".content", context))
+
+ if (templates.length == 0) {
+ $('
' +
+ '
' +
+ '' +
+ '
' +
+ '
').appendTo($(".content", context))
+ } else {
+ $.each(templates, function(id, template){
+ var trow = $('
' +
+ '
' +
+ '
' +
+ '
' +
+ '
'+
+ '
'+
+ '
' +
+ '
'+
+ '
'+
+ '
'+
+ '
').appendTo($(".content", context))
+
+ $(".template_name", trow).data("template_name", template.name)
+ $(".template_name", trow).data("one_template", template.one)
+ });
+ };
+ });
+ },
+ error: function(response){
+ context.hide();
+ Notifier.onError({}, OpenNebulaError(response));
+ }
+ });
+ }
+
+ function _import(context) {
+ $.each($(".template_name:checked", context), function() {
+ var template_context = $(this).closest(".vcenter_template");
+
+ $(".vcenter_template_result:not(.success)", template_context).html(
+ '
' +
+ '' +
+ '' +
+ '');
+
+ var template_json = {
+ "vmtemplate": {
+ "template_raw": $(this).data("one_template")
+ }
+ };
+
+ OpenNebulaTemplate.create({
+ timeout: true,
+ data: template_json,
+ success: function(request, response) {
+ $(".vcenter_template_result", template_context).addClass("success").html(
+ '
' +
+ '' +
+ '' +
+ '');
+
+ $(".vcenter_template_response", template_context).html('
' +
+ Locale.tr("Template created successfully") + ' ID:' + response.VMTEMPLATE.ID +
+ '
');
+ },
+ error: function (request, error_json) {
+ $(".vcenter_template_result", template_context).html('
' +
+ '' +
+ '' +
+ '');
+
+ $(".vcenter_template_response", template_context).html('
' +
+ (error_json.error.message || Locale.tr("Cannot contact server: is it running and reachable?")) +
+ '
');
+ }
+ });
+ });
+ }
+});
\ No newline at end of file
diff --git a/src/sunstone/public/app/utils/vcenter/templates/html.hbs b/src/sunstone/public/app/utils/vcenter/templates/html.hbs
new file mode 100644
index 0000000000..1e14e7707d
--- /dev/null
+++ b/src/sunstone/public/app/utils/vcenter/templates/html.hbs
@@ -0,0 +1,6 @@
+{{#advancedSection (tr "Templates") }}
+
+
+
+
+{{/advancedSection}}