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(){
|
||||
var this_value = $(this).val(),
|
||||
categories_list = $("#categories_list");
|
||||
categories_list = $("#categories_list")
|
||||
layouts_list = $("#layouts_list");
|
||||
|
||||
categories_list.html("");
|
||||
if(this_value){
|
||||
|
@ -114,18 +115,33 @@ var Items = function(){
|
|||
data : {"module" : this_value},
|
||||
type : "get",
|
||||
dataType : "json"
|
||||
}).done(function(categories){
|
||||
}).done(function(data){
|
||||
var controlDiv = $("<div class='controls'></div>");
|
||||
if(categories.categories.length){
|
||||
categories_list.parent().find("label.control-label").prepend("Category List :");
|
||||
if(data.categories.length){
|
||||
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>");
|
||||
controlDiv.append(checkbox);
|
||||
$.each(data.categories,function(i,category){
|
||||
var checkbox = $("<label class='checkbox'><input type='checkbox' value='"+ category.id +"' name='page[categories][]' /> " + category.title + " </label>");
|
||||
controlDiv.append(checkbox);
|
||||
})
|
||||
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();
|
||||
}
|
||||
$.each(categories.categories,function(i,category){
|
||||
var checkbox = $("<label class='checkbox'><input type='checkbox' value='"+ category.id +"' name='page[categories][]' /> " + category.title + " </label>");
|
||||
controlDiv.append(checkbox);
|
||||
})
|
||||
categories_list.append(controlDiv);
|
||||
})
|
||||
}
|
||||
})
|
||||
|
|
|
@ -35,6 +35,7 @@ class PagesController < ApplicationController
|
|||
end
|
||||
|
||||
def show
|
||||
display_type = ""
|
||||
path = request.path.split('/')
|
||||
if path.size <= 2
|
||||
redirect_to root_path
|
||||
|
@ -46,11 +47,13 @@ class PagesController < ApplicationController
|
|||
uid = uid.split("?").first
|
||||
params[:uid] = uid
|
||||
params[:target_action] = params[:method] || "show"
|
||||
display_type = "show"
|
||||
else
|
||||
params[:page_id] = path[-1]
|
||||
params[:slug] = nil
|
||||
params[:uid] = nil
|
||||
params[:target_action] = params[:method] || "index"
|
||||
display_type = "index"
|
||||
OrbitHelper.set_page_number params[:page_no].to_i || 1
|
||||
end
|
||||
page = Page.find_by_param(params[:page_id])
|
||||
|
@ -58,6 +61,9 @@ class PagesController < ApplicationController
|
|||
if page.enabled_for.include? I18n.locale.to_s
|
||||
module_app = page.module.downcase.pluralize
|
||||
params[:target_controller] = "#{module_app}"
|
||||
if display_type == "index"
|
||||
params[:layout_type] = params[:method] || page.layout || "index"
|
||||
end
|
||||
params[:url] = page.url
|
||||
|
||||
@manifest = @key
|
||||
|
@ -131,8 +137,7 @@ class PagesController < ApplicationController
|
|||
"id" => cat.id.to_s
|
||||
}
|
||||
end
|
||||
|
||||
render :json => {"categories" => @categories}.to_json
|
||||
render :json => {"categories" => @categories,"layouts" => (get_layouts module_app.key)}.to_json
|
||||
end
|
||||
|
||||
def new
|
||||
|
@ -148,6 +153,7 @@ class PagesController < ApplicationController
|
|||
@modules = ModuleApp.all.frontend_enabled
|
||||
module_app = ModuleApp.find_by_key(@page.module) rescue nil
|
||||
@categories = module_app.categories rescue []
|
||||
@layout_types = get_layouts module_app.key
|
||||
end
|
||||
|
||||
def update
|
||||
|
@ -171,6 +177,19 @@ class PagesController < ApplicationController
|
|||
|
||||
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)
|
||||
if layout
|
||||
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.url = page.url == "/" ? "" : page.url
|
||||
@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
|
||||
end
|
||||
|
||||
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["menu_enabled_for"] = p["menu_enabled_for"] || []
|
||||
p
|
||||
|
|
|
@ -159,7 +159,11 @@ module ApplicationHelper
|
|||
|
||||
|
||||
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")
|
||||
file.close
|
||||
controller = "#{params[:target_controller].capitalize}_controller".classify.constantize.new
|
||||
|
|
|
@ -47,6 +47,9 @@ module PagesHelper
|
|||
end
|
||||
controller_name = controller_name.downcase.singularize
|
||||
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)
|
||||
doc = Nokogiri::HTML(s, nil, "UTF-8")
|
||||
wrap_elements = doc.css("*[data-repeat]")
|
||||
|
|
|
@ -8,6 +8,7 @@ class Page
|
|||
field :module
|
||||
field :url
|
||||
field :page_id
|
||||
field :layout, type: String, default: "index"
|
||||
field :data_count, type: Integer, default: 10
|
||||
field :enabled_for, type: Array, default: []
|
||||
field :menu_enabled_for, type: Array, default: []
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<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">
|
||||
<% if params[:action] == "edit" %>
|
||||
<div class="controls">
|
||||
|
@ -45,6 +45,16 @@
|
|||
<% end %>
|
||||
</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">
|
||||
<label class="control-label">Data Count :</label>
|
||||
<div class="controls">
|
||||
|
|
Loading…
Reference in New Issue