adjust tag and sort

This commit is contained in:
JiangRu 2014-10-23 15:03:21 +08:00
parent 6b0a6a1fc8
commit d33b0fe5a7
13 changed files with 106 additions and 282 deletions

View File

@ -9,70 +9,48 @@ class Admin::AsksController < OrbitAdminController
@app_title = "ask"
end
# 重新定義排序
def sort
unless params[:sort].blank?
case params[:sort]
when "status"
@sort = {:status=>params[:order]}
when "category"
@sort = {:category_id=>params[:order]}
when "start_date"
@sort = {:postdate=>params[:order]}
when "end_date"
@sort = {:deadline=>params[:order]}
when "last_modified"
@sort = {:update_user_id=>params[:order]}
when "banner"
@sort = {'banner_id'=>params[:order]}
when "banner_name"
@sort = {:title=>params[:order]}
when "effect"
@sort = {:ad_fx=>params[:order]}
when "transition_interval"
@sort = {:timeout=>params[:order]}
when "transition_speed"
@sort = {:speed=>params[:order]}
when "size"
@sort = {:height=>params[:order]}
when "link"
@sort = {:out_link=>params[:order]}
else
s = Sanitize.clean(params[:sort]).to_sym
@sort = {s=>params[:order]}
end
else
@sort = {:created_at=>'desc'}
end
@sort
end
# 重新定義分類搜尋
def filter_fields(categories)
def filter_fields(categories, tags)
{
:status=>[{:title=>"待處理",:id=>"is_hot"},{:title=>"已處理",:id=>"is_top"},{:title=>"轉介其他單位",:id=>"is_hidden"}],
:category=>categories.map{|c| {:title=>(c.title.blank? ? " " : c.title), :id=>c.id}}
:situation=>[{:title=>"is_waiting",:id=>"is_waiting"},{:title=>"is_processed",:id=>"is_processed"},{:title=>"is_referral",:id=>"is_referral"}],
:category=>categories.map{|c| {:title=>(c.title.blank? ? " " : c.title), :id=>c.id}},
:identity=>tags.map{|tag| {:title=>(tag.name.blank? ? " " : tag.name), :id=>tag.id}}
}
end
# 抓取網址的狀態參數
def filter2(type)
case type
when "status"
params[:filters][:status].blank? ? [] : params[:filters][:status] rescue []
when "situation"
params[:filters][:situation].blank? ? [] : params[:filters][:situation] rescue []
when "identity"
params[:filters][:identity].blank? ? [] : params[:filters][:identity] rescue []
end
end
def index
@tags = @module_app.tags
@categories = @module_app.categories
@filter_fields = filter_fields(@categories)
@filter_fields = filter_fields(@categories, @tags)
# 列表欄位
@table_fields = [:status, :category, :title, 'ask.name', 'ask.created_at']
@table_fields = [:situation, :category, :title, 'ask.name', 'ask.created_at']
# 列表排序
if filter2("status").blank?
@askquestions = AskQuestion.order_by(sort) .with_categories(filters("category"))
# debugger
if filter2("situation").blank? and filter2("identity").blank?
@askquestions = AskQuestion.order_by(sort)
.with_categories(filters("category"))
elsif filter2("situation").blank?
@askquestions = AskQuestion.order_by(sort)
.with_categories(filters("category"))
.any_in(:identity => filter2("identity"))
elsif filter2("identity").blank?
@askquestions = AskQuestion.order_by(sort)
.with_categories(filters("category"))
.any_in(:situation => filter2("situation"))
else
@askquestions = AskQuestion.order_by(sort) .with_categories(filters("category")) .where(:status.in => filter2("status"))
@askquestions = AskQuestion.order_by(sort)
.with_categories(filters("category"))
.any_in(:identity => filter2("identity"))
.any_in(:situation => filter2("situation"))
end
# 分頁
@ -82,6 +60,10 @@ class Admin::AsksController < OrbitAdminController
end
end
def search_tag(tag)
Tag.find(tag).name_translations{}
end
def edit
@ask_question = AskQuestion.find(params[:id])
@url = admin_ask_path(@ask_question)
@ -149,16 +131,18 @@ class Admin::AsksController < OrbitAdminController
AskQuestion.human_attribute_name(:reply),
AskQuestion.human_attribute_name(:comment)]
@ask_questions.each do |ask_question|
csv << [ ask_question.category.title,
ask_question.name,
ask_question[:identity],
ask_question.mail,
ask_question.phone,
ask_question.fax,
ask_question.title,
ask_question.content,
ask_question.reply,
ask_question.comment ]
Tag.where({:id => ask_question[:identity]}).each do |tag|
csv << [ ask_question.category.title,
ask_question.name,
tag.name,
ask_question.mail,
ask_question.phone,
ask_question.fax,
ask_question.title,
ask_question.content,
ask_question.reply,
ask_question.comment ]
end
end
end
send_data csv.encode('Big5'), type: 'text/csv', filename: "Questions-#{date_start}-#{date_end}.csv"

