Class: OrderForm
- Inherits:
-
ApplicationForm
- Object
- ApplicationForm
- OrderForm
- Extended by:
- EnumField::EnumeratedAttribute
- Defined in:
- app/forms/order_form.rb
Instance Attribute Summary
Attributes inherited from ApplicationForm
Instance Method Summary collapse
- #remove_text_upload! ⇒ Object
- #send_translate_content ⇒ Object
- #session ⇒ Object
- #setup_params ⇒ Object
- #submit ⇒ Object
Methods inherited from ApplicationForm
Instance Method Details
#remove_text_upload! ⇒ Object
34 35 36 37 38 39 |
# File 'app/forms/order_form.rb', line 34 def remove_text_upload! return if @text_upload.try(:public_token).blank? TranslationCms::Api::Materials::Text.destroy(id: @text_upload.public_token) @text_upload = nil end |
#send_translate_content ⇒ Object
29 30 31 32 |
# File 'app/forms/order_form.rb', line 29 def send_translate_content TranslationCms::Api::Materials::Text.create fileupload_token: order.fileupload_token, content: translate_content end |
#session ⇒ Object
60 61 62 63 64 |
# File 'app/forms/order_form.rb', line 60 def session @session ||= TranslationCms::Api::Session.new(access_token: access_token) @session = nil if @session.errors.present? @session end |
#setup_params ⇒ Object
66 67 68 69 70 71 72 |
# File 'app/forms/order_form.rb', line 66 def setup_params { fileupload_token: order.fileupload_token, country_code: account.try(:country_code), customer_mode_id: customer_mode_id } end |
#submit ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/forms/order_form.rb', line 41 def submit if valid? return false if customer_mode.nil? remove_text_upload! if @text_upload.present? @text_upload = send_translate_content if translate_content.present? api_answer = if customer_mode.signed? TranslationCms::Api::Customers::Order.create(params) else TranslationCms::Api::Order.create(params) end remove_text_upload! if api_answer.errors.present? merge_responce! api_answer end errors.empty? end |