From 963a0cb6043e079f8eaf2a1e1fb2e4ae933e80e5 Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Sat, 7 Apr 2012 00:20:52 +0800 Subject: [PATCH] Change filter to js with history for bulletins --- app/assets/javascripts/new_admin.js | 3 +- app/assets/javascripts/side_bar_history.js | 70 ++++++++++++------- .../back_end/bulletins_controller.rb | 5 -- .../back_end/bulletins/_filter.html.erb | 14 ++-- .../back_end/bulletins/_index.html.erb | 20 ++++++ .../back_end/bulletins/_sort_header.html.erb | 38 ++++++++++ .../back_end/bulletins/index.html.erb | 27 +------ .../back_end/bulletins/index.js.erb | 2 + 8 files changed, 114 insertions(+), 65 deletions(-) create mode 100644 vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_index.html.erb create mode 100644 vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_sort_header.html.erb create mode 100644 vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/index.js.erb diff --git a/app/assets/javascripts/new_admin.js b/app/assets/javascripts/new_admin.js index 5741437c..45bfcbbc 100644 --- a/app/assets/javascripts/new_admin.js +++ b/app/assets/javascripts/new_admin.js @@ -12,4 +12,5 @@ //= require orbit-1.0 //= require tinymce-jquery //= require tinymce_orbit -//= require orbit-bar-search \ No newline at end of file +//= require orbit-bar-search +//= require side_bar_history \ No newline at end of file diff --git a/app/assets/javascripts/side_bar_history.js b/app/assets/javascripts/side_bar_history.js index 036c63d4..e9505aa1 100644 --- a/app/assets/javascripts/side_bar_history.js +++ b/app/assets/javascripts/side_bar_history.js @@ -1,31 +1,49 @@ -$(function () { - $('#back_sidebar a, #back_main a.nav').live('click', - function () { - $.getScript(this.href); - history.pushState(null, document.title, this.href); - history_edited = true; - return false; - } - ); +var history_edited = false; - $('#back_main a.reload').live('click', - function () { - $.getScript(this.href); - history.replaceState(null, document.title, this.href); - history_edited = true; - return false; - } - ); - - $('.form').live('submit', function () { - $.post(this.action, $(this).serialize(), null, 'script'); +$('#back_sidebar a, #back_main a.nav').live('click', + function () { + $.getScript(this.href); + history.pushState(null, document.title, this.href); history_edited = true; return false; - }); + } +); - $(window).bind("popstate", function () { - if (history_edited) { - $.getScript(location.href); - } - }); +$('#back_main a.reload').live('click', + function () { + $.getScript(this.href); + history.replaceState(null, document.title, this.href); + history_edited = true; + return false; + } +); + +$('.form').live('submit', function () { + $.post(this.action, $(this).serialize(), null, 'script'); + history_edited = true; + return false; +}); + +$(document).on('click', '.js_history', + function () { + $.getScript(this.href); + history.pushState(null, document.title, this.href); + history_edited = true; + return false; + } +); + +$(document).on('click', '.pagination a', + function () { + $.getScript(this.href); + history.pushState(null, document.title, this.href); + history_edited = true; + return false; + } +); + +$(window).bind("popstate", function () { + if (history_edited) { + $.getScript(location.href); + } }); \ No newline at end of file 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 e8b899eb..3022afe4 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 @@ -285,11 +285,6 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController end end - def get_tags - module_app = ModuleApp.first(:conditions => {:key => 'announcement'}) - @tags = Tag.all(:conditions => {:module_app_id => module_app.id}).order_by(I18n.locale, :asc) - end - def get_tags module_app = ModuleApp.first(:conditions => {:key => 'announcement'}) @tags = Tag.all(:conditions => {:module_app_id => module_app.id}).order_by(I18n.locale, :asc) diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_filter.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_filter.html.erb index f8ea5418..ae4cf6ed 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_filter.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_filter.html.erb @@ -62,25 +62,25 @@ - <%= link_to t('bulletin.status') + content_tag(:b, nil, :class => is_sort?('status')), panel_announcement_back_end_bulletins_path(sortable('status')) %> + <%= link_to t('bulletin.status') + content_tag(:b, nil, :class => is_sort?('status')), panel_announcement_back_end_bulletins_path(sortable('status')), :class => 'js_history' %> - <%= link_to t('bulletin.category') + content_tag(:b, nil, :class => is_sort?('category')), panel_announcement_back_end_bulletins_path(sortable('category')) %> + <%= link_to t('bulletin.category') + content_tag(:b, nil, :class => is_sort?('category')), panel_announcement_back_end_bulletins_path(sortable('category')), :class => 'js_history' %> - <%= link_to t('bulletin.title') + content_tag(:b, nil, :class => is_sort?('title')), panel_announcement_back_end_bulletins_path(sortable('title')) %> + <%= link_to t('bulletin.title') + content_tag(:b, nil, :class => is_sort?('title')), panel_announcement_back_end_bulletins_path(sortable('title')), :class => 'js_history' %> - <%= link_to t('bulletin.start_date') + content_tag(:b, nil, :class => is_sort?('postdate')), panel_announcement_back_end_bulletins_path(sortable('postdate')) %> + <%= link_to t('bulletin.start_date') + content_tag(:b, nil, :class => is_sort?('postdate')), panel_announcement_back_end_bulletins_path(sortable('postdate')), :class => 'js_history' %> - <%= link_to t('bulletin.end_date') + content_tag(:b, nil, :class => is_sort?('deadline')), panel_announcement_back_end_bulletins_path(sortable('deadline')) %> + <%= link_to t('bulletin.end_date') + content_tag(:b, nil, :class => is_sort?('deadline')), panel_announcement_back_end_bulletins_path(sortable('deadline')), :class => 'js_history' %> - <%= link_to t('bulletin.tags') + content_tag(:b, nil, :class => is_sort?('tags')), panel_announcement_back_end_bulletins_path(sortable('tags')) %> + <%= link_to t('bulletin.tags') + content_tag(:b, nil, :class => is_sort?('tags')), panel_announcement_back_end_bulletins_path(sortable('tags')), :class => 'js_history' %> - <%= link_to t('bulletin.last_modified') + content_tag(:b, nil, :class => is_sort?('update_user_id')), panel_announcement_back_end_bulletins_path(sortable('update_user_id')) %> + <%= link_to t('bulletin.last_modified') + content_tag(:b, nil, :class => is_sort?('update_user_id')), panel_announcement_back_end_bulletins_path(sortable('update_user_id')), :class => 'js_history' %> 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 new file mode 100644 index 00000000..9013cde5 --- /dev/null +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_index.html.erb @@ -0,0 +1,20 @@ + <%= render 'filter' %> + + <%= render 'bulletins' %> +
+ + <%= paginate @bulletins, :params => {:direction => params[:direction], :sort => params[:sort]} %> + + + +
+ <%= 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' %> +
+ +<% content_for :page_specific_javascript do %> + <%= javascript_include_tag "bulletin_form" %> +<% end %> diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_sort_header.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_sort_header.html.erb new file mode 100644 index 00000000..c18be27d --- /dev/null +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_sort_header.html.erb @@ -0,0 +1,38 @@ + + + + + + + + + + + + + +
+ + + + <%= t('bulletin.status') %> + <%= content_tag(:b, nil, :class => is_sort?('status')) %> + + <%= t('bulletin.category') %> + <%= content_tag(:b, nil, :class => is_sort?('category')) %> + + <%= t('bulletin.title') %> + <%= content_tag(:b, nil, :class => is_sort?('title')) %> + + <%= t('bulletin.start_date') %> + <%= content_tag(:b, nil, :class => is_sort?('postdate')) %> + + <%= t('bulletin.end_date') %> + <%= content_tag(:b, nil, :class => is_sort?('deadline')) %> + + <%= t('bulletin.tags') %> + <%= content_tag(:b, nil, :class => is_sort?('tags')) %> + + <%= t('bulletin.last_modified') %> + <%= content_tag(:b, nil, :class => is_sort?('update_user_id')) %> +
\ No newline at end of file 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 2925f0db..a9f90735 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,26 +1 @@ -<%= render 'filter' %> - - <%= render 'bulletins' %> -
- -<%= paginate @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' %> -
- -<% content_for :page_specific_javascript do %> - <%= javascript_include_tag "bulletin_form" %> -<% end %> +<%= render 'index' %> \ No newline at end of file diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/index.js.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/index.js.erb new file mode 100644 index 00000000..f9bc6a8b --- /dev/null +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/index.js.erb @@ -0,0 +1,2 @@ +$("#main-wrap").html("<%= j render 'index' %>"); +mainTablePosition(); \ No newline at end of file