]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/js/ui/default/staff/services/file.js
8dc0c2be77065bfb6f4906213ebe669917af0258
[Evergreen.git] / Open-ILS / web / js / ui / default / staff / services / file.js
1 /**
2  * File upload reader.
3  * http://stackoverflow.com/questions/17063000/ng-model-for-input-type-file
4  *
5  * After reading, the contents will be available in the scope variable
6  * referred to by container="..."
7  */
8
9 angular.module('egCoreMod')
10 .directive("egFileReader", [function () {
11     return {
12         scope: {
13             container: "="
14         },
15         link: function (scope, element, attributes) {
16             // TODO: support DataURL, etc. via attrs
17             element.bind("change", function (changeEvent) {
18                 var reader = new FileReader();
19                 reader.onload = function (loadEvent) {
20                     scope.$apply(function () {
21                         scope.container = loadEvent.target.result;
22                     });
23                 }
24                 reader.readAsText(changeEvent.target.files[0]);
25             });
26         }
27     }
28 }]);