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..32193129 --- /dev/null +++ b/generators/wice_grid_assets_jquery/templates/javascripts/wice_grid_jquery.js @@ -0,0 +1,155 @@ +function WiceGridProcessor(name, base_request_for_filter, base_link_for_show_all_records, + link_for_export, parameter_name_for_query_loading, parameter_name_for_focus, 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.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; + this.filter_declarations = new Array(); + this.environment = environment; + + this.toString = function(){ + return ""; + } + + + 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){ + 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(dom_id_to_focus){ + 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); + } + if (dom_id_to_focus){ + res = this.append_to_url(res, this.parameter_name_for_focus + dom_id_to_focus); + } + 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.2'; 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 54% 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..f4b20b7a 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,68 @@ -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, parameter_name_for_focus, environment){ - checkIfPrototypeIsLoaded : function(){ + this.checkIfJsFrameworkIsLoaded = function(){ if (typeof(Prototype) == "undefined"){ alert("Prototype javascript library not loaded, WiceGrid cannot proceed!") } - }, + } + + + 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; + this.filter_declarations = new Array(); + this.environment = environment; + + this.toString = function(){ + return ""; + } - 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.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){ + 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 +73,45 @@ WiceGridProcessor = Class.create( { sep = '?'; } return url + sep + str; - }, + } - build_url_with_params : function(){ - results = new Array(); + 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( - 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); } + if (dom_id_to_focus){ + res = this.append_to_url(res, this.parameter_name_for_focus + dom_id_to_focus); + } 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 +124,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 +137,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; @@ -149,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/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/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/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 0260369c..60969912 100644 --- a/lib/helpers/wice_grid_misc_view_helpers.rb +++ b/lib/helpers/wice_grid_misc_view_helpers.rb @@ -2,6 +2,7 @@ module Wice module GridViewHelper + # This method dumps all HTTP parameters related to filtering and ordering of a certain grid as hidden form fields. # This might be required if you want to keep the state of a grid while reloading the page using other forms. # 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..e5699c10 100644 --- a/lib/helpers/wice_grid_view_helpers.rb +++ b/lib/helpers/wice_grid_view_helpers.rb @@ -482,14 +482,15 @@ 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$ + %$ 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$ + + %$ } 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 @@ -497,82 +498,47 @@ 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 + + if rendering.element_to_focus + cached_javascript << JsAdaptor.focus_element(rendering.element_to_focus) 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/ + + %/ '#{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 @@ -752,11 +718,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 +733,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..c68f9f64 --- /dev/null +++ b/lib/js_adaptors/jquery_adaptor.rb @@ -0,0 +1,128 @@ +# encoding: UTF-8 +module Wice::JsAdaptor #:nodoc: + + 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 + + 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..eadc8790 --- /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 + include Wice::JsAdaptor::Prototype + else + 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 new file mode 100644 index 00000000..2f901aaa --- /dev/null +++ b/lib/js_adaptors/prototype_adaptor.rb @@ -0,0 +1,150 @@ +# encoding: UTF-8 +module Wice::JsAdaptor #:nodoc: + + 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 + + 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..5c5b6988 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,17 @@ 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' +require 'js_adaptors/jquery_adaptor.rb' +require 'js_adaptors/prototype_adaptor.rb' + + module Wice diff --git a/lib/wice_grid_controller.rb b/lib/wice_grid_controller.rb index 3adc11dd..c6ad52a2 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?