Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #This implements the general JS logic for the checkout
  2. registerFinePrintHandler = (options) ->
  3.   buttonQuerySelector = options.buttonSelector
  4.   textQuerySelector = options.textSelector
  5.   $button = $(buttonQuerySelector)
  6.   $text = $(textQuerySelector)
  7.   $button.click ->
  8.     $text.slideToggle()
  9.  
  10. retrieveUserInformation = (select, isAddress, url) ->
  11.   select.on 'change', (e) ->
  12.  
  13.     e.preventDefault()
  14.     $this = $(this)
  15.     $parent = $this.parent()
  16.     if isAddress
  17.       address_type = $parent.attr("data_address").replace('_','-')
  18.     if isAddress
  19.       form = if address_type == 'address' then $('.delivery-delivery-form') else $("." + address_type)
  20.     else
  21.       form = $('.credit-card-info')
  22.     # Value equal 0 represents the add option
  23.     if $(this).val() != '0'
  24.       form.find(".create").fadeOut()
  25.       form.find(".create input").prop('checked', false)
  26.       $.ajax
  27.         type: 'get'
  28.         url: url + $(this).val()
  29.         dataType: 'json'
  30.         complete: (response) =>
  31.           if response.status == 200
  32.             collection = response.responseJSON
  33.             for key of collection
  34.               form.find("#" + key).val(collection[key])
  35.               if key == 'country_id'
  36.                 if address_type == 'address'
  37.                   handleUserAddressRender($('#delivery_country'), collection[key], ThisPage.deliveryHandler, $('#order_country_postage_id'), $(".delivery"))
  38.                 if address_type == 'return-address'
  39.                   handleUserAddressRender($('#order_post_country_id'), collection[key], ThisPage.postHandler, $("#order_country_return_postage_id"), $(".post-return"))
  40.               form.find("#" + key).selectpicker('refresh')
  41.               form.find("#user_card_id").val($this.val())
  42.             form.find(".update").fadeIn()
  43.     else
  44.       # show add checkbox
  45.       form.find(".create").fadeIn()
  46.       form.find(".update").fadeOut()
  47.       form.find(".update input").prop('checked', false)
  48.  
  49. handleUserAddressRender = (element, value, handler, country_element, active) ->
  50.   # if country is not available render modal
  51.   if element.find("option[value='#{value}']").length == 0
  52.     handleInvalidAddressModalActions(handler, element, value, country_element, active)
  53.   else
  54.     element.val(value)
  55.     element.selectpicker('refresh')
  56.     handler.inhibitNextOnCountryChanged()
  57.     element.change()
  58.  
  59. handleInvalidAddressModalActions = (handler, element, value, country_element, active) ->
  60.   $modal = $("#invalid-address")
  61.   $modal.fadeIn()
  62.   $modal.find("#cancel").on 'click', ->
  63.     country_element.val(value)
  64.     element.val(value)
  65.     element.selectpicker('refresh')
  66.     handler.inhibitNextOnCountryChanged()
  67.     element.change()
  68.     $modal.fadeOut()
  69.   $modal.find("#use").on 'click', ->
  70.     element.selectpicker('refresh')
  71.     country_element.val(element.val())
  72.     country_element.selectpicker('refresh')
  73.     active.find(".cost-and-quantity a.active").click()
  74.     $modal.fadeOut()
  75.  
  76. class NewOrderPage
  77.   constructor: (options) ->
  78.     _(this).extend(options) if options
  79.     @currency = Cookies.get 'currency'
  80.     @initOrderView()
  81.     @fixSidebarPosition()
  82.     @lastOrderStateFiller = new LastOrderStateFiller(this)
  83.     @addressManager = new AddressManager(this)
  84.     this
  85.  
  86.   registerMoreThanTenDevices: (options) ->
  87.     inputQuerySelector = options.inputSelector
  88.     targetUrl = options.targetUrl
  89.     $input = $(inputQuerySelector)
  90.     $input.on 'change', =>
  91.       if parseInt($input.val()) == 11
  92.         @exitOrderPage = true
  93.         window.open(targetUrl,"_self")
  94.  
  95.   fixSidebarPosition: ->
  96.     fix = -> $('#sidebar').affix("checkPosition")
  97.     $ fix
  98.     setTimeout(fix,0)
  99.  
  100.   registerCallbacks: ->
  101.     @registerMoreThanTenDevices
  102.       inputSelector: "#order_n_devices"
  103.       targetUrl: "/group_orders/new"
  104.  
  105.     # @phoneNumberPlaceholderManager = new PhoneNumberPlaceholderManager(this)
  106.     # @phoneNumberPlaceholderManager.registerCallbacks()
  107.     @buildRatingOnFooter()
  108.     @sectionCollapser = new SectionCollapser(this)
  109.     @sectionCollapser.registerCallbacks()
  110.     @orderValidator = new OrderValidator(this)
  111.     @orderValidator.registerCallbacks()
  112.     @initCouponValidator()
  113.     @onlyDisplayCurrentCurrency()
  114.     @registerCurrencyCallbacks()
  115.     @getNumberOfDevicesField().on 'change', @updateOrderView.bind(this)
  116.     @pickupHandler = new PickupDeliveryHandler(this)
  117.     @pickupHandler.registerCallbacks()
  118.     @deliveryHandler = new DeliveryDeliveryHandler(this)
  119.     @deliveryHandler.registerCallbacks()
  120.     @addressCheckAction()
  121.     @registerBillingDetailsCallbacks()
  122.     @formSubmitter = new FormSubmitter(this)
  123.     @formSubmitter.registerCallbacks()
  124.     @checkIfApplePayIsAvailable()
  125.     @registerErrorPageCallbacks()
  126.     @bindPageAlert()
  127.     @loadPurposeUnselect()
  128.     @lastOrderStateFiller.fill()
  129.  
  130.   buildRatingOnFooter: ->
  131.     ratingValue = $(".rating").attr("data-score")
  132.     $('.rate').rateYo
  133.       rating: ratingValue
  134.       starWidth: '20px'
  135.       spacing: '5px'
  136.       ratedFill: '#ffd200'
  137.       readOnly: true
  138.       normalFill: '#FFFFFF'
  139.  
  140.   checkIfApplePayIsAvailable: ->
  141.     applePayContainer = $(".apple_pay")
  142.     paymentsContainer = $(".payments > div")
  143.     Stripe.applePay.checkAvailability (available) ->
  144.       if available
  145.         paymentsContainer.removeClass("col-sm-6").addClass("col-sm-4")
  146.         applePayContainer.show()
  147.         return
  148.     return
  149.   addressCheckAction: ->
  150.     addressCheckbox = $("input#use_delivery_as_return_address")
  151.     addressCheckbox.on 'change', ->
  152.       if this.checked
  153.         $('.return-address').fadeOut()
  154.       else
  155.         $('.return-address').fadeIn()
  156.  
  157.   loadPurposeUnselect: ->
  158.     $('#purpose label').on 'click', (evt)->
  159.       if $(this).prev().is ":checked"
  160.         evt.preventDefault()
  161.         $(this).prev().attr "checked", false
  162.  
  163.   bindPageAlert: ->
  164.     @exitOrderPage = false
  165.     myEvent = window.attachEvent or window.addEventListener
  166.     chkevent = if window.attachEvent then 'onbeforeunload' else 'beforeunload'
  167.     myEvent chkevent, (e) =>
  168.       if !@exitOrderPage
  169.         # For >=IE7, Chrome, Firefox
  170.         confirmationMessage =
  171.           'The progress of your order will be lost if you leave this page.'
  172.         (e or window.event).returnValue = confirmationMessage
  173.         confirmationMessage
  174.     return
  175.  
  176.   showErrorPage: (errorMessage)->
  177.     $('.container.order-error .error-message-description').html(errorMessage)
  178.     $('.container.new-order-form').fadeOut 400, ->
  179.       $('.container.order-error').fadeIn()
  180.  
  181.   showEmailErrorPage: (errorMessage)->
  182.     $('.container.order-email-error .error-message-description').html(errorMessage)
  183.     $('.container.new-order-form').fadeOut 400, ->
  184.       $('.container.order-email-error').fadeIn()
  185.  
  186.   hideErrorPage: ->
  187.     $('button#complete-order-button').prop 'disabled', false
  188.     $('button#complete-order-button i').addClass('hidden')
  189.  
  190.     $('.container.order-error').fadeOut 400, ->
  191.       $('.container.new-order-form').fadeIn()
  192.  
  193.   registerErrorPageCallbacks: =>
  194.     $(".try-again").click (e)=>
  195.       e.preventDefault()
  196.       @hideErrorPage()
  197.  
  198.   registerBillingDetailsCallbacks: ->
  199.     addressCheckbox = $("input#use_delivery_address")
  200.     addressCheckbox.on 'change', ->
  201.       if this.checked
  202.         $('.billing-address').fadeOut()
  203.       else
  204.         $('.billing-address').fadeIn()
  205.     $("input[name=payment_type]").on 'change', ->
  206.       $this = $(this)
  207.       if($this.val() == 'paypal')
  208.         $('.credit-card-info').fadeOut()
  209.         $('#billing-address-section .name-and-email').fadeOut()
  210.         $('#paypal-note').removeClass("hidden")
  211.         $('#paypal-note').hide()
  212.         $('#paypal-note').fadeIn()
  213.       else if($this.val() == 'apple_pay')
  214.         $('.credit-card-info').fadeOut()
  215.         $('#billing-address-section .name-and-email').fadeIn()
  216.         $('#paypal-note').fadeOut()
  217.       else
  218.         $('.credit-card-info').fadeIn()
  219.         $('#billing-address-section .name-and-email').fadeIn()
  220.         $('#paypal-note').fadeOut()
  221.  
  222.   getNumberOfDevices: ->
  223.     parseInt @getNumberOfDevicesField().val()
  224.  
  225.   getNumberOfDevicesField: -> $("#order_n_devices")
  226.  
  227.   updateOrderView: -> @orderView.update()
  228.  
  229.   registerCurrencyCallbacks: ->
  230.     CurrencySelector.onChange (currency)=>
  231.       @currency = currency
  232.       @onlyDisplayCurrentCurrency()
  233.  
  234.   onlyDisplayCurrentCurrency: ->
  235.     Amount.onlyDisplay(@currency)
  236.  
  237.   initializeAddOnModelActions: ->
  238.     $('.add-on').click ->
  239.       sku = $(this).attr('data-sku')
  240.       $('ul').find('.modal[data-sku=\'' + sku + '\']').fadeIn()
  241.       return
  242.     $(".close").click ->
  243.       $(".modal").fadeOut()
  244.  
  245.   onAddToCartPressed: (event) ->
  246.     event.preventDefault()
  247.     has_date = $("#order_start_date").val() != "" && $("#order_end_date").val() != ""
  248.     button = $ event.target
  249.     extraDiv = button.parents '.extra'
  250.     id = extraDiv.find(".extra_id").val()
  251.     extra = @getExtraWithId parseInt(id)
  252.     quantity = parseInt(extraDiv.find("select.extra_quantity").val())
  253.     if (extra.daily && has_date) || !(button.hasClass("active") || quantity == 0) && !extra.daily
  254.       $(".date-error").fadeOut()
  255.       button.html "ADDED TO CART"
  256.       button.addClass 'active'
  257.       extraDiv.find(".form-title").addClass("hidden")
  258.       extraDiv.find(".brief-title").removeClass("hidden")
  259.       extraDiv.find('.on_cart').val(true)
  260.       if quantity != 0
  261.         @addToCart
  262.           extra: extra
  263.           quantity: quantity
  264.       if quantity == 0
  265.         @resetAddToCartButton(extraDiv)
  266.     else
  267.       extraDiv.find("select.extra_quantity").val('0').change()
  268.       $(".date-error").fadeIn() if extra.daily
  269.       return false
  270.  
  271.   onAddOnAddCartPressed: (event) ->
  272.     event.preventDefault()
  273.     button = $(event.target);
  274.     add_on_modal = button.parents '.modal'
  275.     id = add_on_modal.attr("data-id")
  276.     add_on = @getAddOnWithId parseInt(id)
  277.     addOnDiv = $(".add-on[data-sku='" + add_on.sku + "']")
  278.     onCart = addOnDiv.find('.on_cart')
  279.     if onCart.val() == "false"
  280.       button.html "REMOVE FROM CART"
  281.       addOnDiv.addClass 'active'
  282.       onCart.val(true)
  283.       @addToCartAddOn
  284.         add_on: add_on
  285.         quantity: 1
  286.     else
  287.       button.html "ADD TO CART"
  288.       addOnDiv.removeClass 'active'
  289.       @orderView.removeAddOn(id)
  290.       onCart.val(false)
  291.  
  292.   resetAddToCartButton: (extraDiv)->
  293.     button = extraDiv.find('.add-to-cart .btn')
  294.     extraDiv.find('.on_cart').val(false)
  295.     button.html "ADD TO CART"
  296.     button.removeClass 'active'
  297.     extraDiv.find(".form-title").removeClass("hidden")
  298.     extraDiv.find(".brief-title").addClass("hidden")
  299.  
  300.   getExtraWithId:(id) ->
  301.     vals = @getExtras().filter (e)->
  302.       e.id == id
  303.     if vals.length > 0 then vals[0] else null
  304.  
  305.   getAddOnWithId: (id) ->
  306.     vals = @getAddOns().filter (a) ->
  307.       a.id == id
  308.     if vals.length > 0 then vals[0] else null
  309.  
  310.   addToCart: (options) ->
  311.     extra = options.extra
  312.     quantity = options.quantity
  313.     @orderView.addExtra options
  314.  
  315.   addToCartAddOn: (options) ->
  316.     add_on =  options.add_on
  317.     quantity = 1
  318.     @orderView.addAddOn options
  319.  
  320.   registerExtrasCallbacks: ->
  321.     $('.extras .add-to-cart .btn').click (clickEvent) =>
  322.       @onAddToCartPressed(clickEvent)
  323.     $('.extras .extra_quantity').change (event)=>
  324.       $target = $(event.target)
  325.       extraDiv = $target.parents('.extra')
  326.       id = extraDiv.find(".extra_id").val()
  327.       extra = @getExtraWithId parseInt(id)
  328.       @orderView.removeExtra(id)
  329.       @resetAddToCartButton extraDiv
  330.  
  331.   registerAddOnCallbacks: ->
  332.     $('.modal .modal-header .btn').click (clickEvent) =>
  333.       clickEvent.preventDefault()
  334.       @onAddOnAddCartPressed(clickEvent)
  335.  
  336.   getDailyPriceString: ->
  337.     value = @destination.prices[@currency]
  338.     priceString =
  339.       eur: "#{value}€"
  340.       pound: "#{value}£"
  341.       dollar: "$#{value}"
  342.     priceString[@currency]
  343.  
  344.   getNumberOfDays: () ->
  345.     startDateStr = $('#order_start_date').val()
  346.     endDateStr = $('#order_end_date').val()
  347.  
  348.   updatePriceBox: ->
  349.     AmountView.update
  350.       el: '.unlimited-internet-ad .price .currency-amount'
  351.       eur: @destination.prices['eur']
  352.       usd: @destination.prices['usd']
  353.       gbp: @destination.prices['gbp']
  354.  
  355.  
  356. class FormSubmitter
  357.   constructor: (@page) ->
  358.  
  359.   getPaymentType: ->
  360.     $('input[name=payment_type]:checked').val() || "stripe"
  361.  
  362.   stripeResponseHandler: (status, response) ->
  363.     $form = $('form')
  364.     if response.error
  365.       console.log JSON.stringify(response)
  366.       element = null
  367.       param = response.error.param.replace('_', '-')
  368.       if param == ''
  369.         param = 'number'
  370.       if param == 'exp-month' or param == 'exp-year'
  371.         element = $('select[data-stripe=' + param + ']').parent()
  372.       else
  373.         element = $('input[data-stripe=' + param + ']')
  374.       ThisPage.orderValidator.showError
  375.         message: response.error.message
  376.         element: element
  377.       # Show the errors on the form
  378.       #$form.find('.payment-errors').text response.error.message
  379.       $form.find('#complete-order-button').prop 'disabled', false
  380.       $form.find('button#complete-order-button i').addClass('hidden')
  381.  
  382.     else
  383.       # response contains id and card, which contains additional card details
  384.       token = response.id
  385.       # Insert the token into the form so it gets submitted to the server
  386.       $form.append $('<input type="hidden" name="stripeToken" />').val(token)
  387.       # and submit
  388.       $ @submit.bind(this)
  389.  
  390.   createApplePayOrder: ->
  391.     # Ajax call to create the order, this have to be sync because we need the order info to create a new apple pay session
  392.     paymentRequest = {}
  393.     requestObject = {}
  394.     $ =>
  395.       data = $('form').serialize()
  396.       $.ajax
  397.         type: 'post'
  398.         data: data
  399.         async: false
  400.         dataType: 'json'
  401.         url: @page.basePath
  402.         success: (response) =>
  403.           country_code = $(".apple_pay").attr("data_country")
  404.           paymentRequest = {
  405.             countryCode: country_code,
  406.             currencyCode: response.currency.toUpperCase(),
  407.             total: {
  408.               label: 'for tepwireless',
  409.               amount: response.original_price
  410.             }
  411.           }
  412.           requestObject = {orderid: response.id,payment:paymentRequest}
  413.         error: (error) =>
  414.           console.log(error)
  415.     return requestObject
  416.  
  417.   buildApplePaySession: (paymentObject,currThis) ->
  418.     session = Stripe.applePay.buildSession(paymentObject.payment, ((result, completion) ->
  419.       payment_url = currThis.page.basePath + "/payment_apple_pay"
  420.       success_url = currThis.page.basePath + "/order_success"
  421.       $.post(payment_url, token: result.token.id,id:paymentObject.orderid).done(->
  422.         completion ApplePaySession.STATUS_SUCCESS
  423.         $.get(success_url,apple_order_id:paymentObject.orderid).done(->
  424.           window.location = success_url + "?apple_order_id=" + paymentObject.orderid
  425.         ).fail((jqXHR,textStatus) ->
  426.           if jqXHR.status == 503
  427.             order_id = JSON.parse(jqXHR.responseText).order_id
  428.             currThis.page.showEmailErrorPage("Your order number " + order_id + " has been processed but the confirmation email was not successfully sent.")
  429.           else
  430.             currThis.page.showErrorPage("")
  431.           return
  432.         )
  433.       ).fail ->
  434.         completion ApplePaySession.STATUS_FAILURE
  435.         currThis.page.showErrorPage("")
  436.         return
  437.       return
  438.     ), (error) ->
  439.       currThis.page.showErrorPage("")
  440.       return
  441.     )
  442.     return session
  443.  
  444.   submit: ->
  445.     fbq('track', 'InitiateCheckout')
  446.     if @getPaymentType() == 'stripe'
  447.       cc=$('input[data-stripe="number"]').val()
  448.       lastDigits = cc.substring(cc.length - 4, cc.length)
  449.       $('#order_cc_end').val(lastDigits)
  450.     $ =>
  451.       data = $('form.new_order').serialize()
  452.       $.ajax
  453.         type: 'post'
  454.         url: @page.basePath
  455.         data: data
  456.         dataType: 'json'
  457.         success: (response) =>
  458.           @page.exitOrderPage = true
  459.           paymentMethod = @getPaymentType()
  460.           url =
  461.             if paymentMethod == 'stripe'
  462.               "#{@page.basePath}/order_success"
  463.             else
  464.               "#{@page.basePath}/payment"
  465.           form = $("<form action='#{url}' method='post'>\
  466.            <input type='text' name='id' value=#{response.id} />\
  467.            </form>")
  468.           $('body').append(form)
  469.           form.submit()
  470.         error: (response) =>
  471.           if response.status == 422
  472.             @page.orderValidator.handleValidationResponse(response)
  473.           else if response.status == 401
  474.             @page.showErrorPage(response.responseJSON.error_message)
  475.           else if response.status == 503
  476.             order_id = JSON.parse(response.responseText).order_id
  477.             @page.showEmailErrorPage("Your order number " + order_id + " has been processed but the confirmation email was not successfully sent.")
  478.           else
  479.             @page.showErrorPage("")
  480.  
  481.   validateUserAccount: ($form, paymentType, applePaySession) ->
  482.     data = $form.serialize()
  483.     $.ajax
  484.       type: 'post'
  485.       url: '/front_users/'
  486.       data: data
  487.       dataType: 'json'
  488.       success: (response) =>
  489.         $form.find('.error-message').remove()
  490.         $form.find('input#front_users_id').val(response.id)
  491.         @handleFormSubmit($form, paymentType, applePaySession)
  492.       error: (errors) =>
  493.         errorsObject = if errors.responseJSON != undefined then errors.responseJSON.errors else []
  494.         for key of errorsObject
  495.           $form.find("#front_user_#{key}").parent().append("<span class='error-message'>#{errorsObject[key]}</span>")
  496.         $form.find('#complete-order-button').prop 'disabled', false
  497.         $form.find('button#complete-order-button i').addClass('hidden')
  498.         $form.find('.complete-order .button-container').parent().append("<span class='error-message'>PLEASE REVIEW THE FIELDS ABOVE</span>")
  499.  
  500.   handleFormSubmit: ($form, paymentType, applePaySession) ->
  501.     @page.orderValidator.trackCheckoutFunnel 4, =>
  502.       isSuccess = true
  503.       if paymentType == 'stripe'
  504.         if $("#use_customer").val() == 'true'
  505.           $ @submit.bind(this)
  506.         else
  507.           Stripe.card.createToken $form, @stripeResponseHandler.bind(this)
  508.         return false
  509.       else if paymentType == 'apple_pay'
  510.         $form.find('#complete-order-button').prop 'disabled', false
  511.         $form.find('button#complete-order-button i').addClass('hidden')
  512.         applePaySession.begin()
  513.         return false
  514.       else
  515.         @submit()
  516.  
  517.   registerCallbacks: ->
  518.     $form = $ 'form.new_order'
  519.     $form.on 'submit', (event) =>
  520.       event.preventDefault()
  521.       paymentType = @getPaymentType()
  522.       if paymentType == 'apple_pay'
  523.         applePaymentObject = @createApplePayOrder()
  524.         applePaySession = @buildApplePaySession(applePaymentObject,this)
  525.  
  526.       # Disable the submit button to prevent repeated clicks
  527.       $form.find('#complete-order-button').prop 'disabled', true
  528.       $form.find('button#complete-order-button i').removeClass('hidden')
  529.       completeOrderBtn = $form.find('#complete-order-button')
  530.       @page.orderValidator.lastPressedContinueButton = completeOrderBtn
  531.       @page.orderValidator.hideErrors()
  532.       @page.orderValidator.validateThirdSection
  533.         success: =>
  534.           if $(".create-account #create_account").prop("checked")
  535.             password = $(".create-account #front_user_password").val()
  536.             $(".create-account #front_user_password_confirmation").val(password)
  537.             @validateUserAccount($form, paymentType, applePaySession)
  538.           else
  539.             @handleFormSubmit($form, paymentType, applePaySession)
  540.           # Prevent the form from submitting with the default action
  541.         error: ->
  542.           $form.find('#complete-order-button').prop 'disabled', false
  543.           $form.find('button#complete-order-button i').addClass('hidden')
  544.       return false
  545.  
  546.  
  547. class SectionCollapser
  548.   constructor: (@page)->
  549.   registerCallbacks: ->
  550.     return
  551.  
  552.   toggleTargetSection: (event) ->
  553.     section = $(event.target).parents("section")
  554.     collapserIcon = section.find('.collapser i')
  555.     collapsable = section.find('.collapsable')
  556.     if collapserIcon.hasClass('fa-chevron-up')
  557.       collapserIcon.removeClass('fa-chevron-up')
  558.       collapserIcon.addClass('fa-chevron-down')
  559.       collapsable.fadeOut => @page.fixSidebarPosition()
  560.     else
  561.       collapserIcon.removeClass('fa-chevron-down')
  562.       collapserIcon.addClass('fa-chevron-up')
  563.       collapsable.fadeIn => @page.fixSidebarPosition()
  564.  
  565.   uncollapseDeliveryDetails: ->
  566.     section = $('section.delivery')
  567.     collapserIcon = section.find('.collapser i')
  568.     collapsable = section.find('.collapsable')
  569.     collapserIcon.removeClass('fa-chevron-down')
  570.     collapserIcon.addClass('fa-chevron-up')
  571.     collapsable.fadeIn => @page.fixSidebarPosition()
  572.  
  573.   uncollapseAddOnsDetails: ->
  574.     section = $('section.add-ons')
  575.     collapserIcon = section.find('.collapser i')
  576.     collapsable = section.find('.collapsable')
  577.     collapserIcon.removeClass('fa-chevron-down')
  578.     collapserIcon.addClass('fa-chevron-up')
  579.     collapsable.fadeIn => @page.fixSidebarPosition()
  580.  
  581.   uncollapseBillingDetails: ->
  582.     section = $('section.billing')
  583.     collapserIcon = section.find('.collapser i')
  584.     collapsable = section.find('.collapsable')
  585.     collapserIcon.removeClass('fa-chevron-down')
  586.     collapserIcon.addClass('fa-chevron-up')
  587.     collapsable.fadeIn => @page.fixSidebarPosition()
  588.  
  589.  
  590. class Extra
  591.   constructor: (options) ->
  592.     _(this).extend options
  593.  
  594. class AddOn
  595.   constructor: (options) ->
  596.     _(this).extend options
  597.  
  598. class AddressManager
  599.   constructor: (options) ->
  600.     _(this).extend options
  601.  
  602.   isDefaultDeliverySelected: ->
  603.     $('.delivery-delivery-form[data-address-is-default]').length > 0
  604.  
  605.   isDefaultReturnSelected: ->
  606.     $('.return-address[data-address-is-default]').length > 0
  607.  
  608.   resetDeliveryAddress: ->
  609.     @resetAddressForm $('.delivery-delivery-form')
  610.  
  611.   resetReturnAddress: ->
  612.     @resetAddressForm $('.return-address')
  613.  
  614.   resetAddressForm: (topLevelElement) ->
  615.     addressSelector = topLevelElement.find '.user-select'
  616.     topLevelElement.find('input[type=text]').val('')
  617.     addressSelector.val(0)
  618.     addressSelector.selectpicker("refresh")
  619.     addressSelector.trigger('change')
  620.  
  621.  
  622.  
  623.  
  624.  
  625.  
  626. root = exports ? this
  627. root.NewOrderPage = NewOrderPage
  628. root.Extra = Extra
  629. root.AddressManager = AddressManager
  630. root.AddOn = AddOn
  631.  
  632.  
  633. $ ->
  634.   if $("body.orders, body.sales").length > 0
  635.     $("section.delivery .sign-in a").bind 'click', ->
  636.       $(".sign-modal").fadeIn()
  637.       return
  638.  
  639.     use_customer = $(".credit-card-info #use_customer")
  640.  
  641.     $(".credit-card-info input").on 'change', ->
  642.       if use_customer.val() == 'true'
  643.         use_customer.val('false')
  644.  
  645.     $(".create-account #create_account").click (e) ->
  646.       $this = $(this)
  647.       if $this.prop("checked")
  648.         $this.parent().find(".fields").fadeIn()
  649.         email = if $(".delivery-delivery-form #email").val() != '' then $(".delivery-delivery-form #email").val() else $(".billing-address #email").val()
  650.         $(".create-account #front_user_email").val(email)
  651.       else
  652.         $this.parent().find(".fields").fadeOut()
  653.  
  654.     retrieveUserInformation($(".user-addresses select"), true, '/front_users/addresses/')
  655.     retrieveUserInformation($(".user-payments select"), false, '/front_users/payments/')
  656.  
  657.     $(".new_front_user .submit").click (e) ->
  658.       ThisPage.exitOrderPage = true
  659.       $.ajax
  660.         type: 'post'
  661.         data: $("#new_order").serialize()
  662.         url: ThisPage.basePath + '/save_order_state'
  663.         success: (response) =>
  664.         error: (response) =>
  665.  
  666.     $('[data-toggle="popover"]').popover
  667.       trigger: 'hover'
  668.     if(".order_success").length > 0
  669.       ratingValue = $(".rating").attr("data-score")
  670.       $('.rate').rateYo
  671.         rating: ratingValue
  672.         starWidth: '20px'
  673.         spacing: '5px'
  674.         ratedFill: '#ffd200'
  675.         readOnly: true
  676.         normalFill: '#FFFFFF'
  677.  
  678.     registerFinePrintHandler
  679.       buttonSelector: '.unlimited-internet-ad'
  680.       textSelector: '.unlimited-instructions'
  681.  
  682.     # Address and Billing address phone country code
  683.     $('''#order_address_attributes_country_code,
  684.         #order_billing_address_attributes_country_code''').selectpicker
  685.       showSubtext: true
  686.       showContent: true
  687.       mobile: true
  688.       dropupAuto: false
  689.  
  690.  
  691.     prefix = $('#order_address_attributes_country_code').data('phone-prefix')
  692.     $('#order_address_attributes_country_code').selectpicker('val', prefix)
  693.     $('#order_billing_address_attributes_country_code')
  694.       .selectpicker('val',
  695.                     $('#order_billing_address_attributes_country_code')
  696.                       .data('phone-prefix'))
  697.  
  698.  
  699.   if $("body.orders, body.errors").length == 0
  700.     $('.navbar select.destinations').selectpicker()
  701.     $('.navbar .btn-group.destinations').addClass('bounceInDown')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement