cobuild-angular-stack
Version:
Base stack angular sass jade gulp
51 lines (44 loc) • 1.91 kB
JavaScript
(function(module) {
'use strict';
module
.controller('AdminBannerNewController', AdminBannerNewController);
AdminBannerNewController.$inject = ['$scope', '$timeout', '$state', 'PredefinedBanner', '$uibModalInstance', 'toastr', 'Upload', '$translate', 'lodash'];
function AdminBannerNewController($scope, $timeout, $state, PredefinedBanner, $uibModalInstance, toastr, Upload, $translate, lodash) {
$scope.disabled = false;
$scope.coverPhoto = 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.cropablePhoto = $file.$ngfBlobUrl;
};
$scope.save = function() {
$scope.disabled = true;
Upload
.upload({
url: 'http://uniko.co:3000/api/v2/predefinedbanners/uploadAndCreate',
data: {
image: Upload.dataUrltoBlob($scope.coverPhoto)
}
})
.then(function(response) {
$scope.disabled = false;
$uibModalInstance.close(response.data);
$translate('success-image').then(function(translation){
toastr.success(translation);
});
});
};
$scope.bye = function() {
$uibModalInstance.dismiss('cancel');
};
}
})(angular.module('uniko.admin.banners'));