View File

@ -7,10 +7,12 @@ class AsksController < ApplicationController
def index
module_app = ModuleApp.where(:key => "ask").first
categories = module_app.categories
tags = module_app.tags
ask_question = AskQuestion.new
{
"ask_question" => ask_question,
"categories" => categories,
"tags" => tags,
"module_app" => module_app
}
end

View File

@ -1,8 +1,9 @@
class AskQuestion
include Mongoid::Document
include Mongoid::Timestamps
include ActiveModel::Validations
# include ActiveModel::Validations
include OrbitCategory::Categorizable
include OrbitTag::Taggable
# 欄位
field :name, type: String
@ -15,11 +16,11 @@ class AskQuestion
field :reply, type: String
field :comment, type: String
field :status, type: String, default: "is_hot" #預設待處理
field :situation, type: String, default: "is_waiting" #預設待處理
field :send_email, type: Boolean, default: false
field :email_id
validates_presence_of :name, :identity, :mail, :title, :content
# validates_presence_of :name, :identity, :mail, :title, :content
def email
mail = Email.find(self.email_id) rescue nil

View File

@ -1,186 +0,0 @@
<% content_for :right_nav do %>
<% if !search_dom_id.nil?%>
<div class="searchClear pull-left" style="clear: left;">
<form id="module-search-form">
<input type="text" id="filter-input" class="search-query input-medium" placeholder="<%= t(:search_) %>" value="<%=params[:keywords]%>">
</form>
<img id="search-preloader" src="/assets/preloader.gif" style="height: 40px; position: absolute; left: 220px; top: -5px; display:none;">
</div>
<% end %>
<ul class="nav nav-pills filter-nav pull-right">
<% fields.keys.each do |field| %>
<li class="accordion-group">
<div class="accordion-heading">
<a href="#collapse-<%= field %>" data-toggle="collapse" data-parent="#filter" class="accordion-toggle"><%= t(field) %></a>
</div>
</li>
<% end %>
</ul>
<div class="filter-group accordion-group">
<% fields.keys.each do |field| %>
<div class="accordion-body collapse" id="collapse-<%= field %>">
<div class="accordion-inner pagination-right" data-toggle="buttons-checkbox">
<% fields[field].each do |val| %>
<%= link_to (val[:title].blank? ? "" : t(val[:title])), "#", :onclick => "filter.addFilter('filters[#{field}][]=#{val[:id]}')", :class => "btn btn-small #{is_filter_active?(field, val[:id])}", :id => "filter_#{val[:id]}" %>
<% end %>
</div>
<div class="filter-clear">
<a href="#" onclick="filter.clearFilter();" class="btn btn-link btn-small"><i class="icons-cycle"></i> <%= t(:clear) %></a>
</div>
</div>
<% end %>
</div>
<% end %>
<script type="text/javascript">
<% if !search_dom_id.nil?%>
var interval = 0;
var keyword;
var searchLock=false;
$("#filter-input").bind("input", function() {queueSearch();});
$("#module-search-form").submit(function(){queueSearch(); return false; });
var params = function(key){
var result = {};
var datas = window.location.search ? window.location.search.replace('?','').split('&') : []
datas.map(function(data){
tmp = data.split("=");
tmp[1] = decodeURIComponent(tmp[1]);
if(key){
if(tmp[0]==key){
if(tmp[0].indexOf('[]')>=0){
if(!Array.isArray(result)) result = [];
result.push(tmp[1]);
}else{
result = tmp[1];
}
}
}else{
if(tmp[0].indexOf('[]')>=0){
if(typeof(result[tmp[0]]) == "undefined") result[tmp[0]] = [];
result[tmp[0]].push(tmp[1]);
}else{
result[tmp[0]] = tmp[1];
}
}
});
return result;
}
var queueSearch = function(){
if($("#filter-input").val()!=keyword){
keyword = $("#filter-input").val();
interval=500;
if(!searchLock) moduleSearch();
}
}
var moduleSearch = function(){
$("#search-preloader").fadeIn();
searchLock = true;
if(interval==0){
url = document.URL;
url = url.replace('#','');
if(url.indexOf("keywords=")>=0){
url = url.replace("keywords="+encodeURIComponent(params("keywords")),"keywords="+keyword)
}else{
url = (url.indexOf("?")>=0) ? url+"&keywords="+keyword : url+"?keywords="+keyword
}
url = url.replace("page="+params("page"),"page=1");
history.pushState(null, null, url);
$.get(url,function(data){
searchLock = false;
$("#<%= search_dom_id %>").html(data);
bindPagination();
$("#search-preloader").fadeOut();
});
}else{
interval -= 100;
setTimeout(moduleSearch,100);
}
}
<% end %>
var bindPagination = function(){
$(".pagination a").click(function(){
filter.updateTable($(this).attr('href'),false,true);
return false;
});
}
var Filter = function(dom){
var self = this;
var makeFilters = function(){
return (window.location.search ? window.location.search.replace('?','').split('&') : []);
}
var filters = makeFilters(),
dom = $(dom),
mainUrl = window.location.pathname;
this.updateTable = function(url, goback, is_pagination){
update = true;
xurl = (url == null ? ( filters.length ? mainUrl + "?" + filters.join('&') : mainUrl ) : url);
$.ajax({
url : xurl,
type : "get",
dataType : "html"
}).done(function(data){
if(is_pagination){
history.pushState(null, null, decodeURIComponent(xurl));
}else{
if(!goback) history.replaceState(null, null, decodeURIComponent(xurl));
}
filters = makeFilters();
dom.html(data);
bindPagination();
update = false;
})
}
this.addFilter = function(filter){
filters = makeFilters();
$.each(filters,function(idx,data){
if(typeof(data)=="undefined") return true;
if(data.indexOf("page=")>-1) filters.splice(idx,1);
});
if( (index = filters.indexOf(filter) ) > -1){
mainUrl = mainUrl.replace(filter,'');
filters.splice(index,1);
}else{
filters.push(filter);
}
self.updateTable();
return false;
};
this.clearFilter = function(){
$(".filter-group a.active").removeClass("active");
filters = [];
self.updateTable();
return false;
}
window.onpopstate = function(event){
if(!update){
$("#filter-input").val( $.isEmptyObject(params('keywords')) ? "" : params('keywords') );
self.updateTable(document.location, true);
$(".filter-group .btn-small").removeClass('active');
$.each(document.location.search.split('&'),function(key,filter){
if(filter.split('=')[0].indexOf("keywords")>=0) return true;
$('#filter_'+filter.split('=')[1]).addClass('active');
});
}
update = false;
}
}
var update = false;
var filter;
$(document).ready(function(){
filter = new Filter("#<%= search_dom_id %>");
bindPagination();
});
</script>

