diff --git a/env/sunstone/public/js/user-plugins/apptools.appenv.js b/env/sunstone/public/js/user-plugins/apptools.appenv.js index 45338e4252..d8b03de205 100644 --- a/env/sunstone/public/js/user-plugins/apptools.appenv.js +++ b/env/sunstone/public/js/user-plugins/apptools.appenv.js @@ -618,6 +618,7 @@ function setupCreateAppEnvDialog(){ return false; }); +/******** UNUSED $('#add_custom_var_appenv_button', dialog).click( function(){ var name = $('#custom_var_appenv_name',dialog).val(); @@ -640,6 +641,7 @@ function setupCreateAppEnvDialog(){ return false; } ); +*/ $('#create_appenv_form',dialog).submit(function(){ diff --git a/flow/sunstone/public/js/user-plugins/apptools.appflow.services.js b/flow/sunstone/public/js/user-plugins/apptools.appflow.services.js index 598603f1a4..fa8b91939e 100644 --- a/flow/sunstone/public/js/user-plugins/apptools.appflow.services.js +++ b/flow/sunstone/public/js/user-plugins/apptools.appflow.services.js @@ -400,9 +400,22 @@ function updateServicesView(request, services_list){ //updateVResDashboard("images",images_list); } +// Callback to refresh the list of Virtual Machines +function updateServiceVMInfo(vmachine_list){ + var vmachine_list_array = []; + + $.each(vmachine_list,function(){ + vmachine_list_array.push( vMachineElementArray(this)); + }); + + updateView(vmachine_list_array, servicevmsDataTable); +}; + // Callback to update the information panel tabs and pop it up function updateServiceInfo(request,elem){ var elem_info = elem.DOCUMENT; + + /* elem_info.TEMPLATE.BODY = JSON.parse(elem_info.TEMPLATE.BODY); // Form trs for variables @@ -426,43 +439,35 @@ function updateServiceInfo(request,elem){ compat_templates += ''; - +*/ var info_tab = { - title: tr("Flowironment information"), + title: tr("Information"), content: - '\ + '
\ \ - \ \ \ - \ - \ + \ + \ \ \ - \ - \ + \ + \ \ \ - \ - \ + \ + \ \ \ - \ - \ + \ + \ \ - \ - \ - \ - \ -'+ (templates ? - '' : "") -+ (elem_info.TEMPLATE.BODY.cookbooks ? - '' : "")+ -' \ + \ \ \ \ @@ -475,41 +480,79 @@ function updateServiceInfo(request,elem){ \ \ \ -'+ (!$.isEmptyObject(defaults) ? - '' + - prettyPrintJSON(defaults, 28) : "") + '
'+tr("Flowironment")+' "'+elem_info.NAME+'" '+ +
'+tr("Service")+' \"'+elem_info.NAME+'\" '+ tr("information")+'
'+tr("ID")+''+elem_info.ID+''+tr("ID")+''+elem_info.ID+'
'+tr("Name")+''+elem_info.NAME+''+tr("Name")+''+elem_info.NAME+'
'+tr("Description")+''+(elem_info.TEMPLATE.BODY.description ? elem_info.TEMPLATE.BODY.description : "None" )+''+tr("Owner")+''+elem_info.UNAME+'
'+tr("Owner")+''+elem_info.UNAME+''+tr("Group")+''+elem_info.GNAME+'
'+tr("Group")+''+elem_info.GNAME+'
'+tr("Compatible templates")+''+ templates.join(',')+'
'+tr("Cookbooks")+''+elem_info.TEMPLATE.BODY.cookbooks+'
'+tr("Permissions")+'
'+tr("Permissions")+'
     '+tr("Owner")+''+ownerPermStr(elem_info)+'      '+tr("Other")+''+otherPermStr(elem_info)+'
'+tr("Default variables")+'
\ -\ - \ - \ - \ - \ \ - \ - \ - \ - \ - \ + \ + \ \ -'+ vars +'\ - \ - \ - \ -
'+tr("Instantiate this flowironment")+'
'+tr("Template")+':
'+tr("Variables")+':'+tr("Strategy")+''+elem_info.TEMPLATE.BODY.deployment+'
' + ' } var node_tab = { title: tr("Node"), content: '\ '+ - (elem_info.TEMPLATE.BODY.node ? prettyPrintJSON(elem_info.TEMPLATE.BODY.node) : "" )+ + (elem_info.TEMPLATE.BODY ? prettyPrintJSON(elem_info.TEMPLATE.BODY) : "" )+ '
'+tr("Node")+'
' } + var vms_tab = { + title : "Virtual Machines", + content : '\ +
\ +\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ +
IDOwnerGroupNameStatusUsed CPUUsed MemoryHostIPsStart Time
' + }; + + + + var vms = []; + vms.push(elem_info.TEMPLATE.BODY.roles[0].nodes[0].vm_info); + + Sunstone.updateInfoPanelTab("service_info_panel","service_info_tab",info_tab); Sunstone.updateInfoPanelTab("service_info_panel","service_node_tab",node_tab); + Sunstone.updateInfoPanelTab("service_info_panel","service_vms_tab",vms_tab); + + servicevmsDataTable = $('#datatable_service_vms').dataTable({ + "bJQueryUI": true, + "bSortClasses": false, + "sPaginationType": "full_numbers", + "bAutoWidth":false, + "sDom" : '<"H"lfrC>t<"F"ip>', + "aoColumnDefs": [ + { "sWidth": "35px", "aTargets": [0] }, + { "sWidth": "60px", "aTargets": [5,6] }, + { "sWidth": "100px", "aTargets": [1,2,4,8] }, + { "bVisible" : false, "aTargets": [5,6,9] } + ] + }); + + var vmachine_list_array = []; + + $.each(vms,function(){ + vmachine_list_array.push( vMachineElementArray(this)); + }); + + servicevmsDataTable.fnAddData(vmachine_list_array); + servicevmsDataTable.fnDraw(false); Sunstone.popUpInfoPanel("service_info_panel"); - } @@ -634,6 +677,8 @@ $(document).ready(function(){ } : "" }); + + dataTable_services.fnClearTable(); addElement([ spinner, diff --git a/flow/sunstone/public/js/user-plugins/apptools.appflow.templates.js b/flow/sunstone/public/js/user-plugins/apptools.appflow.templates.js index 2c7b92f03f..21a655c40b 100644 --- a/flow/sunstone/public/js/user-plugins/apptools.appflow.templates.js +++ b/flow/sunstone/public/js/user-plugins/apptools.appflow.templates.js @@ -16,6 +16,11 @@ var ServiceTemplate = { "resource" : 'DOCUMENT', "path" : 'service_template', + "create": function(params){ + OpenNebula.Action.create(params, ServiceTemplate.resource, + ServiceTemplate.path); + }, + "instantiate": function(params){ var action_obj = params.data.extra_param; OpenNebula.Action.simple_action(params, @@ -76,50 +81,55 @@ var service_template_tab_content = '\ \ -->\ '; -/*+++++++++++++++++++++++++++++++ + var create_service_template_tmpl = '\
\
\ - ' + tr("Flowironment") + '\ + ' + tr("Service") + '\
\ - \ + \
\
\ - \ -
\ -
\ - \ - \ + \ + \ \
\ -
\ - \ -
\
\ -\
\ -
\ - \ -
\ - \ -
\ + ' + tr("Current Roles") + '\ + \ + \ + \ + \ + \ + \ + \ + \ + \ +
'+tr("Name")+''+tr("Card.")+''+tr("Template")+''+tr("Parents")+''+tr("Delete")+'
\
\
\
\ @@ -129,6 +139,7 @@ var create_service_template_tmpl = '\
\
'; +/* var update_service_template_tmpl = '
\

'+tr("Please, choose and modify the flowironment you want to update")+':

\ @@ -182,10 +193,22 @@ var update_service_template_tmpl =
'; */ var dataTable_service_templates; -//var $create_service_template_dialog; +var $create_service_template_dialog; var service_template_actions = { + "ServiceTemplate.create" : { + type: "create", + call: ServiceTemplate.create, + callback: addServiceTemplateElement, + error: onError, + notify:true + }, + + "ServiceTemplate.create_dialog" : { + type : "custom", + call: popUpCreateServiceTemplateDialog + }, "ServiceTemplate.list" : { type: "list", @@ -223,9 +246,6 @@ var service_template_actions = { } }, - - - "ServiceTemplate.delete" : { type: "multiple", call: ServiceTemplate.del, @@ -292,6 +312,10 @@ var service_template_buttons = { text: '', alwaysActive: true }, + "ServiceTemplate.create_dialog" : { + type: "create_dialog", + text: tr('+ New') + }, "ServiceTemplate.chown" : { type: "confirm_with_select", text: tr("Change owner"), @@ -525,8 +549,160 @@ function updateServiceTemplateInfo(request,elem){ } +// Prepare the creation dialog +function setupCreateServiceTemplateDialog(){ + dialogs_context.append('
'); + $create_service_template_dialog = $('#create_service_template_dialog',dialogs_context); + + var dialog = $create_service_template_dialog; + dialog.html(create_service_template_tmpl); + + var height = Math.floor($(window).height()*0.8); //set height to a percentage of the window + + //Prepare jquery dialog + dialog.dialog({ + autoOpen: false, + modal:true, + width: 650, + height: height + }); + + $('button',dialog).button(); + + var addParentRole = function(name){ + var select = $('select[name="parents"]', dialog); + var exists = $('option[value="'+ name +'"]', select); + if (exists.length) + return false; + select.append( + ''); + return true; + + } + + var removeParentRole = function(name){ + $('select[name="parents"] option[value="'+ name +'"]', dialog).remove(); + } + + $('.role_delete_icon').live('click', function(){ + var row = $(this).parents('tr'); + removeParentRole(row.attr('name')); + row.fadeOut().remove(); + }); + + $('select[name="parents"]', dialog).change(function(){ + $(this).val(""); + return false; + }); + + $('select[name="parents"] option').live('click', function(){ + var clicked = $(this).attr('clicked'); + if (clicked){//unbold, unmark + $(this).text($(this).text().replace(/☒/g,'☐')); + $(this).removeAttr('clicked'); + } + else {//bold,mark + $(this).text($(this).text().replace(/☐/g,'☒')); + $(this).attr('clicked','clicked'); + } + return false; + }); + + $('button#add_role', dialog).click(function(){ + var context = $(this).parent(); + var name = $('input[name="name"]', context).val(); + var cardinality = $('input[name="cardinality"]', context).val(); + var template = $('select[name="vm_template"]', context).val(); + var parents_opt = $('select[name="parents"] option[clicked="clicked"]', + context); + var parents = []; + + if (!name || !cardinality || !template){ + notifyError(tr("Please specify name, cardinality and template for this role")); + return false; + }; + + parents_opt.each(function(){ + parents.push($(this).val()) + }); + + var role = { + name : name, + cardinality: cardinality, + template: template, + parents: parents + }; + + var str = ''; + str += ''+ name +''; + str += ''+ cardinality +''; + str += ''+ template +''; + str += ''+ parents.join(',') +''; + str += ''; + str += ''; + + var ok = addParentRole(name); + + if (ok) + $('table#current_roles tbody', dialog).append($(str).hide().fadeIn()); + else + notifyError(tr("There is already a role with this name!")); + + return false; + }); + $('#create_service_template_form',dialog).submit(function(){ + var name = $('input[name="service_name"]', this).val(); + var deployment = $('select[name="deployment"]', this).val(); + + if (!name){ + notifyError(tr("Name is mandatory!")); + return false; + } + + var roles = []; + + $('table#current_roles tbody tr').each(function(){ + roles.push(JSON.parse($(this).attr('role'))); + }); + + var obj = { + name: name, + deployment: deployment, + roles: roles + } + + Sunstone.runAction("ServiceTemplate.create", { 'DOCUMENT': obj }); + dialog.dialog('close'); + return false; + }); +} + +function popUpCreateServiceTemplateDialog(){ + var dialog = $create_service_template_dialog; + var tpl_select = makeSelectOptions(dataTable_templates, 1, 4, [], [], true); + $('select[name="vm_template"]', dialog).html(tpl_select); + // $('select[name="templates"] option', dialog).each(function(){ + // $(this).text('☐ '+$(this).text()); + // }); + + // //Somehow this needs to go here. Live() doesn't respond in setup function + // $('select[name="templates"] option', dialog).click(function(){ + // var clicked = $(this).attr('clicked'); + // if (clicked){//unbold, unmark + // $(this).text($(this).text().replace(/☒/g,'☐')); + // $(this).removeAttr('clicked'); + // } + // else {//bold,mark + // $(this).text($(this).text().replace(/☐/g,'☒')); + // $(this).attr('clicked','clicked'); + // } + // return false; + // }); + + dialog.dialog('open'); +} // Set the autorefresh interval for the datatable @@ -653,7 +829,7 @@ $(document).ready(function(){ Sunstone.runAction("ServiceTemplate.list"); - + setupCreateServiceTemplateDialog(); // setupImageCloneDialog(); setServiceTemplateAutorefresh();