'+
+ '
'+
+ '
'+
+ '
'+
+ '
'+
+ ''+role.cardinality+' '+
+ ' '+
+ ''+role.name + ' ' + Locale.tr("VMs")+' '+
+ '
'+
+ '
'+
+ '
'+
+ '
'+
+ ' '+
+ ' '+
+ ''+Locale.tr("The cardinality for this role cannot be changed")+' '+
+ '
'+
+ '
'+
+ '
'+
+ '
'+
+ '
× '+
+ '
');
+
+
+ if (max_vms > min_vms) {
+ $( ".cardinality_slider_div", context).show();
+ $( ".cardinality_no_slider_div", context).hide();
+
+ var provision_cardinality_slider = $( ".cardinality_slider", context).noUiSlider({
+ handles: 1,
+ connect: "lower",
+ range: [min_vms, max_vms],
+ step: 1,
+ start: role.cardinality,
+ value: role.cardinality,
+ slide: function(type) {
+ if ( type != "move"){
+ if ($(this).val()) {
+ $(".cardinality_value", context).html($(this).val());
+ }
+ }
+ }
+ });
+
+ provision_cardinality_slider.val(role.cardinality)
+
+ provision_cardinality_slider.addClass("noUiSlider");
+ } else {
+ $( ".cardinality_slider_div", context).hide();
+ $( ".cardinality_no_slider_div", context).show();
+ }
+
+ return false;
+ });
+
+ context.on("click", ".provision_change_cardinality_button", function(){
+ var flow_id = $(".provision_info_flow", context).attr("flow_id");
+ var cardinality = $(".cardinality_slider", context).val()
+
+ OpenNebula.Role.update({
+ data : {
+ id: flow_id + '/role/' + $(this).attr("role_id"),
+ extra_param: {
+ cardinality: cardinality
+ }
+ },
+ success: function(request, response){
+ OpenNebula.Action.clear_cache("SERVICE");
+ $(".provision_refresh_info", context).trigger("click");
+ },
+ error: Notifier.onError
+ })
+ });
+
+ context.on("click", ".provision_delete_confirm_button", function(){
+ $(".provision_confirm_action:first", context).html(
+ '
'+
+ '
'+
+ '
'+
+ ''+
+ Locale.tr("Be careful, this action will inmediately destroy your Service")+
+ ' '+
+ Locale.tr("All the information will be lost!")+
+ ' '+
+ '
'+
+ '
'+
+ '
'+
+ '
× '+
+ '
');
+ });
+
+ context.on("click", ".provision_shutdown_confirm_button", function(){
+ $(".provision_confirm_action:first", context).html(
+ '
'+
+ '
'+
+ '
'+
+ ''+
+ Locale.tr("Be careful, this action will inmediately shutdown your Service")+
+ ' '+
+ Locale.tr("All the information will be lost!")+
+ ' '+
+ '
'+
+ '
'+
+ '
'+
+ '
× '+
+ '
');
+ });
+
+ context.on("click", ".provision_recover_button", function(){
+ var flow_id = $(".provision_info_flow", context).attr("flow_id");
+
+ OpenNebula.Service.recover({
+ data : {
+ id: flow_id
+ },
+ success: function(request, response){
+ update_provision_flow_info(flow_id, context);
+ },
+ error: Notifier.onError
+ })
+ });
+
+ context.on("click", ".provision_shutdown_button", function(){
+ var flow_id = $(".provision_info_flow", context).attr("flow_id");
+
+ OpenNebula.Service.shutdown({
+ data : {
+ id: flow_id
+ },
+ success: function(request, response){
+ update_provision_flow_info(flow_id, context);
+ },
+ error: Notifier.onError
+ })
+ });
+
+ context.on("click", ".provision_delete_button", function(){
+ var button = $(this);
+ button.attr("disabled", "disabled");
+ var flow_id = $(".provision_info_flow", context).attr("flow_id");
+
+ OpenNebula.Service.del({
+ data : {
+ id: flow_id
+ },
+ success: function(request, response){
+ $(".provision_back", context).click();
+ $(".provision_flows_list_refresh_button", context).click();
+ button.removeAttr("disabled");
+ },
+ error: function(request, response){
+ Notifier.onError(request, response);
+ button.removeAttr("disabled");
+ }
+ })
+ });
+
+ context.on("click", ".provision_refresh_info", function(){
+ var flow_id = $(".provision_info_flow", context).attr("flow_id");
+ var role_id = $(".provision_info_flow", context).data("role_id");
+ update_provision_flow_info(flow_id, context, role_id);
+ //$(".provision_flows_list_refresh_button", $(".provision_flows_list_section")).trigger("click");
+ return false;
+ });
+
+ //
+ // Info Flow
+ //
+
+ $(".provision_list_flows", context).on("click", ".provision_info_flow_button", function(){
+ $("a.provision_show_flow_accordion", context).trigger("click");
+
+ var flow_id = $(this).parents(".provision-pricing-table").attr("opennebula_id")
+ update_provision_flow_info(flow_id, context);
+ return false;
+ })
+ }
+
+ function setup_provision_flows_list(context, opts){
+ //
+ // List Flows
+ //
+
+ provision_flows_datatable = $('.provision_flows_table', context).dataTable({
+ "iDisplayLength": 6,
+ "sDom" : '<"H">t<"F"lp>',
+ "aLengthMenu": [[6, 12, 36, 72], [6, 12, 36, 72]],
+ "aaSorting" : [[0, "desc"]],
+ "aoColumnDefs": [
+ { "bVisible": false, "aTargets": ["all"]}
+ ],
+ "aoColumns": [
+ { "mDataProp": "DOCUMENT.ID" },
+ { "mDataProp": "DOCUMENT.NAME" },
+ { "mDataProp": "DOCUMENT.UID" }
+ ],
+ "fnPreDrawCallback": function (oSettings) {
+ // create a thumbs container if it doesn't exist. put it in the dataTables_scrollbody div
+ if (this.$('tr', {"filter": "applied"} ).length == 0) {
+ this.html('
'+
+ '
'+
+ ' '+
+ ' '+
+ ' '+
+ '
'+
+ '
'+
+ '
'+
+ Locale.tr("Looks like you don't have any Service. Click the button below to get started")+
+ ' '+
+ '
'+
+ '
'+
+ '
'+
+ '
'+
+ '
'+
+ '
');
+ } else {
+ $(".provision_flows_table", context).html('
');
+ }
+
+ return true;
+ },
+ "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
+ var data = aData.DOCUMENT;
+ var body = data.TEMPLATE.BODY;
+ var state = get_provision_flow_state(body);
+ var start_time = get_provision_flow_start_time(body);
+
+ var roles_li = "";
+ if (body.roles) {
+ $.each(body.roles, function(index, role) {
+ var role_state = get_provision_flow_state(role);
+ var rvms = {
+ str : (role.nodes ? role.nodes.length : 0) + " / " + role.cardinality ,
+ percentage : Math.floor((role.nodes ? role.nodes.length : 0) / role.cardinality)*100
+ }
+
+ roles_li +=
+ '
'+
+ ' '+
+ role.name+
+ ' '+
+ '
'+
+ ''+
+ ' '+
+ '
'+
+ ' '+
+ '
'+
+ //''+
+ // state.str+
+ //' '+
+ ''+rvms.str+" VMs "+
+ ' ';
+ });
+ }
+
+ $(".provision_flows_ul", context).append('
'+
+ ''+
+ ''+
+ ''+ data.NAME + ' '+
+ ' '+
+ ' '+
+ ''+
+ ''+
+ ' '+
+ state.str+
+ ' '+
+ ' '+
+ roles_li +
+ ''+
+ ''+
+ ' '+
+ data.UNAME+
+ ' '+
+ ''+
+ ' '+
+ (start_time ? Humanize.prettyTimeAgo(start_time) : '-') +
+ ' '+
+ ' '+
+ ' '+
+ ' ');
+
+ return nRow;
+ }
+ });
+
+ $('.provision_list_flows_search', context).keyup(function(){
+ provision_flows_datatable.fnFilter( $(this).val() );
+ })
+
+ $('.provision_list_flows_search', context).change(function(){
+ provision_flows_datatable.fnFilter( $(this).val() );
+ })
+
+ context.on("click", ".provision_flows_list_refresh_button", function(){
+ OpenNebula.Action.clear_cache("SERVICE");
+ update_provision_flows_datatable(provision_flows_datatable, 0);
+ return false;
+ });
+
+ context.on("click", ".provision_flows_list_search_button", function(){
+ $(".provision_list_flows_search", context).fadeIn();
+ });
+
+ $(".provision_list_flows_filter", context).on("change", ".resource_list_select", function(){
+ if ($(this).val() != "-2"){
+ provision_flows_datatable.fnFilter("^" + $(this).val() + "$", 2, true, false);
+ } else {
+ provision_flows_datatable.fnFilter("", 2);
+ }
+ })
+
+ ResourceSelect.insert(
+ ".provision_list_flows_filter",
+ context,
+ "User",
+ (opts.filter_expression ? opts.filter_expression : "-2"),
+ false,
+ '
'+Locale.tr("ALL")+' ',
+ null,
+ null,
+ true,
+ true);
+
+ context.on("click", ".provision_flows_list_filter_button", function(){
+ $(".provision_list_flows_filter", context).fadeIn();
+ return false;
+ });
+
+ OpenNebula.Action.clear_cache("SERVICE");
+ update_provision_flows_datatable(provision_flows_datatable, 0);
+
+ $(document).foundation();
+ }
+
+ function generate_provision_flows_list(context, opts) {
+ context.off();
+ context.html(provision_list_flows(opts));
+ setup_provision_flows_list(context, opts);
+ setup_info_flow(context);
+ }
+
+ function setup_provision_user_info(context) {
+ function update_provision_vdc_user_info(user_id, context) {
+ $(".provision_info_vdc_user_name", context).text("");
+ $(".provision_vdc_info_container", context).html("");
+ $(".provision_info_vdc_user", context).hide();
+ $(".provision_info_vdc_user_loading", context).fadeIn();
+
+ OpenNebula.User.show({
+ data : {
+ id: user_id
+ },
+ error: Notifier.onError,
+ success: function(request, response){
+ var data = response.USER
+
+ $(".provision_vdc_user_confirm_action",context).html("");
+ $(".provision_info_vdc_user_acct",context).html("");
+
+ $(".provision_info_vdc_user", context).attr("opennebula_id", data.ID);
+ $(".provision_info_vdc_user", context).attr("uname", data.NAME);
+ $(".provision_info_vdc_user", context).attr("quotas", JSON.stringify(data.VM_QUOTA));
+ $(".provision_info_vdc_user_name", context).text(data.NAME);
+
+ $(".provision-pricing-table_user_info", context).html("");
+
+ QuotaWidgets.initEmptyQuotas(data);
+
+ if (!$.isEmptyObject(data.VM_QUOTA)){
+ var default_user_quotas = QuotaDefaults.default_quotas(data.DEFAULT_USER_QUOTAS);
+ quotas = QuotaWidgets.quotaFloatInfo(
+ data.VM_QUOTA.VM.VMS_USED,
+ data.VM_QUOTA.VM.VMS,
+ default_user_quotas.VM_QUOTA.VM.VMS,
+ true);
+
+ $(".provision-pricing-table_user_info", context).append('
'+
+ Locale.tr("Running VMs")+
+ ''+quotas.str+" "+
+ ' '+
+ '
'+
+ ''+
+ ' '+
+ '
'+
+ ' ');
+
+ quotas = QuotaWidgets.quotaFloatInfo(
+ data.VM_QUOTA.VM.CPU_USED,
+ data.VM_QUOTA.VM.CPU,
+ default_user_quotas.VM_QUOTA.VM.CPU,
+ true);
+
+ $(".provision-pricing-table_user_info", context).append('
'+
+ Locale.tr("CPU")+
+ ''+quotas.str+" "+
+ ' '+
+ '
'+
+ ''+
+ ' '+
+ '
'+
+ ' ');
+
+ quotas = QuotaWidgets.quotaMBInfo(
+ data.VM_QUOTA.VM.MEMORY_USED,
+ data.VM_QUOTA.VM.MEMORY,
+ default_user_quotas.VM_QUOTA.VM.MEMORY,
+ true);
+
+ $(".provision-pricing-table_user_info", context).append('
'+
+ Locale.tr("Memory")+
+ ''+quotas.str+" "+
+ ' '+
+ '
'+
+ ''+
+ ' '+
+ '
'+
+ ' ');
+ } else {
+ quotas = QuotaWidgets.quotaFloatInfo(0, 0, null, true);
+
+ $(".provision-pricing-table_user_info", context).append('
'+
+ Locale.tr("Running VMs")+
+ ''+quotas.str+" "+
+ ' '+
+ '
'+
+ ''+
+ ' '+
+ '
'+
+ ' ');
+
+ quotas = QuotaWidgets.quotaFloatInfo(0, 0, null, true);
+
+ $(".provision-pricing-table_user_info", context).append('
'+
+ Locale.tr("CPU")+
+ ''+quotas.str+" "+
+ ' '+
+ '
'+
+ ''+
+ ' '+
+ '
'+
+ ' ');
+
+ quotas = QuotaWidgets.quotaMBInfo(0, 0, null, true);
+
+ $(".provision-pricing-table_user_info", context).append('
'+
+ Locale.tr("Memory")+
+ ''+quotas.str+" "+
+ ' '+
+ '
'+
+ ''+
+ ' '+
+ '
'+
+ ' ');
+ }
+
+ $(".provision-pricing-table_user_info", context).append(
+ '
'+
+ ' '+
+ ' '+
+ '
'+
+ ''+
+ ' '+
+ ' '+
+ ''+
+ ' '+
+ ' '+
+ ''+
+ ' '+
+ ' '+
+ ''+
+ ' '+
+ ' '+
+ (Config.isFeatureEnabled("showback") ? ''+
+ ' '+
+ ' ' : '') +
+ ' '+
+ '
'+
+ ' ')
+
+ var start_time = Math.floor(new Date().getTime() / 1000);
+ // ms to s
+
+ // 604800 = 7 days = 7*24*60*60
+ start_time = start_time - 604800;
+
+ // today
+ var end_time = -1;
+
+ var options = {
+ "start_time": start_time,
+ "end_time": end_time,
+ "userfilter": user_id
+ }
+
+ var no_table = true;
+
+ OpenNebula.VM.accounting({
+ success: function(req, response){
+ Accounting.fillAccounting($(".dashboard_vm_accounting", context), req, response, no_table);
+ },
+ error: Notifier.onError,
+ data: options
+ });
+
+ $(".provision_info_vdc_user", context).show();
+ $(".provision_info_vdc_user_loading", context).hide();
+
+ $(document).foundation();
+ //$("#provision_info_vdc_quotas").html(quotas_html);
+ }
+ })
+ }
+ //
+ // Info User
+ //
+
+ $(".provision_list_users", context).on("click", ".provision_info_user_button", function(){
+ $("a.provision_show_user_accordion", context).trigger("click");
+ // TODO loading
+
+ var user_id = $(this).parents(".provision-pricing-table").attr("opennebula_id")
+ update_provision_vdc_user_info(user_id, context);
+ })
+
+ context.on("click", ".provision_vdc_user_info_show_vms", function(){
+ $(".provision_vdc_info_container", context).html('
'+
+ ''+
+ ' '+
+ ' '+
+ ' '+
+ ' '+
+ ' '+
+ ''+
+ ' '+
+ '
');
+
+ generate_provision_vms_list(
+ $(".provision_vdc_info_container", context),
+ {
+ title: $(".provision_info_vdc_user", context).attr("uname") + ' ' + Locale.tr("VMs"),
+ active: true,
+ refresh: true,
+ create: false,
+ filter: false,
+ filter_expression: $(".provision_info_vdc_user", context).attr("opennebula_id")
+ });
+ })
+
+ context.on("click", ".provision_vdc_user_info_show_templates", function(){
+ $(".provision_vdc_info_container", context).html('
'+
+ ''+
+ ' '+
+ ' '+
+ ' '+
+ ' '+
+ ' '+
+ ''+
+ ' '+
+ '
');
+
+ generate_provision_templates_list(
+ $(".provision_vdc_info_container", context),
+ {
+ title: $(".provision_info_vdc_user", context).attr("uname") + ' ' + Locale.tr("Templates"),
+ active: true,
+ refresh: true,
+ create: false,
+ filter: false,
+ filter_expression: $(".provision_info_vdc_user", context).attr("opennebula_id")
+ });
+ })
+
+ context.on("click", ".provision_vdc_user_info_show_flows", function(){
+ $(".provision_vdc_info_container", context).html('
'+
+ ''+
+ ' '+
+ ' '+
+ ' '+
+ ' '+
+ ' '+
+ ''+
+ ' '+
+ '
');
+
+ generate_provision_flows_list(
+ $(".provision_vdc_info_container", context),
+ {
+ title: $(".provision_info_vdc_user", context).attr("uname") + ' ' + Locale.tr("Services"),
+ active: true,
+ refresh: true,
+ create: false,
+ filter: false,
+ filter_expression: $(".provision_info_vdc_user", context).attr("opennebula_id")
+ });
+ })
+
+
+ context.on("click", ".provision_vdc_user_info_show_acct", function(){
+ $(".provision_vdc_info_container", context).html("");
+
+ $(".provision_vdc_info_container", context).html(Accounting.html());
+ Accounting.setup(
+ $(".provision_vdc_info_container", context),
+ { fixed_user: $(".provision_info_vdc_user", context).attr("opennebula_id"),
+ init_group_by: "vm" });
+
+ $(".provision_vdc_info_container", context).prepend(
+ '')
+ })
+
+ if (Config.isFeatureEnabled("showback")) {
+ context.on("click", ".provision_vdc_user_info_show_showback", function(){
+ $(".provision_vdc_info_container", context).html("");
+
+ $(".provision_vdc_info_container", context).html(Showback.html());
+ Showback.setup(
+ $(".provision_vdc_info_container", context),
+ { fixed_user: $(".provision_info_vdc_user", context).attr("opennebula_id"),
+ fixed_group: "" });
+
+ $(".provision_vdc_info_container", context).prepend(
+ '')
+ })
+ };
+
+ context.on("click", ".provision_vdc_user_delete_confirm_button", function(){
+ $(".provision_vdc_user_confirm_action", context).html(
+ '
'+
+ '
'+
+ '
'+
+ ''+
+ Locale.tr("Be careful, this action will inmediately remove the User from OpenNebula")+
+ ' '+
+ '
'+
+ '
'+
+ '
'+
+ '
'+
+ '
× '+
+ '
');
+ });
+
+ context.on("click", ".provision_vdc_user_password_confirm_button", function(){
+ $(".provision_vdc_user_confirm_action", context).html(
+ '
'+
+ '
'+
+ '
'+
+ '
'+
+ ' '+
+ ' '+
+ '
'+
+ '
'+
+ '
'+
+ '
'+
+ ''+Locale.tr("Update Password")+' '+
+ '
'+
+ '
'+
+ '
× '+
+ '
');
+
+ context.on("click", ".provision_vdc_user_change_password_button", function(){
+ var button = $(this);
+ button.attr("disabled", "disabled");
+ var user_id = $(".provision_info_vdc_user", context).attr("opennebula_id");
+ var pw = $('.provision_vdc_user_new_password', context).val();
+ var confirm_password = $('.provision_vdc_user_new_confirm_password', context).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;
+ }
+
+ OpenNebula.User.passwd({
+ data : {
+ id: user_id,
+ extra_param: pw
+ },
+ success: function(request, response){
+ update_provision_vdc_user_info(user_id, context);
+ button.removeAttr("disabled");
+ },
+ error: function(request, response){
+ Notifier.onError(request, response);
+ button.removeAttr("disabled");
+ }
+ })
+ return false;
+ });
+ });
+
+
+
+ context.on("click", ".provision_vdc_user_quota_confirm_button", function(){
+ $(".provision_vdc_user_confirm_action", context).html(
+ '
'+
+ provision_quota_widget+
+ '
'+
+ '
'+
+ '
'+
+ '
× '+
+ '
');
+
+ setup_provision_quota_widget(context);
+
+ $(document).foundation();
+
+ var quotas_str = $(".provision_info_vdc_user", context).attr("quotas");
+ if (quotas_str) {
+ var quotas = JSON.parse(quotas_str);
+
+ var vms_limit = QuotaLimits.QUOTA_LIMIT_DEFAULT;
+ var cpu_limit = QuotaLimits.QUOTA_LIMIT_DEFAULT;
+ var mem_limit = QuotaLimits.QUOTA_LIMIT_DEFAULT;
+
+ if ( quotas.VM != undefined ){
+ vms_limit = quotas.VM.VMS;
+ cpu_limit = quotas.VM.CPU;
+ mem_limit = quotas.VM.MEMORY;
+
+ if(mem_limit != QuotaLimits.QUOTA_LIMIT_UNLIMITED &&
+ mem_limit != QuotaLimits.QUOTA_LIMIT_DEFAULT){
+
+ mem_limit = quotas.VM.MEMORY/1024;
+ }
+ }
+
+ var fill_limits = function(limit, select, input){
+ switch(limit){
+ case QuotaLimits.QUOTA_LIMIT_DEFAULT:
+ select.val('default').change();
+ input.val('').change();
+ break;
+
+ case QuotaLimits.QUOTA_LIMIT_UNLIMITED:
+ select.val('unlimited').change();
+ input.val('').change();
+ break;
+
+ default:
+ select.val('edit').change();
+ input.val(limit).change();
+ }
+ }
+
+ fill_limits(
+ vms_limit,
+ $("div.provision_rvms_quota select.provision_quota_select", context),
+ $(".provision_rvms_quota_input", context) );
+
+ fill_limits(
+ cpu_limit,
+ $("div.provision_cpu_quota select.provision_quota_select", context),
+ $(".provision_cpu_quota_input", context) );
+
+ fill_limits(
+ mem_limit,
+ $("div.provision_memory_quota select.provision_quota_select", context),
+ $(".provision_memory_quota_tmp_input", context) );
+ }
+ });
+
+ context.on("click", ".provision_delete_button", function(){
+ var button = $(this);
+ button.attr("disabled", "disabled");
+ var user_id = $(".provision_info_vdc_user", context).attr("opennebula_id");
+ OpenNebula.User.del({
+ data : {
+ id: user_id
+ },
+ success: function(request, response){
+ $(".provision_back", context).click();
+ $(".provision_users_list_refresh_button", context).click();
+ button.removeAttr("disabled");
+ },
+ error: function(request, response){
+ Notifier.onError(request, response);
+ button.removeAttr("disabled");
+ }
+ })
+ });
+
+ context.on("click", ".provision_update_quota_button", function(){
+ var button = $(this);
+ button.attr("disabled", "disabled");
+ var user_id = $(".provision_info_vdc_user", context).attr("opennebula_id");
+
+ quota_json = retrieve_provision_quota_widget(context);
+
+ OpenNebula.User.set_quota({
+ data : {
+ id: user_id,
+ extra_param: quota_json
+ },
+ success: function(request, response){
+ update_provision_vdc_user_info(user_id, context);
+ button.removeAttr("disabled");
+ },
+ error: function(request, response){
+ Notifier.onError(request, response);
+ button.removeAttr("disabled");
+ }
+ })
+ });
+
+ context.on("click", ".provision_refresh_info", function(){
+ var user_id = $(".provision_info_vdc_user", context).attr("opennebula_id");
+ update_provision_vdc_user_info(user_id, context);
+ return false;
+ });
+ }
+
+ function setup_provision_users_list(context){
+ var provision_users_datatable = $('.provision_users_table', context).dataTable({
+ "iDisplayLength": 6,
+ "sDom" : '<"H">t<"F"lp>',
+ "aLengthMenu": [[6, 12, 36, 72], [6, 12, 36, 72]],
+ "aaSorting" : [[0, "desc"]],
+ "aoColumnDefs": [
+ { "bVisible": false, "aTargets": ["all"]}
+ ],
+ "aoColumns": [
+ { "mDataProp": "USER.ID" },
+ { "mDataProp": "USER.NAME" }
+ ],
+ "fnPreDrawCallback": function (oSettings) {
+ // create a thumbs container if it doesn't exist. put it in the dataTables_scrollbody div
+ if (this.$('tr', {"filter": "applied"} ).length == 0) {
+ this.html('
'+
+ ''+
+ ' '+
+ ' '+
+ ' '+
+ ' '+
+ ' '+
+ ''+
+ Locale.tr("The list of users is empty")+
+ ' '+
+ '
');
+ } else {
+ $(".provision_users_table", context).html('
');
+ }
+
+ return true;
+ },
+ "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
+ var data = aData.USER;
+ //var state = get_provision_vm_state(data);
+ var vms = "";
+ var memory = "";
+ var cpu = "";
+
+ // Inject the VM user quota. This info is returned separately in the
+ // pool info call, but the userElementArray expects it inside the USER,
+ // as it is returned by the individual info call
+ var q = provision_quotas_list[data.ID];
+
+ var quotas_html;
+
+ if (q != undefined){
+ var quota = q.QUOTAS;
+
+ if ($.isEmptyObject(quota.VM_QUOTA)){
+ var limit = (data.ID != 0 ? QuotaLimits.QUOTA_LIMIT_DEFAULT : QuotaLimits.QUOTA_LIMIT_UNLIMITED);
+
+ quota.VM_QUOTA = {
+ VM: {
+ VMS : limit,
+ VMS_USED : 0,
+ CPU : limit,
+ CPU_USED : 0,
+ MEMORY : limit,
+ MEMORY_USED : 0
+ }
+ }
+ }
+
+ if (!$.isEmptyObject(quota.VM_QUOTA)){
+ var default_user_quotas = QuotaDefaults.getDefaultUserQuotas();
+
+ quotas = QuotaWidgets.quotaFloatInfo(
+ quota.VM_QUOTA.VM.VMS_USED,
+ quota.VM_QUOTA.VM.VMS,
+ default_user_quotas.VM_QUOTA.VM.VMS,
+ true);
+
+ quotas_html = "";
+ quotas_html += '
'+
+ Locale.tr("Running VMs")+
+ ''+quotas.str+" "+
+ ' '+
+ '
'+
+ ''+
+ ' '+
+ '
'+
+ ' ';
+
+ quotas = QuotaWidgets.quotaFloatInfo(
+ quota.VM_QUOTA.VM.CPU_USED,
+ quota.VM_QUOTA.VM.CPU,
+ default_user_quotas.VM_QUOTA.VM.CPU,
+ true);
+
+ quotas_html += '
'+
+ Locale.tr("CPU")+
+ ''+quotas.str+" "+
+ ' '+
+ '
'+
+ ''+
+ ' '+
+ '
'+
+ ' ';
+
+ quotas = QuotaWidgets.quotaMBInfo(
+ quota.VM_QUOTA.VM.MEMORY_USED,
+ quota.VM_QUOTA.VM.MEMORY,
+ default_user_quotas.VM_QUOTA.VM.MEMORY,
+ true);
+
+ quotas_html += '
'+
+ Locale.tr("Memory")+
+ ''+quotas.str+" "+
+ ' '+
+ '
'+
+ ''+
+ ' '+
+ '
'+
+ ' ';
+ } else {
+ quotas = QuotaWidgets.quotaFloatInfo(0, 0, null, true);
+
+ quotas_html = "";
+ quotas_html += '
'+
+ Locale.tr("Running VMs")+
+ ''+quotas.str+" "+
+ ' '+
+ '
'+
+ ''+
+ ' '+
+ '
'+
+ ' ';
+
+ quotas = QuotaWidgets.quotaFloatInfo(0, 0, null, true);
+
+ quotas_html += '
'+
+ Locale.tr("CPU")+
+ ''+quotas.str+" "+
+ ' '+
+ '
'+
+ ''+
+ ' '+
+ '
'+
+ ' ';
+
+ quotas = QuotaWidgets.quotaMBInfo(0, 0, null, true);
+
+ quotas_html += '
'+
+ Locale.tr("Memory")+
+ ''+quotas.str+" "+
+ ' '+
+ '
'+
+ ''+
+ ' '+
+ '
'+
+ ' ';
+ }
+ }
+
+
+ $(".provision_users_ul", context).append('
'+
+ ''+
+ ' ');
+
+ return nRow;
+ }
+ });
+
+
+ $('.provision_list_users_search', context).keyup(function(){
+ provision_users_datatable.fnFilter( $(this).val() );
+ })
+
+ $('.provision_list_users_search', context).change(function(){
+ provision_users_datatable.fnFilter( $(this).val() );
+ })
+
+ context.on("click", ".provision_users_list_refresh_button", function(){
+ OpenNebula.Action.clear_cache("USER");
+ update_provision_users_datatable(provision_users_datatable, 0);
+ return false;
+ });
+
+ $(document).foundation();
+ }
+
+ function generate_provision_users_list(context, opts) {
+ context.off();
+ context.html(provision_list_users(opts));
+ setup_provision_users_list(context);
+ setup_provision_user_info(context);
+ }
+
+ // Closes and resets the create user wizard
+ function clear_provision_create_user(){
+ OpenNebula.Action.clear_cache("USER");
+ show_provision_user_list(0);
+
+ var context = $("#provision_create_user");
+ $("#username", context).val('');
+ $("#password", context).val('');
+ $("#repeat_password", context).val('');
+
+ reset_provision_quota_widget(context);
+
+ $(".alert-box-error", context).hide();
+ $(".alert-box-error", context).html("");
+ }
+
+ var Tab = {
+ tabId: TAB_ID,
+ list_header: "",
+ actions: povision_actions,
+ content: provision_content,
+ setup: _setup
+ };
+
+ return Tab;
+
+ function _setup() {
+ $(document).ready(function(){
+ var tab_name = 'provision-tab';
+ var tab = $("#"+tab_name);
+
+ if (Config.isTabEnabled(tab_name)) {
+ $('.right-header').prepend(
+ '
'+
+ '
'+
+ '
'+
+ provision_header+
+ '
'+
+ '
'+
+ '
')
+
+ $(".left-content").remove();
+ $(".right-content").addClass("large-centered small-centered");
+ $("#footer").removeClass("right");
+ $("#footer").addClass("large-centered small-centered");
+
+ //$(".user-zone-info").remove();
+
+ $("#provision_logout").click(function(){
+ OpenNebula.Auth.logout({
+ success: function(){
+ window.location.href = "login";
+ }
+ });
+
+ return false;
+ });
+
+ $(".provision_image_header").on("click", function(){
+ show_provision_dashboard();
+ })
+
+ generate_provision_vms_list($(".provision_vms_list_section"), {active: true});
+
+ if (Config.isTabPanelEnabled("provision-tab", "templates")) {
+ generate_provision_templates_list($(".provision_templates_list_section"), {active: true});
+ }
+
+ // TODO check if active
+ generate_provision_flows_list($(".provision_flows_list_section"), {active: true});
+ generate_provision_users_list($(".provision_users_list_section"), {active: true});
+
+ //
+ // Dashboard
+ //
+
+ show_provision_dashboard();
+
+ $(document).on("click", ".provision_vms_list_button", function(){
+ OpenNebula.Action.clear_cache("VM");
+ show_provision_vm_list(0);
+ });
+
+ $(document).on("click", ".provision_templates_list_button", function(){
+ OpenNebula.Action.clear_cache("VMTEMPLATE");
+ show_provision_template_list(0);
+ });
+
+ $(document).on("click", ".provision_flows_list_button", function(){
+ OpenNebula.Action.clear_cache("SERVICE");
+ show_provision_flow_list(0);
+ });
+
+ $(document).on("click", ".provision_users_list_button", function(){
+ OpenNebula.Action.clear_cache("USER");
+ show_provision_user_list(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('
'+view+' ')
+ });
+
+ $("#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
+ //
+
+ function appendTemplateCard(aData, tableID) {
+ var data = aData.VMTEMPLATE;
+ var logo;
+
+ if (data.TEMPLATE.LOGO) {
+ logo = '
'+
+ ' '+
+ ' ';
+ } else {
+ logo = '
'+
+ ' '+
+ ' ';
+ }
+
+ var li = $('
'+
+ ''+
+ ''+
+ data.NAME+
+ ' '+
+ ''+
+ logo +
+ ' '+
+ ''+
+ (data.TEMPLATE.DESCRIPTION || '...')+
+ ' '+
+ ' '+
+ ' ').appendTo($("#"+tableID+'_ul'));
+
+ $(".provision-pricing-table", li).data("opennebula", aData);
+ }
+
+ function initializeTemplateCards(context, tableID) {
+ // create a thumbs container if it doesn't exist. put it in the dataTables_scrollbody div
+ if (context.$('tr', {"filter": "applied"} ).length == 0) {
+ context.html('
'+
+ ''+
+ ' '+
+ ' '+
+ ' '+
+ ' '+
+ ' '+
+ ''+
+ Locale.tr("There are no templates available")+
+ ' '+
+ '
');
+ } else {
+ $('#'+tableID+'_table').html(
+ '
');
+ }
+
+ return true;
+ }
+
+ provision_system_templates_datatable = $('#provision_system_templates_table').dataTable({
+ "iDisplayLength": 6,
+ "sDom" : '<"H">t<"F"lp>',
+ "aLengthMenu": [[6, 12, 36, 72], [6, 12, 36, 72]],
+ "aoColumnDefs": [
+ { "bVisible": false, "aTargets": ["all"]}
+ ],
+ "aoColumns": [
+ { "mDataProp": "VMTEMPLATE.ID" },
+ { "mDataProp": "VMTEMPLATE.NAME" },
+ { "mDataProp": "VMTEMPLATE.TEMPLATE.SAVED_TEMPLATE_ID", "sDefaultContent" : "-" }
+ ],
+ "fnPreDrawCallback": function (oSettings) {
+ initializeTemplateCards(this, "provision_system_templates")
+ },
+ "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
+ appendTemplateCard(aData, "provision_system_templates");
+ return nRow;
+ }
+ });
+
+
+ provision_vdc_templates_datatable = $('#provision_vdc_templates_table').dataTable({
+ "iDisplayLength": 6,
+ "sDom" : '<"H">t<"F"lp>',
+ "aLengthMenu": [[6, 12, 36, 72], [6, 12, 36, 72]],
+ "aoColumnDefs": [
+ { "bVisible": false, "aTargets": ["all"]}
+ ],
+ "aoColumns": [
+ { "mDataProp": "VMTEMPLATE.ID" },
+ { "mDataProp": "VMTEMPLATE.NAME" },
+ { "mDataProp": "VMTEMPLATE.TEMPLATE.SAVED_TEMPLATE_ID", "sDefaultContent" : "-" },
+ { "mDataProp": "VMTEMPLATE.PERMISSIONS.GROUP_U" }
+ ],
+ "fnPreDrawCallback": function (oSettings) {
+ initializeTemplateCards(this, "provision_vdc_templates")
+ },
+ "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
+ appendTemplateCard(aData, "provision_vdc_templates");
+ return nRow;
+ }
+ });
+
+
+ provision_saved_templates_datatable = $('#provision_saved_templates_table').dataTable({
+ "iDisplayLength": 6,
+ "sDom" : '<"H">t<"F"lp>',
+ "aLengthMenu": [[6, 12, 36, 72], [6, 12, 36, 72]],
+ "aoColumnDefs": [
+ { "bVisible": false, "aTargets": ["all"]}
+ ],
+ "aoColumns": [
+ { "mDataProp": "VMTEMPLATE.ID" },
+ { "mDataProp": "VMTEMPLATE.NAME" },
+ { "mDataProp": "VMTEMPLATE.TEMPLATE.SAVED_TEMPLATE_ID", "sDefaultContent" : "-" },
+ { "mDataProp": "VMTEMPLATE.PERMISSIONS.GROUP_U" }
+ ],
+ "fnPreDrawCallback": function (oSettings) {
+ initializeTemplateCards(this, "provision_saved_templates")
+ },
+ "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
+ appendTemplateCard(aData, "provision_saved_templates");
+ return nRow;
+ }
+ });
+
+
+ $('#provision_create_template_search').on('keyup',function(){
+ provision_system_templates_datatable.fnFilter( $(this).val() );
+ provision_saved_templates_datatable.fnFilter( $(this).val() );
+ provision_vdc_templates_datatable.fnFilter( $(this).val() );
+ })
+
+ $('#provision_create_template_search').on('change',function(){
+ provision_system_templates_datatable.fnFilter( $(this).val() );
+ provision_saved_templates_datatable.fnFilter( $(this).val() );
+ provision_vdc_templates_datatable.fnFilter( $(this).val() );
+ })
+
+ $("#provision_create_template_refresh_button").click(function(){
+ OpenNebula.Action.clear_cache("VMTEMPLATE");
+ update_provision_templates_datatable(provision_system_templates_datatable);
+ update_provision_templates_datatable(provision_saved_templates_datatable);
+ update_provision_templates_datatable(provision_vdc_templates_datatable);
+
+ });
+
+ tab.on("click", "#provision_create_vm .provision_select_template .provision-pricing-table.only-one" , function(){
+ var create_vm_context = $("#provision_create_vm");
+
+ if ($(this).hasClass("selected")){
+ $(".provision_network_selector", create_vm_context).html("");
+ $(".provision_capacity_selector", create_vm_context).html("");
+
+ $(".provision_accordion_template .selected_template").hide();
+ $(".provision_accordion_template .select_template").show();
+ } else {
+ var template_id = $(this).attr("opennebula_id");
+ var template_json = $(this).data("opennebula");
+
+ var template_nic = template_json.VMTEMPLATE.TEMPLATE.NIC
+ var nics = []
+ if ($.isArray(template_nic))
+ nics = template_nic
+ else if (!$.isEmptyObject(template_nic))
+ nics = [template_nic]
+
+ $(".provision_accordion_template .selected_template").show();
+ $(".provision_accordion_template .select_template").hide();
+ $(".provision_accordion_template .selected_template_name").html(template_json.VMTEMPLATE.NAME)
+ if (template_json.VMTEMPLATE.TEMPLATE.LOGO) {
+ $(".provision_accordion_template .selected_template_logo").html('
');
+ } else {
+ $(".provision_accordion_template .selected_template_logo").html('
');
+ }
+
+ $(".provision_accordion_template a").first().trigger("click");
+
+ generate_provision_instance_type_accordion(
+ $(".provision_capacity_selector", create_vm_context),
+ template_json.VMTEMPLATE.TEMPLATE);
+
+ if (Config.provision.create_vm.isEnabled("network_select") && (template_json.VMTEMPLATE.TEMPLATE.SUNSTONE_NETWORK_SELECT != "NO")) {
+ generate_provision_network_accordion(
+ $(".provision_network_selector", create_vm_context));
+
+ $.each(nics, function(index, nic){
+ generate_provision_network_table(
+ $(".provision_nic_accordion", create_vm_context),
+ nic);
+ })
+ } else {
+ $(".provision_network_selector", create_vm_context).html("");
+ }
+
+ if (template_json.VMTEMPLATE.TEMPLATE.USER_INPUTS) {
+ generate_custom_attrs(
+ $(".provision_custom_attributes_selector", create_vm_context),
+ template_json.VMTEMPLATE.TEMPLATE.USER_INPUTS);
+ } else {
+ $(".provision_custom_attributes_selector", create_vm_context).html("");
+ }
+ }
+ })
+
+ tab.on("click", "#provision_create_vm .provision-pricing-table.only-one" , function(){
+ if ($(this).hasClass("selected")){
+ $(this).removeClass("selected");
+ } else {
+ $(".provision-pricing-table", $(this).parents(".large-block-grid-3,.large-block-grid-2")).removeClass("selected")
+ $(this).addClass("selected");
+ }
+ })
+
+ $("#provision_create_vm").submit(function(){
+ var context = $(this);
+
+ var vm_name = $("#vm_name", context).val();
+ var template_id = $(".tabs-content .content.active .selected", context).attr("opennebula_id");
+
+ var nics = [];
+ var nic;
+ $(".selected_network", context).each(function(){
+ if ($(this).attr("template_nic")) {
+ nic = JSON.parse($(this).attr("template_nic"))
+ } else if ($(this).attr("opennebula_id")) {
+ nic = {
+ 'network_id': $(this).attr("opennebula_id")
+ }
+ } else {
+ nic = undefined;
+ }
+
+ if (nic) {
+ nics.push(nic);
+ }
+ });
+
+ var instance_type = $(".provision_instance_types_ul .selected", context);
+
+ if (!template_id) {
+ $(".alert-box-error", context).fadeIn().html(Locale.tr("You must select at least a template configuration"));
+ return false;
+ }
+
+ var extra_info = {
+ 'vm_name' : vm_name,
+ 'template': {
+ }
+ }
+
+ if (nics.length > 0) {
+ extra_info.template.nic = nics;
+ }
+
+ if (instance_type.length > 0) {
+ var instance_typa_data = instance_type.data("opennebula");
+ delete instance_typa_data.name;
+
+ $.extend(extra_info.template, instance_typa_data)
+ }
+
+ var missing_attr = false;
+ var user_inputs_values = {};
+ if ($(".provision_custom_attributes", $(this))) {
+ $(".provision_custom_attribute", $(".provision_custom_attributes", $(this))).each(function(){
+ if (!$(this).val()) {
+ $(this).parent("label").css("color", "red");
+ missing_attr = true;
+ } else {
+ $(this).parent("label").css("color", "#777");
+ user_inputs_values[$(this).attr("attr_name")] = $(this).val();
+ }
+ })
+ }
+
+ if (missing_attr) {
+ $(".alert-box-error", $(this)).fadeIn().html(Locale.tr("You have not specified all the Custom Atrributes for this VM"));
+ return false;
+ }
+
+ if (!$.isEmptyObject(user_inputs_values)) {
+ $.extend(extra_info.template, user_inputs_values)
+ }
+
+ Sunstone.runAction("Provision.instantiate", template_id, extra_info);
+ return false;
+ })
+
+ $(document).on("click", ".provision_create_vm_button", function(){
+ show_provision_create_vm();
+ });
+
+
+ //
+ // Create FLOW
+ //
+
+ provision_flow_templates_datatable = $('#provision_flow_templates_table').dataTable({
+ "iDisplayLength": 6,
+ "sDom" : '<"H">t<"F"lp>',
+ "aLengthMenu": [[6, 12, 36, 72], [6, 12, 36, 72]],
+ "aaSorting" : [[1, "asc"]],
+ "aoColumnDefs": [
+ { "bVisible": false, "aTargets": ["all"]}
+ ],
+ "aoColumns": [
+ { "mDataProp": "DOCUMENT.ID" },
+ { "mDataProp": "DOCUMENT.NAME" }
+ ],
+ "fnPreDrawCallback": function (oSettings) {
+ // create a thumbs container if it doesn't exist. put it in the dataTables_scrollbody div
+ if (this.$('tr', {"filter": "applied"} ).length == 0) {
+ this.html('
'+
+ ''+
+ ' '+
+ ' '+
+ ' '+
+ ' '+
+ ' '+
+ ''+
+ Locale.tr("There are no templates available")+
+ ' '+
+ '
');
+ } else {
+ $("#provision_flow_templates_table").html('
');
+ }
+
+ return true;
+ },
+ "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
+ var data = aData.DOCUMENT;
+ var body = data.TEMPLATE.BODY;
+ var logo;
+
+ var roles_li = "";
+ if (body.roles) {
+ $.each(body.roles, function(index, role) {
+ var role_state = get_provision_flow_state(role);
+
+ roles_li +=
+ '
'+
+ ' '+
+ role.name+
+ ''+role.cardinality+" VMs "+
+ ' ';
+ });
+ }
+
+ if (body.LOGO) {
+ logo = '
'+
+ ' '+
+ ' ';
+ } else {
+ logo = '
'+
+ ' '+
+ ' ';
+ }
+
+ var li = $('
'+
+ ''+
+ ''+
+ data.NAME+
+ ' '+
+ ''+
+ logo +
+ ' '+
+ roles_li +
+ ''+
+ (data.TEMPLATE.DESCRIPTION || '')+
+ ' '+
+ ' '+
+ ' ').appendTo($("#provision_flow_templates_ul"));
+
+ $(".provision-pricing-table", li).data("opennebula", aData);
+
+ return nRow;
+ }
+ });
+
+ $('#provision_create_flow_template_search').on('keyup',function(){
+ provision_flow_templates_datatable.fnFilter( $(this).val() );
+ })
+
+ $('#provision_create_flow_template_search').on('change',function(){
+ provision_flow_templates_datatable.fnFilter( $(this).val() );
+ })
+
+ $("#provision_create_flow_template_refresh_button").click(function(){
+ OpenNebula.Action.clear_cache("SERVICE_TEMPLATE");
+ update_provision_flow_templates_datatable(provision_flow_templates_datatable);
+
+ });
+
+ tab.on("click", ".provision_select_flow_template .provision-pricing-table.only-one" , function(){
+ var context = $("#provision_create_flow");
+
+ if ($(this).hasClass("selected")){
+ $("#provision_customize_flow_template").hide();
+ $("#provision_customize_flow_template").html("");
+ $(".provision_network_selector", context).html("")
+ $(".provision_custom_attributes_selector", context).html("")
+
+ $(".provision_accordion_flow_template .selected_template").hide();
+ $(".provision_accordion_flow_template .select_template").show();
+ } else {
+ $("#provision_customize_flow_template").show();
+ $("#provision_customize_flow_template").html("");
+
+ var data = $(this).data("opennebula");
+ var body = data.DOCUMENT.TEMPLATE.BODY;
+
+ $(".provision_accordion_flow_template .selected_template").show();
+ $(".provision_accordion_flow_template .select_template").hide();
+ $(".provision_accordion_flow_template .selected_template_name").html(body.name)
+ $(".provision_accordion_flow_template .selected_template_logo").html('
');
+ $(".provision_accordion_flow_template a").first().trigger("click");
+
+ var context = $("#provision_create_flow");
+
+ if (body.custom_attrs) {
+ var network_attrs = [];
+ var text_attrs = [];
+
+ $.each(body.custom_attrs, function(key, value){
+ var parts = value.split("|");
+ // 0 mandatory; 1 type; 2 desc;
+ var attrs = {
+ "name": key,
+ "mandatory": parts[0],
+ "type": parts[1],
+ "description": parts[2],
+ }
+
+ switch (parts[1]) {
+ case "vnet_id":
+ network_attrs.push(attrs)
+ break;
+ case "text":
+ text_attrs.push(attrs)
+ break;
+ case "password":
+ text_attrs.push(attrs)
+ break;
+ }
+ })
+
+ if (network_attrs.length > 0) {
+ generate_provision_network_accordion(
+ $(".provision_network_selector", context), true);
+
+ $.each(network_attrs, function(index, vnet_attr){
+ generate_provision_network_table(
+ $(".provision_nic_accordion", context),
+ null,
+ vnet_attr);
+ });
+ }
+
+ //if (text_attrs.length > 0) {
+ // generate_custom_attrs(
+ // $(".provision_custom_attributes_selector", context),
+ // text_attrs);
+ //}
+ } else {
+ $(".provision_network_selector", context).html("")
+ $(".provision_custom_attributes_selector", context).html("")
+ }
+
+ $.each(body.roles, function(index, role){
+ var context = $('
'+
+ '
'+
+ '
'+
+ ''+
+ ' '+
+ '
'+
+ '
'+
+ '
'+
+ '
'+
+ '
'+
+ '
'+
+ '
'+
+ '
').appendTo($("#provision_customize_flow_template"))
+
+ context.data("opennebula", role);
+
+ var template_id = role.vm_template;
+ var role_html_id = "#provision_create_flow_role_"+index;
+
+ OpenNebula.Template.show({
+ data : {
+ id: template_id
+ },
+ success: function(request,template_json){
+ var role_context = $(role_html_id)
+
+ generate_cardinality_selector(
+ $(".provision_cardinality_selector", context),
+ role,
+ template_json);
+
+ if (template_json.VMTEMPLATE.TEMPLATE.USER_INPUTS) {
+ generate_custom_attrs(
+ $(".provision_custom_attributes_selector", role_context),
+ template_json.VMTEMPLATE.TEMPLATE.USER_INPUTS);
+ } else {
+ $(".provision_custom_attributes_selector", role_context).html("");
+ }
+ }
+ })
+
+
+ })
+
+ $(document).foundation();
+ }
+ })
+
+ tab.on("click", "#provision_create_flow .provision-pricing-table.only-one" , function(){
+ if ($(this).hasClass("selected")){
+ $(this).removeClass("selected");
+ } else {
+ $(".provision-pricing-table", $(this).parents(".large-block-grid-3,.large-block-grid-2")).removeClass("selected")
+ $(this).addClass("selected");
+ }
+ })
+
+ $("#provision_create_flow").submit(function(){
+ var context = $(this);
+
+ var flow_name = $("#flow_name", context).val();
+ var template_id = $(".provision_select_flow_template .selected", context).attr("opennebula_id");
+
+ if (!template_id) {
+ $(".alert-box-error", context).fadeIn().html(Locale.tr("You must select at least a template configuration"));
+ return false;
+ }
+
+ var custom_attrs = {}
+ var missing_network = false;
+ if ($(".provision_nic_accordion", context)) {
+ $(".selected_network", $(".provision_nic_accordion", context)).each(function(){
+ if (!$(this).attr("opennebula_id")) {
+ $(this).css("color", "red");
+ missing_network = true;
+ } else {
+ $(this).css("color", "#777");
+ custom_attrs[$(this).attr("attr_name")] = $(this).attr("opennebula_id");
+ }
+ })
+ }
+
+ if (missing_network) {
+ $(".alert-box-error", context).fadeIn().html(Locale.tr("You have not specified all the Networks for this Service"));
+ return false;
+ }
+
+ var roles = [];
+ var missing_attr = false;
+
+ $(".provision_create_flow_role", context).each(function(){
+ var user_inputs_values = {};
+ if ($(".provision_custom_attributes", $(this))) {
+ $(".provision_custom_attribute", $(".provision_custom_attributes", $(this))).each(function(){
+ if (!$(this).val()) {
+ $(this).parent("label").css("color", "red");
+ missing_attr = true;
+ } else {
+ $(this).parent("label").css("color", "#777");
+ user_inputs_values[$(this).attr("attr_name")] = $(this).val();
+ }
+ })
+ }
+
+ var role_template = $(this).data("opennebula");
+
+ $.each(role_template.elasticity_policies, function(i, pol){
+ pol.expression = htmlDecode(pol.expression);
+ });
+
+ roles.push($.extend(role_template, {
+ "cardinality": $(".cardinality_value", $(this)).text(),
+ "user_inputs_values": user_inputs_values
+ }));
+ })
+
+ var extra_info = {
+ 'merge_template': {
+ "name" : flow_name,
+ "roles" : roles,
+ "custom_attrs_values": custom_attrs
+ }
+ }
+
+ if (missing_attr) {
+ $(".alert-box-error", $(this)).fadeIn().html(Locale.tr("You have not specified all the Custom Atrributes for this Service"));
+ return false;
+ }
+
+ Sunstone.runAction("Provision.Flow.instantiate", template_id, extra_info);
+ return false;
+ })
+
+ $(".provision_create_flow_button").on("click", function(){
+ show_provision_create_flow();
+ });
+
+ //
+ // Group Info
+ //
+
+
+ $("#provision_vdc_info_button").on("click", function(){
+ OpenNebula.Action.clear_cache("GROUP");
+ show_provision_vdc_info();
+ });
+
+ //
+ // Create User
+ //
+
+ var context = $("#provision_create_user");
+
+ setup_provision_quota_widget(context);
+
+ // Workaround to fix sliders. Apparently the setup fails while they are hidden
+ $('a[href="#provision_create_user_manual_quota"]', context).on("click", function(){
+ $(".provision_rvms_quota_input", context).change();
+ $(".provision_memory_quota_input", context).change();
+ $(".provision_memory_quota_tmp_input", context).change();
+ $(".provision_cpu_quota_input", context).change();
+ });
+
+ $("#provision_create_user").submit(function(){
+ var context = $(this);
+
+ var username = $("#username", context).val();
+ var password = $("#password", context).val();
+ var repeat_password = $("#repeat_password", context).val();
+
+ // TODO driver
+ var driver = 'core';
+
+ if (!username.length || !password.length){
+ $(".alert-box-error", context).fadeOut();
+ $(".alert-box-error", context).fadeIn().html(Locale.tr("You have to provide a username and password"));
+ return false;
+ }
+
+ if (password !== repeat_password){
+ $(".alert-box-error", context).fadeOut();
+ $(".alert-box-error", context).fadeIn().html(Locale.tr("Passwords do not match"));
+ return false;
+ }
+
+ var user_json = { "user" :
+ { "name" : username,
+ "password" : password,
+ "auth_driver" : driver
+ }
+ };
+
+ Sunstone.runAction("Provision.User.create",user_json);
+ $(".alert-box-error", context).html('
'+
+ ''+
+ ' '+
+ ' '+
+ ' '+
+ ' '+
+ ' '+
+ ''+
+ ' '+
+ '
');
+
+ return false;
+ });
+
+ $(document).on("click", ".provision_create_user_button", function(){
+ show_provision_create_user();
+ });
+ }
+ });
+ }
+
+});
\ No newline at end of file
diff --git a/src/sunstone/public/app/tabs/provision-tab/tabId.js b/src/sunstone/public/app/tabs/provision-tab/tabId.js
new file mode 100644
index 0000000000..7a7616ddca
--- /dev/null
+++ b/src/sunstone/public/app/tabs/provision-tab/tabId.js
@@ -0,0 +1,3 @@
+define(function(require) {
+ return 'provision-tab';
+});