UNPKG

cobuild-angular-stack

Version:

Base stack angular sass jade gulp

105 lines (91 loc) 4.03 kB
/** * Created by garusis on 8/04/16. */ (function (module) { AdminShowOrderController.$inject = ['$scope', '$state', '$stateParams', 'Order', 'toastr', 'CoupleAccount', '$translate', 'AdminAuth', 'lodash']; module.controller('AdminShowOrderController', AdminShowOrderController); function AdminShowOrderController($scope, $state, $stateParams, Order, toastr, CoupleAccount, $translate, AdminAuth, lodash) { $scope.tmp = {updated: false}; var originalOrder; var updateWatch; console.log('AdminAuth.getAuthData = ',AdminAuth.getAuthData()); var adminUpdate = {}; adminUpdate.adminId = AdminAuth.getAuthData().currentUserId; $scope.coupleAccount = $stateParams.couple; $scope.fromCoupleAccount = !!$stateParams.couple; Order .findOne({filter: {where: {id: $stateParams.orderId}}}) .$promise .then(function (order) { originalOrder = order; $scope.coupleAccount = $scope.coupleAccount || CoupleAccount.findOne({filter: {where: {id: order.coupleAccountId}}}); $scope.order = lodash.cloneDeep(order); $scope.message = lodash.cloneDeep(order.paymentData.message); updateWatch = $scope.$watch(function () { return JSON.stringify($scope.order); }, function (newVal, oldVal) { if (newVal !== oldVal) { updateWatch(); $scope.tmp.updated = true; } }); }) .catch(console.error.bind(console)); this.update = function () { if (!updateWatch) return; $scope.disabled = true; adminUpdate.dataUpdated = new Date(); console.log('$scope.order.adminUpdated = ', $scope.order.adminUpdated); if (!$scope.order.adminUpdated) { $scope.order.adminUpdated = []; } $scope.order.adminUpdated.push(adminUpdate); console.log('Order to Update = ', $scope.order); $scope.order.$save() .then(function (order) { originalOrder = order; $scope.order = lodash.cloneDeep(order); $scope.tmp.updated = false; $scope.disabled = false; $translate('success-order').then(function (translation) { toastr.success(translation); }); updateWatch = $scope.$watch(function () { return JSON.stringify($scope.order); }, function (newVal, oldVal) { if (newVal !== oldVal) { updateWatch(); $scope.tmp.updated = true; } }); }) .catch(function (err) { toastr.error(err); }); }; this.resendEmail = function () { Order .prototype$sendEmail({id: $stateParams.orderId}) .$promise .then(function () { $translate('success-email-order').then(function (translation) { toastr.success(translation); }); }) .catch(console.log.bind(console)); }; this.reset = function () { $scope.order = lodash.cloneDeep(originalOrder); $scope.tmp.updated = false; $scope.disabled = false; updateWatch = $scope.$watch(function () { return JSON.stringify($scope.order); }, function (newVal, oldVal) { if (newVal !== oldVal) { updateWatch(); $scope.tmp.updated = true; } }); } } })(angular.module('uniko.admin.orders'));