ask module

This commit is contained in:
JiangRu 2014-10-02 14:00:35 +08:00
commit 6b0a6a1fc8
43 changed files with 1345 additions and 0 deletions

8
.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
.bundle/
log/*.log
pkg/
test/dummy/db/*.sqlite3
test/dummy/db/*.sqlite3-journal
test/dummy/log/*.log
test/dummy/tmp/
test/dummy/.sass-cache

14
Gemfile Normal file
View File

@ -0,0 +1,14 @@
source "https://rubygems.org"
# Declare your gem's dependencies in ask.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
gemspec
# Declare any dependencies that are still in development here instead of in
# your gemspec. These might include edge Rails or gems from your path or
# Git. Remember to move these dependencies to your gemspec before releasing
# your gem to rubygems.org.
# To use debugger
# gem 'debugger'

20
MIT-LICENSE Normal file
View File

@ -0,0 +1,20 @@
Copyright 2014 YOURNAME
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

3
README.rdoc Normal file
View File

@ -0,0 +1,3 @@
= Ask
This project rocks and uses MIT-LICENSE.

32
Rakefile Normal file
View File

@ -0,0 +1,32 @@
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
require 'rdoc/task'
RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'Ask'
rdoc.options << '--line-numbers'
rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('lib/**/*.rb')
end
Bundler::GemHelper.install_tasks
require 'rake/testtask'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = false
end
task default: :test

View File

@ -0,0 +1,2 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

View File

View File

@ -0,0 +1,7 @@
/*
Place all the styles related to the matching controller here.
They will automatically be included in application.css.
*/
.table .expired{
color: #BE2E2E;
}

View File

View File

@ -0,0 +1,53 @@
.form-horizontal {
background-color: #fdfdfd;
padding: 2em;
}
.form-horizontal .control-group {
margin-bottom: 1em;
padding-bottom: 0.5em;
}
.form-horizontal .control-label {
font-size: 1em;
float: left;
width: 10em;
text-align: right;
line-height: 1em;
margin-top: 0;
margin-bottom: 0;
display: block;
}
.form-horizontal .control-group .controls {
margin-left: 13.5em;
}
.form-horizontal input[type="text"],
.form-horizontal textarea,
.form-horizontal select {
height: 2.1em;
line-height: 2.1em;
width: 220px;
background-color: #FFF;
border: 1px solid #d7dadb;
border-radius: 0.3em;
}
.form-horizontal textarea {
width: 97%;
height: 180px;
}
/*button*/
.form-horizontal .form-actions {
border-top: 1px solid #d7dadb;
padding: 1em 0 0 20em;
}
/*驗證碼*/
.text-error {
color: #b94a48;
font-size: 10px;
}

View File

@ -0,0 +1,19 @@
class Admin::AskAcknowledgementsController < OrbitAdminController
def initialize
super
@app_title = 'ask_acknowledgement'
end
def index
@ask_acknowledgements = AskAcknowledgement.first || AskAcknowledgement.create
@url = admin_ask_acknowledgement_path(@ask_acknowledgements)
end
def update
@ask_acknowledgements = AskAcknowledgement.first
@ask_acknowledgements.update_attributes(params.require(:ask_acknowledgement).permit!)
redirect_to admin_ask_acknowledgements_path, notice: t('ask.save_success')
end
end

View File

@ -0,0 +1,45 @@
# encoding: utf-8
class Admin::AskAdminsController < OrbitAdminController
def initialize
super
@app_title = 'ask_admin'
end
def index
@ask_admin = AskAdmin.new
@table_fields = [:email]
@ask_admins = AskAdmin.order_by(sort)
end
def create
@ask_admins = AskAdmin.new(ask_admin_params)
@ask_admins.save
redirect_to admin_ask_admins_path
end
def edit
@ask_admin = AskAdmin.find(params[:id])
@table_fields = [:email]
@ask_admins = AskAdmin.order_by(sort)
@url = admin_ask_admin_path(@ask_admin)
end
def update
@ask_admin = AskAdmin.find(params[:id])
@ask_admin.update_attributes(ask_admin_params)
redirect_to admin_ask_admins_path
end
def destroy
@ask_admin = AskAdmin.find(params[:id])
@ask_admin.destroy
redirect_to admin_ask_admins_path
end
def ask_admin_params
params.require(:ask_admin).permit!
end
end

