diff --git a/app/common/directives/file-upload.directive.js b/app/common/directives/file-upload.directive.js index 052bfe3ca2..881bcbc342 100644 --- a/app/common/directives/file-upload.directive.js +++ b/app/common/directives/file-upload.directive.js @@ -7,29 +7,42 @@ function FileUpload() { replace: true, scope: { container: '=', - model: '=' + model: '=', + validation: '=' }, controller: [ - '$scope', '$attrs', + '$scope', '$attrs', 'Notify', function ( - $scope, $attrs + $scope, $attrs, Notify ) { $scope.required = typeof $attrs.required !== 'undefined'; $scope.uploadFile = function ($event) { - $scope.container.file = $event.target.files[0]; - var reader = new FileReader(); - reader.onload = function () { - var dataURL = reader.result; - $scope.container.dataURI = dataURL; - $scope.container.changed = true; - $scope.container.deleted = false; - $scope.model = 'changed'; - $scope.$apply(); - }; - reader.readAsDataURL($event.target.files[0]); - - + if (validateFile($event.target.files[0])) { + $scope.container.file = $event.target.files[0]; + var reader = new FileReader(); + reader.onload = function () { + var dataURL = reader.result; + $scope.container.dataURI = dataURL; + $scope.container.changed = true; + $scope.container.deleted = false; + $scope.model = 'changed'; + $scope.$apply(); + }; + reader.readAsDataURL($event.target.files[0]); + } else { + Notify.error('post.media.error_in_upload'); + } }; + + function validateFile(container) { + if ($scope.validation === 'image') { + var mimeReg = /[\/.](gif|jpg|jpeg|png)$/i; + var mimeCheck = mimeReg.test(container.type); + var sizeCheck = container.size < 1048576; + return mimeCheck && sizeCheck; + } + return true; + } }] }; } diff --git a/app/common/directives/mode-bar/support-links.html b/app/common/directives/mode-bar/support-links.html index a2d14f7358..0d922673c9 100644 --- a/app/common/directives/mode-bar/support-links.html +++ b/app/common/directives/mode-bar/support-links.html @@ -10,8 +10,8 @@