From 6b0a6a1fc8a04dc709b1addb3d83ad31d3c07df1 Mon Sep 17 00:00:00 2001 From: JiangRu Date: Thu, 2 Oct 2014 14:00:35 +0800 Subject: [PATCH] ask module --- .gitignore | 8 + Gemfile | 14 ++ MIT-LICENSE | 20 ++ README.rdoc | 3 + Rakefile | 32 +++ app/assets/javascripts/admin/ask.js | 2 + app/assets/javascripts/ask/.keep | 0 app/assets/stylesheets/admin/ask.css | 7 + app/assets/stylesheets/ask/.keep | 0 app/assets/stylesheets/ask/ask.css | 53 +++++ .../admin/ask_acknowledgements_controller.rb | 19 ++ .../admin/ask_admins_controller.rb | 45 +++++ app/controllers/admin/asks_controller.rb | 170 ++++++++++++++++ app/controllers/asks_controller.rb | 73 +++++++ app/helpers/admin/asks_helper.rb | 27 +++ app/mailers/.keep | 0 app/models/.keep | 0 app/models/ask_acknowledgement.rb | 6 + app/models/ask_admin.rb | 6 + app/models/ask_question.rb | 34 ++++ .../admin/ask_acknowledgements/index.html.erb | 14 ++ app/views/admin/ask_admins/edit.html.erb | 46 +++++ app/views/admin/ask_admins/index.html.erb | 62 ++++++ app/views/admin/asks/_filter.html.erb | 186 ++++++++++++++++++ app/views/admin/asks/_form.html.erb | 59 ++++++ app/views/admin/asks/_index.html.erb | 44 +++++ app/views/admin/asks/edit.html.erb | 5 + app/views/admin/asks/email.html.erb | 13 ++ app/views/admin/asks/export.html.erb | 21 ++ app/views/admin/asks/index.html.erb | 6 + app/views/asks/email.html.erb | 36 ++++ app/views/asks/index.html.erb | 126 ++++++++++++ app/views/asks/sorry.html.erb | 8 + app/views/asks/thank.html.erb | 7 + ask.gemspec | 21 ++ bin/rails | 4 + config/locales/en.yml | 24 +++ config/locales/zh_tw.yml | 48 +++++ config/routes.rb | 19 ++ lib/ask.rb | 4 + lib/ask/engine.rb | 66 +++++++ lib/ask/version.rb | 3 + lib/tasks/ask_tasks.rake | 4 + 43 files changed, 1345 insertions(+) create mode 100644 .gitignore create mode 100644 Gemfile create mode 100644 MIT-LICENSE create mode 100644 README.rdoc create mode 100644 Rakefile create mode 100644 app/assets/javascripts/admin/ask.js create mode 100644 app/assets/javascripts/ask/.keep create mode 100644 app/assets/stylesheets/admin/ask.css create mode 100644 app/assets/stylesheets/ask/.keep create mode 100644 app/assets/stylesheets/ask/ask.css create mode 100644 app/controllers/admin/ask_acknowledgements_controller.rb create mode 100644 app/controllers/admin/ask_admins_controller.rb create mode 100644 app/controllers/admin/asks_controller.rb create mode 100644 app/controllers/asks_controller.rb create mode 100644 app/helpers/admin/asks_helper.rb create mode 100644 app/mailers/.keep create mode 100644 app/models/.keep create mode 100644 app/models/ask_acknowledgement.rb create mode 100644 app/models/ask_admin.rb create mode 100644 app/models/ask_question.rb create mode 100644 app/views/admin/ask_acknowledgements/index.html.erb create mode 100644 app/views/admin/ask_admins/edit.html.erb create mode 100644 app/views/admin/ask_admins/index.html.erb create mode 100644 app/views/admin/asks/_filter.html.erb create mode 100644 app/views/admin/asks/_form.html.erb create mode 100644 app/views/admin/asks/_index.html.erb create mode 100644 app/views/admin/asks/edit.html.erb create mode 100644 app/views/admin/asks/email.html.erb create mode 100644 app/views/admin/asks/export.html.erb create mode 100644 app/views/admin/asks/index.html.erb create mode 100644 app/views/asks/email.html.erb create mode 100644 app/views/asks/index.html.erb create mode 100644 app/views/asks/sorry.html.erb create mode 100644 app/views/asks/thank.html.erb create mode 100644 ask.gemspec create mode 100755 bin/rails create mode 100644 config/locales/en.yml create mode 100644 config/locales/zh_tw.yml create mode 100644 config/routes.rb create mode 100644 lib/ask.rb create mode 100644 lib/ask/engine.rb create mode 100644 lib/ask/version.rb create mode 100644 lib/tasks/ask_tasks.rake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..de5d954 --- /dev/null +++ b/.gitignore @@ -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 diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..2517763 --- /dev/null +++ b/Gemfile @@ -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' diff --git a/MIT-LICENSE b/MIT-LICENSE new file mode 100644 index 0000000..ea966ec --- /dev/null +++ b/MIT-LICENSE @@ -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. diff --git a/README.rdoc b/README.rdoc new file mode 100644 index 0000000..9ca9e14 --- /dev/null +++ b/README.rdoc @@ -0,0 +1,3 @@ += Ask + +This project rocks and uses MIT-LICENSE. \ No newline at end of file diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..9bcfe45 --- /dev/null +++ b/Rakefile @@ -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 diff --git a/app/assets/javascripts/admin/ask.js b/app/assets/javascripts/admin/ask.js new file mode 100644 index 0000000..dee720f --- /dev/null +++ b/app/assets/javascripts/admin/ask.js @@ -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. diff --git a/app/assets/javascripts/ask/.keep b/app/assets/javascripts/ask/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/assets/stylesheets/admin/ask.css b/app/assets/stylesheets/admin/ask.css new file mode 100644 index 0000000..2c22c38 --- /dev/null +++ b/app/assets/stylesheets/admin/ask.css @@ -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; +} \ No newline at end of file diff --git a/app/assets/stylesheets/ask/.keep b/app/assets/stylesheets/ask/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/assets/stylesheets/ask/ask.css b/app/assets/stylesheets/ask/ask.css new file mode 100644 index 0000000..a5203bb --- /dev/null +++ b/app/assets/stylesheets/ask/ask.css @@ -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; +} \ No newline at end of file diff --git a/app/controllers/admin/ask_acknowledgements_controller.rb b/app/controllers/admin/ask_acknowledgements_controller.rb new file mode 100644 index 0000000..76bcad9 --- /dev/null +++ b/app/controllers/admin/ask_acknowledgements_controller.rb @@ -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 \ No newline at end of file diff --git a/app/controllers/admin/ask_admins_controller.rb b/app/controllers/admin/ask_admins_controller.rb new file mode 100644 index 0000000..ce6432e --- /dev/null +++ b/app/controllers/admin/ask_admins_controller.rb @@ -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 diff --git a/app/controllers/admin/asks_controller.rb b/app/controllers/admin/asks_controller.rb new file mode 100644 index 0000000..7ccf9cf --- /dev/null +++ b/app/controllers/admin/asks_controller.rb @@ -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 diff --git a/app/controllers/asks_controller.rb b/app/controllers/asks_controller.rb new file mode 100644 index 0000000..839d4e2 --- /dev/null +++ b/app/controllers/asks_controller.rb @@ -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 \ No newline at end of file diff --git a/app/helpers/admin/asks_helper.rb b/app/helpers/admin/asks_helper.rb new file mode 100644 index 0000000..9390c41 --- /dev/null +++ b/app/helpers/admin/asks_helper.rb @@ -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 diff --git a/app/mailers/.keep b/app/mailers/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/models/.keep b/app/models/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/models/ask_acknowledgement.rb b/app/models/ask_acknowledgement.rb new file mode 100644 index 0000000..454f408 --- /dev/null +++ b/app/models/ask_acknowledgement.rb @@ -0,0 +1,6 @@ +class AskAcknowledgement + include Mongoid::Document + include Mongoid::Timestamps + + field :content, type: String +end \ No newline at end of file diff --git a/app/models/ask_admin.rb b/app/models/ask_admin.rb new file mode 100644 index 0000000..eda70d6 --- /dev/null +++ b/app/models/ask_admin.rb @@ -0,0 +1,6 @@ +class AskAdmin + include Mongoid::Document + include Mongoid::Timestamps + + field :email, type: String +end \ No newline at end of file diff --git a/app/models/ask_question.rb b/app/models/ask_question.rb new file mode 100644 index 0000000..12c5827 --- /dev/null +++ b/app/models/ask_question.rb @@ -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 diff --git a/app/views/admin/ask_acknowledgements/index.html.erb b/app/views/admin/ask_acknowledgements/index.html.erb new file mode 100644 index 0000000..e3aff30 --- /dev/null +++ b/app/views/admin/ask_acknowledgements/index.html.erb @@ -0,0 +1,14 @@ +
+ <%= form_for @ask_acknowledgements, url: @url, html: { class: 'form-horizontal' } do |f| %> +
+ <%= f.label :content, t('ask.acknowledgements'), class: 'control-label' %> +
+ <%= f.text_area :content, rows: 10 %> +
+
+
+ <%= f.submit t('submit'), class: 'btn btn-primary' %> + <%= f.button t('cancel'), type: 'reset', class: 'btn' %> +
+ <% end %> +
\ No newline at end of file diff --git a/app/views/admin/ask_admins/edit.html.erb b/app/views/admin/ask_admins/edit.html.erb new file mode 100644 index 0000000..f5ac3c8 --- /dev/null +++ b/app/views/admin/ask_admins/edit.html.erb @@ -0,0 +1,46 @@ +<%= render 'layouts/delete_modal', delete_options: @delete_options %> + + + + <% @table_fields.each do |f| %> + <%= thead(f) %> + <% end %> + + + + <% @ask_admins.each do |a| %> + + + + <% end %> + +
+ <%= a.email %> +
+ +
+
+ +<%= form_for @ask_admin, url: @url, html: { class: 'form-horizontal' } do |f| %> + +