View File

@ -0,0 +1,170 @@
# encoding: utf-8
class Admin::AsksController < OrbitAdminController
include Admin::AsksHelper
before_action ->(module_app = @app_title) { set_variables module_app }
before_action :set_askquestion, only: [:edit, :destroy]
def initialize
super
@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)
{
: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}}
}
end
# 抓取網址的狀態參數
def filter2(type)
case type
when "status"
params[:filters][:status].blank? ? [] : params[:filters][:status] rescue []
end
end
def index
@categories = @module_app.categories
@filter_fields = filter_fields(@categories)
# 列表欄位
@table_fields = [:status, :category, :title, 'ask.name', 'ask.created_at']
# 列表排序
if filter2("status").blank?
@askquestions = AskQuestion.order_by(sort) .with_categories(filters("category"))
else
@askquestions = AskQuestion.order_by(sort) .with_categories(filters("category")) .where(:status.in => filter2("status"))
end
# 分頁
@askquestions = search_data(@askquestions,[:title]).page(params[:page]).per(10)
if request.xhr?
render :partial => "index"
end
end
def edit
@ask_question = AskQuestion.find(params[:id])
@url = admin_ask_path(@ask_question)
end
def destroy
@askquestions.destroy
redirect_to "/admin/asks"
end
def update
@ask_question = AskQuestion.find(params[:id])
@ask_question.update_attributes(params.require(:ask_question).permit!)
if @ask_question.send_email?
build_email(@ask_question)
end
redirect_to admin_asks_path, notice: t('ask.reply_success')
end
def build_email(email_er)
email = Email.new
email.save
email_er.email_id = email.id
email_er.save
@group_mail = email_er.mail
@mail_sentdate = DateTime.now
email_er.email.update_attributes(
:create_user=>current_user,
:mail_sentdate=>@mail_sentdate,
:module_app=>@module_app,
:mail_to=>@group_mail,
:mail_subject=>Site.first.title_translations["zh_tw"]+" #{t('ask.reply')}"+email_er.title,
:template=>'admin/asks/email',
:template_data=>{
"reply" => email_er.reply
}
)
OrbitMailer.set_mail(email_er.email).deliver
end
def export
end
def do_export
Rails.application.config.mongoid.use_activesupport_time_zone = true
date_start = "#{params[:export]['start(1i)']}-#{params[:export]['start(2i)']}-#{params[:export]['start(3i)']}"
date_end = "#{params[:export]['end(1i)']}-#{params[:export]['end(2i)']}-#{params[:export]['end(3i)']}"
@ask_questions = AskQuestion.where(:created_at.gte => date_start.to_datetime, :created_at.lte => date_end.to_datetime+1)
csv = CSV.generate do |csv|
csv << [ t('category'),
AskQuestion.human_attribute_name(:name),
AskQuestion.human_attribute_name(:identity),
AskQuestion.human_attribute_name(:mail),
AskQuestion.human_attribute_name(:phone),
AskQuestion.human_attribute_name(:fax),
AskQuestion.human_attribute_name(:title),
AskQuestion.human_attribute_name(:content),
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 ]
end
end
send_data csv.encode('Big5'), type: 'text/csv', filename: "Questions-#{date_start}-#{date_end}.csv"
end
def set_askquestion
@askquestions = AskQuestion.find(params[:id])
end
end

View File

@ -0,0 +1,73 @@
class AsksController < ApplicationController
def initialize
super
@app_title = 'ask'
end
def index
module_app = ModuleApp.where(:key => "ask").first
categories = module_app.categories
ask_question = AskQuestion.new
{
"ask_question" => ask_question,
"categories" => categories,
"module_app" => module_app
}
end
def create
@ask_question = AskQuestion.new(create_params)
if gotcha_valid? && @ask_question.save
build_email(@ask_question)
redirect_to "#{params[:referer_url]}/?method=thank"
else
redirect_to "#{params[:referer_url]}/?method=sorry"
end
end
def thank
acknowledgement = AskAcknowledgement.last
{
"acknowledgement" => acknowledgement
}
end
def sorry
{}
end
def build_email(email_er)
email = Email.new
email.save
email_er.email_id = email.id
email_er.save
@group_mail = email_er.email_address
@mail_sentdate = DateTime.now
email_er.email.update_attributes(
:create_user=>current_user,
:mail_sentdate=>@mail_sentdate,
:module_app=>@module_app,
:mail_to=>@group_mail,
:mail_subject=>Site.first.title_translations["zh_tw"]+" #{t('ask.new_question')}"+email_er.title,
:template=>'asks/email',
:template_data=>{
"title" => email_er.title,
"name" => email_er.name,
"identity" => email_er[:identity],
"mail" => email_er.mail,
"phone" => email_er.phone,
"fax" => email_er.fax,
"content" => email_er.content
}
)
OrbitMailer.set_mail(email_er.email).deliver
end
def create_params
params.require(:ask_question).permit!
end
end

