Orbit Ask Module

This commit is contained in:
Manson Wang 2014-01-15 18:56:54 +08:00
parent 7b1eb374f4
commit 893734b8d1
56 changed files with 1154 additions and 0 deletions

7
.gitignore vendored Normal file
View File

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

17
Gemfile Normal file
View File

@ -0,0 +1,17 @@
source "http://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
# jquery-rails is used by the dummy application
gem "jquery-rails"
# 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 2013 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.

38
Rakefile Normal file
View File

@ -0,0 +1,38 @@
#!/usr/bin/env rake
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
begin
require 'rdoc/task'
rescue LoadError
require 'rdoc/rdoc'
require 'rake/rdoctask'
RDoc::Task = Rake::RDocTask
end
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,23 @@
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :set_locale
# Set I18n.locale
def set_locale
# update session if passed
session[:locale] = params[:locale] if params[:locale]
# set locale based on session or default
begin
# check if locale is valid for non site pages
if !VALID_LOCALES.include?(session[:locale])
I18n.locale = I18n.default_locale
else
I18n.locale = session[:locale]
end
rescue
I18n.locale = I18n.default_locale
end
end
end

View File

@ -0,0 +1,23 @@
class Panel::Ask::BackEnd::AskAcknowledgementsController < OrbitBackendController
include AdminHelper
include OrbitControllerLib::DivisionForDisable
before_filter :for_app_manager
def initialize
super
@app_title = 'ask_acknowledgement'
end
def index
@ask_acknowledgement = AskAcknowledgement.first || AskAcknowledgement.create
@url = panel_ask_back_end_ask_acknowledgement_path(@ask_acknowledgement)
end
def update
@ask_acknowledgement = AskAcknowledgement.first
@ask_acknowledgement.update_attributes(params[:ask_acknowledgement])
redirect_to panel_ask_back_end_ask_acknowledgements_path, notice: t('ask.save_success')
end
end

View File

@ -0,0 +1,56 @@
class Panel::Ask::BackEnd::AskAdminsController < OrbitBackendController
include AdminHelper
include OrbitControllerLib::DivisionForDisable
before_filter :for_app_manager
def initialize
super
@app_title = 'ask_admins'
end
def index
@ask_admins = AskAdmin.all
@ask_admin = AskAdmin.new
@url = panel_ask_back_end_ask_admins_path
end
def create
@ask_admin = AskAdmin.new(params[:ask_admin])
@ask_admin.save
respond_to do |format|
format.js
end
end
def edit
@ask_admin = AskAdmin.find(params[:id])
@url = panel_ask_back_end_ask_admin_path(@ask_admin)
respond_to do |format|
format.js
end
end
def update
@ask_admin = AskAdmin.find(params[:id])
@url = panel_ask_back_end_ask_admin_path(@ask_admin)
@ask_admin.update_attributes(params[:ask_admin])
respond_to do |format|
format.js
end
end
def destroy
@ask_admin = AskAdmin.find(params[:id])
@ask_admin.destroy
respond_to do |format|
format.js
end
end
end

View File

@ -0,0 +1,57 @@
class Panel::Ask::BackEnd::AskCategoriesController < OrbitBackendController
include AdminHelper
include OrbitControllerLib::DivisionForDisable
before_filter :for_app_manager
def initialize
super
@app_title = 'ask_categories'
end
def index
@ask_categories = AskCategory.admin_manager_all
@ask_category = AskCategory.new
@url = panel_ask_back_end_ask_categories_path
end
def create
@ask_category = AskCategory.new(params[:ask_category])
@ask_category.save!
respond_to do |format|
format.js
end
end
def edit
@ask_category = AskCategory.find(params[:id])
@url = panel_ask_back_end_ask_category_path(@ask_category)
respond_to do |format|
format.js
end
end
def update
@ask_category = AskCategory.find(params[:id])
@url = panel_ask_back_end_ask_category_path(@ask_category)
@ask_category.update_attributes(params[:ask_category])
respond_to do |format|
format.js
end
end
def destroy
@ask_category = AskCategory.find(params[:id])
@ask_category.disable = !@ask_category.disable
@ask_category.save!
respond_to do |format|
format.js
end
end
end

View File

