Forked from robertjwhitney/activeadmin_sortable.js.coffee
Last active
August 29, 2015 14:05
-
-
Save raedatoui/14a1aad5f9a4a3feae42 to your computer and use it in GitHub Desktop.
Revisions
-
raedatoui revised this gist
Aug 16, 2014 . No changes.There are no files selected for viewing
-
raedatoui revised this gist
Aug 16, 2014 . No changes.There are no files selected for viewing
-
raedatoui renamed this gist
Aug 16, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
raedatoui revised this gist
Aug 16, 2014 . 2 changed files with 50 additions and 27 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,30 +2,40 @@ # # ActiveAdmin already includes the necessary jquery in active_admin/base, # so just add this to javascripts/active_admin.js after //= require active_admin/base # # # Serialize and Sort # # model_name - you guessed it, the name of the model we are calling sort on. # This is the actual variable name, no need to change it. # sendSortRequestOfModel = (model_name, tbody) -> formData = $(tbody).sortable('serialize') formData += '&' + $('meta[name=csrf-param]').attr('content') + '=' + encodeURIComponent($('meta[name=csrf-token]').attr('content')) content = $(tbody).html() formData += '&markup=' + encodeURIComponent(content) formData += '&utf8=✓' $.ajaxSetup({ scriptCharset: "utf-8" ,contentType: "application/x-www-form-urlencoded; charset=UTF-8" }) $.ajax type: 'post' data: formData dataType: 'html' contentType: 'application/x-www-form-urlencoded; charset=UTF-8' url: '/admin/' + model_name + '/sort' success: (data, textStatus, jqXHR) -> $(tbody).html data enableSort = (model_name, tbody) -> $(tbody).disableSelection() $(tbody).sortable axis: 'y' cursor: 'move' update: (event, ui) -> sendSortRequestOfModel(model_name, tbody) jQuery ($) -> if $('body.admin_profiles.index').length enableSort('profiles', '#index_table_profiles tbody') This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,17 +1,30 @@ ActiveAdmin.register Profile do permit_params :name, :title, :image, :bio, :quote, :featured, :thumb, :second_col, :display_order config.sort_order = "display_order_asc" collection_action :sort, :method => :post do params[:profile].each_with_index do |id, index| Profile.update_all(['display_order=?', index+1], ['id=?', id]) end content = Nokogiri::HTML(params[:markup], nil, 'utf-8') rows = content.css('tr') counter = 1 rows.each do |row| display_order_col = row.at_css 'td.col-display_order' if display_order_col display_order_col.content = counter end row['class'] = counter % 2 == 0 ? 'even' : 'odd' counter = counter+1 end render text: content.to_html end ... end -
robertjwhitney revised this gist
Jul 3, 2012 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ # http://stackoverflow.com/a/8936202 # # ActiveAdmin already includes the necessary jquery in active_admin/base, # so just add this to javascripts/active_admin.js after //= require active_admin/base # -
robertjwhitney revised this gist
Jul 3, 2012 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,8 +9,8 @@ # sendSortRequestOfModel = (model_name) -> formData = $('#' + model_name + ' tbody').sortable('serialize') formData += '&' + $('meta[name=csrf-param]').attr('content') + '=' + encodeURIComponent($('meta[name=csrf-token]').attr('content')) $.ajax type: 'post' data: formData @@ -21,9 +21,9 @@ sendSortRequestOfModel = (model_name) -> # jQuery ($) -> if $('body.admin_ducks.index').length $( '#ducks tbody' ).disableSelection() $( '#ducks tbody' ).sortable axis: 'y' cursor: 'move' update: (event, ui) -> sendSortRequestOfModel('ducks') -
robertjwhitney revised this gist
Jul 3, 2012 . 2 changed files with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,6 @@ # ActiveAdmin already includes the necessary jquery in active_admin/base, # so just add this to javascripts/active_admin.js after //= require active_admin/base # # # Serialize and Sort # This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ # admin/duck.rb # Duck is the Model this particular file refers to. # Ref. ActiveAdmin documentation for more. # http://activeadmin.info/ -
robertjwhitney created this gist
Jul 3, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ # ActiveAdmin already includes the necessary jquery in active_admin/base, # so just add this to javascripts/active_admin.js # # Serialize and Sort # # model_name - you guessed it, the name of the model we are calling sort on. # This is the actual variable name, no need to change it. # sendSortRequestOfModel = (model_name) -> formData = $('#' + model_name + ' tbody').sortable('serialize') formData += "&" + $('meta[name=csrf-param]').attr("content") + "=" + encodeURIComponent($('meta[name=csrf-token]').attr("content")) $.ajax type: 'post' data: formData dataType: 'script' url: '/admin/' + model_name + '/sort' # Don't forget we are sorting Duck, so ducks refers specifically to that. # jQuery ($) -> if $('body.admin_ducks.index').length $( "#ducks tbody" ).disableSelection() $( "#ducks tbody" ).sortable axis: 'y' cursor: 'move' update: (event, ui) -> sendSortRequestOfModel("ducks") This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ # Duck is the Model this particular file refers to. # Ref. ActiveAdmin documentation for more. # http://activeadmin.info/ ActiveAdmin.register Duck do config.sort_order = 'position_asc' ... collection_action :sort, :method => :post do params[:story].each_with_index do |id, index| Duck.update_all(['position=?', index+1], ['id=?', id]) end render :nothing => true end end