<%= @ask_admin.new_record? ? t(:add) : t(:edit) %>

+ +
+
+ <%= f.label :email, class: 'control-label' %> +
+ <%= f.text_field :email, class: 'input-xxlarge' %> +
+
+
+
+ <%= f.submit t(:submit), class: 'btn btn-primary' %> +
+ +<% end %> + diff --git a/app/views/admin/ask_admins/index.html.erb b/app/views/admin/ask_admins/index.html.erb new file mode 100644 index 0000000..5763d69 --- /dev/null +++ b/app/views/admin/ask_admins/index.html.erb @@ -0,0 +1,62 @@ +<%= render 'layouts/delete_modal', delete_options: @delete_options %> + + + + <% @table_fields.each do |f| %> + <%= thead(f) %> + <% end %> + + + + <% @ask_admins.each do |a| %> + + + + <% end %> + +
+ <%= a.email %> +
+ +
+
+ +<%= javascript_include_tag 'validator' %> +<%= form_for @ask_admin, url: admin_ask_admins_path, html: {class: "form-horizontal main-forms previewable"} do |f| %> + +

<%= @ask_admin.new_record? ? t(:add) : t(:edit) %>

+ +
+
+ <%= f.label :email, class: 'control-label' %> +
+ <%= f.text_field :email, class: 'input-xxlarge', data: {"fv-validation" => "required;check_email;", "fv-messages" => "必填欄位;Email不正確;"} %> +
+
+
+ +
+ <%= f.submit t(:submit), class: 'btn btn-primary' %> +
+ +<% end %> + + + diff --git a/app/views/admin/asks/_filter.html.erb b/app/views/admin/asks/_filter.html.erb new file mode 100644 index 0000000..808eb5a --- /dev/null +++ b/app/views/admin/asks/_filter.html.erb @@ -0,0 +1,186 @@ +<% content_for :right_nav do %> + <% if !search_dom_id.nil?%> +
+
+ +
+ +
+ <% end %> + + +
+ <% fields.keys.each do |field| %> +
+
+ <% 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 %> +
+ +
+ <% end %> +
+<% end %> + diff --git a/app/views/admin/asks/_form.html.erb b/app/views/admin/asks/_form.html.erb new file mode 100644 index 0000000..d7eb83e --- /dev/null +++ b/app/views/admin/asks/_form.html.erb @@ -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 %> + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
<%= AskQuestion.human_attribute_name(:name) %>:<%= @ask_question.name %><%= AskQuestion.human_attribute_name(:identity) %>:<%= @ask_question[:identity] %><%= AskQuestion.human_attribute_name(:mail) %>:<%= @ask_question.mail %><%= AskQuestion.human_attribute_name(:phone) %>:<%= @ask_question.phone %><%= AskQuestion.human_attribute_name(:fax) %>:<%= @ask_question.fax %>
<%= AskQuestion.human_attribute_name(:title) %>:<%= @ask_question.title %>
<%= AskQuestion.human_attribute_name(:content) %>:
<%= @ask_question.content %>
+ <%= f.label :reply %> +
<%= f.text_area :reply, rows: 10, style: 'width: 500px' %> +
+ <%= f.label :comment %> +
<%= f.text_field :comment, style: 'width: 500px' %>
<%= f.label :status %> <%= f.select :status, [ + ['待處理', 'is_hot'], + ['已處理', 'is_top'], + ['轉介其他單位', 'is_hidden'] + ] %>
+ <%= f.label :send_email %><%= f.radio_button :send_email, 1, checked: @ask_question.send_email? %><%= t('ask.yes') %> +      + <%= f.radio_button :send_email, 0, checked: !@ask_question.send_email? %><%= t('ask.no') %> +
+
+
+ +
+ <%= f.submit t('submit'), class: 'btn btn-primary' %> + <%= f.button t('cancel'), type: 'reset', class: 'btn' %> +
diff --git a/app/views/admin/asks/_index.html.erb b/app/views/admin/asks/_index.html.erb new file mode 100644 index 0000000..a22b03e --- /dev/null +++ b/app/views/admin/asks/_index.html.erb @@ -0,0 +1,44 @@ + + + + <% @table_fields.each do |f| %> + <%= thead(f) %> + <% end %> + + + + <% @askquestions.each do |b| %> + + + + + + + + <% end %> + +
+ <% if b.status == 'is_hot' %> + <%= t('待處理') %> + <% elsif b.status == 'is_top' %> + <%= t('已處理') %> + <% elsif b.status == 'is_hidden' %> + <%= t('轉介其他單位') %> + <% end %> + <%= b.category.title %> + <%= b.title %> +
+ +
+
<%= b.name %><%= format_value b.created_at %>
+ +<%= + content_tag :div, class: "bottomnav clearfix" do + content_tag :div, paginate(@askquestions), class: "pagination pagination-centered" + end +%> \ No newline at end of file diff --git a/app/views/admin/asks/edit.html.erb b/app/views/admin/asks/edit.html.erb new file mode 100644 index 0000000..3675252 --- /dev/null +++ b/app/views/admin/asks/edit.html.erb @@ -0,0 +1,5 @@ +<%= form_for @ask_question, url: @url, html: { class: 'form-horizontal main-forms previewable' } do |f| %> +
+ <%= render :partial => 'form', locals: {f: f} %> +
+<% end %> \ No newline at end of file diff --git a/app/views/admin/asks/email.html.erb b/app/views/admin/asks/email.html.erb new file mode 100644 index 0000000..f16b23e --- /dev/null +++ b/app/views/admin/asks/email.html.erb @@ -0,0 +1,13 @@ + + + + + + +

