/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ var SignupCompany = (function ($) { var redirectable, isDistributor = false, reseller_name = ""; var comNa = "", fiNa = "", laNa = "", email = "", phone = "", password = "", department = "", address1 = "", city = "", state = "", country = "", zip = "", usagePlan = "", billingCycle = "", currency = ""; function loadPaymentPackage(currentcy) { return $.ajax({ type: "POST", url: "api/v1/GetPaymentPackage", beforeSend: function () { Modal.closeModal(); }, success: function (data) { if (data.status === 'OK') { var payPackages = data.list_package; makePaymentPakageList(payPackages, currentcy); } else { Modal.showAlert({content: i18n.t('company.message.fail_load_payment_package')}); } } }); } function makePaymentPakageList(packages, currentcy) { // sort package by ID _.sortBy(packages, 'paymentId'); var contentList = ""; $.each(packages, function (i, value) { switch (parseInt(value.paymentId)) { case 1: var content = (currentcy === "yen") ? i18n.t('payment_package.package1_ja') : i18n.t('payment_package.package1'); contentList += ''; break; case 2: var content = (currentcy === "yen") ? i18n.t('payment_package.package2_ja') : i18n.t('payment_package.package2'); contentList += ''; break; case 3: var content = (currentcy === "yen") ? i18n.t('payment_package.package3_ja') : i18n.t('payment_package.package3'); contentList += ''; break; case 4: var content = (currentcy === "yen") ? i18n.t('payment_package.package4_ja') : i18n.t('payment_package.package4'); contentList += ''; break; } $('#listPayPackage').html(contentList); }); $("form#validation input[name=paymentTerm]").on("change", function () { var paymentTerm = $("input[name=paymentTerm]:checked").val(); if (parseInt(paymentTerm) === 4) { $("#otherPaymentTerm").prop("disabled", false); } else { $("#otherPaymentTerm").prop("disabled", true); $("#otherPaymentTerm").val(''); } }); $("form#validation input[name=plan]").on("change", function () { if ($(this).is(':checked')) { $(this).parent().parent().parent().parent().parent().find('.active').removeClass('active'); $(this).parent().parent().parent().addClass('active'); } }); } function hasChangeElement() { if ($.trim(comNa) !== $.trim($('#companyName').val()) || $.trim(fiNa) !== $.trim($('#firstName').val()) || $.trim(laNa) !== $.trim($('#lastName').val()) || $.trim(phone) !== $.trim($('#phoneNumber').val()) || $.trim(password) !== $.trim($('#password').val()) || $.trim(department) !== $.trim($('#department').val()) || $.trim(email) !== $.trim($('#email').val()) || $.trim(address1) !== $.trim($('#address1').val()) || $.trim(city) !== $.trim($('#city').val()) || $.trim(state) !== $.trim($('#state').val()) || $.trim(country) !== $.trim($('#country').val()) || $.trim(zip) !== $.trim($('#zip').val()) || $.trim(usagePlan) !== $.trim($('input[name=plan]:checked').val())) { // || $.trim(billingCycle) !== $.trim($('#billingCycle').val()) HoGoUtils.enableButton('#btnSignup', {colorClass: 'green', isSubmitForm: true, formID: 'validation'}); return true; } else { HoGoUtils.disableButton('#btnSignup', {colorClass: 'green'}); return false; } } var signup = { doSignup: function () { if (!formStatus) return false; var post = {}; post["FirstName"] = $('#firstName').val(); post["CompanyName"] = $('#companyName').val(); post["MiddleName"] = $('#middleName').val(); post["LastName"] = $('#lastName').val(); post["PhoneNumber"] = $('#phoneNumber').val(); post["Email"] = $('#email').val(); var passHash = $('#password').val(); post["Password"] = HoGoUtils.MD5(passHash); post["Address1"] = $('#address1').val(); post["Address2"] = $('#address2').val(); post["City"] = $('#city').val(); post["State"] = $('#state').val(); post["Country"] = $('#country').val(); post["zip"] = $('#zip').val(); post["ReferralCode"] = HoGoUtils.getParameter()['code']; post["UsagePlan"] = $('input[name=plan]:checked').val(); post["billingCycle"] = $('#billingCycles').val(); post["Currentcy"] = $('#currentcy').val(); post["Lang"] = 'auto-' + HoGoUtils.detectBrowserLang(); return $.ajax({ type: "POST", url: "api/v1/SignupCompany", data: post, dataType: "json", beforeSend: function () { //Disable btn save HoGoUtils.disableButton('#btnSignup', {colorClass: 'green'}); //Display loader $("#validation .actionBar>.loader").show('fast'); }, success: function (data) { //Remove load $("#validation .actionBar>.loader").hide('slow'); var status = data.status; if (status === "OK") { redirectable = true; Modal.createModal(4, { title: i18n.t('registration.message.signup_success.title'), content: i18n.t('registration.message.signup_success.content'), okCallback: function (modal) { window.location.href = "http://www.hogodoc.com/enterprise"; } }); } else { if (status === APIConst.userAlreadyExistStatus) { Modal.createModal(2, { title: i18n.t('registration.message.exist_email.title'), content: i18n.t('registration.message.exist_email.content'), okCallback: function (modal) { HoGoUtils.enableButton('#validation', { colorClass: 'green', isSubmitForm: false, formID: 'validation' }); }, cancelCallback: function (modal) { HoGoUtils.enableButton('#validation', { colorClass: 'green', isSubmitForm: false, formID: 'validation' }); } }); } else { Modal.showAlert({content: "There are some errors occur"}); // HoGoUtils.enableButton('#validation', { // colorClass: 'green', // isSubmitForm: false, // formID: 'validation' // }); } } } }); } }; function isValidDistributor() { var post = {}; post["code"] = HoGoUtils.getParameter()['code']; if (post["code"] === undefined) { post["code"] = ""; } return $.ajax({ type: "POST", url: "api/v1/CheckDistributor", data: post, dataType: "json", success: function (data) { var status = data.status; if (status === "OK") { var reseller_info = data.reseller_info; isDistributor = true; $("#subpage_one").show(); $("#error-msg").hide(); currency = reseller_info.currentcy; reseller_name = reseller_info.reseller_name; //$('#lblBillingCycle').text(reseller_info.billing_cycle); var billingCycle = reseller_info.billing_cycle; var options = ''; for (var i = 0; i < billingCycle.length; i++) { if (billingCycle.charAt(i) === '1') { switch (i) { case 0: // 1 month options += ''; break; case 1: // 3 months options += ''; break; case 2: // 6 months options += ''; break; default: // 12 months or orther month(s) options += ''; break; } } } $('#billingCycles').html(options).selectmenu(); } else { $("#subpage_one").hide(); $("#error-msg").show(); isDistributor = false; } } }); } // get currentcy base on browser language function getCurrentcyBaseOnLanguage() { var lang = HoGoUtils.detectBrowserLang(); var currentcy = ""; switch (lang) { case "ja": currentcy = "yen"; break; case "usd": currentcy = "usd"; default : currentcy = "usd"; break; } return currentcy; } return { fStatus: false, dosignup: function () { signup.doSignup(); }, init: function () { HoGoUtils.renderNameBaseLang(HoGoUtils.getPageName(), i18n.lng()); var pName = HoGoUtils.getPageName(); // check valid distributor isValidDistributor().done(function () { if (isDistributor) { HoGoUtils.validateForm('validation'); if (pName === 'signupcom.html') { loadPaymentPackage(currency); $("#resseller_name").html(reseller_name); $("#policy_term").html(i18n.t('registration.label.term_policy')); // Set defaut country when lang is Japan if (i18n.lng() === "ja"){ $('#country').val("日本"); } $("#termsLink,#privacyLink").live('click', function (e) { e.preventDefault(); var title = $(this).text(); var url = $(this).prop('href'); var objModal = { title: title, size: 'large', content: '
' }; Modal.createModal(1, objModal); }); $(window).bind('beforeunload', function () { if (hasChangeElement() === true && redirectable === false) { return i18n.t('company.message.confirm_change_page'); } }); $('form#validation').find(':input').bind('keyup focusout', (function () { hasChangeElement(); })); $("#lang-ja").bind("click", function () { HoGoObjects.translateAndInitLogoutState("ja"); $('#country').val("日本"); }); $("#lang-en").bind("click", function () { HoGoObjects.translateAndInitLogoutState("en"); $('#country').val(""); }); } } }); } }; })(jQuery);