Permalink
Browse files

alpha

  • Loading branch information...
1 parent 1053925 commit e0f0ab06848d455bcba159df5e2d1017c1687b96 Alexander Gräfenstein committed Oct 18, 2010
View
BIN .DS_Store
Binary file not shown.
View
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2009 Alexander Gräfenstein
+
+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.
View
@@ -0,0 +1,17 @@
+= railsgrid
+
+Description goes here.
+
+== Note on Patches/Pull Requests
+
+* Fork the project.
+* Make your feature addition or bug fix.
+* Add tests for it. This is important so I don't break it in a
+ future version unintentionally.
+* Commit, do not mess with rakefile, version, or history.
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
+* Send me a pull request. Bonus points for topic branches.
+
+== Copyright
+
+Copyright (c) 2010 Alexander Gräfenstein. See LICENSE for details.
View
@@ -0,0 +1,53 @@
+require 'rubygems'
+require 'rake'
+
+begin
+ require 'jeweler'
+ Jeweler::Tasks.new do |gem|
+ gem.name = "railsgrid"
+ gem.summary = %Q{Tables in rails}
+ gem.description = %Q{Easy tables in rails}
+ gem.email = "giniedp@online.de"
+ gem.homepage = "http://github.com/giniedp/railsgrid"
+ gem.authors = ["Alexander Gräfenstein"]
+ # gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
+ end
+ Jeweler::GemcutterTasks.new
+rescue LoadError
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
+end
+
+require 'rake/testtask'
+Rake::TestTask.new(:test) do |test|
+ test.libs << 'lib' << 'test'
+ test.pattern = 'test/**/test_*.rb'
+ test.verbose = true
+end
+
+begin
+ require 'rcov/rcovtask'
+ Rcov::RcovTask.new do |test|
+ test.libs << 'test'
+ test.pattern = 'test/**/test_*.rb'
+ test.verbose = true
+ end
+rescue LoadError
+ task :rcov do
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
+ end
+end
+
+task :test => :check_dependencies
+
+task :default => :test
+
+require 'rake/rdoctask'
+Rake::RDocTask.new do |rdoc|
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
+
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = "railsgrid #{version}"
+ rdoc.rdoc_files.include('README*')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
View
@@ -0,0 +1 @@
+0.1.0
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,221 @@
+(function($, undefined) {
+
+ $.fn.railsgrid = function(method) {
+ if ( methods[method] ) {
+ return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
+ } else if (typeof(method) === 'object' || !method) {
+ return methods.init.apply(this, arguments);
+ } else {
+ $.error( 'Method ' + method + ' does not exist on jQuery.railsgrid' );
+ }
+ };
+
+ var methods = {
+ init : function(options){
+ var settings = {
+ url : "/",
+ name : "",
+ query : {
+ pagination : { page : 0, per_page : 20 },
+ conditions : {},
+ order : {}
+ },
+ searchFadeTime : 250,
+ searchFadeOpac : 0.5,
+ queries : 0
+ }
+ options = (options || {});
+ $.extend(settings, options);
+
+ return this.each(function(){
+ var $this = $(this);
+ var data = $this.data('railsgrid');
+
+ if (!data){
+ // initialize railsgrid
+
+ // set data
+ $this.data('railsgrid', settings);
+
+ // search attribute changed/focused
+ $this.find(".js-attribute").bind("change.railsgrid", function(){
+ $(this).parents(".js-railsgrid").railsgrid('newSearch');
+ return false;
+ }).bind("focus.railsgrid", function(){
+ $(this).select();
+ return false;
+ });
+
+ // search attribute changed/focused
+ $this.find(".js-page").bind("change.railsgrid", function(){
+ $(this).parents(".js-railsgrid").railsgrid('page', $(this).val());
+ return false;
+ }).bind("focus.railsgrid", function(){
+ $(this).select();
+ return false;
+ });
+
+ // previous page click
+ $this.find(".js-previous").bind("click.railsgrid", function(){
+ $(this).parents(".js-railsgrid").railsgrid('previousPage');
+ return false;
+ });
+
+ // next page click
+ $this.find(".js-next").bind("click.railsgrid", function(){
+ $(this).parents(".js-railsgrid").railsgrid('nextPage');
+ return false;
+ });
+
+ // reload click
+ $this.find(".js-reload").bind("click.railsgrid", function(){
+ $(this).parents(".js-railsgrid").railsgrid('reloadPage');
+ return false;
+ });
+
+ // clear click
+ $this.find(".js-clear").bind("click.railsgrid", function(){
+ $(this).parents(".js-railsgrid").railsgrid('clearSearch');
+ return false;
+ });
+
+ // clear click
+ $this.find(".js-per-page").bind("change.railsgrid", function(){
+ $(this).parents(".js-railsgrid").railsgrid('perPage', $(this).val());
+ return false;
+ });
+ } else {
+ $.extend(data, options);
+ }
+ });
+ },
+ destroy : function(){
+ return this.each(function(){
+ var $this = $(this);
+ data = $this.data('railsgrid');
+ $this.unbind('.railsgrid');
+ $this.removeData('railsgrid');
+ });
+ },
+ setupConditions : function(){
+ var $this = $(this);
+ var data = $this.data('railsgrid');
+
+ data.query.conditions = {};
+ $(this).find(".js-attribute").each(function(){
+ data.query.conditions[$(this).attr("name")] = $(this).val();
+ });
+ },
+ setupPagination : function(page, perPage){
+ var $this = $(this);
+ var data = $this.data('railsgrid');
+
+ data.query.pagination = { page : 0, per_page : 20 };
+ if(!isNaN(Number(page)) && Number(page) >= 0){
+ data.query.pagination.page = page;
+ }
+ if (!isNaN(Number(perPage)) && Number(perPage) > 0){
+ data.query.pagination.per_page = perPage;
+ }
+ },
+ order : function(){
+ return "";
+ },
+ search : function(){
+ var $this = $(this);
+ var $content = $this.find(".js-tablewrapper");
+ var $control = $this.find(".js-tablecontrol");
+ var data = $this.data('railsgrid');
+ data.queries += 1;
+
+ $control.find(".js-reload").addClass("loading");
+ $this.fadeTo(data.searchFadeTime, data.searchFadeOpac);
+
+ $.ajax({
+ type : "GET",
+ url : data.url,
+ data : data.query,
+ dataType : "html",
+ success : function(result){
+ data.queries -= 1;
+ if(data.queries == 0){
+ $content.find(".js-row").detach();
+ $content.find("table").append($(result).find(".js-row"));
+ $control.find(".js-per-page").val(data.query.pagination.per_page);
+ $control.find(".js-page").val(Number(data.query.pagination.page) + 1);
+
+ total = (Number($(result).find(".js-page-total").text()));
+ totalPages = total / data.query.pagination.per_page
+ totalPages = (totalPages | 0) + 1;
+
+ $control.find(".js-page-total").text(totalPages);
+
+ $this.fadeTo(data.searchFadeTime, 1.0, function(){
+ $control.find(".js-reload").removeClass("loading");
+ });
+ }
+ },
+ error : function(){
+ data.queries -= 1;
+ if(data.queries == 0){
+ $content.find(".js-row").detach();
+ $this.fadeTo(data.searchFadeTime, 1.0, function(){
+ $control.find(".js-reload").removeClass("loading");
+ });
+ }
+ }
+ });
+ },
+ nextPage : function(){
+ var $this = $(this);
+ data = $this.data('railsgrid');
+ $this.railsgrid("setupPagination", data.query.pagination.page + 1, data.query.pagination.per_page);
+ $this.railsgrid("search");
+ },
+ previousPage : function(){
+ var $this = $(this);
+ data = $this.data('railsgrid');
+ $this.railsgrid("setupPagination", data.query.pagination.page - 1, data.query.pagination.per_page);
+ $this.railsgrid("search");
+ },
+ perPage : function(perPage){
+ var $this = $(this);
+ data = $this.data('railsgrid');
+ $this.railsgrid("setupPagination", 0, perPage);
+ $this.railsgrid("search");
+ },
+ page : function(page){
+ var $this = $(this);
+ data = $this.data('railsgrid');
+ $this.railsgrid("setupPagination", Number(page) - 1, data.query.pagination.per_page);
+ $this.railsgrid("search");
+ },
+ reloadPage : function(){
+ var $this = $(this);
+ data = $this.data('railsgrid');
+ $this.railsgrid("setupPagination", data.query.pagination.page, data.query.pagination.per_page);
+ $this.railsgrid("setupConditions");
+ $this.railsgrid("search");
+ },
+ newSearch : function(){
+ var $this = $(this);
+ data = $this.data('railsgrid');
+ $this.railsgrid("setupPagination", 0, data.query.pagination.per_page);
+ $this.railsgrid("setupConditions");
+ $this.railsgrid("search");
+ },
+ clearSearch : function(){
+ var $this = $(this);
+ data = $this.data('railsgrid');
+ $this.find(".js-attribute").each(function(){
+ $(this).val("");
+ });
+ $this.railsgrid("setupPagination", 0, data.query.pagination.per_page);
+ $this.railsgrid("setupConditions");
+ $this.railsgrid("search");
+ },
+ action : function(name, value){
+ $(this).trigger("action_" + name, value);
+ }
+ };
+})(jQuery);
Oops, something went wrong.

0 comments on commit e0f0ab0

Please sign in to comment.