View File

@ -0,0 +1,27 @@
module Admin::AsksHelper
def page_for_askquestion(askquestion)
ann_page = nil
pages = Page.where(:module=>'ask')
pages.each do |page|
if page.categories.count ==1
if page.categories.include?(askquestion.category.id.to_s)
ann_page = page
end
end
break if !ann_page.nil?
end
if ann_page.nil?
pages.each do |page|
if page.categories.include?(askquestion.category.id.to_s)
ann_page = page
end
break if !ann_page.nil?
end
end
ann_page = pages.first if ann_page.nil?
request.protocol+(request.host_with_port+ann_page.url+'/'+askquestion.to_param).gsub('//','/') rescue "/"
end
end

0
app/mailers/.keep Normal file
View File

0
app/models/.keep Normal file
View File

View File

@ -0,0 +1,6 @@
class AskAcknowledgement
include Mongoid::Document
include Mongoid::Timestamps
field :content, type: String
end

6
app/models/ask_admin.rb Normal file
View File

@ -0,0 +1,6 @@
class AskAdmin
include Mongoid::Document
include Mongoid::Timestamps
field :email, type: String
end

View File

@ -0,0 +1,34 @@
class AskQuestion
include Mongoid::Document
include Mongoid::Timestamps
include ActiveModel::Validations
include OrbitCategory::Categorizable
# 欄位
field :name, type: String
field :identity, type: String
field :mail, type: String
field :phone, type: String
field :fax, type: String
field :title, type: String
field :content, type: String
field :reply, type: String
field :comment, type: String
field :status, type: String, default: "is_hot" #預設待處理
field :send_email, type: Boolean, default: false
field :email_id
validates_presence_of :name, :identity, :mail, :title, :content
def email
mail = Email.find(self.email_id) rescue nil
end
def email_address
email_address = AskAdmin.all.collect{|a| a.email} rescue []
# email_address = email_address +[self.mail] if !self.mail.blank?
email_address.flatten
end
end

View File

@ -0,0 +1,14 @@
<div id="ask-acknowledgements">
<%= form_for @ask_acknowledgements, url: @url, html: { class: 'form-horizontal' } do |f| %>
<div class="control-group">
<%= f.label :content, t('ask.acknowledgements'), class: 'control-label' %>
<div class="controls">
<%= f.text_area :content, rows: 10 %>
</div>
</div>
<div class="form-actions">
<%= f.submit t('submit'), class: 'btn btn-primary' %>
<%= f.button t('cancel'), type: 'reset', class: 'btn' %>
</div>
<% end %>
</div>

View File

@ -0,0 +1,46 @@
<%= render 'layouts/delete_modal', delete_options: @delete_options %>
<table class="table main-list">
<thead>
<tr class="sort-header">
<% @table_fields.each do |f| %>
<%= thead(f) %>
<% end %>
</tr>
</thead>
<tbody>
<% @ask_admins.each do |a| %>
<tr>
<td>
<%= a.email %>
<div class="quick-edit">
<ul class="nav nav-pills">
<% if can_edit_or_delete?(a) %>
<li><a href="/admin/ask_admins/<%=a.id.to_s%>/edit"><%= t(:edit) %></a></li>
<li><a href="#" class="delete text-error" rel="/admin/ask_admins/<%=a.id.to_s%>"><%= t(:delete_) %></a></li>
<% end %>
</ul>
</div>
</td>
</tr>
<% end %>
</tbody>
</table>
<%= form_for @ask_admin, url: @url, html: { class: 'form-horizontal' } do |f| %>
<h2><%= @ask_admin.new_record? ? t(:add) : t(:edit) %></h2>
<div id="widget-title">
<div class="control-group">
<%= f.label :email, class: 'control-label' %>
<div class="controls">
<%= f.text_field :email, class: 'input-xxlarge' %>
</div>
</div>
</div>
<div class="form-actions">
<%= f.submit t(:submit), class: 'btn btn-primary' %>
</div>
<% end %>

