forked from saurabh/orbit4-5
update site structure for members and member frontend controller
This commit is contained in:
parent
91e6b2385c
commit
c37976c62e
|
@ -92,11 +92,18 @@ var Items = function(){
|
|||
}
|
||||
})
|
||||
|
||||
sidePanel.on("click","#status_list input[type=checkbox]",function(){
|
||||
sidePanel.on("click","#role_list input[type=checkbox]",function(){
|
||||
if($(this).is(":checked") && $(this).hasClass("checkbox-all")){
|
||||
$(".view-page .content #status_list input[type=checkbox]").not($(this)).removeAttr("checked");
|
||||
$(".view-page .content #role_list input[type=checkbox]").not($(this)).removeAttr("checked");
|
||||
}else{
|
||||
$(".view-page .content #status_list input[type=checkbox].checkbox-all").removeAttr("checked");
|
||||
$(".view-page .content #role_list input[type=checkbox].checkbox-all").removeAttr("checked");
|
||||
$("#status-list-"+$(this).val()+" input[type=checkbox]").removeAttr("checked");
|
||||
}
|
||||
})
|
||||
|
||||
sidePanel.on("click",".status-checkbox",function(){
|
||||
if($(this).is(":checked")){
|
||||
$(this).parent().parent().parent().parent().find(".role-checkbox").removeAttr("checked");
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -127,13 +134,13 @@ var Items = function(){
|
|||
var this_value = $(this).val(),
|
||||
categories_list = $("#categories_list")
|
||||
tags_list = $("#tags_list"),
|
||||
status_list = $("#status_list"),
|
||||
role_list = $("#role_list"),
|
||||
layouts_list = $("#layouts_list"),
|
||||
data_count_area = $("#data_count_area");
|
||||
|
||||
categories_list.html("");
|
||||
tags_list.html("");
|
||||
status_list.html("");
|
||||
role_list.html("");
|
||||
if(this_value){
|
||||
$.ajax({
|
||||
url : "<%= Rails.application.routes.url_helpers.pages_get_categories_path %>",
|
||||
|
@ -170,17 +177,24 @@ var Items = function(){
|
|||
}
|
||||
|
||||
var controlDiv = $("<div class='controls'></div>");
|
||||
if(data.role_status.length){
|
||||
status_list.parent().find("label.control-label").text("<%= I18n.t(:role) %> :");
|
||||
if(data.roles.length){
|
||||
role_list.parent().find("label.control-label").text("<%= I18n.t(:role) %> :");
|
||||
var checkbox = $("<label class='checkbox'><input type='checkbox' value='all' name='page[categories][]' class='checkbox-all' /> <%= I18n.t(:all) %> </label>");
|
||||
controlDiv.append(checkbox);
|
||||
$.each(data.role_status,function(i,category){
|
||||
var checkbox = $("<label class='checkbox'><input type='checkbox' value='"+ category.id +"' name='page[categories][]' /> " + category.title + " </label>");
|
||||
$.each(data.roles,function(i,role){
|
||||
var status_list = '<ul id="status-list-'+role.id+'">';
|
||||
$.each(role.status,function(i,status){
|
||||
status_list+='<li><label class="checkbox"><input type="checkbox" value="'+status['id']+'" class="status-checkbox" name="page[role_status][]" >'+status['title']+'</label></li>';
|
||||
});
|
||||
|
||||
status_list += '</ul>';
|
||||
|
||||
var checkbox = $("<label class='checkbox'><input type='checkbox' class='role-checkbox' value='"+ role.id +"' name='page[categories][]' /> " + role.title + status_list + " </label>");
|
||||
controlDiv.append(checkbox);
|
||||
})
|
||||
status_list.html(controlDiv);
|
||||
role_list.html(controlDiv);
|
||||
}else{
|
||||
status_list.parent().find("label.control-label").text("");
|
||||
role_list.parent().find("label.control-label").text("");
|
||||
}
|
||||
|
||||
if(data.layouts.length){
|
||||
|
|
|
@ -1,55 +1,86 @@
|
|||
class MembersController < ApplicationController
|
||||
def index
|
||||
statuses = OrbitHelper.page_categories
|
||||
@statuses = []
|
||||
if statuses.first == "all"
|
||||
module_app = OrbitHelper.this_module_app
|
||||
@statuses = module_app.role_status.collect do |stat|
|
||||
page_roles = OrbitHelper.page_categories
|
||||
page_role_status = OrbitHelper.page_role_status
|
||||
|
||||
if page_roles.include?("all")
|
||||
roles = Role.all.collect do |role|
|
||||
{
|
||||
"status" => stat.title,
|
||||
"id" => stat.id.to_s,
|
||||
"status-role" => stat.role.title,
|
||||
"rs" => stat
|
||||
"title" => role.title,
|
||||
"id" => role.id
|
||||
}
|
||||
end
|
||||
else
|
||||
statuses.each do |stat|
|
||||
s = RoleStatus.find(stat)
|
||||
@statuses << {"status" => s.title, "id" => s.id.to_s, "rs" => s, "status-role" => s.role.title}
|
||||
page_role_status.each do |status_id|
|
||||
page_roles << RoleStatus.find(status_id).role.id.to_s
|
||||
end
|
||||
roles = Role.find(page_roles.uniq).collect do |role|
|
||||
{
|
||||
"title" => role.title,
|
||||
"id" => role.id,
|
||||
"status" => RoleStatus.where(:role_id=>role, :_id.in=>page_role_status)
|
||||
}
|
||||
end
|
||||
end
|
||||
stats = @statuses.collect do |status|
|
||||
members = status["rs"].member_profiles
|
||||
member_list = members.collect do |member|
|
||||
if member.avatar.present?
|
||||
image = member.avatar.thumb.url
|
||||
else
|
||||
image = "http://placehold.it/100x100"
|
||||
end
|
||||
roles = member.roles.collect do |role|
|
||||
{
|
||||
"role" => role.title
|
||||
|
||||
role_list = []
|
||||
roles.each do |role|
|
||||
status_list = []
|
||||
if !role['status'].blank?
|
||||
role['status'].each do |status|
|
||||
member_profiles = get_members_by_status(status)
|
||||
status_list << {
|
||||
"status-title" => status.title,
|
||||
"members" => member_profiles
|
||||
}
|
||||
end
|
||||
{
|
||||
"name" => member.name,
|
||||
"roles" => roles,
|
||||
"img_src" => image,
|
||||
"email" => member.email,
|
||||
"link_to_show" => OrbitHelper.url_to_show(member.to_param)
|
||||
else
|
||||
# Members with status
|
||||
RoleStatus.where(:role_id=>role['id']).each do |status|
|
||||
member_profiles = get_members_by_status(status)
|
||||
status_list << {
|
||||
"status-title" => status.title,
|
||||
"members" => member_profiles
|
||||
}
|
||||
end
|
||||
# Members without status
|
||||
member_profiles = []
|
||||
MemberProfile.where(:role_ids.in=>[role['id']], :role_status_ids.in=>[nil,[]]).collect do |profile|
|
||||
member_profiles << get_member_data(profile)
|
||||
end
|
||||
status_list << {
|
||||
"status-title" => "",
|
||||
"members" => member_profiles
|
||||
}
|
||||
|
||||
end
|
||||
{
|
||||
"status-title" => status["status"],
|
||||
"role-title" => status["status-role"],
|
||||
"members" => member_list
|
||||
role_list << {
|
||||
"role-title" => role['title'],
|
||||
"status-list" => status_list
|
||||
}
|
||||
end
|
||||
{
|
||||
"stats" => stats,
|
||||
"extras" => {"widget-title" => "Members"}
|
||||
{
|
||||
"roles" => role_list,
|
||||
"extras" => {
|
||||
"widget-title"=>t(:member_)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def get_members_by_status(status)
|
||||
member_profiles = []
|
||||
status.member_profiles.each do |profile|
|
||||
member_profiles<<get_member_data(profile)
|
||||
end
|
||||
return member_profiles
|
||||
end
|
||||
|
||||
def get_member_data(profile)
|
||||
{
|
||||
"name"=>profile.name,
|
||||
"email" => profile.email,
|
||||
"image" => profile.avatar.present? ? profile.avatar.thumb.url : "http://placehold.it/100x100",
|
||||
"link_to_show" => OrbitHelper.url_to_show(profile.to_param)
|
||||
}
|
||||
end
|
||||
|
||||
def show
|
||||
|
|
|
@ -80,6 +80,7 @@ class PagesController < ApplicationController
|
|||
OrbitHelper.set_this_module_app module_app.singularize
|
||||
OrbitHelper.set_page_categories page.categories || []
|
||||
OrbitHelper.set_page_tags page.tags || []
|
||||
OrbitHelper.set_page_role_status page.role_status || []
|
||||
OrbitHelper.set_page_data_count page.data_count
|
||||
if params[:layout].kind_of?(String)
|
||||
layout = to_bool(params[:layout])
|
||||
|
@ -141,10 +142,16 @@ class PagesController < ApplicationController
|
|||
def get_categories
|
||||
module_app = ModuleApp.find_by_key(params[:module]);
|
||||
if module_app.key.eql?("member")
|
||||
role_status = module_app.role_status.collect do |cat|
|
||||
roles = Role.all.collect do |role|
|
||||
{
|
||||
"title" => "#{cat.role.title} - #{cat.title}",
|
||||
"id" => cat.id.to_s
|
||||
"title" => role.title,
|
||||
"id" => role.id.to_s,
|
||||
"status" => RoleStatus.where(:role=>role).collect do |status|
|
||||
{
|
||||
"title" => status.title,
|
||||
"id" => status.id.to_s
|
||||
}
|
||||
end
|
||||
}
|
||||
end
|
||||
else
|
||||
|
@ -156,13 +163,13 @@ class PagesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
role_status = role_status.nil? ? [] : role_status.sort_by{|status| status['title']}
|
||||
roles = roles.nil? ? [] : roles.sort_by{|status| status['title']}
|
||||
categories = categories.nil? ? [] : categories
|
||||
|
||||
if module_app.data_count.nil?
|
||||
render :json => {"categories" => categories, "tags" => module_app.tags,"role_status" => role_status,"layouts" => (get_layouts module_app.key),"data_count" => {"present"=>false}}.to_json
|
||||
render :json => {"categories" => categories, "tags" => module_app.tags,"roles" => roles,"layouts" => (get_layouts module_app.key),"data_count" => {"present"=>false}}.to_json
|
||||
else
|
||||
render :json => {"categories" => categories, "tags" => module_app.tags,"role_status" => role_status,"layouts" => (get_layouts module_app.key),"data_count" => {"present"=>true,"start"=>module_app.data_count.begin, "end" => module_app.data_count.end}}.to_json
|
||||
render :json => {"categories" => categories, "tags" => module_app.tags,"roles" => roles,"layouts" => (get_layouts module_app.key),"data_count" => {"present"=>true,"start"=>module_app.data_count.begin, "end" => module_app.data_count.end}}.to_json
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -187,15 +194,16 @@ class PagesController < ApplicationController
|
|||
@categories = @module_app.categories rescue []
|
||||
@tags = @module_app.tags rescue []
|
||||
if @module_app.key.eql?("member")
|
||||
@status = @module_app.role_status.collect do |cat|
|
||||
@roles = Role.all.collect do |role|
|
||||
{
|
||||
"title" => "#{cat.role.title} - #{cat.title}",
|
||||
"id" => cat.id.to_s
|
||||
"title" => role.title,
|
||||
"id" => role.id.to_s,
|
||||
"status" => RoleStatus.where(:role=>role)
|
||||
}
|
||||
end
|
||||
@status = @status.sort_by{|status| status['title']}
|
||||
@roles = @roles.sort_by{|status| status['title']}
|
||||
else
|
||||
@status = []
|
||||
@roles = []
|
||||
end
|
||||
@layout_types = get_layouts @module_app.key
|
||||
end
|
||||
|
@ -323,7 +331,7 @@ 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_type, :page_id, :module, :layout, :parent_page, :data_count, :enabled_for_mobile, enabled_for_sitemap: [], enabled_for: [], menu_enabled_for: [], categories: [], tags: [], name_translations: [:en, :zh_tw],external_url_translations: [:en, :zh_tw])
|
||||
p = params.require(:page).permit(:number, :page_type, :page_id, :module, :layout, :parent_page, :data_count, :enabled_for_mobile, enabled_for_sitemap: [], enabled_for: [], menu_enabled_for: [], categories: [], tags: [], role_status: [], name_translations: [:en, :zh_tw],external_url_translations: [:en, :zh_tw])
|
||||
p["url"] = @url
|
||||
if p["external_url_translations"]
|
||||
p["external_url_translations"]["en"] = p["external_url_translations"]["en"].sub("http://" + request.host_with_port,"")
|
||||
|
@ -333,7 +341,9 @@ class PagesController < ApplicationController
|
|||
end
|
||||
|
||||
def page_update_params
|
||||
p = params.require(:page).permit(:number, :page_type, :page_id, :module, :layout, :parent_page, :data_count, :enabled_for_mobile, enabled_for_sitemap: [], enabled_for: [],menu_enabled_for: [], categories: [], tags: [], name_translations: [:en, :zh_tw], external_url_translations: [:en, :zh_tw])
|
||||
p = params.require(:page).permit(:number, :page_type, :page_id, :module, :layout, :parent_page, :data_count, :enabled_for_mobile, enabled_for_sitemap: [], enabled_for: [],menu_enabled_for: [], categories: [], tags: [], role_status: [], name_translations: [:en, :zh_tw], external_url_translations: [:en, :zh_tw])
|
||||
p["role_status"] = p["role_status"] || []
|
||||
p["categories"] = p["categories"] || []
|
||||
p["enabled_for"] = p["enabled_for"] || []
|
||||
p["menu_enabled_for"] = p["menu_enabled_for"] || []
|
||||
p["enabled_for_mobile"] = p["enabled_for_mobile"] || 0
|
||||
|
|
|
@ -11,6 +11,10 @@ module OrbitHelper
|
|||
@tags = tags;
|
||||
end
|
||||
|
||||
def self.set_page_role_status(role_status)
|
||||
@role_status = role_status;
|
||||
end
|
||||
|
||||
def self.set_page_data_count(data_count)
|
||||
@data_count = data_count
|
||||
end
|
||||
|
@ -38,6 +42,10 @@ module OrbitHelper
|
|||
@tags
|
||||
end
|
||||
|
||||
def self.page_role_status
|
||||
@role_status
|
||||
end
|
||||
|
||||
def self.page_for_tag(tag)
|
||||
page_for_tag = nil
|
||||
pages = Page.where(:module => @module_app.key)
|
||||
|
|
|
@ -17,6 +17,7 @@ class Page
|
|||
field :menu_enabled_for, type: Array, default: []
|
||||
field :categories, type: Array, :default => []
|
||||
field :tags, type: Array, :default => []
|
||||
field :role_status, type: Array, :default => []
|
||||
field :enabled_for_sitemap, type: Array, :default => []
|
||||
field :rss2_id, type: String
|
||||
|
||||
|
|
|
@ -2,27 +2,35 @@
|
|||
<h3 class="index-title">
|
||||
<span>{{widget-title}}</span>
|
||||
</h3>
|
||||
<div class="index-member-group" data-list="stats" data-level="0">
|
||||
<div class="index-member-group" data-list="roles" data-level="0">
|
||||
<div class="index-member-group-item">
|
||||
<div class="index-member-group-title">
|
||||
<h4>{{status-title}} ({{role-title}})</h4>
|
||||
<h4>{{role-title}}</h4>
|
||||
</div>
|
||||
<div class="index-member-list row" data-level="1" data-list="members">
|
||||
<div class="index-member-item clearfix col-sm-6">
|
||||
<div class="index-member-avatar pull-left">
|
||||
<img class="img-circle" src="{{img_src}}" alt="">
|
||||
</div>
|
||||
<div class="index-member-info">
|
||||
<h5 class="index-member-name">
|
||||
<a href="{{link_to_show}}">{{name}}</a>
|
||||
</h5>
|
||||
<p data-level="2" data-list="roles">
|
||||
<span class="index-member-role">{{role}}</span>
|
||||
</p>
|
||||
<p class="index-member-mail">{{email}}</p>
|
||||
|
||||
<div class="index-member-status" data-level="1" data-list="status-list">
|
||||
<div class="index-member-status-title">
|
||||
<h4>{{status-title}}</h4>
|
||||
</div>
|
||||
|
||||
<div class="index-member-list row" data-level="2" data-list="members">
|
||||
<div class="index-member-item clearfix col-sm-6">
|
||||
<div class="index-member-avatar pull-left">
|
||||
<img class="img-circle" src="{{image}}" alt="">
|
||||
</div>
|
||||
<div class="index-member-info">
|
||||
<h5 class="index-member-name">
|
||||
<a href="{{link_to_show}}">{{name}}</a>
|
||||
</h5>
|
||||
<p data-level="2" data-list="roles">
|
||||
<span class="index-member-role">{{role-title}}</span>
|
||||
</p>
|
||||
<p class="index-member-mail">{{email}}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -70,20 +70,30 @@
|
|||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label class="control-label"><%= t(:role)+" :" if params[:action] == "edit" && !@status.blank? %></label>
|
||||
<div id="status_list">
|
||||
<label class="control-label"><%= t(:role)+" :" if params[:action] == "edit" && !@roles.blank? %></label>
|
||||
<div id="role_list">
|
||||
<% if params[:action] == "edit" %>
|
||||
<div class="controls">
|
||||
<% if !@status.blank? %>
|
||||
<% if !@roles.blank? %>
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" value="all" class="checkbox-all" name="page[categories][]" <%= "checked='checked'" if (@page.categories.include? "all") %> >
|
||||
<%= t(:all) %>
|
||||
</label>
|
||||
<% end %>
|
||||
<% @status.each do |status| %>
|
||||
<% @roles.each do |role| %>
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" name="page[categories][]" value="<%= status['id'] %>" <%= "checked='checked'" if (@page.categories.include? status['id']) %> />
|
||||
<%= status['title'] %>
|
||||
<input type="checkbox" name="page[categories][]" class="role-checkbox" value="<%= role['id'] %>" <%= "checked='checked'" if (@page.categories.include? role['id']) %> />
|
||||
<%= role['title'] %>
|
||||
<ul id="status-list-<%= role['id'] %>">
|
||||
<% role['status'].each do |status| %>
|
||||
<li>
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" value="<%= status.id %>" class="status-checkbox" name="page[role_status][]" <%= "checked='checked'" if (@page.role_status.include? status.id.to_s) %> >
|
||||
<%= status.title %>
|
||||
</label>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</label>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue