{= # # # save_macro_item.cvf # # save_macro_item.cfv is called from the client when a new macro item has been created. # # include "templates.util.base_util"; include "templates.util.encoding"; debug_message("#### save_macro_item.cvf START \n"); string profile_name = internal.profile_name; string session_id = volatile.session_id; bool is_root_admin = get_is_root_admin(); bool is_macros_permission = is_root_admin or get_report_feature_permission(session_id, profile_name, "macros"); string page_token = v.sys.page_token; if (is_macros_permission and get_is_valid_page_token(session_id, "statistics", page_token)) then ( debug_message("\n" . node_as_string("v.sys") . "\n"); bool is_replace_existing_macro = v.sys.is_replace_existing_macro; string existing_macro_name = v.sys.existing_macro_name; string new_macro_name = ""; node new_macro_src = "v.sys.new_macro_item"; string user_node_name = node_name(volatile.authenticated_user_node_path); string preferences_path = "users_cache." . user_node_name . ".profiles." . profile_name . ".preferences"; # # If no macro node exists yet then create one now # if (!?(preferences_path . ".macros")) then ( preferences_path . ".macros" = ""; ); node macros = preferences_path . ".macros"; # # Get new_macro_name # if (is_replace_existing_macro and macros?{existing_macro_name}) then ( new_macro_name = existing_macro_name; ) else ( int item_count = 0; while (macros?{item_count}) ( item_count++; ); new_macro_name = item_count; set_subnode_value(macros, new_macro_name, ""); ); # # # Set new macro values # # Note, we only save properties which should be active at macro activation. # I.e. if no dateFilter is checked then it isn't saved but the macro will use # any current active date filter. # If the date filter is saved within the macro then we actually use the # date filter value of the macro. An empty date filter value is allowed, # in this case the macro should not apply any date filter! # # string filter_id = ""; node new_macro = macros{new_macro_name}; # Clean new_macro of any existing nodes (possible upon replacement) if (num_subnodes(new_macro) > 0) then ( node item; foreach item new_macro ( delete_node(item); ); ); new_macro . ".label" = @new_macro_src{"label"}; if (new_macro_src?{"rn"}) then ( new_macro . ".rn" = @new_macro_src{"rn"}; ); if (new_macro_src?{"df"}) then ( new_macro . ".df" = @new_macro_src{"df"}; ); if (new_macro_src?{"fi"}) then ( # Note, filter_id and command line filter are handled as single filter! filter_id = @new_macro_src{"fi"}; new_macro . ".fi" = filter_id; new_macro . ".f" = @new_macro_src{"f"}; # filters new_macro . ".fc" = @new_macro_src{"fc"}; # filters_comment ); # # Save macros # save_node(preferences_path); # # Handle filters backup # We save a backup of filters with filter_id in users_cache so that we have access to this # filter items in case that the filters node in filters_cache becomes deleted. # if (filter_id ne "") then ( node filter = "filters_cache." . profile_name . "." . filter_id; string macro_item_filters_path = "users_cache." . user_node_name . ".profiles." . profile_name . ".macro_item_filters." . filter_id; clone_node(filter, macro_item_filters_path); save_node(macro_item_filters_path); ); # # # Send response # # string dat = "{"; dat .= add_json("isReplaceExistingMacro", is_replace_existing_macro, "bool"); dat .= add_json("newMacroName", new_macro_name, "string"); dat = close_json(dat); 'macroItem.saveMacroItemResponse(' . dat . ')\n'; ) else ( # No permission to view this resource (URL) display_no_permission_html(); ); =}