From df03157f711e4f9c8c0df07c3a343402224865e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=8D=9A=E4=BA=9E?= Date: Wed, 27 Sep 2023 21:04:20 +0800 Subject: [PATCH 1/6] move code to core --- app/helpers/admin/seminars_values_helper.rb | 107 ---------- app/models/seminar_signup_value.rb | 221 +------------------- 2 files changed, 1 insertion(+), 327 deletions(-) diff --git a/app/helpers/admin/seminars_values_helper.rb b/app/helpers/admin/seminars_values_helper.rb index f076cd2..2cbfd7c 100644 --- a/app/helpers/admin/seminars_values_helper.rb +++ b/app/helpers/admin/seminars_values_helper.rb @@ -3,111 +3,4 @@ module Admin::SeminarsValuesHelper markup = attribute_field.markup $seminar_list[:markups][markup]["panel"] == type ? type : [type,'hide'].join(" ") end - def show_west_calender(from_to=nil) - case from_to - when :to - date = get_date(:to) - when :from - date = get_date(:from) - when nil - date = get_date - end - - # case self.member_profile_field["typeC"]["format"] - # when 'format1' # Y/M/D h:m - # date.strftime("%Y/%m/%d %H:%M") - # when 'format2' # Y/M/D - # date.strftime("%Y/%m/%d") - # when 'format3' # Y/M - # date.strftime("%Y/%m") - # when 'format4' # Y - # date.strftime("%Y") - # end # of case west cal format - end - - def show_minguo_calendar(from_to=nil) - get_minguo - - case from_to - when :to - date = get_date(:to) - when :from - date = get_date(:from) - when nil - date = get_date - end - - @date = date.split('/') - date_year = @date[0].to_i - - year_str = "" - unless date_year == 1912 - m_year = (date_year - 1912).abs.to_s + I18n.t("date.minguo_calendar.year") - year_str = minguo_format_year(m_year) - end - get_minguo_year(from_to) + minguo_m_y_d_time(from_to) - end - - def get_minguo_year(from_to=nil) - case from_to - when :to - date = get_date(:to) - when :from - date = get_date(:from) - when nil - date = get_date - end - - @date = date.split('/') - date_year = @date[0].to_i - - m_year = (date_year - 1911).abs - year_end = I18n.t("date.minguo_calendar.year") - case - when date_year <1912 - I18n.t("date.minguo_calendar.before") + (m_year+1).to_s + year_end - when date_year ==1912 - I18n.t("date.minguo_calendar.first_year") - when date_year >1912 - I18n.t("date.minguo_calendar.after")+ (m_year).to_s + year_end - end # of case tw_calendar year - end - - def minguo_m_y_d_time(from_to=nil) - case from_to - when :to - date = get_date(:to) - when :from - date = get_date(:from) - when nil - date = get_date - end - @date = date.split('/') - - case self.seminar_signup_field["typeC"]["format"] - when 'format1' # Y/M/D h:m - "/#{@date[1]}/#{@date[2]}" - when 'format2' # Y/M/D - "/#{@date[1]}/#{@date[2]}" - when 'format3' # Y/M - - "/#{@date[1]}#{I18n.t("date.minguo_calendar.month")}"\ - when 'format4' # Y - '' - end # of case - end - - def get_date_by_format(from_to = nil) - case I18n.locale - when :zh_tw - case - when self.seminar_signup_field["typeC"]["calendar"] == "west_calendar" - show_west_calender(from_to) - when self.seminar_signup_field["typeC"]["calendar"] == "tw_calendar" - show_minguo_calendar(from_to) - end #case self.seminar_signup_field["typeC"]["calendar"] - when :en - show_west_calender(from_to) - end - end end \ No newline at end of file diff --git a/app/models/seminar_signup_value.rb b/app/models/seminar_signup_value.rb index bc36467..a0b8a09 100644 --- a/app/models/seminar_signup_value.rb +++ b/app/models/seminar_signup_value.rb @@ -2,228 +2,9 @@ class SeminarSignupValue include Mongoid::Document include Mongoid::Timestamps include Mongoid::Attributes::Dynamic + belongs_to :seminar_signup_field #must for FieldParser include ::AttributeValuesHelper include ::Admin::SeminarsValuesHelper - field :key, type: String - - belongs_to :seminar_signup_field belongs_to :seminar_signup - - before_save :check_key - before_save :data_proc - - def add_more_counter - index_max = self["val"].count rescue 0 - index_max == 0 ? 1 : index_max - end - - def value(index = nil) - site = Site.first - result = case self.seminar_signup_field.markup - when 'text_field','text_area' - if self.seminar_signup_field.add_more and (self.seminar_signup_field.markup == "text_field") - index.nil? ? self["val"] : self["val"][index] - else - self.seminar_signup_field.get_data["cross_lang"] =="true" ? self["val"] : Hash[site.valid_locales.collect{|lang| [lang,self[lang.to_sym]]}] - end - when 'select','radio_button','address' - self["val"] - when 'date' - if !self["val"].blank? and !self["val"]['(1i)'].blank? - "#{self["val"]['(1i)']}/#{self["val"]['(2i)']}/#{self["val"]['(3i)']}" - else - self["val"] - end - when 'checkbox' - self["val"] - end #end of case self.seminar_signup_field.markup - end - - def value=(value) - #save everything to temp_data waiting for futher process - self[:temp_data] = value - end - - def get_field_value - seminar_signup_field = self.seminar_signup_field - if (seminar_signup_field.markup.eql?("text_field") || seminar_signup_field.markup.eql?("text_area")) - if self.value.class == String - field_value = self.value - else - field_value = self.value[I18n.locale] - end - elsif (seminar_signup_field.markup.eql?("select") || seminar_signup_field.markup.eql?("radio_button")) - field_value = seminar_signup_field.markup_value["#{self.value}"][I18n.locale] rescue nil - elsif seminar_signup_field.markup.eql?("address") - field_value = rf[:address_key][I18n.locale].map{|k,v| v}.delete_if(&:blank?).join(', ') - elsif seminar_signup_field.markup.eql?("date") - case seminar_signup_field.typeC['format'] - when 'format1' - field_value = self.value.to_date.strftime("%Y/%m/%d") - when 'format2' - field_value = self.value.to_date.strftime("%Y/%m/%d") - when 'format3' - field_value = self.value.to_date.strftime("%Y/%m") - when 'format4' - field_value = self.value.to_date.strftime("%Y") - end - elsif seminar_signup_field.markup.eql?("checkbox") - field_value = self.value.map {|v| seminar_signup_field.markup_value["#{v}"][I18n.locale]}.join(', ') rescue nil - end - - field_value = (field_value =~ /\A#{URI::regexp(['http', 'https'])}\z/) ? "#{field_value}" : field_value - field_value = (field_value =~ /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i) ? "#{field_value}" : field_value - - if !field_value.blank? - { - "key" => seminar_signup_field.key, - "title" => seminar_signup_field.title, - "value" => field_value, - "val" => field_value = self.value - } - else - { - "key" => seminar_signup_field.key, - "title" => seminar_signup_field.title, - "value" => "", - "val" => field_value = self.value - } - end - end - - def get_value_by_locale(locale,add_more_index=nil) - seminar_signup_field = self.seminar_signup_field - case seminar_signup_field.markup - when "text_field" - case seminar_signup_field.add_more - when true - if seminar_signup_field.locale - add_more_index.nil? ? self.value.collect{|t| t[locale.to_s]}.join(",") : self.value(add_more_index)[locale] - else - add_more_index.nil? ? self.value.join(",") : self.value(add_more_index) - end - - when false - seminar_signup_field.locale ? self[locale.to_s] : self.value - end - - when "select" - markup_values = seminar_signup_field.self_defined_markup_options? ? seminar_signup_field.markup_value : self.seminar_signup_field.markup_value - markup_values[self.value][locale.to_s] rescue 'NoData' - - when "text_area" - seminar_signup_field.locale ? self[locale.to_s] : self.value - - when "date" - if seminar_signup_field.date_is_range? - get_date_by_format(:from) + ' ~ ' + get_date_by_format(:to) - # self.value["from"] + ' ~ ' + self.value["to"] - else - get_date_by_format - # self.value - end - - when "address" - self.value[locale.to_s] - - when "radio_button" - markup_values = seminar_signup_field.markup_value - markup_values[self.value][locale.to_s] - - when "checkbox" - markup_values = seminar_signup_field.markup_value - self.value.collect{|key| markup_values["#{key}"][I18n.locale]}.join(",") - when "date_durnation" - self.value - - else - seminar_signup_field.locale ? self[locale.to_s] : self.value - end - end - - def get_date(item = nil) - case item - when :from - # data = self[:val]["from"] - data = self.value["from"] - when :to - # data = self[:val]["to"] - data = self.value["to"] - when nil - # data = self[:val] - data = self.value - end - - # Date.new(data["(1i)"].to_i,data["(2i)"].to_i,data["(3i)"].to_i) rescue nil - end - - def self.put_field_values(member, field_value_param, field_value_id=nil,field_value_status) - if field_value_status.eql?(true) - @seminar_signup_field_value = member.seminar_signup_values.find(field_value_id) rescue nil - if @seminar_signup_field_value!=nil - @seminar_signup_field_value.update(field_value_param) rescue nil - @seminar_signup_field_value.save rescue nil - end - else - @seminar_signup_field_value = member.seminar_signup_values.build(field_value_param) rescue nil - @seminar_signup_field_value.save - end - return @seminar_signup_field_value - end - - -protected - -def unset_all_lang_values - VALID_LOCALES.each{|t| self.unset t} - end - - def data_proc - seminar_signup_field = self.seminar_signup_field - unless self[:temp_data].nil? - case seminar_signup_field.markup - when "address" - self["val"] = self["temp_data"] - when 'text_field','text_area' - if seminar_signup_field.add_more - self["val"] = self["temp_data"] - else # if not add_more - if seminar_signup_field.can_muti_lang_input? - self[:temp_data].each do |key,val| - self[key] = val - end if(!seminar_signup_field.get_data[:cross_lang]) - else - self["val"] = self[:temp_data] - end - end # of self.seminar_signup_field.add_more - - when 'select','date','radio_button' - self["val"] = self[:temp_data] - when 'checkbox' - self["val"] = self[:temp_data].keys - end #end of case self.seminar_signup_field.markup - end # of self[:temp_data].nil? - self.unset('temp_data') - self.unset('temp') - end #of data_proc - - def check_key - if self.seminar_signup_field_id.present? && self.seminar_signup_field.nil? - begin - self.seminar_signup_field = SeminarSignupField.find(self.seminar_signup_field_id) - rescue - nil - end - end - self.key = self.seminar_signup_field.key rescue nil - end - - def method_missing(*field) - if field.size < 1 - self[field[0]] - else - self[(field[0].to_s.delete "=")] = field[1] - end - end end From f6decf3770dd9c5304b9fa675cc95bf9e96d6e8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=8D=9A=E4=BA=9E?= Date: Wed, 27 Sep 2023 22:21:17 +0800 Subject: [PATCH 2/6] add new custom field type(file upload) --- config/list.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/list.yml b/config/list.yml index 90ea26a..1e8330e 100644 --- a/config/list.yml +++ b/config/list.yml @@ -37,6 +37,9 @@ markups: muti_lang_input_supprt: false ext_support: false panel: member_relations + file_field: + muti_lang_input_supprt: false + ext_support: false seminar_preferred_session: muti_lang_input_supprt: false ext_support: false From d4aba5c2cbe33597a0df1e2cb34e0229dd802988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=8D=9A=E4=BA=9E?= Date: Wed, 27 Sep 2023 22:56:21 +0800 Subject: [PATCH 3/6] add new custom field type(file upload) --- app/helpers/admin/seminars_field_helper.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/helpers/admin/seminars_field_helper.rb b/app/helpers/admin/seminars_field_helper.rb index 8e4f04e..3ae5e4f 100644 --- a/app/helpers/admin/seminars_field_helper.rb +++ b/app/helpers/admin/seminars_field_helper.rb @@ -182,6 +182,19 @@ module Admin::SeminarsFieldHelper end end + def render_file_field + a = control_group_wrapper_for_sm do |key,value| + add_more_blank = can_add_more ? "[]" : "" + key_field = can_muti_lang_input? ? "[#{key}]" : "" + field_name = [get_field_name_base,add_more_blank,key_field].join + file_required =@require ? 'required="required"' : '' + "
#{value}".html_safe + end + end + def date_is_range? is_range = "false" data = get_data From b1f505d9d7a1484a7ad26011f1c02938b3ecf244 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=8D=9A=E4=BA=9E?= Date: Wed, 27 Sep 2023 23:03:40 +0800 Subject: [PATCH 4/6] set form multipart --- app/views/seminars/show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/seminars/show.html.erb b/app/views/seminars/show.html.erb index 87b6710..6808bed 100644 --- a/app/views/seminars/show.html.erb +++ b/app/views/seminars/show.html.erb @@ -53,7 +53,7 @@ margin: 0; } -<%= form_for @seminar_signup, url: seminars_path, html: {class: "content form-horizontal" , :id=>"new-seminar-signup"} do |f| %> +<%= form_for @seminar_signup, url: seminars_path, html: {class: "content form-horizontal" , :id=>"new-seminar-signup", multipart: true} do |f| %>
From 9e1af5e918704e311c1acc56280eddec847a0d73 Mon Sep 17 00:00:00 2001 From: BoHung Chiu Date: Thu, 28 Sep 2023 00:14:43 +0800 Subject: [PATCH 5/6] Fix bug. --- app/helpers/admin/seminars_field_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/admin/seminars_field_helper.rb b/app/helpers/admin/seminars_field_helper.rb index 3ae5e4f..21ffe5c 100644 --- a/app/helpers/admin/seminars_field_helper.rb +++ b/app/helpers/admin/seminars_field_helper.rb @@ -211,7 +211,7 @@ protected [I18n.locale]+(site.valid_locales-[I18n.locale]) end - def lang_panel_tabbable_wrapper(add_more_params,&block) + def lang_panel_tabbable_wrapper_for_sm(add_more_params,&block) add_more_counter = '' if self.markup=='text_area' #or self.markup=='address' @@ -324,7 +324,7 @@ protected end if can_muti_lang_input_for_sm? - result << lang_panel_tabbable_wrapper(add_more_params,&block) + result << lang_panel_tabbable_wrapper_for_sm(add_more_params,&block) result << gen_modal_dialog if self.markup == "address" # result << add_more_unt if can_add_more else #cross lang field From 228fcd87818472524e3896db8840f6d40cbb8d5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=8D=9A=E4=BA=9E?= Date: Thu, 28 Sep 2023 00:18:01 +0800 Subject: [PATCH 6/6] fix field error --- app/models/seminar_signup_field.rb | 3 ++- app/views/seminars/show_privacy.html.erb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/seminar_signup_field.rb b/app/models/seminar_signup_field.rb index 4f5ee8d..2025454 100644 --- a/app/models/seminar_signup_field.rb +++ b/app/models/seminar_signup_field.rb @@ -47,7 +47,8 @@ class SeminarSignupField end def locale - get_data["cross_lang"] == "true" ? false : true + tmp = get_data + !tmp || get_data["cross_lang"] == "true" ? false : true end def self_defined_markup_options? diff --git a/app/views/seminars/show_privacy.html.erb b/app/views/seminars/show_privacy.html.erb index e41ef30..bab1c61 100644 --- a/app/views/seminars/show_privacy.html.erb +++ b/app/views/seminars/show_privacy.html.erb @@ -19,7 +19,7 @@
-<%= @seminar_agreement.content.html_safe %> +<%= @seminar_agreement.content.html_safe rescue '' %>