1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-10 21:24:20 +01:00
fab-manager/app/assets/javascripts/directives/bs-jasny-fileinput.js

38 lines
1.1 KiB
JavaScript
Raw Normal View History

2015-05-05 03:10:25 +02:00
'use strict';
Application.Directives.directive('bsJasnyFileinput', [function(){
return {
require : ['ngModel'],
link : function($scope, elm, attrs, requiredCtrls){
var ngModelCtrl = requiredCtrls[0];
var fileinput = elm.parents('[data-provides=fileinput]');
var filetypeRegex = attrs.bsJasnyFileinput;
fileinput.on('clear.bs.fileinput', function(e){
if(ngModelCtrl){
ngModelCtrl.$setViewValue(null);
ngModelCtrl.$setPristine();
$scope.$apply();
}
});
fileinput.on('change.bs.fileinput', function(e, files){
if(ngModelCtrl){
if(files){
ngModelCtrl.$setViewValue(files.result);
} else {
ngModelCtrl.$setPristine();
}
// TODO: ne marche pas pour filetype
if (filetypeRegex) {
if(files && typeof files.type !== "undefined" && files.type.match(new RegExp(filetypeRegex)))
ngModelCtrl.$setValidity('filetype', true);
else
ngModelCtrl.$setValidity('filetype', false);
2016-03-23 18:39:41 +01:00
};
2015-05-05 03:10:25 +02:00
}
$scope.$apply();
});
}
}
}]);