@ -0,0 +1,85 @@
require 'csv'
class Panel::Ask::BackEnd::AskQuestionsController < OrbitBackendController
def initialize
super
@app_title = 'ask_questions'
end
def index
@ask_questions = AskQuestion.all
respond_to do |format|
format.html
format.js
end
end
def edit
@ask_question = AskQuestion.find(params[:id])
@ask_reply = @ask_question.ask_reply
if @ask_reply
@url = panel_ask_back_end_ask_question_ask_reply_path(@ask_question, @ask_question.ask_reply)
@method = 'put'
else
@ask_reply = AskReply.new
@url = panel_ask_back_end_ask_question_ask_replies_path(@ask_question)
@method = 'post'
end
end
def destroy
@ask_question = AskQuestion.find(params[:id])
@ask_question.destroy
respond_to do |format|
format.js
end
end
def delete
if params[:ids]
ask_questions = AskQuestion.any_in(:_id => params[:ids]).destroy_all
end
redirect_to panel_ask_back_end_ask_questions_url(:direction => params[:direction], :sort => params[:sort], :sort_options => params[:sort_options])
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.includes(:ask_category).includes(:ask_reply).where(:created_at.gte => date_start, :created_at.lte => date_end)
csv = CSV.generate do |csv|
csv << [ t('category'),
AskQuestion.human_attribute_name(:name),
AskQuestion.human_attribute_name(:identity),
AskQuestion.human_attribute_name(:email),
AskQuestion.human_attribute_name(:phone),
AskQuestion.human_attribute_name(:tax),
AskQuestion.human_attribute_name(:title),
AskQuestion.human_attribute_name(:content),
AskReply.human_attribute_name(:content),
AskReply.human_attribute_name(:comment)]
@ask_questions.each do |ask_question|
ask_question.ask_reply ||= AskReply.new
csv << [ ask_question.ask_category.name,
ask_question.name,
ask_question.identity,
ask_question.email,
ask_question.phone,
ask_question.tax,
ask_question.title,
ask_question.content,
ask_question.ask_reply.content,
ask_question.ask_reply.comment ]
end
end
send_data csv.encode('Big5'), type: 'text/csv', filename: "Questions-#{date_start}-#{date_end}.csv"
end
end

View File

@ -0,0 +1,31 @@
class Panel::Ask::BackEnd::AskRepliesController < OrbitBackendController
include AdminHelper
include OrbitControllerLib::DivisionForDisable
before_filter :for_app_manager
def initialize
super
@app_title = 'ask_replies'
end
def create
@ask_question = AskQuestion.find(params[:ask_question_id])
@ask_question.ask_reply = AskReply.new(params[:ask_reply])
@ask_question.save
if @ask_question.ask_reply.send_email?
Resque.enqueue(SendAskReplyMail, @ask_reply.ask_question.id)
end
redirect_to panel_ask_back_end_ask_questions_path, notice: t('ask.reply_success')
end
def update
@ask_reply = AskReply.find(params[:id])
@ask_reply.update_attributes(params[:ask_reply])
if @ask_reply.send_email?
Resque.enqueue(SendAskReplyMail, @ask_reply.ask_question.id)
end
redirect_to panel_ask_back_end_ask_questions_path, notice: t('ask.reply_success')
end
end

View File

@ -0,0 +1,52 @@
class Panel::Ask::FrontEnd::AskQuestionsController < OrbitWidgetController
layout false
def initialize
super
@app_title = 'ask'
end
def index
@ask_question = AskQuestion.new
@categories = @module_app.categories.enabled
end
def create
@ask_question = AskQuestion.new(params[:ask_question])
if gotcha_valid? && @ask_question.save
@acknowledgement = AskAcknowledgement.last
@ask_acknowledgement = AskAcknowledgement.first || AskAcknowlegement.new
AskAdmin.all.each do |ask_admin|
AskMailer.notice(ask_admin, @ask_question).deliver
Resque.enqueue(SendAskNoticeMail, ask_admin.id, @ask_question.id)
end
# Render to create.js.erb
respond_to do |format|
format.js
end
else
# Render to index.js.erb
respond_to do |format|
format.js { render :index }
end
end
end
def thank_you
@acknowledgement = AskAcknowledgement.last
@item = Page.find(params[:page_id]) rescue nil
if @item
if @item.frontend_data_count
@page_num = @item.frontend_data_count
else
@page_num = 15
end
@frontend_style = @item.frontend_style
end
@item = Page.find(params[:page_id]) rescue nil
end
end

