berkshelf-store 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +2 -0
  3. data/Gemfile +5 -0
  4. data/README.md +83 -0
  5. data/Rakefile +44 -0
  6. data/berkshelf-store.gemspec +26 -0
  7. data/bin/berkshelf-store +49 -0
  8. data/lib/berkshelf-store/backends/filesystem.rb +138 -0
  9. data/lib/berkshelf-store/backends.rb +5 -0
  10. data/lib/berkshelf-store/webservice.rb +100 -0
  11. data/lib/berkshelf-store.rb +5 -0
  12. data/test/data/arbo/cookbooks/apache2/1.10.4/data.json +1 -0
  13. data/test/data/arbo/cookbooks/couchbase/1.1.0/data.json +1 -0
  14. data/test/data/arbo/cookbooks/couchbase/1.2.0/data.json +1 -0
  15. data/test/data/catalog.json +69 -0
  16. data/test/data/tarballs/apache2-v1.10.4.tar.gz +0 -0
  17. data/test/data/tarballs/couchbase-v1.1.0.tar.gz +0 -0
  18. data/test/data/tarballs/couchbase-v1.2.0.tar.gz +0 -0
  19. data/test/data/tarballs/not_a_cookbook.tgz +0 -0
  20. data/test/test_berkshelf-store_backends_filesystem.rb +76 -0
  21. data/ui/static/bootstrap/css/bootstrap-theme.css +347 -0
  22. data/ui/static/bootstrap/css/bootstrap-theme.css.map +1 -0
  23. data/ui/static/bootstrap/css/bootstrap-theme.min.css +7 -0
  24. data/ui/static/bootstrap/css/bootstrap.css +5785 -0
  25. data/ui/static/bootstrap/css/bootstrap.css.map +1 -0
  26. data/ui/static/bootstrap/css/bootstrap.min.css +7 -0
  27. data/ui/static/bootstrap/fonts/glyphicons-halflings-regular.eot +0 -0
  28. data/ui/static/bootstrap/fonts/glyphicons-halflings-regular.svg +229 -0
  29. data/ui/static/bootstrap/fonts/glyphicons-halflings-regular.ttf +0 -0
  30. data/ui/static/bootstrap/fonts/glyphicons-halflings-regular.woff +0 -0
  31. data/ui/static/bootstrap/js/bootstrap.js +1951 -0
  32. data/ui/static/bootstrap/js/bootstrap.min.js +6 -0
  33. data/ui/static/jquery/jquery.min.js +4 -0
  34. data/ui/static/jquery_file_upload/CONTRIBUTING.md +42 -0
  35. data/ui/static/jquery_file_upload/Gruntfile.js +37 -0
  36. data/ui/static/jquery_file_upload/README.md +123 -0
  37. data/ui/static/jquery_file_upload/angularjs.html +211 -0
  38. data/ui/static/jquery_file_upload/basic-plus.html +226 -0
  39. data/ui/static/jquery_file_upload/basic.html +136 -0
  40. data/ui/static/jquery_file_upload/blueimp-file-upload.jquery.json +50 -0
  41. data/ui/static/jquery_file_upload/bower.json +85 -0
  42. data/ui/static/jquery_file_upload/cors/postmessage.html +75 -0
  43. data/ui/static/jquery_file_upload/cors/result.html +24 -0
  44. data/ui/static/jquery_file_upload/css/demo-ie8.css +21 -0
  45. data/ui/static/jquery_file_upload/css/demo.css +67 -0
  46. data/ui/static/jquery_file_upload/css/jquery.fileupload-noscript.css +22 -0
  47. data/ui/static/jquery_file_upload/css/jquery.fileupload-ui-noscript.css +17 -0
  48. data/ui/static/jquery_file_upload/css/jquery.fileupload-ui.css +57 -0
  49. data/ui/static/jquery_file_upload/css/jquery.fileupload.css +36 -0
  50. data/ui/static/jquery_file_upload/css/style.css +15 -0
  51. data/ui/static/jquery_file_upload/img/loading.gif +0 -0
  52. data/ui/static/jquery_file_upload/img/progressbar.gif +0 -0
  53. data/ui/static/jquery_file_upload/index.html +255 -0
  54. data/ui/static/jquery_file_upload/jquery-ui.html +250 -0
  55. data/ui/static/jquery_file_upload/js/app.js +101 -0
  56. data/ui/static/jquery_file_upload/js/cors/jquery.postmessage-transport.js +117 -0
  57. data/ui/static/jquery_file_upload/js/cors/jquery.xdr-transport.js +86 -0
  58. data/ui/static/jquery_file_upload/js/jquery.fileupload-angular.js +429 -0
  59. data/ui/static/jquery_file_upload/js/jquery.fileupload-audio.js +106 -0
  60. data/ui/static/jquery_file_upload/js/jquery.fileupload-image.js +315 -0
  61. data/ui/static/jquery_file_upload/js/jquery.fileupload-jquery-ui.js +152 -0
  62. data/ui/static/jquery_file_upload/js/jquery.fileupload-process.js +172 -0
  63. data/ui/static/jquery_file_upload/js/jquery.fileupload-ui.js +699 -0
  64. data/ui/static/jquery_file_upload/js/jquery.fileupload-validate.js +119 -0
  65. data/ui/static/jquery_file_upload/js/jquery.fileupload-video.js +106 -0
  66. data/ui/static/jquery_file_upload/js/jquery.fileupload.js +1426 -0
  67. data/ui/static/jquery_file_upload/js/jquery.iframe-transport.js +214 -0
  68. data/ui/static/jquery_file_upload/js/main.js +75 -0
  69. data/ui/static/jquery_file_upload/js/vendor/jquery.ui.widget.js +530 -0
  70. data/ui/static/jquery_file_upload/package.json +54 -0
  71. data/ui/static/jquery_file_upload/server/gae-go/app/main.go +296 -0
  72. data/ui/static/jquery_file_upload/server/gae-go/app.yaml +12 -0
  73. data/ui/static/jquery_file_upload/server/gae-go/static/favicon.ico +0 -0
  74. data/ui/static/jquery_file_upload/server/gae-go/static/robots.txt +2 -0
  75. data/ui/static/jquery_file_upload/server/gae-python/app.yaml +16 -0
  76. data/ui/static/jquery_file_upload/server/gae-python/main.py +170 -0
  77. data/ui/static/jquery_file_upload/server/gae-python/static/favicon.ico +0 -0
  78. data/ui/static/jquery_file_upload/server/gae-python/static/robots.txt +2 -0
  79. data/ui/static/jquery_file_upload/server/node/package.json +41 -0
  80. data/ui/static/jquery_file_upload/server/node/server.js +292 -0
  81. data/ui/static/jquery_file_upload/server/php/UploadHandler.php +1330 -0
  82. data/ui/static/jquery_file_upload/server/php/index.php +15 -0
  83. data/ui/static/jquery_file_upload/test/index.html +166 -0
  84. data/ui/static/jquery_file_upload/test/test.js +1288 -0
  85. data/ui/views/catalog.erb +20 -0
  86. data/ui/views/doc.erb +23 -0
  87. data/ui/views/layout.erb +47 -0
  88. data/ui/views/upload.erb +46 -0
  89. metadata +210 -0
