Merge branch 'master' of gitlab.tp.rulingcom.com:saurabh/orbit4-5 into nccu

This commit is contained in:
Harry Bomrah 2015-04-22 22:53:52 +08:00
commit 4b6c27de75
12 changed files with 276 additions and 22 deletions

View File

@ -318,7 +318,7 @@
if( e.type == "keyup" && e.keyCode != 27) return;
// Make sure it's visible, and we're not modal
if( $pageslide.is( ':visible' ) && !$pageslide.data( 'modal' ) ) {
if( $pageslide.is( ':visible' ) && !$pageslide.data( 'modal' ) && !$("#modify_fields_to_show").is(":visible")) {
$.pageslide.close();
}
});

View File

@ -6,4 +6,39 @@
*/
.ui-helper-hidden-accessible{
display: none;
}
.current-roles {
list-style: none;
margin: 0 0 20px 0;
padding: 0;
}
.current-roles > li {
padding: 8px 10px;
margin-bottom: 8px;
border-radius: 4px;
border: 1px solid #eee;
-webkit-box-shadow: 0 0 2px 0 rgba(0,0,0,.2);
box-shadow: 0 0 2px 0 rgba(0,0,0,.2);
}
.role-value {
display: inline-block;
margin-right: 8px;
}
.remove-role {
cursor: pointer;
float: right;
padding-left: 16px;
border-left: 2px solid #e6e6e6;
}
.remove-role > i {
font-size: 1.125rem;
}
.remove-role:hover {
color: #ff4444;
}
.link-to-show {
float: right;
margin-right: 16px;
}

View File

@ -2,12 +2,14 @@ class MembersController < ApplicationController
def index
page_roles = OrbitHelper.page_categories
page_role_status = OrbitHelper.page_role_status
params = OrbitHelper.params
page = Page.where(:page_id => params[:page_id]).first rescue nil
fields_to_show = page.custom_array_field if !page.nil? rescue []
fields_to_show = [
{"key"=>"name", "type"=>"profile","sort_order"=>2,"link_to_show"=>true},
{"key"=>"discipline", "type"=>"role", "max_length"=>12},
{"key"=>"email", "type"=>"profile"},
{"key"=>"office_tel", "type"=>"profile"}
]
] if fields_to_show.blank?
if OrbitHelper.member_sort_position
sort = "data['list_order']"
@ -35,16 +37,10 @@ class MembersController < ApplicationController
role_list = []
roles.each do |role|
attribute_field = AttributeField.where(:key => 'job_title', :role_id => role['id']).first
if !attribute_field.blank?
role_fields_to_show = [{"id"=> attribute_field.id.to_s, "key"=>"job_title", "type"=>"role","sort_order"=>1}] + fields_to_show
else
role_fields_to_show = fields_to_show
end
status_list = []
if !role['status'].blank?
role['status'].each do |status|
member_profiles = get_members_by_status(status, sort, role_fields_to_show)
member_profiles = get_members_by_status(status, sort, fields_to_show)
status_list << { "status-title" => status.title, "members" => member_profiles } if !member_profiles.blank?
end
else
@ -53,7 +49,7 @@ class MembersController < ApplicationController
role_status_ids = role_status.collect{|status| status.id.to_s}
role_status.each do |status|
member_profiles = get_members_by_status(status, sort, role_fields_to_show)
member_profiles = get_members_by_status(status, sort, fields_to_show)
next if member_profiles.blank?
status_list << { "status-title" => status.title, "members" => member_profiles }
end

View File

@ -173,6 +173,60 @@ class PagesController < ApplicationController
end
end
def get_member_attributes
@page_id = params[:page_id]
@selected_attribs = Page.find(@page_id).custom_array_field
@selected_attribs = [
{"key"=>"name", "type"=>"profile","sort_order"=>2,"link_to_show"=>true, "human_readable" => I18n.t("users.name")},
{"key"=>"email", "type"=>"profile", "human_readable" => I18n.t("users.email")},
{"key"=>"office_tel", "type"=>"profile", "human_readable" => I18n.t("users.office_tel")}
] if @selected_attribs.blank?
personal_attribs = [
{"key" => "first_name", "human_readable" => I18n.t("users.first_name")},
{"key" => "last_name", "human_readable" => I18n.t("users.last_name")},
{"key" => "name", "human_readable" => I18n.t("users.name")},
{"key" => "sex", "human_readable" => I18n.t("users.sex")},
{"key" => "office_tel", "human_readable" => I18n.t("users.office_tel")},
{"key" => "birthday", "human_readable" => I18n.t("users.birthday")},
{"key" => "address", "human_readable" => I18n.t("users.address")},
{"key" => "personal_website", "human_readable" => I18n.t("users.personal_website")},
{"key" => "autobiography", "human_readable" => I18n.t("users.autobiography")},
{"key" => "email", "human_readable" => I18n.t("users.email")}
]
custom_attribs = MemberProfileField.all.collect do |mpf|
{"key" => mpf.key, "human_readable" => mpf.title}
end
role_attribs = AttributeField.all.collect do |af|
{"key" => af.key, "human_readable" => af.title}
end
@attribs = {
"profile" => personal_attribs,
"custom" => custom_attribs,
"role" => role_attribs,
"types" =>[
{"key" => "profile", "human_readable" => "Profile"},
{"key" => "custom", "human_readable" => "Custom"},
{"key" => "role", "human_readable" => "Role"}
]
}
render :partial => "member_frontend_field"
end
def save_member_frontend_fields
fields = params["fields"]
array = []
fields.each do |field|
array << field.last
end
page = Page.find(params[:page_id])
page.custom_array_field = array
page.save
render :json => {"success" => true}.to_json
end
def get_categories
module_app = ModuleApp.find_by_key(params[:module]);
if module_app.key.eql?("member")