View File

@ -0,0 +1,62 @@
<%= render 'layouts/delete_modal', delete_options: @delete_options %>
<table class="table main-list">
<thead>
<tr class="sort-header">
<% @table_fields.each do |f| %>
<%= thead(f) %>
<% end %>
</tr>
</thead>
<tbody>
<% @ask_admins.each do |a| %>
<tr>
<td>
<%= a.email %>
<div class="quick-edit">
<ul class="nav nav-pills">
<% if can_edit_or_delete?(a) %>
<li><a href="/admin/ask_admins/<%=a.id.to_s%>/edit"><%= t(:edit) %></a></li>
<li><a href="#" class="delete text-error" rel="/admin/ask_admins/<%=a.id.to_s%>"><%= t(:delete_) %></a></li>
<% end %>
</ul>
</div>
</td>
</tr>
<% end %>
</tbody>
</table>
<%= javascript_include_tag 'validator' %>
<%= form_for @ask_admin, url: admin_ask_admins_path, html: {class: "form-horizontal main-forms previewable"} do |f| %>
<h2><%= @ask_admin.new_record? ? t(:add) : t(:edit) %></h2>
<div id="widget-title">
<div class="control-group">
<%= f.label :email, class: 'control-label' %>
<div class="controls">
<%= f.text_field :email, class: 'input-xxlarge', data: {"fv-validation" => "required;check_email;", "fv-messages" => "必填欄位;Email不正確;"} %>
</div>
</div>
</div>
<div class="form-actions">
<%= f.submit t(:submit), class: 'btn btn-primary' %>
</div>
<% end %>
<script type='text/javascript'>
$(function(){
var fv = new FormValidator($("#new_ask_admin"));
fv.validate_functions.check_email = function(value){
reg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
if (reg.test(value)) {
return true;
}else{
return false;
}
}
})
</script>

View File

@ -0,0 +1,186 @@
<% 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

