Permalink
Browse files

Initial Commit

  • Loading branch information...
0 parents commit 770ac99192a7e018e0a9bb8f5fcf96d76e0447d0 @supercleanse supercleanse committed May 11, 2011
@@ -0,0 +1,4 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in datatables.gemspec
+gemspec
@@ -0,0 +1,21 @@
+Copyright (c) 2004-2011 Caseproof, LLC
+
+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.
+
@@ -0,0 +1,12 @@
+= Datatables
+
+Datatables is a Rails 3 plugin that enables the easy creation of dynamic datatable views on top of any ActiveRecord model. Datatables provides a simple helper that can be utilized in the view to automatically display a dynamic view on top of a model. Datatables handles the entire front end and backend support to do this.
+
+= Installation
+= Example
+= Why use this plugin?
+= Support
+
+Bug report? Faulty/incomplete documentation? Feature request? Please post an issue on 'http://github.com/Caseproof/metafy/issues'. If its urgent, please contact me from my website at 'http://blairwilliams.com/contact'
+
+Copyright (c) 2004-2011 Caseproof, LLC, released under the MIT license
@@ -0,0 +1,2 @@
+require 'bundler'
+Bundler::GemHelper.install_tasks
@@ -0,0 +1,29 @@
+module DatatableHelper
+ def datatable(modelname,columns,options={},jsoptions={})
+ if modelname.kind_of? Array
+ @modelname = modelname[0].to_s
+ @scope = modelname[1].to_s
+ @id = modelname[2]
+ else
+ @modelname = modelname.to_s
+ end
+
+ @columns = columns
+ @jsoptions = jsoptions
+ @pptions = options
+
+ @col_str = ""
+ @columns.each_pair do |key,col|
+ @col_str += "," unless @columns.keys.first == key
+ @col_str += key.to_s
+ if !col[:column].nil?
+ real_column_name = col[:column].gsub( /[\.#|]/, ":" )
+ @col_str += ":#{real_column_name}"
+ logger.debug real_column_name
+ logger.debug @col_str
+ end
+ end
+
+ render :partial => '/datatable/datatable'
+ end
+end
@@ -0,0 +1,163 @@
+<% unless @pptions[:selectable].nil? or !@pptions[:selectable] -%>
+<div id="rd_buttons">
+ <a id="rd_clear_selections" class="rd_disabled">Clear Selections</a>
+ <% unless @pptions[:selectable_actions].nil? -%>
+ <% @pptions[:selectable_actions].each do |sa| %>
+&nbsp;&nbsp;<%= sa %>
+ <% end -%>
+ <% end -%>
+</div>
+<% end -%>
+<table cellpadding="0" cellspacing="0" border="0" class="display" id="rdatatable">
+ <thead>
+ <tr>
+ <% @columns.each_pair do |key,col| -%>
+ <th width="<%= col[:width] %>"><%= col[:label] || key.to_s.humanize %></th>
+ <% end -%>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td colspan="<%= @columns.length.to_s %>" class="dataTables_empty"><%= image_tag "upload_indicator.gif", :title => "progress", :class => "progress" %></td>
+ </tr>
+ </tbody>
+ <tfoot>
+ <tr>
+ <% @columns.each_pair do |key,col| -%>
+ <th><input type="text" name="search_<%= key.to_s %>" value="Search <%= col[:label] || key.to_s.humanize %>" class="search_init" rel="<%= @columns.keys.index(key) %>" /></th>
+ <% end -%>
+ </tr>
+ </tfoot>
+</table>
+
+<%= javascript_tag :defer => 'defer' do -%>
+ var asInitVals = new Array();
+
+<% unless @pptions[:selectable].nil? or !@pptions[:selectable] -%>
+ var gaiSelected = [];
+
+ function rd_toggle_buttons() {
+ if( gaiSelected.length > 0 )
+ {
+ jQuery("#rd_buttons a").removeClass('rd_disabled');
+ jQuery("#rd_buttons a").addClass('rd_enabled');
+ }
+ else
+ {
+ jQuery("#rd_buttons a").removeClass('rd_enabled');
+ jQuery("#rd_buttons a").addClass('rd_disabled');
+ }
+ }
+<% end -%>
+
+ function rd_bulk_edit_users() {
+ if( jQuery('#rd_bulk_edit_users').hasClass('rd_enabled') )
+ {
+ jQuery.prettyPhoto.open('/admin/projects/<%= @id %>/edit_users/' + gaiSelected + '?iframe=true&width=90%&height=90%');
+ }
+ }
+
+ jQuery(document).ready(function() {
+ var oTable = jQuery('#rdatatable').dataTable( {
+
+ /* Custom Options */
+ <% @jsoptions.each_pair do |k,v| -%>
+ "<%= k %>": <%= v %>,
+ <% end -%>
+
+ /* Visible / Hidden columns & Formatting */
+ "aoColumnDefs": [
+ <% @columns.each_pair do |name,attrs| -%>
+ <% if attrs[:type] == 'link' -%>
+ /* <%= name.to_s %> */ {
+ "fnRender": function ( oObj ) {
+ return '<a href="' + "<%= attrs[:link] %>".replace( /<%= attrs[:replace] %>/i, oObj.aData[<%= @columns.keys.index( attrs[:replace].to_sym ) %>] ) + '">' + oObj.aData[<%= @columns.keys.index( name.to_sym ) %>] + '</a>';
+ },
+ "aTargets": [ <%= @columns.keys.index( name ) %> ]
+ }<%= "," unless @columns.keys.last == name %>
+ <% elsif attrs[:type] == 'hidden' -%>
+ /* <%= name.to_s %> */ { "bVisible": false, "aTargets": [ <%= @columns.keys.index( name ) %> ] }<%= "," unless @columns.keys.last == name %>
+ <% else -%>
+ /* <%= name.to_s %> */ { "aTargets": [ <%= @columns.keys.index( name ) %> ] }<%= "," unless @columns.keys.last == name %>
+ <% end -%>
+ <% end -%>
+ ],
+
+ <% unless @pptions[:selectable].nil? or !@pptions[:selectable] -%>
+ "fnRowCallback": function( nRow, aData, iDisplayIndex ) {
+ if ( jQuery.inArray(aData[0], gaiSelected) != -1 ) {
+ jQuery(nRow).addClass('row_selected');
+ }
+ return nRow;
+ },
+ <% end -%>
+
+ /* Boilerplate Options */
+ "sPaginationType": "full_numbers",
+ "aLengthMenu": [[10, 25, 50, 100, 500], [10, 25, 50, 100, 500]],
+ "bProcessing": true,
+ "bServerSide": true,
+ "sAjaxSource": '/rdtable/<%= @modelname %><%= "/#{@col_str}" %><%= @scope.nil? ? '' : "/#{@scope}" %><%= @id.nil? ? '' : "/#{@id}" %>'
+ } );
+
+ <% unless @pptions[:selectable].nil? or !@pptions[:selectable] -%>
+ jQuery('#rd_clear_selections').click( function () {
+ gaiSelected = [];
+ jQuery("#rdatatable tbody tr").removeClass('row_selected');
+ rd_toggle_buttons();
+ });
+
+ /* Click event handler */
+ jQuery('#rdatatable tbody tr').live('click', function () {
+ var aData = oTable.fnGetData( this );
+ var iId = aData[0];
+
+ if ( jQuery.inArray(iId, gaiSelected) == -1 )
+ {
+ gaiSelected[gaiSelected.length++] = iId;
+ }
+ else
+ {
+ gaiSelected = jQuery.grep(gaiSelected, function(value) {
+ return value != iId;
+ } );
+ }
+
+ jQuery(this).toggleClass('row_selected');
+ rd_toggle_buttons();
+ } );
+ <% end -%>
+
+ jQuery("tfoot input").keyup( function () {
+ /* Filter on the column (the index) of this element */
+ oTable.fnFilter( this.value, jQuery(this).attr('rel') );
+ gaiSelected = []; // clear the selection on filter
+ rd_toggle_buttons();
+ } );
+
+ /*
+ * Support functions to provide a little bit of 'user friendlyness' to the textboxes in
+ * the footer
+ */
+ jQuery("tfoot input").each( function (i) {
+ asInitVals[i] = this.value;
+ } );
+
+ jQuery("tfoot input").focus( function () {
+ if ( this.className == "search_init" )
+ {
+ this.className = "";
+ this.value = "";
+ }
+ } );
+
+ jQuery("tfoot input").blur( function (i) {
+ if ( this.value == "" )
+ {
+ this.className = "search_init";
+ this.value = asInitVals[jQuery("tfoot input").index(this)];
+ }
+ } );
+
+ } );
+<% end -%>
@@ -0,0 +1,47 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "datatables/version"
+
+Gem::Specification.new do |s|
+ s.name = "datatables"
+ s.version = Datatables::VERSION
+ s.platform = Gem::Platform::RUBY
+ s.authors = ["TODO: Write your name"]
+ s.email = ["TODO: Write your email address"]
+ s.homepage = ""
+ s.summary = %q{TODO: Write a gem summary}
+ s.description = %q{TODO: Write a gem description}
+
+ s.rubyforge_project = "datatables"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+end
+
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+
+Gem::Specification.new do |s|
+ s.name = "datatables"
+ s.version = "0.0.1"
+ s.platform = Gem::Platform::RUBY
+ s.authors = ["Blair Williams","Brandon Toone"]
+ s.email = ["blair@caseproof.com","btoone@gmail.com"]
+ s.homepage = "http://blairwilliams.com/ruby-on-rails/datatables"
+ s.summary = %q{Datatables is a Rails 3 plugin that enables the easy creation of dynamic datatable views on top of any ActiveRecord model}
+ s.description = %q{Datatables is a Rails 3 plugin that enables the easy creation of dynamic datatable views on top of any ActiveRecord model. Datatables provides a simple helper that can be utilized in the view to automatically display a dynamic view on top of a model. Datatables handles the entire front end and backend support to do this. }
+
+ s.add_dependency('rails','>= 3.0.3')
+ s.add_dependency('jquery-rails')
+
+ s.license = 'MIT'
+
+ s.rubyforge_project = "datatables"
+
+ s.files = `git ls-files`.split("\n")
+ #s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ #s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ #s.require_paths = ["app","config","lib"]
+end
@@ -0,0 +1,4 @@
+module Datatables
+ require 'datatables/engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3
+ require 'datatables/activerecord_methods' if defined?(Rails) && Rails::VERSION::MAJOR == 3
+end
Oops, something went wrong.

0 comments on commit 770ac99

Please sign in to comment.