From 6b1fa23265fcfe27775df009e719ff7ec27b65eb Mon Sep 17 00:00:00 2001 From: chiu Date: Tue, 19 Nov 2019 17:35:00 +0800 Subject: [PATCH 1/5] fix the problem that file being deleted by js in orbit4-5 --- app/views/admin/seminars/_form_file.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/seminars/_form_file.html.erb b/app/views/admin/seminars/_form_file.html.erb index 8628623..a1ab19a 100644 --- a/app/views/admin/seminars/_form_file.html.erb +++ b/app/views/admin/seminars/_form_file.html.erb @@ -1,7 +1,7 @@ <% if form_file.new_record? %>
<% else %> -
+
<% if form_file.file.blank? %> <%= t(:no_file) %> <% else %> From 454723887d9008c5f7f1ba22190be5c810d7ebcf Mon Sep 17 00:00:00 2001 From: chiu Date: Tue, 26 Nov 2019 23:52:52 +0800 Subject: [PATCH 2/5] add some feature and fix some problem for using for convinient --- .../javascripts/field-forms-submission.js | 494 ++++++++++++++++++ .../admin/seminar_signups_controller.rb | 2 +- app/controllers/admin/seminars_controller.rb | 111 +++- app/controllers/seminars_controller.rb | 75 ++- app/helpers/admin/seminars_field_helper.rb | 129 +++-- app/models/seminar_main.rb | 11 +- app/models/seminar_signup.rb | 4 +- app/models/seminar_signup_contribute.rb | 10 +- app/models/seminar_signup_field.rb | 1 + app/models/seminar_signup_field_custom.rb | 8 + app/models/seminar_signup_field_set.rb | 11 + app/models/seminar_signup_value.rb | 11 +- app/models/seminar_submission_field.rb | 186 +++++++ app/models/seminar_submission_field_set.rb | 11 + app/models/seminar_submission_value.rb | 212 ++++++++ app/views/admin/seminar_signups/edit.html.erb | 269 +++++----- .../_attribute_submission_field.html.erb | 132 +++++ app/views/admin/seminars/_form.html.erb | 108 +++- app/views/admin/seminars/_index.html.erb | 1 + .../admin/seminars/seminar_signup.html.erb | 192 ++++++- .../seminar_submission_field.html.erb | 36 ++ app/views/seminars/add_file.html.erb | 86 ++- app/views/seminars/check_email.html.erb | 2 +- app/views/seminars/con_upload.html.erb | 5 +- app/views/seminars/edit_file.html.erb | 92 +++- app/views/seminars/show.html.erb | 294 ++++++----- app/views/seminars/show_privacy.html.erb | 4 +- app/views/seminars/signup_ok.html.erb | 6 + config/locales/en.yml | 29 +- config/locales/zh_tw.yml | 26 +- config/routes.rb | 1 + seminar.gemspec | 33 +- 32 files changed, 2158 insertions(+), 434 deletions(-) create mode 100644 app/assets/javascripts/field-forms-submission.js create mode 100644 app/models/seminar_signup_field_custom.rb create mode 100644 app/models/seminar_signup_field_set.rb create mode 100644 app/models/seminar_submission_field.rb create mode 100644 app/models/seminar_submission_field_set.rb create mode 100644 app/models/seminar_submission_value.rb create mode 100644 app/views/admin/seminars/_attribute_submission_field.html.erb create mode 100644 app/views/admin/seminars/seminar_submission_field.html.erb diff --git a/app/assets/javascripts/field-forms-submission.js b/app/assets/javascripts/field-forms-submission.js new file mode 100644 index 0000000..c64b9fc --- /dev/null +++ b/app/assets/javascripts/field-forms-submission.js @@ -0,0 +1,494 @@ +// Retrieve the initial data +function temporary() { + attributesArray.length = 0; + $('.attributes').each(function() { + var attributesData = {}, + $selectType = $('.dataType').data().type; + + // Capture "attributes-body" within the input[type = "text"] val + $(this).find('.attributes-body').find('input[type="text"]').each(function(i) { + var $type = $(this).data().type; + attributesData[$type] = $(this).val(); + }); + + // Capture "attributes-body" within the input[type = "radio"] checked + $(this).find('.attributes-body').find('input[type="radio"]').each(function(i) { + var $type = $(this).data().type; + attributesData[$type] = $(this).prop("checked"); + }); + + // Capture "attributes-body" within the dataType selected + $(this).find('.attributes-body').find('.dataType').children("option:selected").each(function () { + attributesData[$selectType] = {}; + attributesData[$selectType].index = $(this).index(); + attributesData[$selectType].name = $(this).attr('ref'); + if($(this).attr('ref') == 'typeB' || $(this).attr('ref') == 'typeE' || $(this).attr('ref') == 'typeF') { + attributesData[$selectType].option = []; + } + }); + + // Capture "field-type" within the input[type = "text"] val + $(this).find('.field-type').find('input[type="text"]').each(function(i) { + var $type = $(this).data().type; + if(!$type.match('option_lang')) { + attributesData[$selectType][$type] = $(this).val(); + } + }); + + $(this).find('.field-type .add-target').find('.input-append').each(function() { + var append = [] + $(this).children('input[type="text"]').each(function() { + var val = $(this).val(); + append.push(val); + }); + attributesData[$selectType].option.push(append); + }) + + // Capture "field-type" within the input[type = "checkbox"] checked + $(this).find('.field-type').find('input[type="checkbox"]').each(function() { + var $type = $(this).data().type; + attributesData[$selectType][$type] = $(this).prop("checked"); + }); + + // Capture "field-type" within the input[type = "radio"] checked + $(this).find('.field-type').find('input[type="radio"]').each(function() { + var $type = $(this).data().type; + attributesData[$selectType][$type] = $(this).prop("checked"); + }); + + // Capture "field-type" within the dataType selected + $(this).find('.field-type').find('select').children("option:selected").each(function () { + attributesData[$selectType].dateFormat = $(this).index(); + }); + + attributesArray.push(attributesData); + }); +}; + +// Determine the Append input length +function inputAppendLength() { + $('.add-target').each(function(i) { + if($(this).children('.input-append:not(:hidden)').length == 1 || $(this).children('.input-append').length == 1) { + $(this).children('.input-append').each(function() { + if($(this).children('div').hasClass('tab-content')) { + var btnLength = $(this).children('.btn').length; + $(this).find('.btn').eq(btnLength-2).addClass('last'); + $(this).find('.remove-input').addClass('hide'); + } else { + var mediumLength = $(this).children('.input-medium').length; + $(this).children('.input-medium').eq(mediumLength-1).addClass('last'); + $(this).children('.remove-input').addClass('hide'); + } + }); + } else { + $(this).children('.input-append').each(function() { + if($(this).children('div').hasClass('tab-content')) { + $(this).find('.btn').removeClass('last'); + $(this).find('.remove-input').removeClass('hide'); + } else { + $(this).children('.input-medium').removeClass('last'); + $(this).children('.remove-input').removeClass('hide'); + } + }); + } + }); +}; + +// Role Attribute Template Data +function setData(l, type, ol) { + var fields = $('#info').length ? "info[seminar_submission_fields]" : $('#sub_seminar_main').length ? "sub_seminar_main[seminar_submission_fields]" : "seminar_main[seminar_submission_fields]", + data = { + _add_more: ["add_more_" +l, fields+"["+l+"]["+type+"][add_more]"], + _calendar: ["calendar_" +l, fields+"["+l+"]["+type+"][calendar]"], + _cross_lang: ["cross_lang_" +l, fields+"["+l+"]["+type+"][cross_lang]"], + _disabled: ["disabled_" +l, fields+"["+l+"][disabled]"], + _format: ["format_" +l, fields+"["+l+"]["+type+"][format]"], + _initial: ["initial_" +l, fields+"["+l+"]["+type+"][initial]"], + _is_range: ["is_range_" +l, fields+"["+l+"]["+type+"][is_range]"], + _key: ["key_" +l, fields+"["+l+"][key]"], + _markup: fields+"["+l+"][markup]", + _option_list: ["option_list_"+l+"_"+ol, fields+"["+l+"]["+type+"][option_list]["+ol+"]", "option_list_"+ol], + _placeholder: ["placeholder_" +l, fields+"["+l+"]["+type+"][placeholder]"], + _title_translations: ["title_translations_" +l, fields+"["+l+"][title_translations]"], + _to_delete: ["to_delete_" +l, fields+"["+l+"][to_delete]"], + _to_require: ["to_require_" +l, fields+"["+l+"][to_require]"], + }; + return data; +} + +// Get Default Address Form +function getAddressForm(trigger, element, decide) { + if(decide) { + addressVal.length = addressArray.length = 0; + var addressAllVal = []; + var inputNameArray = []; + trigger.closest('.input-append').find('.tab-pane').each(function() { + var adderssText = $(this).children('input[type="text"]').val(), + addersshidden = '', + addressData = {}, + inputName = []; + $(this).children('input:not(:first)').each(function(j) { + var name = $(this).attr('name'), + val = $(this).val(); + addersshidden += val; + addressData[name] = val; + inputName.push(name); + }); + addressArray.push(addressData); + addressAllVal.push(adderssText); + inputNameArray.push(inputName); + if(adderssText != addersshidden) { + addressVal.push(false); + } else { + addressVal.push(true); + } + }); + element.find('.tab-pane').each(function(i) { + $(this).find('textarea, input[type="text"]').each(function(j) { + $(this).attr('name',inputNameArray[i][j]); + }); + if(addressVal[i]) { + $(this).find('textarea, input[type="text"]').each(function(j) { + $(this).val(addressArray[i][$(this).attr('name')]); + }); + } else { + $(this).find('textarea').val(addressAllVal[i]); + $(this).find('input[type="text"]').each(function(j) { + $(this).val(''); + }); + } + }); + }; + element.off('show'); +}; + +// Return Address Form +function returnAddressForm(element, decide) { + if(decide) { + addressArray.length = 0; + element.find('.tab-pane').each(function(i) { + var addressData = {}; + $(this).find('textarea, input[type="text"]').each(function(j) { + var name = $(this).attr('name'), + val = $(this).val(); + addressData[name] = val; + }); + addressArray.push(addressData); + }); + $.map(addressInputId, function(n, i) { + var v = ''; + $('#'+n).find('input[type="hidden"]').each(function() { + $(this).val(addressArray[i][$(this).attr('name')]); + v += addressArray[i][$(this).attr('name')] + }); + $('#'+n).find('input[type="text"]').each(function() { + $(this).val(v); + }); + }); + }; + returnDecide = false; +}; + +$(function() { + appendIndex = null; + if($('#user-forms').length) { + addressVal = []; + addressArray = []; + addressInputId = []; + seminar_mainType = null; + returnDecide = false; + $('.attributes').each(function() { + if($(this).find('.toggle-check').attr('value') == "true") { + $(this).addClass('disabled').children('.attributes-body').hide(); + } + }); + $('.returnDecide').on(clickEvent, function() { + returnDecide = true; + }) + $('#address-field').on('hidden', function () { + $('.btn[data-toggle="modal"]').removeClass('active').blur(); + $(this).find('.nav-tabs > li').removeClass('active').eq(0).addClass('active'); + $(this).find('.tab-content > .tab-pane').removeClass('active in').eq(0).addClass('active in'); + $(this).on('show', getAddressForm(null, $(this), false)); + returnAddressForm($(this), returnDecide) + }); + $('.control-group').delegate('.btn[data-toggle="modal"]', 'click', function() { + var $trigger = $(this); + addressInputId.length = 0; + $(this).closest('.input-append').find('.tab-pane').each(function() { + addressInputId.push($(this).attr('id')); + }); + $('#address-field').on('show', getAddressForm($trigger, $('#address-field'), true)); + }); + $('#user-forms').delegate('.togglebox, .delete, .trigger, .remove-input', clickEvent, function(event) { + if($(this).hasClass('togglebox')) { + var seminar_main_staus = []; + if($(this).hasClass('disable')) { + $(this).find('.toggle-check') + .attr('value', 'false') + .closest('.attributes') + .removeClass('disabled') + .children('.attributes-body') + .fadeIn(300); + } else { + $(this).find('.toggle-check') + .attr('value', 'true') + .closest('.attributes') + .addClass('disabled') + .children('.attributes-body') + .fadeOut(300) + .find('.check') + .attr("checked",false) + .attr("value",seminar_main_staus); + } + $(this).toggleClass('disable'); + }; + if($(this).hasClass('remove-input')) { + $(this).closest('.input-append').fadeOut(300, function() { + $(this).remove(); + inputAppendLength(); + }); + }; + if($(this).hasClass('trigger')) { + appendIndex = $(this).closest('.controls').find('.input-append').length; + nameNumber = $(this).closest('.controls').find('.input-append:eq(0)').find('input').eq(0).attr('name'); + nameNumber = nameNumber.match(/[^[\D\]]+(?=])/g)[0]; + seminar_mainType = $(this).data('seminar_mains') + if($(this).hasClass('textInput')) { + $("#template-text").tmpl().appendTo($(this).closest('.controls').find('.add-target')); + } else if ($(this).hasClass('textLengInput')) { + $("#template-text-language").tmpl().appendTo($(this).closest('.controls').find('.add-target')); + } else if ($(this).hasClass('address')) { + $("#template-address").tmpl().appendTo($(this).closest('.controls').find('.add-target')); + } + inputAppendLength(); + }; + event.preventDefault(); + }); + inputAppendLength(); + } else { + attributesArray = []; + attributesHeaderLength = null; + templateType = null; + attributeIndex = null; + if($('.add-target').length) { + inputAppendLength(); + } + if(!$('.attributes').length) { + $('#attributes-area').addClass('clickHere'); + } else { + temporary(); + }; + + $('.add-attributes').on(clickEvent, function() { + if($('#attributes-area').hasClass('clickHere')) { + $('#attributes-area').removeClass('clickHere'); + }; + attributesHeaderLength = $('.attributes:not(:hidden)').length+1; + attributesLength = $('#attributes-area .attributes').length; + $("#template-attributes").tmpl(setData(attributesLength, templateType, appendIndex)).appendTo( "#attributes-area" ); + $('.toggle-check').togglebox(); + }); + + + + $('.attributes.default').each(function(i) { + $(this).children('.field-type').not('.default').hide(); + $(this).find('input[type="text"]').on('keyup', function() { + $(this).trigger("checking"); + }); + $(this).find('input[type="radio"], input[type="checkbox"], select').change(function() { + $(this).trigger("checking"); + }); + $(this).delegate('input[type="text"], input[type="radio"], input[type="checkbox"], select', 'checking', function(e) { + var e = e.target.type, + $data = $(this).data().type; + switch(e) { + case 'text': + var val = $(this).val(); + if(!$(this).closest('.field-type').length) { + $data = attributesArray[i][$data]; + } else if(!$(this).closest('.add-target').length) { + $data = attributesArray[i].select[$data]; + } else { + appendIndex = $(this).parent('.input-append').index() + optionIndex = $(this).index() + $data = attributesArray[i].select.option[appendIndex][optionIndex]; + } + if(val != $data) { + $(this).closest('.attributes').find('.reply').removeClass('hide'); + } + break; + case 'radio': + var checked = $(this).prop("checked"); + $data = attributesArray[i][$data]; + if(checked != $data) { + $(this).closest('.attributes').find('.reply').removeClass('hide'); + } + break; + case 'checkbox': + var checked = $(this).prop("checked"); + $data = attributesArray[i].select[$data]; + if(checked != $data) { + $(this).closest('.attributes').find('.reply').removeClass('hide'); + } + break; + case 'select-one': + var ref, + $data = attributesArray[i].select.name; + $(this).children("option:selected").each(function() { + ref = $(this).attr('ref'); + }); + if(ref != $data) { + $(this).closest('.attributes').find('.reply').removeClass('hide'); + } + break; + }; + }); + $(this).delegate('.reply', clickEvent, function() { + var $bodyText = $(this).parent('.attributes-header').siblings('.attributes-body').find('input[type="text"]'), + $bodyRadio = $(this).parent('.attributes-header').siblings('.attributes-body').find('input[type="radio"]'), + $bodySelected = $(this).parent('.attributes-header').siblings('.attributes-body').find('.dataType').children("option"), + $fieldTypeO = $(this).parent('.attributes-header').siblings('.field-type.default'), + $fieldTypeN = $(this).parent('.attributes-header').siblings('.field-type').not('.default'); + $bodyText.each(function() { + var $type = $(this).data().type; + $(this).val(attributesArray[i][$type]); + }); + $bodyRadio.each(function() { + var $type = $(this).data().type; + $(this).prop("checked", attributesArray[i][$type]) + }); + $fieldTypeO.find('input[type="text"]').each(function() { + var $type = $(this).data().type; + if(!$type.match('option_lang')) { + $(this).val(attributesArray[i].select[$type]); + } + }); + $fieldTypeO.find('.add-target').find('.input-append').each(function(k) { + $(this).children('input[type="text"]').each(function(j) { + $(this).val(attributesArray[i].select.option[k][j]); + // var val = $(this).val(); + // append.push(val); + }); + }) + $fieldTypeO.find('input[type="checkbox"], input[type="radio"]').each(function() { + var $type = $(this).data().type; + $(this).prop("checked", attributesArray[i].select[$type]); + }); + $fieldTypeO.find('select').children("option").eq(attributesArray[i].select.dateFormat).prop('selected',true); + $bodySelected.eq(attributesArray[i].select.index).prop('selected',true); + $fieldTypeO.show(); + $fieldTypeN.empty().hide(); + $(this).addClass('hide') + return false + }) + }); + $('#attributes-area').delegate('.togglebox, .delete, .trigger, .remove-input', clickEvent, function(event) { + if($(this).hasClass('togglebox')) { + if($(this).hasClass('disable')) { + $(this).find('.toggle-check') + .attr('value', 'false') + .closest('.attributes') + .removeClass('disabled') + .find('input, select') + .removeAttr('disabled') + .end('.attributes') + .find('.btn-group .btn') + .removeClass('disabled') + .end().find('.attribute_field_disabled').attr('value', 'false'); + if($(this).closest('.attributes').find('.dataType').children("option:selected").attr('ref')) { + $(this).closest('.attributes').find('.field-type').addClass('in').find('.control-group').delay(150).fadeIn(300); + } + } else { + $(this).find('.toggle-check') + .attr('value', 'true') + .closest('.attributes') + .addClass('disabled') + .find('.attributes-body input, .attributes-body select') + .attr({'disabled': 'disabled'}) + .end('.attributes') + .find('.btn-group .btn') + .addClass('disabled') + .end().find('.attribute_field_disabled').attr('value', 'true') + .end().find('.field-type .control-group').fadeOut(300, function() { + $(this).parent('.field-type').removeClass('in'); + }); + } + $(this).toggleClass('disable'); + }; + if($(this).hasClass('delete')) { + $(this).closest('.attributes').fadeOut(300, function() { + $('.attributes:not(:hidden)').each(function(i) { + $(this).find('.attributes-header h4 span').text(i+1); + }); + attributesHeaderLength = $('.attributes:not(:hidden)').length+1; + if(!$('.attributes:not(:hidden)').length) { + $('#attributes-area').addClass('clickHere'); + }; + }).find('.attribute_field_to_delete').attr('value', 'true');; + }; + if($(this).hasClass('trigger')) { + // appendIndex = $(this).closest('.controls').find('.input-append').length; + appendIndex = $(this).closest('.controls').find('.input-append:last-child').children('input:first-child').attr('name'); + // appendIndex = appendIndex.split("]["); + // appendIndex = parseInt(appendIndex[appendIndex.length-2])+1; + appendIndex = parseInt(appendIndex.match(/[^[\D\]]+(?=])/g)[1])+1; + console.log(appendIndex) + attributeIndex = $(this).closest('.attributes').index(); + templateType = $(this).closest('.attributes').find('.dataType').children("option:selected").attr('ref'); + $("#template-input-append").tmpl(setData(attributeIndex, templateType, appendIndex)).appendTo($(this).closest('.controls').find('.add-target')); + inputAppendLength(); + }; + if($(this).hasClass('remove-input')) { + $(this).parent('.input-append').fadeOut(300, function() { + $(this).remove() + inputAppendLength(); + }); + + } + event.preventDefault(); + }); + $('#attributes-area').delegate('.dataType', 'change', function() { + $(this).children("option:selected").each(function () { + var target = $(this).closest('.attributes').find('.field-type').not('.default'); + attributeIndex = $(this).closest('.attributes').index(); + appendIndex = 0 + // $(this).closest('.attributes').find('.add-target').find('.input-append').length; + if($(this).closest('.attributes').hasClass('default')){ + var i = $(this).closest('.attributes').index() + if($(this).attr('ref') == attributesArray[i].select.name) { + $(this).closest('.attributes').find('.field-type.default').show() + target.empty().hide(); + } else { + $(this).closest('.attributes').find('.field-type.default').hide() + if($(this).attr('ref')) { + templateType = $(this).attr('ref'); + target.removeAttr('class').addClass('field-type fade in ' + templateType).empty(); + $("#template-type").tmpl(setData(attributeIndex, templateType, appendIndex)).appendTo(target); + if(templateType == 'typeB' || templateType == 'typeE' || templateType == 'typeF') { + inputAppendLength(); + } + } else { + target.removeAttr('class').addClass('field-type fade') + target.empty(); + }; + target.show(); + } + } else { + if($(this).attr('ref')) { + templateType = $(this).attr('ref'); + target.removeAttr('class').addClass('field-type fade in ' + templateType).empty(); + $("#template-type").tmpl(setData(attributeIndex, templateType, appendIndex)).appendTo(target); + if(templateType == 'typeB' || templateType == 'typeE' || templateType == 'typeF') { + inputAppendLength(); + } + } else { + target.removeAttr('class').addClass('field-type fade') + target.empty(); + }; + } + }); + }); + } +}); \ No newline at end of file diff --git a/app/controllers/admin/seminar_signups_controller.rb b/app/controllers/admin/seminar_signups_controller.rb index 792341d..5f1e989 100644 --- a/app/controllers/admin/seminar_signups_controller.rb +++ b/app/controllers/admin/seminar_signups_controller.rb @@ -9,7 +9,7 @@ class Admin::SeminarSignupsController < OrbitAdminController end def edit - + OrbitHelper.set_params(params,current_user) params[:controller] = "admin/seminars" @seminar_signup = SeminarSignup.find(params[:id]) diff --git a/app/controllers/admin/seminars_controller.rb b/app/controllers/admin/seminars_controller.rb index d95ad02..619ad7e 100644 --- a/app/controllers/admin/seminars_controller.rb +++ b/app/controllers/admin/seminars_controller.rb @@ -2,7 +2,7 @@ class Admin::SeminarsController < OrbitAdminController require 'axlsx' - + helper Admin::SeminarsFieldHelper before_action ->(module_app = @app_title) { set_variables module_app } before_action :set_seminar, only: [:edit, :set_write_off, :seminar_signup, :destroy] @@ -60,6 +60,10 @@ class Admin::SeminarsController < OrbitAdminController def new @member = nil @seminar = SeminarMain.new + create_set + @signup_sets = @seminar.seminar_signup_field_sets + @submission_set = @seminar.seminar_submission_field_sets + @custom_set = @seminar.seminar_signup_field_customs @seminar_items = SeminarItem.all @review = @seminar.seminar_reviews.new() end @@ -85,11 +89,30 @@ class Admin::SeminarsController < OrbitAdminController def edit @seminar_items = SeminarItem.all - attribute = SeminarMain.where(id: params[:id]) - if attribute.first.seminar_reviews.first.nil? - @review = attribute.first.seminar_reviews.new() + @seminar = SeminarMain.where(id: params[:id]).first + @seminar.seminar_signup_field_sets.each do |signup_field_set| + if !(SeminarSignup.attribute_names.include? signup_field_set.field_name) && signup_field_set.field_name != 'recaptcha' + signup_field_set.delete + end + end + @seminar.seminar_submission_field_sets.each do |submission_field_set| + if !(SeminarSignupContribute.attribute_names.include? submission_field_set.field_name) + submission_field_set.delete + end + end + @seminar.seminar_signup_field_customs.each do |custom_set| + if !(@seminar.seminar_signup_fields.collect(&:id).include? custom_set.seminar_signup_field_id) + custom_set.delete + end + end + create_set + @signup_sets = @seminar.seminar_signup_field_sets + @submission_set = @seminar.seminar_submission_field_sets + @custom_set = @seminar.seminar_signup_field_customs + if @seminar.seminar_reviews.first.nil? + @review = @seminar.seminar_reviews.new() else - @review = attribute.first.seminar_reviews.first + @review = @seminar.seminar_reviews.first end @member = MemberProfile.find(@review.reviewer_id) rescue nil end @@ -113,7 +136,17 @@ class Admin::SeminarsController < OrbitAdminController @seminar.seminar_signup_fields.each{|t| t.destroy if t["to_delete"] == true} redirect_to admin_seminars_path + elsif params[:seminar_main][:seminar_submission_fields] + params[:seminar_main][:seminar_submission_fields].each do |a| + @field_name = 'seminar_main' + field_status = a.last[:id].present? + @attribute_field = SeminarSubmissionField.add_seminar_signup_field(@seminar, a.last, a.last[:id], field_status) + @attribute = @seminar + end + flash.now[:notice] = "Updated Fields" + @seminar.seminar_submission_fields.each{|t| t.destroy if t["to_delete"] == true} + redirect_to admin_seminars_path else if !seminar_params['seminar_links_attributes'].nil? @@ -123,7 +156,6 @@ class Admin::SeminarsController < OrbitAdminController end @seminar.update_user_id = current_user.id - if @seminar.update_attributes(seminar_params) @seminar.seminar_signup_fields.each{|t| t.destroy if t["to_delete"] == true} redirect_to params['referer_url'] @@ -158,6 +190,13 @@ class Admin::SeminarsController < OrbitAdminController @class = 'seminars' end + def seminar_submission_field + @field_name = 'seminar_main' + @attribute = SeminarMain.find(params[:id]) + @attribute_type = 'seminar' + @class = 'seminars' + end + def seminar_signup if !params[:search].blank? @@ -193,5 +232,63 @@ class Admin::SeminarsController < OrbitAdminController def seminar_params params.require(:seminar_main).permit! end - + def create_set + SeminarSignup.attribute_names.each do |attr_signup| + if !(['_id', 'created_at', 'updated_at','seminar_main_id'].include? attr_signup) + signup_set = @seminar.seminar_signup_field_sets.select{|v| v.field_name==attr_signup } + if signup_set.length==0 + if ['status','name','tel','phone','email','password'].include? attr_signup + disabled = false + else + disabled = true + end + if ['status','name','tel'].include? attr_signup + hidden = false + else + hidden = true + end + name1 = Hash.new + now_locale = I18n.locale + I18n.available_locales.each do |locale| + I18n.locale = locale + name1[locale] = t("seminar_signup.#{attr_signup}") + end + I18n.locale = now_locale + @seminar.seminar_signup_field_sets.create(field_name:attr_signup,disabled:disabled,hidden:hidden,name:name1,placeholder:name1) + end + end + end + signup_set = @seminar.seminar_signup_field_sets.select{|v| v.field_name== 'recaptcha' } + if signup_set.length==0 + name1 = Hash.new + now_locale = I18n.locale + I18n.available_locales.each do |locale| + I18n.locale = locale + name1[locale] = t("seminar_signup.recaptcha") + end + I18n.locale = now_locale + @seminar.seminar_signup_field_sets.create(field_name:'recaptcha',name:name1,placeholder:name1,hidden:true) + end + SeminarSignupContribute.attribute_names.each do |attr_submission| + if !(['_id', 'created_at', 'updated_at','seminar_signup_id'].include? attr_submission) + signup_set = @seminar.seminar_submission_field_sets.select{|v| v.field_name==attr_submission } + if signup_set.length==0 + name1 = Hash.new + now_locale = I18n.locale + I18n.available_locales.each do |locale| + I18n.locale = locale + name1[locale] = t("seminar_signup.#{attr_submission}") + end + I18n.locale = now_locale + @seminar.seminar_submission_field_sets.create(field_name:attr_submission,name:name1,placeholder:name1) + end + end + end + @seminar.seminar_signup_fields.all.map{|v| v}.each do |field| + set = @seminar.seminar_signup_field_customs.select{|v| v.seminar_signup_field_id==field.id} + if set.length == 0 + @seminar.seminar_signup_field_customs.create(seminar_signup_field_id:field.id) + end + end + end end diff --git a/app/controllers/seminars_controller.rb b/app/controllers/seminars_controller.rb index baf931f..03a4cbe 100644 --- a/app/controllers/seminars_controller.rb +++ b/app/controllers/seminars_controller.rb @@ -105,9 +105,9 @@ class SeminarsController < ApplicationController if !params[:email].blank? count = SeminarSignup.where(:email => params[:email], :seminar_main_id => params[:no]).count - result = count > 0 ? '已存在' : '可使用' + result = count > 0 ? t('seminar.already_used') : t('seminar.available') else - result = '請輸入email' + result = t('seminar.please_enter_email') end { @@ -134,7 +134,7 @@ class SeminarsController < ApplicationController @signup = SeminarSignup.where(email: params[:seminar_signup][:email], seminar_main_id: params[:seminar_signup][:seminar_main_id] ).first @seminar_signup = SeminarSignup.new(seminar_signup_params) - if gotcha_valid? + #if gotcha_valid? if @signup.blank? && @seminar_signup.save # if gotcha_valid? && @seminar_signup.save @@ -144,8 +144,12 @@ class SeminarsController < ApplicationController @custom_field_value = SeminarSignupValue.put_field_values(@seminar_signup, r.last, r.last[:seminar_signup_field_id], field_value) end end - - redirect_to "#{params[:referer_url]}/?method=signup_ok" + if params['seminar_signup']['status']=='C' + status_param = '&status=' + else + status_param = '' + end + redirect_to "#{params[:referer_url]}/?method=signup_ok#{status_param}" else if !@signup.blank? redirect_to "#{params[:referer_url]}", :notice => 'mail已存在' @@ -153,9 +157,9 @@ class SeminarsController < ApplicationController redirect_to "#{params[:referer_url]}", :notice => t('recaptcha.errors.verification_failed') end end - else - redirect_to "#{params[:referer_url]}", :notice => t('recaptcha.errors.verification_failed') - end + #else + # redirect_to "#{params[:referer_url]}", :notice => t('recaptcha.errors.verification_failed') + #end end @@ -164,8 +168,18 @@ class SeminarsController < ApplicationController def add_file_proc - @con = SeminarSignupContribute.new(seminar_signup_contribute_params) - + update_params = seminar_signup_contribute_params.merge('seminar_submission_values'=>params['seminar_submission_values']) + flag = true + update_params.permit! + update_params['seminar_submission_values']['0']['value'].each do |key,value| + if !value.to_s.blank? + flag = false + end + end + if flag + update_params['seminar_submission_values']['0']['value']['en'] = ' ' + end + @con = SeminarSignupContribute.new(update_params) if @con.save redirect_to "#{params[:referer_url]}/?method=con_upload" @@ -176,12 +190,28 @@ class SeminarsController < ApplicationController end def update - @con = SeminarSignupContribute.find(params[:seminar_signup_contribute][:id]) - @con.update_attributes(seminar_signup_contribute_params) - + update_params = seminar_signup_contribute_params.merge('seminar_submission_values'=>params['seminar_submission_values']) + flag = true + update_params.permit! + if update_params['seminar_submission_values']['0']['value'].class==String + value = update_params['seminar_submission_values']['0']['value'] + if !value.to_s.blank? + flag = false + end + else + update_params['seminar_submission_values']['0']['value'].each do |key,value| + if !value.to_s.blank? + flag = false + end + end + end + + if flag + update_params['seminar_submission_values']['0']['value']['en'] = ' ' + end + @con.update_attributes(update_params) if @con.save - redirect_to "#{params[:referer_url]}/?method=con_upload" else redirect_to "#{params[:referer_url]}", :notice => t('recaptcha.errors.verification_failed') @@ -207,7 +237,6 @@ class SeminarsController < ApplicationController if !@@session[:seminar_main_id].blank? seminar = SeminarMain.find_by(id: @@session[:seminar_main_id]) - seminar_signup = SeminarSignup.find_by(_id: @@session[:seminar_signup_id], seminar_main_id: @@session[:seminar_main_id] ) else @@ -230,11 +259,19 @@ class SeminarsController < ApplicationController def edit_file params = OrbitHelper.params - + if !@@session[:seminar_main_id].blank? + seminar = SeminarMain.find_by(id: @@session[:seminar_main_id]) + seminar_signup = SeminarSignup.find_by(_id: @@session[:seminar_signup_id], seminar_main_id: @@session[:seminar_main_id] ) + else + seminar = {} + seminar_signup = {} + end con = SeminarSignupContribute.find(params[:con_no]) - + puts ['con',con.inspect] { - 'con' => con + 'con' => con, + 'seminar' => seminar, + 'seminar_signup' => seminar_signup } end @@ -315,4 +352,4 @@ class SeminarsController < ApplicationController params.require(:seminar_signup_values).permit! end -end \ No newline at end of file +end diff --git a/app/helpers/admin/seminars_field_helper.rb b/app/helpers/admin/seminars_field_helper.rb index 9c0eb8d..48d0afe 100644 --- a/app/helpers/admin/seminars_field_helper.rb +++ b/app/helpers/admin/seminars_field_helper.rb @@ -52,8 +52,8 @@ module Admin::SeminarsFieldHelper @prefiled_value ||=[] control_group_wrapper do a = self.typeE[:option_list].collect do |key,value| - label_tag(key,check_box_tag(get_field_name_base+"[#{key}]", true , (@prefiled_value.include?(key) ? true : false), { :id=>"seminar_signup_values_#{self.id}"})+value[I18n.locale.to_s],@markup_options.merge(:class=>"checkbox inline")) - end.join rescue "" + label_tag(key,check_box_tag(get_field_name_base+"[#{key}]", true , (@prefiled_value.include?(key) ? true : false), { :id=>"#{get_basic_field_name_org}_#{self.id}"})+value[I18n.locale.to_s],@markup_options.merge(:class=>"checkbox inline")) + end.join.html_safe rescue "" end end @@ -139,7 +139,7 @@ module Admin::SeminarsFieldHelper control_group_wrapper do self.typeE[:option_list].collect do |key,value| label_tag(key,radio_button_tag(get_field_name_base, key , (@prefiled_value.include?(key) ? true : false), {:required=>@require})+value[I18n.locale.to_s],@markup_options.merge(:class=>"radio inline")) - end.join + end.join.html_safe end end @@ -151,19 +151,25 @@ module Admin::SeminarsFieldHelper def render_text_area control_group_wrapper do |key,value| - value = can_muti_lang_input? ? @prefiled_value[key] : @prefiled_value - key = can_muti_lang_input? ? "[#{key}]" : "" - place_holder= @panel_setting["placeholder"][I18n.locale.to_s] rescue '' - text_area_tag(get_field_name_base + key, value,@markup_options.merge(:placeholder=>place_holder)) + if !@prefiled_value.nil? + value = can_muti_lang_input? ? @prefiled_value[key] : @prefiled_value + else + value = nil + end + key = can_muti_lang_input? ? "#{key}" : I18n.locale + place_holder= typeD["placeholder"][key] rescue '' + name1 = can_muti_lang_input? ? (get_field_name_base + "[#{key}]") : get_field_name_base + text_area_tag(name1, value,@markup_options.merge(:placeholder=>place_holder,:class=>'ckeditor input-medium form-control')) end end def render_text_field a = control_group_wrapper do |key,value| add_more_blank = can_add_more ? "[]" : "" - key_field = can_muti_lang_input? ? "[#{key}]" : "" - place_holder= @panel_setting["placeholder"][key] rescue '' - text_field_tag([get_field_name_base,add_more_blank,key_field].join, value,@markup_options.merge(:placeholder=>place_holder)) + key_field = can_muti_lang_input? ? "#{key}" : I18n.locale + place_holder= typeA["placeholder"][key_field] rescue '' + name1 = can_muti_lang_input? ? ([get_field_name_base,add_more_blank,"[#{key_field}]"].join) : ([get_field_name_base,add_more_blank].join) + text_field_tag(name1, value,@markup_options.merge(:placeholder=>place_holder,:class=>'input-medium form-control')) end end @@ -186,15 +192,17 @@ protected def lang_panel_tabbable_wrapper(add_more_params,&block) add_more_counter = '' - if self.markup=='text_area' #or self.markup=='address' - + if self.markup=='text_area' #or self.markup=='address' tmp1 = valid_locales.collect do |key| - value = @prefiled_value[key] rescue nil + if !@prefiled_value.nil? + value = @prefiled_value[key] rescue nil + else + value = nil + end # div_class_ary = ["tab-pane" ,"fade","#{get_pairing_tab_class({})}_#{key}"] div_class_ary = ["tab-pane" ,"fade"] div_id = "#{get_pairing_tab_class({})}_#{key}" - if can_add_more add_more_value = add_more_params[0][:value] add_more_counter = add_more_params[0][:counter] @@ -206,8 +214,6 @@ protected div_class << (key == I18n.locale ? " active in" : '') content_tag(:div,yield(key,value), :id=>div_id,:class=>div_class) end# of VALID_LOCALES.collect for tabed input - - tmp2 = content_tag(:div,:class => 'btn-group', :data=>{:toggle=>"buttons-radio"}) do buff2 = valid_locales.each.collect do |key| # link_entry = self.add_more ? "#{add_more_tab(:tab_btn,loop_counter,key)}" : "#tab"+id.to_s+"_#{key}" @@ -221,12 +227,9 @@ protected buff2 << link_to((content_tag :i,'',:class=>'icon-trash'),"#",:class=>"btn remove-input") if self.add_more buff2.join.html_safe end # of content ul - - tmp = content_tag :div,:class=> "tab-content textarea-lang" do tmp2 << tmp1.join('').html_safe end - else # tmp = content_tag :div,:class=> (add_more || self.markup=='address') ? "input-append" : "tab-content" do @@ -283,7 +286,7 @@ protected def controls_wrapper(*add_more_params,&block) - result = '' + result = Array.new add_more_counter = "" if can_add_more @@ -296,7 +299,6 @@ protected if can_muti_lang_input? result << lang_panel_tabbable_wrapper(add_more_params,&block) result << gen_modal_dialog if self.markup == "address" - # result << add_more_unt if can_add_more else #cross lang field @@ -312,15 +314,18 @@ protected end - - result.html_safe + if self.markup == "address" + result + else + result[0] + end end # of def controls_wrapper(&block) def control_group_wrapper(&block) div_class = can_muti_lang_input? ? "col-sm-10 controls" : "col-sm-10 controls" # div_class = can_muti_lang_input? ? "control-group language-swich" : "control-group" - result ="" + result = "" case self.markup @@ -343,8 +348,7 @@ protected # result = label + multipleInputs + add_more_unt # result = label + 一堆的輸入框(要用 multipleInput editMore 包起來) + add_more btn + hidden_fields else - result = form_label + content_tag(:div,controls_wrapper(&block),:class=>div_class) - + result = form_label + content_tag(:div,controls_wrapper(&block),:class=>div_class) end when "address" @@ -357,11 +361,9 @@ protected result = address else - result = form_label + content_tag(:div,controls_wrapper(&block),:class=>div_class) - + result = form_label + content_tag(:div,controls_wrapper(&block),:class=>div_class) end - - result << end_block + result = result + end_block result.html_safe end @@ -387,7 +389,7 @@ protected def end_block if @new_attribute - hidden_field_tag(get_basic_field_name_base+"[seminar_signup_field_id]",id,:for=>"field_#{@index}") + hidden_field_tag(get_basic_field_name_base+"[#{get_basic_field_name}_id]",id,:for=>"field_#{@index}") else hidden_field_tag(get_basic_field_name_base+"[id]",@attribute_value.id,:for=>"field_#{@index}") end @@ -410,8 +412,16 @@ protected suffix.nil? ? str : str + suffix end + def get_basic_field_name_org + "seminar_signup_values" + end + + def get_basic_field_name + "seminar_signup_field" + end + def get_basic_field_name_base - "seminar_signup_values[#{@index}]" + "#{get_basic_field_name_org}[#{@index}]" end def get_field_name_base @@ -419,7 +429,14 @@ protected end def form_label - label_tag(key,(!@require.blank? ? '*'+title : title),:class=>"col-sm-2 control-label muted") + if self.markup == "text_area" + plc = typeD["placeholder"][I18n.locale].to_s.blank? ? '' : "(#{typeD["placeholder"][I18n.locale]})" + ""+ + label_tag(key,(!@require.blank? ? '*'+title : title),:class=>"col-sm-2 control-label muted",:style =>'display: contents;')+ + tag(:br)+"#{plc}" + else + label_tag(key,(!@require.blank? ? '*'+title : title),:class=>"col-sm-2 control-label muted") + end end def can_muti_lang_input? @@ -447,5 +464,49 @@ protected } ) end - + def show_set_field(field_sets,key_field,key_index,field) + def self.can_muti_lang_input? + true + end + def self.can_add_more + false + end + def self.markup + 'text_field' + end + def self.add_more + false + end + @new_attribute = false + @key_index = key_index + def self.key + @key_index + end + def self.form_label + '' + end + def self.end_block + hidden_field_tag("seminar_main[#{@key_field}][#{@key_index}]"+"[id]",@attribute_value.id,:for=>"field_#{@key_index}") + end + @key_field = key_field + @field = field + def self.get_basic_field_name_base + "seminar_main[#{@key_field}][#{@key_index}][#{@field}]" + end + def self.get_field_name_base + "seminar_main[#{@key_field}][#{@key_index}][#{@field}]" + end + @attribute_value = field_sets + @prefiled_value = field_sets[field] + a = content_tag(:span,:class => 'btn-group') do + control_group_wrapper do |key,value| + add_more_blank = "" + text_field_tag([get_field_name_base,"[#{key}]"].join,value) + end + end + @key_field = nil + @key_index = nil + @field = nil + return a.html_safe + end end \ No newline at end of file diff --git a/app/models/seminar_main.rb b/app/models/seminar_main.rb index c9badcc..5342a47 100644 --- a/app/models/seminar_main.rb +++ b/app/models/seminar_main.rb @@ -34,17 +34,22 @@ class SeminarMain has_many :seminar_files, :autosave => true, :dependent => :destroy has_many :seminar_item_contents, :autosave => true, :dependent => :destroy has_many :seminar_signups, :autosave => true, :dependent => :destroy + has_many :seminar_submission_fields, :autosave => true, :dependent => :destroy has_many :seminar_signup_fields, :autosave => true, :dependent => :destroy has_many :seminar_reviews, :autosave => true, :dependent => :destroy - + has_many :seminar_signup_field_sets, autosave: true, dependent: :destroy + has_many :seminar_submission_field_sets, autosave: true, dependent: :destroy + has_many :seminar_signup_field_customs, :autosave => true, :dependent => :destroy accepts_nested_attributes_for :seminar_links, :allow_destroy => true accepts_nested_attributes_for :seminar_files, :allow_destroy => true accepts_nested_attributes_for :seminar_item_contents, :allow_destroy => true accepts_nested_attributes_for :seminar_signups, :allow_destroy => true + accepts_nested_attributes_for :seminar_submission_fields, :allow_destroy => true accepts_nested_attributes_for :seminar_signup_fields, :allow_destroy => true accepts_nested_attributes_for :seminar_reviews, :allow_destroy => true - - + accepts_nested_attributes_for :seminar_signup_field_sets, :allow_destroy => true + accepts_nested_attributes_for :seminar_submission_field_sets, :allow_destroy => true + accepts_nested_attributes_for :seminar_signup_field_customs, :allow_destroy => true def self.time_range(date1 = null, date2 = null) if !date1.blank? diff --git a/app/models/seminar_signup.rb b/app/models/seminar_signup.rb index 983f365..9f40877 100644 --- a/app/models/seminar_signup.rb +++ b/app/models/seminar_signup.rb @@ -5,9 +5,9 @@ class SeminarSignup include Mongoid::Timestamps field :status - field :name + field :name # become Last Name for TICC + field :tel, type: String # become First Name for TICC field :unit, localize: true - field :tel, type: String field :phone, type: String field :fax, type: String field :email, type: String diff --git a/app/models/seminar_signup_contribute.rb b/app/models/seminar_signup_contribute.rb index 1174cd3..bae17c3 100644 --- a/app/models/seminar_signup_contribute.rb +++ b/app/models/seminar_signup_contribute.rb @@ -3,12 +3,10 @@ class SeminarSignupContribute include Mongoid::Document include Mongoid::Timestamps - mount_uploader :file, AssetUploader - - field :description field :title - - + field :description + mount_uploader :file, AssetUploader belongs_to :seminar_signup - + has_many :seminar_submission_values, autosave: true, dependent: :destroy + accepts_nested_attributes_for :seminar_submission_values, :allow_destroy => true end \ No newline at end of file diff --git a/app/models/seminar_signup_field.rb b/app/models/seminar_signup_field.rb index cce01b9..ca6c3fb 100644 --- a/app/models/seminar_signup_field.rb +++ b/app/models/seminar_signup_field.rb @@ -25,6 +25,7 @@ class SeminarSignupField belongs_to :seminar_main has_many :seminar_signup_values, autosave: true, dependent: :destroy + accepts_nested_attributes_for :seminar_signup_values, :allow_destroy => true before_save :check_option_list def markup_value diff --git a/app/models/seminar_signup_field_custom.rb b/app/models/seminar_signup_field_custom.rb new file mode 100644 index 0000000..ac322db --- /dev/null +++ b/app/models/seminar_signup_field_custom.rb @@ -0,0 +1,8 @@ +class SeminarSignupFieldCustom + include Mongoid::Document + include Mongoid::Timestamps + + field :seminar_signup_field_id + field :hidden, type: Boolean, default: true + belongs_to :seminar_main +end diff --git a/app/models/seminar_signup_field_set.rb b/app/models/seminar_signup_field_set.rb new file mode 100644 index 0000000..0470192 --- /dev/null +++ b/app/models/seminar_signup_field_set.rb @@ -0,0 +1,11 @@ +class SeminarSignupFieldSet + include Mongoid::Document + include Mongoid::Timestamps + + field :field_name, type: String + field :placeholder + field :name + field :disabled, type: Boolean, default: false + field :hidden, type: Boolean, default: false + belongs_to :seminar_main +end diff --git a/app/models/seminar_signup_value.rb b/app/models/seminar_signup_value.rb index 9175137..d73f13d 100644 --- a/app/models/seminar_signup_value.rb +++ b/app/models/seminar_signup_value.rb @@ -154,9 +154,14 @@ class SeminarSignupValue 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 = self.find(field_value_id) rescue nil - @seminar_signup_field_value.update(field_value_param) rescue nil - @seminar_signup_field_value.save rescue nil + @seminar_signup_field_value = member.seminar_signup_values.find(field_value_id) rescue nil + if @seminar_signup_field_value!=nil + puts ['yes'] + @seminar_signup_field_value.update(field_value_param) rescue nil + @seminar_signup_field_value.save rescue nil + else + puts ['no'] + end else @seminar_signup_field_value = member.seminar_signup_values.build(field_value_param) rescue nil @seminar_signup_field_value.save diff --git a/app/models/seminar_submission_field.rb b/app/models/seminar_submission_field.rb new file mode 100644 index 0000000..07e8e5a --- /dev/null +++ b/app/models/seminar_submission_field.rb @@ -0,0 +1,186 @@ +class SeminarSubmissionField + include Mongoid::Document + include Mongoid::Timestamps + include Mongoid::Attributes::Dynamic + include ::AttributeFieldsHelper + include ::Admin::SeminarsFieldHelper + + field :key, type: String + field :af_count + field :title, type: String, localize: true + field :markup, default: "text_field" + field :option_list, type: Hash,default: {} + field :markup_options, type: Hash + field :built_in, type: Boolean, default: false + field :disabled, type: Boolean, default: false + field :to_delete, type: Boolean, default: false + + field :to_require,type: Boolean, default: true + + field :typeA, type: Hash, default: {cross_lang: false} + field :typeB, type: Hash, default: {} + field :typeC, type: Hash, default: {calendar: "west_calendar", format: "format3"} + field :typeD, type: Hash, default: {cross_lang: false} + field :typeE, type: Hash, default: {} + + belongs_to :seminar_main + has_many :seminar_submission_values, autosave: true, dependent: :destroy + accepts_nested_attributes_for :seminar_submission_values, :allow_destroy => true + before_save :check_option_list + def get_basic_field_name_org + "seminar_submission_values" + end + + def get_basic_field_name + "seminar_submission_field" + end + def block_helper(member,index,disable = false,attribute_type=nil,con_field=nil, to_require=true,rf) + unless self.disabled + @index = index + @require = to_require + @markup_options = markup_options.merge(:disabled=>disable, :required => to_require) + @member = member + if !(con_field.seminar_submission_values.nil?) && con_field.seminar_submission_values!=[] + @attribute_value = con_field.seminar_submission_values.select{|v| v.seminar_submission_field_id.to_s==rf.id.to_s}[0] + else + @attribute_value = nil + end + @attribute_type = attribute_type + @new_attribute = @attribute_value.nil? + @prefiled_value = @attribute_value.value rescue nil + html = (instance_eval("render_#{markup}") rescue "") + return html + end + end + + def markup_value + get_data["option_list"] + end + + def add_more + (get_data["add_more"] == "true" ? true : false) rescue false + end + + def locale + get_data["cross_lang"] == "true" ? false : true + end + + def self_defined_markup_options? + (self.seminar.method(self[:key].pluralize.to_sym) && self.seminar.method(self[:key].pluralize+"_for_"+markup)) rescue false + end + + def option_list + if self_defined_markup_options? + #Class need to have corresponding field and value agent + # Ex: For "status" the class must have field called "statuses" for the relation and "statuses_for_select" for the select function + method = self.seminar.method(self[:key].pluralize+"_for_"+markup) + return (method.call rescue {}) + elsif self[:option_list].nil? || (self[:option_list].empty?) + return {} + else + return self[:option_list] + end + end + + def markup_options=(var) + self[:markup_options] = (eval(var) rescue {}) + end + + def markup_options + if self[:markup_options].nil? + return {} + else + Hash[self[:markup_options].map{|key,val|[key.to_sym,val]}] rescue {} + end + + end + + def panel + panel = LIST[:markups][self[:markup]]["panel"] + end + + def get_data + self[panel] + end + + def typeA=(var) + check_add_more_convert(var) + check_cross_lang_convert(var,"typeA") + self["typeA"] = var + end + + def typeD=(var) + check_cross_lang_convert(var,"typeD") + self["typeD"] = var + end + + def is_built_in? + self.built_in + end + + def is_disabled? + self.disabled + end + + def self.add_seminar_signup_field(seminar,seminar_param, seminar_submission_field_id=nil,field_status) + @field_name = 'seminar' + if field_status.eql?(true) + @seminar_submission_field_counter = seminar.seminar_submission_fields.count rescue nil + @seminar_submission_field = self.find(seminar_submission_field_id) rescue nil + old_key = @seminar_submission_field.key + @seminar_submission_field.update(seminar_param) + @seminar_submission_field.save + attribute_values = @seminar_submission_field.seminar_submission_values + if attribute_values.count > 0 + attribute_values.each do |av| + av.key = seminar_param["key"] + av.save + end + end + @seminar_submission_field[:af_count] = @seminar_submission_field_counter + else + @seminar_submission_field_counter = seminar.seminar_submission_fields.count rescue nil + @seminar_submission_field = seminar.seminar_submission_fields.build(seminar_param) rescue nil + @seminar_submission_field.save + @seminar_submission_field[:af_count] = @seminar_submission_field_counter + end + return @seminar_submission_field + end + + protected + + def check_cross_lang_convert(var,field) + if self[field]["cross_lang"] != var["cross_lang"] + case var["cross_lang"] + when "true" #from no-add_more to add_more + cross_lang_convert(:to_cross_lang) + else #from add_more to no-add_more + cross_lang_convert(:to_no_cross_lang) + end # of case + end # of if + end + + def check_add_more_convert(var) + if self["typeA"]["add_more"] != var["add_more"] + case var["add_more"] + when "true" #from no-add_more to add_more + add_more_convert(:to_add_more) + else #from add_more to no-add_more + add_more_convert(:to_no_add_more) + end # of case + end # of if + end + + def cross_lang_convert(opt) + + end + + def check_option_list + self[:option_list] = self[panel]["option_list"] rescue nil + end + + def add_more_convert(opt) + + end + +end \ No newline at end of file diff --git a/app/models/seminar_submission_field_set.rb b/app/models/seminar_submission_field_set.rb new file mode 100644 index 0000000..0f5b0e5 --- /dev/null +++ b/app/models/seminar_submission_field_set.rb @@ -0,0 +1,11 @@ +class SeminarSubmissionFieldSet + include Mongoid::Document + include Mongoid::Timestamps + + field :field_name, type: String + field :placeholder + field :name + field :disabled, type: Boolean, default: false + field :hidden, type: Boolean, default: false + belongs_to :seminar_main +end \ No newline at end of file diff --git a/app/models/seminar_submission_value.rb b/app/models/seminar_submission_value.rb new file mode 100644 index 0000000..b04aea8 --- /dev/null +++ b/app/models/seminar_submission_value.rb @@ -0,0 +1,212 @@ +class SeminarSubmissionValue + include Mongoid::Document + include Mongoid::Timestamps + include Mongoid::Attributes::Dynamic + include ::AttributeValuesHelper + include ::Admin::SeminarsValuesHelper + + field :key, type: String + + belongs_to :seminar_submission_field + belongs_to :seminar_signup_contribute + 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_submission_field.markup + when 'text_field','text_area' + if self.seminar_submission_field.add_more and (self.seminar_submission_field.markup == "text_field") + index.nil? ? self["val"] : self["val"][index] + else + self.seminar_submission_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_submission_field.markup + end + + def value=(value) + #save everything to temp_data waiting for futher process + self[:temp_data] = value + end + + def get_field_value + if (self.seminar_submission_field.markup.eql?("text_field") || self.seminar_submission_field.markup.eql?("text_area")) + field_value = self.value[I18n.locale] + elsif (self.seminar_submission_field.markup.eql?("select") || self.seminar_submission_field.markup.eql?("radio_button")) + field_value = self.seminar_submission_field.markup_value["#{self.value}"][I18n.locale] rescue nil + elsif self.seminar_submission_field.markup.eql?("address") + field_value = rf[:address_key][I18n.locale].map{|k,v| v}.delete_if(&:blank?).join(', ') + elsif self.seminar_submission_field.markup.eql?("date") + case self.seminar_submission_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 self.seminar_submission_field.markup.eql?("checkbox") + field_value = self.value.map {|v| self.seminar_submission_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" => self.seminar_submission_field.key, + "title" => self.seminar_submission_field.title, + "value" => field_value, + "val" => field_value = self.value + } + else + { + "key" => self.seminar_submission_field.key, + "title" => self.seminar_submission_field.title, + "value" => "", + "val" => field_value = self.value + } + end + end + + def get_value_by_locale(locale,add_more_index=nil) + case self.seminar_submission_field.markup + when "text_field" + case self.seminar_submission_field.add_more + when true + if self.seminar_submission_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 + self.seminar_submission_field.locale ? self[locale.to_s] : self.value + end + + when "select" + markup_values = self.seminar_submission_field.self_defined_markup_options? ? self.seminar_submission_field.markup_value : self.seminar_submission_field.markup_value + markup_values[self.value][locale.to_s] rescue 'NoData' + + when "text_area" + self.seminar_submission_field.locale ? self[locale.to_s] : self.value + + when "date" + if self.seminar_submission_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 = self.seminar_submission_field.markup_value + markup_values[self.value][locale.to_s] + + when "checkbox" + markup_values = self.seminar_submission_field.markup_value + self.value.collect{|key| markup_values["#{key}"][I18n.locale]}.join(",") + when "date_durnation" + self.value + + else + self.seminar_submission_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_submission_field_value = self.find(field_value_id) rescue nil + @seminar_submission_field_value.update(field_value_param) rescue nil + @seminar_submission_field_value.save rescue nil + else + @seminar_submission_field_value = member.seminar_submission_values.build(field_value_param) rescue nil + @seminar_submission_field_value.save + end + return @seminar_submission_field_value + end + + +protected + +def unset_all_lang_values + VALID_LOCALES.each{|t| self.unset t} + end + + def data_proc + unless self[:temp_data].nil? + case self.seminar_submission_field.markup + when "address" + self["val"] = self["temp_data"] + when 'text_field','text_area' + if self.seminar_submission_field.add_more + self["val"] = self["temp_data"] + else # if not add_more + if self.seminar_submission_field.can_muti_lang_input? + self[:temp_data].each do |key,val| + self[key] = val + end if(!self.seminar_submission_field.get_data[:cross_lang]) + else + self["val"] = self[:temp_data] + end + end # of self.seminar_submission_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_submission_field.markup + end # of self[:temp_data].nil? + self.unset('temp_data') + self.unset('temp') + end #of data_proc + + def check_key + self.key = self.seminar_submission_field.key + end + + def method_missing(*field) + if field.size < 1 + self[field[0]] + else + self[(field[0].to_s.delete "=")] = field[1] + end + end +end diff --git a/app/views/admin/seminar_signups/edit.html.erb b/app/views/admin/seminar_signups/edit.html.erb index 468ee44..ec29d8e 100644 --- a/app/views/admin/seminar_signups/edit.html.erb +++ b/app/views/admin/seminar_signups/edit.html.erb @@ -24,149 +24,161 @@
- +
<%= @seminar.title %>
- -
- -
- - -
-
- - -
- -
- <%= f.text_field :name, :class => "input-block-level", placeholder: t('seminar_signup.name') %> -
-
- - -
- -
-
-
- <% @site_in_use_locales.each_with_index do |locale, i| %> -
" id="unit_<%= locale %>"> - <%= f.fields_for "unit_translations".to_sym do |f| %> - <%= f.text_field locale, :class=>"input-block-level", :value => (@seminar_signup.send("unit_translations")[locale] rescue nil), :placeholder=> "#{t(locale.to_s)}", :required => true %> - <% end %> -
- <% end %> -
-
- <% @site_in_use_locales.each_with_index do |locale, i| %> - " href="#unit_<%= locale %>" data-toggle="tab"><%= t(locale.to_s) %> - <% end %> -
-
-
-
- - -
- -
- <%= f.text_field :tel, :class=>"input-block-level", :placeholder=> t('seminar_signup.tel'), :required => true %> -
-
- - -
- -
- <%= f.text_field :phone, :class=>"input-block-level", :placeholder=> t('seminar_signup.phone') %> -
-
- - -
- -
- <%= f.text_field :phone, :class=>"input-block-level", :placeholder=> t('seminar_signup.fax') %> -
-
- - -
- -
- -
-
- <% @site_in_use_locales.each_with_index do |locale, i| %> -
" id="address_<%= locale %>"> - <%= f.fields_for "address_translations".to_sym do |f| %> - <%= f.text_field locale, :class=>"input-block-level", :value => (@seminar_signup.send("address_translations")[locale] rescue nil), :placeholder=> "#{t(locale.to_s)}" %> - <% end %> -
- <% end %> -
-
- <% @site_in_use_locales.each_with_index do |locale, i| %> - " href="#address_<%= locale %>" data-toggle="tab"><%= t(locale.to_s) %> - <% end %> -
-
-
-
- - -
- -
- <%= f.email_field :email, :class=>"input-block-level", :placeholder=> t(:email), :required => true %> -
-
- - -
- -
- <%= f.text_field :password, :class=>"input-block-level", :placeholder=> t('seminar_signup.password') %> -
-
- - - - -
- -
-
-
- <% @site_in_use_locales.each_with_index do |locale, i| %> - " href="#note_<%= locale %>" for="<%= locale %>" data-toggle="tab"><%= t(locale.to_s) %> - <% end %> -
- <% @site_in_use_locales.each_with_index do |locale, i| %> -
" id="note_<%= locale %>"> - <%= f.fields_for "note_translations".to_sym do |f| %> - <%= f.text_area locale, rows: 5, :class=>"input-block-level", :value => (@seminar_signup.send("note_translations")[locale] rescue nil), :placeholder=> "#{t(locale.to_s)}" %> + <% if @seminar.seminar_signup_field_sets.count != 0 %> + <% @seminar.seminar_signup_field_sets.each do |signup_field| %> + <% if !(signup_field.disabled) && signup_field.field_name != 'recaptcha' %> + + <% end %> + <% end %> + <% else %> +
+ +
+ <% if @seminar.registration_status.include?('G') %> + + <% end %> + <% if @seminar.registration_status.include?('C') %> + <% end %>
-
-
+
+
*(required)
+
+ + +
+ +
+ <%= f.text_field :name, :class=>"input-block-level", :id=>'name', :placeholder=> t('seminar_signup.name'), :required => true %> +
+
+ + +
+ +
+ <%= f.text_field :tel, :class=>"input-block-level", :placeholder=> t('seminar_signup.tel'), :required => true %> +
+
+ + +
+ +
+ <%= f.email_field :email, :class=>"input-block-level", :placeholder=> t(:email), :required => true %> check mail +
+
+ +
+ +
+ <%= f.text_field :password, :class=>"input-block-level", :placeholder=> t('seminar_signup.password') %> + <%= t('seminar_signup.password_message') %> +
+
+ <% end %> + <% @form_index = 0 %> <% @seminar.seminar_signup_fields.asc(:_id).each do |rf| %>
- <%= rf.block_helper(@seminar,@form_index,false,"seminar_signup", @seminar_signup, rf.to_require) %> + <%= rf.block_helper(@seminar,@form_index,false,"seminar_signup",@seminar_signup, rf.to_require) %>
@@ -175,6 +187,7 @@ <% end %> +
diff --git a/app/views/admin/seminars/_attribute_submission_field.html.erb b/app/views/admin/seminars/_attribute_submission_field.html.erb new file mode 100644 index 0000000..c29edc8 --- /dev/null +++ b/app/views/admin/seminars/_attribute_submission_field.html.erb @@ -0,0 +1,132 @@ +
+<% + attribute_submission_field.af_count ? @af_counter = attribute_submission_field_counter + attribute_submission_field.af_count : @af_counter = attribute_submission_field_counter +%> +
+
+
+ <%= hidden_field "#{@field_name}[seminar_submission_fields][#{@af_counter}]","disabled",:value=>attribute_submission_field.disabled,:class=>"toggle-check", :data=>{:deploy=>"right"} %> + +
+
+ <%= t(:delete_)%> + <%= hidden_field "#{@field_name}[seminar_submission_fields][#{@af_counter}]","to_delete",:value=>false,:class=>"attribute_submission_field_to_delete"%> + Reset +