@ -0,0 +1,59 @@
<% content_for :page_specific_css do %>
<%= stylesheet_link_tag "lib/main-forms" %>
<%= stylesheet_link_tag "lib/main-list" %>
<% end %>
<% content_for :page_specific_javascript do %>
<%= javascript_include_tag "lib/module-area" %>
<% end %>
<div class="input-area">
<div id="ask-asks">
<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(: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>
</tr>
<tr>
<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>
</tr>
<tr>
<td colspan="5">
<%= f.label :reply %>
<br/> <%= f.text_area :reply, rows: 10, style: 'width: 500px' %>
</td>
</tr>
<tr>
<td colspan="5">
<%= f.label :comment %>
<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>
</tr>
<tr>
<td colspan="5">
<%= f.label :send_email %><%= f.radio_button :send_email, 1, checked: @ask_question.send_email? %><%= t('ask.yes') %>
&nbsp;&nbsp;&nbsp;&nbsp;
<%= f.radio_button :send_email, 0, checked: !@ask_question.send_email? %><%= t('ask.no') %>
</td>
</tr>
</table>
</div>
</div>
<div class="form-actions">
<%= f.submit t('submit'), class: 'btn btn-primary' %>
<%= f.button t('cancel'), type: 'reset', class: 'btn' %>
</div>

View File

@ -0,0 +1,44 @@
<table class="table main-list">
<thead>
<tr class="sort-header">
<% @table_fields.each do |f| %>
<%= thead(f) %>
<% end %>
</tr>
</thead>
<tbody>
<% @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>
<% end %>
</td>
<td><%= b.category.title %></td>
<td>
<%= b.title %>
<div class="quick-edit">
<ul class="nav nav-pills">
<% if can_edit_or_delete?(b) %>
<li><a href="/admin/asks/<%=b.id.to_s%>/edit"><%= t(:edit) %></a></li>
<li><a href="#" class="delete text-error" rel="/admin/asks/<%=b.id.to_s%>"><%= t(:delete_) %></a></li>
<% end %>
</ul>
</div>
</td>
<td><%= b.name %></td>
<td><%= format_value b.created_at %></td>
</tr>
<% end %>
</tbody>
</table>
<%=
content_tag :div, class: "bottomnav clearfix" do
content_tag :div, paginate(@askquestions), class: "pagination pagination-centered"
end
%>

View File

@ -0,0 +1,5 @@
<%= form_for @ask_question, url: @url, html: { class: 'form-horizontal main-forms previewable' } do |f| %>
<fieldset>
<%= render :partial => 'form', locals: {f: f} %>
</fieldset>
<% end %>

View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
</head>
<body>
<p>
<%= @data['reply'] %>
</p>
<br />
<p>此為系統自動發信,請勿直接回覆</p>
</body>
</html>

View File

@ -0,0 +1,21 @@
<div id="asks-export">
<%= form_tag export_admin_asks_path, method: 'post' do |f| %>
<table>
<tr>
<td><%= t('date_') %></td>
<td><%= date_select 'export', :start %> <%= t('ask.to') %></td>
</tr>
<tr>
<td></td>
<td><%= date_select 'export', :end %></td>
</tr>
<tr>
<td colspan="2">
<div class="form-actions">
<%= submit_tag t('submit'), class: 'btn btn-primary' %>
</div>
</td>
</tr>
</table>
<% end %>
</div>

View File

@ -0,0 +1,6 @@
<%= render_filter @filter_fields, "index_table" %>
<span id="index_table">
<%= render 'index'%>
</span>
<%= render 'layouts/delete_modal', delete_options: @delete_options %>

View File

@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<h1><%= @data['title'] %></h1>
<table>
<tr>
<td><%= AskQuestion.human_attribute_name(:name) %></td>
<td><%= @data['name'] %></td>
</tr>
<tr>
<td><%= AskQuestion.human_attribute_name(:identity) %></td>
<td><%= @data['identity'] %></td>
</tr>
<tr>
<td><%= AskQuestion.human_attribute_name(:mail) %></td>
<td><%= @data['mail'] %></td>
</tr>
<tr>
<td><%= AskQuestion.human_attribute_name(:phone) %></td>
<td><%= @data['phone'] %></td>
</tr>
<tr>
<td><%= AskQuestion.human_attribute_name(:fax) %></td>
<td><%= @data['fax'] %></td>
</tr>
<tr>
<td><%= AskQuestion.human_attribute_name(:content) %></td>
<td><%= @data['content'] %></td>
</tr>
</table>
<p>此為系統自動發信,請勿直接回覆</p>
</body>
</html>

View File

@ -0,0 +1,126 @@
<% data = action_data
@ask_question = data["ask_question"]
@categories = data["categories"]
@module_app = data["module_app"]
%>
<%= javascript_include_tag 'validator' %>
<link href="/assets/ask/ask.css" media="screen" rel="stylesheet">
<div id="new-ask-question" class="ask-question">
<%= form_for @ask_question, url: asks_path, html: {class: 'form-horizontal'} do |f| %>
<!-- Category -->
<div class="control-group">
<%= f.label :ask_category_id, class: 'control-label required' %>
<div class="controls">
<%= f.select :category_id, @categories.collect{|t| [ t.title, t.id ]} %>
</div>
</div>
<!-- 姓名 -->
<div class="control-group">
<%= f.label :name, class: 'control-label required' %>
<div class="controls">
<%= f.text_field :name, data: {"fv-validation" => "required;", "fv-messages" => "必填欄位;"} %>
</div>
</div>
<!-- 身分 -->
<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]} ) %>
</div>
</div>
<!-- Email -->
<div class="control-group">
<%= f.label :mail, class: 'control-label required' %>
<div class="controls">
<%= f.text_field :mail, data: {"fv-validation" => "required;check_email;", "fv-messages" => "必填欄位;Email不正確;"} %>
</div>
</div>
<!-- 聯絡電話 -->
<div class="control-group">
<%= f.label :phone, class: 'control-label' %>
<div class="controls">
<%= f.text_field :phone %>
</div>
</div>
<!-- 傳真 -->
<div class="control-group">
<%= f.label :fax, class: 'control-label' %>
<div class="controls">
<%= f.text_field :fax %>
</div>
</div>
<!-- 主旨 -->
<div class="control-group">
<%= f.label :title, class: 'control-label required' %>
<div class="controls">
<%= f.text_field :title, data: {"fv-validation" => "required;", "fv-messages" => "必填欄位;"} %>
</div>
</div>
<!-- 內容 -->
<div class="control-group">
<%= f.label :content, class: 'control-label required' %>
<div class="controls">
<%= f.text_area :content, rows: 8, class: 'input-xlarge' %>
</div>
</div>
<!-- 驗證碼 -->
<div class="control-group">
<%= f.label :recaptcha, class: 'control-label' %>
<div class="controls">
<%= gotcha_error %>
<%= gotcha %>
</div>
</div>
<div class="form-actions">
<input type="hidden" name="referer_url" value="<%= request.original_url.split(request.env["HTTP_HOST"]).last %>">
<%= f.submit t('submit'), class: 'btn btn-primary', :id => 'button-mail' %>
<%= f.button t('cancel'), type: 'reset', class: 'btn' %>
</div>
<% end %>
</div>
<script type='text/javascript'>
// $(function(){
// $("#button-mail").click(function(){
// if( $("#ask_question_name").val()!='' ) $("#ask_question_name").css('border','');
// if( $("#ask_question_email").val()!='' ) $("#ask_question_email").css('border','');
// if( $("#ask_question_title").val()!='' ) $("#ask_question_title").css('border','');
// if( $("#ask_question_content").val()!='' ) $("#ask_question_content").css('border','');
// if( $("#ask_question_name").val()=='' ) $("#ask_question_name").css('border','1px solid #F00');
// if( $("#ask_question_email").val()=='' ) $("#ask_question_email").css('border','1px solid #F00');
// if( $("#ask_question_title").val()=='' ) $("#ask_question_title").css('border','1px solid #F00');
// if( $("#ask_question_content").val()=='' ) $("#ask_question_content").css('border','1px solid #F00');
// });
$('#new-ask-question .required').each(function() {
$(this).text('*' + $(this).text());
});
// $('#new-ask-question form') .submit(function() {
// $.post($(this).attr('action'), $(this).serializeArray());
// return false;
// });
// });
$(function(){
var fv = new FormValidator($("#new_ask_question"));
fv.validate_functions.check_email = function(value){
reg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
if (reg.test(value)) {
return true;
}else{
return false;
}
}
// fv.validate_functions.test_function = function(value, element){
// }
})
</script>