+ <%= @data['reply'] %> +

+
+

此為系統自動發信,請勿直接回覆

+ + \ No newline at end of file diff --git a/app/views/admin/asks/export.html.erb b/app/views/admin/asks/export.html.erb new file mode 100644 index 0000000..34a4782 --- /dev/null +++ b/app/views/admin/asks/export.html.erb @@ -0,0 +1,21 @@ +
+ <%= form_tag export_admin_asks_path, method: 'post' do |f| %> + + + + + + + + + + + + +
<%= t('date_') %><%= date_select 'export', :start %> <%= t('ask.to') %>
<%= date_select 'export', :end %>
+
+ <%= submit_tag t('submit'), class: 'btn btn-primary' %> +
+
+ <% end %> +
\ No newline at end of file diff --git a/app/views/admin/asks/index.html.erb b/app/views/admin/asks/index.html.erb new file mode 100644 index 0000000..1ad9a26 --- /dev/null +++ b/app/views/admin/asks/index.html.erb @@ -0,0 +1,6 @@ +<%= render_filter @filter_fields, "index_table" %> + + <%= render 'index'%> + + +<%= render 'layouts/delete_modal', delete_options: @delete_options %> \ No newline at end of file diff --git a/app/views/asks/email.html.erb b/app/views/asks/email.html.erb new file mode 100644 index 0000000..63bfb07 --- /dev/null +++ b/app/views/asks/email.html.erb @@ -0,0 +1,36 @@ + + + + + + +