View File

@ -11,7 +11,11 @@
<table class="table">
<tr>
<td><%= AskQuestion.human_attribute_name(:name) %><%= @ask_question.name %></td>
<td><%= AskQuestion.human_attribute_name(:identity) %><%= @ask_question[:identity] %></td>
<td><%= AskQuestion.human_attribute_name(:identity) %>
<% Tag.where({:id => @ask_question[:identity]}).each do |tag| %>
<%= tag.name %>
<% end %>
</td>
<td><%= AskQuestion.human_attribute_name(:mail) %><%= @ask_question.mail %></td>
<td><%= AskQuestion.human_attribute_name(:phone) %><%= @ask_question.phone %></td>
<td><%= AskQuestion.human_attribute_name(:fax) %><%= @ask_question.fax %></td>
@ -20,7 +24,7 @@
<td colspan="5"><%= AskQuestion.human_attribute_name(:title) %><%= @ask_question.title %></td>
</tr>
<tr>
<td colspan="5"><%= AskQuestion.human_attribute_name(:content) %><br/><%= @ask_question.content %></td>
<td colspan="5"><%= AskQuestion.human_attribute_name(:content) %><br/><%= @ask_question.content.gsub(/[(\n)(\r)]/, "\n" => "<br/>", "\r" => "" ).html_safe %></td>
</tr>
<tr>
@ -35,10 +39,10 @@
<br/> <%= f.text_field :comment, style: 'width: 500px' %></td>
</tr>
<tr>
<td colspan="5"><%= f.label :status %> <%= f.select :status, [
['待處理', 'is_hot'],
['已處理', 'is_top'],
['轉介其他單位', 'is_hidden']
<td colspan="5"><%= f.label t('situation') %> <%= f.select :situation, [
[t('is_waiting'), 'is_waiting'],
[t('is_processed'), 'is_processed'],
[t('is_referral'), 'is_referral']
] %></td>
</tr>

View File

@ -10,12 +10,12 @@
<% @askquestions.each do |b| %>
<tr>
<td>
<% if b.status == 'is_hot' %>
<span class='label label-important'><%= t('待處理') %></span>
<% elsif b.status == 'is_top' %>
<span class='label label-success'><%= t('已處理') %></span>
<% elsif b.status == 'is_hidden' %>
<span class='label'><%= t('轉介其他單位') %></span>
<% if b.situation == 'is_waiting' %>
<span class='label label-important'><%= t('is_waiting') %></span>
<% elsif b.situation == 'is_processed' %>
<span class='label label-success'><%= t('is_processed') %></span>
<% elsif b.situation == 'is_referral' %>
<span class='label'><%= t('is_referral') %></span>
<% end %>
</td>
<td><%= b.category.title %></td>

View File

@ -5,7 +5,7 @@
</head>
<body>
<p>
<%= @data['reply'] %>
<%= @data['reply'].gsub(/[(\n)(\r)]/, "\n" => "<br/>", "\r" => "" ).html_safe %>
</p>
<br />
<p>此為系統自動發信,請勿直接回覆</p>

View File

@ -7,28 +7,32 @@
<h1><%= @data['title'] %></h1>
<table>
<tr>
<td><%= AskQuestion.human_attribute_name(:name) %></td>
<th><%= AskQuestion.human_attribute_name(:name) %></th>
<td><%= @data['name'] %></td>
</tr>
<tr>
<td><%= AskQuestion.human_attribute_name(:identity) %></td>
<td><%= @data['identity'] %></td>
<th><%= AskQuestion.human_attribute_name(:identity) %></th>
<td>
<% Tag.where({:id => @data['identity']}).each do |tag| %>
<%= tag.name %>
<% end %>
</td>
</tr>
<tr>
<td><%= AskQuestion.human_attribute_name(:mail) %></td>
<th><%= AskQuestion.human_attribute_name(:mail) %></th>
<td><%= @data['mail'] %></td>
</tr>
<tr>
<td><%= AskQuestion.human_attribute_name(:phone) %></td>
<th><%= AskQuestion.human_attribute_name(:phone) %></th>
<td><%= @data['phone'] %></td>
</tr>
<tr>
<td><%= AskQuestion.human_attribute_name(:fax) %></td>
<th><%= AskQuestion.human_attribute_name(:fax) %></th>
<td><%= @data['fax'] %></td>
</tr>
<tr>
<td><%= AskQuestion.human_attribute_name(:content) %></td>
<td><%= @data['content'] %></td>
<th><%= AskQuestion.human_attribute_name(:content) %></th>
<td><%= @data['content'].gsub(/[(\n)(\r)]/, "\n" => "<br/>", "\r" => "" ).html_safe %></td>
</tr>
</table>
<p>此為系統自動發信,請勿直接回覆</p>

View File

@ -1,6 +1,7 @@
<% data = action_data
@ask_question = data["ask_question"]
@categories = data["categories"]
@tags = data["tags"]
@module_app = data["module_app"]
%>
@ -23,14 +24,10 @@
</div>
</div>
<!-- 身分 -->
<div class="control-group">
<div class="control-group">
<%= f.label :identity, class: 'control-label required' %>
<div class="controls">
<%= f.select :identity, options_for_select( [t('ask.teacher'),
t('ask.stuff'),
t('ask.student'),
t('ask.schoolfellow'),
t('ask.others')].map{|i| [i, i]} ) %>
<%= select_tag "ask_question[identity]", options_for_select(@tags.collect{|t| [ t.name, t.id ]}) if !@tags.nil? %>
</div>
</div>
<!-- Email -->

View File

@ -17,5 +17,5 @@ Gem::Specification.new do |s|
s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
s.test_files = Dir["test/**/*"]
s.add_dependency "gotcha"
# s.add_dependency ~> "gotcha"
end

View File

@ -1,8 +1,12 @@
en:
situation: Situation
is_waiting: Pending
is_processed: Processed
is_referral: Rreferral
ask:
ask: Ask
all_articles: All
export: Export
exports: Export
reply: Reply
reply_success: Reply success
to: To
@ -15,10 +19,11 @@ en:
schoolfellow: Schoolfellow
others: Others
acknowledgements: Thank You
admin: Administrator
admins: Administrator
new_question: New question
pending: Pending
mongoid:
attributes:
ask_question:
ask_category_id: Ask Category
ask_category_id: Ask Category
identity: Identity

View File

@ -1,4 +1,11 @@
zh_tw:
situation: 狀況
identity: 身份
is_waiting: 待處理
is_processed: 已處理
is_referral: 轉介其他單位
module_name:
ask: 發問
recaptcha:
@ -27,7 +34,6 @@ zh_tw:
acknowledgements: 感謝詞
admins: 管理者
new_question: 新的發問
pending: 待處理
mongoid:
attributes:

View File

@ -6,7 +6,7 @@ module Ask
base_url File.expand_path File.dirname(__FILE__)
# widget_methods ["widget","widget1"]
# widget_settings [{"data_count"=>10}]
#taggable "AskQuestion"
taggable "AskQuestion"
categorizable
authorizable
frontend_enabled
@ -45,6 +45,13 @@ module Ask
:priority=>5,
:active_for_action=>{'admin/asks'=>'exports'},
:available_for => 'managers'
context_link 'tags',
:link_path=>"admin_module_app_tags_path" ,
:link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'ask').id}",
:priority=>4,
:active_for_action=>{'admin/ask'=>'tags'},
:active_for_tag => 'Ask',
:available_for => 'managers'
# context_link 'new_',
# :link_path=>"new_admin_ask_path" ,
# :priority=>2,