View File

@ -22,6 +22,8 @@ class Page
field :member_sort_position, type: Boolean, :default => false
field :enabled_for_sitemap, type: Array, :default => []
field :rss2_id, type: String
field :custom_string_field, type: String
field :custom_array_field, type: Array, :default => []
has_many :page_parts, :autosave => true, :dependent => :destroy
has_many :mobile_page_parts, :autosave => true, :dependent => :destroy

View File

@ -10,7 +10,7 @@ class SubPart
field :content, localize: true
field :data_count, type: Integer, default: 10
field :categories, type: Array, :default => []
field :tags, type: Array, :default => []
field :tags, type: Array, :default => []
field :custom_string_field, type: String
field :custom_array_field, type: Array, :default => []

View File

@ -8,6 +8,7 @@
<%= render 'node_and_children', {node: node, level: 0} %>
</ol>
<% end %>
<%= render :partial => "pages/modify_member_frontend_fields" %>
<%##= render 'layouts/delete_modal', delete_options: {remote: true} %>
<%#= render 'form_page' %>
<%#= render 'form_link' %>

View File

@ -29,16 +29,36 @@
</div>
</div>
<div class="control-group" id="member_sort_setting">
<% if @module_app and @module_app.key.eql?("member") %>
<label class="control-label"><%= t(:sort) %>:</label>
<div class="controls">
<%= f.radio_button :member_sort_position, false, checked: !@page.member_sort_position? %> <%= t(:sort_by_role_fields) %><br/>
<%= f.radio_button :member_sort_position, true, checked: @page.member_sort_position?%> <%= t(:sort_manually) %>
<a href="/admin/members/edit_order_list" target="_blank"> <%= t(:sort_edit_order) %> </a>
<% if @module_app and @module_app.key.eql?("member") %>
<div class="control-group" id="member_sort_setting">
<label class="control-label"><%= t(:sort) %>:</label>
<div class="controls">
<%= f.radio_button :member_sort_position, false, checked: !@page.member_sort_position? %> <%= t(:sort_by_role_fields) %><br/>
<%= f.radio_button :member_sort_position, true, checked: @page.member_sort_position?%> <%= t(:sort_manually) %>
<a href="/admin/members/edit_order_list" target="_blank"> <%= t(:sort_edit_order) %> </a><br />
</div>
</div>
<% end %>
</div>
<div class="control-group">
<label class="control-label"><%= t(:feilds_to_show_for_index) %>:</label>
<div class="controls">
<a href="" id="modify_fields_btn"> <%= t(:modify) %> </a>
<script type="text/javascript">
$("#modify_fields_btn").on("click",function(){
var modal = $("#modify_fields_to_show");
modal.modal("show");
$.ajax({
url : "/pages/get_member_attributes",
data : {"page_id" : "<%= @page.id.to_s %>"},
dataType : "html",
}).done(function(data){
modal.find("div.modal-body").html(data);
})
return false;
})
</script>
</div>
</div>
<% end %>
<div class="control-group">
<label class="control-label"><%= t(:category)+" :" if params[:action] == "edit" && !@categories.blank? %></label>

View File