View File

@ -0,0 +1,8 @@
<link href="/assets/ask/ask.css" media="screen" rel="stylesheet">
<div class="form-horizontal">
<p>發問失敗,請重新發問!</p>
<p>Failed to ask questions, please re-ask!</p>
<div class="form-actions">
<input name="goback" type="button" class="btn" onclick="window.history.go(-1);" onkeypress="window.history.go(-1);" value="回上一頁">
</div>
</div>

View File

@ -0,0 +1,7 @@
<% data = action_data
@acknowledgement = data["acknowledgement"]
%>
<link href="/assets/ask/ask.css" media="screen" rel="stylesheet">
<div class="form-horizontal">
<%= @acknowledgement[:content].gsub(/[(\n)(\r)]/, "\n" => "<br/>", "\r" => "" ).html_safe %>
</div>

21
ask.gemspec Normal file
View File

@ -0,0 +1,21 @@
$:.push File.expand_path("../lib", __FILE__)
# Maintain your gem's version:
require "ask/version"
# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = "ask"
s.version = Ask::VERSION
s.authors = ["RulingDigital"]
s.email = ["orbit@rulingcom.com"]
s.homepage = "http://www.rulingcom.com"
s.summary = "Ask for orbit"
s.description = "Ask for orbit"
s.license = "MIT"
s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
s.test_files = Dir["test/**/*"]
s.add_dependency "gotcha"
end

4
bin/rails Executable file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env ruby
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
require 'rails/commands'

24
config/locales/en.yml Normal file
View File

