Adjust for module authorized feature.(sub_managers)
This commit is contained in:
parent
ec1ff2051a
commit
ee94cdec5a
|
@ -1,6 +1,7 @@
|
|||
# encoding: utf-8
|
||||
class Admin::AsksController < OrbitAdminController
|
||||
helper Admin::AsksHelper
|
||||
include Admin::AsksHelper
|
||||
before_action ->(module_app = @app_title) { set_variables module_app }
|
||||
before_action :set_askquestion, only: [:edit, :destroy, :update, :print]
|
||||
layout :compute_layout
|
||||
|
@ -16,13 +17,26 @@ class Admin::AsksController < OrbitAdminController
|
|||
@app_title = "ask"
|
||||
end
|
||||
def print_setting
|
||||
@set = AskPrintSetting.first
|
||||
@set = nil
|
||||
@cats_relations = get_categories_info
|
||||
@category_id = (params[:category] || @cats_relations[0][0] rescue nil)
|
||||
if @category_id.blank?
|
||||
@set = AskPrintSetting.first
|
||||
else
|
||||
@set = AskCategoryPrintSetting.where(:category_id=>@category_id).first
|
||||
@set = AskPrintSetting.first if @set.nil?
|
||||
end
|
||||
@set = AskPrintSetting.create if @set.nil?
|
||||
@url = print_setting_save_admin_asks_path
|
||||
end
|
||||
def print_setting_save
|
||||
locale = I18n.locale
|
||||
set = AskPrintSetting.first
|
||||
if params[:ask_print_setting][:category_id].present?
|
||||
set = AskCategoryPrintSetting.where(:category_id=>params[:ask_print_setting][:category_id]).first
|
||||
set = AskCategoryPrintSetting.create(:category_id=>params[:ask_print_setting][:category_id]) if set.nil?
|
||||
else
|
||||
set = AskPrintSetting.first
|
||||
end
|
||||
set.update_attributes(print_format: params[:ask_print_setting][:print_format],save_name: params[:ask_print_setting][:save_name])
|
||||
redirect_to "/#{locale}/admin/asks"
|
||||
end
|
||||
|
@ -89,7 +103,7 @@ class Admin::AsksController < OrbitAdminController
|
|||
@ask_setting = AskSetting.first
|
||||
@ask_setting = AskSetting.create() if @ask_setting.nil?
|
||||
@tags = @module_app.tags
|
||||
@categories = @module_app.categories
|
||||
@categories = @module_app.categories.enabled.sort_by{|category| (((module_app.asc rescue true) ? category.sort_number.to_i : -category.sort_number.to_i) rescue category.id)}
|
||||
@filter_fields = filter_fields(@categories, @tags)
|
||||
# 列表欄位
|
||||
@table_fields = [:situation, :category, 'title' , 'ask.name', 'ask.phone', 'ask.appointment','ask.created_at']
|
||||
|
@ -125,9 +139,9 @@ class Admin::AsksController < OrbitAdminController
|
|||
end
|
||||
def category_setting
|
||||
@default_ask_setting = AskSetting.first
|
||||
@categories = @module_app.categories
|
||||
@category_ids = @categories.pluck(:id)
|
||||
@category_titles = @categories.pluck(:title).collect{|v| v[I18n.locale]}
|
||||
@categories = current_user.approved_categories_for_module(@module_app).sort_by{|category| (((module_app.asc rescue true) ? category.sort_number.to_i : -category.sort_number.to_i) rescue category.id)}
|
||||
@category_ids = @categories.collect(&:id)
|
||||
@category_titles = @categories.collect{|v| v.title}
|
||||
|
||||
@category_added = AskCategorySetting.all.asc(:created_at)
|
||||
@category_added_ids = @category_added.pluck(:category_id)
|
||||
|
@ -386,7 +400,9 @@ class Admin::AsksController < OrbitAdminController
|
|||
@ask_question = AskQuestion.find(params[:id])
|
||||
end
|
||||
def order_fields
|
||||
@disp_fields_infos = AskSetting.get_disp_fields_infos(params[:category])
|
||||
@cats_relations = get_categories_info
|
||||
@category_id = (params[:category] || @cats_relations[0][0] rescue nil)
|
||||
@disp_fields_infos = AskSetting.get_disp_fields_infos(@category_id)
|
||||
end
|
||||
def update_order_fields
|
||||
if params[:category]
|
||||
|
|
|
@ -13,8 +13,12 @@ class AsksController < ApplicationController
|
|||
read_more_page = Page.where(id: subpart.read_more_page_id).first || Page.where(:module => 'ask').first
|
||||
referer_url = read_more_page ? "/#{I18n.locale}#{read_more_page.url}" : "/#{I18n.locale}/asks"
|
||||
module_app = ModuleApp.where(:key => "ask").first
|
||||
categories = Array(Category.find(OrbitHelper.widget_categories)) rescue ['all']
|
||||
categories = module_app.categories if categories.include? 'all'
|
||||
if OrbitHelper.widget_categories.include?('all')
|
||||
categories = module_app.categories.enabled
|
||||
else
|
||||
categories = Category.where(:id.in=>OrbitHelper.widget_categories).enabled
|
||||
end
|
||||
categories = categories.sort_by{|category| (((module_app.asc rescue true) ? category.sort_number.to_i : -category.sort_number.to_i) rescue category.id)}
|
||||
tags = module_app.tags
|
||||
ask_question = AskQuestion.new
|
||||
locale = I18n.locale
|
||||
|
@ -114,12 +118,12 @@ class AsksController < ApplicationController
|
|||
end
|
||||
if @layout_type == 'index'
|
||||
module_app = ModuleApp.where(:key => "ask").first
|
||||
categories = Array(Category.find(OrbitHelper.page_categories)) rescue ['all']
|
||||
if categories.include? 'all'
|
||||
if OrbitHelper.page_categories.include? 'all'
|
||||
categories = module_app.categories.enabled
|
||||
else
|
||||
categories = categories & module_app.categories.enabled
|
||||
categories = Category.where(:id.in=>OrbitHelper.page_categories).enabled
|
||||
end
|
||||
categories = categories.sort_by{|category| (((module_app.asc rescue true) ? category.sort_number.to_i : -category.sort_number.to_i) rescue category.id)} if !(categories.include?("all"))
|
||||
ask_settings = AskCategorySetting.where(:category_id.in=> categories.collect{|v| v.id.to_s}).to_a
|
||||
if ask_settings.count != categories.count
|
||||
ask_settings = [AskSetting.first]+ask_settings
|
||||
|
|
|
@ -10,6 +10,20 @@ module Admin::AsksHelper
|
|||
extend ActionView::Helpers::UrlHelper
|
||||
extend OrbitFormHelper
|
||||
extend Ckeditor::Helpers::FormHelper
|
||||
def get_categories_info
|
||||
current_user = OrbitHelper.current_user
|
||||
OrbitHelper.set_params(params,current_user)
|
||||
OrbitHelper.set_this_module_app("ask")
|
||||
cats_relations = []
|
||||
access_level = OrbitHelper.user_access_level?
|
||||
if access_level == "sub_manager"
|
||||
cats_relations = current_user.approved_categories_for_module(@module_app).map{|c| [c.id.to_s, c.title]}
|
||||
else
|
||||
cats = @module_app.categories.enabled
|
||||
cats_relations = [["",t(:all)]] + cats.map{|c| [c.id.to_s, c.title]}
|
||||
end
|
||||
cats_relations
|
||||
end
|
||||
def set_input_name(input_name)
|
||||
@input_name = input_name
|
||||
end
|
||||
|
|
|
@ -13,14 +13,10 @@
|
|||
</style>
|
||||
<div>
|
||||
<form>
|
||||
<%
|
||||
cats = @module_app.categories.enabled
|
||||
cats_relations = [["",t(:all)]] + cats.map{|c| [c.id.to_s, c.title]}
|
||||
%>
|
||||
<h4><%= t(:category) %></h4>
|
||||
<select name="category" id="submit_when_change">
|
||||
<% cats_relations.each do |id, title| %>
|
||||
<option value="<%=id%>" <%= params[:category] == id ? 'selected' : '' %>><%= title %></option>
|
||||
<% @cats_relations.each do |id, title| %>
|
||||
<option value="<%=id%>" <%= @category_id == id ? 'selected' : '' %>><%= title %></option>
|
||||
<% end %>
|
||||
</select>
|
||||
</form>
|
||||
|
@ -133,7 +129,7 @@
|
|||
})
|
||||
$.ajax({
|
||||
url : "/admin/asks/update_order_fields",
|
||||
data : {"sort_number" : sort_number,"category": "<%=params[:category]%>"},
|
||||
data : {"sort_number" : sort_number,"category": "<%=@category_id%>"},
|
||||
dataType : "json",
|
||||
type : "post"
|
||||
}).done(function(){
|
||||
|
|
|
@ -1,4 +1,15 @@
|
|||
<%= form_for @set,method: 'post',url: @url,html: { class: 'form-horizontal main-forms previewable' } do |f| %>
|
||||
<div>
|
||||
<form>
|
||||
<h4><%= t(:category) %></h4>
|
||||
<select name="category" id="submit_when_change">
|
||||
<% @cats_relations.each do |id, title| %>
|
||||
<option value="<%=id%>" <%= @category_id == id ? 'selected' : '' %>><%= title %></option>
|
||||
<% end %>
|
||||
</select>
|
||||
</form>
|
||||
</div>
|
||||
<%= form_for @set, as: :ask_print_setting ,method: 'post',url: @url,html: { class: 'form-horizontal main-forms previewable' } do |f| %>
|
||||
<%= hidden_field_tag "#{f.object_name}[category_id]", @category_id %>
|
||||
<fieldset>
|
||||
<table>
|
||||
<thead>
|
||||
|
@ -33,4 +44,11 @@
|
|||
</table>
|
||||
</fieldset>
|
||||
<% end %>
|
||||
<%= render partial: 'print_format_explain' %>
|
||||
<%= render partial: 'print_format_explain' %>
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
$("#submit_when_change").on("change",function(){
|
||||
$(this)[0].form.submit();
|
||||
})
|
||||
})
|
||||
</script>
|
|
@ -109,7 +109,7 @@ module Ask
|
|||
:link_path=>"order_fields_admin_asks_path" ,
|
||||
:priority=>7,
|
||||
:active_for_action=>{'admin/asks'=>'order_fields'},
|
||||
:available_for => 'managers'
|
||||
:available_for => 'sub_managers'
|
||||
context_link 'ask.setting',
|
||||
:link_path=>"setting_admin_asks_path" ,
|
||||
:priority=>7,
|
||||
|
@ -119,12 +119,12 @@ module Ask
|
|||
:link_path=>"category_setting_admin_asks_path" ,
|
||||
:priority=>7,
|
||||
:active_for_action=>{'admin/asks'=>'category_setting'},
|
||||
:available_for => 'managers'
|
||||
:available_for => 'sub_managers'
|
||||
context_link 'ask.print_setting',
|
||||
:link_path=>"print_setting_admin_asks_path" ,
|
||||
:priority=>8,
|
||||
:active_for_action=>{'admin/asks'=>'print_setting'},
|
||||
:available_for => 'managers'
|
||||
:available_for => 'sub_managers'
|
||||
# context_link 'new_',
|
||||
# :link_path=>"new_admin_ask_path" ,
|
||||
# :priority=>2,
|
||||
|
|
Loading…
Reference in New Issue