{= # # # # save_report_fields.cfv # # # include "templates.util.base_util"; include "templates.util.rbac.rbac_util"; include "templates.config_pages.report_fields.save_report_fields_util"; # Following nodes/properties are send from the client and must # be deleted prior saving the report fields: # - ori_node_name # - is_new # - position (defines node order) # The form processing report fields node contains a ori_node_name subnode # which is used to check if a node name changed. In case of a # node name change we have to update any dependend report_field in reports. # After this check the we need to delete the subnodes ori_node_name, etc. debug_message("\n\n#### save_report_fields.cfv START \n"); string profile_name = internal.profile_name; string session_id = volatile.session_id; bool is_root_admin = get_is_root_admin(); string page_token = v.fp.page_token; # # Check RBAC permissions # if ((is_root_admin or get_config_feature_permission(session_id, profile_name, "report_fields", "edit")) and get_is_valid_page_token(session_id, "report_fields", page_token)) then ( debug_message("\n\n" . node_as_string("v.fp") . "\n"); node profile = "profiles." . profile_name; node report_fields = profile . ".statistics.report_fields"; node new_report_fields = "v.fp.report_fields"; bool is_new_report_fields = (num_subnodes(new_report_fields) > 0); debug_message("#### is_new_report_fields: " . is_new_report_fields . "\n"); if (is_new_report_fields) then ( # # # Sort report fields # # sort(new_report_fields, "field:position,integer,ascending"); # # # Handle node names, resolve labels and clean up from helper nodes # The following subroutine returns ori_node_names_with_new_node_names. If this node # contains any subnodes then we must update existing report field names in reports. # # node ori_node_names_with_new_node_names = process_new_report_fields(new_report_fields); debug_message("#### new_report_fields after cleanup:\n" . node_as_string(new_report_fields) . "\n"); debug_message("#### ori_node_names_with_new_node_names:\n" . node_as_string(ori_node_names_with_new_node_names) . "\n"); # # # Update any report_field node name changes in reports # # update_report_fields_in_reports(profile, ori_node_names_with_new_node_names); ); # # # Delete existing report fields # # node item; foreach item report_fields ( delete_node(item); ); # # # Clone new report fields # # if (is_new_report_fields) then ( clone_node(new_report_fields, report_fields); ); # # # Save the profile # # save_node(profile); "reportFields.saveReportFieldsResponse()\n"; ) else ( # No permission to access this resource (URL) display_no_permission_html(); ); =}