diff --git a/app/assets/stylesheets/custom_field.css b/app/assets/stylesheets/custom_field.css index 1a627c1..e9ef739 100644 --- a/app/assets/stylesheets/custom_field.css +++ b/app/assets/stylesheets/custom_field.css @@ -17,4 +17,12 @@ input[type=checkbox]:focus { .ask-question .control-group{ justify-content: center; } +} +.file-selector,.ask-question .controls >.file-selector{ + display: inline-flex; + flex-wrap: wrap; + justify-content: center; +} +.filename{ + word-break: break-all; } \ No newline at end of file diff --git a/app/controllers/admin/asks_controller.rb b/app/controllers/admin/asks_controller.rb index b8f18dc..917c79e 100644 --- a/app/controllers/admin/asks_controller.rb +++ b/app/controllers/admin/asks_controller.rb @@ -98,8 +98,32 @@ class Admin::AsksController < OrbitAdminController def update locale = I18n.locale - ask_question_param = params.require(:ask_question).permit! - @ask_question.update_attributes(ask_question_param) + temp_params = params.require(:ask_question).permit! + + all_to_save = [] + ask_setting = AskSetting.first + ask_setting = AskSetting.create() if ask_setting.nil? + ask_setting.custom_fields.select{|k,v| v['type']=='file' || v['type']=='image'}.each do |k,v| + file = temp_params['custom_values'][k] + if !file.blank? + if v['type']=='image' + all_to_save += [[k,AskImage.new(file: file,ask_question_id: @ask_question.id)]] + else + all_to_save += [[k,AskFile.new(file: file,ask_question_id: @ask_question.id)]] + end + else + temp_params['custom_values'][k] = @ask_question.custom_values[k] + end + end + flag = @ask_question.save + if flag + all_to_save.each do |to_save| + flag = flag && to_save[1].save + temp_params['custom_values'][to_save[0]] = [temp_params['custom_values'][to_save[0]].original_filename ,to_save[1].file.url] + end + end + + @ask_question.update_attributes(temp_params) if @ask_question.send_email? build_email(@ask_question) end diff --git a/app/controllers/asks_controller.rb b/app/controllers/asks_controller.rb index 1c3cf96..490325f 100644 --- a/app/controllers/asks_controller.rb +++ b/app/controllers/asks_controller.rb @@ -118,7 +118,6 @@ class AsksController < ActionController::Base end def show ask_question = AskQuestion.where(id: @params['item']).first - puts ask_question.inspect {'ask_question' => ask_question,'layout_type'=>'show'} end def index @@ -161,8 +160,30 @@ class AsksController < ActionController::Base end def create - @ask_question = AskQuestion.new(create_params) - if (gotcha_valid? || !AskSetting.first.default_setting['recaptcha'])&& @ask_question.save + @ask_question = AskQuestion.new() + temp_params = create_params + all_to_save = [] + ask_setting = AskSetting.first + ask_setting = AskSetting.create() if ask_setting.nil? + ask_setting.custom_fields.select{|k,v| v['type']=='file' || v['type']=='image'}.each do |k,v| + file = temp_params['custom_values'][k] + if !file.blank? + if v['type']=='image' + all_to_save += [[k,AskImage.new(file: file,ask_question_id: @ask_question.id)]] + else + all_to_save += [[k,AskFile.new(file: file,ask_question_id: @ask_question.id)]] + end + end + end + flag =(gotcha_valid? || !AskSetting.first.default_setting['recaptcha']) && @ask_question.save + if flag + all_to_save.each do |to_save| + flag = flag && to_save[1].save + temp_params['custom_values'][to_save[0]] = [temp_params['custom_values'][to_save[0]].original_filename ,to_save[1].file.url] + end + end + if flag + @ask_question.update_attributes(temp_params) build_email(@ask_question) redirect_to "#{params[:referer_url]}/?method=thank" else diff --git a/app/helpers/admin/asks_helper.rb b/app/helpers/admin/asks_helper.rb index 641713a..c5dd961 100644 --- a/app/helpers/admin/asks_helper.rb +++ b/app/helpers/admin/asks_helper.rb @@ -147,6 +147,22 @@ module Admin::AsksHelper readonly ? value.collect{|k1,v1| Array(v['options'])[v1.to_i][1][I18n.locale]}.join(', ') : Array(v['options']).select{|index1,option| option['disabled'] != 'true'}.collect do |index1,option| "#{check_box_tag("#{field_name}[#{index1}]",index1,value[index1]==index1)}#{option[I18n.locale]}" end.join + when 'file' + file_value = value[0] rescue nil + file_path = value[1] rescue nil + file_required = v['required']=='true' ? 'required="required"' : '' + readonly ? "#{file_value}" : "