forked from saurabh/orbit4-5
now can select different layouts for different modules
This commit is contained in:
parent
218e7f16df
commit
bc7e2f9514
|
@ -105,7 +105,8 @@ var Items = function(){
|
||||||
|
|
||||||
sidePanel.on("change","select.module_select", function(){
|
sidePanel.on("change","select.module_select", function(){
|
||||||
var this_value = $(this).val(),
|
var this_value = $(this).val(),
|
||||||
categories_list = $("#categories_list");
|
categories_list = $("#categories_list")
|
||||||
|
layouts_list = $("#layouts_list");
|
||||||
|
|
||||||
categories_list.html("");
|
categories_list.html("");
|
||||||
if(this_value){
|
if(this_value){
|
||||||
|
@ -114,18 +115,33 @@ var Items = function(){
|
||||||
data : {"module" : this_value},
|
data : {"module" : this_value},
|
||||||
type : "get",
|
type : "get",
|
||||||
dataType : "json"
|
dataType : "json"
|
||||||
}).done(function(categories){
|
}).done(function(data){
|
||||||
var controlDiv = $("<div class='controls'></div>");
|
var controlDiv = $("<div class='controls'></div>");
|
||||||
if(categories.categories.length){
|
if(data.categories.length){
|
||||||
categories_list.parent().find("label.control-label").prepend("Category List :");
|
categories_list.parent().find("label.control-label").text("Category List :");
|
||||||
var checkbox = $("<label class='checkbox'><input type='checkbox' value='all' name='page[categories][]' class='checkbox-all' /> All </label>");
|
var checkbox = $("<label class='checkbox'><input type='checkbox' value='all' name='page[categories][]' class='checkbox-all' /> All </label>");
|
||||||
controlDiv.append(checkbox);
|
controlDiv.append(checkbox);
|
||||||
}
|
$.each(data.categories,function(i,category){
|
||||||
$.each(categories.categories,function(i,category){
|
|
||||||
var checkbox = $("<label class='checkbox'><input type='checkbox' value='"+ category.id +"' name='page[categories][]' /> " + category.title + " </label>");
|
var checkbox = $("<label class='checkbox'><input type='checkbox' value='"+ category.id +"' name='page[categories][]' /> " + category.title + " </label>");
|
||||||
controlDiv.append(checkbox);
|
controlDiv.append(checkbox);
|
||||||
})
|
})
|
||||||
categories_list.append(controlDiv);
|
categories_list.html(controlDiv);
|
||||||
|
}else{
|
||||||
|
categories_list.parent().find("label.control-label").text("");
|
||||||
|
}
|
||||||
|
if(data.layouts.length){
|
||||||
|
layouts_list.parent().find("label.control-label").text("Layout type:");
|
||||||
|
var controlDiv = $("<div class='controls'></div>"),
|
||||||
|
select = $("<select name='page[layout]'></select>");
|
||||||
|
$.each(data.layouts,function(i,layout){
|
||||||
|
select.append("<option value='" + layout + "'>" + layout + "</option>");
|
||||||
|
})
|
||||||
|
controlDiv.html(select);
|
||||||
|
layouts_list.html(controlDiv);
|
||||||
|
}else{
|
||||||
|
layouts_list.parent().find("label.control-label").text("");
|
||||||
|
layouts_list.empty();
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -35,6 +35,7 @@ class PagesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
display_type = ""
|
||||||
path = request.path.split('/')
|
path = request.path.split('/')
|
||||||
if path.size <= 2
|
if path.size <= 2
|
||||||
redirect_to root_path
|
redirect_to root_path
|
||||||
|
@ -46,11 +47,13 @@ class PagesController < ApplicationController
|
||||||
uid = uid.split("?").first
|
uid = uid.split("?").first
|
||||||
params[:uid] = uid
|
params[:uid] = uid
|
||||||
params[:target_action] = params[:method] || "show"
|
params[:target_action] = params[:method] || "show"
|
||||||
|
display_type = "show"
|
||||||
else
|
else
|
||||||
params[:page_id] = path[-1]
|
params[:page_id] = path[-1]
|
||||||
params[:slug] = nil
|
params[:slug] = nil
|
||||||
params[:uid] = nil
|
params[:uid] = nil
|
||||||
params[:target_action] = params[:method] || "index"
|
params[:target_action] = params[:method] || "index"
|
||||||
|
display_type = "index"
|
||||||
OrbitHelper.set_page_number params[:page_no].to_i || 1
|
OrbitHelper.set_page_number params[:page_no].to_i || 1
|
||||||
end
|
end
|
||||||
page = Page.find_by_param(params[:page_id])
|
page = Page.find_by_param(params[:page_id])
|
||||||
|
@ -58,6 +61,9 @@ class PagesController < ApplicationController
|
||||||
if page.enabled_for.include? I18n.locale.to_s
|
if page.enabled_for.include? I18n.locale.to_s
|
||||||
module_app = page.module.downcase.pluralize
|
module_app = page.module.downcase.pluralize
|
||||||
params[:target_controller] = "#{module_app}"
|
params[:target_controller] = "#{module_app}"
|
||||||
|
if display_type == "index"
|
||||||
|
params[:layout_type] = params[:method] || page.layout || "index"
|
||||||
|
end
|
||||||
params[:url] = page.url
|
params[:url] = page.url
|
||||||
|
|
||||||
@manifest = @key
|
@manifest = @key
|
||||||
|
@ -131,8 +137,7 @@ class PagesController < ApplicationController
|
||||||
"id" => cat.id.to_s
|
"id" => cat.id.to_s
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
render :json => {"categories" => @categories,"layouts" => (get_layouts module_app.key)}.to_json
|
||||||
render :json => {"categories" => @categories}.to_json
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
|
@ -148,6 +153,7 @@ class PagesController < ApplicationController
|
||||||
@modules = ModuleApp.all.frontend_enabled
|
@modules = ModuleApp.all.frontend_enabled
|
||||||
module_app = ModuleApp.find_by_key(@page.module) rescue nil
|
module_app = ModuleApp.find_by_key(@page.module) rescue nil
|
||||||
@categories = module_app.categories rescue []
|
@categories = module_app.categories rescue []
|
||||||
|
@layout_types = get_layouts module_app.key
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
|
@ -171,6 +177,19 @@ class PagesController < ApplicationController
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def get_layouts(module_app)
|
||||||
|
layout_types = []
|
||||||
|
Dir.glob("#{Rails.root}/app/templates/#{@key}/modules/#{module_app}/*").each do |w|
|
||||||
|
next if File.ftype(w).eql?("directory")
|
||||||
|
w = File.basename(w, ".*")
|
||||||
|
w = File.basename(w, ".*")
|
||||||
|
if w[0,1] != "_" && w[0,1] != "s"
|
||||||
|
layout_types << w
|
||||||
|
end
|
||||||
|
end
|
||||||
|
layout_types
|
||||||
|
end
|
||||||
|
|
||||||
def render_final_page(original_view=get_view,page,layout)
|
def render_final_page(original_view=get_view,page,layout)
|
||||||
if layout
|
if layout
|
||||||
parts = $mobile.blank? ? (page.page_parts rescue []) : (page.mobile_page_parts rescue [])
|
parts = $mobile.blank? ? (page.page_parts rescue []) : (page.mobile_page_parts rescue [])
|
||||||
|
@ -251,13 +270,13 @@ class PagesController < ApplicationController
|
||||||
page = Page.find(params[:page][:parent_page])
|
page = Page.find(params[:page][:parent_page])
|
||||||
page.url = page.url == "/" ? "" : page.url
|
page.url = page.url == "/" ? "" : page.url
|
||||||
@url = page.url + "/#{params[:page][:page_id]}"
|
@url = page.url + "/#{params[:page][:page_id]}"
|
||||||
p = params.require(:page).permit(:number, :page_id, :module, :parent_page, :data_count, enabled_for_sitemap: [], enabled_for: [], menu_enabled_for: [], categories: [], name_translations: [:en, :zh_tw])
|
p = params.require(:page).permit(:number, :page_id, :module, :layout, :parent_page, :data_count, enabled_for_sitemap: [], enabled_for: [], menu_enabled_for: [], categories: [], name_translations: [:en, :zh_tw])
|
||||||
p["url"] = @url
|
p["url"] = @url
|
||||||
p
|
p
|
||||||
end
|
end
|
||||||
|
|
||||||
def page_update_params
|
def page_update_params
|
||||||
p = params.require(:page).permit(:number, :page_id, :module, :parent_page, :data_count, enabled_for_sitemap: [], enabled_for: [],menu_enabled_for: [], categories: [], name_translations: [:en, :zh_tw])
|
p = params.require(:page).permit(:number, :page_id, :module, :layout, :parent_page, :data_count, enabled_for_sitemap: [], enabled_for: [],menu_enabled_for: [], categories: [], name_translations: [:en, :zh_tw])
|
||||||
p["enabled_for"] = p["enabled_for"] || []
|
p["enabled_for"] = p["enabled_for"] || []
|
||||||
p["menu_enabled_for"] = p["menu_enabled_for"] || []
|
p["menu_enabled_for"] = p["menu_enabled_for"] || []
|
||||||
p
|
p
|
||||||
|
|
|
@ -159,7 +159,11 @@ module ApplicationHelper
|
||||||
|
|
||||||
|
|
||||||
if params[:target_action] == "index"
|
if params[:target_action] == "index"
|
||||||
file = File.open(File.join(Rails.root, 'app', 'templates', "#{@key}", 'modules', params[:target_controller].singularize, "#{params[:target_action]}.html.erb"))
|
f = File.join(Rails.root, 'app', 'templates', "#{@key}", 'modules', params[:target_controller].singularize, "#{params[:layout_type]}.html.erb")
|
||||||
|
if !File.exists?f
|
||||||
|
f = File.join(Rails.root, 'app', 'templates', "#{@key}", 'modules', params[:target_controller].singularize, "index.html.erb")
|
||||||
|
end
|
||||||
|
file = File.open(f)
|
||||||
doc = Nokogiri::HTML(file, nil, "UTF-8")
|
doc = Nokogiri::HTML(file, nil, "UTF-8")
|
||||||
file.close
|
file.close
|
||||||
controller = "#{params[:target_controller].capitalize}_controller".classify.constantize.new
|
controller = "#{params[:target_controller].capitalize}_controller".classify.constantize.new
|
||||||
|
|
|
@ -47,6 +47,9 @@ module PagesHelper
|
||||||
end
|
end
|
||||||
controller_name = controller_name.downcase.singularize
|
controller_name = controller_name.downcase.singularize
|
||||||
f = File.join('../templates', "#{@key}", 'modules', "#{controller_name}", "_#{widget_file}.html.erb");
|
f = File.join('../templates', "#{@key}", 'modules', "#{controller_name}", "_#{widget_file}.html.erb");
|
||||||
|
if !File.exists?f
|
||||||
|
f = File.join('../templates', "#{@key}", 'modules', "#{controller_name}", "_widget.html.erb");
|
||||||
|
end
|
||||||
s = render_to_string(f)
|
s = render_to_string(f)
|
||||||
doc = Nokogiri::HTML(s, nil, "UTF-8")
|
doc = Nokogiri::HTML(s, nil, "UTF-8")
|
||||||
wrap_elements = doc.css("*[data-repeat]")
|
wrap_elements = doc.css("*[data-repeat]")
|
||||||
|
|
|
@ -8,6 +8,7 @@ class Page
|
||||||
field :module
|
field :module
|
||||||
field :url
|
field :url
|
||||||
field :page_id
|
field :page_id
|
||||||
|
field :layout, type: String, default: "index"
|
||||||
field :data_count, type: Integer, default: 10
|
field :data_count, type: Integer, default: 10
|
||||||
field :enabled_for, type: Array, default: []
|
field :enabled_for, type: Array, default: []
|
||||||
field :menu_enabled_for, type: Array, default: []
|
field :menu_enabled_for, type: Array, default: []
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label class="control-label"><%= "Category List :" if params[:action] == "edit" %></label>
|
<label class="control-label"><%= "Category List :" if params[:action] == "edit" && !@categories.blank? %></label>
|
||||||
<div id="categories_list">
|
<div id="categories_list">
|
||||||
<% if params[:action] == "edit" %>
|
<% if params[:action] == "edit" %>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
|
@ -45,6 +45,16 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="control-group">
|
||||||
|
<label class="control-label"><%= "Layout type :" if params[:action] == "edit" && !@layout_types.blank? %></label>
|
||||||
|
<div id="layouts_list">
|
||||||
|
<% if params[:action] == "edit" && !@layout_types.blank? %>
|
||||||
|
<div class="controls">
|
||||||
|
<%= f.select(:layout, @layout_types) %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label class="control-label">Data Count :</label>
|
<label class="control-label">Data Count :</label>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
|
|
Loading…
Reference in New Issue