Files
apps.supersamsev.ru/webroot/js/ordersInfoController.js
T

1 line
8.4 KiB
JavaScript

"use strict";function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor))throw new TypeError("Cannot call a class as a function")}function _defineProperties(target,props){for(var descriptor,i=0;i<props.length;i++)descriptor=props[i],descriptor.enumerable=descriptor.enumerable||!1,descriptor.configurable=!0,"value"in descriptor&&(descriptor.writable=!0),Object.defineProperty(target,descriptor.key,descriptor)}function _createClass(Constructor,protoProps,staticProps){return protoProps&&_defineProperties(Constructor.prototype,protoProps),staticProps&&_defineProperties(Constructor,staticProps),Constructor}supersamApp.controller("OrdersInfoController",["$scope","$http","$timeout","localStorageService","$filter","config","$interval",function($scope,$http,$timeout,localStorageService,$filter,config,$interval){var ordersInfoApp;return ordersInfoApp=function(){var ordersInfoApp=/*#__PURE__*/function(){function ordersInfoApp(){_classCallCheck(this,ordersInfoApp),this.cleanup=this.cleanup.bind(this),this.changePhone=this.changePhone.bind(this),this.processSearchResponse=this.processSearchResponse.bind(this),this.pageReload=this.pageReload.bind(this),this.setCookie=this.setCookie.bind(this),this.searchOrders=this.searchOrders.bind(this),this.clearConfirmCodeResendTimeoutPromise=this.clearConfirmCodeResendTimeoutPromise.bind(this),this.startConfirmCodeResendTimeout=this.startConfirmCodeResendTimeout.bind(this),this.tryToAuthorizePhone=this.tryToAuthorizePhone.bind(this),$scope.utilities.showContentOnLoad(),config.isPhoneAuthorized&&(config.sortFields={ordersList:{field:"created",direction:"desc"}},this.searchOrders())}return _createClass(ordersInfoApp,[{key:"cleanup",value:function cleanup(){return this.errors=[],this.isSubmitting=!1,this.warnings=[]}},{key:"changePhone",value:function changePhone(){return this.setCookie("oip","",-1),this.pageReload()}},{key:"processSearchResponse",value:function processSearchResponse(data){var _Mathmax=Math.max,_Mathceil=Math.ceil;return this.errors=[],this.ordersList=data.ordersList,this.totalOrders=data.totalOrders,this.ordersTotalSum=data.ordersTotalSum,this.pagination.totalItems=data.totalOrders,this.pagination.totalPages=1>this.pagination.numPerPage?1:_Mathceil(this.pagination.totalItems/this.pagination.numPerPage),this.pagination.totalPages=_Mathmax(this.pagination.totalPages||0,1),$timeout(function(){return angular.element("body").scrollTo("#table-order-payment-head",50,{offset:{top:-300}})})}},{key:"pageReload",value:function pageReload(){return window.location.reload()}},{key:"setCookie",value:function setCookie(name,value,days){var date,expires;return expires="",days&&(date=new Date,date.setTime(date.getTime()+1e3*(60*(60*(24*days)))),expires="; expires="+date.toUTCString()),document.cookie=name+"="+(value||"")+expires+"; path=/"}},{key:"searchOrders",value:function searchOrders(){var dataToSend,_this=this;if(!this.isSubmitting)return this.isSubmitting=!0,dataToSend={action:"searchOrders",currentPage:this.pagination.currentPage,numPerPage:this.pagination.numPerPage,sortFields:config.sortFields.ordersList},$http.post(config.ordersInfoUrl,dataToSend).then(function(response){var data;if(data=response.data,_this.isSubmitting=!1,data)return data.isPhoneAuthorized?data.status&&"success"===data.status?_this.processSearchResponse(data):data.errors&&data.errors.length?_this.errors=data.errors:_this.errors=[config.global_labels.defaultErrorMessage.value]:(toastr.warning("\u041F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u0435\u043B\u044C \u043D\u0435 \u0430\u0432\u0442\u043E\u0440\u0438\u0437\u043E\u0432\u0430\u043D!"),$timeout(function(){return _this.setCookie("oip","",-1),_this.pageReload()},1200))})["catch"](function(response){return _this.errors=response.data&&response.data.errors?response.data.errors:[config.global_labels.defaultErrorMessage.value],_this.isSubmitting=!1})}},{key:"clearConfirmCodeResendTimeoutPromise",value:function clearConfirmCodeResendTimeoutPromise(){if(this.confirmCodeResendTimeoutPromise)return $interval.cancel(this.confirmCodeResendTimeoutPromise),this.confirmCodeResendTimeoutPromise=null}},{key:"startConfirmCodeResendTimeout",value:function startConfirmCodeResendTimeout(){var _this2=this;return this.confirmCodeResendTimeoutPromise=$interval(function(){if(_this2.confirmCodeResendTimeout--,0>=_this2.confirmCodeResendTimeout)return _this2.clearConfirmCodeResendTimeoutPromise()},1e3)}},{key:"tryToAuthorizePhone",value:function tryToAuthorizePhone(step){var dataToSend,_this3=this,cleanupConfirmCodeHash=!(1<arguments.length&&void 0!==arguments[1])||arguments[1];switch(step){case"enterPhone":if(!this.isSubmitting)return this.isSubmitting=!0,this.errors=[],this.confirmCode="",cleanupConfirmCodeHash&&(this.confirmCodeHash=""),this.tooManyCodeInputRetries=!1,this.confirmCodeResendTimeout=0,this.clearConfirmCodeResendTimeoutPromise(),dataToSend={action:"sendConfirmCode",phoneToAuthorize:this.phoneToAuthorize,confirmCodeHash:this.confirmCodeHash},$http.post(config.ordersInfoAuthUrl,dataToSend).then(function(response){var data;if(data=response.data,_this3.isSubmitting=!1,data){if(!(data.status&&"success"===data.status))return data.errors&&data.errors.length?_this3.errors=data.errors:_this3.errors=[config.global_labels.defaultErrorMessage.value];if(data.confirmCodeIsSent)return _this3.phoneToAuthorizeStep="confirm",_this3.confirmCodeIsSent=!0,_this3.confirmCodeHash=data.confirmCodeHash,_this3.confirmCodeResendTimeout=120,_this3.startConfirmCodeResendTimeout()}})["catch"](function(response){return response.data&&response.data.errors&&(_this3.errors=response.data.errors),_this3.isSubmitting=!1});break;case"changePhone":return this.phoneToAuthorizeStep="enterPhone",this.phoneToAuthorize="",this.confirmCodeIsSent=!1,this.confirmCode="",this.confirmCodeHash="",this.tooManyCodeInputRetries=!1,this.confirmCodeResendTimeout=0,this.errors=[],this.clearConfirmCodeResendTimeoutPromise();case"resendConfirmCode":if(0>=this.confirmCodeResendTimeout)return this.tryToAuthorizePhone("enterPhone",!1);break;case"confirm":if(!this.isSubmitting)return this.errors=[],this.isSubmitting=!0,dataToSend={action:"checkConfirmCode",phoneToAuthorize:this.phoneToAuthorize,confirmCode:this.confirmCode,confirmCodeHash:this.confirmCodeHash},$http.post(config.ordersInfoAuthUrl,dataToSend).then(function(response){var data;return data=response.data,_this3.isSubmitting=!1,data?data.status&&"success"===data.status?data.isPhoneAuthorized?_this3.pageReload():(_this3.confirmCode="",data.tooManyCodeInputRetries&&(_this3.tooManyCodeInputRetries=!0),_this3.errors=data.errors):(_this3.confirmCode="",data.tooManyCodeInputRetries&&(_this3.tooManyCodeInputRetries=!0),_this3.errors=data.errors&&data.errors.length?data.errors:[config.global_labels.defaultErrorMessage.value]):(_this3.confirmCode="",data.tooManyCodeInputRetries&&(_this3.tooManyCodeInputRetries=!0),_this3.errors=data.errors&&data.errors.length?data.errors:[config.global_labels.defaultErrorMessage.value])})["catch"](function(response){return _this3.confirmCode="",_this3.errors=response.data&&response.data.errors?response.data.errors:[config.global_labels.defaultErrorMessage.value],_this3.isSubmitting=!1});}}}]),ordersInfoApp}();return ordersInfoApp.prototype.errors=[],ordersInfoApp.prototype.isSubmitting=!1,ordersInfoApp.prototype.ordersList=[],ordersInfoApp.prototype.phoneToAuthorize="",ordersInfoApp.prototype.phoneToAuthorizeStep="enterPhone",ordersInfoApp.prototype.confirmCodeIsSent=!1,ordersInfoApp.prototype.confirmCodeHash="",ordersInfoApp.prototype.tooManyCodeInputRetries=!1,ordersInfoApp.prototype.confirmCodeResendTimeout=0,ordersInfoApp.prototype.confirmCodeResendTimeoutPromise=null,ordersInfoApp.prototype.pagination={currentPage:1,numPerPage:20,totalItems:0,onWatchChange:function onWatchChange(newValue,oldValue){if(newValue!==oldValue)return $scope.ordersInfo.searchOrders()},setPage:function setPage(page){return page!==$scope.ordersInfo.pagination.currentPage&&($scope.ordersInfo.pagination.currentPage=page),$scope.ordersInfo.pagination.totalPages=0,$scope.ordersInfo.ordersList=[],$scope.ordersInfo.searchOrders()}},ordersInfoApp}.call(this),$scope.config=config,$scope.utilities=new UtilitiesClass(config,$filter,$timeout),$scope.ordersInfo=new ordersInfoApp,$scope.$watch("ordersInfo.pagination.currentPage",$scope.ordersInfo.pagination.onWatchChange),$scope.$watch("config.sortFields.ordersList.field",$scope.ordersInfo.pagination.onWatchChange),$scope.$watch("config.sortFields.ordersList.direction",$scope.ordersInfo.pagination.onWatchChange)}]);