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 775a9ab204..8879583136 100644 --- a/flow/sunstone/public/js/user-plugins/apptools.appflow.templates.js +++ b/flow/sunstone/public/js/user-plugins/apptools.appflow.templates.js @@ -139,19 +139,13 @@ var create_service_template_tmpl = '\ \ '; -/* + var update_service_template_tmpl = '
\ -

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

\ +

'+tr("Please, choose and modify the service template")+':

\
\ - \ - \ -
\ - \ - \ -
\ - \ + \ + \
\
\ \ @@ -162,36 +156,34 @@ var update_service_template_tmpl = \ \ \ - \ - \ - \ + \ + \ + \ \ \ \ - \ - \ - \ + \ + \ + \ \ \ \ - \ - \ - \ + \ + \ + \ \
'+tr("Admin")+'
'+tr("Owner")+'
'+tr("Group")+'
'+tr("Other")+'
\
\ - \ -
\ - \
\
\
\ - \
\
\
'; -*/ + var dataTable_service_templates; var $create_service_template_dialog; @@ -210,6 +202,11 @@ var service_template_actions = { call: popUpCreateServiceTemplateDialog }, + "ServiceTemplate.update_dialog" : { + type : "custom", + call : popUpServiceTemplateUpdateDialog + }, + "ServiceTemplate.list" : { type: "list", call: ServiceTemplate.list, @@ -288,10 +285,20 @@ var service_template_actions = { "ServiceTemplate.chmod" : { type: "single", call: ServiceTemplate.chmod, -// callback error: onError, notify: true }, + + "ServiceTemplate.fetch_permissions" : { + type : "single", + call : ServiceTemplate.show, + callback : function(request, json){ + var dialog = $('#service_template_update_dialog form'); + var tmpl = json.DOCUMENT; + setPermissionsTable(tmpl, dialog); + }, + error: onError + }, /* "ServiceTemplate.clone_dialog" : { type: "custom", @@ -324,6 +331,13 @@ var service_template_buttons = { type: "create_dialog", text: tr("+ New") }, + + "ServiceTemplate.update_dialog" : { + type: "action", + text: tr("Update properties"), + alwaysActive: true + }, + "ServiceTemplate.instantiate" : { type: "action", text: tr("Instantiate") @@ -724,6 +738,99 @@ function popUpCreateServiceTemplateDialog(){ } +function setupServiceTemplateUpdateDialog(){ + //Append to DOM + dialogs_context.append('
'); + var dialog = $('#service_template_update_dialog',dialogs_context); + + //Put HTML in place + dialog.html(update_service_template_tmpl); + + var height = Math.floor($(window).height()*0.8); //set height to a percentage of the window + + //Convert into jQuery + dialog.dialog({ + autoOpen:false, + width:500, + modal:true, + height:height, + resizable:true + }); + + $('button',dialog).button(); + + $('#service_template_update_select',dialog).change(function(){ + var id = $(this).val(); + $('.permissions_table input', dialog).removeAttr('checked'); + $('.permissions_table', dialog).removeAttr('update'); + if (id && id.length){ + Sunstone.runAction("ServiceTemplate.fetch_permissions", id); + }; + }); + + $('.permissions_table input',dialog).change(function(){ + $(this).parents('table').attr('update','update'); + }); + + $('form',dialog).submit(function(){ + var dialog = $(this); + var id = $('#service_template_update_select',dialog).val(); + if (!id || !id.length) { + $(this).parents('#service_template_update_dialog').dialog('close'); + return false; + }; + + var permissions = $('.permissions_table',dialog); + if (permissions.attr('update')){ + var perms = { + octet : buildOctet(permissions) + }; + Sunstone.runAction("ServiceTemplate.chmod", id, perms); + }; + + $(this).parents('#service_template_update_dialog').dialog('close'); + return false; + }); +}; + + +function popUpServiceTemplateUpdateDialog(){ + var select = makeSelectOptions(dataTable_service_templates, + 1,//id_col + 4,//name_col + [], + [] + ); + var sel_elems = getSelectedNodes(dataTable_service_templates); + + + var dialog = $('#service_template_update_dialog'); + $('#service_template_update_select', dialog).html(select); +// $('#service_template_update_textarea',dialog).val(""); + $('.permissions_table input', dialog).removeAttr('checked'); + $('.permissions_table', dialog).removeAttr('update'); + + if (sel_elems.length >= 1){ //several items in the list are selected + //grep them + var new_select= sel_elems.length > 1? '' : ""; + $('option','').each(function(){ + var val = $(this).val(); + if ($.inArray(val,sel_elems) >= 0){ + new_select+=''; + }; + }); + $('#service_template_update_select', dialog).html(new_select); + if (sel_elems.length == 1) { + $('#service_template_update_select option', + dialog).attr('selected','selected'); + $('#service_template_update_select', dialog).trigger("change"); + }; + }; + + dialog.dialog('open'); + return false; +} + // Set the autorefresh interval for the datatable function setServiceTemplateAutorefresh() { setInterval(function(){ @@ -848,7 +955,7 @@ $(document).ready(function(){ setupCreateServiceTemplateDialog(); - + setupServiceTemplateUpdateDialog(); // setupImageCloneDialog(); setServiceTemplateAutorefresh();