<%= @data['title'] %>

+ + + + + + + + + + + + + + + + + + + + + + + + + +
<%= AskQuestion.human_attribute_name(:name) %>:<%= @data['name'] %>
<%= AskQuestion.human_attribute_name(:identity) %>:<%= @data['identity'] %>
<%= AskQuestion.human_attribute_name(:mail) %>:<%= @data['mail'] %>
<%= AskQuestion.human_attribute_name(:phone) %>:<%= @data['phone'] %>
<%= AskQuestion.human_attribute_name(:fax) %>:<%= @data['fax'] %>
<%= AskQuestion.human_attribute_name(:content) %>:<%= @data['content'] %>
+

此為系統自動發信,請勿直接回覆

+ + \ No newline at end of file diff --git a/app/views/asks/index.html.erb b/app/views/asks/index.html.erb new file mode 100644 index 0000000..6e7a8f3 --- /dev/null +++ b/app/views/asks/index.html.erb @@ -0,0 +1,126 @@ +<% data = action_data + @ask_question = data["ask_question"] + @categories = data["categories"] + @module_app = data["module_app"] +%> + +<%= javascript_include_tag 'validator' %> + +
+ <%= form_for @ask_question, url: asks_path, html: {class: 'form-horizontal'} do |f| %> + +
+ <%= f.label :ask_category_id, class: 'control-label required' %> +
+ <%= f.select :category_id, @categories.collect{|t| [ t.title, t.id ]} %> +
+
+ +
+ <%= f.label :name, class: 'control-label required' %> +
+ <%= f.text_field :name, data: {"fv-validation" => "required;", "fv-messages" => "必填欄位;"} %> +
+
+ +
+ <%= f.label :identity, class: 'control-label required' %> +
+ <%= 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]} ) %> +
+
+ +
+ <%= f.label :mail, class: 'control-label required' %> +
+ <%= f.text_field :mail, data: {"fv-validation" => "required;check_email;", "fv-messages" => "必填欄位;Email不正確;"} %> +
+
+ +
+ <%= f.label :phone, class: 'control-label' %> +
+ <%= f.text_field :phone %> +
+
+ +
+ <%= f.label :fax, class: 'control-label' %> +
+ <%= f.text_field :fax %> +
+
+ +
+ <%= f.label :title, class: 'control-label required' %> +
+ <%= f.text_field :title, data: {"fv-validation" => "required;", "fv-messages" => "必填欄位;"} %> +
+
+ +
+ <%= f.label :content, class: 'control-label required' %> +
+ <%= f.text_area :content, rows: 8, class: 'input-xlarge' %> +
+
+ +
+ <%= f.label :recaptcha, class: 'control-label' %> +
+ <%= gotcha_error %> + <%= gotcha %> +
+
+ +
+ "> + <%= f.submit t('submit'), class: 'btn btn-primary', :id => 'button-mail' %> + <%= f.button t('cancel'), type: 'reset', class: 'btn' %> +
+ <% end %> +
+ + \ No newline at end of file diff --git a/app/views/asks/sorry.html.erb b/app/views/asks/sorry.html.erb new file mode 100644 index 0000000..a7f2009 --- /dev/null +++ b/app/views/asks/sorry.html.erb @@ -0,0 +1,8 @@ + +
+