14
app/mailers/ask_mailer.rb Normal file
View File

@ -0,0 +1,14 @@
class AskMailer < ActionMailer::Base
default from: 'orbit_test@rulingcom.com'
def reply(ask_question)
@ask_question = ask_question
mail(:to => @ask_question.email, :subject => "#{t('ask.reply')}:#{@ask_question.title}")
end
def notice(ask_admin, ask_question)
@ask_admin = ask_admin
@ask_question = ask_question
mail(:to => @ask_admin.email, :subject => "#{t('ask.new_question')}:#{@ask_question.title}")
end
end

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,10 @@
class AskCategory
include Mongoid::Document
include Mongoid::Timestamps
include OrbitCoreLib::ObjectDisable
field :name, localize: true
field :key
has_many :ask_questions
end

View File

@ -0,0 +1,24 @@
class AskQuestion
include Mongoid::Document
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
include OrbitCategory::Categorizable
include OrbitModel::Approval
include Mongoid::Document
include Mongoid::Timestamps
field :name, type: String
field :identity, type: String
field :email, type: String
field :phone, type: String
field :tax, type: String
field :title, type: String
field :content, type: String
validates_presence_of :name, :identity, :email, :title, :content
has_one :ask_reply, dependent: :destroy
end

11
app/models/ask_reply.rb Normal file
View File

@ -0,0 +1,11 @@
class AskReply
include Mongoid::Document
include Mongoid::Timestamps
field :content, type: String
field :comment, type: String
field :status, type: String
field :send_email, type: Boolean, detault: false
belongs_to :ask_question
end

View File

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

View File

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

View File

@ -0,0 +1,14 @@
<div id="ask-acknowledgement">
<%= form_for @ask_acknowledgement, url: @url, html: { class: 'form-horizontal' } do |f| %>
<div class="control-group">
<%= f.label :content, t('ask.acknowledgement'), 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,13 @@
<tr id="<%= dom_id ask_admin %>" class="with_action">
<td>
<%= ask_admin.email %>
<%if at_least_module_manager %>
<div class="quick-edit">
<ul class="nav nav-pills hide">
<li><%= link_to t(:edit), edit_panel_ask_back_end_ask_admin_path(ask_admin), :remote => true %></li>
<li><%= link_to t(:delete), panel_ask_back_end_ask_admin_path(ask_admin), :confirm => t(:sure?), :method => :delete, :remote => true ,:class=> "archive_toggle"%></li>
</ul>
</div>
<% end -%>
</td>
</tr>

View File

@ -0,0 +1,19 @@
<%= form_for(@ask_admin, :remote => true, :url => @url) 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,2 @@
$('<%= j render :partial => 'ask_admin', :collection => [@ask_admin] %>').appendTo('#ask-admins').hide().fadeIn();
$("#new_ask_admin")[0].reset();

View File

@ -0,0 +1 @@
$("#<%= dom_id @ask_admin %>").fadeOut();

View File

@ -0,0 +1 @@
$("#form > form").replaceWith("<%= j render "form" %>");

View File

@ -0,0 +1,23 @@
<%= flash_messages %>
<div id="filter" class="subnav">
<div class="filters">
<div id="sort_headers" class="table-label">
<table class="table main-list">
<thead>
<tr>
<th class="span1-2"><%= t(:email) %></th>
</tr>
</thead>
</table>
</div>
</div>
</div>
<table id="ask-admins" class="table main-list">
<tbody class="sort-holder">
<%= render :partial => 'ask_admin', :collection => @ask_admins %>
</tbody>
</table>
<div id="form"><%= render :partial => "form" if at_least_module_manager%></div>

View File

@ -0,0 +1,4 @@
$("#<%= dom_id @ask_admin %>").replaceWith("<%= j render :partial => 'ask_admin', :collection => [@ask_admin] %>");
<% @ask_admin = AskAdmin.new(:display => 'List') # reset for new form %>
$(".edit_ask_admin").replaceWith("<%= j render "form" %>")
$(".new_ask_admin")[0].reset();

View File

