finish the first version of patch_file

This commit is contained in:
chiu committed 2019-09-28 19:48:59 +08:00
commit a2d46ca121
398 files changed
+12910

No files matched your search

+821
View File
@@ -0,0 +1,821 @@
class Admin::MembersController < OrbitMemberController
before_action :show_member_profile, only: [:show, :edit, :update, :edit_passwd, :edit_privilege]
before_action :check_password_reset
helper MemberHelper
helper OrbitBackendHelper
require 'spreadsheet'
require 'rubyXL'
def index
@roles = Role.excludes(disabled: true)
@member_tags = MemberTag.all
page_num = params[:page] || 1
param_temp = request.fullpath.split("?")
@edit_params = (param_temp.count > 1 ? "?" + param_temp.last : "") rescue ""
@filter = params[:filter]
@mq = params[:mq]
@new_filter = params[:new_filter]
if @filter && params[:clear]
@filter.delete(params[:type])
elsif @filter && @new_filter
if @filter.has_key?(@new_filter[:type]) && @filter[@new_filter[:type]].include?(@new_filter[:id].to_s)
@filter[@new_filter[:type]].delete(@new_filter[:id].to_s)
elsif @filter.has_key?(@new_filter[:type])
@filter[@new_filter[:type]] << @new_filter[:id].to_s
else
@filter.merge!({@new_filter[:type] => [@new_filter[:id].to_s]})
end
elsif @new_filter
@filter = {@new_filter[:type] => [@new_filter[:id].to_s]}
end
render_401 and return if current_user.nil? || !current_user.is_approved?
if @filter.blank? and @mq.blank?
render case params[:at]
when 'summary'
@members = MemberProfile.all.page(page_num).per(12).desc("_id")
"index_summary"
when 'thumbnail'
@members = MemberProfile.all.page(page_num).per(36).desc("_id")
"index_thumbnail"
else
@members = MemberProfile.all.page(page_num).per(10).desc("_id")
"index"
end
elsif @filter.blank? and !@mq.blank?
render case params[:at]
when 'summary'
@members=MemberProfile.all.any_of({:user_id => /#{@mq}/i}, {:first_name => /#{@mq}/i}, {:last_name => /#{@mq}/i}, {:email => /#{@mq}/i}, {:office_tel => /#{@mq}/i}).desc("_id")
"index_summary"
when 'thumbnail'
@members=MemberProfile.all.any_of({:user_id => /#{@mq}/i}, {:first_name => /#{@mq}/i}, {:last_name => /#{@mq}/i}, {:email => /#{@mq}/i}, {:office_tel => /#{@mq}/i}).desc("_id")
"index_thumbnail"
else
@members=MemberProfile.all.any_of({:user_id => /#{@mq}/i}, {:first_name => /#{@mq}/i}, {:last_name => /#{@mq}/i}, {:email => /#{@mq}/i}, {:office_tel => /#{@mq}/i}).desc("_id")
"index"
end
elsif !@filter.blank? and @mq.blank?
render case params[:at]
when 'summary'
case (@new_filter["type"] rescue @filter.keys.first)
when "role"
@members=MemberProfile.all.any_in(:role_ids=>@filter['role']).page(page_num).per(12).desc("_id")
"index_summary"
when "tag"
@members=MemberProfile.all.any_in(:member_tag_ids=>@filter['tag']).page(page_num).per(12).desc("_id")
"index_summary"
end
when 'thumbnail'
case (@new_filter["type"] rescue @filter.keys.first)
when "role"
@members=MemberProfile.all.any_in(:role_ids=>@filter['role']).page(page_num).per(36).desc("_id")
"index_thumbnail"
when "tag"
@members=MemberProfile.all.any_in(:member_tag_ids=>@filter['tag']).page(page_num).per(36).desc("_id")
"index_thumbnail"
end
else
case (@new_filter["type"] rescue @filter.keys.first)
when "role"
@members=MemberProfile.all.any_in(:role_ids=>@filter['role']).page(page_num).per(10).desc("_id")
"index"
when "tag"
@members=MemberProfile.all.any_in(:member_tag_ids=>@filter['tag']).page(page_num).per(10).desc("_id")
"index"
end
end
end
end
def show
@custom_fields = @member.member_profile_field_values rescue []
if current_site.personal_plugins_sort.blank?
@plugins = OrbitApp::Plugin::Registration.all rescue nil
else
plugin_list = OrbitApp::Plugin::Registration.all.collect{|p| p.module_app_name}
plugin_list = current_site.personal_plugins_sort | plugin_list
@plugins = OrbitApp::Plugin::Registration.sort_by_array(plugin_list) rescue nil
end
# @ppname = Array.new
# @plugins.each do |aa|
# @ppname << [aa.sort_number.to_i, [aa.name, aa.app_name, aa.intro_app_name, aa.front_partial_path]]
# end
@plugin_shows = @plugins.collect {|v| {"name"=>v.name,"app_name"=>v.app_name,"intro_app_name"=>v.intro_app_name,"front_partial_path"=>v.front_partial_path, "count" => (v.app_name.classify.constantize.where(:member_profile_id => @member.id).count rescue 0)} }
if(!params[:show_plugin_profile].nil?)
@right_partial = OrbitApp::Plugin::Registration.find_by_app_name(params[:show_plugin_profile]).profile_partial_path rescue 'plugin_summary'
@plugin_app_name = OrbitApp::Plugin::Registration.find_by_app_name(params[:show_plugin_profile]).name rescue nil
else
@right_partial = "new_profile_partial"
@plugin_app_name = ''
end
get_info_and_roles
render_401 and return if current_user.nil? || (@member.id.to_s != current_user.member_profile.id.to_s && !current_user.is_approved?)
end
def make_alpha_from_numbers(number)
@numeric = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
if number < @numeric.size
@a = @numeric[number]
else
@dev_by = (number/@numeric.size).floor
@a = "#{make_alpha_from_numbers(@dev_by-1)}#{make_alpha_from_numbers(number-(@dev_by*@numeric.size))}";
end
end
def import_data_check(file)
profile_data_row = ["email","sid","office_tel","sex","birthday"]
profile_lang_data_row = ["first_name","last_name","address","autobiography"]
@field_type = {'text_field' => 'typeA', 'select' => 'typeB', 'date' => 'typeC', 'text_area' => 'typeD', 'radio_button' => 'typeE', 'checkbox' => 'typeE', 'address' => ''}
@date_type = {'format1' => '%Y/%m/%d %H:%M', 'format2' => '%Y/%m/%d', 'format3' => '%Y/%m', 'format4' => '%Y'}
@error_msg = Array.new
workbook = RubyXL::Parser.parse(file.tempfile)
sheet = workbook['Member'].extract_data
sheet.each_with_index do |row,index|
if index == 0
@field_data = row
end
if index > 2
@user_id = row[@field_data.index('user_id')]
if !@user_id.blank?
check_id = User.where(:user_name => @user_id).first
@error_msg << "#{make_alpha_from_numbers(@field_data.index('user_id'))}#{index+1}欄位帳號已存在。" if !check_id.blank?
@error_msg << "#{make_alpha_from_numbers(@field_data.index('user_id'))}#{index+1}欄位格式不符。" if @user_id.size < 3
end
@password = row[@field_data.index('password')]
if !@password.blank? and !@user_id.blank?
@error_msg << "#{make_alpha_from_numbers(@field_data.index('password'))}#{index+1}欄位格式不符。" if @password.size < 8
elsif @password.blank? and !@user_id.blank?
@error_msg << "#{make_alpha_from_numbers(@field_data.index('password'))}#{index+1}欄位格式不符。"
end
@error_msg << "#{make_alpha_from_numbers(@field_data.index('birthday'))}#{index+1}欄位日期格式不符。" if row[@field_data.index("birthday")].class.to_s != 'DateTime' and !row[@field_data.index('birthday')].blank?
@infos = MemberInfo.all
@infos.each do |info|
info.member_profile_fields.each do |member_profile_field|
if member_profile_field.markup == 'select' or member_profile_field.markup == 'radio_button'
@option_list = member_profile_field[@field_type[member_profile_field.markup]]['option_list'].collect{|p| p[0]}
@rowname = "#{info.key}-#{member_profile_field.key}"
@error_msg << "#{make_alpha_from_numbers(@field_data.index(@rowname))}#{index+1}欄位格式不符。" if !@option_list.include?("#{row[@field_data.index(@rowname)]}") and !row[@field_data.index(@rowname)].blank?
elsif member_profile_field.markup == 'checkbox'
@rowname = "#{info.key}-#{member_profile_field.key}"
@error_msg << "#{make_alpha_from_numbers(@field_data.index(@rowname))}#{index+1}欄位格式不符。" if row[@field_data.index(@rowname)].to_s.split(',').last == row[@field_data.index(@rowname)] and !row[@field_data.index(@rowname)].blank?
elsif member_profile_field.markup == 'date'
@rowname = "#{info.key}-#{member_profile_field.key}"
@error_msg << "#{make_alpha_from_numbers(@field_data.index(@rowname))}#{index+1}欄位日期格式不符。" if row[@field_data.index(@rowname)].class.to_s != 'DateTime' and !row[@field_data.index(@rowname)].blank?
end
end
end
@roles = Role.all
@roles.each do |role|
role_statuses = RoleStatus.where(role_id: role.id, :disable=> false)
if !role_statuses.blank?
@rowname = "#{role.key}-status"
if !@field_data.index(@rowname).blank?
@error_msg << "#{make_alpha_from_numbers(@field_data.index(@rowname))}#{index+1}欄位格式不符。" if row[@field_data.index(@rowname)].to_s.split(',').last == row[@field_data.index(@rowname)] and !row[@field_data.index(@rowname)].blank?
end
end
role.attribute_fields.asc(:created_at).each do |attribute_field|
if attribute_field.markup == 'select' or attribute_field.markup == 'radio_button'
@option_list = attribute_field[@field_type[attribute_field.markup]]['option_list'].collect{|p| p[0]}
@rowname = "#{role.key}-#{attribute_field.key}"
if !@field_data.index(@rowname).blank?
@error_msg << "#{make_alpha_from_numbers(@field_data.index(@rowname))}#{index+1}欄位格式不符。" if !@option_list.include?("#{row[@field_data.index(@rowname)]}") and !row[@field_data.index(@rowname)].blank?
end
elsif attribute_field.markup == 'checkbox'
@rowname = "#{role.key}-#{attribute_field.key}"
if !@field_data.index(@rowname).blank?
@error_msg << "#{make_alpha_from_numbers(@field_data.index(@rowname))}#{index+1}欄位格式不符。" if row[@field_data.index(@rowname)].to_s.split(',').last == row[@field_data.index(@rowname)] and !row[@field_data.index(@rowname)].blank?
end
elsif attribute_field.markup == 'date'
@rowname = "#{role.key}-#{attribute_field.key}"
if !@field_data.index(@rowname).blank?
@error_msg << "#{make_alpha_from_numbers(@field_data.index(@rowname))}#{index+1}欄位日期格式不符。" if row[@field_data.index(@rowname)].class.to_s != 'DateTime' and !row[@field_data.index(@rowname)].blank?
end
end
end
end
end
end
end
def import_members
if !params[:file].blank?
import_data_check(params[:file])
if @error_msg.blank?
profile_data_row = ["email","sid","office_tel","sex","birthday"]
profile_lang_data_row = ["first_name","last_name","address","autobiography"]
@field_type = {'text_field' => 'typeA', 'select' => 'typeB', 'date' => 'typeC', 'text_area' => 'typeD', 'radio_button' => 'typeE', 'checkbox' => 'typeE', 'address' => ''}
@date_type = {'format1' => '%Y/%m/%d %H:%M', 'format2' => '%Y/%m/%d', 'format3' => '%Y/%m', 'format4' => '%Y'}
workbook = RubyXL::Parser.parse(params[:file].tempfile)
sheet = workbook['Member'].extract_data
sheet.each_with_index do |row,index|
if index == 0
@field_data = row
end
if index > 2
if !row[0].blank? and !row[1].blank?
@member_profile = MemberProfile.new
@site_in_use_locales.each_with_index do |locale, i|
@member_profile.first_name_translations = @member_profile.first_name_translations.merge!( "#{locale}" => row[@field_data.index("first_name(#{locale})")]) if !row[@field_data.index("first_name(#{locale})")].blank?
@member_profile.last_name_translations = @member_profile.last_name_translations.merge!( "#{locale}" => row[@field_data.index("last_name(#{locale})")]) if !row[@field_data.index("last_name(#{locale})")].blank?
@member_profile.address_translations = @member_profile.address_translations.merge!( "#{locale}" => row[@field_data.index("address(#{locale})")]) if !row[@field_data.index("address(#{locale})")].blank?
@member_profile.autobiography_translations = @member_profile.autobiography_translations.merge!( "#{locale}" => row[@field_data.index("autobiography(#{locale})")]) if !row[@field_data.index("autobiography(#{locale})")].blank?
end
@member_profile.email = row[@field_data.index("email")]
@member_profile.sid = row[@field_data.index("sid")]
@member_profile.office_tel = row[@field_data.index("office_tel")]
@member_profile.sex = ( row[@field_data.index("sex")] == 'male' or row[@field_data.index("sex")] == 'female' ) ? row[@field_data.index("sex")] : 'unknown'
@member_profile.birthday = row[@field_data.index("birthday")].class.to_s == 'DateTime' ? row[@field_data.index("birthday")] : ''
@member_profile.save
@infos = MemberInfo.all
@infos.each do |info|
info.member_profile_fields.each do |member_profile_field|
value = member_profile_field.member_profile_field_values.build
value.member_profile_id = @member_profile.id
if member_profile_field.markup == 'text_field' or member_profile_field.markup == 'text_area'
if member_profile_field[@field_type[member_profile_field.markup]]['cross_lang'] == 'true'
@rowname = "#{info.key}-#{member_profile_field.key}"
value["val"] = row[@field_data.index(@rowname)] if !row[@field_data.index(@rowname)].blank?
else
@site_in_use_locales.each_with_index do |locale, i|
@rowname = "#{info.key}-#{member_profile_field.key}(#{locale})"
value["#{locale}"] = row[@field_data.index(@rowname)] if !row[@field_data.index(@rowname)].blank?
end
end
elsif member_profile_field.markup == 'checkbox'
@rowname = "#{info.key}-#{member_profile_field.key}"
value["val"] = row[@field_data.index(@rowname)].to_s.split(',') if !row[@field_data.index(@rowname)].blank?
elsif member_profile_field.markup == 'date'
@rowname = "#{info.key}-#{member_profile_field.key}"
value["val"] = row[@field_data.index(@rowname)].class.to_s == 'DateTime' ? row[@field_data.index(@rowname)].to_datetime.strftime(@date_type[member_profile_field['typeC']['format']]) : ''
elsif member_profile_field.markup == 'address'
@site_in_use_locales.each_with_index do |locale, i|
@rowname = "#{info.key}-#{member_profile_field.key}(#{locale})"
value["#{locale}"] = row[@field_data.index(@rowname)] if !row[@field_data.index(@rowname)].blank?
end
else
@rowname = "#{info.key}-#{member_profile_field.key}"
value["val"] = "#{row[@field_data.index(@rowname)]}"
end
value.save
end
end
@role_status_data = []
@roles = Role.all
@roles.each do |role|
role_statuses = RoleStatus.where(role_id: role.id, :disable=> false).asc(:_id)
if !role_statuses.blank?
@rowname = "#{role.key}-status"
if !@field_data.index(@rowname).blank?
if !row[@field_data.index(@rowname)].blank?
@status_value = row[@field_data.index(@rowname)].to_s.split(',')
role_statuses.each do |role_status|
if @status_value.include?(role_status.key)
@role_status_data << role_status.id
end
end
end
end
end
@role_add_value = 0
role.attribute_fields.asc(:created_at).each do |attribute_field|
value = attribute_field.attribute_values.build
value.member_profile_id = @member_profile.id
if attribute_field.markup == 'text_field' or attribute_field.markup == 'text_area'
if attribute_field[@field_type[attribute_field.markup]]['cross_lang'] == 'true'
@rowname = "#{role.key}-#{attribute_field.key}"
if !@field_data.index(@rowname).blank?
if !row[@field_data.index(@rowname)].blank?
value["val"] = row[@field_data.index(@rowname)]
@role_add_value = @role_add_value + 1
end
end
else
@site_in_use_locales.each_with_index do |locale, i|
@rowname = "#{role.key}-#{attribute_field.key}(#{locale})"
if !@field_data.index(@rowname).blank?
if !row[@field_data.index(@rowname)].blank?
value["#{locale}"] = row[@field_data.index(@rowname)]
@role_add_value = @role_add_value + 1
end
end
end
end
elsif attribute_field.markup == 'checkbox'
@rowname = "#{role.key}-#{attribute_field.key}"
if !@field_data.index(@rowname).blank?
if !row[@field_data.index(@rowname)].blank?
value["val"] = row[@field_data.index(@rowname)].to_s.split(',')
@role_add_value = @role_add_value + 1
end
end
elsif attribute_field.markup == 'date'
@rowname = "#{role.key}-#{attribute_field.key}"
if !@field_data.index(@rowname).blank?
value["val"] = row[@field_data.index(@rowname)].class.to_s == 'DateTime' ? row[@field_data.index(@rowname)].to_datetime.strftime(@date_type[attribute_field['typeC']['format']]) : ''
end
elsif attribute_field.markup == 'address'
@site_in_use_locales.each_with_index do |locale, i|
@rowname = "#{role.key}-#{attribute_field.key}(#{locale})"
if !@field_data.index(@rowname).blank?
if !row[@field_data.index(@rowname)].blank?
value["#{locale}"] = row[@field_data.index(@rowname)]
@role_add_value = @role_add_value + 1
end
end
end
else
@rowname = "#{role.key}-#{attribute_field.key}"
if !@field_data.index(@rowname).blank?
if !row[@field_data.index(@rowname)].blank?
value["val"] = "#{row[@field_data.index(@rowname)]}"
@role_add_value = @role_add_value + 1
end
end
end
value.save
end
if @role_add_value > 0
role.member_profiles << @member_profile
role.save
end
end
if !@role_status_data.blank?
@member_profile.role_status_ids = @role_status_data
@member_profile.save
end
@user = User.new(
user_name: row[@field_data.index("user_id")],
password: row[@field_data.index("password")],
member_profile_id: @member_profile.id,
approved: true
)
@user.save
end
end
end
redirect_to admin_members_path
else
render 'import_error_msg'
end
end
end
def download_export
@users = User.all
@member_role = params[:member_role].blank? ? Role.all.asc(:_id) : params[:member_role]
@member_roles = @member_role.collect{|a| a[0]}
respond_to do |format|
format.xlsx {
response.headers['Content-Disposition'] = 'attachment; filename="member_import_data.xlsx"'
}
end
end
def new
if has_access?
@member = MemberProfile.new
get_info_and_roles
@user = User.new
@form_index = 0
else
render_401
end
end
def edit
param_temp = request.fullpath.split("?")
@edit_params = (param_temp.count > 1 ? "?" + param_temp.last : "") rescue ""
if has_access?
@form_index = 0
get_info_and_roles
if @member.user.present?
@user = @member.user
else
@user = User.new(member_profile_id: @member.id)
end
else
render_401
end
end
def create
@member = MemberProfile.new(member_profile_params)
if @member.save
if user_params["user_name"] != ""
@user = User.new(user_params) rescue nil
@user.member_profile = @member
if !@user.save
@member.destroy
get_info_and_roles
@form_index = 0
render 'new' and return
end
end
mpfv_params = member_profile_field_values_params
if !mpfv_params.nil?
mpfv_params.each_with_index do |m,i|
@custom_field_value = @member.member_profile_field_values.build(value: m.second["value"], member_profile_field_id: m.second["member_profile_field_id"])
@custom_field_value.save
end
end
rfv_params = role_field_values_params
if !rfv_params.nil?
rfv_params.each_with_index do |r,i|
field_value = r.last[:id].present?
@custom_field_value = AttributeValue.put_field_values(@member, r.last, r.last[:attribute_field_id], field_value)
end
end
redirect_to admin_members_path
else
render 'new'
end
end
def update
param_temp = request.fullpath.split("?")
@edit_params = (param_temp.count > 1 ? "?" + param_temp.last : "") rescue ""
respond_to do |format|
if @member.user.present?
@user = @member.user
@user.update(user_params)
else
if user_params["user_name"] != ""
@user = User.new(user_params) rescue nil
@user.member_profile = @member
@user.save
else
@user = User.new(user_params) rescue nil
end
end
if @member.update_attributes(member_profile_params)
if params[:edit_type]!="edit_privilege" and (params[:member_profile].nil? or params[:member_profile][:role_status_ids].nil?)
@member.update_attributes(role_status_ids: [])
end
mpfv_params = member_profile_field_values_params
if !mpfv_params.nil?
mpfv_params.each_with_index do |m,i|
field_value = m.last[:id].present?
@custom_field_value = MemberProfileFieldValue.put_field_values(@member, m.last, m.last[:id], field_value)
end
# elsif !params[:member_profile_field_value].nil?
# params[:member_profile_field_value].each_with_index do |m,i|
# field_value = m.last[:id].present?
# @custom_field_value = MemberProfileFieldValue.put_field_values(@member, m.last, nil, field_value)
# end
end
rfv_params = role_field_values_params
if !rfv_params.nil?
rfv_params.each_with_index do |r,i|
field_value = r.last[:id].present?
@custom_field_value = AttributeValue.put_field_values(@member, r.last, r.last[:id], field_value)
end
end
if params[:edit_type]=="edit_privilege"
@member.user.update_attributes(workgroup_id: params[:workgroup_id])
end
format.html { redirect_to admin_members_path() + @edit_params, notice: 'Successfully Updated the User' }
format.json { head :no_content }
else
get_info_and_roles
@form_index = 0
format.html { render action: "edit_passwd"} if params[:edit_type] == "edit_passwd"
format.html { render action: 'edit' }
format.json { render json: @member.errors, status: :unprocessable_entity }
end
end
end
def destroy
if params[:id].eql?(current_user.id.to_s)
flash[:error] = t(:cant_delete_self)
else
@member_profile = MemberProfile.find(params[:id])
@member_profile.user.delete if @member_profile.user.present?
@member_profile.destroy
@member_profile.roles.clear
@member_profile.role_statuses.clear
end
respond_to do |format|
format.js
end
end
def unapproved_members
@member_query = Sanitize.clean(params[:member_query])
page_num = params[:page] || 1
if !@member_query.blank?
members = MemberProfile.all.any_of({:user_id => /#{@member_query}/i}, {:first_name => /#{@member_query}/i}, {:last_name => /#{@member_query}/i}, {:email => /#{@member_query}/i})
@members = members.collect do |member|
if !member.user.approved
member.user
end
end
else
@members = User.unapproved.page(page_num).per(12)
end
end
def accept_member
user = User.find(params[:member_id])
user.approved = true
user.save
redirect_to admin_members_unapproved_members_path
end
def edit_passwd
if has_access?
@user = @member.user
else
render_401
end
end
def edit_privilege
@edit_params = "?" + request.fullpath.split("?").last rescue ""
if current_user.is_admin?
@user = @member.user
@workgroup = Workgroup.find_by(key: 'admin')
else
render_401
end
end
def edit_order_card
@members = MemberProfile.order('created_at DESC')
@type = 'card'
render 'edit_order'
end
def edit_order_list
@members = MemberProfile.order(:position=>'asc',:created_at=>'desc')
@type = 'list'
render 'edit_order'
end
def update_order_card
@error = false
if params[:users].present?
to_go = params[:users][:position].to_i
member_at_position = MemberProfile.find_by(position: to_go + 1)
member = MemberProfile.find(params[:users][:id])
if member_at_position
if member.position > member_at_position.position
member.move_above(member_at_position)
else
member.move_below(member_at_position)
end
end
end
render nothing: true, status: 200
end
def update_order_list
if params[:position].present?
params[:position].each do |id, position|
profile = MemberProfile.find(id)
profile.position = position.to_i
profile.save(:validate => false)
end
end
# @error = []
# if params[:users].present?
# params[:users].values.sort.each do |pair|
# to_go = pair[0].to_i
# if to_go > 0
# member_at_position = MemberProfile.where(position: to_go).first
# member = MemberProfile.find(pair[1])
# if member_at_position && !(member_at_position == member)
# if member.position > member_at_position.position
# member.move_above(member_at_position)
# else
# member.move_below(member_at_position)
# end
# elsif to_go > MemberProfile.count
# member.move_to_bottom
# end
# end
# end
# end
# @members = MemberProfile.asc(:position)
render :nothing=>true
end
def save_autobiography
content = params[:content]
member = MemberProfile.find(params["member-id"]) rescue nil
if !member.nil?
member.autobiography = content
member.save
end
render :json => {"success" => true}.to_json
end
def new_tag
membertag = MemberTag.new(member_tag_params)
membertag.created_by = current_user.id
membertag.save
render :json => {"success" => true, "title" => membertag.title, "id" => membertag.id.to_s}.to_json
end
def setting_account
if params[:member_id].blank?
redirect_to action: :index
else
@user = MemberProfile.find(params[:member_id])
if current_user.id != @user.id
redirect_to action: :index
end
end
end
def get_role_fields
role = Role.find(params[:id])
statuses = role.role_statuses.map{|status| {'key'=>status.key, 'title'=>status.title}}.select{|s| s['key']='part_time'}
render :json=>{"statuses"=>statuses}
end
def set_privacy
id = params[:id]
status = params[:status]
if current_user.is_admin?
member = MemberProfile.find(params[:memberid])
else
member = current_user.member_profile
end
old = member.get_privacy_type_for_field(id)
case status
when "locked"
member.locked_privacy << id
when "logged_in"
member.logged_in_privacy << id
when "public"
member.public_privacy << id
end
case old
when "locked"
member.locked_privacy.delete(id)
when "logged_in"
member.logged_in_privacy.delete(id)
when "public"
member.public_privacy.delete(id)
end
member.save
render :json => {"success" => true}.to_json
end
private
# Use callbacks to share common setup or constraints between actions.
def set_member_profile
@member = MemberProfile.find(params[:id])
end
def show_member_profile
path = request.path.split('/')
if path.last.include? '-'
uid = path[-1].split("-").last
uid = uid.split("?").first
else
uid = path[-2].split("-").last
uid = uid.split("?").first
end
@member = MemberProfile.find_by(uid: uid)
end
# Never trust parameters from the scary internet, only allow the white list through.
def member_profile_params
params.require(:member_profile).permit! rescue nil
end
def role_field_values_params
params.require(:role_field_values).permit! rescue nil
end
def member_profile_field_values_params
params.require(:member_profile_field_values).permit! rescue nil
end
def user_params
params.require(:user).permit! rescue nil
end
def member_tag_params
params.require(:member_tag).permit!
end
protected
def get_info_and_roles
if current_user.is_admin?
@roles = Role.excludes(disabled: true).asc(:key)
else
@roles = current_user.member_profile.roles
end
@infos = MemberProfileField.excludes(disabled: true)
end
def set_attribute
@class = 'users'
end
end
+505
View File
@@ -0,0 +1,505 @@
<head>
<%= stylesheet_link_tag "lib/wrap-nav"%>
<%= stylesheet_link_tag "lib/main-forms"%>
<%= stylesheet_link_tag "lib/fileupload"%>
<%= stylesheet_link_tag "lib/togglebox"%>
<%= javascript_include_tag 'lib/bootstrap-fileupload' %>
<%= javascript_include_tag 'lib/site_set' %>
</head>
<%= form_for @site, :url => admin_site_path(@site.id), :html => {:class => "form-horizontal main-forms"} do |f| %>
<fieldset>
<!-- Input Area -->
<div class="input-area">
<div class="nav-name"><strong><%= t('preferences.classification') %></strong></div>
<ul class="nav nav-pills language-nav">
<% if current_user.user_name == "rulingcom" || current_user.beta_tester %>
<li>
<a href="#sidebar-nav" data-toggle="tab"><%= t('preferences.sidebar_nav') %></a>
</li>
<% end %>
<li class="active">
<a href="#system-email" data-toggle="tab"><%= t('preferences.system_email') %></a>
</li>
<li>
<a href="#openness" data-toggle="tab"><%= t('preferences.openness') %></a>
</li>
<li>
<a href="#language-set" data-toggle="tab"><%= t('preferences.language') %></a>
</li>
<li>
<a href="#orbitBar-them" data-toggle="tab"><%= t('preferences.orbitbar_theme') %></a>
</li>
<li>
<a href="#google-oauth" data-toggle="tab">Google OAuth</a>
</li>
<li>
<a href="#social-sharer" data-toggle="tab">Social Share</a>
</li>
<li>
<a href="#sign-up" data-toggle="tab">Sign Up</a>
</li>
</ul>
<div class="tab-content">
<!-- Sidebar Nav -->
<% if current_user.user_name == "rulingcom" || current_user.beta_tester %>
<div id="sidebar-nav" class="tab-pane fade in active">
<div class="control-group">
<label class="control-label muted"><%= t("preferences.nav_enabled") %></label>
<div class="controls">
<input type="checkbox" class="toggle-check set-sidebar-state" data-disabled="true">
</div>
</div>
</div>
<% end %>
<!-- System Email -->
<%= f.fields_for :site_settings, @site['site_settings'] do |f| %>
<div id="system-email" class="tab-pane fade in active">
<div class="control-group">
<label class="control-label muted"><%= t 'mail.service_email' %></label>
<div class="controls">
<%= f.text_field :service_email, :value => (@site['site_settings']['service_email'] rescue nil), :class=>"input-large", :placeholder=>"Administrator Mail" %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t 'mail.reply_email' %></label>
<div class="controls">
<%= f.text_field :reply_email, :value => (@site['site_settings']['reply_email'] rescue nil), :class=>"input-large", :placeholder=>"Reply Mail" %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t 'mail.address' %></label>
<div class="controls">
<%= f.text_field :address, :value => (@site['site_settings']['address'] rescue nil), :class=>"input-large", :placeholder=>"Email Address" %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t 'mail.domain' %></label>
<div class="controls">
<%= f.text_field :domain, :value => (@site['site_settings']['domain'] rescue nil), :class=>"input-large", :placeholder=>"Domain" %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t 'mail.authentication' %></label>
<div class="controls">
<%= f.text_field :authentication, :value => (@site['site_settings']['authentication'] rescue nil), :class=>"input-large", :placeholder =>"Authentication" %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t 'mail.user_name' %></label>
<div class="controls">
<%= f.text_field :user_name, :value => (@site['site_settings']['user_name'] rescue nil), :class=>"input-large", :placeholder=>"User Name" %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t 'mail.password' %></label>
<div class="controls">
<%= f.password_field :password, :value => (@site['site_settings']['password'] rescue nil), :class=>"input-large", :placeholder=>"Password" %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t 'mail.port' %></label>
<div class="controls">
<%= f.text_field :port, :value => (@site['site_settings']['port'] rescue nil),:placeholder=>"Port", :class=>"input-mini" %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t 'mail.tls' %></label>
<div class="controls">
<%= f.check_box :tls, :checked => (@site['site_settings']['tls'].eql?('1') rescue false),:class=>"toggle-check", :data=> { disabled: true } %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t 'mail.enable_starttls_auto' %></label>
<div class="controls">
<%= f.check_box 'enable_starttls_auto', :checked => (@site['site_settings']['enable_starttls_auto'].eql?('1') rescue false), :class=>"toggle-check", :data=> { disabled: true } %>
</div>
</div>
</div>
<% end %>
<!-- Openness -->
<div id="openness" class="tab-pane fade">
<div class="control-group">
<label class="control-label muted"><%= I18n.t('site.frontend_open')%></label>
<div class="controls">
<%= f.check_box :frontend_open , :class=>"toggle-check", :data=> { disabled: true } %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= I18n.t('site.backend_openness_on') %></label>
<div class="controls">
<%= f.check_box :backend_openness_on , :class=>"toggle-check", :data=> { disabled: true } %>
</div>
</div>
<div class="control-group hide">
<label class="control-label muted"><%= I18n.t('site.disable_personal_desktop')%></label>
<div class="controls">
<%= f.check_box :desktop_closed , :class=>"toggle-check", :data=> { disabled: true } %>
</div>
</div>
</div>
<!-- Language -->
<div id="language-set" class="tab-pane fade">
<!-- <div class="control-group">
<label class="control-label muted">Enable User Language Detection</label>
<div class="controls">
<input type="checkbox" class="toggle-check" data-disabled="true">
</div>
</div> -->
<!-- Terms of Use -->
<div class="control-group">
<label class="control-label muted"><%= t('preferences.lang_detection') %>
</label>
<div class="controls">
<%= f.check_box :enable_language_detection, :class => "toggle-check reset_default_locale", data: {disabled: true} %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t('preferences.enable_zh_cn') %>
</label>
<div class="controls">
<%= f.check_box :enable_zh_cn, :class => "toggle-check", data: {disabled: true} %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t('preferences.lang_enabled') %></label>
<div class="controls">
<% I18n.available_locales.each do |valid_locale| %>
<%= check_box_tag "site[in_use_locales][#{valid_locale}]", valid_locale, @site.in_use_locales.include?(valid_locale), :class=>"toggle-check in_use_locales", :data => { :title => "#{t(valid_locale.to_s)}", disabled: true }, "data-deploy"=>"inline" %>
<% end %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t('preferences.lang_default') %></label>
<div class="controls">
<% I18n.available_locales.each do |locale| %>
<%= radio_button_tag "site[default_locale]", locale, @locale == locale ,:class=>"toggle-check", :data => { :title => "#{t(locale.to_s)}" }, "data-deploy"=>"inline", :checked => (@site.default_locale.eql?("#{locale}")) %>
<% end %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t('preferences.redirect_index') %>
</label>
<div class="controls">
<%= f.check_box :enable_redirect_index, :class => "toggle-check reset_default_locale", data: {disabled: true} %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t('preferences.enable_language_options') %>
</label>
<div class="controls">
<%= f.check_box :enable_language_options, :class => "toggle-check", data: {disabled: true} %>
</div>
</div>
</div>
<!-- OrbitBar Them -->
<div id="orbitBar-them" class="tab-pane fade">
<div class="control-group">
<label class="control-label muted">OrbitBar Logo <%= t('preferences.icon') %></label>
<div class="controls">
<!-- if this page editing please add class "fileupload-edit" -->
<div class="fileupload fileupload-new clearfix" data-provides="fileupload">
<div class="fileupload-new thumbnail pull-left" style="background:black;">
<% if @site.default_image.file.present? %>
<%= image_tag( @site.default_image, :size=>"120x120") rescue ''%>
<% else %>
<%= image_tag "orbit-logo.png",:class => "pull-left upload-picture"%>
<% end %>
</div>
<div class="fileupload-preview fileupload-exists thumbnail pull-left"></div>
<% if @site.default_image.file.present?%>
<span class="btn btn-file">
<%= f.file_field :default_image, :id => "input-upload", :class => 'fileupload-new', :onchange => "document.getElementById('fu').innerHTML = this.form.fu.value = this.value;" %><%= t('preferences.change') %>
</span>
<%= f.check_box :remove_default_image %>
<%= t(:remove) %> OrbitBar Logo
<%else%>
<span class="btn btn-file">
<%= f.file_field :default_image, :id => "input-upload", :class => 'fileupload-new', :onchange => "document.getElementById('fu').innerHTML = this.form.fu.value = this.value;" %><%= t('preferences.select_image') %>
</span>
<%end%>
<a href="#" class="btn fileupload-exists" data-dismiss="fileupload"><%= t(:cancel) %></a>
</div>
</div>
<div class="control-group">
<label class="control-label muted">Orbit <%= t('preferences.favicon') %></label>
<div class="controls">
<!-- if this page editing please add class "fileupload-edit" -->
<div class="fileupload fileupload-new clearfix" data-provides="fileupload">
<div class="fileupload-new thumbnail pull-left">
<% if @site.favicon.file.present? %>
<%= image_tag( @site.favicon, :size=>"120x120") rescue ''%>
<% else %>
<%= image_tag "favicon.ico", :class => "pull-left upload-picture"%>
<% end %>
</div>
<div class="fileupload-preview fileupload-exists thumbnail pull-left"></div>
<% if @site.favicon.file.present?%>
<span class="btn btn-file">
<%= f.file_field :favicon, :id => "input-upload", :class => 'fileupload-new', :onchange => "document.getElementById('fu').innerHTML = this.form.fu.value = this.value;" %><%= t('preferences.change') %>
</span>
<%= f.check_box :remove_favicon %>
<%= t(:remove) %> <%= t('preferences.favicon') %>
<%else%>
<span class="btn btn-file">
<%= f.file_field :favicon, :id => "input-upload", :class => 'fileupload-new', :onchange => "document.getElementById('fu').innerHTML = this.form.fu.value = this.value;" %><%= t('preferences.select_image') %>
</span>
<%end%>
<a href="#" class="btn fileupload-exists" data-dismiss="fileupload"><%= t(:cancel) %></a>
</div>
</div>
</div>
<div class="control-group">
<label class="control-label muted">Orbit <%= t('preferences.site_logo') %>(second image or the only one image)</label>
<div class="controls">
<!-- if this page editing please add class "fileupload-edit" -->
<div class="fileupload fileupload-new clearfix" data-provides="fileupload">
<div class="fileupload-new thumbnail pull-left">
<% if @site.site_logo.file.present? %>
<%= image_tag( @site.site_logo, :size=>"120x120") rescue ''%>
<% else %>
<%= image_tag "site-logo.png", :class => "pull-left upload-picture"%>
<% end %>
</div>
<div class="fileupload-preview fileupload-exists thumbnail pull-left"></div>
<% if @site.site_logo.file.present?%>
<span class="btn btn-file">
<%= f.file_field :site_logo, :id => "input-upload", :class => 'fileupload-new', :onchange => "document.getElementById('fu').innerHTML = this.form.fu.value = this.value;" %><%= t('preferences.change') %>
</span>
<%= f.check_box :remove_site_logo %>
<%= t(:remove) %> <%= t('preferences.site_logo') %>
<%else%>
<span class="btn btn-file">
<%= f.file_field :site_logo, :id => "input-upload", :class => 'fileupload-new', :onchange => "document.getElementById('fu').innerHTML = this.form.fu.value = this.value;" %><%= t('preferences.select_image') %>
</span>
<%end%>
<a href="#" class="btn fileupload-exists" data-dismiss="fileupload"><%= t(:cancel) %></a>
</div>
</div>
</div>
<div class="control-group">
<label class="control-label muted">Orbit <%= t('preferences.site_logo_1') %></label>
<div class="controls">
<!-- if this page editing please add class "fileupload-edit" -->
<div class="fileupload fileupload-new clearfix" data-provides="fileupload">
<div class="fileupload-new thumbnail pull-left">
<% if @site.site_logo_1.file.present? %>
<%= image_tag( @site.site_logo_1, :size=>"120x120") rescue ''%>
<% else %>
<%= image_tag "site-logo.png", :class => "pull-left upload-picture"%>
<% end %>
</div>
<div class="fileupload-preview fileupload-exists thumbnail pull-left"></div>
<% if @site.site_logo_1.file.present?%>
<span class="btn btn-file">
<%= f.file_field :site_logo_1, :id => "input-upload", :class => 'fileupload-new', :onchange => "document.getElementById('fu').innerHTML = this.form.fu.value = this.value;" %><%= t('preferences.change') %>
</span>
<%= f.check_box :remove_site_logo_1 %>
<%= t(:remove) %> <%= t('preferences.site_logo_1') %>
<%else%>
<span class="btn btn-file">
<%= f.file_field :site_logo_1, :id => "input-upload", :class => 'fileupload-new', :onchange => "document.getElementById('fu').innerHTML = this.form.fu.value = this.value;" %><%= t('preferences.select_image') %>
</span>
<%end%>
<a href="#" class="btn fileupload-exists" data-dismiss="fileupload"><%= t(:cancel) %></a>
</div>
</div>
<div class="control-group"><label class="control-label muted">home_link(for site logo)</label><div class="controls"><%= f.text_field :home_link %></div></div>
<div class="control-group"><label class="control-label muted">home_link_1(for site logo 1)</label><div class="controls"><%= f.text_field :home_link_1 %></div></div>
<% @site_in_use_locales.each do |locale| %>
<%= f.fields_for :site_title do |f| %>
<div class="control-group">
<label class="control-label muted">Site title (for site logo) (<%= t(locale) %>)</label>
<div class="controls">
<%= f.text_field locale, :value => (@site.site_title[locale.to_s] rescue nil), :placeholder=>"site_title" %>
</div>
</div>
<% end %>
<%= f.fields_for :site_title_1 do |f| %>
<div class="control-group">
<label class="control-label muted">Site title 1 (for site logo 1) (<%= t(locale) %>)</label>
<div class="controls">
<%= f.text_field locale, :value => (@site.site_title_1[locale.to_s] rescue nil), :placeholder=>"site_title_1" %>
</div>
</div>
<% end %>
<% end %>
</div>
<% @site_in_use_locales.each do |locale| %>
<%= f.fields_for :mobile_orbit_bar_title_translations do |f| %>
<div class="control-group">
<label class="control-label muted">Orbit bar title (<%= t(locale) %>)</label>
<div class="controls">
<%= f.text_field locale, :value => (@site.mobile_orbit_bar_title_translations[locale.to_s] rescue nil), :placeholder=>"Orbit bar title" %>
</div>
</div>
<% end %>
<% end %>
</div>
</div>
<div id="google-oauth" class="tab-pane fade">
<div class="control-group">
<label class="control-label muted">Enable Google OAuth</label>
<div class="controls">
<%= f.check_box :google_oauth_enabled %>
</div>
</div>
<div class="control-group">
<label class="control-label muted">Google client id</label>
<div class="controls">
<%= f.text_field :google_client_id, :value => (@site['google_client_id'] rescue nil), :class=>"input-large google-oauth-fields", :placeholder=>"Google client id", :disabled => !@site[:google_oauth_enabled] %>
</div>
</div>
<div class="control-group">
<label class="control-label muted">Google client secret</label>
<div class="controls">
<%= f.text_field :google_client_secret, :value => (@site['google_client_secret'] rescue nil), :class=>"input-large google-oauth-fields", :placeholder=>"Google client secret", :disabled => !@site[:google_oauth_enabled] %>
</div>
</div>
<div class="alert alert-info">Please restart the website after modifying these settings. Click on the restart button and refresh the page in sometime. <a class="btn btn-small btn-primary" id="restart_server">Restart server</a></div>
</div>
<div id="social-sharer" class="tab-pane fade">
<div class="control-group">
<label class="control-label muted">Enable Social Share</label>
<div class="controls">
<input type="checkbox" value="facebook" name="site[every_page_sharer][]" <%= @site.every_page_sharer.include?("facebook") ? "checked=checked" : "" %> > Facebook
<input type="checkbox" value="twitter" name="site[every_page_sharer][]" <%= @site.every_page_sharer.include?("twitter") ? "checked=checked" : "" %> > Twitter
<input type="checkbox" value="google" name="site[every_page_sharer][]" <%= @site.every_page_sharer.include?("google") ? "checked=checked" : "" %> >
Google
<input type="checkbox" value="printer" name="site[every_page_sharer][]" <%= @site.every_page_sharer.include?("printer") ? "checked=checked" : "" %> >
Printer
<input type="hidden" value="disable" name="site[every_page_sharer][]">
</div>
</div>
</div>
<!-- sign up -->
<div id="sign-up" class="tab-pane fade">
<div class="control-group">
<label class="control-label muted"><%= I18n.t('site.roles_for_sign_up')%></label>
<div class="controls">
<% Role.where(:disabled => false).each do |r| %>
<input type="checkbox" value="<%= r.id.to_s %>" name="site[sign_up_roles][]" <%= @site.sign_up_roles.include?(r.id.to_s) ? "checked=checked" : "" %> > <%= r.title %><br />
<% end %>
</div>
</div>
</div>
</div>
<!-- Form Actions -->
<div class="form-actions" style="background: none;">
<%= f.submit t("submit"), :class => "btn btn-primary" %>
<%= f.submit t("cancel"), :class => "btn ", :type => 'reset' %>
</div>
</fieldset>
<%end%>
<% content_for :page_specific_javascript do %>
<%end%>
<script type="text/javascript">
$(".language-nav li a").click(function(){window.location.hash = $(this).attr("href")});
$(document).ready(function(){
var language_detection = $("#site_enable_language_detection");
var default_locale = $( "input[name='site[default_locale]']" );
$(language_detection).click(function(){
if ( !$(this).parent().hasClass("disable") ){
// Disable default language if language detection enbaled
$.each($(default_locale),function(){
if ( !$(this).parent().hasClass("disable") ){
$(this).parent().toggleClass('disable');
$(this).toggleClass('disable');
}
$(language_detection).val(1);
});
}else{
// Enable a default language when language detection is disabled
$(default_locale).first().click();
}
});
// Disable language detection if default language enbaled
$.each($(default_locale),function(){
$(this).change(function(){
if(!$(language_detection).parent().hasClass("disable")) {
$(language_detection).parent().toggleClass('disable');
$(language_detection).val(0);
}
});
});
});
var locales = <%= @site.in_use_locales.to_json.html_safe %>;
$(document).ready(function(){
$( ".in_use_locales" ).each( function(){
$( this ).parent( "div.togglebox" ).addClass( "disabled" );
var val = $( this ).val();
if( locales.filter(function(a){ return a == val }).length == 1){
$( this ).parent( "div.togglebox" ).removeClass( "disabled" );
}
})
});
delete locales;
$(function() {
$('a[data-toggle="tab"]').on('click', function (e) {
var tab = $(this).attr('href');
localStorage.setItem('lastTab', tab);
});
//go to the latest tab, if it exists:
var lastTab = localStorage.getItem('lastTab');
if (lastTab) {
$('a[href='+lastTab+']').click();
}
});
$("#site_google_oauth_enabled").on("click",function(){
if($(this).is(":checked")){
$(".google-oauth-fields").removeAttr("disabled");
}else{
$(".google-oauth-fields").attr("disabled","disabled");
}
})
$("#restart_server").on("click",function(){
$.ajax({
url : "<%= admin_site_restart_server_path(@site) %>",
type : "get"
})
return false;
})
</script>