發問失敗,請重新發問!

+

Failed to ask questions, please re-ask!

+
+ +
+
\ No newline at end of file diff --git a/app/views/asks/thank.html.erb b/app/views/asks/thank.html.erb new file mode 100644 index 0000000..0ffe327 --- /dev/null +++ b/app/views/asks/thank.html.erb @@ -0,0 +1,7 @@ +<% data = action_data + @acknowledgement = data["acknowledgement"] +%> + +
+ <%= @acknowledgement[:content].gsub(/[(\n)(\r)]/, "\n" => "
", "\r" => "" ).html_safe %> +
diff --git a/ask.gemspec b/ask.gemspec new file mode 100644 index 0000000..75f6722 --- /dev/null +++ b/ask.gemspec @@ -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 diff --git a/bin/rails b/bin/rails new file mode 100755 index 0000000..728cd85 --- /dev/null +++ b/bin/rails @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +APP_PATH = File.expand_path('../../config/application', __FILE__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/config/locales/en.yml b/config/locales/en.yml new file mode 100644 index 0000000..cdd0b56 --- /dev/null +++ b/config/locales/en.yml @@ -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 \ No newline at end of file diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml new file mode 100644 index 0000000..bee83b6 --- /dev/null +++ b/config/locales/zh_tw.yml @@ -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: 是否回信 \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb new file mode 100644 index 0000000..ab02daa --- /dev/null +++ b/config/routes.rb @@ -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 + diff --git a/lib/ask.rb b/lib/ask.rb new file mode 100644 index 0000000..785ecd5 --- /dev/null +++ b/lib/ask.rb @@ -0,0 +1,4 @@ +require "ask/engine" + +module Ask +end diff --git a/lib/ask/engine.rb b/lib/ask/engine.rb new file mode 100644 index 0000000..9d5c7bb --- /dev/null +++ b/lib/ask/engine.rb @@ -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 \ No newline at end of file diff --git a/lib/ask/version.rb b/lib/ask/version.rb new file mode 100644 index 0000000..a87c4ad --- /dev/null +++ b/lib/ask/version.rb @@ -0,0 +1,3 @@ +module Ask + VERSION = "0.0.1" +end diff --git a/lib/tasks/ask_tasks.rake b/lib/tasks/ask_tasks.rake new file mode 100644 index 0000000..441822c --- /dev/null +++ b/lib/tasks/ask_tasks.rake @@ -0,0 +1,4 @@ +# desc "Explaining what the task does" +# task :ask do +# # Task goes here +# end