@ -0,0 +1,24 @@
en:
ask:
ask: Ask
all_articles: All
export: Export
reply: Reply
reply_success: Reply success
to: To
widget:
index: Form
save_success: Successfully saved
teacher: Teacher
stuff: Stuff
student: Student
schoolfellow: Schoolfellow
others: Others
acknowledgements: Thank You
admin: Administrator
new_question: New question
pending: Pending
mongoid:
attributes:
ask_question:
ask_category_id: Ask Category

48
config/locales/zh_tw.yml Normal file
View File

@ -0,0 +1,48 @@
zh_tw:
module_name:
ask: 發問
recaptcha:
errors:
verification_failed: 驗證碼錯誤
ask:
name: 發問人
created_at: 發問時間
status: 狀態
ask: 發問
all_articles: 全部
exports: 匯出
reply: 問題回覆
reply_success: 回覆成功
to:
yes:
no:
widget:
index: 表單
save_success: 儲存成功
teacher: 教師
stuff: 職員
student: 學生
schoolfellow: 校友
others: 其他
acknowledgements: 感謝詞
admins: 管理者
new_question: 新的發問
pending: 待處理
mongoid:
attributes:
ask_question:
ask_category_id: 諮詢類別
recaptcha: 驗證碼
name: 姓名
identity: 身份
mail: Email
phone: 聯絡電話
fax: 傳真
title: 主旨
reply: 回覆
created_at: 日期
content: 內容
comment: 備註
status: 狀態
send_email: 是否回信

19
config/routes.rb Normal file
View File

@ -0,0 +1,19 @@
Rails.application.routes.draw do
locales = Site.first.in_use_locales rescue I18n.available_locales
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
namespace :admin do #backend
resources :asks do
collection do
get 'export'
post 'export', to: 'asks#do_export'
end
end
resources :ask_acknowledgements
resources :ask_admins
end
resources :asks #fronted
end
end

4
lib/ask.rb Normal file
View File

@ -0,0 +1,4 @@
require "ask/engine"
module Ask
end

66
lib/ask/engine.rb Normal file
View File

@ -0,0 +1,66 @@
module Ask
class Engine < ::Rails::Engine
initializer "ask" do
OrbitApp.registration "Ask", :type => "ModuleApp" do
module_label "ask.ask"
base_url File.expand_path File.dirname(__FILE__)
# widget_methods ["widget","widget1"]
# widget_settings [{"data_count"=>10}]
#taggable "AskQuestion"
categorizable
authorizable
frontend_enabled
# data_count 1..10
side_bar do
head_label_i18n 'ask.ask', icon_class: "icon-lightbulb"
available_for "users"
active_for_controllers (['admin/asks'])
head_link_path "admin_asks_path"
context_link 'ask.all_articles',
:link_path=>"admin_asks_path" ,
:priority=>1,
:active_for_action=>{'admin/asks'=>'index'},
:available_for => 'users'
context_link 'categories',
:link_path=>"admin_module_app_categories_path" ,
:link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'ask').id}",
:priority=>2,
:active_for_action=>{'admin/asks'=>'categories'},
:active_for_category => 'Ask',
:available_for => 'managers'
context_link 'ask.acknowledgements',
:link_path=>"admin_ask_acknowledgements_path" ,
:priority=>3,
:active_for_action=>{'admin/asks'=>'acknowledgements'},
:available_for => 'managers'
context_link 'ask.admins',
:link_path=>"admin_ask_admins_path" ,
:priority=>4,
:active_for_action=>{'admin/asks'=>'admins'},
:available_for => 'managers'
context_link 'ask.exports',
:link_path=>"export_admin_asks_path" ,
:priority=>5,
:active_for_action=>{'admin/asks'=>'exports'},
:available_for => 'managers'
# context_link 'new_',
# :link_path=>"new_admin_ask_path" ,
# :priority=>2,
# :active_for_action=>{'admin/asks'=>'new'},
# :available_for => 'sub_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/asks'=>'tags'},
# :active_for_tag => 'Ask',
# :available_for => 'managers'
end
end
end
end
end

3
lib/ask/version.rb Normal file
View File

@ -0,0 +1,3 @@
module Ask
VERSION = "0.0.1"
end

4
lib/tasks/ask_tasks.rake Normal file
View File

@ -0,0 +1,4 @@
# desc "Explaining what the task does"
# task :ask do
# # Task goes here
# end