UNPKG

cobuild-angular-stack

Version:

Base stack angular sass jade gulp

152 lines (135 loc) 4.44 kB
(function(module) { AdminExperiencesAddController.$inject = ['$scope', '$timeout','$state', '$stateParams','$translate', 'toastr', '$uibModalInstance', 'Upload', 'ProductTemplate', 'Experiences']; AdminExperiencesEditController.$inject = ['$scope', '$timeout','$state', '$stateParams','$translate', 'toastr', '$uibModalInstance', 'Upload', 'ProductTemplate', 'Experiences', 'experience']; module.controller('AdminExperiencesAddController', AdminExperiencesAddController); module.controller("AdminExperiencesEditController", AdminExperiencesEditController); function AdminExperiencesAddController($scope, $timeout, $state, $stateParams,$translate, toastr, $uibModalInstance, Upload, ProductTemplate, Experiences) { $scope.modal = { description: "", imagesList: [], $resolved: true, image: null } $scope.uploadButton = function() { $("#upload-btn").click();; } $scope.create = function() { var body = { description: $scope.modal.description } if($scope.modal.image) { body.img = $scope.modal.image, body.altImg = $scope.modal.image } Experiences.create(body).$promise.then(function(experience) { $translate('success-save-data').then(function(translation){ toastr.success(translation); $uibModalInstance.close(experience); }); }).catch($scope.error); }; $scope.uploadImage = function ($file) { if ($file) { $scope.profilePhoto = $file; var imagesList = $scope.modal.imagesList; imagesList.unshift(null); $scope.modal.$resolved = false; $scope.newPhoto = true; $timeout(function () { $scope.modal.$resolved = true; $scope.newPhoto = false; }, 0); Upload .upload({ url: 'https://uniko-api-prod.herokuapp.com/api/v2/producttemplates/addImage', data: { image: $file } }) .then(function (response) { $scope.modal.$resolved = false; $scope.newPhoto = true; $timeout(function () { imagesList.splice(0, 1, response.data.url); if (!$scope.modal.image) { $scope.modal.image = response.data.url; } $scope.modal.$resolved = true; $scope.newPhoto = false; }, 0); }); } }; $scope.error = function(err) { toastr.error(err); }; $scope.close = function() { $uibModalInstance.dismiss('cancel'); }; } function AdminExperiencesEditController($scope, $timeout, $state, $stateParams,$translate, toastr, $uibModalInstance, Upload, ProductTemplate, Experiences, experience) { $scope.modal = { description: experience.description, imagesList: [], $resolved: true, image: experience.img } $scope.uploadButton = function() { $("#upload-btn").click();; } $scope.create = function() { var body = { description: $scope.modal.description, id: experience.id } if($scope.modal.image) { body.img = $scope.modal.image, body.altImg = $scope.modal.image } Experiences.save(body).$promise.then(function(experience) { $translate('success-save-data').then(function(translation){ toastr.success(translation); $uibModalInstance.close(experience); }); }).catch($scope.error); }; $scope.uploadImage = function ($file) { if ($file) { $scope.profilePhoto = $file; var imagesList = $scope.modal.imagesList; imagesList.unshift(null); $scope.modal.$resolved = false; $scope.newPhoto = true; $timeout(function () { $scope.modal.$resolved = true; $scope.newPhoto = false; }, 0); Upload .upload({ url: 'https://uniko-api-prod.herokuapp.com/api/v2/producttemplates/addImage', data: { image: $file } }) .then(function (response) { $scope.modal.$resolved = false; $scope.newPhoto = true; $timeout(function () { imagesList.splice(0, 1, response.data.url); if (!$scope.modal.image) { $scope.modal.image = response.data.url; } $scope.modal.$resolved = true; $scope.newPhoto = false; }, 0); }); } }; $scope.error = function(err) { toastr.error(err); }; $scope.close = function() { $uibModalInstance.dismiss('cancel'); }; } })(angular.module('uniko.admin.experiences'));