2018-11-21 10:59:07 +01:00
|
|
|
'use strict'
|
2015-05-05 03:10:25 +02:00
|
|
|
|
2018-11-21 10:59:07 +01:00
|
|
|
Application.Directives.directive('bsJasnyFileinput', [function () {
|
2015-05-05 03:10:25 +02:00
|
|
|
return {
|
2018-11-21 10:59:07 +01:00
|
|
|
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()
|
2015-05-05 03:10:25 +02:00
|
|
|
}
|
2018-11-21 10:59:07 +01:00
|
|
|
})
|
|
|
|
fileinput.on('change.bs.fileinput', function (e, files) {
|
|
|
|
if (ngModelCtrl) {
|
|
|
|
if (files) {
|
|
|
|
ngModelCtrl.$setViewValue(files.result)
|
2015-05-05 03:10:25 +02:00
|
|
|
} else {
|
2018-11-21 10:59:07 +01:00
|
|
|
ngModelCtrl.$setPristine()
|
2015-05-05 03:10:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: ne marche pas pour filetype
|
|
|
|
if (filetypeRegex) {
|
2018-11-21 10:59:07 +01:00
|
|
|
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
|
|
|
}
|
2018-11-21 10:59:07 +01:00
|
|
|
$scope.$apply()
|
|
|
|
})
|
2015-05-05 03:10:25 +02:00
|
|
|
}
|
|
|
|
}
|
2018-11-21 10:59:07 +01:00
|
|
|
}])
|