.row .col-sm-12 .box .box-header.dark-background .box-content = form_for [:user, @registration], html: { multipart: true, class: 'form form-horizontal'} do |f| = form_group(@registration, :product_id) do %label.col-md-2.control-label{for: :product_id} Printer* .col-md-5 = f.collection_select :product_id, Product.all, :id, :name, { prompt: true }, class: 'form-control', :onchange => "sawgrassableWarranty(this)" .product-variations = form_group(@registration, :variation_id) do %label.col-md-2.control-label{for: :variation_id} Print & Color Management Software* .col-md-5 = f.collection_select :variation_id, [], :id, :name, { prompt: true }, class: 'form-control' .product-options = f.hidden_field :options_array, multiple: true, value: nil - unless @registration.new_record? = form_group(@registration, :options_array) do %label.col-md-2.control-label{for: :product_options} Options .col-md-10 - @registration.product_options.each do |opt| %label.checkbox-inline = f.check_box :options_array, { multiple: true }, opt, nil = opt = form_group(@registration, :serial_number) do #help_sn.icon-question-sign.left{ "data-featherlight" => "image", :href => "../../assets/snhelp.jpg"} %label.col-md-2.control-label{for: :serial_number} Serial Number* .col-md-5 = f.text_field :serial_number, class: 'form-control' = form_group(@registration, :powerdriver_challenge) do #help_sn.icon-question-sign.left{ "data-featherlight" => "../../assets/reg_instructions.png"} %label.col-md-2.control-label{for: :powerdriver_challenge} Product ID* .col-md-5 = f.text_field :powerdriver_challenge, class: 'form-control' = form_group(@registration, :reseller_id) do %label.col-md-2.control-label{for: :reseller_id} Reseller* .col-md-5 = f.collection_select :reseller_id, Reseller.order(name: :asc), :id, :name, { prompt: true }, class: 'form-control' #sawgrassable = form_group(@registration, :date_of_purchase) do %label.col-md-2.control-label{for: :date_of_purchase} Date of Printer Purchase .col-md-5.datepicker.input-group = f.text_field :date_of_purchase, class: 'form-control', :id => 'purchase_date', :readonly => "readonly" %span.input-group-addon %span.icon-calendar{ data: { 'date-icon' => 'icon-calendar', 'time-icon' => 'icon-time'}, id: 'cal_icon' } = form_group(@registration, :proof_of_purchase) do %label.col-md-2.control-label{for: :proof_of_purchase} Proof of Printer Purchase .col-md-5 - unless @registration.has_proof_of_purchase? %small jpg, png, pdf or tiff up to 10MB = f.file_field :proof_of_purchase, class: 'form-control' - else = f.file_field :proof_of_purchase, class: 'form-control' = link_to("Proof of Purchase", @registration.proof_of_purchase.url) =form_group(@registration, :has_warranty) do %label.col-md-2.control-label Extended Warranty? .col-md-5 = f.label :has_warranty, "Yes" = f.radio_button :has_warranty, true = f.label :has_warranty, "No" = f.radio_button :has_warranty, false .warranty{:id => "warranty"} = form_group(@registration, :reseller_warranty_code) do %label.col-md-2.control-label{for: :reseller_warranty_code} Warranty Code .col-md-5 = f.text_field :reseller_warranty_code, class: 'form-control' = form_group(@registration, :registration_reason) do %label.col-md-2.control-label{for: :registration_reason, :id => "reg_label"} Registration Reason* .col-md-5 = f.collection_select :registration_reason, ProductRegistration::REASONS, :first, :last, { prompt: true }, class: 'form-control' .form-actions.form-actions-padding-sm .row .col-md-10.col-md-offset-2 = f.submit "Save", class: 'btn btn-primary' :javascript window.registration = #{@registration.to_json}; :javascript $('#purchase_date').datepicker({format: 'dd/mm/yyyy'}) country = "#{ current_user.profile.country }" has_warranty = "#{@warranty}" variation = "#{@variation.nil? ? 0 : @variation.id}" product = "#{@product.nil? ? 0 : @product.id}" pd_challenge = "#{@ref_code.nil? ? '' : @ref_code}" $(document).ready(function(){ if(has_warranty == "true"){ $('#warranty').show() $('#product_registration_has_warranty_true').prop('checked', true) } setTimeout(function(){ if(variation.length > 0){ $('#product_registration_product_id').val(product); $('#product_registration_product_id').change(); } }, 500) setTimeout(function(){ $('#product_registration_variation_id').val(variation); }, 900) $('#product_registration_powerdriver_challenge').val(pd_challenge) $('#product_registration_variation_id').change(function(){ $.getJSON("/user/product_variations/" + $('#product_registration_variation_id').val() + ".json", function(data){ console.log(data.force_new_registration); if(data.force_new_registration == true){ console.log("Force new registration"); $('#product_registration_registration_reason').val("new_registration"); $('#product_registration_registration_reason').hide(); $('#reg_label').hide(); } }) }); console.log("Read") $('#sawgrassable').hide(); $('#warranty').hide(); $('#help_sn').hide(); $('#cal_icon').click(function(){ $('#product_registration_date_of_purchase').focus(); }) if($('#product_registration_has_warranty_true').is(":checked")){ $('#warranty').show() } if(($('#product_registration_product_id').val() == 35 || $('#product_registration_product_id').val() == 36) && country == "US"){ $('#sawgrassable').show(); $('#help_sn').show(); } $('#product_registration_has_warranty_false').click(function(){ if($(this).is(":checked")){ $('#warranty').hide() } }) $('#product_registration_has_warranty_true').click(function(){ if($(this).is(":checked")){ $('#warranty').show() } }) $('#help_fw').click(function(){ console.log("Herp derp"); }) }) function showSnHelp(){ console.log("Help") } function sawgrassableWarranty(printer){ value = printer.value; if((value == 35 || value == 36) && country == "US"){ $('#sawgrassable').show(); $('#help_sn').show(); }else{ $('#sawgrassable').hide(); $('#help_sn').hide(); } }