Add isotope, categories for announcement page, sort for announcement

This commit is contained in:
Christophe Vilayphiou committed 2012-02-23 15:52:58 +08:00
1 parent 53ed4b0404
commit 63d7810b35
20 files changed
+704 -43

No files matched your search

@@ -12,7 +12,9 @@ class Panel::Announcement::BackEnd::BulletinsController < ApplicationController
# @bulletins = Bulletin.where("bulletin_category_id" => params[:bulletin_category_id]).desc("postdate") if params[:bulletin_category_id]
@bulletins = Bulletin.search(params[:search], params[:category_id]).order_by([params[:sort], params[:direction]])
# @bulletins = Bulletin.search(params[:search], params[:category_id])
# @bulletins = Bulletin.all.order_by([params[:sort], params[:direction]])
@bulletins = params[:sort] ? get_sorted_bulletins : Bulletin.all
@bulletin_categories = BulletinCategory.all
module_app = ModuleApp.first(:conditions => {:key => 'announcement'})
@@ -20,6 +22,7 @@ class Panel::Announcement::BackEnd::BulletinsController < ApplicationController
respond_to do |format|
format.html # index.html.erb
format.js
format.xml { render :xml => @bulletins }
end
end
@@ -145,6 +148,36 @@ class Panel::Announcement::BackEnd::BulletinsController < ApplicationController
def get_categorys(id = nil)
@bulletin_categorys = (id ? BulletinCategory.find(id).to_a : BulletinCategory.excludes('disabled' => true))
end
def get_sorted_bulletins
bulletins = Bulletin.all
case params[:sort]
when 'postdate', 'deadline'
bulletins.order_by([params[:sort], params[:direction]])
when 'category'
category_ids = bulletins.distinct(:bulletin_category_id)
categories = BulletinCategory.find(category_ids) if category_ids
if categories
h = Hash.new
categories.each { |category| h[category.i18n_variable[I18n.locale]] = category.id }
sorted = params[:direction].eql?('asc') ? h.sort : h.sort.reverse!
sorted_categorys = sorted.collect {|a| bulletins.where(:bulletin_category_id => a[1]).entries }
sorted_categorys.flatten
else
nil
end
when 'title'
h = Hash.new
bulletins.each { |bulletin| h[bulletin.title[I18n.locale]] = bulletin }
sorted = params[:direction].eql?('asc') ? h.sort : h.sort.reverse!
sorted.collect {|a| a[1] }
when 'status'
# a << bulletins.order_by(:is_top, params[:direction]).order_by
# a << bulletins.where(:is_hot => true).entries
# a << bulletins.where(:is_hidden => true).entries
# a.flatten.uniq
end
end
end
@@ -10,9 +10,12 @@ class Panel::Announcement::FrontEnd::BulletinsController < ObitWidgetController
def index
date_now = Time.now
@bulletins = Bulletin.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page]).per(1)
date_now = Time.now
if params[:bulletin_category_id]
@bulletins = Bulletin.where(:bulletin_category_id => params[:bulletin_category_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page]).per(1)
else
@bulletins = Bulletin.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page]).per(1)
end
get_categorys
end
@@ -0,0 +1,36 @@
<thead>
<tr class="sort-header">
<th class="span1 strong">
<input type="checkbox">
<a href class="list-remove"><i class="icon-trash"></i></a>
</th>
<th id="sort-status" class="sort span1 <%= is_sort_active?('status') %>">
<%= link_to (t('bulletin.status') + content_tag(:b, nil)), panel_announcement_back_end_bulletins_path(sortable('status')) %>
</th>
<th id="sort-category" class="sort span1-2 <%= is_sort_active?('category') %>" rel="<%= panel_announcement_back_end_bulletins_path(sortable('category')) %>">
<%= t('bulletin.category') %>
<%= content_tag(:b, nil, :class => is_sort?('category')) %>
</th>
<th id="sort-title" class="sort span7 <%= is_sort_active?('title') %>" rel="<%= panel_announcement_back_end_bulletins_path(sortable('title')) %>">
<%= t('bulletin.title') %>
<%= content_tag(:b, nil, :class => is_sort?('title')) %>
</th>
<th id="sort-postdate" class="sort span1-2 <%= is_sort_active?('postdate') %>" rel="<%= panel_announcement_back_end_bulletins_path(sortable('postdate')) %>">
<%= t('bulletin.start_date') %>
<%= content_tag(:b, nil, :class => is_sort?('postdate')) %>
</th>
<th id="sort-deadline" class="sort span1-2 <%= is_sort_active?('deadline') %>" rel="<%= panel_announcement_back_end_bulletins_path(sortable('deadline')) %>">
<%= t('bulletin.end_date') %>
<%= content_tag(:b, nil, :class => is_sort?('deadline')) %>
</th>
<th id="sort-tags" class="sort span1-2">
<%= link_to (t('bulletin.tags') + content_tag(:b, nil)), panel_announcement_back_end_bulletins_path(sortable('tags')) %>
</th>
<th id="sort-update_user_id" class="sort span1-2">
<%= link_to (t('bulletin.last_modified') + content_tag(:b, nil)), panel_announcement_back_end_bulletins_path(sortable('update_user_id')) %>
</th>
</tr>
</thead>
<tbody class="sort-holder">
<%= render :partial => 'bulletin', :collection => @bulletins %>
</tbody>
@@ -3,7 +3,7 @@
<div class="control-group">
<label class="control-label">Picture</label>
<div class="control-group">
<img class="pull-left upload-picture" src="img/default-img.png" />
<img class="pull-left upload-picture" src="" />
<div class="controls file-upload">
<label class="control-label btn" for="input-upload">
Browse/選擇檔案
@@ -1,31 +1,6 @@
<%= render 'filter' %>
<table class="table main-list">
<thead>
<tr>
<th class="span1 strong">
<input type="checkbox">
<a href class="list-remove"><i class="icon-trash"></i></a>
</th>
<th id="sort-status" class="sort span1">
<%= link_to (t('bulletin.status') + content_tag(:b, nil, :class => "web-symbol")), panel_announcement_back_end_bulletins_path(sortable('status')) %>
</th>
<th id="sort-status" class="sort span1-2">
<%= link_to (t('bulletin.category') + content_tag(:b, nil, :class => "web-symbol")), panel_announcement_back_end_bulletins_path(sortable('category')) %>
</th>
<%= link_to content_tag(:th, (t('bulletin.title') + content_tag(:b, nil, :class => "web-symbol")), :id => "sort-title", :class => "sort span7 select active"), panel_announcement_back_end_bulletins_path %>
<th id="sort-status" class="sort span1-2">
<%= link_to (t('bulletin.start_date') + content_tag(:b, nil, :class => "web-symbol")), panel_announcement_back_end_bulletins_path(sortable('start_date')) %>
</th>
<th id="sort-status" class="sort span1-2">
<%= link_to (t('bulletin.end_date') + content_tag(:b, nil, :class => "web-symbol")), panel_announcement_back_end_bulletins_path(sortable('end_date')) %>
</th>
<%= link_to content_tag(:th, (t('bulletin.tags') + content_tag(:b, nil, :class => "web-symbol")), :id => "sort-tags", :class => "sort span1-2"), panel_announcement_back_end_bulletins_path %>
<%= link_to content_tag(:th, (t('bulletin.last_modified') + content_tag(:b, nil, :class => "web-symbol")), :id => "sort-lastModified", :class => "sort span1-2"), panel_announcement_back_end_bulletins_path %>
</tr>
</thead>
<tbody>
<%= render :partial => 'bulletin', :collection => @bulletins %>
</tbody>
<table id="bulettin_sort_list" class="table main-list">
<%= render 'bulletins' %>
</table>
<div class="form-actions">
@@ -0,0 +1 @@
$("#bulettin_sort_list").html("<%= j render 'bulletins' %>")