diff --git a/src/sunstone/public/app/tabs/provision-tab.js b/src/sunstone/public/app/tabs/provision-tab.js index 60480b3ca7..01298994d2 100644 --- a/src/sunstone/public/app/tabs/provision-tab.js +++ b/src/sunstone/public/app/tabs/provision-tab.js @@ -37,273 +37,7 @@ define(function(require) { var TAB_ID = require('./provision-tab/tabId'); - var provision_user_info = ''; - var povision_actions = { - "Provision.User.show" : { - type: "single", - call: OpenNebula.User.show, - callback: show_provision_user_info_callback, - error: Notifier.onError - }, - - "Provision.User.passwd" : { - type: "single", - call: OpenNebula.User.passwd, - callback: function() { - show_provision_user_info(); - Notifier.notifyMessage("Password updated successfully"); - }, - error: Notifier.onError - }, - - "Provision.User.update_template" : { - type: "single", - call: OpenNebula.User.update, - callback: function() { - show_provision_user_info(); - Notifier.notifyMessage("SSH key updated successfully"); - }, - error: Notifier.onError - }, - "Provision.User.create" : { type: "create", call: OpenNebula.User.create, @@ -1267,49 +1001,6 @@ define(function(require) { } - function show_provision_user_info_callback(request, response) { - var info = response.USER; - - var default_user_quotas = QuotaDefaults.default_quotas(info.DEFAULT_USER_QUOTAS); - - var quotas_tab_html = QuotaWidgets.initQuotasPanel(info, default_user_quotas, - "#provision_user_info_quotas_div", false); - - $("#provision_user_info_quotas_div").html(quotas_tab_html); - - QuotaWidgets.setupQuotasPanel(info, - "#provision_user_info_quotas_div", - false, - "User"); - - var ssh_key = info.TEMPLATE.SSH_PUBLIC_KEY; - if (ssh_key && ssh_key.length) { - $("#provision_ssh_key").val(ssh_key); - $(".provision_add_ssh_key_button").hide(); - $(".provision_update_ssh_key_button").show(); - } else { - $(".provision_add_ssh_key_button").show(); - $(".provision_update_ssh_key_button").hide(); - } - - $('#provision_new_language option[value="'+config['user_config']["lang"]+'"]').attr('selected','selected'); - $('#provision_user_views_select option[value="'+config['user_config']["default_view"]+'"]').attr('selected','selected'); - - $("#provision_user_info_acct_div").html(Accounting.html()); - Accounting.setup( - $("#provision_user_info_acct_div"), - { fixed_user: info.ID, - fixed_group_by: "vm" }); - - - if (Config.isFeatureEnabled("showback")) { - $("#provision_user_info_showback_div").html(Showback.html()); - Showback.setup( - $("#provision_user_info_showback_div"), - { fixed_user: info.ID, fixed_group: ""}); - } - } - function show_provision_group_info_callback(request, response) { var info = response.GROUP; @@ -1551,10 +1242,6 @@ define(function(require) { return false; }); - $(".provision_image_header").on("click", function(){ - show_provision_dashboard(); - }) - ProvisionVmsList.generate($(".provision_vms_list_section"), {active: true}); if (Config.isTabPanelEnabled("provision-tab", "templates")) { @@ -1569,9 +1256,20 @@ define(function(require) { // Dashboard // + $(".provision_image_header").on("click", function(){ + Sunstone.showTab(TAB_ID); + $('li', '.provision-header').removeClass("active"); + show_provision_dashboard(); + }) + + $(".configuration").on("click", function(){ + $('li', '.provision-header').removeClass("active"); + }) + show_provision_dashboard(); $('.provision-header').on('click', 'li', function(){ + Sunstone.showTab(TAB_ID); $('li', '.provision-header').removeClass("active"); $(this).closest('li').addClass("active"); }) @@ -1596,138 +1294,6 @@ define(function(require) { ProvisionUsersList.show(0); }); - // - // User Info - // - - $("#provision_user_info_button").on("click", function(){ - show_provision_user_info(); - }); - - $("#provision_user_info").on("click", "#provision_user_info_refresh_button", function(){ - show_provision_user_info(); - }); - - $.each( config['available_views'], function(id, view) { - $('select#provision_user_views_select').append('') - }); - - $("#provision_change_password_form").submit(function(){ - var pw = $('#provision_new_password', this).val(); - var confirm_password = $('#provision_new_confirm_password', this).val(); - - if (!pw.length){ - Notifier.notifyError(Locale.tr("Fill in a new password")); - return false; - } - - if (pw !== confirm_password){ - Notifier.notifyError(Locale.tr("Passwords do not match")); - return false; - } - - Sunstone.runAction("Provision.User.passwd", "-1", pw); - return false; - }); - - $("#provision_add_ssh_key_form").submit(function(){ - var keypair = $('#provision_ssh_key', this).val(); - - if (!keypair.length){ - Notifier.notifyError(Locale.tr("You have to provide an SSH key")); - return false; - } - - OpenNebula.User.show({ - data : { - id: "-1" - }, - success: function(request,user_json){ - var template = user_json.USER.TEMPLATE; - - template["SSH_PUBLIC_KEY"] = keypair; - - template_str = ""; - $.each(template,function(key,value){ - template_str += (key + '=' + '"' + value + '"\n'); - }); - - Sunstone.runAction("Provision.User.update_template", "-1", template_str); - } - }) - return false; - }); - - $("#provision_change_view_form").submit(function(){ - var view = $('#provision_user_views_select', this).val(); - - OpenNebula.User.show({ - data : { - id: "-1" - }, - success: function(request,user_json){ - var template = user_json.USER.TEMPLATE; - - template["DEFAULT_VIEW"] = view; - - template_str = ""; - $.each(template,function(key,value){ - template_str += (key + '=' + '"' + value + '"\n'); - }); - - var data = OpenNebula.Helper.action('update', {"template_raw" : template_str }); - - $.ajax({ - url: 'config', - type: "POST", - dataType: "json", - data: JSON.stringify(data), - success: function(){ - window.location.href = "."; - }, - error: function(response){ - } - }); - } - }) - return false; - }); - - $("#provision_change_language_form").submit(function(){ - var lang = $('#provision_new_language', this).val(); - - OpenNebula.User.show({ - data : { - id: "-1" - }, - success: function(request,user_json){ - var template = user_json.USER.TEMPLATE; - - template["LANG"] = lang; - - template_str = ""; - $.each(template,function(key,value){ - template_str += (key + '=' + '"' + value + '"\n'); - }); - - var data = OpenNebula.Helper.action('update', {"template_raw" : template_str }); - - $.ajax({ - url: 'config', - type: "POST", - dataType: "json", - data: JSON.stringify(data), - success: function(){ - window.location.href = "."; - }, - error: function(response){ - } - }); - } - }) - return false; - }); - // // Create VM // diff --git a/src/sunstone/public/app/tabs/settings-tab.js b/src/sunstone/public/app/tabs/settings-tab.js index fc3e984646..fbe8dd5550 100644 --- a/src/sunstone/public/app/tabs/settings-tab.js +++ b/src/sunstone/public/app/tabs/settings-tab.js @@ -18,6 +18,7 @@ define(function(require) { var _panels = [ require('tabs/users-tab/panels/info'), + require('tabs/settings-tab/panels/user-config'), require('tabs/users-tab/panels/quotas'), require('tabs/settings-tab/panels/group-quotas'), require('tabs/users-tab/panels/accounting'), diff --git a/src/sunstone/public/app/tabs/settings-tab/panels/user-config.js b/src/sunstone/public/app/tabs/settings-tab/panels/user-config.js new file mode 100644 index 0000000000..1e7d71be18 --- /dev/null +++ b/src/sunstone/public/app/tabs/settings-tab/panels/user-config.js @@ -0,0 +1,191 @@ +define(function(require) { + /* + DEPENDENCIES + */ + + require('foundation.accordion'); + var Locale = require('utils/locale'); + var Config = require('sunstone-config'); + var OpenNebula = require('opennebula'); + + /* + TEMPLATES + */ + + var TemplateEasyInfo = require('hbs!./user-config/html'); + + /* + CONSTANTS + */ + + var TAB_ID = require('../tabId'); + var PANEL_ID = require('./user-config/panelId'); + var RESOURCE = "User"; + var XML_ROOT = "USER"; + + /* + CONSTRUCTOR + */ + + function Panel(info, tabId) { + this.tabId = tabId || TAB_ID; + this.title = Locale.tr("Config"); + this.icon = "fa-info"; + + this.element = info[XML_ROOT]; + + return this; + } + + Panel.PANEL_ID = PANEL_ID; + Panel.prototype.html = _html; + Panel.prototype.setup = _setup; + + return Panel; + + /* + FUNCTION DEFINITIONS + */ + + function _html() { + return TemplateEasyInfo({'languageOptions': Locale.language_options}); + } + + function _setup(context) { + $(document).foundation('accordion', 'reflow'); + var ssh_key = this.element.TEMPLATE.SSH_PUBLIC_KEY; + if (ssh_key && ssh_key.length) { + $("#provision_ssh_key", context).val(ssh_key); + $(".provision_add_ssh_key_button", context).hide(); + $(".provision_update_ssh_key_button"), context.show(); + } else { + $(".provision_add_ssh_key_button", context).show(); + $(".provision_update_ssh_key_button", context).hide(); + } + + $('#provision_new_language option[value="' + config['user_config']["lang"] + '"]', context).attr('selected', 'selected'); + $('#provision_user_views_select option[value="' + config['user_config']["default_view"] + '"]', context).attr('selected', 'selected'); + + $.each(config['available_views'], function(id, view) { + $('select#provision_user_views_select', context).append('') + }); + + $("#provision_change_password_form").submit(function() { + var pw = $('#provision_new_password', this).val(); + var confirm_password = $('#provision_new_confirm_password', this).val(); + + if (!pw.length) { + Notifier.notifyError(Locale.tr("Fill in a new password")); + return false; + } + + if (pw !== confirm_password) { + Notifier.notifyError(Locale.tr("Passwords do not match")); + return false; + } + + Sunstone.runAction("User.passwd", "-1", pw); + return false; + }); + + $("#provision_add_ssh_key_form").submit(function() { + var keypair = $('#provision_ssh_key', this).val(); + + if (!keypair.length) { + Notifier.notifyError(Locale.tr("You have to provide an SSH key")); + return false; + } + + OpenNebula.User.show({ + data : { + id: "-1" + }, + success: function(request, user_json) { + var template = user_json.USER.TEMPLATE; + + template["SSH_PUBLIC_KEY"] = keypair; + + template_str = ""; + $.each(template, function(key, value) { + template_str += (key + '=' + '"' + value + '"\n'); + }); + + Sunstone.runAction("User.update_template", "-1", template_str); + } + }) + return false; + }); + + $("#provision_change_view_form").submit(function() { + var view = $('#provision_user_views_select', this).val(); + + OpenNebula.User.show({ + data : { + id: "-1" + }, + success: function(request, user_json) { + var template = user_json.USER.TEMPLATE; + + template["DEFAULT_VIEW"] = view; + + template_str = ""; + $.each(template, function(key, value) { + template_str += (key + '=' + '"' + value + '"\n'); + }); + + var data = OpenNebula.Helper.action('update', {"template_raw" : template_str}); + + $.ajax({ + url: 'config', + type: "POST", + dataType: "json", + data: JSON.stringify(data), + success: function() { + window.location.href = "."; + }, + error: function(response) { + } + }); + } + }) + return false; + }); + + $("#provision_change_language_form").submit(function() { + var lang = $('#provision_new_language', this).val(); + + OpenNebula.User.show({ + data : { + id: "-1" + }, + success: function(request, user_json) { + var template = user_json.USER.TEMPLATE; + + template["LANG"] = lang; + + template_str = ""; + $.each(template, function(key, value) { + template_str += (key + '=' + '"' + value + '"\n'); + }); + + var data = OpenNebula.Helper.action('update', {"template_raw" : template_str}); + + $.ajax({ + url: 'config', + type: "POST", + dataType: "json", + data: JSON.stringify(data), + success: function() { + window.location.href = "."; + }, + error: function(response) { + } + }); + } + }) + return false; + }); + + return false; + } +}); diff --git a/src/sunstone/public/app/tabs/settings-tab/panels/user-config/html.hbs b/src/sunstone/public/app/tabs/settings-tab/panels/user-config/html.hbs new file mode 100644 index 0000000000..34d9d790fc --- /dev/null +++ b/src/sunstone/public/app/tabs/settings-tab/panels/user-config/html.hbs @@ -0,0 +1,183 @@ +
+
+
+
+
+
+ +
+
+
+ + +
+
+
+
+ + {{tr "Change Language"}} +
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+ + + + +
+
+
+
+ + {{tr "Change Password"}} +
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+ + + + +
+
+
+
+ + {{tr "Change view"}} +
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+ + + + +
+
+
+
+ + {{tr "Add SSH Key"}} + {{tr "Update SSH Key"}} +
+
+
+

+ + {{tr "Add a public SSH key to your account!"}} +
+ {{tr "You will be able to access your Virtual Machines without password"}} +
+ + {{tr "Update your public SSH key!"}} +
+ {{tr "You will be able to access your Virtual Machines without password"}} +
+

+
+
+ +
+
+
+
+ + +
+
+
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/src/sunstone/public/app/tabs/settings-tab/panels/user-config/panelId.js b/src/sunstone/public/app/tabs/settings-tab/panels/user-config/panelId.js new file mode 100644 index 0000000000..95393c5055 --- /dev/null +++ b/src/sunstone/public/app/tabs/settings-tab/panels/user-config/panelId.js @@ -0,0 +1,3 @@ +define(function(require) { + return 'user_config_tab'; +});