@ -0,0 +1,136 @@
<form id="form_for_attribs" action="">
<div class="form-inline">
<ul class="current-roles">
</ul>
</div>
<div class="form-inline controls-row">
<label>Attribute Type: </label>
<select class="role-selector" id="type_selector" style="width:100px;">
</select>
<label> Attribute: </label>
<select class="role-selector attrb-selector" id="profile_selector">
</select>
<select class="role-selector hide attrb-selector" id="custom_selector">
</select>
<select class="role-selector hide attrb-selector" id="role_selector">
</select>
<a href="#" class="add-role btn btn-default">Add role</a>
</div>
<div class="form-actions">
<input type="hidden" value="<%= @page_id %>">
<a href="#" id="form_for_attribs_btns" class="btn btn-primary">Save</a>
<a href="#" class="btn" data-dismiss="modal">Cancel</a>
</div>
</form>
<script type="text/javascript">
var selected_attribs = <%= @selected_attribs.to_json.html_safe %>,
attributes = <%= @attribs.to_json.html_safe %>;
var render_default_attributes = function(){
var html = "";
$.each(selected_attribs,function(i,attrib){
var collection = attributes[attrib.type],
node = collection.filter(function(x){return x.key == attrib.key})[0];
if(typeof node !== "undefined"){
if(attrib.key != "email"){
html+= '<li class="clearfix" data-attrib-key="' + attrib.key + '" data-attrib-type="' + attrib.type + '"><span class="role-value">' + node.human_readable + '</span><span class="remove-role"><i class="icon-remove-sign"></i></span><label class="checkbox link-to-show"><input type="checkbox" value="true" ' + (attrib.link_to_show ? "checked=checked" : "" ) + '> Link to show </label></li>';
}else{
html+= '<li class="clearfix" data-attrib-key="' + attrib.key + '" data-attrib-type="' + attrib.type + '"><span class="role-value">' + node.human_readable + '</span><span class="remove-role"><i class="icon-remove-sign"></i></span></li>';
}
}
})
$("#form_for_attribs ul.current-roles").html(html);
}();
var render_default_type_selectors = function(){
var html = "",
keys = [];
$.each(attributes.types,function(i, type){
html+= "<option value='" + type.key + "'>" + type.human_readable + "</option>";
keys.push(type.key);
})
$("#form_for_attribs select#type_selector").html(html).on("change",function(){
var val = $(this).val();
$("#form_for_attribs .attrb-selector").addClass("hide");
$("#form_for_attribs #" + val + "_selector").removeClass("hide");
});
$.each(keys,function(i,key){
var attribs = attributes[key],
html = "";
$.each(attribs,function(x,attrib){
html+= "<option value='"+ attrib.key +"'>" + attrib.human_readable + "</option>";
})
$("#" + key + "_selector").html(html);
})
}();
$(document).ready(function(){
// Add Role function, get the current selected item value and append it to select element
function addRole( e ) {
var type = $("#form_for_attribs #type_selector").val(),
attrib_key = $("#form_for_attribs #"+type+"_selector").val(),
attrib_text = $("#form_for_attribs #"+type+"_selector option[value="+attrib_key+"]").text();
// If the select is empty, stop appending or it will keep appending blank content to select element
if(attrib_key != "email"){
$( ".current-roles" ).append( "<li class=\"clearfix\" data-attrib-key=\"" + attrib_key + "\" data-attrib-type=\"" + type + "\"><span class=\"role-value\">" + attrib_text + "</span><span class=\"remove-role\"><i class=\"icon-remove-sign\"></i></span><label class=\"checkbox link-to-show\"><input type=\"checkbox\" value=\"true\"> Link to show </label></li>" );
}else{
$( ".current-roles" ).append( "<li class=\"clearfix\" data-attrib-key=\"" + attrib_key + "\" data-attrib-type=\"" + type + "\"><span class=\"role-value\">" + attrib_text + "</span><span class=\"remove-role\"><i class=\"icon-remove-sign\"></i></span></li>" );
}
e.preventDefault();
}
// Remove the select role and append it back to select element
function removeRole( e ) {
var el = $( this ).closest( "li" ).remove();
$( "select" ).append( "<option>" + el.find( ".role-value" ).text() + "</option>" );
e.preventDefault();
}
// Add event listeners
$( ".add-role" ).on( "click", addRole );
$( ".current-roles" ).on( "click", ".remove-role", removeRole );
$("#form_for_attribs ul.current-roles").sortable();
$("#form_for_attribs #form_for_attribs_btns").on("click",function(){
var data = [];
$("#form_for_attribs ul.current-roles li").each(function(i){
var opts = {};
opts["key"] = $(this).data("attrib-key");
opts["type"] = $(this).data("attrib-type");
opts["sort"] = i + 2;
// opts["human_readable"] = $(this).find("span.role-value").text();
if($(this).find("input[type=checkbox]").is(":checked")){
opts["link_to_show"] = true;
}
if(opts["key"] == "discipline"){
opts["max_length"] = 12;
}
data.push(opts);
})
$.ajax({
url : "/pages/save_member_frontend_fields",
data : {"fields" : data, "page_id" : $("#form_for_attribs input[type=hidden]").val()},
type : "post",
dataType : "json"
}).done(function(){
$("#modify_fields_to_show").modal("hide");
})
return false;
})
})
</script>

View File

@ -0,0 +1,9 @@
<div id="modify_fields_to_show" class="modal hide fade" role="dialog">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h3>Modify Fields</h3>
</div>
<div class="modal-body">
<img src="/assets/preloader.gif" />
</div>
</div>

View File

@ -7,4 +7,4 @@
<%= page.url %>
</li>
<% end %>
</ul>
</ul>

View File

@ -650,6 +650,7 @@ en:
first_name: First Name
last_name: Last Name
male: Male
discipline: Discipline
name: Name
valid_old_password: Current password doesn't match confirmation
new_password: New password