diff --git a/app/controllers/actives_controller.rb b/app/controllers/actives_controller.rb index 3b42c19..479292c 100644 --- a/app/controllers/actives_controller.rb +++ b/app/controllers/actives_controller.rb @@ -115,8 +115,27 @@ class ActivesController < ApplicationController act_signup = ActSignup.new(id: nil) - time_now = Time.now + time_now = Time.now + # ↓ 新增:需先登入才能報名,且尚未登入,導向登入頁 + if act.need_pre_register && OrbitHelper.current_user.nil? + OrbitHelper.get_page_controller.redirect_to "/sessions/new" + return nil + end + + if act.need_pre_register && OrbitHelper.current_user + mp = OrbitHelper.current_user.member_profile rescue nil + if mp + act_signup.name = "#{mp.last_name_translations[I18n.locale.to_s]}#{mp.first_name_translations[I18n.locale.to_s]}".presence || mp.tmp_name + act_signup.email = mp.email + act_signup.birthday = mp.birthday + act_signup.sex = mp.sex + act_signup.fax = mp.fax + act_signup.address = mp.address + act_signup.tel = mp.office_tel + act_signup.phone = mp.mobile_no + end + end { "act" => act, "act_signup" => act_signup, @@ -144,4 +163,4 @@ class ActivesController < ApplicationController params.require(:act_signup).permit! end -end \ No newline at end of file +end diff --git a/app/controllers/admin/actives_controller.rb b/app/controllers/admin/actives_controller.rb index 9f2813e..18ad42e 100644 --- a/app/controllers/admin/actives_controller.rb +++ b/app/controllers/admin/actives_controller.rb @@ -86,6 +86,7 @@ class Admin::ActivesController < OrbitAdminController end def export + return render_401 unless can_see_act_signup(@act) title = @act.title.gsub(/\\|\//,'_') respond_to do |format| format.xlsx { @@ -96,7 +97,7 @@ class Admin::ActivesController < OrbitAdminController end def act_signup - + return render_401 unless can_see_act_signup(@act) @act_signups = ActSignup.where(:act_id => @act.id).page(params[:page]).per(10) end diff --git a/app/helpers/admin/actives_helper.rb b/app/helpers/admin/actives_helper.rb index 58af52b..401f2c6 100644 --- a/app/helpers/admin/actives_helper.rb +++ b/app/helpers/admin/actives_helper.rb @@ -1,4 +1,8 @@ module Admin::ActivesHelper + def can_see_act_signup(act) + can_edit_or_delete?(act) + end + def page_for_act(active=nil) ann_page = nil pages = Page.where(:module=>'active') @@ -28,4 +32,4 @@ module Admin::ActivesHelper request.protocol+(request.host_with_port+'/'+I18n.locale.to_s+ann_page.url+'/').gsub('//','/') rescue "/" end end -end \ No newline at end of file +end diff --git a/app/models/act.rb b/app/models/act.rb index 87dea98..c2dd529 100644 --- a/app/models/act.rb +++ b/app/models/act.rb @@ -29,6 +29,7 @@ class Act field :sign_start_date , :type => DateTime, :default => Time.now field :sign_end_date , :type => DateTime, :default => Time.now field :sign_up, :type => Boolean, :default => false + field :need_pre_register, :type => Boolean, :default => false field :note, localize: true field :has_name, :type => Boolean, :default => true @@ -65,6 +66,23 @@ class Act field :enabled_emergency_contact_person, :type => Boolean, :default => false field :enabled_vegetarian, :type => Boolean, :default => false + # ↓ 新增:自訂欄位顯示名稱(多語言) + field :signup_label_name, localize: true + field :signup_label_tel, localize: true + field :signup_label_phone, localize: true + field :signup_label_fax, localize: true + field :signup_label_email, localize: true + field :signup_label_idno, localize: true + field :signup_label_sex, localize: true + field :signup_label_birthday, localize: true + field :signup_label_organization, localize: true + field :signup_label_title, localize: true + field :signup_label_address, localize: true + field :signup_label_emergency_contact_number, localize: true + field :signup_label_emergency_contact_person, localize: true + field :signup_label_vegetarian, localize: true + field :signup_label_note, localize: true + has_many :act_links, :autosave => true, :dependent => :destroy has_many :act_files, :autosave => true, :dependent => :destroy has_many :act_signups, :autosave => true, :dependent => :destroy @@ -136,6 +154,12 @@ class Act self.is_external_link && !self.external_link.blank? end + # ↓ 新增:取得欄位自訂名稱,空白時 fallback 回 i18n 預設 + def field_label(key) + custom = self.send("signup_label_#{key}") rescue nil + custom.presence || I18n.t("act_signup.#{key}") + end + def signup_show time_now = Time.now if self.sign_up diff --git a/app/views/actives/show.html.erb b/app/views/actives/show.html.erb index 9c55342..fed9783 100644 --- a/app/views/actives/show.html.erb +++ b/app/views/actives/show.html.erb @@ -1,6 +1,9 @@ <% # encoding: utf-8 %> <% - data = action_data + data = action_data + if data.nil? + return + end @act = data["act"] @act_signup = data["act_signup"] @time_now = data["time_now"] @@ -8,7 +11,11 @@ %> <% if !@act.sign_up.blank? and @act.sign_start_date < @time_now and ( @act.sign_end_date > @time_now or @act.sign_end_date.nil? ) %> - + <% if @act.need_pre_register && OrbitHelper.current_user %> +
+ <%= t('act.logged_in_as', email: (OrbitHelper.current_user.member_profile.email rescue '')) %> +
+ <% end %> <%= stylesheet_link_tag "basic/bootstrap-datetimepicker" %> <%= javascript_include_tag "lib/bootstrap-datetimepicker" %> @@ -40,12 +47,12 @@ <% if @act.enabled_name %>
- +
<% if @act.has_name %> - <%= f.text_field :name, :class=>"input-medium form-control", :id=>'name', :placeholder=> t('act_signup.name'), :data => {"fv-validation" => "required;", "fv-messages" => "Cannot be empty.;"} %> + <%= f.text_field :name, :class=>"input-medium form-control", :id=>'name', :data => {"fv-validation" => "required;", "fv-messages" => "Cannot be empty.;"} %> <% else %> - <%= f.text_field :name, :class=>"input-medium form-control", :id=>'name', :placeholder=> t('act_signup.name') %> + <%= f.text_field :name, :class=>"input-medium form-control", :id=>'name' %> <% end %>
@@ -54,12 +61,12 @@ <% if @act.enabled_idno %>
- +
<% if @act.has_idno %> - <%= f.text_field :idno, :class=>"input-medium form-control", :placeholder=> t('act_signup.idno'), :data => {"fv-validation" => "required;", "fv-messages" => "Cannot be empty.;"} %> + <%= f.text_field :idno, :class=>"input-medium form-control", :data => {"fv-validation" => "required;", "fv-messages" => "Cannot be empty.;"} %> <% else %> - <%= f.text_field :idno, :class=>"input-medium form-control", :placeholder=> t('act_signup.idno') %> + <%= f.text_field :idno, :class=>"input-medium form-control" %> <% end %>
@@ -69,12 +76,12 @@ <% if @act.enabled_birthday %>
- +
<% if @act.has_birthday %> - <%= f.datetime_picker :birthday, :no_label => true, :format=>"yyyy/MM/dd", :data => {"fv-validation" => "required;", "fv-messages" => "Cannot be empty.;"} %> + <%= f.datetime_picker :birthday, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @act_signup.birthday.blank?, :data => {"fv-validation" => "required;", "fv-messages" => "Cannot be empty.;"} %> <% else %> - <%= f.datetime_picker :birthday, :no_label => true, :format=>"yyyy/MM/dd" %> + <%= f.datetime_picker :birthday, :no_label => true, :format=>"yyyy/MM/dd", :new_record => @act_signup.birthday.blank? %> <% end %>
@@ -83,7 +90,7 @@ <% if @act.enabled_sex %>
- +