@ -0,0 +1,17 @@
<tr id="<%= dom_id ask_category %>" class="with_action">
<td>
<%= ask_category.key %>
<%if at_least_module_manager %>
<div class="quick-edit">
<ul class="nav nav-pills hide">
<li><%= link_to t(:edit), edit_panel_ask_back_end_ask_category_path(ask_category), :remote => true %></li>
<li><%= link_to show_toggle_archive_btn(ask_category), panel_ask_back_end_ask_category_path(ask_category), :confirm => t(:sure?), :method => :delete, :remote => true ,:class=> "archive_toggle"%></li>
<li><%#= show_ask_permission_link ask_category %></li>
</ul>
</div>
<% end -%>
</td>
<% @site_in_use_locales.each do |locale| %>
<td><%= ask_category.name_translations[locale] rescue nil %></td>
<% end %>
</tr>

View File

@ -0,0 +1,28 @@
<%= form_for(@ask_category, :remote => true, :url => @url) do |f| %>
<h2><%= (@ask_category.new_record? ? t(:add) : t(:edit)) %></h2>
<div id="widget-title">
<%= f.label :key, t(:key) %>
<%= f.text_field :key %>
</div>
<div id="widget-title">
<%= f.fields_for :name_translations do |f| %>
<% @site_in_use_locales.each do |locale| %>
<div class="control-group">
<%= label_tag "name-#{locale}", "#{t(:name)}-#{I18nVariable.from_locale(locale)}", :class => 'control-label' %>
<div class="controls">
<%= f.text_field locale, :class => 'input-xxlarge', :value => (@ask_category.name_translations[locale] rescue nil) %>
</div>
</div>
<% end %>
<% end %>
</div>
<div class="form-actions">
<%= f.submit t(:submit), :class=>'btn btn-primary' %>
</div>
<% end %>

View File

@ -0,0 +1,2 @@
$('<%= j render :partial => 'ask_category', :collection => [@ask_category] %>').appendTo('#ask_categories').hide().fadeIn();
$("#new_ask_category")[0].reset();

View File

@ -0,0 +1 @@
$("#<%= dom_id @ask_category %>").find(".archive_toggle").text("<%= show_toggle_archive_btn(@ask_category) %> ");

View File

@ -0,0 +1 @@
$("#form > form").replaceWith("<%= j render "form" %>");

View File

@ -0,0 +1,34 @@
<%= flash_messages %>
<div id="filter" class="subnav">
<div class="filters">
<div id="sort_headers" class="table-label">
<table class="table main-list">
<thead>
<tr>
<th class="span1-2"><%= t(:key) %></th>
<% %w[服務 Service].each do |name| %>
<th class="span1-2"><%= name %></th>
<% end %>
</tr>
</thead>
</table>
</div>
</div>
</div>
<table id="ask_categories" class="table main-list">
<thead>
<tr>
<th class="span1-2"></th>
<% @site_in_use_locales.each do |locale| %>
<th class="span1-2"></th>
<% end %>
</tr>
</thead>
<tbody class="sort-holder">
<%= render :partial => 'ask_category', :collection => @ask_categories %>
</tbody>
</table>
<div id="form"><%= render :partial => "form" if at_least_module_manager%></div>

View File

@ -0,0 +1,4 @@
$("#<%= dom_id @ask_category %>").replaceWith("<%= j render :partial => 'ask_category', :collection => [@ask_category] %>");
<% @ask_category = QaCategory.new(:display => 'List') # reset for new form %>
$(".edit_ask_category").replaceWith("<%= j render "form" %>")
$(".new_ask_category")[0].reset();

View File

@ -0,0 +1,27 @@
<tr id="<%= dom_id ask_question %>" class="with_action">
<td>
<%= check_box_tag 'to_delete[]', ask_question.id, false, :class => "checkbox_in_list" %>
</td>
<td>
<%= ask_question.ask_reply ? ask_question.ask_reply.status : t('ask.pending') %>
</td>
<td>
<%= ask_question.title %>
<div class="quick-edit">
<ul class="nav nav-pills hide">
<%if at_least_module_manager || ask_question.ask_category.cur_user_is_sub_manager_of(:edit)%>
<li><%= link_to t('edit'), edit_panel_ask_back_end_ask_question_path(ask_question, :page => params[:page]) %></li>
<li><%= link_to t(:delete_), panel_ask_back_end_ask_question_path(ask_question), :confirm => t('sure?'), :method => :delete, :remote => true %></li>
<% end -%>
</ul>
</div>
</td>
<td>
<%= ask_question.name %>
</td>
<td>
<%= ask_question.created_at.strftime "%Y-%m-%d %H:%M:%S" %>
</td>
</tr>

View File

