{"version":3,"names":[],"mappings":"","sources":["my-order/my-order-controller.js"],"sourcesContent":["(function() {\r\n 'use strict';\r\n\r\n /**\r\n * @ngdoc object\r\n * @name myOrder.controller:MyOrderCtrl\r\n *\r\n * @description\r\n *\r\n */\r\n angular\r\n .module('myOrder')\r\n .controller('MyOrderCtrl', MyOrderCtrl);\r\n\r\n function MyOrderCtrl($scope, $rootScope, consts, $sce, $mdDialog, $timeout, MyOrder, App) {\r\n $rootScope.pageTitle = \"ההזמנה שלי\";\r\n $scope.currentOrder = MyOrder.getOrder();\r\n\r\n $scope.minDate = new Date();\r\n $scope.maxDate = undefined;\r\n\r\n $scope.paymentData = $scope.getItemFromLocalStorage(\"paymentData\");\r\n\r\n\r\n $scope.user = $scope.getItemFromLocalStorage(\"userDetails\");\r\n\r\n if ($scope.user == undefined) $scope.user = {};\r\n\r\n $scope.updateUserDetails = function(valid) {\r\n if (!valid) return;\r\n $scope.orderStep++;\r\n\r\n if ($scope.user.Address != undefined && typeof($scope.user.Address) != \"string\") {\r\n var place = getDataFromGooglePlaceObject($scope.user.Address);\r\n $scope.user.Longitude = place.Longitude;\r\n $scope.user.Latitude = place.Latitude;\r\n $scope.user.Address = place.Address;\r\n }\r\n $scope.setItemInLocalStorage(\"userDetails\", $scope.user);\r\n App.updateUserDetails($scope.user);\r\n }\r\n\r\n $scope.payAndOrder = function() {\r\n $scope.orderStep = 1;\r\n //$scope.currentOrder.time = new Date();\r\n\r\n $scope.currentOrder.orderType = 'delivery';\r\n\r\n if ($scope.currentOrder.orderTypeTime == undefined) {\r\n $scope.currentOrder.orderTypeTime = 'now';\r\n }\r\n var loginToken = $scope.getItemFromLocalStorage(\"loginToken\");\r\n //$scope.currentOrder.totalPrice\r\n $scope.tranzilaIframe = $sce.trustAsResourceUrl(\"https://direct.tranzila.com/\" + consts.tranzilaUsername + \"/iframe.php\" + \"?sum=\" + $scope.currentOrder.totalPrice + \"¤cy=1&cred_type=1&tranmode=AK&pdesc=\" + consts.franchiseId + \"&franchiseId=\" + consts.franchiseId + \"&userLoginToken=\" + loginToken);\r\n\r\n $mdDialog.show({\r\n templateUrl: 'order-steps/steps.html',\r\n scope: $scope,\r\n preserveScope: true\r\n });\r\n }\r\n\r\n window.iframeLoad = function(iframe) {\r\n console.log(\"iframeLoad\");\r\n console.log($(\"#tranzilaIframe\")[0].contentWindow.location.search);\r\n\r\n if ($(\"#tranzilaIframe\")[0].contentWindow.location.search.indexOf(\"TranzilaTK\") != -1) {\r\n console.log(\"GOOD\");\r\n\r\n var params = $(\"#tranzilaIframe\")[0].contentWindow.location.search.split(\"&\");\r\n\r\n\r\n var tranzilaToken = _.find(params, function(e) {\r\n return e.indexOf(\"TranzilaTK\") != -1\r\n });\r\n tranzilaToken = tranzilaToken.split(\"TranzilaTK=\");\r\n tranzilaToken = tranzilaToken[tranzilaToken.length - 1];\r\n\r\n var expyear = _.find(params, function(e) {\r\n return e.indexOf(\"expyear\") != -1\r\n });\r\n expyear = expyear.split(\"expyear=\");\r\n expyear = expyear[expyear.length - 1];\r\n if (expyear.length == 1) {\r\n expyear = \"0\" + expyear;\r\n }\r\n\r\n var expmonth = _.find(params, function(e) {\r\n return e.indexOf(\"expmonth\") != -1\r\n });\r\n expmonth = expmonth.split(\"expmonth=\");\r\n expmonth = expmonth[expmonth.length - 1];\r\n if (expmonth.length == 1) {\r\n expmonth = \"0\" + expmonth;\r\n }\r\n\r\n var paymentData = {\r\n tranzilaToken: tranzilaToken,\r\n expdate: expmonth + expyear\r\n }\r\n\r\n var loginToken = $scope.getItemFromLocalStorage(\"loginToken\");\r\n $scope.setItemInLocalStorage(\"paymentData\", paymentData);\r\n\r\n MyOrder.paymentRequest($scope.currentOrder, loginToken, tranzilaToken, expmonth + expyear, $scope.user).then(function(response) {\r\n $scope.paymentCallBack(response);\r\n });\r\n }\r\n }\r\n\r\n $scope.showTimePicker = function(ev) {\r\n // $scope.currentOrder.orderTypeTime = \"future\";\r\n document.getElementById('takeawayTimepicker').dispatchEvent(new Event('focus'));\r\n }\r\n\r\n\r\n $scope.branchChanged = function(branch) {\r\n if (!branch.IsOpen) {\r\n // $scope.currentOrder.orderType = 'takeaway';\r\n $scope.currentOrder.orderTypeTime = \"future\";\r\n $scope.currentOrder.time = getDateTimeFromTimeStr($scope.currentOrder.branch.OpeningTime);\r\n $scope.minDate = getDateTimeFromTimeStr($scope.currentOrder.branch.OpeningTime);\r\n $scope.maxDate = getDateTimeFromTimeStr($scope.currentOrder.branch.ClosingTime);\r\n\r\n } else {\r\n $scope.minDate = new Date();\r\n $scope.currentOrder.time = new Date();\r\n $scope.maxDate = getDateTimeFromTimeStr($scope.currentOrder.branch.ClosingTime);\r\n }\r\n var timeToAdd = $scope.currentOrder.orderType == 'delivery' ? $scope.currentOrder.branch.DeliveryTimeInMinutes : $scope.currentOrder.branch.TakeawayTimeInMinutes;\r\n $scope.minDate.setMinutes($scope.minDate.getMinutes() + timeToAdd);\r\n $scope.currentOrder.time.setMinutes($scope.currentOrder.time.getMinutes() + timeToAdd);\r\n }\r\n\r\n $scope.setOrderType = function(type) {\r\n $scope.currentOrder.orderType = type;\r\n\r\n //Order type changed - min time to delivery changed (takeaway or delivery)\r\n if (!$scope.currentOrder.branch.IsOpen) {\r\n $scope.minDate = getDateTimeFromTimeStr($scope.currentOrder.branch.OpeningTime);\r\n $scope.currentOrder.time = getDateTimeFromTimeStr($scope.currentOrder.branch.OpeningTime);\r\n } else {\r\n $scope.minDate = new Date();\r\n $scope.currentOrder.time = new Date();\r\n }\r\n\r\n var timeToAdd = $scope.currentOrder.orderType == 'delivery' ? $scope.currentOrder.branch.DeliveryTimeInMinutes : $scope.currentOrder.branch.TakeawayTimeInMinutes;\r\n $scope.currentOrder.time.setMinutes($scope.currentOrder.time.getMinutes() + timeToAdd);\r\n $scope.minDate.setMinutes($scope.minDate.getMinutes() + timeToAdd);\r\n\r\n }\r\n\r\n var animationTimeout = undefined;\r\n\r\n $scope.nextOrderStep = function(clickedOrderStep) {\r\n if (clickedOrderStep == undefined) {\r\n $scope.orderStep++;\r\n } else {\r\n if (clickedOrderStep < $scope.orderStep) $scope.orderStep = clickedOrderStep; //Cant skip steps\r\n }\r\n //If 'credit' goes to iframe and the n pay.\r\n if ($scope.orderStep == 4 && $scope.currentOrder.payment != 'credit') {\r\n var loginToken = $scope.getItemFromLocalStorage(\"loginToken\");\r\n\r\n if ($scope.paymentData == undefined) $scope.paymentData = {};\r\n\r\n MyOrder.paymentRequest($scope.currentOrder, loginToken, $scope.paymentData.tranzilaToken, $scope.paymentData.expdate, $scope.user).then(function(response) {\r\n $scope.paymentCallBack(response);\r\n });\r\n }\r\n }\r\n\r\n $scope.paymentCallBack = function(response) {\r\n var now = new Date()\r\n $scope.currentOrder.ordered = true;\r\n $rootScope.$broadcast(\"itemAddedToOrder\",0)\r\n $scope.currentOrder.orderedDate = now.toLocaleDateString(\"pt\");\r\n $scope.currentOrder.orderedTime = now.toLocaleTimeString(\"pt\");\r\n $scope.currentOrder.payment = 'creditSuccess';\r\n\r\n if ($scope.currentOrder.branch.IsOpen) {\r\n $scope.currentOrder.estimatedTime = $scope.currentOrder.orderType == 'delivery' ? $scope.currentOrder.branch.DeliveryTimeInMinutes : $scope.currentOrder.branch.TakeawayTimeInMinutes;\r\n } else {\r\n $scope.currentOrder.estimatedTime = $scope.currentOrder.time.toLocaleTimeString(\"pt\");\r\n }\r\n animationTimeout = $timeout(function() {\r\n $scope.slideUp();\r\n $scope.hideDialog();\r\n }, 5000);\r\n }\r\n\r\n\r\n $scope.removeItemFromOrder = function(item, index) {\r\n MyOrder.removeItemFromOrder(item, index);\r\n }\r\n\r\n $scope.addOne = function(item, index) {\r\n MyOrder.addItemAmount(index);\r\n }\r\n $scope.removeOne = function(item, index) {\r\n if (item.amount == 1) return;\r\n MyOrder.subItemAmount(index);\r\n }\r\n\r\n var getDateTimeFromTimeStr = function(time) {\r\n var dateTime = new Date();\r\n if (time != undefined && time.indexOf(\":\") >= 0) {\r\n dateTime = new Date(dateTime.setMinutes(time.split(\":\")[1]));\r\n dateTime = new Date(dateTime.setHours(time.split(\":\")[0]));\r\n return dateTime;\r\n }\r\n return undefined;\r\n }\r\n\r\n var minutesOfDay = function(date) {\r\n return date.getMinutes() + date.getHours() * 60;\r\n }\r\n\r\n var getDataFromGooglePlaceObject = function(place) {\r\n if (place == undefined || place.geometry == undefined) return {};\r\n return {\r\n Longitude: place.geometry.location.lng(),\r\n Latitude: place.geometry.location.lat(),\r\n Address: place.formatted_address\r\n }\r\n }\r\n\r\n $scope.$on(\"$destroy\", function() {\r\n if (animationTimeout) {\r\n $timeout.cancel(animationTimeout);\r\n }\r\n });\r\n\r\n if ($scope.branches.length == 1) {\r\n $scope.currentOrder.branch = $scope.branches[0];\r\n $scope.branchChanged($scope.currentOrder.branch);\r\n }\r\n\r\n }\r\n}());\r\n"],"file":"my-order-controller.js"}