Add order fields for cateogies setting.
This commit is contained in:
parent
ffff41153c
commit
ec1ff2051a
|
@ -386,10 +386,22 @@ class Admin::AsksController < OrbitAdminController
|
|||
@ask_question = AskQuestion.find(params[:id])
|
||||
end
|
||||
def order_fields
|
||||
@disp_fields_infos = AskSetting.get_disp_fields_infos
|
||||
@disp_fields_infos = AskSetting.get_disp_fields_infos(params[:category])
|
||||
end
|
||||
def update_order_fields
|
||||
AskSetting.update_all(:sort_number=>params[:sort_number])
|
||||
if params[:category]
|
||||
ask_setting = AskCategorySetting.where(:category_id=>params[:category]).first
|
||||
if ask_setting.nil?
|
||||
default_setting = AskSetting.first
|
||||
default_setting = AskSetting.create if default_setting.nil?
|
||||
ask_setting = AskCategorySetting.create(category_id: params[:category])
|
||||
p1 = default_setting.get_attrs
|
||||
ask_setting.update_attributes(p1)
|
||||
end
|
||||
ask_setting.update(:sort_number=>params[:sort_number])
|
||||
else
|
||||
AskSetting.update_all(:sort_number=>params[:sort_number])
|
||||
end
|
||||
render :json => {:success=>true}
|
||||
end
|
||||
private
|
||||
|
|
|
@ -115,7 +115,11 @@ class AsksController < ApplicationController
|
|||
if @layout_type == 'index'
|
||||
module_app = ModuleApp.where(:key => "ask").first
|
||||
categories = Array(Category.find(OrbitHelper.page_categories)) rescue ['all']
|
||||
categories = module_app.categories if categories.include? 'all'
|
||||
if categories.include? 'all'
|
||||
categories = module_app.categories.enabled
|
||||
else
|
||||
categories = categories & module_app.categories.enabled
|
||||
end
|
||||
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
|
||||
|
@ -251,7 +255,7 @@ class AsksController < ApplicationController
|
|||
end
|
||||
private
|
||||
def cal_form_from_setting(ask_setting,categories,show_categories=false,filter_fields=nil)
|
||||
disp_fields_infos = AskSetting.get_disp_fields_infos
|
||||
disp_fields_infos = AskSetting.get_disp_fields_infos(ask_setting.class == AskCategorySetting ? ask_setting.category_id : nil)
|
||||
if filter_fields
|
||||
disp_fields_infos = disp_fields_infos.select{|field, info| filter_fields.include?(field)}
|
||||
end
|
||||
|
@ -261,12 +265,10 @@ class AsksController < ApplicationController
|
|||
tmp_ask_cat_id = (tmp_type == 1) ? ask_setting.id.to_s : ""
|
||||
disp_fields_infos.each do |field, info|
|
||||
if field.include?("default@")
|
||||
if tmp_type == 0
|
||||
k = field[8..-1]
|
||||
v = ask_setting.custom_fields[k]
|
||||
if v
|
||||
defalt_fields << {'label'=>ask_label(v['field'][I18n.locale],v['required']),'content'=>show_on_front(k,v)}
|
||||
end
|
||||
k = field[8..-1]
|
||||
v = ask_setting.custom_fields[k]
|
||||
if v
|
||||
defalt_fields << {'label'=>ask_label(v['field'][I18n.locale],v['required']),'content'=>show_on_front(k,v)}
|
||||
end
|
||||
elsif field.include?("custom@") && tmp_ask_cat_id != ""
|
||||
if tmp_type == 1 && field.include?(tmp_ask_cat_id)
|
||||
|
|
|
@ -41,9 +41,22 @@ class AskSetting
|
|||
|
||||
field :custom_fields, type: Hash,default: {}
|
||||
field :usage_rule
|
||||
|
||||
def self.get_disp_fields_infos
|
||||
ask_setting = self.first
|
||||
def get_attrs
|
||||
attrs = self.attributes.clone
|
||||
self.fields.each do |k, v|
|
||||
if (v.options[:localize] rescue false)
|
||||
attrs["#{k}_translations"] = attrs[k]
|
||||
attrs.delete(k)
|
||||
end
|
||||
end
|
||||
attrs.except("_type","_id","uid","updated_at", "created_at")
|
||||
end
|
||||
def self.get_disp_fields_infos(cat=nil)
|
||||
ask_setting = nil
|
||||
if cat.present?
|
||||
ask_setting = AskCategorySetting.where(:category_id=>cat).first
|
||||
end
|
||||
ask_setting = self.first if ask_setting.nil?
|
||||
ask_setting = self.create() if ask_setting.nil?
|
||||
disp_fields = self::All_default_fields
|
||||
disp_fields_infos = {}
|
||||
|
@ -62,7 +75,13 @@ class AskSetting
|
|||
tmp_k = "default@#{k}"
|
||||
disp_fields_infos[tmp_k] = {"trans"=>trans,"sort_number"=>ask_setting.sort_number[tmp_k]}
|
||||
end
|
||||
AskCategorySetting.all.each do |c|
|
||||
ask_category_settings = []
|
||||
if ask_setting.class == AskCategorySetting || cat.present?
|
||||
ask_category_settings = []
|
||||
else
|
||||
ask_category_settings = AskCategorySetting.all.to_a
|
||||
end
|
||||
ask_category_settings.each do |c|
|
||||
cat = Category.find(c.category_id)
|
||||
c.custom_fields.each do |k,v|
|
||||
trans = v["field"]
|
||||
|
|
|
@ -11,6 +11,20 @@
|
|||
background: aqua;
|
||||
}
|
||||
</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>
|
||||
<% end %>
|
||||
</select>
|
||||
</form>
|
||||
</div>
|
||||
<div class="order-edit-notification"><%= t("ask.please_save") %></div>
|
||||
<table width="100%" id="ask_fields_order_table" class="table table-striped" class="ask_fields_table">
|
||||
<thead>
|
||||
|
@ -119,7 +133,7 @@
|
|||
})
|
||||
$.ajax({
|
||||
url : "/admin/asks/update_order_fields",
|
||||
data : {"sort_number" : sort_number},
|
||||
data : {"sort_number" : sort_number,"category": "<%=params[:category]%>"},
|
||||
dataType : "json",
|
||||
type : "post"
|
||||
}).done(function(){
|
||||
|
@ -135,6 +149,9 @@
|
|||
<script>
|
||||
var th_width = {};
|
||||
$(document).ready(function(){
|
||||
$("#submit_when_change").on("change",function(){
|
||||
$(this)[0].form.submit();
|
||||
})
|
||||
$( ".table tbody" ).each(function(i,tbody){
|
||||
var table = $(tbody).parents("table").eq(0);
|
||||
table.data("index",i);
|
||||
|
|
Loading…
Reference in New Issue