@ -0,0 +1,11 @@
<div id='filter' class="subnav">
<div class="filters accordion-group">
<div id="sort_headers" class="table-label">
<%= render 'sort_headers' %>
</div>
</div>
</div>
<% content_for :page_specific_javascript do %>
<%= javascript_include_tag 'sort_header' %>
<% end %>

View File

@ -0,0 +1 @@
$("#<%= dom_id @ask_question %>").remove();

View File

@ -0,0 +1,55 @@
<div id="ask_question_reply">
<%= form_for @ask_reply, url: @url, method: @method do |f| %>
<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(:email) %><%= @ask_question.email %></td>
<td><%= AskQuestion.human_attribute_name(:phone) %><%= @ask_question.phone %></td>
<td><%= AskQuestion.human_attribute_name(:tax) %><%= @ask_question.tax %></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 :content %>
<br/> <%= f.text_area :content, 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, [
['待處理', '待處理'],
['已處理', '已處理'],
['轉介其他單位', '轉介其他單位']
] %></td>
</tr>
<tr>
<td colspan="5">
<%= f.label :send_email %><%= f.radio_button :send_email, 1, checked: @ask_reply.send_email? %><%= t('ask.yes') %>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
<%= f.radio_button :send_email, 0, checked: !@ask_reply.send_email? %><%= t('ask.no') %>
</td>
</tr>
<tr>
<td colspan="5">
<div class="form-actions">
<%= f.submit t('submit'), class: 'btn btn-primary' %>
<%= f.button t('cancel'), type: 'reset', class: 'btn' %>
</div>
</td>
</tr>
</table>
<% end %>
</div>

View File

@ -0,0 +1,21 @@
<div id="ask-questions-export">
<%= form_tag export_panel_ask_back_end_ask_questions_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,19 @@
<table class="table main-list">
<thead>
<tr>
<th class="span1"></th>
<th class="span1"><%= t('ask.status') %></th>
<th class="span1"><%= t('ask.question') %></th>
<th class="span1"><%= t('ask.sender') %></th>
<th class="span3"><%= t('ask.created_at') %></th>
</tr>
</thead>
<tbody id="tbody_surveys" class="sort-holder">
<%= render :partial => 'ask_question', :collection => @ask_questions %>
</tbody>
</table>
<div class="form-actions form-fixed pagination-right">
<div id="ask_questions_pagination" class="paginationFixed">
</div>
</div>

View File

@ -0,0 +1,4 @@
$("#delete_all").attr("action", "<%= delete_panel_ask_back_end_ask_questions_path(:direction => params[:direction], :sort => params[:sort], :filter => @filter, :new_filter => nil, :sort_options => params[:sort_options]) %>");
$("#sort_headers").html("<%= j render 'sort_headers' %>");
$("#tbody_surveys").html("<%= j render :partial => 'ask_question', :collection => @ask_questions %>");
$("#ask_questions_pagination").html("<%= j paginate @ask_questions %>");

View File

@ -0,0 +1 @@
window.location.href= "<%= panel_ask_front_end_thank_you_path %>"

View File

@ -0,0 +1,118 @@
<!-- <link href='/assets/ask.css' rel='stylesheet' type='text/css' /> -->
<style type="text/css">
.spinner {
position: fixed;
top: 50%;
left: 50%;
margin-left: -50px; /* half width of the spinner gif */
margin-top: -50px; /* half height of the spinner gif */
text-align:center;
z-index:1234;
overflow: auto;
width: 100px; /* width of the spinner gif */
height: 102px; /*hight of the spinner gif +2px to fix IE8 issue */
}
</style>
<script type="text/javascript">
$(document).ready(function(){
$("#spinner").bind("ajaxSend", function() {
$(this).show();
}).bind("ajaxStop", function() {
$(this).hide();
}).bind("ajaxError", function() {
$(this).hide();
});
});
</script>
<div id="spinner" class="spinner" style="display:none;">
Sending Mail <%= image_tag 'loading.gif', :id => "img-spinner"%>
</div>
<div id="new-ask-question" class="ask-question">
<div id="acknowledgement"></div>
<%= form_for @ask_question, url: panel_ask_front_end_ask_questions_path(standalone: true), html: {class: 'form-horizontal'} do |f| %>
<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 %>
</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>
<div class="control-group">
<%= f.label :email, class: 'control-label required' %>
<div class="controls">
<%= f.text_field :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 :tax, class: 'control-label' %>
<div class="controls">
<%= f.text_field :tax %>
</div>
</div>
<div class="control-group">
<%= f.label :title, class: 'control-label required' %>
<div class="controls">
<%= f.text_field :title %>
</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">
<div class="controls">
<%= gotcha_error %>
<%= gotcha%>
</div>
</div>
<div class="form-actions">
<%= 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">
$(document).ready(function(){
$('#button-mail').click(function() {
$('#spinner').show();
});
});
</script>
<script type="text/javascript">
$(function() {
$('#new-ask-question .required').each(function() {
$(this).text('*' + $(this).text());
});
$('#new-ask-question form') .submit(function() {
$.post($(this).attr('action'), $(this).serializeArray());
return false;
});
});
</script>

