From c32b0dd4b4c466bf213c8ce896d194e676091073 Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Tue, 14 Aug 2012 00:59:01 +0800 Subject: [PATCH] Move delete checkboxes to js --- app/assets/javascripts/sort_header.js | 11 +++++- app/controllers/admin/assets_controller.rb | 4 +-- app/controllers/admin/designs_controller.rb | 4 +-- app/helpers/orbit_backend_helper.rb | 4 +-- app/views/admin/assets/_sort_headers.html.erb | 3 +- app/views/admin/assets/index.html.erb | 36 +++++++++---------- .../admin/designs/_sort_headers.html.erb | 3 +- app/views/admin/designs/index.html.erb | 10 +++--- config/routes.rb | 4 +-- .../back_end/bulletins_controller.rb | 4 +-- .../back_end/bulletins/_sort_headers.html.erb | 3 +- .../back_end/bulletins/index.html.erb | 10 +++--- .../announcement/config/routes.rb | 2 +- .../back_end/news_bulletins_controller.rb | 4 +-- .../news_bulletins/_sort_headers.html.erb | 3 +- .../back_end/news_bulletins/index.html.erb | 10 +++--- vendor/built_in_modules/news/config/routes.rb | 2 +- .../page_contexts/_sort_headers.html.erb | 2 +- .../back_end/web_links_controller.rb | 4 +-- .../back_end/web_links/_sort_headers.html.erb | 3 +- .../back_end/web_links/index.html.erb | 32 ++++++++--------- .../web_resource/config/routes.rb | 2 +- 22 files changed, 82 insertions(+), 78 deletions(-) diff --git a/app/assets/javascripts/sort_header.js b/app/assets/javascripts/sort_header.js index 25a16344..ef0f5a9c 100644 --- a/app/assets/javascripts/sort_header.js +++ b/app/assets/javascripts/sort_header.js @@ -1,5 +1,14 @@ $(document).on('click', '.list-remove', function(){ - $('#delete_all').submit(); + var a = []; + $('.checkbox_in_list').each(function(){ + if (this.checked) a.push("ids[]=" + this.value); + }); + var url = $(this).attr('rel'); + if (url.indexOf('?') > -1){ + $.getScript(url + '&' + a.join('&')); + }else{ + $.getScript(url + '?' + a.join('&')); + } }); $(document).on('click', '#check_all', function(){ diff --git a/app/controllers/admin/assets_controller.rb b/app/controllers/admin/assets_controller.rb index 092cb971..6a847a12 100644 --- a/app/controllers/admin/assets_controller.rb +++ b/app/controllers/admin/assets_controller.rb @@ -87,8 +87,8 @@ class Admin::AssetsController < OrbitBackendController end def delete - if params[:to_delete] - asset = Asset.any_in(:_id => params[:to_delete]).delete_all + if params[:ids] + asset = Asset.any_in(:_id => params[:ids]).delete_all end redirect_to assets_url(:filter => params[:filter], :direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options]) end diff --git a/app/controllers/admin/designs_controller.rb b/app/controllers/admin/designs_controller.rb index 84f2b770..9d434ff8 100644 --- a/app/controllers/admin/designs_controller.rb +++ b/app/controllers/admin/designs_controller.rb @@ -86,8 +86,8 @@ class Admin::DesignsController < OrbitBackendController end def delete - if params[:to_delete] - designs = Design.any_in(:_id => params[:to_delete]).delete_all + if params[:ids] + designs = Design.any_in(:_id => params[:ids]).delete_all end redirect_to admin_designs_url(:direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options]) end diff --git a/app/helpers/orbit_backend_helper.rb b/app/helpers/orbit_backend_helper.rb index e2865b9f..3bc4d31b 100644 --- a/app/helpers/orbit_backend_helper.rb +++ b/app/helpers/orbit_backend_helper.rb @@ -20,13 +20,13 @@ module OrbitBackendHelper ' active' if (@filter[type].include?(id.to_s) rescue nil) end - def render_sort_bar(delete_all, *titles) + def render_sort_bar(delete_all, url, *titles) content_tag :table, :class => "table main-list" do content_tag :thead do content_tag :tr, :class => "sort-header" do concat (content_tag :th, :class => "span1 strong" do concat check_box_tag :check_all - concat link_to content_tag(:i, nil, :class => "icon-trash"), '#', :class => "list-remove" + concat link_to content_tag(:i, nil, :class => "icon-trash"), '#', :class => "list-remove", :rel => url end) if (delete_all && (is_admin? || (is_manager? rescue nil))) titles.each do |title| concat render_title(title[0], title[1], title[2], title[3]) diff --git a/app/views/admin/assets/_sort_headers.html.erb b/app/views/admin/assets/_sort_headers.html.erb index 43cb5927..d266a086 100644 --- a/app/views/admin/assets/_sort_headers.html.erb +++ b/app/views/admin/assets/_sort_headers.html.erb @@ -1,4 +1,5 @@ -<%= render_sort_bar(true, ['title', 'title','span4', 'admin.title'], +<%= render_sort_bar(true, delete_admin_assets_path(:direction => params[:direction], :sort => params[:sort], :filter => @filter, :new_filter => nil, :sort_options => params[:sort_options]), + ['title', 'title','span4', 'admin.title'], ['description', 'description', 'span1-2', 'admin.data'], ['intro', 'intro', 'span1-2', 'admin.file_type'], ['intro', 'intro', 'span1-2', 'admin.file_length'], diff --git a/app/views/admin/assets/index.html.erb b/app/views/admin/assets/index.html.erb index 394e18e8..38ec6b5e 100644 --- a/app/views/admin/assets/index.html.erb +++ b/app/views/admin/assets/index.html.erb @@ -1,22 +1,20 @@ -<%= form_for :assets, :url => delete_admin_assets_path(:direction => params[:direction], :sort => params[:sort], :filter => @filter, :new_filter => nil, :sort_options => params[:sort_options]), :html => {:id => 'delete_all'}, :remote => true do %> - <%= render 'filter' %> - - - - - - - - - - - - - - <%= render :partial => 'asset', :collection => @assets %> - -
-<% end %> +<%= render 'filter' %> + + + + + + + + + + + + + + <%= render :partial => 'asset', :collection => @assets %> + +
<%= link_to content_tag(:i, nil, :class => 'icon-plus icon-white') + t('admin.add'), new_admin_asset_path, :remote => true, :class => 'btn btn-primary pull-right' %> diff --git a/app/views/admin/designs/_sort_headers.html.erb b/app/views/admin/designs/_sort_headers.html.erb index 15f5481f..fb697143 100644 --- a/app/views/admin/designs/_sort_headers.html.erb +++ b/app/views/admin/designs/_sort_headers.html.erb @@ -1,3 +1,4 @@ -<%= render_sort_bar(true, ['title', 'title','span7', 'admin.title'], +<%= render_sort_bar(true, delete_admin_designs_path(:direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options]), + ['title', 'title','span7', 'admin.title'], ['author', 'author', 'span2', 'admin.author'], ['intro', 'intro', 'span2', 'admin.intro']).html_safe %> diff --git a/app/views/admin/designs/index.html.erb b/app/views/admin/designs/index.html.erb index 968b1914..a25b6d7f 100644 --- a/app/views/admin/designs/index.html.erb +++ b/app/views/admin/designs/index.html.erb @@ -2,12 +2,10 @@ <%= render 'admin/sites/side_bar' %> <% end %> -<%= form_for :news_bulletins, :url => delete_admin_designs_path(:direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options]), :html => {:id => 'delete_all'}, :remote => true do %> - <%= render 'filter' %> - - <%= render 'designs' %> -
-<% end %> +<%= render 'filter' %> + + <%= render 'designs' %> +
<%= link_to content_tag(:i, nil, :class => 'icon-plus icon-white') + t('admin.add'), new_admin_design_path, :class => 'btn btn-primary' %> diff --git a/config/routes.rb b/config/routes.rb index 91a28d60..6f5dbd92 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -17,7 +17,7 @@ Orbit::Application.routes.draw do resources :assets do collection do get 'file_upload' - post 'delete' + get 'delete' end end resources :asset_categories @@ -53,7 +53,7 @@ Orbit::Application.routes.draw do resources :designs do collection do get 'upload_package' - post 'delete' + get 'delete' post 'upload_package' end member do diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb index 60784f05..5018b264 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb @@ -292,8 +292,8 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController end def delete - if params[:to_delete] - bulletins = Bulletin.any_in(:_id => params[:to_delete]).delete_all + if params[:ids] + bulletins = Bulletin.any_in(:_id => params[:ids]).delete_all end redirect_to panel_announcement_back_end_bulletins_url(:filter => params[:filter], :direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options]) end diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_sort_headers.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_sort_headers.html.erb index f0d41dea..59606c64 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_sort_headers.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_sort_headers.html.erb @@ -1,4 +1,5 @@ -<%= render_sort_bar(true, ['status', ['is_top', 'is_hot', 'is_hidden', 'is_pending', 'is_checked', 'is_rejected'], 'span1-2', 'bulletin.status'], +<%= render_sort_bar(true, delete_panel_announcement_back_end_bulletins_path(:direction => params[:direction], :sort => params[:sort], :filter => @filter, :new_filter => nil, :sort_options => params[:sort_options]), + ['status', ['is_top', 'is_hot', 'is_hidden', 'is_pending', 'is_checked', 'is_rejected'], 'span1-2', 'bulletin.status'], ['category', 'bulletin_category', 'span1-2', 'bulletin.category'], ['title', 'title','span7', 'bulletin.title'], ['start_date', 'postdate', 'span1-2', 'bulletin.start_date'], diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/index.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/index.html.erb index 51dd07b7..c5a367fc 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/index.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/index.html.erb @@ -1,9 +1,7 @@ -<%= form_for :bulletins, :url => delete_panel_announcement_back_end_bulletins_path(:direction => params[:direction], :sort => params[:sort], :filter => @filter, :new_filter => nil, :sort_options => params[:sort_options]), :html => {:id => 'delete_all'}, :remote => true do %> - <%= render 'filter' %> - - <%= render 'bulletins' %> -
-<% end %> +<%= render 'filter' %> + + <%= render 'bulletins' %> +
<%= link_to content_tag(:i, nil, :class => 'icon-plus icon-white') + t('admin.add'), new_panel_announcement_back_end_bulletin_path, :class => 'btn btn-primary pull-right' %> diff --git a/vendor/built_in_modules/announcement/config/routes.rb b/vendor/built_in_modules/announcement/config/routes.rb index 0640a1f0..b2d8d161 100644 --- a/vendor/built_in_modules/announcement/config/routes.rb +++ b/vendor/built_in_modules/announcement/config/routes.rb @@ -15,7 +15,7 @@ Rails.application.routes.draw do get 'load_quick_edit' end collection do - post 'delete' + get 'delete' end match "file_quick_add/:bulletin_id" => "bulletins#file_quick_add" ,:as => :file_quick_add match "file_quick_edit/:bulletin_id" => "bulletins#file_quick_edit" ,:as => :file_quick_edit diff --git a/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_bulletins_controller.rb b/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_bulletins_controller.rb index fa08cac1..a0765e55 100644 --- a/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_bulletins_controller.rb +++ b/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_bulletins_controller.rb @@ -329,8 +329,8 @@ class Panel::News::BackEnd::NewsBulletinsController < OrbitBackendController end def delete - if params[:to_delete] - news_bulletins = NewsBulletin.any_in(:_id => params[:to_delete]).delete_all + if params[:ids] + news_bulletins = NewsBulletin.any_in(:_id => params[:ids]).delete_all end redirect_to panel_news_back_end_news_bulletins_url(:filter => params[:filter], :direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options]) end diff --git a/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_sort_headers.html.erb b/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_sort_headers.html.erb index d91134b6..66d3269b 100644 --- a/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_sort_headers.html.erb +++ b/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_sort_headers.html.erb @@ -1,4 +1,5 @@ -<%= render_sort_bar(true, ['status', ['is_top', 'is_hot', 'is_hidden', 'is_pending', 'is_checked', 'is_rejected'], 'span1-2', 'news_bulletin.status'], +<%= render_sort_bar(true, delete_panel_news_back_end_news_bulletins_path(:direction => params[:direction], :sort => params[:sort], :filter => @filter, :new_filter => nil, :sort_options => params[:sort_options]), + ['status', ['is_top', 'is_hot', 'is_hidden', 'is_pending', 'is_checked', 'is_rejected'], 'span1-2', 'news_bulletin.status'], ['category', 'news_bulletin_category', 'span1-2', 'news_bulletin.category'], ['title', 'title','span7', 'news_bulletin.title'], ['start_date', 'postdate', 'span1-2', 'news_bulletin.start_date'], diff --git a/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/index.html.erb b/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/index.html.erb index 3f889a99..d16bb55c 100644 --- a/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/index.html.erb +++ b/vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/index.html.erb @@ -1,9 +1,7 @@ -<%= form_for :news_bulletins, :url => delete_panel_news_back_end_news_bulletins_path(:direction => params[:direction], :sort => params[:sort], :filter => @filter, :new_filter => nil, :sort_options => params[:sort_options]), :html => {:id => 'delete_all'}, :remote => true do %> - <%= render 'filter' %> - - <%= render 'news_bulletins' %> -
-<% end %> +<%= render 'filter' %> + + <%= render 'news_bulletins' %> +
<%= link_to content_tag(:i, nil, :class => 'icon-plus icon-white') + t('admin.add'), new_panel_news_back_end_news_bulletin_path, :class => 'btn btn-primary' %> diff --git a/vendor/built_in_modules/news/config/routes.rb b/vendor/built_in_modules/news/config/routes.rb index 701136e5..5220248c 100644 --- a/vendor/built_in_modules/news/config/routes.rb +++ b/vendor/built_in_modules/news/config/routes.rb @@ -15,7 +15,7 @@ Rails.application.routes.draw do get 'load_quick_edit' end collection do - post 'delete' + get 'delete' end match "file_quick_add/:news_bulletin_id" => "news_bulletins#file_quick_add" ,:as => :file_quick_add match "file_quick_edit/:news_bulletin_id" => "news_bulletins#file_quick_edit" ,:as => :file_quick_edit diff --git a/vendor/built_in_modules/page_content/app/views/panel/page_content/back_end/page_contexts/_sort_headers.html.erb b/vendor/built_in_modules/page_content/app/views/panel/page_content/back_end/page_contexts/_sort_headers.html.erb index 7a37d4a7..0c15e3e1 100644 --- a/vendor/built_in_modules/page_content/app/views/panel/page_content/back_end/page_contexts/_sort_headers.html.erb +++ b/vendor/built_in_modules/page_content/app/views/panel/page_content/back_end/page_contexts/_sort_headers.html.erb @@ -1,4 +1,4 @@ -<%= render_sort_bar(false, ['name', 'page','span7', 'page_context.name'], +<%= render_sort_bar(false, nil, ['name', 'page','span7', 'page_context.name'], ['version', 'version', 'span2', 'page_context.version'], ['update_time', 'updated_at', 'span2', 'page_context.update_time'], ['last_modified', 'update_user_id', 'span2', 'page_context.last_modified']).html_safe %> diff --git a/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/back_end/web_links_controller.rb b/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/back_end/web_links_controller.rb index ef96e7d3..1f2263d3 100644 --- a/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/back_end/web_links_controller.rb +++ b/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/back_end/web_links_controller.rb @@ -124,8 +124,8 @@ class Panel::WebResource::BackEnd::WebLinksController < OrbitBackendController end def delete - if params[:to_delete] - web_links = WebLink.any_in(:_id => params[:to_delete]).delete_all + if params[:ids] + web_links = WebLink.any_in(:_id => params[:ids]).delete_all end redirect_to panel_web_resource_back_end_web_links_url(:direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options]) end diff --git a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_sort_headers.html.erb b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_sort_headers.html.erb index a53e38bd..4d3bc2d3 100644 --- a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_sort_headers.html.erb +++ b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/_sort_headers.html.erb @@ -1,4 +1,5 @@ -<%= render_sort_bar(true, ['status', ['is_top', 'is_hot', 'is_hidden', 'is_pending', 'is_checked', 'is_rejected'], 'span1', 'bulletin.status'], +<%= render_sort_bar(true, delete_panel_web_resource_back_end_web_links_path(:direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options]), + ['status', ['is_top', 'is_hot', 'is_hidden', 'is_pending', 'is_checked', 'is_rejected'], 'span1', 'bulletin.status'], ['category', 'bulletin_category', 'span2', 'bulletin.category'], ['title', 'title','span3', 'bulletin.title'], ['tags', 'tags', 'span2', 'bulletin.tags']).html_safe %> \ No newline at end of file diff --git a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/index.html.erb b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/index.html.erb index 8a300f7a..d8215e9d 100644 --- a/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/index.html.erb +++ b/vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/index.html.erb @@ -1,20 +1,18 @@ -<%= form_for :news_bulletins, :url => delete_panel_web_resource_back_end_web_links_path(:direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options]), :html => {:id => 'delete_all'}, :remote => true do %> - <%= render 'filter' %> - - - - - - - - - - - - <%= render :partial => 'web_link', :collection => @web_links %> - -
-<% end %> +<%= render 'filter' %> + + + + + + + + + + + + <%= render :partial => 'web_link', :collection => @web_links %> + +
<%= link_to content_tag(:i, nil, :class => 'icon-plus icon-white') + t('announcement.add_new'), new_panel_web_resource_back_end_web_link_path, :class => 'btn btn-primary pull-right' %> diff --git a/vendor/built_in_modules/web_resource/config/routes.rb b/vendor/built_in_modules/web_resource/config/routes.rb index 02c81a82..d585c6b3 100644 --- a/vendor/built_in_modules/web_resource/config/routes.rb +++ b/vendor/built_in_modules/web_resource/config/routes.rb @@ -6,7 +6,7 @@ Rails.application.routes.draw do root :to => "web_links#index" resources :web_links do collection do - post 'delete' + get 'delete' end end resources :web_link_categorys