--- src/vendor/plugins/rails_datatables/MIT-LICENSE | 20 +++ src/vendor/plugins/rails_datatables/README.md | 138 ++++++++++++++++++++ src/vendor/plugins/rails_datatables/Rakefile | 23 ++++ src/vendor/plugins/rails_datatables/init.rb | 1 + src/vendor/plugins/rails_datatables/install.rb | 1 + .../rails_datatables/lib/rails_datatables.rb | 94 +++++++++++++ .../rails_datatables/test/rails_datatables_test.rb | 8 + .../plugins/rails_datatables/test/test_helper.rb | 3 + src/vendor/plugins/rails_datatables/uninstall.rb | 1 + 9 files changed, 289 insertions(+), 0 deletions(-) create mode 100644 src/vendor/plugins/rails_datatables/MIT-LICENSE create mode 100644 src/vendor/plugins/rails_datatables/README.md create mode 100644 src/vendor/plugins/rails_datatables/Rakefile create mode 100644 src/vendor/plugins/rails_datatables/init.rb create mode 100644 src/vendor/plugins/rails_datatables/install.rb create mode 100644 src/vendor/plugins/rails_datatables/lib/rails_datatables.rb create mode 100644 src/vendor/plugins/rails_datatables/test/rails_datatables_test.rb create mode 100644 src/vendor/plugins/rails_datatables/test/test_helper.rb create mode 100644 src/vendor/plugins/rails_datatables/uninstall.rb
diff --git a/src/vendor/plugins/rails_datatables/MIT-LICENSE b/src/vendor/plugins/rails_datatables/MIT-LICENSE new file mode 100644 index 0000000..9376605 --- /dev/null +++ b/src/vendor/plugins/rails_datatables/MIT-LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2009 [name of plugin creator] + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/src/vendor/plugins/rails_datatables/README.md b/src/vendor/plugins/rails_datatables/README.md new file mode 100644 index 0000000..cb40b38 --- /dev/null +++ b/src/vendor/plugins/rails_datatables/README.md @@ -0,0 +1,138 @@ +## RailsDatatables + +A simpler, Rails-friendly interface to using the [DataTables](http://datatables.net) jQuery library. + +### Prerequisites +Make sure you have jQuery.js and jQuery.dataTables.js in /public/javascripts/ and that they're included in your layout. + +### Setup + +Give table a class of 'datatable' so that the Javascript knows which table to alter. NOTE: If you want to use multiple tables on a single page, include the :table_dom_id in the options hash to specify the ID table to be altered. + +Add thead around the table header (These elements will associate to the columns array created below, allowing sorting). + +Add tbody around the table rows (These are the elements that will be sorted and paginated.) + +Activate using <%= datatable() %>, passing in the columns, how to filter them (sorting type), and any other settings (ajax source, search?, label for search, processing image) + + <% columns = [{:type => 'html', :class => "first"}, {:type => 'html'}, {:type => 'html'}, {:type => nil, :class => "last"}] %> + <%= datatable(columns, {:sort_by => "[0, 'desc']", :processing => image_tag("spinner.gif") }) %> + + <table id='users' class='datatable'> + <thead> + <tr> + <th>Name</th> + <th>Account Level</th> + <th>Email</th> + <th>Actions</th> + </tr> + </thead> + <tbody> + <%- @users.each do |user| -%> + <tr id="<%= dom_id(user) %>"> + <td><%= user.name %></td> + <td><%= user.account.account_level.name %></td> + <td><%= user.email %></td> + <td><%= link_to "Edit", edit_system_user_path(user) %></td> + </tr> + <%- end -%> + </tbody> + </table> + +### Options + +#### Table Options + + :sort_by - array, default column number (0 - n-1) and sort order. e.g. "[2, 'desc']". Defaults to initial order. + :search - boolean, display the search field. Defaults to true. + :search_label - string, the label for the search field. Defaults to "Search". + :processing - string, the text or image to display while processing data. Defaults to "Processing". + :persist_state - boolean, remember the sorting and page of the tables for the user. Defaults to true. + :additional_data - hash, pass along additional data, such as filter values. Default is none. + :table_dom_id - string, the ID of the table to alter. If nothing is passed, it will look for a class of 'datatable'. Necessary if you want to have multiple DataTables on a single page. + :per_page - the number of rows to show per page (renamed from display_length) + :append - functions to all at the end of the dataTable() call. Useful for [Datatables plugins](http://www.datatables.net/plug-ins/api) + :no_records_message - Message to display if no records are found, whether on load or after searching + :auto_width - Automatically adjust the width of the columns. Defaults to true. + :row_callback - a function to run on each row in the table. Inserted in to "'fnRowCallback': function( nRow, aData, iDisplayIndex ) { }". See [documentation for fnRowCallback](http://www.datatables.net/usage/callbacks) for more information. + +#### Column Options + + :class - string, the class to assign to the table cell. Default is none. + :type - string, the type of content in the column, for non-Ajax tables. 'html' will strip all HTML and sort on the inner value, as a string. Default is string. + :sortable - boolean, allow this column to be sorted on. Default is true. + :searchable - boolean, allow this column to be searched, for non-Ajax tables. Default is true. + +#### AJAX Options + + When you're working with large datasets it's not reasonable to load everything on page load. Use an :ajax_source to load just the records that are being displayed, do custom searching (DB, Solr, etc). + + :ajax_source - string, for large datasets, use an ajax source to load each page on its own. For smaller datasets, just load the whole set and let datatable do the sorting + +Add a datatable method on your controller to return JSON +* Return the objects to be displayed +* Return the total number of objects +* Add a method to handle sorting - DataTables returns the column that is being sorted (0 - n), so you need to know which column is which and sort on it. + +### AJAX Example + +#### Datatable view example - datatable.html.erb + + {"sEcho": <%= params[:sEcho] || -1 %>, + "iTotalRecords": <%= @total_objects %>, + "iTotalDisplayRecords": <%= @total_object %>, + "aaData":[ + <% @objects.each do |object| %> + ['<%= link_to(object.user.name, user) %>', + '<%= object.description || "-" %>', + '<%= object.created_at %>' + ], + <% end %> + ]} + +#### Controller example - using will_paginate + + def datatable + @objects = current_objects(params) + @total_objectss = total_objects(params) + render :layout => false + end + + private + + def current_objects(params={}) + current_page = (params[:iDisplayStart].to_i/params[:iDisplayLength].to_i rescue 0)+1 + @current_objects = Object.paginate :page => current_page, + :include => [:user], + :order => "#{datatable_columns(params[:iSortCol_0])} #{params[:sSortDir_0] || "DESC"}", + :conditions => conditions, + :per_page => params[:iDisplayLength] + end + + def total_objects(params={}) + @total_objects = Object.count :include => [:user], :conditions => conditions + end + + def datatable_columns(column_id) + case column_id.to_i + when 1 + return "objects.description" + when 2 + return "objects.created_at" + else + return "users.name" + end + end + + def conditions + conditions = [] + conditions << "(objects.description ILIKE '%#{params[:sSearch]}%' OR users.name ILIKE '%#{params[:sSearch]}%')" if(params[:sSearch]) + return conditions.join(" AND ") + end + +### Note +There is a more functionality offered by DataTables than this plugin currently provides. We add to it as we find need for other features. If there's a feature of DataTables that you'd like to see, fork this repo and add it so we can all benefit. + +### Credits + +Copyright (c) 2009 [Phronos](http://phronos.com), released under the MIT license diff --git a/src/vendor/plugins/rails_datatables/Rakefile b/src/vendor/plugins/rails_datatables/Rakefile new file mode 100644 index 0000000..6be4ee9 --- /dev/null +++ b/src/vendor/plugins/rails_datatables/Rakefile @@ -0,0 +1,23 @@ +require 'rake' +require 'rake/testtask' +require 'rake/rdoctask' + +desc 'Default: run unit tests.' +task :default => :test + +desc 'Test the rails_datatables plugin.' +Rake::TestTask.new(:test) do |t| + t.libs << 'lib' + t.libs << 'test' + t.pattern = 'test/**/*_test.rb' + t.verbose = true +end + +desc 'Generate documentation for the rails_datatables plugin.' +Rake::RDocTask.new(:rdoc) do |rdoc| + rdoc.rdoc_dir = 'rdoc' + rdoc.title = 'RailsDatatables' + rdoc.options << '--line-numbers' << '--inline-source' + rdoc.rdoc_files.include('README') + rdoc.rdoc_files.include('lib/**/*.rb') +end diff --git a/src/vendor/plugins/rails_datatables/init.rb b/src/vendor/plugins/rails_datatables/init.rb new file mode 100644 index 0000000..538f335 --- /dev/null +++ b/src/vendor/plugins/rails_datatables/init.rb @@ -0,0 +1 @@ +ActionView::Base.send :include, RailsDatatables \ No newline at end of file diff --git a/src/vendor/plugins/rails_datatables/install.rb b/src/vendor/plugins/rails_datatables/install.rb new file mode 100644 index 0000000..f7732d3 --- /dev/null +++ b/src/vendor/plugins/rails_datatables/install.rb @@ -0,0 +1 @@ +# Install hook code here diff --git a/src/vendor/plugins/rails_datatables/lib/rails_datatables.rb b/src/vendor/plugins/rails_datatables/lib/rails_datatables.rb new file mode 100644 index 0000000..5e2b00b --- /dev/null +++ b/src/vendor/plugins/rails_datatables/lib/rails_datatables.rb @@ -0,0 +1,94 @@ +module RailsDatatables + def datatable(columns, opts={}) + sort_by = opts[:sort_by] || nil + additional_data = opts[:additional_data] || {} + search = opts[:search].present? ? opts[:search].to_s : "true" + search_label = opts[:search_label] || "Search" + processing = opts[:processing] || "Processing" + persist_state = opts[:persist_state].present? ? opts[:persist_state].to_s : "true" + table_dom_id = opts[:table_dom_id] ? "##{opts[:table_dom_id]}" : ".datatable" + per_page = opts[:per_page] || opts[:display_length]|| 25 + no_records_message = opts[:no_records_message] || nil + auto_width = opts[:auto_width].present? ? opts[:auto_width].to_s : "true" + row_callback = opts[:row_callback] || nil + toolbar = opts[:toolbar] || nil + + append = opts[:append] || nil + + ajax_source = opts[:ajax_source] || nil + server_side = opts[:ajax_source].present? + + additional_data_string = "" + additional_data.each_pair do |name,value| + additional_data_string = additional_data_string + ", " if !additional_data_string.blank? && value + additional_data_string = additional_data_string + "{'name': '#{name}', 'value':'#{value}'}" if value + end + + var_name = "dataTable_" + table_dom_id.sub(/[^a-zA-Z0-9]/ ,'') + + %Q{ + <script type="text/javascript"> + $(function() { + #{var_name} = $('#{table_dom_id}').dataTable({ + "oLanguage": { + "sSearch": "#{search_label}", + #{"'sZeroRecords': '#{no_records_message}'," if no_records_message} + "sProcessing": '#{processing}' + }, + #{"'sDom': '<\"toolbar\">frtip'," if toolbar} + "sPaginationType": "full_numbers", + "iDisplayLength": #{per_page}, + "bProcessing": true, + "bServerSide": #{server_side}, + "bLengthChange": false, + "bStateSave": #{persist_state}, + "bFilter": #{search}, + "bAutoWidth": #{auto_width}, + "bJQueryUI": true, + #{"'aaSorting': [#{sort_by}]," if sort_by} + #{"'sAjaxSource': '#{ajax_source}'," if ajax_source} + "aoColumns": [ + #{formatted_columns(columns)} + ], + #{"'fnRowCallback': function( nRow, aData, iDisplayIndex ) { #{row_callback} }," if row_callback} + #{"'fnDrawCallback': #{opts[:draw_callback]}," if opts[:draw_callback]} + "fnServerData": function ( sSource, aoData, fnCallback ) { + aoData.push( #{additional_data_string} ); + $.getJSON( sSource, aoData, function (json) { + fnCallback(json); + } ); + } + })#{append}; + #{"$('#{table_dom_id} tbody').click(#{opts[:click_callback]});" if opts[:click_callback]} + #{"$('div.toolbar').html('#{toolbar}');" if toolbar} + }); + </script> + } + end + + private + def formatted_columns(columns) + i = 0 + columns.map {|c| + i += 1 + if c.nil? or c.empty? + "null" + else + onclick_code = c[:checkbox_toggle_callback] ? "onclick=#{c[:checkbox_toggle_callback]}" : '' + searchable = c[:searchable].to_s.present? ? c[:searchable].to_s : "true" + sortable = c[:sortable].to_s.present? ? c[:sortable].to_s : "true" + "{ + 'sType': '#{c[:type] || "string"}', + 'bVisible': #{c.has_key?(:visible) ? c[:visible] : true}, + 'bSortable':#{sortable}, + 'bSearchable':#{searchable} + #{",'sClass':'#{c[:class]}'" if c[:class]} + #{",'sName':'#{c[:name]}'" if c[:name]} + #{",'sWidth':'#{c[:width]}'" if c[:width]} + #{",'fnRender':#{c[:fn_render]}" if c[:fn_render]} + #{",'fnRender': function(obj) {return '<input type=\"checkbox\" #{onclick_code} name=\"#{c[:checkbox_id]}[]\" value=\"' + obj.aData[obj.iDataColumn] + '\">';}" if c[:checkbox_id]} + }" + end + }.join(",") + end +end diff --git a/src/vendor/plugins/rails_datatables/test/rails_datatables_test.rb b/src/vendor/plugins/rails_datatables/test/rails_datatables_test.rb new file mode 100644 index 0000000..e96dcb0 --- /dev/null +++ b/src/vendor/plugins/rails_datatables/test/rails_datatables_test.rb @@ -0,0 +1,8 @@ +require 'test_helper' + +class RailsDatatablesTest < ActiveSupport::TestCase + # Replace this with your real tests. + test "the truth" do + assert true + end +end diff --git a/src/vendor/plugins/rails_datatables/test/test_helper.rb b/src/vendor/plugins/rails_datatables/test/test_helper.rb new file mode 100644 index 0000000..cf148b8 --- /dev/null +++ b/src/vendor/plugins/rails_datatables/test/test_helper.rb @@ -0,0 +1,3 @@ +require 'rubygems' +require 'active_support' +require 'active_support/test_case' \ No newline at end of file diff --git a/src/vendor/plugins/rails_datatables/uninstall.rb b/src/vendor/plugins/rails_datatables/uninstall.rb new file mode 100644 index 0000000..9738333 --- /dev/null +++ b/src/vendor/plugins/rails_datatables/uninstall.rb @@ -0,0 +1 @@ +# Uninstall hook code here -- 1.6.2.5 _______________________________________________ deltacloud-devel mailing list [email protected] https://fedorahosted.org/mailman/listinfo/deltacloud-devel