View File

@ -0,0 +1 @@
window.location.href = "<%= panel_ask_front_end_sorry_path %>";

View File

@ -0,0 +1 @@
<h3><%= t(:ask_fail, :scope => :ask) %> !</h3>

View File

@ -0,0 +1 @@
<h3><%= @acknowledgement.content.html_safe%></h3>

22
ask.gemspec Normal file
View File

@ -0,0 +1,22 @@
$:.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 = ["service@rulingcom.com"]
s.homepage = "http://www.rulingcom.com"
s.summary = ""
s.description = "Orbit Ask module"
s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"]
s.test_files = Dir["test/**/*"]
# s.add_dependency "rails", "~> 3.2.16"
s.add_development_dependency "sqlite3"
end

12
ask.json Normal file
View File

@ -0,0 +1,12 @@
{
"title": "ask",
"version": "0.1",
"organization": "Rulingcom",
"author": "RD dep",
"intro": "ask",
"update_info": "Some info",
"create_date": "05-23-2013",
"widgets": ["index"],
"category": ["gallery_categories"],
"enable_frontend": true
}

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

@ -0,0 +1,24 @@
en:
ask:
ask: Ask
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
acknowledgement: Acknowledgement
admin: Administrator
new_question: New question
pending: Pending
mongoid:
attributes:
ask_question:
ask_category_id: Ask Category

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

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

29
config/routes.rb Normal file
View File

@ -0,0 +1,29 @@
Rails.application.routes.draw do
namespace :panel do
namespace :ask do
namespace :back_end do
resources :ask_questions do
collection do
get 'delete'
get 'export'
post 'export', to: 'ask_questions#do_export'
end
resources :ask_replies
end
resources :ask_categories
resources :ask_acknowledgements
resources :ask_admins
end
namespace :front_end do
match "ask_questions/thank_you" => "ask_questions#thank_you", :as => 'thank_you'
match "ask_questions/sorry" => "ask_questions#sorry", :as => 'sorry'
resources :ask_questions
end
end
end
end

63
lib/ask.rb Normal file
View File

@ -0,0 +1,63 @@
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__)
# personal_plugin :enable => true,:path=>"panel/faq/plugin/profile",:i18n=>'admin.faq'
version "0.1"
organization "Rulingcom"
author "RD dep"
intro "I am intro"
update_info 'some update_info'
front_end do
app_page 'ask_questions' do
frontend_i18n 'ask.ask'
end
app_page 'thank_you' do
frontend_i18n "ask.thank_you"
end
end
widgets do
default_widget do
end
categories_query 'Category.all'
end
authorizable
approvable
categorizable
side_bar do
head_label_i18n 'ask.ask', icon_class: 'icons-light-bulb'
available_for [:admin,:manager,:sub_manager]
active_for_controllers ({:private=>['ask_questions', 'ask_admins', 'ask_ackowledgements']})
active_for_controllers({ private: ['ask_questions'] })
head_link_path "panel_ask_back_end_ask_questions_path"
context_link 'announcement.categories',
:link_path=>"admin_module_app_categories_path(get_module_app)" ,
:priority=>3,
:active_for_category => 'Ask',
:available_for => [:admin]
context_link 'ask.acknowledgement', link_path: 'panel_ask_back_end_ask_acknowledgements_path',
priority: 1,
available_for: [:all]
context_link 'ask.admin', link_path: 'panel_ask_back_end_ask_admins_path',
priority: 1,
available_for: [:all]
context_link 'ask.export', link_path: 'export_panel_ask_back_end_ask_questions_path',
priority: 1,
available_for: [:all]
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