@@ -0,0 +1,117 @@
1
+ /*
2
+ * jQuery postMessage Transport Plugin 1.1.1
3
+ * https://github.com/blueimp/jQuery-File-Upload
4
+ *
5
+ * Copyright 2011, Sebastian Tschan
6
+ * https://blueimp.net
7
+ *
8
+ * Licensed under the MIT license:
9
+ * http://www.opensource.org/licenses/MIT
10
+ */
11
+
12
+ /* global define, window, document */
13
+
14
+ (function (factory) {
15
+ 'use strict';
16
+ if (typeof define === 'function' && define.amd) {
17
+ // Register as an anonymous AMD module:
18
+ define(['jquery'], factory);
19
+ } else {
20
+ // Browser globals:
21
+ factory(window.jQuery);
22
+ }
23
+ }(function ($) {
24
+ 'use strict';
25
+
26
+ var counter = 0,
27
+ names = [
28
+ 'accepts',
29
+ 'cache',
30
+ 'contents',
31
+ 'contentType',
32
+ 'crossDomain',
33
+ 'data',
34
+ 'dataType',
35
+ 'headers',
36
+ 'ifModified',
37
+ 'mimeType',
38
+ 'password',
39
+ 'processData',
40
+ 'timeout',
41
+ 'traditional',
42
+ 'type',
43
+ 'url',
44
+ 'username'
45
+ ],
46
+ convert = function (p) {
47
+ return p;
48
+ };
49
+
50
+ $.ajaxSetup({
51
+ converters: {
52
+ 'postmessage text': convert,
53
+ 'postmessage json': convert,
54
+ 'postmessage html': convert
55
+ }
56
+ });
57
+
58
+ $.ajaxTransport('postmessage', function (options) {
59
+ if (options.postMessage && window.postMessage) {
60
+ var iframe,
61
+ loc = $('<a>').prop('href', options.postMessage)[0],
62
+ target = loc.protocol + '//' + loc.host,
63
+ xhrUpload = options.xhr().upload;
64
+ return {
65
+ send: function (_, completeCallback) {
66
+ counter += 1;
67
+ var message = {
68
+ id: 'postmessage-transport-' + counter
69
+ },
70
+ eventName = 'message.' + message.id;
71
+ iframe = $(
72
+ '<iframe style="display:none;" src="' +
73
+ options.postMessage + '" name="' +
74
+ message.id + '"></iframe>'
75
+ ).bind('load', function () {
76
+ $.each(names, function (i, name) {
77
+ message[name] = options[name];
78
+ });
79
+ message.dataType = message.dataType.replace('postmessage ', '');
80
+ $(window).bind(eventName, function (e) {
81
+ e = e.originalEvent;
82
+ var data = e.data,
83
+ ev;
84
+ if (e.origin === target && data.id === message.id) {
85
+ if (data.type === 'progress') {
86
+ ev = document.createEvent('Event');
87
+ ev.initEvent(data.type, false, true);
88
+ $.extend(ev, data);
89
+ xhrUpload.dispatchEvent(ev);
90
+ } else {
91
+ completeCallback(
92
+ data.status,
93
+ data.statusText,
94
+ {postmessage: data.result},
95
+ data.headers
96
+ );
97
+ iframe.remove();
98
+ $(window).unbind(eventName);
99
+ }
100
+ }
101
+ });
102
+ iframe[0].contentWindow.postMessage(
103
+ message,
104
+ target
105
+ );
106
+ }).appendTo(document.body);
107
+ },
108
+ abort: function () {
109
+ if (iframe) {
110
+ iframe.remove();
111
+ }
112
+ }
113
+ };
114
+ }
115
+ });
116
+
117
+ }));
@@ -0,0 +1,86 @@
1
+ /*
2
+ * jQuery XDomainRequest Transport Plugin 1.1.3
3
+ * https://github.com/blueimp/jQuery-File-Upload
4
+ *
5
+ * Copyright 2011, Sebastian Tschan
6
+ * https://blueimp.net
7
+ *
8
+ * Licensed under the MIT license:
9
+ * http://www.opensource.org/licenses/MIT
10
+ *
11
+ * Based on Julian Aubourg's ajaxHooks xdr.js:
12
+ * https://github.com/jaubourg/ajaxHooks/
13
+ */
14
+
15
+ /* global define, window, XDomainRequest */
16
+
17
+ (function (factory) {
18
+ 'use strict';
19
+ if (typeof define === 'function' && define.amd) {
20
+ // Register as an anonymous AMD module:
21
+ define(['jquery'], factory);
22
+ } else {
23
+ // Browser globals:
24
+ factory(window.jQuery);
25
+ }
26
+ }(function ($) {
27
+ 'use strict';
28
+ if (window.XDomainRequest && !$.support.cors) {
29
+ $.ajaxTransport(function (s) {
30
+ if (s.crossDomain && s.async) {
31
+ if (s.timeout) {
32
+ s.xdrTimeout = s.timeout;
33
+ delete s.timeout;
34
+ }
35
+ var xdr;
36
+ return {
37
+ send: function (headers, completeCallback) {
38
+ var addParamChar = /\?/.test(s.url) ? '&' : '?';
39
+ function callback(status, statusText, responses, responseHeaders) {
40
+ xdr.onload = xdr.onerror = xdr.ontimeout = $.noop;
41
+ xdr = null;
42
+ completeCallback(status, statusText, responses, responseHeaders);
43
+ }
44
+ xdr = new XDomainRequest();
45
+ // XDomainRequest only supports GET and POST:
46
+ if (s.type === 'DELETE') {
47
+ s.url = s.url + addParamChar + '_method=DELETE';
48
+ s.type = 'POST';
49
+ } else if (s.type === 'PUT') {
50
+ s.url = s.url + addParamChar + '_method=PUT';
51
+ s.type = 'POST';
52
+ } else if (s.type === 'PATCH') {
53
+ s.url = s.url + addParamChar + '_method=PATCH';
54
+ s.type = 'POST';
55
+ }
56
+ xdr.open(s.type, s.url);
57
+ xdr.onload = function () {
58
+ callback(
59
+ 200,
60
+ 'OK',
61
+ {text: xdr.responseText},
62
+ 'Content-Type: ' + xdr.contentType
63
+ );
64
+ };
65
+ xdr.onerror = function () {
66
+ callback(404, 'Not Found');
67
+ };
68
+ if (s.xdrTimeout) {
69
+ xdr.ontimeout = function () {
70
+ callback(0, 'timeout');
71
+ };
72
+ xdr.timeout = s.xdrTimeout;
73
+ }
74
+ xdr.send((s.hasContent && s.data) || null);
75
+ },
76
+ abort: function () {
77
+ if (xdr) {
78
+ xdr.onerror = $.noop();
79
+ xdr.abort();
80
+ }
81
+ }
82
+ };
83
+ }
84
+ });
85
+ }
86
+ }));
@@ -0,0 +1,429 @@
1
+ /*
2
+ * jQuery File Upload AngularJS Plugin 2.2.0
3
+ * https://github.com/blueimp/jQuery-File-Upload
4
+ *
5
+ * Copyright 2013, Sebastian Tschan
6
+ * https://blueimp.net
7
+ *
8
+ * Licensed under the MIT license:
9
+ * http://www.opensource.org/licenses/MIT
10
+ */
11
+
12
+ /* jshint nomen:false */
13
+ /* global define, angular */
14
+
15
+ (function (factory) {
16
+ 'use strict';
17
+ if (typeof define === 'function' && define.amd) {
18
+ // Register as an anonymous AMD module:
19
+ define([
20
+ 'jquery',
21
+ 'angular',
22
+ './jquery.fileupload-image',
23
+ './jquery.fileupload-audio',
24
+ './jquery.fileupload-video',
25
+ './jquery.fileupload-validate'
26
+ ], factory);
27
+ } else {
28
+ factory();
29
+ }
30
+ }(function () {
31
+ 'use strict';
32
+
33
+ angular.module('blueimp.fileupload', [])
34
+
35
+ // The fileUpload service provides configuration options
36
+ // for the fileUpload directive and default handlers for
37
+ // File Upload events:
38
+ .provider('fileUpload', function () {
39
+ var scopeEvalAsync = function (expression) {
40
+ var scope = angular.element(this)
41
+ .fileupload('option', 'scope');
42
+ // Schedule a new $digest cycle if not already inside of one
43
+ // and evaluate the given expression:
44
+ scope.$evalAsync(expression);
45
+ },
46
+ addFileMethods = function (scope, data) {
47
+ var files = data.files,
48
+ file = files[0];
49
+ angular.forEach(files, function (file, index) {
50
+ file._index = index;
51
+ file.$state = function () {
52
+ return data.state();
53
+ };
54
+ file.$processing = function () {
55
+ return data.processing();
56
+ };
57
+ file.$progress = function () {
58
+ return data.progress();
59
+ };
60
+ file.$response = function () {
61
+ return data.response();
62
+ };
63
+ });
64
+ file.$submit = function () {
65
+ if (!file.error) {
66
+ return data.submit();
67
+ }
68
+ };
69
+ file.$cancel = function () {
70
+ return data.abort();
71
+ };
72
+ },
73
+ $config;
74
+ $config = this.defaults = {
75
+ handleResponse: function (e, data) {
76
+ var files = data.result && data.result.files;
77
+ if (files) {
78
+ data.scope.replace(data.files, files);
79
+ } else if (data.errorThrown ||
80
+ data.textStatus === 'error') {
81
+ data.files[0].error = data.errorThrown ||
82
+ data.textStatus;
83
+ }
84
+ },
85
+ add: function (e, data) {
86
+ if (e.isDefaultPrevented()) {
87
+ return false;
88
+ }
89
+ var scope = data.scope,
90
+ filesCopy = [];
91
+ angular.forEach(data.files, function (file) {
92
+ filesCopy.push(file);
93
+ });
94
+ scope.$apply(function () {
95
+ addFileMethods(scope, data);
96
+ var method = scope.option('prependFiles') ?
97
+ 'unshift' : 'push';
98
+ Array.prototype[method].apply(scope.queue, data.files);
99
+ });
100
+ data.process(function () {
101
+ return scope.process(data);
102
+ }).always(function () {
103
+ scope.$apply(function () {
104
+ addFileMethods(scope, data);
105
+ scope.replace(filesCopy, data.files);
106
+ });
107
+ }).then(function () {
108
+ if ((scope.option('autoUpload') ||
109
+ data.autoUpload) &&
110
+ data.autoUpload !== false) {
111
+ data.submit();
112
+ }
113
+ });
114
+ },
115
+ progress: function (e, data) {
116
+ if (e.isDefaultPrevented()) {
117
+ return false;
118
+ }
119
+ data.scope.$apply();
120
+ },
121
+ done: function (e, data) {
122
+ if (e.isDefaultPrevented()) {
123
+ return false;
124
+ }
125
+ var that = this;
126
+ data.scope.$apply(function () {
127
+ data.handleResponse.call(that, e, data);
128
+ });
129
+ },
130
+ fail: function (e, data) {
131
+ if (e.isDefaultPrevented()) {
132
+ return false;
133
+ }
134
+ var that = this,
135
+ scope = data.scope;
136
+ if (data.errorThrown === 'abort') {
137
+ scope.clear(data.files);
138
+ return;
139
+ }
140
+ scope.$apply(function () {
141
+ data.handleResponse.call(that, e, data);
142
+ });
143
+ },
144
+ stop: scopeEvalAsync,
145
+ processstart: scopeEvalAsync,
146
+ processstop: scopeEvalAsync,
147
+ getNumberOfFiles: function () {
148
+ var scope = this.scope;
149
+ return scope.queue.length - scope.processing();
150
+ },
151
+ dataType: 'json',
152
+ autoUpload: false
153
+ };
154
+ this.$get = [
155
+ function () {
156
+ return {
157
+ defaults: $config
158
+ };
159
+ }
160
+ ];
161
+ })
162
+
163
+ // Format byte numbers to readable presentations:
164
+ .provider('formatFileSizeFilter', function () {
165
+ var $config = {
166
+ // Byte units following the IEC format
167
+ // http://en.wikipedia.org/wiki/Kilobyte
168
+ units: [
169
+ {size: 1000000000, suffix: ' GB'},
170
+ {size: 1000000, suffix: ' MB'},
171
+ {size: 1000, suffix: ' KB'}
172
+ ]
173
+ };
174
+ this.defaults = $config;
175
+ this.$get = function () {
176
+ return function (bytes) {
177
+ if (!angular.isNumber(bytes)) {
178
+ return '';
179
+ }
180
+ var unit = true,
181
+ i = 0,
182
+ prefix,
183
+ suffix;
184
+ while (unit) {
185
+ unit = $config.units[i];
186
+ prefix = unit.prefix || '';
187
+ suffix = unit.suffix || '';
188
+ if (i === $config.units.length - 1 || bytes >= unit.size) {
189
+ return prefix + (bytes / unit.size).toFixed(2) + suffix;
190
+ }
191
+ i += 1;
192
+ }
193
+ };
194
+ };
195
+ })
196
+
197
+ // The FileUploadController initializes the fileupload widget and
198
+ // provides scope methods to control the File Upload functionality:
199
+ .controller('FileUploadController', [
200
+ '$scope', '$element', '$attrs', '$window', 'fileUpload',
201
+ function ($scope, $element, $attrs, $window, fileUpload) {
202
+ var uploadMethods = {
203
+ progress: function () {
204
+ return $element.fileupload('progress');
205
+ },
206
+ active: function () {
207
+ return $element.fileupload('active');
208
+ },
209
+ option: function (option, data) {
210
+ if (arguments.length === 1) {
211
+ return $element.fileupload('option', option);
212
+ }
213
+ $element.fileupload('option', option, data);
214
+ },
215
+ add: function (data) {
216
+ return $element.fileupload('add', data);
217
+ },
218
+ send: function (data) {
219
+ return $element.fileupload('send', data);
220
+ },
221
+ process: function (data) {
222
+ return $element.fileupload('process', data);
223
+ },
224
+ processing: function (data) {
225
+ return $element.fileupload('processing', data);
226
+ }
227
+ };
228
+ $scope.disabled = !$window.jQuery.support.fileInput;
229
+ $scope.queue = $scope.queue || [];
230
+ $scope.clear = function (files) {
231
+ var queue = this.queue,
232
+ i = queue.length,
233
+ file = files,
234
+ length = 1;
235
+ if (angular.isArray(files)) {
236
+ file = files[0];
237
+ length = files.length;
238
+ }
239
+ while (i) {
240
+ i -= 1;
241
+ if (queue[i] === file) {
242
+ return queue.splice(i, length);
243
+ }
244
+ }
245
+ };
246
+ $scope.replace = function (oldFiles, newFiles) {
247
+ var queue = this.queue,
248
+ file = oldFiles[0],
249
+ i,
250
+ j;
251
+ for (i = 0; i < queue.length; i += 1) {
252
+ if (queue[i] === file) {
253
+ for (j = 0; j < newFiles.length; j += 1) {
254
+ queue[i + j] = newFiles[j];
255
+ }
256
+ return;
257
+ }
258
+ }
259
+ };
260
+ $scope.applyOnQueue = function (method) {
261
+ var list = this.queue.slice(0),
262
+ i,
263
+ file;
264
+ for (i = 0; i < list.length; i += 1) {
265
+ file = list[i];
266
+ if (file[method]) {
267
+ file[method]();
268
+ }
269
+ }
270
+ };
271
+ $scope.submit = function () {
272
+ this.applyOnQueue('$submit');
273
+ };
274
+ $scope.cancel = function () {
275
+ this.applyOnQueue('$cancel');
276
+ };
277
+ // Add upload methods to the scope:
278
+ angular.extend($scope, uploadMethods);
279
+ // The fileupload widget will initialize with
280
+ // the options provided via "data-"-parameters,
281
+ // as well as those given via options object:
282
+ $element.fileupload(angular.extend(
283
+ {scope: $scope},
284
+ fileUpload.defaults
285
+ )).on('fileuploadadd', function (e, data) {
286
+ data.scope = $scope;
287
+ }).on('fileuploadfail', function (e, data) {
288
+ if (data.errorThrown === 'abort') {
289
+ return;
290
+ }
291
+ if (data.dataType &&
292
+ data.dataType.indexOf('json') === data.dataType.length - 4) {
293
+ try {
294
+ data.result = angular.fromJson(data.jqXHR.responseText);
295
+ } catch (ignore) {}
296
+ }
297
+ }).on([
298
+ 'fileuploadadd',
299
+ 'fileuploadsubmit',
300
+ 'fileuploadsend',
301
+ 'fileuploaddone',
302
+ 'fileuploadfail',
303
+ 'fileuploadalways',
304
+ 'fileuploadprogress',
305
+ 'fileuploadprogressall',
306
+ 'fileuploadstart',
307
+ 'fileuploadstop',
308
+ 'fileuploadchange',
309
+ 'fileuploadpaste',
310
+ 'fileuploaddrop',
311
+ 'fileuploaddragover',
312
+ 'fileuploadchunksend',
313
+ 'fileuploadchunkdone',
314
+ 'fileuploadchunkfail',
315
+ 'fileuploadchunkalways',
316
+ 'fileuploadprocessstart',
317
+ 'fileuploadprocess',
318
+ 'fileuploadprocessdone',
319
+ 'fileuploadprocessfail',
320
+ 'fileuploadprocessalways',
321
+ 'fileuploadprocessstop'
322
+ ].join(' '), function (e, data) {
323
+ if ($scope.$emit(e.type, data).defaultPrevented) {
324
+ e.preventDefault();
325
+ }
326
+ }).on('remove', function () {
327
+ // Remove upload methods from the scope,
328
+ // when the widget is removed:
329
+ var method;
330
+ for (method in uploadMethods) {
331
+ if (uploadMethods.hasOwnProperty(method)) {
332
+ delete $scope[method];
333
+ }
334
+ }
335
+ });
336
+ // Observe option changes:
337
+ $scope.$watch(
338
+ $attrs.fileUpload,
339
+ function (newOptions) {
340
+ if (newOptions) {
341
+ $element.fileupload('option', newOptions);
342
+ }
343
+ }
344
+ );
345
+ }
346
+ ])
347
+
348
+ // Provide File Upload progress feedback:
349
+ .controller('FileUploadProgressController', [
350
+ '$scope', '$attrs', '$parse',
351
+ function ($scope, $attrs, $parse) {
352
+ var fn = $parse($attrs.fileUploadProgress),
353
+ update = function () {
354
+ var progress = fn($scope);
355
+ if (!progress || !progress.total) {
356
+ return;
357
+ }
358
+ $scope.num = Math.floor(
359
+ progress.loaded / progress.total * 100
360
+ );
361
+ };
362
+ update();
363
+ $scope.$watch(
364
+ $attrs.fileUploadProgress + '.loaded',
365
+ function (newValue, oldValue) {
366
+ if (newValue !== oldValue) {
367
+ update();
368
+ }
369
+ }
370
+ );
371
+ }
372
+ ])
373
+
374
+ // Display File Upload previews:
375
+ .controller('FileUploadPreviewController', [
376
+ '$scope', '$element', '$attrs',
377
+ function ($scope, $element, $attrs) {
378
+ $scope.$watch(
379
+ $attrs.fileUploadPreview + '.preview',
380
+ function (preview) {
381
+ $element.empty();
382
+ if (preview) {
383
+ $element.append(preview);
384
+ }
385
+ }
386
+ );
387
+ }
388
+ ])
389
+
390
+ .directive('fileUpload', function () {
391
+ return {
392
+ controller: 'FileUploadController',
393
+ scope: true
394
+ };
395
+ })
396
+
397
+ .directive('fileUploadProgress', function () {
398
+ return {
399
+ controller: 'FileUploadProgressController',
400
+ scope: true
401
+ };
402
+ })
403
+
404
+ .directive('fileUploadPreview', function () {
405
+ return {
406
+ controller: 'FileUploadPreviewController'
407
+ };
408
+ })
409
+
410
+ // Enhance the HTML5 download attribute to
411
+ // allow drag&drop of files to the desktop:
412
+ .directive('download', function () {
413
+ return function (scope, elm) {
414
+ elm.on('dragstart', function (e) {
415
+ try {
416
+ e.originalEvent.dataTransfer.setData(
417
+ 'DownloadURL',
418
+ [
419
+ 'application/octet-stream',
420
+ elm.prop('download'),
421
+ elm.prop('href')
422
+ ].join(':')
423
+ );
424
+ } catch (ignore) {}
425
+ });
426
+ };
427
+ });
428
+
429
+ }));