From 191e33b119621bc5f24e56368fdae0c5c6a0a0d6 Mon Sep 17 00:00:00 2001 From: Yuri Leikind Date: Sun, 18 Jul 2010 19:04:42 +0200 Subject: [PATCH 1/5] initial support for jQuery. No JS calendar yet. --- README.rdoc | 30 +++- .../icons/arrow_down.gif | Bin .../icons/arrow_up.gif | Bin .../icons/calendar_view_month.png | Bin .../icons/delete.png | Bin .../icons/expand.png | Bin .../icons/page_white_excel.png | Bin .../icons/page_white_find.png | Bin .../icons/table.png | Bin .../icons/table_refresh.png | Bin .../icons/tick_all.png | Bin .../icons/untick_all.png | Bin .../initializers/wice_grid_config.rb | 3 + .../locales/wice_grid.yml | 30 ++++ .../stylesheets/wice_grid.css | 0 .../wice_grid_assets_jquery/templates/USAGE | 6 + .../templates/javascripts/wice_grid_jquery.js | 151 ++++++++++++++++++ .../wice_grid_assets_jquery_generator.rb | 35 ++++ .../USAGE | 2 +- .../templates/javascripts/calendarview.js | 0 .../javascripts/wice_grid_prototype.js} | 113 +++++++------ .../templates/stylesheets/calendarview.css | 0 .../wice_grid_assets_prototype_generator.rb} | 19 ++- ...rs.rb => js_calendar_helpers_prototype.rb} | 0 lib/helpers/wice_grid_misc_view_helpers.rb | 2 +- ...ce_grid_serialized_queries_view_helpers.rb | 22 ++- lib/helpers/wice_grid_view_helpers.rb | 73 ++------- lib/js_adaptors/jquery_adaptor.rb | 110 +++++++++++++ lib/js_adaptors/js_adaptor.rb | 11 ++ lib/js_adaptors/prototype_adaptor.rb | 136 ++++++++++++++++ lib/view_columns.rb | 24 +-- lib/views/create.rjs | 2 +- lib/views/delete.rjs | 2 +- lib/wice_grid.rb | 5 +- lib/wice_grid_controller.rb | 1 + 35 files changed, 611 insertions(+), 166 deletions(-) rename generators/{wice_grid_assets/templates => common_templates}/icons/arrow_down.gif (100%) rename generators/{wice_grid_assets/templates => common_templates}/icons/arrow_up.gif (100%) rename generators/{wice_grid_assets/templates => common_templates}/icons/calendar_view_month.png (100%) rename generators/{wice_grid_assets/templates => common_templates}/icons/delete.png (100%) rename generators/{wice_grid_assets/templates => common_templates}/icons/expand.png (100%) rename generators/{wice_grid_assets/templates => common_templates}/icons/page_white_excel.png (100%) rename generators/{wice_grid_assets/templates => common_templates}/icons/page_white_find.png (100%) rename generators/{wice_grid_assets/templates => common_templates}/icons/table.png (100%) rename generators/{wice_grid_assets/templates => common_templates}/icons/table_refresh.png (100%) rename generators/{wice_grid_assets/templates => common_templates}/icons/tick_all.png (100%) rename generators/{wice_grid_assets/templates => common_templates}/icons/untick_all.png (100%) rename generators/{wice_grid_assets/templates => common_templates}/initializers/wice_grid_config.rb (98%) rename generators/{wice_grid_assets/templates => common_templates}/locales/wice_grid.yml (96%) rename generators/{wice_grid_assets/templates => common_templates}/stylesheets/wice_grid.css (100%) create mode 100644 generators/wice_grid_assets_jquery/templates/USAGE create mode 100644 generators/wice_grid_assets_jquery/templates/javascripts/wice_grid_jquery.js create mode 100644 generators/wice_grid_assets_jquery/wice_grid_assets_jquery_generator.rb rename generators/{wice_grid_assets => wice_grid_assets_prototype}/USAGE (80%) rename generators/{wice_grid_assets => wice_grid_assets_prototype}/templates/javascripts/calendarview.js (100%) rename generators/{wice_grid_assets/templates/javascripts/wice_grid.js => wice_grid_assets_prototype/templates/javascripts/wice_grid_prototype.js} (59%) rename generators/{wice_grid_assets => wice_grid_assets_prototype}/templates/stylesheets/calendarview.css (100%) rename generators/{wice_grid_assets/wice_grid_assets_generator.rb => wice_grid_assets_prototype/wice_grid_assets_prototype_generator.rb} (51%) rename lib/helpers/{js_calendar_helpers.rb => js_calendar_helpers_prototype.rb} (100%) create mode 100644 lib/js_adaptors/jquery_adaptor.rb create mode 100644 lib/js_adaptors/js_adaptor.rb create mode 100644 lib/js_adaptors/prototype_adaptor.rb diff --git a/README.rdoc b/README.rdoc index 6eaf172a..2b52e3b9 100644 --- a/README.rdoc +++ b/README.rdoc @@ -2,6 +2,7 @@ Version:: 0.5 Author:: Yuri Leikind +Contributor:: Xavier Defrang Homepage:: http://leikind.org/pages/wicegrid Examples online:: http://grid.leikind.org News:: http://leikind.org/wicegrid @@ -33,6 +34,8 @@ than 2.1 can still be functional depending on the functionalities used. WiceGrid is known to work with MySQL and Postgres. +WiceGrid works with Prototype and jQuery (experimental). + WiceGrid is compliant with Ruby 1.9.1. === Examples @@ -46,7 +49,7 @@ Rails version 2.1.0 or newer. will_paginate[http://github.com/mislav/will_paginate/wikis] version 2.3.2 or newer. -Prototype[http://www.prototypejs.org] version 1.5.1 or newer. +Prototype[http://www.prototypejs.org] version 1.5.1 or newer, or jQuery[http://jquery.com/]. == How-To @@ -56,13 +59,30 @@ Run the following command to install the plugin: script/plugin install git://github.com/leikind/wice_grid.git -To copy the plugin initializer, icons, javascripts, and stylesheets to correct location, run the following command: +If your application is Prototype-based (default in Rails 2.x), run the following generator to copy all plugin assets: - ./script/generate wice_grid_assets + ./script/generate wice_grid_assets_prototype + +For jQuery: + + ./script/generate wice_grid_assets_jquery + +This will copy images, stylesheets, configuration file config/initializers/wice_grid_config.rb, and the correct version +of javascript files. + +=== Support for Prototype and jQuery + +WiceGrid started as a plugin using the Prototype javascript framework. Support for jQuery was added for version 0.6. +The plugin contains two versions of the main javascript file wice_grid.js, and depending on the generator run to +install the assets (+wice_grid_assets_prototype+ or +wice_grid_assets_jquery+) the correct file is copied into public/javascripts. -Using ./script/generate to copy assets gives the advantage of collision control - if a file with the same name already -exists at the given location, the script will pause and ask the user about what action to take. +Some javascript code is also generated and injected into the HTML page. The value of constant Wice::Defaults::JS_FRAMEWORK in +configuration file wice_grid_config.rb defines for which JS framework code should be generated. +Generators +wice_grid_assets_prototype+ and +wice_grid_assets_jquery+ create a version of wice_grid_config.rb +with the corresponding value of Wice::Defaults::JS_FRAMEWORK. +THERE IS TEMPORARILY NO JAVASCRIPT CALENDAR IN THE JQUERY VERSION AND ALL DATE/DATETIME FILTERS FALL BACK TO THE DEFAULT +RAILS DATE/DATETIME HELPERS. === Basics diff --git a/generators/wice_grid_assets/templates/icons/arrow_down.gif b/generators/common_templates/icons/arrow_down.gif similarity index 100% rename from generators/wice_grid_assets/templates/icons/arrow_down.gif rename to generators/common_templates/icons/arrow_down.gif diff --git a/generators/wice_grid_assets/templates/icons/arrow_up.gif b/generators/common_templates/icons/arrow_up.gif similarity index 100% rename from generators/wice_grid_assets/templates/icons/arrow_up.gif rename to generators/common_templates/icons/arrow_up.gif diff --git a/generators/wice_grid_assets/templates/icons/calendar_view_month.png b/generators/common_templates/icons/calendar_view_month.png similarity index 100% rename from generators/wice_grid_assets/templates/icons/calendar_view_month.png rename to generators/common_templates/icons/calendar_view_month.png diff --git a/generators/wice_grid_assets/templates/icons/delete.png b/generators/common_templates/icons/delete.png similarity index 100% rename from generators/wice_grid_assets/templates/icons/delete.png rename to generators/common_templates/icons/delete.png diff --git a/generators/wice_grid_assets/templates/icons/expand.png b/generators/common_templates/icons/expand.png similarity index 100% rename from generators/wice_grid_assets/templates/icons/expand.png rename to generators/common_templates/icons/expand.png diff --git a/generators/wice_grid_assets/templates/icons/page_white_excel.png b/generators/common_templates/icons/page_white_excel.png similarity index 100% rename from generators/wice_grid_assets/templates/icons/page_white_excel.png rename to generators/common_templates/icons/page_white_excel.png diff --git a/generators/wice_grid_assets/templates/icons/page_white_find.png b/generators/common_templates/icons/page_white_find.png similarity index 100% rename from generators/wice_grid_assets/templates/icons/page_white_find.png rename to generators/common_templates/icons/page_white_find.png diff --git a/generators/wice_grid_assets/templates/icons/table.png b/generators/common_templates/icons/table.png similarity index 100% rename from generators/wice_grid_assets/templates/icons/table.png rename to generators/common_templates/icons/table.png diff --git a/generators/wice_grid_assets/templates/icons/table_refresh.png b/generators/common_templates/icons/table_refresh.png similarity index 100% rename from generators/wice_grid_assets/templates/icons/table_refresh.png rename to generators/common_templates/icons/table_refresh.png diff --git a/generators/wice_grid_assets/templates/icons/tick_all.png b/generators/common_templates/icons/tick_all.png similarity index 100% rename from generators/wice_grid_assets/templates/icons/tick_all.png rename to generators/common_templates/icons/tick_all.png diff --git a/generators/wice_grid_assets/templates/icons/untick_all.png b/generators/common_templates/icons/untick_all.png similarity index 100% rename from generators/wice_grid_assets/templates/icons/untick_all.png rename to generators/common_templates/icons/untick_all.png diff --git a/generators/wice_grid_assets/templates/initializers/wice_grid_config.rb b/generators/common_templates/initializers/wice_grid_config.rb similarity index 98% rename from generators/wice_grid_assets/templates/initializers/wice_grid_config.rb rename to generators/common_templates/initializers/wice_grid_config.rb index 621befcd..3e0c906b 100644 --- a/generators/wice_grid_assets/templates/initializers/wice_grid_config.rb +++ b/generators/common_templates/initializers/wice_grid_config.rb @@ -1,5 +1,8 @@ if defined?(Wice::Defaults) + Wice::Defaults::JS_FRAMEWORK = :<%= active_js_framework %> + # Wice::Defaults::JS_FRAMEWORK = :<%= inactive_js_framework %> + # Style of the view helper. # +false+ is a usual view helper. # +true+ will allow to embed erb content in column (cell) definitions. diff --git a/generators/wice_grid_assets/templates/locales/wice_grid.yml b/generators/common_templates/locales/wice_grid.yml similarity index 96% rename from generators/wice_grid_assets/templates/locales/wice_grid.yml rename to generators/common_templates/locales/wice_grid.yml index 90eafdd6..e1881112 100644 --- a/generators/wice_grid_assets/templates/locales/wice_grid.yml +++ b/generators/common_templates/locales/wice_grid.yml @@ -1,4 +1,9 @@ en: + date: + order: + - :year + - :month + - :day wice_grid: show_filter_tooltip: Show filter hide_filter_tooltip: Hide filter @@ -41,6 +46,11 @@ en: is: + date: + order: + - :year + - :month + - :day wice_grid: show_filter_tooltip: Sýna síumöguleika hide_filter_tooltip: Fela síumoguleika @@ -80,6 +90,11 @@ is: query_saved_message: leitaskipun hefur verið vistuð nl: + date: + order: + - :year + - :month + - :day wice_grid: show_filter_tooltip: Filter tonen hide_filter_tooltip: Filter verbergen @@ -119,6 +134,11 @@ nl: query_saved_message: Query opgeslagen fr: + date: + order: + - :year + - :month + - :day wice_grid: show_filter_tooltip: Afficher le filtre hide_filter_tooltip: Cacher le filtrer @@ -158,6 +178,11 @@ fr: query_saved_message: La requête a été sauvée. ru: + date: + order: + - :year + - :month + - :day wice_grid: show_filter_tooltip: Показать фильтр hide_filter_tooltip: Спрятать фильтр @@ -200,6 +225,11 @@ ru: pt: + date: + order: + - :year + - :month + - :day wice_grid: show_filter_tooltip: Mostrar o filtro hide_filter_tooltip: Esconder o filtro diff --git a/generators/wice_grid_assets/templates/stylesheets/wice_grid.css b/generators/common_templates/stylesheets/wice_grid.css similarity index 100% rename from generators/wice_grid_assets/templates/stylesheets/wice_grid.css rename to generators/common_templates/stylesheets/wice_grid.css diff --git a/generators/wice_grid_assets_jquery/templates/USAGE b/generators/wice_grid_assets_jquery/templates/USAGE new file mode 100644 index 00000000..9c51e5ba --- /dev/null +++ b/generators/wice_grid_assets_jquery/templates/USAGE @@ -0,0 +1,6 @@ +Description: + Copies + configuration file wice_grid_config.rb to config/initializers/ + wice_grid_jquery.js to public/javascripts/wice_grid.js + wice_grid.css to public/stylesheets/ + wice_grid images to public/images/icons/grid diff --git a/generators/wice_grid_assets_jquery/templates/javascripts/wice_grid_jquery.js b/generators/wice_grid_assets_jquery/templates/javascripts/wice_grid_jquery.js new file mode 100644 index 00000000..5c575e31 --- /dev/null +++ b/generators/wice_grid_assets_jquery/templates/javascripts/wice_grid_jquery.js @@ -0,0 +1,151 @@ +function WiceGridProcessor(name, base_request_for_filter, base_link_for_show_all_records, + link_for_export, parameter_name_for_query_loading, environment){ + + this.checkIfJsFrameworkIsLoaded = function(){ + if (! jQuery){ + alert("jQuery not loaded, WiceGrid cannot proceed!") + } + } + + this.checkIfJsFrameworkIsLoaded(); + this.name = name; + this.parameter_name_for_query_loading = parameter_name_for_query_loading; + this.base_request_for_filter = base_request_for_filter; + this.base_link_for_show_all_records = base_link_for_show_all_records; + this.link_for_export = link_for_export; + this.filter_declarations = new Array(); + this.environment = environment; + + this.toString = function(){ + return ""; + } + + + this.process = function(){ + window.location = this.build_url_with_params(); + } + + this.reload_page_for_given_grid_state = function(grid_state){ + var request_path = this.grid_state_to_request(grid_state); + window.location = this.append_to_url(this.base_link_for_show_all_records, request_path); + } + + this.load_query = function(query_id){ + var request = this.append_to_url(this.build_url_with_params(), + (this.parameter_name_for_query_loading + encodeURIComponent(query_id))); + window.location = request; + } + + this.save_query = function(query_name, base_path_to_query_controller, grid_state, input_ids){ + if (input_ids instanceof Array) { + input_ids.each(function(dom_id){ + grid_state.push(['extra[' + dom_id + ']', $('#'+ dom_id)[0].value]) + }); + } + + var request_path = this.grid_state_to_request(grid_state); + + jQuery.ajax({ + url: base_path_to_query_controller, + async: true, + data: request_path + '&query_name=' + encodeURIComponent(query_name), + dataType: 'script', + type: 'POST' + }); + } + + this.grid_state_to_request = function(grid_state){ + return jQuery.map(grid_state, function(pair){ + return encodeURIComponent(pair[0]) + '=' + encodeURIComponent(pair[1]); + }).join('&'); + } + + + this.append_to_url = function(url, str){ + var sep; + if (url.indexOf('?') != -1){ + if (/[&\?]$/.exec(url)){ + sep = ''; + }else{ + sep = '&'; + } + }else{ + sep = '?'; + } + return url + sep + str; + } + + + this.build_url_with_params = function(){ + var results = new Array(); + var _this = this; + jQuery.each(this.filter_declarations, function(i, filter_declaration){ + param = _this.read_values_and_form_query_string( + filter_declaration.filter_name, filter_declaration.detached, + filter_declaration.templates, filter_declaration.ids); + if (param && param != ''){ + results.push(param); + } + }); + + var res = this.base_request_for_filter; + if ( results.length != 0){ + all_filter_params = results.join('&'); + res = this.append_to_url(res, all_filter_params); + } + return res; + } + + this.reset = function(){ + window.location = this.base_request_for_filter; + } + + this.export_to_csv = function(){ + window.location = this.link_for_export; + } + + this.register = function(func){ + this.filter_declarations.push(func); + } + + this.read_values_and_form_query_string = function(filter_name, detached, templates, ids){ + var res = new Array(); + for(i = 0; i < templates.length; i++){ + if($(ids[i]) == null){ + if (this.environment == "development"){ + message = 'WiceGrid: Error reading state of filter "' + filter_name + '". No DOM element with id "' + ids[i] + '" found.' + if (detached){ + message += 'You have declared "' + filter_name + + '" as a detached filter but have not output it anywhere in the template. Read documentation about detached filters.' + } + alert(message); + } + return ''; + } + var val = $('#' + ids[i]).val(); + if (val instanceof Array) { + for(j = 0; j < val.length; j++){ + if (val[j] && val[j] != "") + res.push(templates[i] + encodeURIComponent(val[j])); + } + } else if (val && val != ''){ + res.push(templates[i] + encodeURIComponent(val)); + } + } + return res.join('&'); + } + +}; + +function toggle_multi_select(select_id, link_obj, expand_label, collapse_label) { + var select = $('#' + select_id)[0]; + if (select.multiple == true) { + select.multiple = false; + link_obj.title = expand_label; + } else { + select.multiple = true; + link_obj.title = collapse_label; + } +} + +WiceGridProcessor._version = '0.4.1'; diff --git a/generators/wice_grid_assets_jquery/wice_grid_assets_jquery_generator.rb b/generators/wice_grid_assets_jquery/wice_grid_assets_jquery_generator.rb new file mode 100644 index 00000000..21203d21 --- /dev/null +++ b/generators/wice_grid_assets_jquery/wice_grid_assets_jquery_generator.rb @@ -0,0 +1,35 @@ +class WiceGridAssetsJqueryGenerator < Rails::Generator::Base + def active_js_framework + 'jquery' + end + def inactive_js_framework + 'prototype' + end + + def manifest + record do |m| + # wice_grid config + m.directory "config/initializers" + @active_js_framework = 'jquery' + @inactive_js_framework = 'prototype' + m.template "../../common_templates/initializers/wice_grid_config.rb", "config/initializers/wice_grid_config.rb" + + # wice_grid locales + m.directory "config/locales" + m.file "../../common_templates/locales/wice_grid.yml", "config/locales/wice_grid.yml" + + # wice_grid js & css + m.file "javascripts/wice_grid_jquery.js", "public/javascripts/wice_grid.js" + m.file "../../common_templates/stylesheets/wice_grid.css", "public/stylesheets/wice_grid.css" + + # images + m.directory "public/images/icons/grid" + + %w(arrow_down.gif calendar_view_month.png expand.png page_white_find.png table_refresh.png + arrow_up.gif delete.png page_white_excel.png table.png tick_all.png untick_all.png ).each do |f| + m.file "../../common_templates/icons/#{f}", "public/images/icons/grid/#{f}" + end + + end + end +end diff --git a/generators/wice_grid_assets/USAGE b/generators/wice_grid_assets_prototype/USAGE similarity index 80% rename from generators/wice_grid_assets/USAGE rename to generators/wice_grid_assets_prototype/USAGE index e4b598cc..c873d483 100644 --- a/generators/wice_grid_assets/USAGE +++ b/generators/wice_grid_assets_prototype/USAGE @@ -1,7 +1,7 @@ Description: Copies configuration file wice_grid_config.rb to config/initializers/ - wice_grid.js to public/javascripts/ + wice_grid_prototype.js to public/javascripts/wice_grid.js wice_grid.css to public/stylesheets/ calendarview.js to public/javascripts/ calendarview.css to public/stylesheets/ diff --git a/generators/wice_grid_assets/templates/javascripts/calendarview.js b/generators/wice_grid_assets_prototype/templates/javascripts/calendarview.js similarity index 100% rename from generators/wice_grid_assets/templates/javascripts/calendarview.js rename to generators/wice_grid_assets_prototype/templates/javascripts/calendarview.js diff --git a/generators/wice_grid_assets/templates/javascripts/wice_grid.js b/generators/wice_grid_assets_prototype/templates/javascripts/wice_grid_prototype.js similarity index 59% rename from generators/wice_grid_assets/templates/javascripts/wice_grid.js rename to generators/wice_grid_assets_prototype/templates/javascripts/wice_grid_prototype.js index f711abe3..71ddcb8c 100644 --- a/generators/wice_grid_assets/templates/javascripts/wice_grid.js +++ b/generators/wice_grid_assets_prototype/templates/javascripts/wice_grid_prototype.js @@ -1,66 +1,67 @@ -WiceGridProcessor = Class.create( { - - initialize : function(name, base_request_for_filter, base_link_for_show_all_records, - link_for_export, parameter_name_for_query_loading, environment){ - this.checkIfPrototypeIsLoaded(); - this.name = name; - this.parameter_name_for_query_loading = parameter_name_for_query_loading; - this.base_request_for_filter = base_request_for_filter; - this.base_link_for_show_all_records = base_link_for_show_all_records; - this.link_for_export = link_for_export; - this.filter_declarations = new Array(); - this.environment = environment; - }, - - toString : function(){ - return ""; - }, +function WiceGridProcessor(name, base_request_for_filter, base_link_for_show_all_records, + link_for_export, parameter_name_for_query_loading, environment){ - checkIfPrototypeIsLoaded : function(){ + this.checkIfJsFrameworkIsLoaded = function(){ if (typeof(Prototype) == "undefined"){ alert("Prototype javascript library not loaded, WiceGrid cannot proceed!") } - }, + } + - process : function(){ + this.checkIfJsFrameworkIsLoaded(); + this.name = name; + this.parameter_name_for_query_loading = parameter_name_for_query_loading; + this.base_request_for_filter = base_request_for_filter; + this.base_link_for_show_all_records = base_link_for_show_all_records; + this.link_for_export = link_for_export; + this.filter_declarations = new Array(); + this.environment = environment; + + this.toString = function(){ + return ""; + } + + + this.process = function(){ window.location = this.build_url_with_params(); - }, + } - reload_page_for_given_grid_state : function(grid_state){ - request_path = this.grid_state_to_request(grid_state); + this.reload_page_for_given_grid_state = function(grid_state){ + var request_path = this.grid_state_to_request(grid_state); window.location = this.append_to_url(this.base_link_for_show_all_records, request_path); - }, + } - load_query :function(query_id){ - request = this.append_to_url(this.build_url_with_params(), + this.load_query = function(query_id){ + var request = this.append_to_url(this.build_url_with_params(), (this.parameter_name_for_query_loading + encodeURIComponent(query_id))); window.location = request; - }, + } - save_query : function(query_name, base_path_to_query_controller, grid_state, input_ids){ + this.save_query = function(query_name, base_path_to_query_controller, grid_state, input_ids){ if (input_ids instanceof Array) { input_ids.each(function(dom_id){ grid_state.push(['extra[' + dom_id + ']', $F(dom_id)]) }); } - request_path = this.grid_state_to_request(grid_state); + var request_path = this.grid_state_to_request(grid_state); new Ajax.Request(base_path_to_query_controller, { asynchronous:true, evalScripts:true, parameters: request_path + '&query_name=' + encodeURIComponent(query_name) }) - }, + } - grid_state_to_request : function(grid_state){ + this.grid_state_to_request = function(grid_state){ return res = grid_state.collect(function(pair){ return encodeURIComponent(pair[0]) + '=' + encodeURIComponent(pair[1]); }).join('&'); - }, + } - append_to_url : function(url, str){ + this.append_to_url = function(url, str){ + var sep; if (url.include('?')){ if (/[&\?]$/.exec(url)){ sep = ''; @@ -71,46 +72,42 @@ WiceGridProcessor = Class.create( { sep = '?'; } return url + sep + str; - }, + } - build_url_with_params : function(){ - results = new Array(); + this.build_url_with_params = function(){ + var results = new Array(); this.filter_declarations.each(function(filter_declaration){ param = this.read_values_and_form_query_string( - filter_declaration.filter_name, - filter_declaration.detached, - filter_declaration.templates, - filter_declaration.ids); - if (param && ! param.empty()){ + filter_declaration.filter_name, filter_declaration.detached, + filter_declaration.templates, filter_declaration.ids); + if (param && param != ''){ results.push(param); } }.bind(this)); - res = this.base_request_for_filter; - if ( results.size() != 0){ + var res = this.base_request_for_filter; + if ( results.length != 0){ all_filter_params = results.join('&'); res = this.append_to_url(res, all_filter_params); } return res; - }, - - + } - reset : function(){ + this.reset = function(){ window.location = this.base_request_for_filter; - }, + } - export_to_csv : function(){ + this.export_to_csv = function(){ window.location = this.link_for_export; - }, + } - register : function(func){ + this.register = function(func){ this.filter_declarations.push(func); - }, + } - read_values_and_form_query_string : function(filter_name, detached, templates, ids){ - res = new Array(); + this.read_values_and_form_query_string = function(filter_name, detached, templates, ids){ + var res = new Array(); for(i = 0; i < templates.length; i++){ if($(ids[i]) == null){ if (this.environment == "development"){ @@ -123,10 +120,10 @@ WiceGridProcessor = Class.create( { } return ''; } - val = $F(ids[i]); + var val = $F(ids[i]); if (val instanceof Array) { for(j = 0; j < val.length; j++){ - if (val[j] && ! val[j].empty()) + if (val[j] && val[j] != "") res.push(templates[i] + encodeURIComponent(val[j])); } } else if (val && ! val.empty()){ @@ -136,10 +133,10 @@ WiceGridProcessor = Class.create( { return res.join('&'); } -}); +}; function toggle_multi_select(select_id, link_obj, expand_label, collapse_label) { - select = $(select_id); + var select = $(select_id); if (select.multiple == true) { select.multiple = false; link_obj.title = expand_label; diff --git a/generators/wice_grid_assets/templates/stylesheets/calendarview.css b/generators/wice_grid_assets_prototype/templates/stylesheets/calendarview.css similarity index 100% rename from generators/wice_grid_assets/templates/stylesheets/calendarview.css rename to generators/wice_grid_assets_prototype/templates/stylesheets/calendarview.css diff --git a/generators/wice_grid_assets/wice_grid_assets_generator.rb b/generators/wice_grid_assets_prototype/wice_grid_assets_prototype_generator.rb similarity index 51% rename from generators/wice_grid_assets/wice_grid_assets_generator.rb rename to generators/wice_grid_assets_prototype/wice_grid_assets_prototype_generator.rb index 9d4081f3..7309eb0b 100644 --- a/generators/wice_grid_assets/wice_grid_assets_generator.rb +++ b/generators/wice_grid_assets_prototype/wice_grid_assets_prototype_generator.rb @@ -1,17 +1,24 @@ -class WiceGridAssetsGenerator < Rails::Generator::Base +class WiceGridAssetsPrototypeGenerator < Rails::Generator::Base + def active_js_framework + 'prototype' + end + def inactive_js_framework + 'jquery' + end + def manifest record do |m| # wice_grid config m.directory "config/initializers" - m.file "initializers/wice_grid_config.rb", "config/initializers/wice_grid_config.rb" + m.template "../../common_templates/initializers/wice_grid_config.rb", "config/initializers/wice_grid_config.rb" # wice_grid locales m.directory "config/locales" - m.file "locales/wice_grid.yml", "config/locales/wice_grid.yml" + m.file "../../common_templates/locales/wice_grid.yml", "config/locales/wice_grid.yml" # wice_grid js & css - m.file "javascripts/wice_grid.js", "public/javascripts/wice_grid.js" - m.file "stylesheets/wice_grid.css", "public/stylesheets/wice_grid.css" + m.file "javascripts/wice_grid_prototype.js", "public/javascripts/wice_grid.js" + m.file "../../common_templates/stylesheets/wice_grid.css", "public/stylesheets/wice_grid.css" # calendarview js & css m.file "javascripts/calendarview.js", "public/javascripts/calendarview.js" @@ -22,7 +29,7 @@ def manifest %w(arrow_down.gif calendar_view_month.png expand.png page_white_find.png table_refresh.png arrow_up.gif delete.png page_white_excel.png table.png tick_all.png untick_all.png ).each do |f| - m.file "icons/#{f}", "public/images/icons/grid/#{f}" + m.file "../../common_templates/icons/#{f}", "public/images/icons/grid/#{f}" end end diff --git a/lib/helpers/js_calendar_helpers.rb b/lib/helpers/js_calendar_helpers_prototype.rb similarity index 100% rename from lib/helpers/js_calendar_helpers.rb rename to lib/helpers/js_calendar_helpers_prototype.rb diff --git a/lib/helpers/wice_grid_misc_view_helpers.rb b/lib/helpers/wice_grid_misc_view_helpers.rb index 8a28b7a5..882f6a31 100644 --- a/lib/helpers/wice_grid_misc_view_helpers.rb +++ b/lib/helpers/wice_grid_misc_view_helpers.rb @@ -104,7 +104,7 @@ def include_wice_grid_assets(options = {}) javascript_include_tag('wice_grid') + stylesheet_link_tag('wice_grid') + if opts[:include_calendar] - stylesheet_link_tag("calendarview.css") + javascript_include_tag("calendarview.js") + Wice::JsAdaptor.js_framework_specific_calendar_assets(self) else '' end diff --git a/lib/helpers/wice_grid_serialized_queries_view_helpers.rb b/lib/helpers/wice_grid_serialized_queries_view_helpers.rb index 16dcf943..f8106fa5 100644 --- a/lib/helpers/wice_grid_serialized_queries_view_helpers.rb +++ b/lib/helpers/wice_grid_serialized_queries_view_helpers.rb @@ -25,27 +25,25 @@ def saved_queries_panel(grid, opts = {}) parameters << [ CGI.unescape({:extra => {k => ''}}.to_query.sub(/=$/,'')) , v.to_s ] end parameters << ['authenticity_token', form_authenticity_token] + (%!

