Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function isEmpty(value) {
- return angular.isUndefined(value) || "" === value || null === value || value !== value
- }
- var app = angular.module("quickShip", ["ngRoute", "ngResource", "ngStorage", "ngAnimate", "ui.bootstrap", "toggle-switch", "ngSanitize", "ngTagsInput", "ngDialog"]);
- angular.module("quickShip").config(["$routeProvider", "$httpProvider", "$anchorScrollProvider", "tagsInputConfigProvider", "$locationProvider", function($routeProvider, $httpProvider, $anchorScrollProvider, tagsInputConfigProvider, $locationProvider) {
- $routeProvider.when("/quickship", {
- title: "Personal information",
- templateUrl: window.Configure.base_url + "FRONTEND/js/modules/personal.html",
- controller: "PersonalCtrl"
- }).when("/new-shipment", {
- title: "Personal information",
- templateUrl: window.Configure.base_url + "FRONTEND/js/modules/personal.html",
- controller: "PersonalCtrl"
- }).when("/new-shipment/:param", {
- title: "Personal information",
- templateUrl: window.Configure.base_url + "FRONTEND/js/modules/personal.html",
- controller: "PersonalCtrl"
- }).when("/additional-options", {
- title: "Additional Options",
- templateUrl: window.Configure.base_url + "FRONTEND/js/modules/additional_options.html",
- controller: "AdditionalOptionsCtrl"
- }).when("/package-details", {
- title: "Package Details",
- templateUrl: window.Configure.base_url + "FRONTEND/js/modules/package_details.html",
- controller: "PackageDetailsCtrl"
- }).when("/shipment-rates", {
- title: "Shipment Rates",
- templateUrl: window.Configure.base_url + "FRONTEND/js/modules/shipment_rates.html",
- controller: "ShipmentRatesCtrl"
- }).when("/payment-options", {
- title: "Payment Options",
- templateUrl: window.Configure.base_url + "FRONTEND/js/modules/payment_options.html",
- controller: "PaymentOptionsCtrl"
- }).otherwise({
- redirectTo: "/quickship"
- }), $httpProvider.defaults.cache = !1, $httpProvider.defaults.headers.common["X-From-Angularjs"] = !0, $anchorScrollProvider.disableAutoScrolling(), tagsInputConfigProvider.setDefaults("tagsInput", {
- minLength: 1
- }), $locationProvider.html5Mode(!0)
- }]), angular.module("quickShip").controller("MainCtrl", ["$scope", "$rootScope", "$window", "QuickshipSvc", function($scope, $rootScope, $window, QuickshipSvc) {
- $scope.title = "MainCtrl", $scope.Configure = $window.Configure, $scope.quickship = QuickshipSvc, $rootScope.firstLoad = !0, $scope.init = function() {
- $scope.quickship.configure = $scope.Configure, $rootScope.firstLoad, $scope.quickship.loadSettings(), $rootScope.firstLoad = !1
- }, $scope.init()
- }]), angular.module("quickShip").controller("PersonalCtrl", ["$scope", "$location", "$window", function($scope, $location, $window) {
- $scope.title = "PersonalCtrl", $scope.$parent.quickship.currentStep = 1, $scope.goNext = function(theForm) {
- return theForm.$valid === !1 ? ($scope.$parent.quickship.validatesPersonalDetails = !1, !1) : ($scope.$parent.quickship.validatesPersonalDetails = !0, void $scope.$parent.quickship.updatePersonalInfo().then(function(res) {
- return $scope.$parent.quickship.$storage.personalDetailsCompleted = !0, $location.path("/additional-options")
- }, function(err) {
- alert("Error occurred: " + err)
- }))
- }, $scope.init = function() {
- $window.scrollTo(0, 0)
- }, $scope.init()
- }]), angular.module("quickShip").controller("AdditionalOptionsCtrl", ["$scope", "$location", "$window", function($scope, $location, $window) {
- $scope.title = "AdditionalOptionsCtrl", $scope.$parent.quickship.currentStep = 2, $scope.goPrev = function() {
- return $location.path("/")
- }, $scope.goNext = function(simpleSteps) {
- return $scope.$parent.quickship.$storage.simpleSteps = simpleSteps, $scope.$parent.quickship.$storage.quickship.amount = 1, $scope.$parent.quickship.$storage.quickship.packages = [{
- tracking_code: "",
- carrier: "",
- consolidated: [],
- weight_unit: "lb",
- size_unit: "in",
- items: [{
- description: "",
- weight_unit: "lb",
- price_value: null,
- info: ""
- }]
- }], $location.path("/package-details")
- }, $scope.init = function() {
- return null === $scope.$parent.quickship.$storage.simpleSteps ? ($location.path("/"), !0) : void $window.scrollTo(0, 0)
- }, $scope.init()
- }]), angular.module("quickShip").controller("PackageDetailsCtrl", ["$scope", "$location", "$window", "ngDialog", function($scope, $location, $window, ngDialog) {
- $scope.title = "PackageDetailsCtrl", $scope.$parent.quickship.currentStep = 3, $scope.countriesOfOrigin = [], $scope.activeDetailTab = 0, $scope.validationStarted = !1, $scope.getWeightTitle = function() {
- return $scope.$parent.quickship.consolidatePackages === !0 ? "Total Weight *" : "Weight *"
- }, $scope.goNext = function(frm) {
- if ($scope.validationStarted = !0, frm.$valid === !1) return $scope.$parent.quickship.validatesPackageDetails = !1, !1;
- if ($scope.validateWeights() === !1) return $scope.$parent.quickship.validatesPackageDetails = !1, !1;
- if ($scope.$parent.quickship.validatesPackageDetails = !0, $scope.$parent.quickship.$storage.simpleSteps)
- if ($scope.$parent.quickship.$storage.quickship.consolidatePackages) {
- var newPackagesNum, currentPackagesNum = $scope.$parent.quickship.$storage.quickship.packages.length;
- newPackagesNum = currentPackagesNum % 5 == 0 ? currentPackagesNum / 5 : Math.floor(currentPackagesNum / 5) + 1;
- for (var newPackages = [], smallPackageCount = 0, i = 0; i < newPackagesNum; i++) {
- for (var consolidated = [], items = [], weight = 0, j = 1; j <= 5 && (consolidated.push({
- tracking_code: $scope.$parent.quickship.$storage.quickship.packages[smallPackageCount].tracking_code,
- carrier: $scope.$parent.quickship.$storage.quickship.packages[smallPackageCount].carrier
- }), items = items.concat($scope.$parent.quickship.$storage.quickship.packages[smallPackageCount].items), weight += 1, smallPackageCount++, smallPackageCount != currentPackagesNum); j++);
- newPackages.push({
- weight_unit: "lb",
- size_unit: "in",
- weight: weight,
- length: 24,
- width: 14,
- height: 12,
- tracking_code: "",
- consolidated: [],
- items: []
- }), newPackages[i].consolidated = consolidated, newPackages[i].items = items
- }
- $scope.$parent.quickship.$storage.quickship.small_packages = $scope.$parent.quickship.$storage.quickship.packages, $scope.$parent.quickship.$storage.quickship.packages = newPackages
- } else angular.forEach($scope.$parent.quickship.$storage.quickship.packages, function(item) {
- item.consolidated = [], item.weight_unit = "lb", item.size_unit = "in", item.weight = 1, item.width = 6, item.height = 6, item.length = 6
- });
- else $scope.$parent.quickship.$storage.quickship.consolidatePackages && angular.forEach($scope.$parent.quickship.$storage.quickship.packages, function(pkg) {
- pkg.size_unit = "in", pkg.length = 24, pkg.width = 14, pkg.height = 12
- });
- return $location.path("/shipment-rates")
- }, $scope.goBack = function() {
- return $location.path("/additional-options")
- }, $scope.hasValidWeight = function(form, index) {
- return !!$scope.$parent.quickship.$storage.quickship.consolidatePackages || ($scope.validationStarted === !1 || !($scope.$parent.quickship.$storage.quickship.packages[index].weight < .01) && (!form["package_" + index + "_weight"].$error.required && void 0))
- }, $scope.validateWeights = function() {
- var is_valid = !0;
- return $scope.$parent.quickship.$storage.simpleSteps === !0 || (!!$scope.$parent.quickship.$storage.quickship.consolidatePackages || (angular.forEach($scope.$parent.quickship.$storage.quickship.packages, function(item) {
- if (parseFloat(item.weight) < .01) return !1
- }), is_valid))
- }, $scope.deleteItem = function(package_index, index) {
- $scope.$parent.quickship.$storage.quickship.packages[package_index].items.splice(index, 1)
- }, $scope.addItem = function(index) {
- $scope.$parent.quickship.$storage.quickship.packages[index].items.push({
- description: "",
- weight_unit: "lb",
- price_value: null
- })
- }, $scope.addPackage = function() {
- return $scope.$parent.quickship.addPackage()
- }, $scope.updateSimplePackages = function() {
- $scope.$parent.quickship.updateSimplePackages(), $scope.activeDetailTab = 0
- }, $scope.deletePackage = function(package_index) {
- $scope.$parent.quickship.$storage.quickship.packages.splice(package_index, 1), $scope.activeDetailTab = 0
- }, $scope.setActiveTab = function(tab_index) {
- $scope.activeDetailTab = tab_index
- }, $scope.hasInvalidTabData = function(package_index, form) {
- for (var count_items = $scope.$parent.quickship.$storage.quickship.packages[package_index].items.length, hasErrors = !1, i = 0; i < count_items; i++) "undefined" != typeof form["packages_" + package_index + "_items_" + i + "_country_id"] && form["packages_" + package_index + "_items_" + i + "_country_id"].$invalid === !0 && (hasErrors = !0), "undefined" != typeof form["packages_" + package_index + "_items_" + i + "_description"] && form["packages_" + package_index + "_items_" + i + "_description"].$invalid === !0 && (hasErrors = !0), "undefined" != typeof form["packages_" + package_index + "_items_" + i + "_quantity"] && form["packages_" + package_index + "_items_" + i + "_quantity"].$invalid === !0 && (hasErrors = !0), "undefined" != typeof form["packages_" + package_index + "_items_" + i + "_type_id"] && form["packages_" + package_index + "_items_" + i + "_type_id"].$invalid === !0 && (hasErrors = !0), "undefined" != typeof form["packages_" + package_index + "_items_" + i + "_value"] && form["packages_" + package_index + "_items_" + i + "_value"].$invalid === !0 && (hasErrors = !0), "undefined" != typeof form["packages_" + package_index + "_items_" + i + "_weight"] && form["packages_" + package_index + "_items_" + i + "_weight"].$invalid === !0 && (hasErrors = !0), "undefined" != typeof form["packages_" + package_index + "_items_" + i + "_weight_unit"] && form["packages_" + package_index + "_items_" + i + "_weight_unit"].$invalid === !0 && (hasErrors = !0);
- return hasErrors
- }, $scope.addConsolidatedPackage = function(package_index) {
- return $scope.$parent.quickship.addConsolidatedPackage(package_index)
- }, $scope.deleteConsolidatedPackage = function(package_index, index) {
- $scope.$parent.quickship.$storage.quickship.packages[package_index].consolidated.splice(index, 1), $scope.updateWeight(package_index)
- }, $scope.updateWeight = function(package_index) {
- var sum_weight = 0,
- sum_weight_unit = $scope.$parent.quickship.$storage.quickship.packages[package_index].weight_unit;
- angular.forEach($scope.$parent.quickship.$storage.quickship.packages[package_index].consolidated, function(value, index) {
- parseFloat(value.weight) && (sum_weight += $scope.$parent.quickship.calculateWeight(value.weight, value.unit, sum_weight_unit))
- }), $scope.$parent.quickship.$storage.quickship.packages[package_index].weight = sum_weight
- }, $scope.init = function() {
- return $scope.$parent.quickship.$storage.personalDetailsCompleted === !1 ? $location.path("/") : ("undefined" != typeof $scope.$parent.quickship.$storage.countries && null !== $scope.$parent.quickship.$storage.countries || $scope.$parent.quickship.loadSettings(), $scope.updateSimplePackages(), void $window.scrollTo(0, 0))
- }, $scope.init()
- }]), angular.module("quickShip").controller("ShipmentRatesCtrl", ["$scope", "$location", "$window", function($scope, $location, $window) {
- $scope.title = "ShipmentRatesCtrl", $scope.currentRateGroup = 0, $scope.orderBy = null, $scope.orderByReverse = !1, $scope.$parent.quickship.currentStep = 4, $scope.loadingRates = !1, $scope.oneAtTime = !1, $scope.isFirstOpen = !0, $scope.loadRates = function() {
- return null === $scope.$parent.quickship.$storage.quickship.packages[0].items[0].price_value ? $location.path("/") : ($scope.loadingRates = !0, void $scope.$parent.quickship.loadRates().then(function() {
- $scope.loadingRates = !1
- }, function() {
- return alert("ERROR: Unable to get shipping rates. Try again in a few seconds"), $scope.loadingRates = !1, $location.path("/package-details")
- }))
- }, $scope.goNext = function() {
- return $location.path("/payment-options")
- }, $scope.goBack = function() {
- return $scope.$parent.quickship.$storage.simpleSteps && $scope.$parent.quickship.$storage.quickship.consolidatePackages && ($scope.$parent.quickship.$storage.quickship.packages = $scope.$parent.quickship.$storage.quickship.small_packages), $location.path("/package-details")
- }, $scope.init = function() {
- return "undefined" == typeof $scope.$parent.quickship.$storage.billing.email || null === $scope.$parent.quickship.$storage.billing.email ? $location.path("/") : ($scope.loadRates(), void $window.scrollTo(0, 0))
- }, $scope.init()
- }]), angular.module("quickShip").controller("PaymentOptionsCtrl", ["$scope", "$location", "$window", "ngDialog", function($scope, $location, $window, ngDialog) {
- $scope.title = "PaymentOptionsCtrl", $scope.$parent.quickship.currentStep = 5, $scope.openTermsConditionsDialog = function() {
- ngDialog.open({
- template: window.Configure.base_url + "FRONTEND/js/modules/terms_and_conditions.html",
- className: "ngdialog-theme-default custom-width"
- })
- }, $scope.goBack = function() {
- return $scope.$parent.quickship.$storage.simpleSteps ? $location.path("/package-details") : $location.path("/shipment-rates")
- }, $scope.init = function() {
- return null === $scope.$parent.quickship.$storage.quickship.packages[0].items[0].price_value ? $location.path("/") : void $window.scrollTo(0, 0)
- }, $scope.init()
- }]), angular.module("quickShip").controller("YourUsAddressCtrl", ["$scope", "$window", function($scope, $window) {
- $scope.name = "YourUsAddressCtrl", $scope.$parent.quickship.currentStep = 6, $scope.init = function() {
- $scope.$parent.quickship.address.first_name = $scope.$parent.quickship.$storage.user.first_name, $scope.$parent.quickship.address.last_name = $scope.$parent.quickship.$storage.user.last_name, $scope.$parent.quickship.address.address1 = $scope.$parent.quickship.$storage.address1, $scope.$parent.quickship.address.address2 = $scope.$parent.quickship.$storage.address2, $scope.$parent.quickship.address.address3 = $scope.$parent.quickship.$storage.address3, $scope.$parent.quickship.reset(), $window.scrollTo(0, 0)
- }, $scope.init()
- }]), angular.module("quickShip").directive("ngMin", function() {
- return {
- restrict: "A",
- require: "ngModel",
- link: function(scope, elem, attr, ctrl) {
- scope.$watch(attr.ngMin, function() {
- ctrl.$setViewValue(ctrl.$viewValue)
- });
- var minValidator = function(value) {
- var min = scope.$eval(attr.ngMin) || 0;
- return !isEmpty(value) && value < min ? void ctrl.$setValidity("ngMin", !1) : (ctrl.$setValidity("ngMin", !0), value)
- };
- ctrl.$parsers.push(minValidator), ctrl.$formatters.push(minValidator)
- }
- }
- }), angular.module("quickShip").directive("magicField", function($compile, $timeout) {
- return {
- scope: {},
- template: '<div class="field"></div>',
- transclude: !0,
- replace: !0,
- restrict: "E",
- controller: function($scope, $element) {
- $scope.showLabel = !1
- },
- link: function(scope, element, attrs, ctrl, transclude) {
- transclude(scope, function(clone, scope) {
- element.append(clone)
- });
- var input = element.find("input")[0] || element.find("textarea")[0] || element.find("select")[0];
- element.find("label")[0];
- input = angular.element(input), input.on("focus blur keyup", function(e) {
- "focus" == e.type ? (scope.showLabel = !0, input.attr("placeholder", "")) : "blur" === e.type ? scope.showLabel = !0 : input.val().length > 0 ? (scope.showLabel = !0, input.attr("placehoder", "")) : scope.showLabel = !0, $timeout(function() {
- scope.$apply()
- }, 0)
- })
- }
- }
- }), angular.module("quickShip").directive("plusPrefix", function() {
- return {
- restrict: "A",
- scope: {
- ngModel: "="
- },
- link: function(scope, element, attrs, controller) {
- element.bind("keyup change focus", function() {
- scope.$apply(function() {
- "undefined" == typeof scope.ngModel && (scope.ngModel = ""), scope.ngModel = scope.ngModel.replace("+", ""), scope.ngModel.length >= 0 && (scope.ngModel = "+" + scope.ngModel.replace(/[^\d]/g, ""))
- })
- })
- }
- }
- }), angular.module("quickShip").directive("moneyPrefix", function() {
- return {
- restrict: "A",
- scope: {
- ngModel: "="
- },
- link: function(scope, element, attrs, controller) {
- element.bind("keyup change focus", function() {
- scope.$apply(function() {
- return "undefined" == typeof scope.ngModel || null == scope.ngModel ? (scope.ngModel = "", !1) : (scope.ngModel = scope.ngModel.replace("$", ""), void(scope.ngModel.length >= 0 && (scope.ngModel = "$" + scope.ngModel.replace(/[^\d.]/g, ""))))
- })
- })
- }
- }
- }), angular.module("quickShip").directive("dynamicName", function($compile, $parse) {
- return {
- restrict: "A",
- terminal: !0,
- priority: 1e5,
- link: function(scope, elem) {
- var name = $parse(elem.attr("dynamic-name"))(scope);
- elem.removeAttr("dynamic-name"), elem.attr("name", name), $compile(elem)(scope)
- }
- }
- }), angular.module("quickShip").config(["$provide", function($provide) {
- $provide.decorator("ngModelDirective", function($delegate) {
- var ngModel = $delegate[0],
- controller = ngModel.controller;
- return ngModel.controller = ["$scope", "$element", "$attrs", "$injector", function(scope, element, attrs, $injector) {
- var $interpolate = $injector.get("$interpolate");
- attrs.$set("name", $interpolate(attrs.name || "")(scope)), $injector.invoke(controller, this, {
- $scope: scope,
- $element: element,
- $attrs: attrs
- })
- }], $delegate
- }), $provide.decorator("formDirective", function($delegate) {
- var form = $delegate[0],
- controller = form.controller;
- return form.controller = ["$scope", "$element", "$attrs", "$injector", function(scope, element, attrs, $injector) {
- var $interpolate = $injector.get("$interpolate");
- attrs.$set("name", $interpolate(attrs.name || attrs.ngForm || "")(scope)), $injector.invoke(controller, this, {
- $scope: scope,
- $element: element,
- $attrs: attrs
- })
- }], $delegate
- })
- }]), jQuery("dl.accordion dt").click(function() {
- jQuery(this).toggleClass("active")
- }), angular.module("quickShip").service("QuickshipSvc", ["$http", "$q", "$localStorage", "$rootScope", function($http, $q, $localStorage, $rootScope) {
- var service = this;
- return service.configure = null, service.currentStep = 1, service.processingPayment = !1, service.settingsLoaded = !1, service.validatesPersonalDetails = !0, service.validatesPackageDetails = !0, service.shippingRatesSelected = [], service.address = {}, service.defaultOptions = {
- shippingRates: [],
- shippingRatesSelected: [],
- billing_shipping: !0,
- simpleSteps: !0,
- personalDetailsCompleted: !1,
- countries: null,
- itemTypes: null,
- transactionHash: null,
- payment_type: "Paypal",
- billing: {
- first_name: "",
- last_name: "",
- phone: "",
- address2: ""
- },
- shipping: {
- address2: ""
- },
- quickship: {
- special_instructions: "",
- shipping_options: {
- cheapest: !1,
- fastest: !1
- },
- packagesExpedited: !1,
- repackaged: !1,
- packagesInsurance: !1,
- consolidatePackages: !1,
- requestPhoto: !1,
- amount: 1,
- packages: [{
- tracking_code: "",
- consolidated: [],
- weight_unit: "lb",
- size_unit: "in",
- items: [{
- description: "",
- weight_unit: "lb",
- price_value: null,
- info: ""
- }]
- }]
- }
- }, service.$storage = $localStorage.$default(service.defaultOptions), service.updateSimplePackages = function() {
- if (service.$storage.simpleSteps) {
- var currentPackagesNum = service.$storage.quickship.packages.length,
- newPackagesNum = service.$storage.quickship.amount,
- diff = newPackagesNum - currentPackagesNum;
- if (newPackagesNum < 1) return !1;
- if (newPackagesNum < currentPackagesNum) service.$storage.quickship.packages.splice(newPackagesNum, Math.abs(diff));
- else if (diff > 0)
- for (var i = 0; i < diff; i++) service.$storage.quickship.packages.push({
- items: [{
- description: "",
- weight_unit: "lb",
- price_value: null,
- info: ""
- }]
- })
- }
- }, service.loadSettings = function() {
- service.loadSettingsApi().then(function(res) {
- if (service.$storage.read_only_packages = res.read_only_packages, res.read_only_packages && null != res.transaction && "" != res.transaction.Transaction.id)
- for (service.$storage.quickship.packages = [], i = 0; i < res.transaction.Shipment.length; i++) service.$storage.quickship.packages.push({
- tracking_code: res.transaction.Shipment[i].Package.in_tracking,
- consolidated: !1,
- carrier: res.transaction.Shipment[i].Package.carrier,
- weight_unit: "" != res.transaction.Shipment[i].Package.weight_lb ? "lb" : "kg",
- size_unit: "" != res.transaction.Shipment[i].Package.width_in ? "in" : "cm",
- weight: "" != res.transaction.Shipment[i].Package.weight_lb ? res.transaction.Shipment[i].Package.weight_lb : res.transaction.Shipment[i].Package.weight_in,
- width: "" != res.transaction.Shipment[i].Package.width_in ? res.transaction.Shipment[i].Package.width_in : res.transaction.Shipment[i].Package.width_cm,
- height: "" != res.transaction.Shipment[i].Package.height_in ? res.transaction.Shipment[i].Package.height_in : res.transaction.Shipment[i].Package.height_cm,
- length: "" != res.transaction.Shipment[i].Package.length_in ? res.transaction.Shipment[i].Package.length_in : res.transaction.Shipment[i].Package.length_cm,
- items: [{
- description: "",
- weight_unit: "lb",
- price_value: null,
- info: ""
- }]
- });
- if (null != res.user && "" != res.user.User.id) {
- console.log(res);
- service.$storage.billing.first_name = res.user.User.first_name, service.$storage.billing.last_name = res.user.User.last_name, service.$storage.billing.email = res.user.User.email, service.$storage.billing.phone = res.user.User.phone;
- var billing_index = null,
- shipping_index = null;
- if (1 === res.user.Address.length) billing_index = 0, shipping_index = null;
- else if (res.user.Address.length > 1)
- for (2 === res.user.Address[0].address_type_id ? (billing_index = 0, shipping_index = 1) : (shipping_index = 0, billing_index = 1), i = 0; i < res.user.Address.length; i++) 1 == res.user.Address[i].default_billing && (billing_index = i), 1 == res.user.Address[i].default_shipping && (shipping_index = i);
- null != billing_index && (service.$storage.billing.address1 = res.user.Address[billing_index].address1, service.$storage.billing.address2 = res.user.Address[billing_index].address2, service.$storage.billing.city = res.user.Address[billing_index].city, service.$storage.billing.state = res.user.Address[billing_index].adm_division, service.$storage.billing.postal_code = res.user.Address[billing_index].postal_code, service.$storage.billing.country = res.user.Address[billing_index].country_id, service.$storage.billing_shipping = null == shipping_index, null != shipping_index && (service.$storage.shipping.first_name = res.user.Address[shipping_index].firstname, service.$storage.shipping.last_name = res.user.Address[shipping_index].lastname, service.$storage.shipping.address1 = res.user.Address[shipping_index].address1, service.$storage.shipping.address2 = res.user.Address[shipping_index].address2, service.$storage.shipping.city = res.user.Address[shipping_index].city, service.$storage.shipping.state = res.user.Address[shipping_index].adm_division, service.$storage.shipping.postal_code = res.user.Address[shipping_index].postal_code, service.$storage.shipping.country = res.user.Address[shipping_index].country_id, service.$storage.shipping.email = res.user.User.email, service.$storage.shipping.phone = res.user.User.phone))
- }
- service.$storage.countries = res.countries, service.$storage.itemTypes = res.item_types, service.$storage.handling_fee = res.handling_fee, service.settingsLoaded = !0, $rootScope.$broadcast("event:loaded-api")
- }, function(err) {
- alert("Error occurred: " + err)
- })
- }, service.loadSettingsApi = function() {
- var defer = $q.defer();
- return $http.post(service.configure.base_url + "quickship/api_settings.json", null).success(function(res) {
- defer.resolve(res)
- }).error(function(err) {
- defer.reject(err)
- }), defer.promise
- }, service.updatePersonalInfo = function() {
- var defer = $q.defer();
- return $http.post(service.configure.base_url + "quickship/step1.json", service.$storage).success(function(res) {
- defer.resolve(res)
- }).error(function(err) {
- defer.reject(err)
- }), defer.promise
- }, service.addPackage = function() {
- return service.$storage.quickship.packages.push({
- consolidated: [],
- weight_unit: "lb",
- size_unit: "in",
- items: [{
- description: "",
- weight_unit: "lb",
- price_value: null,
- info: ""
- }]
- })
- }, service.addConsolidatedPackage = function(package_index) {
- var currentItemsNum = service.$storage.quickship.packages[package_index].consolidated.length,
- defaultData = {
- weight: null,
- unit: "lb"
- };
- currentItemsNum < 5 ? service.$storage.quickship.packages[package_index].consolidated.push(defaultData) : (service.addPackage(), service.$storage.quickship.packages[service.$storage.quickship.packages.length - 1].consolidated.push(defaultData))
- }, service.cleanupConsolidated = function() {
- angular.forEach(service.$storage.quickship.packages, function(value, index) {
- service.$storage.quickship.packages[index].consolidated = []
- })
- }, service.updateConsolidated = function() {
- service.$storage.quickship.consolidatePackages === !1 && service.cleanupConsolidated()
- }, service.loadRates = function() {
- var defer = $q.defer();
- return service.$storage.shippingRates = [], service.$storage.shippingRatesSelected = [], $http.post(service.configure.base_url + "quickship/api_rates.json", service.$storage).success(function(res) {
- "object" == typeof res && (service.$storage.shippingRates = res), defer.resolve(res)
- }).error(function(err) {
- defer.reject(err)
- }), defer.promise
- }, service.pay_handling = function() {
- var params = {
- description: "Package handling fee",
- price: service.$storage.handling_fee,
- steps: service.simpleSteps === !0 ? "simple" : "full",
- shipment: service.$storage
- };
- service.processingPayment = !0, $http.post(service.configure.base_url + "quickship/payment.json", params).success(function(res) {
- setTimeout(function(){
- console.log('done');
- res.ok ? window.location = res.approval_link : (alert("Error, please try again"), service.processingPayment = !1)
- }, 7000);
- }).error(function(err) {
- alert("Error, please try again"), service.processingPayment = !1
- })
- }, service.isSelectedItem = function(key, selected_id) {
- return key == selected_id
- }, service.getSimpleStepsAmountMin = function(amount) {
- return service.$storage.simpleSteps === !0 && amount
- }, service.selectService = function(package_index, shipping_rate) {
- service.$storage.shippingRatesSelected[package_index] = {
- package: package_index,
- shipping_rate_id: shipping_rate.rate_id,
- shipment_id: shipping_rate.shipment_id,
- rate: shipping_rate,
- price: shipping_rate.rate,
- price_num: shipping_rate.rate_num
- }, service.$storage.quickship.packages.length > package_index + 1 ? (document.getElementById("divPackage" + (package_index + 1)).scrollIntoView(), angular.element($(".step-4")).scope().currentRateGroup = package_index + 1) : console.log(service.$storage)
- }, service.getShippingCharge = function() {
- if (service.$storage.simpleSteps === !0) return service.$storage.handling_fee;
- var total = 0;
- return service.$storage.shippingRatesSelected.length > 0 && angular.forEach(service.$storage.shippingRatesSelected, function(value) {
- var price = parseFloat(value.price.replace(" USD", ""));
- total += price
- }), service.$storage.quickship.packagesInsurance === !0 && (total += .01 * total), total
- }, service.hasConsolidatedPackages = function(index) {
- var has_consolidated = !1;
- return "undefined" != typeof service.$storage.quickship.packages[index] && "undefined" != typeof service.$storage.quickship.packages[index].consolidated && service.$storage.quickship.packages[index].consolidated.length > 0 && (has_consolidated = !0), has_consolidated
- }, service.cleanup = function() {
- var personal_info = service.$storage.user,
- billing = service.$storage.billing,
- shipping = service.$storage.shipping;
- service.reset(), service.$storage.user = personal_info, service.$storage.billing = billing, service.$storage.shipping = shipping
- }, service.calculateHandlingFee = function() {
- var amount = 0;
- return angular.forEach(service.$storage.quickship.packages, function(value, index) {
- amount++
- }), service.$storage.handling_fee * amount
- }, service.calculateTotal = function() {
- let totalAmount = 0;
- for (i = 0; i < service.$storage.shippingRatesSelected.length; i++){
- totalAmount = service.$storage.shippingRatesSelected[i].price_num + totalAmount;
- }
- return totalAmount.toFixed(2);
- }, service.calculateWeight = function(orig_weight, orig_weight_unit, dest_weight_unit) {
- if (!parseFloat(orig_weight)) return 0;
- if (orig_weight = parseFloat(orig_weight), orig_weight_unit === dest_weight_unit) return orig_weight;
- var new_amount = "lb" === dest_weight_unit ? 2.2046 * orig_weight : orig_weight / 2.2046;
- return new_amount = +(Math.round(new_amount + "e+2") + "e-2")
- }, service.reset = function() {
- service.$storage.$reset(), service.$storage = $localStorage.$default(service.defaultOptions)
- }, service
- }]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement