UNPKG

cobuild-angular-stack

Version:

Base stack angular sass jade gulp

161 lines (136 loc) 6.36 kB
(function () { 'use strict'; angular.module('uniko.authSatellizer') .controller('BannerNewController', BannerNewController) .controller('PhotoNewController', PhotoNewController); BannerNewController.$inject = ['$scope', '$timeout', '$state', 'CoupleAccount', 'PredefinedBanner', 'currentAccount', '$uibModalInstance', 'toastr', 'UnikoUpload', 'Upload', '$translate', 'lodash']; function BannerNewController($scope, $timeout, $state, CoupleAccount, PredefinedBanner, currentAccount, $uibModalInstance, toastr, UnikoUpload, Upload, $translate, lodash) { $scope.banners = PredefinedBanner.find(); $scope.disabled = false; $scope.file = null; $scope.urlImage = null; $scope.isUpdated = false; $scope.originalPhoto = currentAccount.weddingData.coverPhoto; $scope.coverPhoto = null; $scope.cropablePhoto = null; $scope.uploadPhotoProfile = function ($file, $invalidFiles) { if ($invalidFiles && $invalidFiles.length > 0) { lodash.forEach($invalidFiles, function (file) { if (file.$errorMessages.maxHeight) { $translate('error-image-h').then(function (translation) { toastr.error(translation); }); } if (file.$errorMessages.maxSize) { $translate('error-image').then(function (translation) { toastr.error(translation); }); } }); return; } $scope.originalPhoto = null; $scope.cropablePhoto = $file.$ngfBlobUrl; }; $scope.save = function () { $scope.isUpdated = true; if ($scope.originalPhoto) { $uibModalInstance.close({coverPhoto: $scope.originalPhoto, isUpdated: $scope.isUpdated}); } else { $scope.disabled = true; Upload .upload({ url: 'http://uniko.co:3000/api/v2/coupleaccounts/' + currentAccount.id + '/wedding/addCoverPhoto', data: { image: Upload.dataUrltoBlob($scope.coverPhoto) } }) .then(function (response) { currentAccount.weddingData.coverPhoto = $scope.coverPhoto = response.data.url; CoupleAccount.updateMainAttributes(currentAccount, function () { $scope.disabled = false; $translate('success-image').then(function (translation) { toastr.success(translation); }); $uibModalInstance.close({coverPhoto: $scope.coverPhoto, isUpdated: $scope.isUpdated}); }); }); } }; $scope.bye = function () { $uibModalInstance.dismiss('cancel'); }; $scope.selectPredefined = function (url) { $scope.originalPhoto = url; }; $scope.bye = function () { $uibModalInstance.dismiss('cancel'); }; $scope.slickConfig = { enabled: false, dots: true, centerMode: true, prevArrow: '.btn-prev', nextArrow: '.btn-next', appendDots: '.carousel' }; $uibModalInstance.opened.then(function () { $timeout(function () { console.log("opened"); $scope.toggleSlick(); }, 1000); }); $scope.toggleSlick = function () { $scope.slickConfig.enabled = !$scope.slickConfig.enabled; }; } PhotoNewController.$inject = ['$scope', '$timeout', '$state', 'CoupleAccount', 'PredefinedBanner', 'currentAccount', '$uibModalInstance', 'toastr', 'UnikoUpload', 'Upload', '$translate', '$rootScope', 'lodash']; function PhotoNewController($scope, $timeout, $state, CoupleAccount, PredefinedBanner, currentAccount, $uibModalInstance, toastr, UnikoUpload, Upload, $translate, $rootScope, lodash) { $scope.banners = PredefinedBanner.find(); $scope.disabled = false; $scope.file = null; $scope.urlImage = null; $scope.isUpdated = false; $scope.originalPhoto = currentAccount.weddingData.profilePhoto; $scope.profilePhoto = null; $scope.cropablePhoto = null; $scope.uploadPhotoProfile = function ($file, $invalidFiles) { if ($invalidFiles && $invalidFiles.length > 0) { lodash.forEach($invalidFiles, function (file) { if (file.$errorMessages.maxSize) { $translate('error-image').then(function (translation) { toastr.error(translation); }); } }); return; } $scope.originalPhoto = null; $scope.cropablePhoto = $file.$ngfBlobUrl; }; $scope.save = function () { $scope.disabled = true; Upload .upload({ url: 'http://uniko.co:3000/api/v2/coupleaccounts/' + currentAccount.id + '/wedding/addimageprofile', data: { image: Upload.dataUrltoBlob($scope.profilePhoto) } }) .then(function (response) { currentAccount.weddingData.profilePhoto = $scope.urlImage = response.data.url; $rootScope.$broadcast('imageProfile', currentAccount.weddingData.profilePhoto); CoupleAccount.updateMainAttributes(currentAccount, function () { $scope.disabled = false; $translate('success-image').then(function (translation) { toastr.success(translation); }); $uibModalInstance.close(); }); }); }; $scope.bye = function () { $uibModalInstance.dismiss('cancel'); }; } })();