diff --git a/assets/javascripts/reporting.js b/assets/javascripts/reporting.js index 83952fc222..5379f828ef 100644 --- a/assets/javascripts/reporting.js +++ b/assets/javascripts/reporting.js @@ -1,366 +1,342 @@ -/*global $, selectAllOptions, moveOptions */ - -function make_select_accept_multiple_values(select) { - select.multiple = true; - select.size = 4; - // first option just got selected, because THAT'S the kind of world we live in - select.options[0].selected = false; -} - -function make_select_accept_single_value(select) { - select.multiple = false; - select.size = 1; -} - -function toggle_multi_select(select) { - if (select.multiple === true) { - make_select_accept_single_value(select); - } else { - make_select_accept_multiple_values(select); - } -} - -function change_argument_visibility(field, arg_nr) { - var params, i; - params = [$(field + '_arg_1'), $(field + '_arg_2')]; - - for (i = 0; i < 2; i += 1) { - if (params[i] !== null) { - if (arg_nr >= (i + 1) || arg_nr <= (-1 - i)) { - params[i].show(); - } - else { - params[i].hide(); - } - } - } -} - -function operator_changed(field, select) { - var option_tag, arity; - if (select === null) { - return; - } - option_tag = select.options[select.selectedIndex]; - arity = parseInt(option_tag.getAttribute("data-arity"), 10); - change_argument_visibility(field, arity); -} - -function display_category(tr_field) { - var label = $(tr_field.getAttribute("data-label")); - if (label !== null) { - label.show(); - } -} - -function hide_category(tr_field) { - var label = $(tr_field.getAttribute("data-label")); - if (label !== null) { - label.hide(); - } -} - -function set_remove_button_visibility(field, value) { - var remove = $('rm_' + field); - if (remove !== null) { - if (value === true) { - remove.show(); - } else { - remove.hide(); - } - } -} - -function load_available_values_for_filter(filter_name, callback_func) { - var select; - select = $('' + filter_name + '_arg_1_val'); - if (select !== null && select.readAttribute('data-loading') === "ajax" && select.childElements().length === 0) { - new Ajax.Updater({ success: select }, window.global_prefix + '/cost_reports/available_values', { - parameters: { filter_name: filter_name }, - insertion: 'bottom', - evalScripts: false, - onCreate: function (a, b) { - $('operators_' + filter_name).disable(); - $('' + filter_name + '_arg_1_val').disable(); - }, - onComplete: function (a, b) { - $('operators_' + filter_name).enable(); - $('' + filter_name + '_arg_1_val').enable(); - callback_func(); - } - }); - make_select_accept_single_value(select); - } - else { - callback_func(); - } -} - -function show_filter_callback(field, slowly, callback_func) { - var field_el = $('tr_' + field); - if (field_el !== null) { - load_available_values_for_filter(field, callback_func); - // the following command might be included into the callback_function (which is called after the ajax request) later - $('rm_' + field).value = field; - if (slowly) { - new Effect.Appear(field_el); - } else { - field_el.show(); - } - operator_changed(field, $("operators_" + field)); - display_category(field_el); +/* +jslint nomen: true, debug: false, evil: false, + onevar: false, browser: true, white: false, indent: 0 +*/ + +window.Reporting = { + source: ($$("head")[0].select("script[src*='reporting.js']")[0].src), + + require: function(libraryName) { + alert("loading "+ libraryName); + jsName = Reporting.source.replace("reporting.js", "reporting/" + libraryName + ".js"); + try { + // inserting via DOM fails in Safari 2.0, so brute force approach + document.write('