#{WiceGridNlMessageProvider.get_message(:SAVED_QUERY_PANEL_TITLE)}

! + saved_queries_list(grid_name, grid.saved_query, options[:extra_parameters]) + - %!
! + + %!
! + if block_given? view, ids = yield view else '' end + - text_field_tag(id_and_name, '', - :size => 20, :onkeydown=>'', :id => id_and_name) + - button_to_function(WiceGridNlMessageProvider.get_message(:SAVE_QUERY_BUTTON_LABEL), "#{grid_name}_save_query()" ) + '
' + + text_field_tag(id_and_name, '', :size => 20, :onkeydown=>'', :id => id_and_name) + + button_to_function(WiceGridNlMessageProvider.get_message(:SAVE_QUERY_BUTTON_LABEL), "#{grid_name}_save_query()" ) + + '' + javascript_tag do - %/ function #{grid_name}_save_query(){\n/ + - %/ if ( typeof(#{grid_name}) != "undefined")\n/ + - %/ #{grid_name}.save_query($F('#{id_and_name}'), '#{base_path_to_query_controller}', #{parameters.to_json}, #{ids.to_json})\n/ + - %/}\n/ + - %/ $('#{id_and_name}').observe('keydown', function(event){\n/ + - %/ if (event.keyCode == 13) #{grid_name}_save_query();\n/ + - %/ })\n/ - end).html_safe + JsAdaptor.call_to_save_query_and_key_event_initialization_for_saving_queries( + id_and_name, grid_name, base_path_to_query_controller, parameters.to_json, ids.to_json + ) + end + ).html_safe end def saved_queries_list(grid_name, saved_query = nil, extra_parameters = nil) #:nodoc: diff --git a/lib/helpers/wice_grid_view_helpers.rb b/lib/helpers/wice_grid_view_helpers.rb index 4bf2028a..e0f94438 100644 --- a/lib/helpers/wice_grid_view_helpers.rb +++ b/lib/helpers/wice_grid_view_helpers.rb @@ -486,7 +486,7 @@ def grid_html(grid, options, rendering, reuse_last_column_for_filter_buttons) #: prototype_and_js_version_check = if ENV['RAILS_ENV'] == 'development' %$ if (typeof(WiceGridProcessor) == "undefined"){\n$ + %$ alert('wice_grid.js not loaded, WiceGrid cannot proceed! ' +\n$ + - %$ 'Please make sure that you include Prototype and WiceGrid javascripts in your page. ' +\n$ + + %$ 'Please make sure that you include WiceGrid javascript in your page. ' +\n$ + %$ 'Use <%= include_wice_grid_assets %> or <%= include_wice_grid_assets(:include_calendar => true) %> ' +\n$ + %$ 'for WiceGrid javascripts and assets.')\n$ + %$ } else if ((typeof(WiceGridProcessor._version) == "undefined") || ( WiceGridProcessor._version != "0.4.1")) {\n$ + @@ -497,79 +497,39 @@ def grid_html(grid, options, rendering, reuse_last_column_for_filter_buttons) #: end if rendering.show_hide_button_present - cached_javascript << %/ $('#{grid.name}_show_icon').observe('click', function(){\n/+ - %/ Element.toggle('#{grid.name}_show_icon');\n/+ - %/ Element.toggle('#{grid.name}_hide_icon');\n/+ - %/ $('#{filter_row_id}').show();\n/+ - %/ })\n/+ - %/ $('#{grid.name}_hide_icon').observe('click', function(){\n/+ - %/ Element.toggle('#{grid.name}_show_icon');\n/+ - %/ Element.toggle('#{grid.name}_hide_icon');\n/+ - %/ $('#{filter_row_id}').hide();\n/+ - %/ });\n/ + cached_javascript << JsAdaptor.show_hide_button_initialization(grid.name, filter_row_id) end if rendering.reset_button_present - cached_javascript << %/ $$('div##{grid.name}.wice_grid_container .reset').each(function(e){\n/+ - %/ e.observe('click', function(){\n/+ - %/ #{reset_grid_javascript(grid)};\n/+ - %/ })\n/+ - %/ });\n/ + cached_javascript << JsAdaptor.reset_button_initialization(grid.name, reset_grid_javascript(grid)) end if rendering.submit_button_present - cached_javascript << %/ $$('div##{grid.name}.wice_grid_container .submit').each(function(e){\n/+ - %/ e.observe('click', function(){\n/+ - %/ #{submit_grid_javascript(grid)};\n/+ - %/ })\n/+ - %/ });\n/ + cached_javascript << JsAdaptor.submit_button_initialization(grid.name, submit_grid_javascript(grid)) end if rendering.contains_a_text_input? - cached_javascript << - %! $$('div##{grid.name}.wice_grid_container .wice_grid_filter_row input[type=text]').each(function(e){\n! + - %! e.observe('keydown', function(event){\n! + - %! if (event.keyCode == 13) {#{grid.name}.process()}\n! + - %! })\n! + - %! });\n! + cached_javascript << JsAdaptor.enter_key_event_registration(grid.name) end if rendering.csv_export_icon_present - cached_javascript << - %! $$('div##{grid.name}.wice_grid_container .export_to_csv_button').each(function(e){\n! + - %! e.observe('click', function(event){\n! + - %! #{grid.name}.export_to_csv()\n! + - %! })\n! + - %! });\n! + cached_javascript << JsAdaptor.csv_export_icon_initialization(grid.name) end if rendering.contains_auto_reloading_selects - cached_javascript << - %! $$('div##{grid.name}.wice_grid_container select.auto_reload', '.#{grid.name}_detached_filter select.auto_reload').each(function(e){\n! + - %! e.observe('change', function(event){\n! + - %! #{grid.name}.process()\n! + - %! })\n! + - %! });\n! + cached_javascript << JsAdaptor.auto_reloading_selects_event_initialization(grid.name) end if rendering.contains_auto_reloading_inputs - cached_javascript << - %! $$('div##{grid.name}.wice_grid_container input.auto_reload', '.#{grid.name}_detached_filter input.auto_reload').each(function(e){\n! + - %! e.observe('keyup', function(event){\n! + - %! #{grid.name}.process()\n! + - %! })\n! + - %! });\n! + cached_javascript << JsAdaptor.auto_reloading_inputs_event_initialization(grid.name) end if rendering.contains_auto_reloading_calendars - cached_javascript << - %! document.observe('wg:calendarChanged', function(event){\n! + - %! #{grid.name}.process()\n! + - %! });\n! + cached_javascript << JsAdaptor.auto_reloading_calendar_event_initialization(grid.name) end content << javascript_tag( - %/ document.observe("dom:loaded", function() {\n/ + + JsAdaptor.dom_loaded + %/ #{prototype_and_js_version_check}\n/ + %/ window['#{grid.name}'] = new WiceGridProcessor('#{grid.name}', '#{base_link_for_filter}',\n/ + %/ '#{base_link_for_show_all_records}', '#{link_for_export}', '#{parameter_name_for_query_loading}', '#{ENV['RAILS_ENV']}');\n/ + @@ -752,11 +712,8 @@ def show_all_link(collection_total_entries, parameters, grid_name) #:nodoc: message = WiceGridNlMessageProvider.get_message(:ALL_QUERIES_WARNING) confirmation = collection_total_entries > Defaults::START_SHOWING_WARNING_FROM ? "if (confirm('#{message}'))" : '' - js = %/ $$('div##{grid_name}.wice_grid_container .show_all_link').each(function(e){\n/ + - %/ e.observe('click', function(){\n/ + - %/ #{confirmation} #{grid_name}.reload_page_for_given_grid_state(#{parameters.to_json})\n/ + - %/ })\n/ + - %/ })\n/ + + js = JsAdaptor.show_all_link_initialization(grid_name, confirmation, parameters.to_json) tooltip = WiceGridNlMessageProvider.get_message(:SHOW_ALL_RECORDS_TOOLTIP) html = %// + @@ -770,11 +727,7 @@ def back_to_pagination_link(parameters, grid_name) #:nodoc: pagination_override_parameter_name = "#{grid_name}[pp]" parameters = parameters.reject{|k, v| k == pagination_override_parameter_name} - js = %/ $$('div##{grid_name}.wice_grid_container .show_all_link').each(function(e){\n/ + - %/ e.observe('click', function(){\n/ + - %/ #{grid_name}.reload_page_for_given_grid_state(#{parameters.to_json})\n/ + - %/ })\n/ + - %/ })\n/ + js = JsAdaptor.back_to_pagination_link_initialization(grid_name, parameters.to_json) tooltip = WiceGridNlMessageProvider.get_message(:SWITCH_BACK_TO_PAGINATED_MODE_TOOLTIP) html = %/ / + diff --git a/lib/js_adaptors/jquery_adaptor.rb b/lib/js_adaptors/jquery_adaptor.rb new file mode 100644 index 00000000..4078626d --- /dev/null +++ b/lib/js_adaptors/jquery_adaptor.rb @@ -0,0 +1,110 @@ +# encoding: UTF-8 +module Wice::JsAdaptor #:nodoc: + + class << self + def init #:nodoc: + end + + def dom_loaded #:nodoc: + %/$(document).ready(function(){\n/ + end + + def reset_button_initialization(grid_name, reset_grid_javascript) #:nodoc: + %/ $('div##{grid_name}.wice_grid_container .reset').click(function(e){\n/+ + %/ #{reset_grid_javascript};\n/+ + %/ });\n/ + end + + def submit_button_initialization(grid_name, submit_grid_javascript) #:nodoc: + %/ $('div##{grid_name}.wice_grid_container .submit').click(function(e){\n/+ + %/ #{submit_grid_javascript};\n/+ + %/ });\n/ + end + + def show_hide_button_initialization(grid_name, filter_row_id) #:nodoc: + %/ $('##{grid_name}_show_icon').click(function(){\n/+ + %/ $('##{grid_name}_show_icon').hide();\n/+ + %/ $('##{grid_name}_hide_icon').show();\n/+ + %/ $('##{filter_row_id}').show();\n/+ + %/ })\n/+ + %/ $('##{grid_name}_hide_icon').click(function(){\n/+ + %/ $('##{grid_name}_show_icon').show();\n/+ + %/ $('##{grid_name}_hide_icon').hide();\n/+ + %/ $('##{filter_row_id}').hide();\n/+ + %/ });\n/ + end + + def enter_key_event_registration(grid_name) #:nodoc: + %! $('div##{grid_name}.wice_grid_container .wice_grid_filter_row input[type=text]').keydown(function(event){\n! + + %! if (event.keyCode == 13) {#{grid_name}.process()}\n! + + %! });\n! + end + + def csv_export_icon_initialization(grid_name) #:nodoc: + %! $('div##{grid_name}.wice_grid_container .export_to_csv_button').click(function(e){\n! + + %! #{grid_name}.export_to_csv()\n! + + %! });\n! + end + + def auto_reloading_selects_event_initialization(grid_name) #:nodoc: + %! $('div##{grid_name}.wice_grid_container select.auto_reload, .#{grid_name}_detached_filter select.auto_reload').change(function(e){\n! + + %! #{grid_name}.process()\n! + + %! });\n! + end + + def auto_reloading_inputs_event_initialization(grid_name) #:nodoc: + %! $('div##{grid_name}.wice_grid_container input.auto_reload, .#{grid_name}_detached_filter input.auto_reload').keyup(function(e){\n! + + %! #{grid_name}.process()\n! + + %! });\n! + end + + def auto_reloading_calendar_event_initialization(grid_name) #:nodoc: + '' # TO DO jquery calendar is not yet here + end + + def show_all_link_initialization(grid_name, confirmation, parameters_json) #:nodoc: + %/ $('div##{grid_name}.wice_grid_container .show_all_link').click(function(e){ \n/ + + %/ #{confirmation} #{grid_name}.reload_page_for_given_grid_state(#{parameters_json}) \n/ + + %/})\n/ + end + + def back_to_pagination_link_initialization(grid_name, parameters_json) #:nodoc: + %/ $('div##{grid_name}.wice_grid_container .show_all_link').click(function(e){\n/ + + %/ #{grid_name}.reload_page_for_given_grid_state(#{parameters_json})\n/ + + %/ })\n/ + end + + def call_to_save_query_and_key_event_initialization_for_saving_queries( + id_and_name, grid_name, base_path_to_query_controller, parameters_json, ids_json) #:nodoc: + %/ function #{grid_name}_save_query(){\n/ + + %` if ( typeof(#{grid_name}) != "undefined")\n` + + %! #{grid_name}.save_query($('##{id_and_name}')[0].value, '#{base_path_to_query_controller}', #{parameters_json}, #{ids_json})\n! + + %/}\n/ + + %/ $('##{id_and_name}').keydown(function(event){\n/ + + %/ if (event.keyCode == 13) #{grid_name}_save_query();\n/ + + %/ })\n/ + end + + def js_framework_specific_calendar_assets(view) #:nodoc: + '' + end + + def action_column_initialization(grid_name) #:nodoc: + %! $('div##{grid_name}.wice_grid_container .select_all').click(function(e){\n! + + %! $('div##{grid_name}.wice_grid_container .sel input').each(function(i, checkbox){\n! + + %! checkbox.checked = true;\n! + + %! })\n! + + %! })\n! + + %! $('div##{grid_name}.wice_grid_container .deselect_all').click(function(e){\n! + + %! $('div##{grid_name}.wice_grid_container .sel input').each(function(i, checkbox){\n! + + %! checkbox.checked = false;\n! + + %! })\n! + + %! })\n! + end + + def fade_this #:nodoc: + 'jQuery([]).pushStack(this).fadeOut()' + end + + end +end \ No newline at end of file diff --git a/lib/js_adaptors/js_adaptor.rb b/lib/js_adaptors/js_adaptor.rb new file mode 100644 index 00000000..f769d495 --- /dev/null +++ b/lib/js_adaptors/js_adaptor.rb @@ -0,0 +1,11 @@ +# encoding: UTF-8 + +module Wice::JsAdaptor #:nodoc: + def self.init #:nodoc: + if Wice::Defaults::JS_FRAMEWORK == :prototype + require 'js_adaptors/prototype_adaptor.rb' + else + require 'js_adaptors/jquery_adaptor.rb' + end + end +end \ No newline at end of file diff --git a/lib/js_adaptors/prototype_adaptor.rb b/lib/js_adaptors/prototype_adaptor.rb new file mode 100644 index 00000000..30320e88 --- /dev/null +++ b/lib/js_adaptors/prototype_adaptor.rb @@ -0,0 +1,136 @@ +# encoding: UTF-8 +module Wice::JsAdaptor #:nodoc: + + class << self + def init #:nodoc: + end + + def dom_loaded #:nodoc: + %/ document.observe("dom:loaded", function() {\n/ + end + + def reset_button_initialization(grid_name, reset_grid_javascript) #:nodoc: + %/ $$('div##{grid_name}.wice_grid_container .reset').each(function(e){\n/+ + %/ e.observe('click', function(){\n/+ + %/ #{reset_grid_javascript};\n/+ + %/ })\n/+ + %/ });\n/ + end + + def submit_button_initialization(grid_name, submit_grid_javascript) #:nodoc: + %/ $$('div##{grid_name}.wice_grid_container .submit').each(function(e){\n/+ + %/ e.observe('click', function(){\n/+ + %/ #{submit_grid_javascript};\n/+ + %/ })\n/+ + %/ });\n/ + end + + def show_hide_button_initialization(grid_name, filter_row_id) #:nodoc: + %/ $('#{grid_name}_show_icon').observe('click', function(){\n/+ + %/ Element.toggle('#{grid_name}_show_icon');\n/+ + %/ Element.toggle('#{grid_name}_hide_icon');\n/+ + %/ $('#{filter_row_id}').show();\n/+ + %/ })\n/+ + %/ $('#{grid_name}_hide_icon').observe('click', function(){\n/+ + %/ Element.toggle('#{grid_name}_show_icon');\n/+ + %/ Element.toggle('#{grid_name}_hide_icon');\n/+ + %/ $('#{filter_row_id}').hide();\n/+ + %/ });\n/ + end + + def enter_key_event_registration(grid_name) #:nodoc: + %! $$('div##{grid_name}.wice_grid_container .wice_grid_filter_row input[type=text]').each(function(e){\n! + + %! e.observe('keydown', function(event){\n! + + %! if (event.keyCode == 13) {#{grid_name}.process()}\n! + + %! })\n! + + %! });\n! + end + + def csv_export_icon_initialization(grid_name) #:nodoc: + %! $$('div##{grid_name}.wice_grid_container .export_to_csv_button').each(function(e){\n! + + %! e.observe('click', function(event){\n! + + %! #{grid_name}.export_to_csv()\n! + + %! })\n! + + %! });\n! + end + + def auto_reloading_selects_event_initialization(grid_name) #:nodoc: + %! $$('div##{grid_name}.wice_grid_container select.auto_reload', '.#{grid_name}_detached_filter select.auto_reload').each(function(e){\n! + + %! e.observe('change', function(event){\n! + + %! #{grid_name}.process()\n! + + %! })\n! + + %! });\n! + end + + def auto_reloading_inputs_event_initialization(grid_name) #:nodoc: + %! $$('div##{grid_name}.wice_grid_container input.auto_reload', '.#{grid_name}_detached_filter input.auto_reload').each(function(e){\n! + + %! e.observe('keyup', function(event){\n! + + %! #{grid_name}.process()\n! + + %! })\n! + + %! });\n! + end + + def auto_reloading_calendar_event_initialization(grid_name) #:nodoc: + %! document.observe('wg:calendarChanged', function(event){\n! + + %! #{grid_name}.process()\n! + + %! });\n! + end + + + def show_all_link_initialization(grid_name, confirmation, parameters_json) #:nodoc: + %/ $$('div##{grid_name}.wice_grid_container .show_all_link').each(function(e){\n/ + + %/ e.observe('click', function(){\n/ + + %/ #{confirmation} #{grid_name}.reload_page_for_given_grid_state(#{parameters_json})\n/ + + %/ })\n/ + + %/ })\n/ + end + + + def back_to_pagination_link_initialization(grid_name, parameters_json) #:nodoc: + %/ $$('div##{grid_name}.wice_grid_container .show_all_link').each(function(e){\n/ + + %/ e.observe('click', function(){\n/ + + %/ #{grid_name}.reload_page_for_given_grid_state(#{parameters_json})\n/ + + %/ })\n/ + + %/ })\n/ + end + + def call_to_save_query_and_key_event_initialization_for_saving_queries( + id_and_name, grid_name, base_path_to_query_controller, parameters_json, ids_json) #:nodoc: + %/ function #{grid_name}_save_query(){\n/ + + %` if ( typeof(#{grid_name}) != "undefined")\n` + + %/ #{grid_name}.save_query($F('#{id_and_name}'), '#{base_path_to_query_controller}', #{parameters_json}, #{ids_json})\n/ + + %/ }\n/ + + %/ $('#{id_and_name}').observe('keydown', function(event){\n/ + + %/ if (event.keyCode == 13) #{grid_name}_save_query();\n/ + + %/ })\n/ + end + + + def js_framework_specific_calendar_assets(view) #:nodoc: + view.stylesheet_link_tag("calendarview.css") + view.javascript_include_tag("calendarview.js") + end + + def action_column_initialization(grid_name) #:nodoc: + %! $$('div##{grid_name}.wice_grid_container .select_all').each(function(e){\n! + + %! e.observe('click', function(){\n! + + %! $$('div##{grid_name}.wice_grid_container .sel input').each(function(checkbox){\n! + + %! checkbox.checked = true;\n! + + %! })\n! + + %! })\n! + + %! })\n! + + %! $$('div##{grid_name}.wice_grid_container .deselect_all').each(function(e){\n! + + %! e.observe('click', function(){\n! + + %! $$('div##{grid_name}.wice_grid_container .sel input').each(function(checkbox){\n! + + %! checkbox.checked = false;\n! + + %! })\n! + + %! })\n! + + %! })\n! + end + + def fade_this #:nodoc: + 'new Effect.Fade(this)' + end + + end + +end \ No newline at end of file diff --git a/lib/view_columns.rb b/lib/view_columns.rb index 32fec5e5..15f5372d 100644 --- a/lib/view_columns.rb +++ b/lib/view_columns.rb @@ -171,20 +171,8 @@ def column_name #:nodoc: content_tag(:span, image_tag(Defaults::UNTICK_ALL_ICON, :alt => deselect_all_tootip), :class => 'clickable deselect_all', :title => deselect_all_tootip) - js = %! $$('div##{grid.name}.wice_grid_container .select_all').each(function(e){\n! + - %! e.observe('click', function(){\n! + - %! $$('div##{grid.name}.wice_grid_container .sel input').each(function(checkbox){\n! + - %! checkbox.checked = true;\n! + - %! })\n! + - %! })\n! + - %! })\n! + - %! $$('div##{grid.name}.wice_grid_container .deselect_all').each(function(e){\n! + - %! e.observe('click', function(){\n! + - %! $$('div##{grid.name}.wice_grid_container .sel input').each(function(checkbox){\n! + - %! checkbox.checked = false;\n! + - %! })\n! + - %! })\n! + - %! })\n! + js = JsAdaptor.action_column_initialization(grid.name) + [html, js] end @@ -255,7 +243,7 @@ def render_filter_internal(params) #:nodoc: select_options[:multiple] = params.is_a?(Array) && params.size > 1 select_toggle = content_tag(:a, tag(:img, :alt => 'Expand/Collapse', :src => Defaults::TOGGLE_MULTI_SELECT_ICON), - :href => "javascript: toggle_multi_select('#{@dom_id}', this, 'Expand', 'Collapse');", + :href => "javascript: toggle_multi_select('#{@dom_id}', this, 'Expand', 'Collapse');", # TO DO: to locales :class => 'toggle_multi_select_icon', :title => 'Expand') else select_options[:multiple] = false @@ -282,7 +270,6 @@ def has_auto_reloading_select? #:nodoc: end end - class ViewColumnBoolean < ViewColumnCustomDropdown #:nodoc: @@handled_type[:boolean] = self include ActionView::Helpers::FormOptionsHelper @@ -298,7 +285,6 @@ def render_filter_internal(params) #:nodoc: end end - class ViewColumnDatetime < ViewColumn #:nodoc: @@handled_type[:datetime] = self @@handled_type[:timestamp] = self @@ -357,7 +343,7 @@ def render_calendar_filter_internal(params) #:nodoc: def render_filter_internal(params) #:nodoc: - if helper_style == :standard + if helper_style == :standard || Defaults::JS_FRAMEWORK == :jquery prepare_for_standard_filter render_standard_filter_internal(params) else @@ -400,8 +386,6 @@ def render_calendar_filter_internal(params) #:nodoc: end end - - class ViewColumnString < ViewColumn #:nodoc: @@handled_type[:string] = self @@handled_type[:text] = self diff --git a/lib/views/create.rjs b/lib/views/create.rjs index c06d5612..9ed39a3a 100644 --- a/lib/views/create.rjs +++ b/lib/views/create.rjs @@ -10,4 +10,4 @@ else page.replace_html(@grid_title_id, content_tag(:h3,@saved_query.name)) end -page[@notification_messages_dom_id].visual_effect :appear +page[@notification_messages_dom_id].show diff --git a/lib/views/delete.rjs b/lib/views/delete.rjs index 224017e9..7813ca9c 100644 --- a/lib/views/delete.rjs +++ b/lib/views/delete.rjs @@ -9,4 +9,4 @@ else page[@query_list_dom_id].visual_effect :highlight end -page[@notification_messages_dom_id].visual_effect :appear +page[@notification_messages_dom_id].show \ No newline at end of file diff --git a/lib/wice_grid.rb b/lib/wice_grid.rb index baa8060f..2cf0dbb6 100644 --- a/lib/wice_grid.rb +++ b/lib/wice_grid.rb @@ -1,7 +1,6 @@ # encoding: UTF-8 require 'will_paginate.rb' require 'wice_grid_misc.rb' -require 'helpers/js_calendar_helpers.rb' require 'wice_grid_core_ext.rb' require 'grid_renderer.rb' require 'table_column_matrix.rb' @@ -9,11 +8,15 @@ require 'helpers/wice_grid_view_helpers.rb' require 'helpers/wice_grid_misc_view_helpers.rb' require 'helpers/wice_grid_serialized_queries_view_helpers.rb' +require 'helpers/js_calendar_helpers_prototype.rb' require 'view_columns.rb' require 'grid_output_buffer.rb' require 'wice_grid_controller.rb' require 'wice_grid_spreadsheet.rb' require 'wice_grid_serialized_queries_controller.rb' +require 'js_adaptors/js_adaptor.rb' + + module Wice diff --git a/lib/wice_grid_controller.rb b/lib/wice_grid_controller.rb index 3340e9ad..ce223bd2 100644 --- a/lib/wice_grid_controller.rb +++ b/lib/wice_grid_controller.rb @@ -65,6 +65,7 @@ def save_wice_grid_queries def initialize_grid(klass, opts = {}) + Wice::JsAdaptor.init @__wice_grid_on_page = true wg = WiceGrid.new(klass, self, opts) self.wice_grid_instances = [] if self.wice_grid_instances.nil? From fc14ca99bd27d9652cd2b7790c063bf6cc89e915 Mon Sep 17 00:00:00 2001 From: Yuri Leikind Date: Mon, 19 Jul 2010 19:24:25 +0200 Subject: [PATCH 2/5] adding JsAdaptor for include_wice_grid_assets & Co --- lib/helpers/wice_grid_misc_view_helpers.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/helpers/wice_grid_misc_view_helpers.rb b/lib/helpers/wice_grid_misc_view_helpers.rb index 882f6a31..a1d68fd9 100644 --- a/lib/helpers/wice_grid_misc_view_helpers.rb +++ b/lib/helpers/wice_grid_misc_view_helpers.rb @@ -3,18 +3,18 @@ module Wice module GridViewHelper # +wice_grid_custom_filter_params+ generates HTTP parameters understood by WiceGrid custom filters. - # Combined with Rails route helpers it allows to generate links leading to + # Combined with Rails route helpers it allows to generate links leading to # grids with pre-selected custom filters. # # Parameters: - # * :grid_name - The name of the grid. Just like parameter :name of + # * :grid_name - The name of the grid. Just like parameter :name of # initialize_grid, the parameter is optional, and when absent, the name # 'grid' is assumed - # * :attribute_name and :model_class - should be the same as :attribute_name and + # * :attribute_name and :model_class - should be the same as :attribute_name and # :model_class of the column declaration with the target custom filter. # * :value - the value of the column filter. def wice_grid_custom_filter_params(opts = {}) - options = {:grid_name => 'grid', + options = {:grid_name => 'grid', :attribute_name => nil, :model_class => nil, :value => nil} @@ -95,7 +95,7 @@ def scaffolded_grid(grid_obj, opts = {}) #:nodoc: # but it's possible not to include them setting parameter +include_calendar+ to false: # <%= include_wice_grid_assets(:include_calendar => false) %> def include_wice_grid_assets(options = {}) - + Wice::JsAdaptor.init opts = {:include_calendar => true, :load_on_demand => true} options.assert_valid_keys(opts.keys) opts.merge!(options) @@ -119,6 +119,7 @@ def include_wice_grid_assets(options = {}) # By default +names_of_wice_grid_javascripts+ returns all javascripts, but it's possible not to include calendar widget javascripts by # setting parameter :include_calendar to +false+. def names_of_wice_grid_javascripts(options = {}) + Wice::JsAdaptor.init opts = {:include_calendar => true} options.assert_valid_keys(opts.keys) opts.merge!(options) @@ -135,6 +136,7 @@ def names_of_wice_grid_javascripts(options = {}) # By default +names_of_wice_grid_stylesheets+ returns all javascripts, but it's possible not to include calendar widget javascripts by # setting parameter :include_calendar to +false+. def names_of_wice_grid_stylesheets(options = {}) + Wice::JsAdaptor.init opts = {:include_calendar => true} options.assert_valid_keys(opts.keys) opts.merge!(options) From 79fd747de9c4314decce442edf5fe677f540fa51 Mon Sep 17 00:00:00 2001 From: Yuri Leikind Date: Wed, 25 Aug 2010 18:35:28 +0200 Subject: [PATCH 3/5] Filter autoreloading improvement: the text input which caused autoreloading is focused after the page reload. Only for Prototype in this commit. --- .../templates/javascripts/wice_grid_prototype.js | 14 +++++++++----- lib/grid_renderer.rb | 5 +++++ lib/helpers/wice_grid_view_helpers.rb | 10 ++++++++-- lib/js_adaptors/prototype_adaptor.rb | 8 +++++++- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/generators/wice_grid_assets_prototype/templates/javascripts/wice_grid_prototype.js b/generators/wice_grid_assets_prototype/templates/javascripts/wice_grid_prototype.js index 71ddcb8c..f4b20b7a 100644 --- a/generators/wice_grid_assets_prototype/templates/javascripts/wice_grid_prototype.js +++ b/generators/wice_grid_assets_prototype/templates/javascripts/wice_grid_prototype.js @@ -1,5 +1,5 @@ function WiceGridProcessor(name, base_request_for_filter, base_link_for_show_all_records, - link_for_export, parameter_name_for_query_loading, environment){ + link_for_export, parameter_name_for_query_loading, parameter_name_for_focus, environment){ this.checkIfJsFrameworkIsLoaded = function(){ if (typeof(Prototype) == "undefined"){ @@ -11,6 +11,7 @@ function WiceGridProcessor(name, base_request_for_filter, base_link_for_show_all this.checkIfJsFrameworkIsLoaded(); this.name = name; this.parameter_name_for_query_loading = parameter_name_for_query_loading; + this.parameter_name_for_focus = parameter_name_for_focus; this.base_request_for_filter = base_request_for_filter; this.base_link_for_show_all_records = base_link_for_show_all_records; this.link_for_export = link_for_export; @@ -22,8 +23,8 @@ function WiceGridProcessor(name, base_request_for_filter, base_link_for_show_all } - this.process = function(){ - window.location = this.build_url_with_params(); + this.process = function(dom_id_to_focus){ + window.location = this.build_url_with_params(dom_id_to_focus); } this.reload_page_for_given_grid_state = function(grid_state){ @@ -75,7 +76,7 @@ function WiceGridProcessor(name, base_request_for_filter, base_link_for_show_all } - this.build_url_with_params = function(){ + this.build_url_with_params = function(dom_id_to_focus){ var results = new Array(); this.filter_declarations.each(function(filter_declaration){ param = this.read_values_and_form_query_string( @@ -90,6 +91,9 @@ function WiceGridProcessor(name, base_request_for_filter, base_link_for_show_all all_filter_params = results.join('&'); res = this.append_to_url(res, all_filter_params); } + if (dom_id_to_focus){ + res = this.append_to_url(res, this.parameter_name_for_focus + dom_id_to_focus); + } return res; } @@ -146,4 +150,4 @@ function toggle_multi_select(select_id, link_obj, expand_label, collapse_label) } } -WiceGridProcessor._version = '0.4.1'; +WiceGridProcessor._version = '0.4.2'; diff --git a/lib/grid_renderer.rb b/lib/grid_renderer.rb index 6def43e2..c314caba 100644 --- a/lib/grid_renderer.rb +++ b/lib/grid_renderer.rb @@ -118,6 +118,10 @@ def pagination_panel(no_rightmost_column, hide_csv_button) #:nodoc: end end + def element_to_focus #:nodoc: + grid.status['foc'] + end + # Adds a column with checkboxes for each record. Useful for actions with multiple records, for example, deleting # selected records. Please note that +action_column+ only creates the checkboxes and the 'Select All' and @@ -443,6 +447,7 @@ def base_link_for_filter(controller, extra_parameters = {}) #:nodoc: if new_params[@grid.name] new_params[@grid.name].delete(:page) # we reset paging here new_params[@grid.name].delete(:f) # no filter for the base url + new_params[@grid.name].delete(:foc) # nullify the focus new_params[@grid.name].delete(:q) # and no request for the saved query end diff --git a/lib/helpers/wice_grid_view_helpers.rb b/lib/helpers/wice_grid_view_helpers.rb index e0f94438..e5699c10 100644 --- a/lib/helpers/wice_grid_view_helpers.rb +++ b/lib/helpers/wice_grid_view_helpers.rb @@ -482,6 +482,7 @@ def grid_html(grid, options, rendering, reuse_last_column_for_filter_buttons) #: link_for_export = rendering.link_for_export(controller, 'csv', options[:extra_request_parameters]) parameter_name_for_query_loading = {grid.name => {:q => ''}}.to_query + parameter_name_for_focus = {grid.name => {:foc => ''}}.to_query prototype_and_js_version_check = if ENV['RAILS_ENV'] == 'development' %$ if (typeof(WiceGridProcessor) == "undefined"){\n$ + @@ -489,7 +490,7 @@ def grid_html(grid, options, rendering, reuse_last_column_for_filter_buttons) #: %$ 'Please make sure that you include WiceGrid javascript in your page. ' +\n$ + %$ 'Use <%= include_wice_grid_assets %> or <%= include_wice_grid_assets(:include_calendar => true) %> ' +\n$ + %$ 'for WiceGrid javascripts and assets.')\n$ + - %$ } else if ((typeof(WiceGridProcessor._version) == "undefined") || ( WiceGridProcessor._version != "0.4.1")) {\n$ + + %$ } else if ((typeof(WiceGridProcessor._version) == "undefined") || ( WiceGridProcessor._version != "0.4.2")) {\n$ + %$ alert("wice_grid.js in your /public is outdated, please run\\n ./script/generate wice_grid_assets\\nto update it.");\n$ + %$ }\n$ else @@ -528,11 +529,16 @@ def grid_html(grid, options, rendering, reuse_last_column_for_filter_buttons) #: cached_javascript << JsAdaptor.auto_reloading_calendar_event_initialization(grid.name) end + if rendering.element_to_focus + cached_javascript << JsAdaptor.focus_element(rendering.element_to_focus) + end + content << javascript_tag( JsAdaptor.dom_loaded + %/ #{prototype_and_js_version_check}\n/ + %/ window['#{grid.name}'] = new WiceGridProcessor('#{grid.name}', '#{base_link_for_filter}',\n/ + - %/ '#{base_link_for_show_all_records}', '#{link_for_export}', '#{parameter_name_for_query_loading}', '#{ENV['RAILS_ENV']}');\n/ + + %/ '#{base_link_for_show_all_records}', '#{link_for_export}', '#{parameter_name_for_query_loading}',\n/ + + %/ '#{parameter_name_for_focus}', '#{ENV['RAILS_ENV']}');\n/ + if no_filters_at_all '' else diff --git a/lib/js_adaptors/prototype_adaptor.rb b/lib/js_adaptors/prototype_adaptor.rb index 30320e88..fde5b7a1 100644 --- a/lib/js_adaptors/prototype_adaptor.rb +++ b/lib/js_adaptors/prototype_adaptor.rb @@ -65,7 +65,7 @@ def auto_reloading_selects_event_initialization(grid_name) #:nodoc: def auto_reloading_inputs_event_initialization(grid_name) #:nodoc: %! $$('div##{grid_name}.wice_grid_container input.auto_reload', '.#{grid_name}_detached_filter input.auto_reload').each(function(e){\n! + %! e.observe('keyup', function(event){\n! + - %! #{grid_name}.process()\n! + + %! #{grid_name}.process(event.element().id)\n! + %! })\n! + %! });\n! end @@ -131,6 +131,12 @@ def fade_this #:nodoc: 'new Effect.Fade(this)' end + def focus_element(element_to_focus) + %! var elToFocus = $('#{element_to_focus}');\n! + + %! elToFocus.focus();\n! + + %! elToFocus.value = elToFocus.value;\n! # this will just place the cursor at the end of the text input + end + end end \ No newline at end of file From e79c6c67dbb1a6f1ac92b072184df1a69ee94c7f Mon Sep 17 00:00:00 2001 From: Yuri Leikind Date: Thu, 26 Aug 2010 15:08:47 +0200 Subject: [PATCH 4/5] jQuery: Filter autoreloading improvement: the text input which caused autoreloading is focused after the page reload. --- .../templates/javascripts/wice_grid_jquery.js | 14 +++++++++----- lib/js_adaptors/jquery_adaptor.rb | 14 ++++++++++++-- lib/js_adaptors/prototype_adaptor.rb | 2 +- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/generators/wice_grid_assets_jquery/templates/javascripts/wice_grid_jquery.js b/generators/wice_grid_assets_jquery/templates/javascripts/wice_grid_jquery.js index 5c575e31..32193129 100644 --- a/generators/wice_grid_assets_jquery/templates/javascripts/wice_grid_jquery.js +++ b/generators/wice_grid_assets_jquery/templates/javascripts/wice_grid_jquery.js @@ -1,5 +1,5 @@ function WiceGridProcessor(name, base_request_for_filter, base_link_for_show_all_records, - link_for_export, parameter_name_for_query_loading, environment){ + link_for_export, parameter_name_for_query_loading, parameter_name_for_focus, environment){ this.checkIfJsFrameworkIsLoaded = function(){ if (! jQuery){ @@ -10,6 +10,7 @@ function WiceGridProcessor(name, base_request_for_filter, base_link_for_show_all this.checkIfJsFrameworkIsLoaded(); this.name = name; this.parameter_name_for_query_loading = parameter_name_for_query_loading; + this.parameter_name_for_focus = parameter_name_for_focus; this.base_request_for_filter = base_request_for_filter; this.base_link_for_show_all_records = base_link_for_show_all_records; this.link_for_export = link_for_export; @@ -21,8 +22,8 @@ function WiceGridProcessor(name, base_request_for_filter, base_link_for_show_all } - this.process = function(){ - window.location = this.build_url_with_params(); + this.process = function(dom_id_to_focus){ + window.location = this.build_url_with_params(dom_id_to_focus); } this.reload_page_for_given_grid_state = function(grid_state){ @@ -76,7 +77,7 @@ function WiceGridProcessor(name, base_request_for_filter, base_link_for_show_all } - this.build_url_with_params = function(){ + this.build_url_with_params = function(dom_id_to_focus){ var results = new Array(); var _this = this; jQuery.each(this.filter_declarations, function(i, filter_declaration){ @@ -93,6 +94,9 @@ function WiceGridProcessor(name, base_request_for_filter, base_link_for_show_all all_filter_params = results.join('&'); res = this.append_to_url(res, all_filter_params); } + if (dom_id_to_focus){ + res = this.append_to_url(res, this.parameter_name_for_focus + dom_id_to_focus); + } return res; } @@ -148,4 +152,4 @@ function toggle_multi_select(select_id, link_obj, expand_label, collapse_label) } } -WiceGridProcessor._version = '0.4.1'; +WiceGridProcessor._version = '0.4.2'; diff --git a/lib/js_adaptors/jquery_adaptor.rb b/lib/js_adaptors/jquery_adaptor.rb index 4078626d..26ba711e 100644 --- a/lib/js_adaptors/jquery_adaptor.rb +++ b/lib/js_adaptors/jquery_adaptor.rb @@ -53,8 +53,8 @@ def auto_reloading_selects_event_initialization(grid_name) #:nodoc: end def auto_reloading_inputs_event_initialization(grid_name) #:nodoc: - %! $('div##{grid_name}.wice_grid_container input.auto_reload, .#{grid_name}_detached_filter input.auto_reload').keyup(function(e){\n! + - %! #{grid_name}.process()\n! + + %! $('div##{grid_name}.wice_grid_container input.auto_reload, .#{grid_name}_detached_filter input.auto_reload').keyup(function(event, element){\n! + + %! #{grid_name}.process(this.id);\n! + %! });\n! end @@ -106,5 +106,15 @@ def fade_this #:nodoc: 'jQuery([]).pushStack(this).fadeOut()' end + def focus_element(element_to_focus) #:nodoc: + %! var elements = $('##{element_to_focus}');\n! + + %! if (elements[0]){\n! + + %! var elToFocus = elements[0];\n! + + %! elToFocus.value = elToFocus.value;\n! + # this will just place the cursor at the end of the text input + %! elToFocus.focus();\n! + + %! }\n! + end + + end end \ No newline at end of file diff --git a/lib/js_adaptors/prototype_adaptor.rb b/lib/js_adaptors/prototype_adaptor.rb index fde5b7a1..383d537f 100644 --- a/lib/js_adaptors/prototype_adaptor.rb +++ b/lib/js_adaptors/prototype_adaptor.rb @@ -131,7 +131,7 @@ def fade_this #:nodoc: 'new Effect.Fade(this)' end - def focus_element(element_to_focus) + def focus_element(element_to_focus) #:nodoc: %! var elToFocus = $('#{element_to_focus}');\n! + %! elToFocus.focus();\n! + %! elToFocus.value = elToFocus.value;\n! # this will just place the cursor at the end of the text input From 0eec4303ae86121d3224b2c7a12384f9dba29ea6 Mon Sep 17 00:00:00 2001 From: Yuri Leikind Date: Thu, 26 Aug 2010 15:20:55 +0200 Subject: [PATCH 5/5] changed the way JS adaptors are loaded at runtime --- lib/js_adaptors/jquery_adaptor.rb | 232 ++++++++++++----------- lib/js_adaptors/js_adaptor.rb | 4 +- lib/js_adaptors/prototype_adaptor.rb | 274 ++++++++++++++------------- lib/wice_grid.rb | 2 + 4 files changed, 265 insertions(+), 247 deletions(-) diff --git a/lib/js_adaptors/jquery_adaptor.rb b/lib/js_adaptors/jquery_adaptor.rb index 26ba711e..c68f9f64 100644 --- a/lib/js_adaptors/jquery_adaptor.rb +++ b/lib/js_adaptors/jquery_adaptor.rb @@ -1,120 +1,128 @@ # encoding: UTF-8 module Wice::JsAdaptor #:nodoc: - class << self - def init #:nodoc: - end - - def dom_loaded #:nodoc: - %/$(document).ready(function(){\n/ - end - - def reset_button_initialization(grid_name, reset_grid_javascript) #:nodoc: - %/ $('div##{grid_name}.wice_grid_container .reset').click(function(e){\n/+ - %/ #{reset_grid_javascript};\n/+ - %/ });\n/ - end - - def submit_button_initialization(grid_name, submit_grid_javascript) #:nodoc: - %/ $('div##{grid_name}.wice_grid_container .submit').click(function(e){\n/+ - %/ #{submit_grid_javascript};\n/+ - %/ });\n/ - end - - def show_hide_button_initialization(grid_name, filter_row_id) #:nodoc: - %/ $('##{grid_name}_show_icon').click(function(){\n/+ - %/ $('##{grid_name}_show_icon').hide();\n/+ - %/ $('##{grid_name}_hide_icon').show();\n/+ - %/ $('##{filter_row_id}').show();\n/+ - %/ })\n/+ - %/ $('##{grid_name}_hide_icon').click(function(){\n/+ - %/ $('##{grid_name}_show_icon').show();\n/+ - %/ $('##{grid_name}_hide_icon').hide();\n/+ - %/ $('##{filter_row_id}').hide();\n/+ - %/ });\n/ - end - - def enter_key_event_registration(grid_name) #:nodoc: - %! $('div##{grid_name}.wice_grid_container .wice_grid_filter_row input[type=text]').keydown(function(event){\n! + - %! if (event.keyCode == 13) {#{grid_name}.process()}\n! + - %! });\n! - end - - def csv_export_icon_initialization(grid_name) #:nodoc: - %! $('div##{grid_name}.wice_grid_container .export_to_csv_button').click(function(e){\n! + - %! #{grid_name}.export_to_csv()\n! + - %! });\n! - end - - def auto_reloading_selects_event_initialization(grid_name) #:nodoc: - %! $('div##{grid_name}.wice_grid_container select.auto_reload, .#{grid_name}_detached_filter select.auto_reload').change(function(e){\n! + - %! #{grid_name}.process()\n! + - %! });\n! - end + module Jquery + + def self.included(base) + base.extend(ClassMethods) + end + + module ClassMethods + + def init #:nodoc: + end + + def dom_loaded #:nodoc: + %/$(document).ready(function(){\n/ + end + + def reset_button_initialization(grid_name, reset_grid_javascript) #:nodoc: + %/ $('div##{grid_name}.wice_grid_container .reset').click(function(e){\n/+ + %/ #{reset_grid_javascript};\n/+ + %/ });\n/ + end + + def submit_button_initialization(grid_name, submit_grid_javascript) #:nodoc: + %/ $('div##{grid_name}.wice_grid_container .submit').click(function(e){\n/+ + %/ #{submit_grid_javascript};\n/+ + %/ });\n/ + end + + def show_hide_button_initialization(grid_name, filter_row_id) #:nodoc: + %/ $('##{grid_name}_show_icon').click(function(){\n/+ + %/ $('##{grid_name}_show_icon').hide();\n/+ + %/ $('##{grid_name}_hide_icon').show();\n/+ + %/ $('##{filter_row_id}').show();\n/+ + %/ })\n/+ + %/ $('##{grid_name}_hide_icon').click(function(){\n/+ + %/ $('##{grid_name}_show_icon').show();\n/+ + %/ $('##{grid_name}_hide_icon').hide();\n/+ + %/ $('##{filter_row_id}').hide();\n/+ + %/ });\n/ + end + + def enter_key_event_registration(grid_name) #:nodoc: + %! $('div##{grid_name}.wice_grid_container .wice_grid_filter_row input[type=text]').keydown(function(event){\n! + + %! if (event.keyCode == 13) {#{grid_name}.process()}\n! + + %! });\n! + end + + def csv_export_icon_initialization(grid_name) #:nodoc: + %! $('div##{grid_name}.wice_grid_container .export_to_csv_button').click(function(e){\n! + + %! #{grid_name}.export_to_csv()\n! + + %! });\n! + end + + def auto_reloading_selects_event_initialization(grid_name) #:nodoc: + %! $('div##{grid_name}.wice_grid_container select.auto_reload, .#{grid_name}_detached_filter select.auto_reload').change(function(e){\n! + + %! #{grid_name}.process()\n! + + %! });\n! + end + + def auto_reloading_inputs_event_initialization(grid_name) #:nodoc: + %! $('div##{grid_name}.wice_grid_container input.auto_reload, .#{grid_name}_detached_filter input.auto_reload').keyup(function(event, element){\n! + + %! #{grid_name}.process(this.id);\n! + + %! });\n! + end + + def auto_reloading_calendar_event_initialization(grid_name) #:nodoc: + '' # TO DO jquery calendar is not yet here + end + + def show_all_link_initialization(grid_name, confirmation, parameters_json) #:nodoc: + %/ $('div##{grid_name}.wice_grid_container .show_all_link').click(function(e){ \n/ + + %/ #{confirmation} #{grid_name}.reload_page_for_given_grid_state(#{parameters_json}) \n/ + + %/})\n/ + end + + def back_to_pagination_link_initialization(grid_name, parameters_json) #:nodoc: + %/ $('div##{grid_name}.wice_grid_container .show_all_link').click(function(e){\n/ + + %/ #{grid_name}.reload_page_for_given_grid_state(#{parameters_json})\n/ + + %/ })\n/ + end + + def call_to_save_query_and_key_event_initialization_for_saving_queries( + id_and_name, grid_name, base_path_to_query_controller, parameters_json, ids_json) #:nodoc: + %/ function #{grid_name}_save_query(){\n/ + + %` if ( typeof(#{grid_name}) != "undefined")\n` + + %! #{grid_name}.save_query($('##{id_and_name}')[0].value, '#{base_path_to_query_controller}', #{parameters_json}, #{ids_json})\n! + + %/}\n/ + + %/ $('##{id_and_name}').keydown(function(event){\n/ + + %/ if (event.keyCode == 13) #{grid_name}_save_query();\n/ + + %/ })\n/ + end + + def js_framework_specific_calendar_assets(view) #:nodoc: + '' + end + + def action_column_initialization(grid_name) #:nodoc: + %! $('div##{grid_name}.wice_grid_container .select_all').click(function(e){\n! + + %! $('div##{grid_name}.wice_grid_container .sel input').each(function(i, checkbox){\n! + + %! checkbox.checked = true;\n! + + %! })\n! + + %! })\n! + + %! $('div##{grid_name}.wice_grid_container .deselect_all').click(function(e){\n! + + %! $('div##{grid_name}.wice_grid_container .sel input').each(function(i, checkbox){\n! + + %! checkbox.checked = false;\n! + + %! })\n! + + %! })\n! + end + + def fade_this #:nodoc: + 'jQuery([]).pushStack(this).fadeOut()' + end + + def focus_element(element_to_focus) #:nodoc: + %! var elements = $('##{element_to_focus}');\n! + + %! if (elements[0]){\n! + + %! var elToFocus = elements[0];\n! + + %! elToFocus.value = elToFocus.value;\n! + # this will just place the cursor at the end of the text input + %! elToFocus.focus();\n! + + %! }\n! + end - def auto_reloading_inputs_event_initialization(grid_name) #:nodoc: - %! $('div##{grid_name}.wice_grid_container input.auto_reload, .#{grid_name}_detached_filter input.auto_reload').keyup(function(event, element){\n! + - %! #{grid_name}.process(this.id);\n! + - %! });\n! end - def auto_reloading_calendar_event_initialization(grid_name) #:nodoc: - '' # TO DO jquery calendar is not yet here - end - - def show_all_link_initialization(grid_name, confirmation, parameters_json) #:nodoc: - %/ $('div##{grid_name}.wice_grid_container .show_all_link').click(function(e){ \n/ + - %/ #{confirmation} #{grid_name}.reload_page_for_given_grid_state(#{parameters_json}) \n/ + - %/})\n/ - end - - def back_to_pagination_link_initialization(grid_name, parameters_json) #:nodoc: - %/ $('div##{grid_name}.wice_grid_container .show_all_link').click(function(e){\n/ + - %/ #{grid_name}.reload_page_for_given_grid_state(#{parameters_json})\n/ + - %/ })\n/ - end - - def call_to_save_query_and_key_event_initialization_for_saving_queries( - id_and_name, grid_name, base_path_to_query_controller, parameters_json, ids_json) #:nodoc: - %/ function #{grid_name}_save_query(){\n/ + - %` if ( typeof(#{grid_name}) != "undefined")\n` + - %! #{grid_name}.save_query($('##{id_and_name}')[0].value, '#{base_path_to_query_controller}', #{parameters_json}, #{ids_json})\n! + - %/}\n/ + - %/ $('##{id_and_name}').keydown(function(event){\n/ + - %/ if (event.keyCode == 13) #{grid_name}_save_query();\n/ + - %/ })\n/ - end - - def js_framework_specific_calendar_assets(view) #:nodoc: - '' - end - - def action_column_initialization(grid_name) #:nodoc: - %! $('div##{grid_name}.wice_grid_container .select_all').click(function(e){\n! + - %! $('div##{grid_name}.wice_grid_container .sel input').each(function(i, checkbox){\n! + - %! checkbox.checked = true;\n! + - %! })\n! + - %! })\n! + - %! $('div##{grid_name}.wice_grid_container .deselect_all').click(function(e){\n! + - %! $('div##{grid_name}.wice_grid_container .sel input').each(function(i, checkbox){\n! + - %! checkbox.checked = false;\n! + - %! })\n! + - %! })\n! - end - - def fade_this #:nodoc: - 'jQuery([]).pushStack(this).fadeOut()' - end - - def focus_element(element_to_focus) #:nodoc: - %! var elements = $('##{element_to_focus}');\n! + - %! if (elements[0]){\n! + - %! var elToFocus = elements[0];\n! + - %! elToFocus.value = elToFocus.value;\n! + # this will just place the cursor at the end of the text input - %! elToFocus.focus();\n! + - %! }\n! - end - - end end \ No newline at end of file diff --git a/lib/js_adaptors/js_adaptor.rb b/lib/js_adaptors/js_adaptor.rb index f769d495..eadc8790 100644 --- a/lib/js_adaptors/js_adaptor.rb +++ b/lib/js_adaptors/js_adaptor.rb @@ -3,9 +3,9 @@ module Wice::JsAdaptor #:nodoc: def self.init #:nodoc: if Wice::Defaults::JS_FRAMEWORK == :prototype - require 'js_adaptors/prototype_adaptor.rb' + include Wice::JsAdaptor::Prototype else - require 'js_adaptors/jquery_adaptor.rb' + include Wice::JsAdaptor::Jquery end end end \ No newline at end of file diff --git a/lib/js_adaptors/prototype_adaptor.rb b/lib/js_adaptors/prototype_adaptor.rb index 383d537f..2f901aaa 100644 --- a/lib/js_adaptors/prototype_adaptor.rb +++ b/lib/js_adaptors/prototype_adaptor.rb @@ -1,140 +1,148 @@ # encoding: UTF-8 module Wice::JsAdaptor #:nodoc: - class << self - def init #:nodoc: - end - - def dom_loaded #:nodoc: - %/ document.observe("dom:loaded", function() {\n/ - end - - def reset_button_initialization(grid_name, reset_grid_javascript) #:nodoc: - %/ $$('div##{grid_name}.wice_grid_container .reset').each(function(e){\n/+ - %/ e.observe('click', function(){\n/+ - %/ #{reset_grid_javascript};\n/+ - %/ })\n/+ - %/ });\n/ - end - - def submit_button_initialization(grid_name, submit_grid_javascript) #:nodoc: - %/ $$('div##{grid_name}.wice_grid_container .submit').each(function(e){\n/+ - %/ e.observe('click', function(){\n/+ - %/ #{submit_grid_javascript};\n/+ - %/ })\n/+ - %/ });\n/ - end - - def show_hide_button_initialization(grid_name, filter_row_id) #:nodoc: - %/ $('#{grid_name}_show_icon').observe('click', function(){\n/+ - %/ Element.toggle('#{grid_name}_show_icon');\n/+ - %/ Element.toggle('#{grid_name}_hide_icon');\n/+ - %/ $('#{filter_row_id}').show();\n/+ - %/ })\n/+ - %/ $('#{grid_name}_hide_icon').observe('click', function(){\n/+ - %/ Element.toggle('#{grid_name}_show_icon');\n/+ - %/ Element.toggle('#{grid_name}_hide_icon');\n/+ - %/ $('#{filter_row_id}').hide();\n/+ - %/ });\n/ - end - - def enter_key_event_registration(grid_name) #:nodoc: - %! $$('div##{grid_name}.wice_grid_container .wice_grid_filter_row input[type=text]').each(function(e){\n! + - %! e.observe('keydown', function(event){\n! + - %! if (event.keyCode == 13) {#{grid_name}.process()}\n! + - %! })\n! + - %! });\n! - end - - def csv_export_icon_initialization(grid_name) #:nodoc: - %! $$('div##{grid_name}.wice_grid_container .export_to_csv_button').each(function(e){\n! + - %! e.observe('click', function(event){\n! + - %! #{grid_name}.export_to_csv()\n! + - %! })\n! + - %! });\n! - end - - def auto_reloading_selects_event_initialization(grid_name) #:nodoc: - %! $$('div##{grid_name}.wice_grid_container select.auto_reload', '.#{grid_name}_detached_filter select.auto_reload').each(function(e){\n! + - %! e.observe('change', function(event){\n! + - %! #{grid_name}.process()\n! + - %! })\n! + - %! });\n! - end - - def auto_reloading_inputs_event_initialization(grid_name) #:nodoc: - %! $$('div##{grid_name}.wice_grid_container input.auto_reload', '.#{grid_name}_detached_filter input.auto_reload').each(function(e){\n! + - %! e.observe('keyup', function(event){\n! + - %! #{grid_name}.process(event.element().id)\n! + - %! })\n! + - %! });\n! - end - - def auto_reloading_calendar_event_initialization(grid_name) #:nodoc: - %! document.observe('wg:calendarChanged', function(event){\n! + - %! #{grid_name}.process()\n! + - %! });\n! - end - - - def show_all_link_initialization(grid_name, confirmation, parameters_json) #:nodoc: - %/ $$('div##{grid_name}.wice_grid_container .show_all_link').each(function(e){\n/ + - %/ e.observe('click', function(){\n/ + - %/ #{confirmation} #{grid_name}.reload_page_for_given_grid_state(#{parameters_json})\n/ + - %/ })\n/ + - %/ })\n/ - end - - - def back_to_pagination_link_initialization(grid_name, parameters_json) #:nodoc: - %/ $$('div##{grid_name}.wice_grid_container .show_all_link').each(function(e){\n/ + - %/ e.observe('click', function(){\n/ + - %/ #{grid_name}.reload_page_for_given_grid_state(#{parameters_json})\n/ + - %/ })\n/ + - %/ })\n/ - end - - def call_to_save_query_and_key_event_initialization_for_saving_queries( - id_and_name, grid_name, base_path_to_query_controller, parameters_json, ids_json) #:nodoc: - %/ function #{grid_name}_save_query(){\n/ + - %` if ( typeof(#{grid_name}) != "undefined")\n` + - %/ #{grid_name}.save_query($F('#{id_and_name}'), '#{base_path_to_query_controller}', #{parameters_json}, #{ids_json})\n/ + - %/ }\n/ + - %/ $('#{id_and_name}').observe('keydown', function(event){\n/ + - %/ if (event.keyCode == 13) #{grid_name}_save_query();\n/ + - %/ })\n/ - end - - - def js_framework_specific_calendar_assets(view) #:nodoc: - view.stylesheet_link_tag("calendarview.css") + view.javascript_include_tag("calendarview.js") - end - - def action_column_initialization(grid_name) #:nodoc: - %! $$('div##{grid_name}.wice_grid_container .select_all').each(function(e){\n! + - %! e.observe('click', function(){\n! + - %! $$('div##{grid_name}.wice_grid_container .sel input').each(function(checkbox){\n! + - %! checkbox.checked = true;\n! + - %! })\n! + - %! })\n! + - %! })\n! + - %! $$('div##{grid_name}.wice_grid_container .deselect_all').each(function(e){\n! + - %! e.observe('click', function(){\n! + - %! $$('div##{grid_name}.wice_grid_container .sel input').each(function(checkbox){\n! + - %! checkbox.checked = false;\n! + - %! })\n! + - %! })\n! + - %! })\n! - end - - def fade_this #:nodoc: - 'new Effect.Fade(this)' - end + module Prototype + + def self.included(base) + base.extend(ClassMethods) + end + + module ClassMethods + def init #:nodoc: + end + + def dom_loaded #:nodoc: + %/ document.observe("dom:loaded", function() {\n/ + end + + def reset_button_initialization(grid_name, reset_grid_javascript) #:nodoc: + %/ $$('div##{grid_name}.wice_grid_container .reset').each(function(e){\n/+ + %/ e.observe('click', function(){\n/+ + %/ #{reset_grid_javascript};\n/+ + %/ })\n/+ + %/ });\n/ + end + + def submit_button_initialization(grid_name, submit_grid_javascript) #:nodoc: + %/ $$('div##{grid_name}.wice_grid_container .submit').each(function(e){\n/+ + %/ e.observe('click', function(){\n/+ + %/ #{submit_grid_javascript};\n/+ + %/ })\n/+ + %/ });\n/ + end + + def show_hide_button_initialization(grid_name, filter_row_id) #:nodoc: + %/ $('#{grid_name}_show_icon').observe('click', function(){\n/+ + %/ Element.toggle('#{grid_name}_show_icon');\n/+ + %/ Element.toggle('#{grid_name}_hide_icon');\n/+ + %/ $('#{filter_row_id}').show();\n/+ + %/ })\n/+ + %/ $('#{grid_name}_hide_icon').observe('click', function(){\n/+ + %/ Element.toggle('#{grid_name}_show_icon');\n/+ + %/ Element.toggle('#{grid_name}_hide_icon');\n/+ + %/ $('#{filter_row_id}').hide();\n/+ + %/ });\n/ + end + + def enter_key_event_registration(grid_name) #:nodoc: + %! $$('div##{grid_name}.wice_grid_container .wice_grid_filter_row input[type=text]').each(function(e){\n! + + %! e.observe('keydown', function(event){\n! + + %! if (event.keyCode == 13) {#{grid_name}.process()}\n! + + %! })\n! + + %! });\n! + end + + def csv_export_icon_initialization(grid_name) #:nodoc: + %! $$('div##{grid_name}.wice_grid_container .export_to_csv_button').each(function(e){\n! + + %! e.observe('click', function(event){\n! + + %! #{grid_name}.export_to_csv()\n! + + %! })\n! + + %! });\n! + end + + def auto_reloading_selects_event_initialization(grid_name) #:nodoc: + %! $$('div##{grid_name}.wice_grid_container select.auto_reload', '.#{grid_name}_detached_filter select.auto_reload').each(function(e){\n! + + %! e.observe('change', function(event){\n! + + %! #{grid_name}.process()\n! + + %! })\n! + + %! });\n! + end + + def auto_reloading_inputs_event_initialization(grid_name) #:nodoc: + %! $$('div##{grid_name}.wice_grid_container input.auto_reload', '.#{grid_name}_detached_filter input.auto_reload').each(function(e){\n! + + %! e.observe('keyup', function(event){\n! + + %! #{grid_name}.process(event.element().id)\n! + + %! })\n! + + %! });\n! + end + + def auto_reloading_calendar_event_initialization(grid_name) #:nodoc: + %! document.observe('wg:calendarChanged', function(event){\n! + + %! #{grid_name}.process()\n! + + %! });\n! + end + + + def show_all_link_initialization(grid_name, confirmation, parameters_json) #:nodoc: + %/ $$('div##{grid_name}.wice_grid_container .show_all_link').each(function(e){\n/ + + %/ e.observe('click', function(){\n/ + + %/ #{confirmation} #{grid_name}.reload_page_for_given_grid_state(#{parameters_json})\n/ + + %/ })\n/ + + %/ })\n/ + end + + + def back_to_pagination_link_initialization(grid_name, parameters_json) #:nodoc: + %/ $$('div##{grid_name}.wice_grid_container .show_all_link').each(function(e){\n/ + + %/ e.observe('click', function(){\n/ + + %/ #{grid_name}.reload_page_for_given_grid_state(#{parameters_json})\n/ + + %/ })\n/ + + %/ })\n/ + end + + def call_to_save_query_and_key_event_initialization_for_saving_queries( + id_and_name, grid_name, base_path_to_query_controller, parameters_json, ids_json) #:nodoc: + %/ function #{grid_name}_save_query(){\n/ + + %` if ( typeof(#{grid_name}) != "undefined")\n` + + %/ #{grid_name}.save_query($F('#{id_and_name}'), '#{base_path_to_query_controller}', #{parameters_json}, #{ids_json})\n/ + + %/ }\n/ + + %/ $('#{id_and_name}').observe('keydown', function(event){\n/ + + %/ if (event.keyCode == 13) #{grid_name}_save_query();\n/ + + %/ })\n/ + end + + + def js_framework_specific_calendar_assets(view) #:nodoc: + view.stylesheet_link_tag("calendarview.css") + view.javascript_include_tag("calendarview.js") + end + + def action_column_initialization(grid_name) #:nodoc: + %! $$('div##{grid_name}.wice_grid_container .select_all').each(function(e){\n! + + %! e.observe('click', function(){\n! + + %! $$('div##{grid_name}.wice_grid_container .sel input').each(function(checkbox){\n! + + %! checkbox.checked = true;\n! + + %! })\n! + + %! })\n! + + %! })\n! + + %! $$('div##{grid_name}.wice_grid_container .deselect_all').each(function(e){\n! + + %! e.observe('click', function(){\n! + + %! $$('div##{grid_name}.wice_grid_container .sel input').each(function(checkbox){\n! + + %! checkbox.checked = false;\n! + + %! })\n! + + %! })\n! + + %! })\n! + end + + def fade_this #:nodoc: + 'new Effect.Fade(this)' + end + + def focus_element(element_to_focus) #:nodoc: + %! var elToFocus = $('#{element_to_focus}');\n! + + %! elToFocus.focus();\n! + + %! elToFocus.value = elToFocus.value;\n! # this will just place the cursor at the end of the text input + end - def focus_element(element_to_focus) #:nodoc: - %! var elToFocus = $('#{element_to_focus}');\n! + - %! elToFocus.focus();\n! + - %! elToFocus.value = elToFocus.value;\n! # this will just place the cursor at the end of the text input end end diff --git a/lib/wice_grid.rb b/lib/wice_grid.rb index 2cf0dbb6..5c5b6988 100644 --- a/lib/wice_grid.rb +++ b/lib/wice_grid.rb @@ -15,6 +15,8 @@ require 'wice_grid_spreadsheet.rb' require 'wice_grid_serialized_queries_controller.rb' require 'js_adaptors/js_adaptor.rb' +require 'js_adaptors/jquery_adaptor.rb' +require 'js_adaptors/prototype_adaptor.rb'