forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oscFileInput.js
35 lines (34 loc) · 1.03 KB
/
oscFileInput.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'use strict';
angular.module('openshiftConsole')
.directive('oscFileInput', function(Logger) {
return {
restrict: 'E',
scope: {
name: "@",
model: "=",
required: "="
},
templateUrl: 'views/directives/osc-file-input.html',
link: function(scope, element){
scope.supportsFileUpload = (window.File && window.FileReader && window.FileList && window.Blob);
scope.uploadError = false;
$(element).change(function(){
var file = $('input[type=file]',this)[0].files[0];
var reader = new FileReader();
reader.onloadend = function(){
scope.$apply(function(){
scope.fileName = file.name;
scope.model = reader.result;
});
};
reader.onerror = function(e){
scope.supportsFileUpload = false;
scope.uploadError = true;
Logger.error(e);
};
// reader.readAsBinaryString(file);
reader.onerror();
});
}
};
});