Field <%= @af_counter + 1 %>

+
+
+
+ +
+ <%= text_field "#{@field_name}[seminar_submission_fields][#{@af_counter}]","key",:value=>attribute_submission_field.key, :data=>{:type=>"key"} %> +
+
+ + <%= render :partial=>"shared/attribute_field/placeholder_block",:locals=>{:values=>attribute_submission_field.title_translations,:class_ext=>"pull-left",:label_ext=>t(:name),:field_name=>"#{@field_name}[seminar_submission_fields][#{@af_counter}][title_translations]"}%> + +
+ +
+ + +
+
+
+ +
+ +
+
+
+ +
+ + <%= content_tag :div,:class=>"field-type default fade in #{show_type_panel(attribute_submission_field,"typeA")}" do%> +
+ +
+ + +
+
+ <%= render :partial=>"shared/attribute_field/placeholder_block",:locals=>{:values=>attribute_submission_field["typeA"]["placeholder"],:field_name=>"#{@field_name}[seminar_submission_fields][#{@af_counter}][typeA][placeholder]"}%> + <% end if show_type_panel(attribute_submission_field,"typeA") != 'typeA hide' %> + + <%= content_tag :div,:class=>"field-type default fade in #{show_type_panel(attribute_submission_field,"typeB")}" do %> + <%= render :partial=>"shared/attribute_field/placeholder_block",:locals=>{:label_ext=>t(:initial),:values=>attribute_submission_field["typeB"]["initial"],:field_name=>"#{@field_name}[seminar_submission_fields][#{@af_counter}][typeB][initial]"}%> + + <% if attribute_submission_field.self_defined_markup_options?%> + <%= render :partial=>"shared/attribute_field/list_block",:locals=>{:values=>attribute_submission_field["option_list"],:field_name=> "#{@field_name}[seminar_submission_fields][#{@af_counter}][attribute][seminar][statuses]"} %> + <%else #normal list%> + <%= render :partial=>"shared/attribute_field/list_block",:locals=>{:values=>attribute_submission_field["option_list"],:field_name=> "#{@field_name}[seminar_submission_fields][#{@af_counter}][typeB][option_list]"} %> + <% end #of self_defined_markup_options?%> + + <% end if show_type_panel(attribute_submission_field,"typeB") != 'typeB hide' %> + + <%= content_tag :div,:class=>"field-type default fade in #{show_type_panel(attribute_submission_field,"typeC")}" do %> +
+ +
+ <%= select "#{@field_name}[seminar_submission_fields][#{@af_counter}][typeC]","format",Admin::AttributeValuesViewHelper::OPT,:class=>"dataType",:selected=>attribute_submission_field["typeC"]["format"] %> +
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+ <% end if show_type_panel(attribute_submission_field,"typeC") != 'typeC hide' %> + + <%= content_tag :div,:class=>"field-type default fade in #{show_type_panel(attribute_submission_field,"typeD")}" do%> +
+ +
+ +
+
+ <%= render :partial=>"shared/attribute_field/placeholder_block",:locals=>{:field_name=>"#{@field_name}[seminar_submission_fields][#{@af_counter}][typeD][placeholder]",:values=>attribute_submission_field["typeD"]["placeholder"]} %> + <% end if show_type_panel(attribute_submission_field,"typeD") != 'typeD hide' %> + + <%= content_tag :div,:class=>"field-type default fade in #{show_type_panel(attribute_submission_field,"typeE")}" do%> + <%= render :partial=>"shared/attribute_field/list_block",:locals=>{:field_name=>"#{@field_name}[seminar_submission_fields][#{@af_counter}][typeE][option_list]",:values=>attribute_submission_field["typeE"]["option_list"]}%> + <% end if show_type_panel(attribute_submission_field,"typeE") != 'typeE hide' %> + + <%= hidden_field "#{@field_name}[seminar_submission_fields][#{@af_counter}]","id",:value=>attribute_submission_field.id%> + +
\ No newline at end of file diff --git a/app/views/admin/seminars/_form.html.erb b/app/views/admin/seminars/_form.html.erb index e6c94fd..18882c3 100644 --- a/app/views/admin/seminars/_form.html.erb +++ b/app/views/admin/seminars/_form.html.erb @@ -10,7 +10,14 @@ <%= javascript_include_tag "lib/file-type" %> <%= javascript_include_tag "lib/module-area" %> <% end %> - + <% end %>
+ +
+ + + + + + + + + + <% @signup_sets.each_with_index do |attr_signup,signup_index| %> + + + + + + + + <% end %> + +
<%= t('seminar.field_name') %><%= t('seminar.name') %><%= t('seminar.placeholder') %><%= t('seminar.disable') %><%= t('seminar.hidden') %>
+ <%= t("seminar_signup.#{attr_signup.field_name}") %> + + <%= show_set_field(attr_signup,'seminar_signup_field_sets',signup_index,'name') %> + + <%= show_set_field(attr_signup,'seminar_signup_field_sets',signup_index,'placeholder') %> + + + <%= check_box_tag("seminar_main[seminar_signup_field_sets][#{signup_index}][disabled]", true ,attr_signup.disabled) %> + + <% if attr_signup.field_name != 'recaptcha' %> + + <%= check_box_tag("seminar_main[seminar_signup_field_sets][#{signup_index}][hidden]", true ,attr_signup.hidden) %> + <% end %> +
+ +
+ +
+ + + + + + + + + + <% @submission_set.each_with_index do |attr_signup,submission_index| %> + + + + + + + + <% end %> + +
<%= t('seminar.field_name') %><%= t('seminar.name') %><%= t('seminar.placeholder') %><%= t('seminar.disable') %><%= t('seminar.hidden') %>
+ <%= t("seminar_signup.#{attr_signup.field_name}") %> + + <%= show_set_field(attr_signup,'seminar_submission_field_sets',submission_index,'name') %> + + <%= show_set_field(attr_signup,'seminar_submission_field_sets',submission_index,'placeholder') %> + + + <%= check_box_tag("seminar_main[seminar_submission_field_sets][#{submission_index}][disabled]", true ,attr_signup.disabled) %> + + + <%= check_box_tag("seminar_main[seminar_submission_field_sets][#{submission_index}][hidden]", true ,attr_signup.hidden) %> +
+
+ +
+ + + + + + + <% @custom_set.each_with_index do |attr_custom,custom_index| %> + + + + + + <% end %> + +
<%= t('seminar.field_name') %><%= t('seminar.hidden') %>
+ <%= SeminarSignupField.where(id:attr_custom.seminar_signup_field_id).first.title rescue '' %> + + + <%= check_box_tag("seminar_main[seminar_signup_field_customs][#{custom_index}][hidden]", true ,attr_custom.hidden) %> +
+
diff --git a/app/views/admin/seminars/_index.html.erb b/app/views/admin/seminars/_index.html.erb index a1ae842..cb0b6b4 100644 --- a/app/views/admin/seminars/_index.html.erb +++ b/app/views/admin/seminars/_index.html.erb @@ -26,6 +26,7 @@
  • <%= t(:edit) %>
  • <%= t('seminar.set_seminar_item_content') %>
  • <%= t('seminar.set_seminar_signup_field') %>
  • +
  • <%= t('seminar.set_seminar_submission_field') %>
  • <%= t(:delete_) %>
  • <% end %> diff --git a/app/views/admin/seminars/seminar_signup.html.erb b/app/views/admin/seminars/seminar_signup.html.erb index a1a0963..301dce6 100644 --- a/app/views/admin/seminars/seminar_signup.html.erb +++ b/app/views/admin/seminars/seminar_signup.html.erb @@ -17,40 +17,178 @@ - - - - + <% if @seminar.seminar_signup_field_sets.count != 0 %> + <% @seminar.seminar_signup_field_sets.each do |field_set| %> + <% if !(field_set.hidden) %> + + <% end %> + <% end %> + <% else %> + + + + <% end %> + <% if @seminar.seminar_signup_field_customs.count != 0 %> + <% @seminar.seminar_signup_field_customs.each do |field_set| %> + <% if !(field_set.hidden) %> + + <% end %> + <% end %> + <% end %> + <% if @seminar.seminar_submission_field_sets.count != 0 %> + <% @seminar.seminar_submission_field_sets.each do |field_set| %> + <% if !(field_set.hidden) %> + + <% end %> + <% end %> + <% else %> + + + <% end %> + <% @seminar.seminar_submission_fields.each do |submission_field| %> + + <% end %> <% @seminar_signups.each do |seminar_signup| %> + <% len = seminar_signup.seminar_signup_contributes.count %> - - -
      -
    + <% end %> <% end %> - - + + + <% end %> + <% if @seminar.seminar_signup_field_customs.count != 0 %> + <% @seminar.seminar_signup_field_customs.each do |field_set| %> + <% if !(field_set.hidden) %> + + <% end %> + <% end %> + <% end %> + <% count_set = 0 %> + <% if @seminar.seminar_submission_field_sets.count != 0 %> + <% show1 = !(@seminar.seminar_submission_field_sets.select{|v| v.field_name=='title'}[0].hidden) + show2 = !(@seminar.seminar_submission_field_sets.select{|v| v.field_name=='description'}[0].hidden) + show3 = !(@seminar.seminar_submission_field_sets.select{|v| v.field_name=='file'}[0].hidden) + %> + <% @seminar.seminar_submission_field_sets.each do |field_set| %> + <% if !(field_set.hidden) %> + <% count_set+=1 %> + <% end %> + <% end %> + <% else %> + <% show1 = true + show2 = true + show3 = true + %> + <% count_set = 2 %> + <% end %> + <% if len==0 %> + <% + count_field = @seminar.seminar_submission_fields.count + %> +
      + <% for i in 1..count_field+count_set %> +
    + <% end %> + + + <% end %> +
      + <% seminar_signup.seminar_signup_contributes.collect do |seminar_signup_contribute| %> + <% if show1 %> +
    + <% end %> + <% if show2 %> + + <% end %> + <% if show3 %> + + <% end %> + <% + count_value = seminar_signup_contribute.seminar_submission_values.count + count_field = @seminar.seminar_submission_fields.count + %> + <% if count_value == count_field %> + <% seminar_signup_contribute.seminar_submission_values.each do |value| %> + + <% end %> + <% else %> + <% for i in 1..(count_field-count_value) %> + + <% end %> + <% end %> + + <% end %> - <% end %> diff --git a/app/views/admin/seminars/seminar_submission_field.html.erb b/app/views/admin/seminars/seminar_submission_field.html.erb new file mode 100644 index 0000000..c4063b1 --- /dev/null +++ b/app/views/admin/seminars/seminar_submission_field.html.erb @@ -0,0 +1,36 @@ +<% content_for :page_specific_css do -%> + <%= stylesheet_link_tag "lib/wrap-nav.css" %> + <%= stylesheet_link_tag "lib/pageslide.css" %> + <%= stylesheet_link_tag "lib/main-forms.css" %> + <%= stylesheet_link_tag "lib/togglebox.css" %> +<% end -%> + +<% content_for :page_specific_javascript do -%> + <%= javascript_include_tag "lib/jquery.tmpl.min.js" %> + <%= javascript_include_tag "field-forms-submission.js" %> +<% end -%> +<%= form_for @attribute,:url => admin_seminar_path(@attribute) , :html => { :class=> "form-horizontal main-forms" } do |f| %> + <% if flash.now[:notice].present? %> + <%= flash.now[:notice]%> + <% end %> + +

    <%= @attribute.title %>

    +
    + +
    + <%= render partial: "attribute_submission_field",collection: @attribute.seminar_submission_fields.asc(:_id)%> +
    + +
    + + <%= hidden_field_tag 'id', params[:id] if !params[:id].blank? %> + <%= f.submit t(:submit),:class=>"btn btn-primary"%> + <%= link_to t('cancel'), get_go_back, :class=>"btn" %> +
    +
    +<% end %> + + +<% content_for :page_specific_javascript do -%> + <%= render 'support_member_form_js' %> +<% end -%> \ No newline at end of file diff --git a/app/views/seminars/add_file.html.erb b/app/views/seminars/add_file.html.erb index 0fadf5f..66bbb53 100644 --- a/app/views/seminars/add_file.html.erb +++ b/app/views/seminars/add_file.html.erb @@ -8,6 +8,7 @@ @con = data["con"] @seminar = data["seminar"] @seminar_signup = data["seminar_signup"] + @form_index = 0 %> <% if !session[:seminar_signup_id].blank? %> @@ -15,37 +16,82 @@ <%= form_for @con, url: add_file_proc_seminars_path, html: {class: "content form-horizontal" , :id=>"new-seminar-signup-contribute"} do |f| %>
    - + <% if @seminar.seminar_submission_field_sets.count != 0 + data1 = @seminar.seminar_submission_field_sets.select{|v| v.field_name=='title'}[0] + data2 = @seminar.seminar_submission_field_sets.select{|v| v.field_name=='description'}[0] + data3 = @seminar.seminar_submission_field_sets.select{|v| v.field_name=='file'}[0] + show1 = !(data1.disabled) + show2 = !(data2.disabled) + show3 = !(data3.disabled) + name1 = data1['name'][I18n.locale] + name2 = data2['name'][I18n.locale] + name3 = data3['name'][I18n.locale] + plc1 = data1['placeholder'][I18n.locale] + plc2 = data2['placeholder'][I18n.locale]==t('seminar_signup.description') ? '' : data2['placeholder'][I18n.locale] + plc3 = data3['placeholder'][I18n.locale]==t('seminar_signup.file') ? '' : data3['placeholder'][I18n.locale] + else + show1 = true + show2 = true + show3 = true + name1 = t('seminar_signup.title') + name2 = t('seminar_signup.description') + name3 = t('seminar_signup.file') + plc1 = t('seminar_signup.title') + plc2 = '' + plc3 = '' + end + %> + <% if show1 %>
    - +
    - <%= f.text_field :title, :class=>"input-medium form-control", :id=>'name', :placeholder=> t('seminar_signup.file_name'), :required => true %> + <%= f.text_field :title, :class=>"input-medium form-control", :id=>'name', :placeholder=> plc1, :required => true %>
    - -
    - + <% end %> + <% if show2 %> +
    + + +
    + <%= "(#{plc2})" if !(plc2.to_s.blank?) %> +
    - <%= f.text_area :description, rows: 5, :class=>"ckeditor input-medium form-control", :placeholder=> t('seminar_signup.file_note') %> + <%= f.text_area :description, rows: 5, :class=>"ckeditor input-medium form-control", :placeholder=> plc2 %>
    - -
    - + <% end %> + <% if show3 %> +
    + + +
    + <%= "(#{plc3})" if !(plc3.to_s.blank?) %> +
    - <%= f.file_field :file %> + <%= f.file_field :file %>
    - -
    -
    - "> - - <%= f.submit t('submit'), class: 'btn btn-primary', :id => 'button-mail' %> - <%= f.button t('cancel'), type: 'reset', class: 'btn' %> -
    + <% end %> + <% @seminar.seminar_submission_fields.asc(:_id).each do |rf| %> +
    + <%= rf.block_helper(@seminar,@form_index,false,"seminar_signup_contribute",@con, rf.to_require,rf) %>
    - + <% @form_index = @form_index +1 %> + <% end %> +
    +
    + "> + + <%= f.submit t('submit'), class: 'btn btn-primary', :id => 'button-mail' %> + <%= f.button t('cancel'), type: 'reset', class: 'btn' %> +
    +
    +
    <% end %> <% else %> diff --git a/app/views/seminars/check_email.html.erb b/app/views/seminars/check_email.html.erb index 0e026d0..382cbd4 100644 --- a/app/views/seminars/check_email.html.erb +++ b/app/views/seminars/check_email.html.erb @@ -6,5 +6,5 @@

    <%= result %>

    -關閉視窗 +<%= t('seminar.close_window') %>
    \ No newline at end of file diff --git a/app/views/seminars/con_upload.html.erb b/app/views/seminars/con_upload.html.erb index 8c65512..1abe351 100644 --- a/app/views/seminars/con_upload.html.erb +++ b/app/views/seminars/con_upload.html.erb @@ -52,10 +52,9 @@ <%= link_to content_tag(:i, nil, :class => 'icon-plus') +' '+ t('new_'), OrbitHelper.url_to_show(@seminar.to_param) + '?method=add_file', :class => 'btn btn-primary' %> <% end %> -

    - 檔案上限: <%= @seminar.contribute_file_count.blank? ? '無' : @seminar.contribute_file_count %> + <% else %> @@ -70,4 +69,4 @@ 已截止 <% end %> - \ No newline at end of file + diff --git a/app/views/seminars/edit_file.html.erb b/app/views/seminars/edit_file.html.erb index 0c3870e..99f37eb 100644 --- a/app/views/seminars/edit_file.html.erb +++ b/app/views/seminars/edit_file.html.erb @@ -1,46 +1,96 @@ <% # encoding: utf-8 %> <%= stylesheet_link_tag "lib/jquery-ui-1.12.1/jquery-ui.min.css" %> <%= javascript_include_tag 'basic.js' %> +<% @@session = session %> +<%= yield %> <% data = action_data @con = data["con"] + @seminar = data["seminar"] + @seminar_signup = data["seminar_signup"] + @form_index = 0 %> <% if !session[:seminar_signup_id].blank? %> <%= form_for @con, url: edit_file_proc_seminars_path, html: {class: "content form-horizontal" , :id=>"new-seminar-signup-contribute"} do |f| %>
    - + <% if @seminar.seminar_submission_field_sets.count != 0 + data1 = @seminar.seminar_submission_field_sets.select{|v| v.field_name=='title'}[0] + data2 = @seminar.seminar_submission_field_sets.select{|v| v.field_name=='description'}[0] + data3 = @seminar.seminar_submission_field_sets.select{|v| v.field_name=='file'}[0] + show1 = !(data1.disabled) + show2 = !(data2.disabled) + show3 = !(data3.disabled) + name1 = data1['name'][I18n.locale] + name2 = data2['name'][I18n.locale] + name3 = data3['name'][I18n.locale] + plc1 = data1['placeholder'][I18n.locale] + plc2 = data2['placeholder'][I18n.locale]==t('seminar_signup.description') ? '' : data2['placeholder'][I18n.locale] + plc3 = data3['placeholder'][I18n.locale]==t('seminar_signup.file') ? '' : data3['placeholder'][I18n.locale] + else + show1 = true + show2 = true + show3 = true + name1 = t('seminar_signup.title') + name2 = t('seminar_signup.description') + name3 = t('seminar_signup.file') + plc1 = t('seminar_signup.title') + plc2 = '' + plc3 = '' + end + %> + <% if show1 %>
    - +
    - <%= f.text_field :title, :class=>"input-medium form-control", :id=>'name', :placeholder=> t('seminar_signup.file_name'), :required => true %> + <%= f.text_field :title, :class=>"input-medium form-control", :id=>'name', :placeholder=> plc1, :required => true %>
    - -
    - + <% end %> + <% if show2 %> +
    + + +
    + <%= "(#{plc2})" if !(plc2.to_s.blank?) %> +
    - <%= f.text_area :description, rows: 5, :class=>"ckeditor input-medium form-control", :placeholder=> t('seminar_signup.file_note') %> + <%= f.text_area :description, rows: 5, :class=>"ckeditor input-medium form-control", :placeholder=> plc2 %>
    - -
    - + <% end %> + <% if show3 %> +
    + + +
    + <%= "(#{plc3})" if !(plc3.to_s.blank?) %> +
    - <%= f.file_field :file %> + <%= f.file_field :file %>
    - -
    -
    - "> - - - <%= f.submit t('submit'), class: 'btn btn-primary', :id => 'button-mail' %> - <%= f.button t('cancel'), type: 'reset', class: 'btn' %> -
    + <% end %> + <% @seminar.seminar_submission_fields.asc(:_id).each do |rf| %> +
    + <%= rf.block_helper(@seminar,@form_index,false,"seminar_signup_contribute",@con, rf.to_require,rf) %>
    - + <% @form_index = @form_index +1 %> + <% end %> +
    +
    + "> + + + <%= f.submit t('submit'), class: 'btn btn-primary', :id => 'button-mail' %> + <%= f.button t('cancel'), type: 'reset', class: 'btn' %> +
    +
    +
    <% end %> <% else %> diff --git a/app/views/seminars/show.html.erb b/app/views/seminars/show.html.erb index 767e2f7..93009b1 100644 --- a/app/views/seminars/show.html.erb +++ b/app/views/seminars/show.html.erb @@ -28,140 +28,158 @@ <%= @seminar.title %> - -
    - -
    - <% if @seminar.registration_status.include?('G') %> - + <% if @seminar.seminar_signup_field_sets.count != 0 %> + <% @seminar.seminar_signup_field_sets.each do |signup_field| %> + <% if signup_field.field_name == 'name' %> +
    +
    *(<%= t('seminar.required') %>)
    +
    <% end %> - <% if @seminar.registration_status.include?('C') %> - + <% if !(signup_field.disabled) && signup_field.field_name != 'recaptcha' %> + <% end %> -
    -
    - - -
    - -
    - <%= f.text_field :name, :class=>"input-medium form-control", :id=>'name', :placeholder=> t('seminar_signup.name'), :required => true %> -
    -
    - - -
    - -
    -
    -
    - <% @site_in_use_locales.each_with_index do |locale, i| %> -
    " id="unit_<%= locale %>"> - <%= f.fields_for "unit_translations".to_sym do |f| %> - <%= f.text_field locale, :class=>"input-medium form-control", :value => (@seminar_signup.send("unit_translations")[locale] rescue nil), :placeholder=> "#{t(locale.to_s)}", :required => true %> - <% end %> -
    - <% end %> -
    -
    - <% @site_in_use_locales.each_with_index do |locale, i| %> - " href="#unit_<%= locale %>" data-toggle="tab"><%= t(locale.to_s) %> - <% end %> -
    + <% end %> + <% else %> +
    + +
    + <% if @seminar.registration_status.include?('G') %> + + <% end %> + <% if @seminar.registration_status.include?('C') %> + + <% end %>
    -
    - - -
    - -
    - <%= f.text_field :tel, :class=>"input-medium form-control", :placeholder=> t('seminar_signup.tel'), :required => true %> -
    -
    - - -
    - -
    - <%= f.text_field :phone, :class=>"input-medium form-control", :placeholder=> t('seminar_signup.phone') %> -
    -
    - - -
    - -
    - <%= f.text_field :fax, :class=>"input-medium form-control", :placeholder=> t('seminar_signup.fax') %> -
    -
    - - -
    - -
    -
    -
    - <% @site_in_use_locales.each_with_index do |locale, i| %> -
    " id="address_<%= locale %>"> - <%= f.fields_for "address_translations".to_sym do |f| %> - <%= f.text_field locale, :class=>"input-medium form-control", :value => (@seminar_signup.send("address_translations")[locale] rescue nil), :placeholder=> "#{t(locale.to_s)}" %> - <% end %> -
    - <% end %> -
    -
    - <% @site_in_use_locales.each_with_index do |locale, i| %> - " href="#address_<%= locale %>" data-toggle="tab"><%= t(locale.to_s) %> - <% end %> -
    -
    -
    -
    - - -
    - -
    - <%= f.email_field :email, :class=>"input-medium form-control availibility", :placeholder=> t(:email), :required => true %> check mail -
    -
    - -
    - -
    - <%= f.text_field :password, :class=>"input-medium form-control", :placeholder=> t('seminar_signup.password') %> - <%= t('seminar_signup.password_message') %> -
    -
    - - -
    - -
    -
    -
    - <% @site_in_use_locales.each_with_index do |locale, i| %> -
    " id="note_<%= locale %>"> - <%= f.fields_for "note_translations".to_sym do |f| %> - <%= f.text_area locale, rows: 5, :class=>"input-medium form-control", :value => (@seminar_signup.send("note_translations")[locale] rescue nil), :placeholder=> "#{t(locale.to_s)}" %> - <% end %> -
    - <% end %> -
    -
    - <% @site_in_use_locales.each_with_index do |locale, i| %> - " href="#note_<%= locale %>" data-toggle="tab"><%= t(locale.to_s) %> - <% end %> -
    -
    -
    -
    +
    +
    *(<%= t('seminar.required') %>)
    +
    + + +
    + +
    + <%= f.text_field :name, :class=>"input-medium form-control", :id=>'name', :placeholder=> t('seminar_signup.name'), :required => true %> +
    +
    + + +
    + +
    + <%= f.text_field :tel, :class=>"input-medium form-control", :placeholder=> t('seminar_signup.tel'), :required => true %> +
    +
    + + +
    + +
    + <%= f.email_field :email, :class=>"input-medium form-control availibility", :placeholder=> t(:email), :required => true %> check mail +
    +
    + +
    + +
    + <%= f.text_field :password, :class=>"input-medium form-control", :placeholder=> t('seminar_signup.password') %> + <%= t('seminar_signup.password_message') %> +
    +
    + + <% end %> <% @seminar.seminar_signup_fields.asc(:_id).each do |rf| %>
    @@ -176,13 +194,17 @@ -
    - -
    - <%= gotcha_error %> - <%= gotcha %> -
    -
    + <% if @seminar.seminar_signup_field_sets.count != 0 %> + <% if !(@seminar.seminar_signup_field_sets.select{|v| v.field_name=='recaptcha'}[0].disabled) %> +
    + +
    + <%= gotcha_error %> + <%= gotcha %> +
    +
    + <% end %> + <% end %>
    <%= t('seminar_signup.name')%><%= t('seminar.registration_status')%><%= t('seminar_signup.file_note')%><%= t('seminar_signup.uploads')%><%= field_set.name[I18n.locale] %><%= t('seminar_signup.name')%><%= t('seminar_signup.tel')%><%= t('seminar.registration_status')%><%= SeminarSignupField.where(id:field_set.seminar_signup_field_id).first.title rescue '' %><%= field_set.name[I18n.locale] %><%= t('seminar_signup.file_note')%><%= t('seminar_signup.uploads')%><%= submission_field.title %>
    - <%= seminar_signup.name %> -
    - -
    -
    <%= t("seminar.registration_status_#{seminar_signup.status}") if !seminar_signup.status.blank? %> - - <% seminar_signup.seminar_signup_contributes.collect do |seminar_signup_contribute| %> -
  • <%= seminar_signup_contribute.description.to_s.html_safe %>
  • + <% if @seminar.seminar_signup_field_sets.count != 0 %> + <% @seminar.seminar_signup_field_sets.each do |field_set| %> + <% if !(field_set.hidden) %> +
    + <% if field_set.field_name== 'name' %> + <%= seminar_signup.name %> +
    + +
    + <% elsif field_set.field_name== 'status' %> + <%= t("seminar.registration_status_#{seminar_signup.status}") if !seminar_signup.status.blank? %> + <% else %> + <%= seminar_signup.send("#{field_set.field_name}") %> + <% end %> +
    - <% seminar_signup.seminar_signup_contributes.collect do |seminar_signup_contribute| %> -
  • <%= link_to (seminar_signup_contribute.title.blank? ? File.basename(seminar_signup_contribute.file.path) : seminar_signup_contribute.title) , seminar_signup_contribute.file.url, {:target => '_blank', :title => Nokogiri::HTML(seminar_signup_contribute.description).text} if seminar_signup_contribute.file.file %> -
  • + <% else %> +
    + <%= seminar_signup.name %> +
    + +
    +
    <%= seminar_signup.tel %><%= t("seminar.registration_status_#{seminar_signup.status}") if !seminar_signup.status.blank? %> + + <% seminar_signup.seminar_signup_values.each do |seminar_signup_values| %> + <% if seminar_signup_values.seminar_signup_field_id == field_set.seminar_signup_field_id %> + <% if seminar_signup_values.value.class == String || seminar_signup_values.value.nil? %> + <%= seminar_signup_values.get_value_by_locale(I18n.locale,seminar_signup_values) %> + <% else %> + <% seminar_signup_values.value.each do |key,v| %> + <%= "#{I18n.t(key)}:#{seminar_signup_values.get_value_by_locale(key,seminar_signup_values)}" %> +
    + <% end %> + <% end %> + <% end %> + <% end %> +
    +
    +
  • <%= seminar_signup_contribute.title.to_s %>
  • +
    +
  • <%= seminar_signup_contribute.description.to_s.html_safe %>
  • +
    +
  • + <%= link_to (seminar_signup_contribute.title.blank? ? File.basename(seminar_signup_contribute.file.path) : seminar_signup_contribute.title) , seminar_signup_contribute.file.url, {:target => '_blank', :title => Nokogiri::HTML(seminar_signup_contribute.description).text} if seminar_signup_contribute.file.file %> +
  • +
    + + <% if value.value.class == String || value.value.nil? %> + <%= value.get_value_by_locale(I18n.locale,value) %> + <% else %> + <% value.value.each do |key,v| %> + <%= "#{I18n.t(key)}:#{value.get_value_by_locale(key,value)}" %> +
    + <% end %> + <% end %> +
    +
    +