# # # # # profile_javascript.js # # # build_profile_javascript() # # include "templates.util.base_util"; include "templates.util.encoding"; include "templates.util.query_fields_util"; include "templates.statistics.util.reports_menu"; # # # # build_profile_javascript() # # # subroutine(build_profile_javascript( node web_server_root_info, node auto_generated_file_map, string session_id, bool is_root_admin, node super_role_reports, string profile_name, bool is_date_time_support), ( # Creates a common report javascript string which is added to the single js report file debug_message("\n\n#### build_javascript() START \n"); node profile = "profiles." . profile_name; # "var reportInfo = {};\n"; reportInfo is declared in HTML script # # # # Miscellaneous # # # "reportInfo.isDateTimeSupport = " . is_date_time_support . ";\n"; # # # Handle first_weekday & marked_weekday # # # Note, we use first_weekday and marked_weekday of statistics_misc only if they contain a value, # else we use default lang_stats value! subroutine(build_profile_javascript_get_weekday_node_value( node statistics_misc, string first_or_marked_weekday_name), ( int first_or_marked_weekday_value; if (statistics_misc?{first_or_marked_weekday_name} and (@statistics_misc{first_or_marked_weekday_name} ne "")) then ( # Override default with profile specific value first_or_marked_weekday_value = @statistics_misc{first_or_marked_weekday_name}; ) else if (?("lang_stats." . first_or_marked_weekday_name)) then ( # Use lang_stats default value first_or_marked_weekday_value = @("lang_stats." . first_or_marked_weekday_name); ) else ( first_or_marked_weekday_value = 1; ); # Fix older profiles where first_weekday or marked_weekday contains a 0 value. # The 0 value must be converted to 1 if (first_or_marked_weekday_value == 0) then (first_or_marked_weekday_value = 1); first_or_marked_weekday_value; )); node statistics_misc = "profiles." . profile_name . ".statistics.miscellaneous"; int first_weekday = build_profile_javascript_get_weekday_node_value(statistics_misc, "first_weekday"); int marked_weekday = build_profile_javascript_get_weekday_node_value(statistics_misc, "marked_weekday"); # # firstWeekday and markedWeekday are converted to javascript by -1! # "reportInfo.firstWeekday = " . (first_weekday - 1) . ";\n"; "reportInfo.markedWeekday = " . (marked_weekday - 1) . ";\n"; # # # Report fields # # node query_fields = get_query_fields(session_id, is_root_admin, profile_name); string query_fields_dat = query_fields_util_query_fields_to_json(query_fields); "reportInfo.queryFieldsDb = " . query_fields_dat . ";\n"; # # # Session paths # # # reportInfo.sessionPaths keeps the sessionPaths tree object per report element, i.e.: # reportInfo.sessionPaths['re0'] = {id='root', events=22, ...} "reportInfo.sessionPaths = {};\n"; # # # Permissions # # # string permissions_dat = "{"; # Note, we don't need the Customize Report Element permission because # the button wont be avaialble in the HTML if there is no permission. # The same is true for DatabaseInfo # permissions_dat .= add_json("isCRE", (is_root_admin or super_role_reports?{"customize_report_element"}), "bool"); # Customize Report Element # # # KHP 06/Oct/2008 - permissions are added in assemble_report_page()! # # # permissions_dat .= add_json("isCREGraphOptions", (is_root_admin or super_role_reports?{"cre_graph_options"}), "bool"); # permissions_dat .= add_json("isCREPivotTable", (is_root_admin or super_role_reports?{"cre_pivot_table"}), "bool"); # permissions_dat .= add_json("isCRESaveChangesToProfile", (is_root_admin or super_role_reports?{"cre_save_changes_to_profile"}), "bool"); # permissions_dat .= add_json("isUpdateDatabase", (is_root_admin or super_role_reports?{"update_database"}), "bool"); # permissions_dat .= add_json("isBuildDatabase", (is_root_admin or super_role_reports?{"build_database"}), "bool"); # permissions_dat = close_json(permissions_dat); # "reportInfo.permissions = " . permissions_dat . ";\n"; # # # Reports menu # # node dynamic_reports_menu = reports_menu_get_menu_structure(profile_name, true); "var reportsMenuDb = " . reports_menu_build_menu_js(profile_name, dynamic_reports_menu, is_date_time_support, true) . ";\n"; # # # Toolbar images # # build_toolbar_buttons_db("templates.util.toolbar_map.dynamic_report"); # # # Images # # add_js_image_variables("dynamic_reports"); # # # # special javascript language variables # # # string quarter_short = encode_json(@("lang_stats.quarter_short")); # string quartes_js = '["' . q . '1", ' . q . '2", ' . q . '3", ' . node month_item; string months_short_js = "["; foreach month_item "lang_stats.months_short" ( months_short_js .= '"' . encode_json(@month_item) . '",'; ); months_short_js = replace_last(months_short_js, ",", "]"); string weekdays_js = "["; string weekdays_short_js = "["; for (int i = 1; i < 8; i++) ( weekdays_js .= '"' . encode_json(@("lang_stats.weekdays." . i)) . '",'; weekdays_short_js .= '"' . encode_json(@("lang_stats.weekdays_short." . i)) . '",'; ); weekdays_js = replace_last(weekdays_js, ",", "]"); weekdays_short_js = replace_last(weekdays_short_js, ",", "]"); string hours_js = "["; for (int i = 0; i < 24; i++) ( hours_js .= '"' . encode_json(@("lang_stats.hours." . i)) . '",'; ); hours_js = replace_last(hours_js, ",", "]"); string lang_js = "{"; # lang_js .= add_json("thousandsDivider", lang_stats.numbers.thousands_divider, "string"); # lang_js .= add_json("decimalDivider", lang_stats.numbers.decimal_divider, "string"); # lang_js .= add_json("generatingReport", lang_stats.progress.major_task.view_statistics, "string"); # lang_js .= add_json("buildingDatabase", lang_stats.progress.major_task.build_database, "string"); # lang_js .= add_json("updatingDatabase", lang_stats.progress.major_task.update_database, "string"); # lang_js .= add_json("receivingProgressInfo", lang_stats.progress.receiving_progress_information, "string"); # lang_js .= add_json("loadingReport", lang_stats.progress.loading_report, "string"); lang_js .= add_json("quarterShort", quarter_short, "string"); lang_js .= add_json("monthsShort", months_short_js, "obj"); lang_js .= add_json("weekdays", weekdays_js, "obj"); lang_js .= add_json("weekdaysShort", weekdays_short_js, "obj"); lang_js .= add_json("hours", hours_js, "obj"); lang_js = close_json(lang_js); "var lang = " . lang_js . ";\n"; # # # # javascript language variables via js modules # # # add_js_language_variables(web_server_root_info, auto_generated_file_map); ));