From 143b73aea37a7a2c9a7552190f58bbf35796820a Mon Sep 17 00:00:00 2001 From: Tim Felgentreff Date: Wed, 18 May 2011 10:52:12 +0200 Subject: [PATCH 1/2] Fix a JS error if the progressbar is not active --- assets/javascripts/reporting/progressbar.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/assets/javascripts/reporting/progressbar.js b/assets/javascripts/reporting/progressbar.js index bd6cbb0411..9d2ebc7885 100644 --- a/assets/javascripts/reporting/progressbar.js +++ b/assets/javascripts/reporting/progressbar.js @@ -4,7 +4,9 @@ Reporting.Progress = { abort: function () { - window.progressbar.stop(); + if (window.progressbar !== undefined && window.progressbar !== null) { + window.progressbar.stop(); + } }, replace_with_bar: function (element) { From 5621ae55bd59d86fbbb4d3e67c7e12e369a0a703 Mon Sep 17 00:00:00 2001 From: Tim Felgentreff Date: Wed, 18 May 2011 14:04:53 +0200 Subject: [PATCH 2/2] add safeguards to javascripts to avoid script-errors with mal-formed pages --- assets/javascripts/reporting/controls.js | 33 ++++++++++++++--------- assets/javascripts/reporting/filters.js | 13 +++++---- assets/javascripts/reporting/group_bys.js | 17 +++++++----- 3 files changed, 39 insertions(+), 24 deletions(-) diff --git a/assets/javascripts/reporting/controls.js b/assets/javascripts/reporting/controls.js index a7d0e80f4f..3602c08227 100644 --- a/assets/javascripts/reporting/controls.js +++ b/assets/javascripts/reporting/controls.js @@ -96,6 +96,9 @@ Reporting.Controls = { }, attach_settings_callback: function (element, callback) { + if (element === null) { + return; + } failureCallback = function (response) { $('result-table').update(""); Reporting.Controls.default_failure_callback(response); @@ -130,26 +133,30 @@ Reporting.Controls = { }; Reporting.onload(function () { - if ($('query_saved_name').getAttribute("data-update-url") !== null) { - Reporting.Controls.query_name_editor('query_saved_name'); - } - // don't concern ourselves with new queries - if ($('query_saved_name').getAttribute("data-is_new") !== null) { - if ($('query-icon-delete') !== null) { - Reporting.Controls.observe_click("query-icon-delete", Reporting.Controls.toggle_delete_form); - Reporting.Controls.observe_click("query-icon-delete-cancel", Reporting.Controls.toggle_delete_form); - $('delete_form').hide(); + if ($('query_saved_name') !== null) { + if ($('query_saved_name').getAttribute("data-update-url") !== null) { + Reporting.Controls.query_name_editor('query_saved_name'); } + // don't concern ourselves with new queries + if ($('query_saved_name').getAttribute("data-is_new") !== null) { + if ($('query-icon-delete') !== null) { + Reporting.Controls.observe_click("query-icon-delete", Reporting.Controls.toggle_delete_form); + Reporting.Controls.observe_click("query-icon-delete-cancel", Reporting.Controls.toggle_delete_form); + $('delete_form').hide(); + } - if ($("query-breadcrumb-save") !== null) { - // When saving an update of an exisiting query or apply filters, we replace the table on success - Reporting.Controls.attach_settings_callback($("query-breadcrumb-save"), Reporting.Controls.update_result_table); + if ($("query-breadcrumb-save") !== null) { + // When saving an update of an exisiting query or apply filters, we replace the table on success + Reporting.Controls.attach_settings_callback($("query-breadcrumb-save"), Reporting.Controls.update_result_table); + } } } Reporting.Controls.observe_click("query-icon-save-as", Reporting.Controls.toggle_save_as_form); Reporting.Controls.observe_click("query-icon-save-as-cancel", Reporting.Controls.toggle_save_as_form); - $('save_as_form').hide(); + if ($('save_as_form') !== null) { + $('save_as_form').hide(); + } // When saving a new query, the success-response is the new saved query's url -> redirect to that Reporting.Controls.attach_settings_callback($("query-icon-save-button"), function (response) { diff --git a/assets/javascripts/reporting/filters.js b/assets/javascripts/reporting/filters.js index bd6b5d5e3d..4a3996cec2 100644 --- a/assets/javascripts/reporting/filters.js +++ b/assets/javascripts/reporting/filters.js @@ -402,11 +402,14 @@ Reporting.Filters = { }; Reporting.onload(function () { - $("add_filter_select").observe("change", function () { - if (!(Reporting.Filters.exists(this.value))) { - Reporting.Filters.add_filter(this); - }; - }); + if ($("add_filter_select")) { + $("add_filter_select").observe("change", function () { + if (!(Reporting.Filters.exists(this.value))) { + Reporting.Filters.add_filter(this); + }; + }); + } + $$(".filter_rem").each(function (e) { e.observe("click", function () { var filter_name = this.up('tr').getAttribute("data-filter-name"); diff --git a/assets/javascripts/reporting/group_bys.js b/assets/javascripts/reporting/group_bys.js index ff47cc0d9f..fe6116f764 100644 --- a/assets/javascripts/reporting/group_bys.js +++ b/assets/javascripts/reporting/group_bys.js @@ -3,7 +3,10 @@ Reporting.GroupBys = { group_by_container_ids: function() { - return $w('group_by_columns group_by_rows'); + var ids = $w('group_by_columns group_by_rows'); + return ids.select(function (i) { + return $(i) !== null + }); }, sortable_options: function() { @@ -160,10 +163,12 @@ Reporting.GroupBys = { Reporting.onload(function () { Reporting.GroupBys.initialize_drag_and_drop_areas(); [$('add_group_by_rows'), $('add_group_by_columns')].each(function (select) { - select.observe("change", function () { - if (!(Reporting.GroupBys.exists(this.value))) { - Reporting.GroupBys.add_group_by_from_select(this); - }; - }); + if (select !== null) { + select.observe("change", function () { + if (!(Reporting.GroupBys.exists(this.value))) { + Reporting.GroupBys.add_group_by_from_select(this); + }; + }); + } }); });