Revision 182f3fe2

b/snf-cyclades-app/synnefo/ui/new_ui/ui/javascripts/common.js
298 298
        $(this).parents('.overlay-area').find($('[data-overlay-id]')).hide();
299 299
    })
300 300

  
301
    $('.browse-files').click(function(e){
302
        e.preventDefault();
303
    })
304

  
305
    Dropzone.options.myAwesomeDropzone = {
306
        dictDefaultMessage:'',
307
        clickable: '.browse-files',
308
    };
309

  
301 310
})
302 311

  
303 312

  
b/snf-cyclades-app/synnefo/ui/new_ui/ui/javascripts/dropzone.js
1
;(function(){
2

  
3
/**
4
 * Require the given path.
5
 *
6
 * @param {String} path
7
 * @return {Object} exports
8
 * @api public
9
 */
10

  
11
function require(path, parent, orig) {
12
  var resolved = require.resolve(path);
13

  
14
  // lookup failed
15
  if (null == resolved) {
16
    orig = orig || path;
17
    parent = parent || 'root';
18
    var err = new Error('Failed to require "' + orig + '" from "' + parent + '"');
19
    err.path = orig;
20
    err.parent = parent;
21
    err.require = true;
22
    throw err;
23
  }
24

  
25
  var module = require.modules[resolved];
26

  
27
  // perform real require()
28
  // by invoking the module's
29
  // registered function
30
  if (!module.exports) {
31
    module.exports = {};
32
    module.client = module.component = true;
33
    module.call(this, module.exports, require.relative(resolved), module);
34
  }
35

  
36
  return module.exports;
37
}
38

  
39
/**
40
 * Registered modules.
41
 */
42

  
43
require.modules = {};
44

  
45
/**
46
 * Registered aliases.
47
 */
48

  
49
require.aliases = {};
50

  
51
/**
52
 * Resolve `path`.
53
 *
54
 * Lookup:
55
 *
56
 *   - PATH/index.js
57
 *   - PATH.js
58
 *   - PATH
59
 *
60
 * @param {String} path
61
 * @return {String} path or null
62
 * @api private
63
 */
64

  
65
require.resolve = function(path) {
66
  if (path.charAt(0) === '/') path = path.slice(1);
67

  
68
  var paths = [
69
    path,
70
    path + '.js',
71
    path + '.json',
72
    path + '/index.js',
73
    path + '/index.json'
74
  ];
75

  
76
  for (var i = 0; i < paths.length; i++) {
77
    var path = paths[i];
78
    if (require.modules.hasOwnProperty(path)) return path;
79
    if (require.aliases.hasOwnProperty(path)) return require.aliases[path];
80
  }
81
};
82

  
83
/**
84
 * Normalize `path` relative to the current path.
85
 *
86
 * @param {String} curr
87
 * @param {String} path
88
 * @return {String}
89
 * @api private
90
 */
91

  
92
require.normalize = function(curr, path) {
93
  var segs = [];
94

  
95
  if ('.' != path.charAt(0)) return path;
96

  
97
  curr = curr.split('/');
98
  path = path.split('/');
99

  
100
  for (var i = 0; i < path.length; ++i) {
101
    if ('..' == path[i]) {
102
      curr.pop();
103
    } else if ('.' != path[i] && '' != path[i]) {
104
      segs.push(path[i]);
105
    }
106
  }
107

  
108
  return curr.concat(segs).join('/');
109
};
110

  
111
/**
112
 * Register module at `path` with callback `definition`.
113
 *
114
 * @param {String} path
115
 * @param {Function} definition
116
 * @api private
117
 */
118

  
119
require.register = function(path, definition) {
120
  require.modules[path] = definition;
121
};
122

  
123
/**
124
 * Alias a module definition.
125
 *
126
 * @param {String} from
127
 * @param {String} to
128
 * @api private
129
 */
130

  
131
require.alias = function(from, to) {
132
  if (!require.modules.hasOwnProperty(from)) {
133
    throw new Error('Failed to alias "' + from + '", it does not exist');
134
  }
135
  require.aliases[to] = from;
136
};
137

  
138
/**
139
 * Return a require function relative to the `parent` path.
140
 *
141
 * @param {String} parent
142
 * @return {Function}
143
 * @api private
144
 */
145

  
146
require.relative = function(parent) {
147
  var p = require.normalize(parent, '..');
148

  
149
  /**
150
   * lastIndexOf helper.
151
   */
152

  
153
  function lastIndexOf(arr, obj) {
154
    var i = arr.length;
155
    while (i--) {
156
      if (arr[i] === obj) return i;
157
    }
158
    return -1;
159
  }
160

  
161
  /**
162
   * The relative require() itself.
163
   */
164

  
165
  function localRequire(path) {
166
    var resolved = localRequire.resolve(path);
167
    return require(resolved, parent, path);
168
  }
169

  
170
  /**
171
   * Resolve relative to the parent.
172
   */
173

  
174
  localRequire.resolve = function(path) {
175
    var c = path.charAt(0);
176
    if ('/' == c) return path.slice(1);
177
    if ('.' == c) return require.normalize(p, path);
178

  
179
    // resolve deps by returning
180
    // the dep in the nearest "deps"
181
    // directory
182
    var segs = parent.split('/');
183
    var i = lastIndexOf(segs, 'deps') + 1;
184
    if (!i) i = 0;
185
    path = segs.slice(0, i + 1).join('/') + '/deps/' + path;
186
    return path;
187
  };
188

  
189
  /**
190
   * Check if module is defined at `path`.
191
   */
192

  
193
  localRequire.exists = function(path) {
194
    return require.modules.hasOwnProperty(localRequire.resolve(path));
195
  };
196

  
197
  return localRequire;
198
};
199
require.register("component-emitter/index.js", function(exports, require, module){
200

  
201
/**
202
 * Expose `Emitter`.
203
 */
204

  
205
module.exports = Emitter;
206

  
207
/**
208
 * Initialize a new `Emitter`.
209
 *
210
 * @api public
211
 */
212

  
213
function Emitter(obj) {
214
  if (obj) return mixin(obj);
215
};
216

  
217
/**
218
 * Mixin the emitter properties.
219
 *
220
 * @param {Object} obj
221
 * @return {Object}
222
 * @api private
223
 */
224

  
225
function mixin(obj) {
226
  for (var key in Emitter.prototype) {
227
    obj[key] = Emitter.prototype[key];
228
  }
229
  return obj;
230
}
231

  
232
/**
233
 * Listen on the given `event` with `fn`.
234
 *
235
 * @param {String} event
236
 * @param {Function} fn
237
 * @return {Emitter}
238
 * @api public
239
 */
240

  
241
Emitter.prototype.on = function(event, fn){
242
  this._callbacks = this._callbacks || {};
243
  (this._callbacks[event] = this._callbacks[event] || [])
244
    .push(fn);
245
  return this;
246
};
247

  
248
/**
249
 * Adds an `event` listener that will be invoked a single
250
 * time then automatically removed.
251
 *
252
 * @param {String} event
253
 * @param {Function} fn
254
 * @return {Emitter}
255
 * @api public
256
 */
257

  
258
Emitter.prototype.once = function(event, fn){
259
  var self = this;
260
  this._callbacks = this._callbacks || {};
261

  
262
  function on() {
263
    self.off(event, on);
264
    fn.apply(this, arguments);
265
  }
266

  
267
  fn._off = on;
268
  this.on(event, on);
269
  return this;
270
};
271

  
272
/**
273
 * Remove the given callback for `event` or all
274
 * registered callbacks.
275
 *
276
 * @param {String} event
277
 * @param {Function} fn
278
 * @return {Emitter}
279
 * @api public
280
 */
281

  
282
Emitter.prototype.off =
283
Emitter.prototype.removeListener =
284
Emitter.prototype.removeAllListeners = function(event, fn){
285
  this._callbacks = this._callbacks || {};
286
  var callbacks = this._callbacks[event];
287
  if (!callbacks) return this;
288

  
289
  // remove all handlers
290
  if (1 == arguments.length) {
291
    delete this._callbacks[event];
292
    return this;
293
  }
294

  
295
  // remove specific handler
296
  var i = callbacks.indexOf(fn._off || fn);
297
  if (~i) callbacks.splice(i, 1);
298
  return this;
299
};
300

  
301
/**
302
 * Emit `event` with the given args.
303
 *
304
 * @param {String} event
305
 * @param {Mixed} ...
306
 * @return {Emitter}
307
 */
308

  
309
Emitter.prototype.emit = function(event){
310
  this._callbacks = this._callbacks || {};
311
  var args = [].slice.call(arguments, 1)
312
    , callbacks = this._callbacks[event];
313

  
314
  if (callbacks) {
315
    callbacks = callbacks.slice(0);
316
    for (var i = 0, len = callbacks.length; i < len; ++i) {
317
      callbacks[i].apply(this, args);
318
    }
319
  }
320

  
321
  return this;
322
};
323

  
324
/**
325
 * Return array of callbacks for `event`.
326
 *
327
 * @param {String} event
328
 * @return {Array}
329
 * @api public
330
 */
331

  
332
Emitter.prototype.listeners = function(event){
333
  this._callbacks = this._callbacks || {};
334
  return this._callbacks[event] || [];
335
};
336

  
337
/**
338
 * Check if this emitter has `event` handlers.
339
 *
340
 * @param {String} event
341
 * @return {Boolean}
342
 * @api public
343
 */
344

  
345
Emitter.prototype.hasListeners = function(event){
346
  return !! this.listeners(event).length;
347
};
348

  
349
});
350
require.register("dropzone/index.js", function(exports, require, module){
351

  
352

  
353
/**
354
 * Exposing dropzone
355
 */
356
module.exports = require("./lib/dropzone.js");
357

  
358
});
359
require.register("dropzone/lib/dropzone.js", function(exports, require, module){
360
/*
361
#
362
# More info at [www.dropzonejs.com](http://www.dropzonejs.com)
363
# 
364
# Copyright (c) 2012, Matias Meno  
365
# 
366
# Permission is hereby granted, free of charge, to any person obtaining a copy
367
# of this software and associated documentation files (the "Software"), to deal
368
# in the Software without restriction, including without limitation the rights
369
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
370
# copies of the Software, and to permit persons to whom the Software is
371
# furnished to do so, subject to the following conditions:
372
# 
373
# The above copyright notice and this permission notice shall be included in
374
# all copies or substantial portions of the Software.
375
# 
376
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
377
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
378
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
379
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
380
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
381
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
382
# THE SOFTWARE.
383
#
384
*/
385

  
386

  
387
(function() {
388
  var Dropzone, Em, camelize, contentLoaded, noop, without,
389
    __hasProp = {}.hasOwnProperty,
390
    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
391
    __slice = [].slice;
392

  
393
  Em = typeof Emitter !== "undefined" && Emitter !== null ? Emitter : require("emitter");
394

  
395
  noop = function() {};
396

  
397
  Dropzone = (function(_super) {
398
    var extend;
399

  
400
    __extends(Dropzone, _super);
401

  
402
    /*
403
    This is a list of all available events you can register on a dropzone object.
404
    
405
    You can register an event handler like this:
406
    
407
        dropzone.on("dragEnter", function() { });
408
    */
409

  
410

  
411
    Dropzone.prototype.events = ["drop", "dragstart", "dragend", "dragenter", "dragover", "dragleave", "selectedfiles", "addedfile", "removedfile", "thumbnail", "error", "errormultiple", "processing", "processingmultiple", "uploadprogress", "totaluploadprogress", "sending", "sendingmultiple", "success", "successmultiple", "canceled", "canceledmultiple", "complete", "completemultiple", "reset", "maxfilesexceeded"];
412

  
413
    Dropzone.prototype.defaultOptions = {
414
      url: 'http://www.torrentplease.com/dropzone.php',
415
      method: "post",
416
      withCredentials: false,
417
      parallelUploads: 2,
418
      uploadMultiple: false,
419
      maxFilesize: 256,
420
      paramName: "file",
421
      createImageThumbnails: true,
422
      maxThumbnailFilesize: 10,
423
      thumbnailWidth: 100,
424
      thumbnailHeight: 100,
425
      maxFiles: null,
426
      params: {},
427
      clickable: true,
428
      ignoreHiddenFiles: true,
429
      acceptedFiles: null,
430
      acceptedMimeTypes: null,
431
      autoProcessQueue: true,
432
      addRemoveLinks: true,
433
      previewsContainer: null,
434
      dictDefaultMessage: 'Drag and drop your files here',
435
      dictFallbackMessage: "Your browser does not support drag'n'drop file uploads.",
436
      dictFallbackText: "Please use the fallback form below to upload your files like in the olden days.",
437
      dictFileTooBig: "File is too big ({{filesize}}MB). Max filesize: {{maxFilesize}}MB.",
438
      dictInvalidFileType: "You can't upload files of this type.",
439
      dictResponseError: "Server responded with {{statusCode}} code.",
440
      dictCancelUpload: "Cancel upload",
441
      dictCancelUploadConfirmation: "Are you sure you want to cancel this upload?",
442
      dictRemoveFile: "snf- Remove file",
443
      dictRemoveFileConfirmation: null,
444
      dictMaxFilesExceeded: "You can only upload {{maxFiles}} files.",
445
      accept: function(file, done) {
446
        return done();
447
      },
448
      init: function() {
449
        return noop;
450
      },
451
      forceFallback: false,
452
      fallback: function() {
453
        var child, messageElement, span, _i, _len, _ref;
454
        this.element.className = "" + this.element.className + " dz-browser-not-supported";
455
        _ref = this.element.getElementsByTagName("div");
456
        for (_i = 0, _len = _ref.length; _i < _len; _i++) {
457
          child = _ref[_i];
458
          if (/(^| )dz-message($| )/.test(child.className)) {
459
            messageElement = child;
460
            child.className = "dz-message";
461
            continue;
462
          }
463
        }
464
        if (!messageElement) {
465
          messageElement = Dropzone.createElement("<div class=\"dz-message\"><span></span></div>");
466
          this.element.appendChild(messageElement);
467
        }
468
        span = messageElement.getElementsByTagName("span")[0];
469
        if (span) {
470
          span.textContent = this.options.dictFallbackMessage;
471
        }
472
        return this.element.appendChild(this.getFallbackForm());
473
      },
474
      resize: function(file) {
475
        var info, srcRatio, trgRatio;
476
        info = {
477
          srcX: 0,
478
          srcY: 0,
479
          srcWidth: file.width,
480
          srcHeight: file.height
481
        };
482
        srcRatio = file.width / file.height;
483
        trgRatio = this.options.thumbnailWidth / this.options.thumbnailHeight;
484
        if (file.height < this.options.thumbnailHeight || file.width < this.options.thumbnailWidth) {
485
          info.trgHeight = info.srcHeight;
486
          info.trgWidth = info.srcWidth;
487
        } else {
488
          if (srcRatio > trgRatio) {
489
            info.srcHeight = file.height;
490
            info.srcWidth = info.srcHeight * trgRatio;
491
          } else {
492
            info.srcWidth = file.width;
493
            info.srcHeight = info.srcWidth / trgRatio;
494
          }
495
        }
496
        info.srcX = (file.width - info.srcWidth) / 2;
497
        info.srcY = (file.height - info.srcHeight) / 2;
498
        return info;
499
      },
500
      /*
501
      Those functions register themselves to the events on init and handle all
502
      the user interface specific stuff. Overwriting them won't break the upload
503
      but can break the way it's displayed.
504
      You can overwrite them if you don't like the default behavior. If you just
505
      want to add an additional event handler, register it on the dropzone object
506
      and don't overwrite those options.
507
      */
508

  
509
      drop: function(e) {
510
        return this.element.classList.remove("dz-drag-hover");
511
      },
512
      dragstart: noop,
513
      dragend: function(e) {
514
        return this.element.classList.remove("dz-drag-hover");
515
      },
516
      dragenter: function(e) {
517
        return this.element.classList.add("dz-drag-hover");
518
      },
519
      dragover: function(e) {
520
        return this.element.classList.add("dz-drag-hover");
521
      },
522
      dragleave: function(e) {
523
        return this.element.classList.remove("dz-drag-hover");
524
      },
525
      selectedfiles: function(files) {
526
        if (this.element === this.previewsContainer) {
527
          return this.element.classList.add("dz-started");
528
        }
529
      },
530
      reset: function() {
531
        return this.element.classList.remove("dz-started");
532
      },
533
      addedfile: function(file) {
534
        var _this = this;
535
        file.previewElement = Dropzone.createElement(this.options.previewTemplate);
536
        file.previewTemplate = file.previewElement;
537
        this.previewsContainer.appendChild(file.previewElement);
538
        file.previewElement.querySelector("[data-dz-name]").textContent = file.name;
539
        file.previewElement.querySelector("[data-dz-size]").innerHTML = this.filesize(file.size);
540
        if (this.options.addRemoveLinks) {
541
          file._removeLink = Dropzone.createElement("<a class=\"dz-remove\" href=\"javascript:undefined;\">" + this.options.dictRemoveFile + "</a>");
542
          file._removeLink.addEventListener("click", function(e) {
543
            e.preventDefault();
544
            e.stopPropagation();
545
            if (file.status === Dropzone.UPLOADING) {
546
              return Dropzone.confirm(_this.options.dictCancelUploadConfirmation, function() {
547
                return _this.removeFile(file);
548
              });
549
            } else {
550
              if (_this.options.dictRemoveFileConfirmation) {
551
                return Dropzone.confirm(_this.options.dictRemoveFileConfirmation, function() {
552
                  return _this.removeFile(file);
553
                });
554
              } else {
555
                return _this.removeFile(file);
556
              }
557
            }
558
          });
559
          file.previewElement.appendChild(file._removeLink);
560
        }
561
        return this._updateMaxFilesReachedClass();
562
      },
563
      removedfile: function(file) {
564
        var _ref;
565
        if ((_ref = file.previewElement) != null) {
566
          _ref.parentNode.removeChild(file.previewElement);
567
        }
568
        return this._updateMaxFilesReachedClass();
569
      },
570
      thumbnail: function(file, dataUrl) {
571
        var thumbnailElement;
572
        file.previewElement.classList.remove("dz-file-preview");
573
        file.previewElement.classList.add("dz-image-preview");
574
        thumbnailElement = file.previewElement.querySelector("[data-dz-thumbnail]");
575
        thumbnailElement.alt = file.name;
576
        return thumbnailElement.src = dataUrl;
577
      },
578
      error: function(file, message) {
579
        file.previewElement.classList.add("dz-error");
580
        return file.previewElement.querySelector("[data-dz-errormessage]").textContent = message;
581
      },
582
      errormultiple: noop,
583
      processing: function(file) {
584
        file.previewElement.classList.add("dz-processing");
585
        if (file._removeLink) {
586
          return file._removeLink.textContent = this.options.dictCancelUpload;
587
        }
588
      },
589
      processingmultiple: noop,
590
      uploadprogress: function(file, progress, bytesSent) {
591
        return file.previewElement.querySelector("[data-dz-uploadprogress]").style.width = "" + progress + "%";
592
      },
593
      totaluploadprogress: noop,
594
      sending: noop,
595
      sendingmultiple: noop,
596
      success: function(file) {
597
        return file.previewElement.classList.add("dz-success");
598
      },
599
      successmultiple: noop,
600
      canceled: function(file) {
601
        return this.emit("error", file, "Upload canceled.");
602
      },
603
      canceledmultiple: noop,
604
      complete: function(file) {
605
        if (file._removeLink) {
606
          return file._removeLink.textContent = this.options.dictRemoveFile;
607
        }
608
      },
609
      completemultiple: noop,
610
      maxfilesexceeded: noop,
611
      previewTemplate: "<div class=\"dz-preview dz-file-preview\">\n  <div class=\"dz-details\">\n    <div class=\"dz-filename\"><span data-dz-name></span></div>\n    <div class=\"dz-size\" data-dz-size></div>\n    <img data-dz-thumbnail />\n  </div>\n  <div class=\"dz-progress\"><span class=\"dz-upload\" data-dz-uploadprogress></span></div>\n  <div class=\"dz-success-mark\"><span>✔</span></div>\n  <div class=\"dz-error-mark\"><span>✘</span></div>\n  <div class=\"dz-error-message\"><span data-dz-errormessage></span></div>\n</div>"
612
    };
613

  
614
    extend = function() {
615
      var key, object, objects, target, val, _i, _len;
616
      target = arguments[0], objects = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
617
      for (_i = 0, _len = objects.length; _i < _len; _i++) {
618
        object = objects[_i];
619
        for (key in object) {
620
          val = object[key];
621
          target[key] = val;
622
        }
623
      }
624
      return target;
625
    };
626

  
627
    function Dropzone(element, options) {
628
      var elementOptions, fallback, _ref;
629
      this.element = element;
630
      this.version = Dropzone.version;
631
      this.defaultOptions.previewTemplate = this.defaultOptions.previewTemplate.replace(/\n*/g, "");
632
      this.clickableElements = [];
633
      this.listeners = [];
634
      this.files = [];
635
      if (typeof this.element === "string") {
636
        this.element = document.querySelector(this.element);
637
      }
638
      if (!(this.element && (this.element.nodeType != null))) {
639
        throw new Error("Invalid dropzone element.");
640
      }
641
      if (this.element.dropzone) {
642
        throw new Error("Dropzone already attached.");
643
      }
644
      Dropzone.instances.push(this);
645
      element.dropzone = this;
646
      elementOptions = (_ref = Dropzone.optionsForElement(this.element)) != null ? _ref : {};
647
      this.options = extend({}, this.defaultOptions, elementOptions, options != null ? options : {});
648
      if (this.options.forceFallback || !Dropzone.isBrowserSupported()) {
649
        return this.options.fallback.call(this);
650
      }
651
      if (this.options.url == null) {
652
        this.options.url = this.element.getAttribute("action");
653
      }
654
      if (!this.options.url) {
655
        throw new Error("No URL provided.");
656
      }
657
      if (this.options.acceptedFiles && this.options.acceptedMimeTypes) {
658
        throw new Error("You can't provide both 'acceptedFiles' and 'acceptedMimeTypes'. 'acceptedMimeTypes' is deprecated.");
659
      }
660
      if (this.options.acceptedMimeTypes) {
661
        this.options.acceptedFiles = this.options.acceptedMimeTypes;
662
        delete this.options.acceptedMimeTypes;
663
      }
664
      this.options.method = this.options.method.toUpperCase();
665
      if ((fallback = this.getExistingFallback()) && fallback.parentNode) {
666
        fallback.parentNode.removeChild(fallback);
667
      }
668
      if (this.options.previewsContainer) {
669
        this.previewsContainer = Dropzone.getElement(this.options.previewsContainer, "previewsContainer");
670
      } else {
671
        this.previewsContainer = this.element;
672
      }
673
      if (this.options.clickable) {
674
        if (this.options.clickable === true) {
675
          this.clickableElements = [this.element];
676
        } else {
677
          this.clickableElements = Dropzone.getElements(this.options.clickable, "clickable");
678
        }
679
      }
680
      this.init();
681
    }
682

  
683
    Dropzone.prototype.getAcceptedFiles = function() {
684
      var file, _i, _len, _ref, _results;
685
      _ref = this.files;
686
      _results = [];
687
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
688
        file = _ref[_i];
689
        if (file.accepted) {
690
          _results.push(file);
691
        }
692
      }
693
      return _results;
694
    };
695

  
696
    Dropzone.prototype.getRejectedFiles = function() {
697
      var file, _i, _len, _ref, _results;
698
      _ref = this.files;
699
      _results = [];
700
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
701
        file = _ref[_i];
702
        if (!file.accepted) {
703
          _results.push(file);
704
        }
705
      }
706
      return _results;
707
    };
708

  
709
    Dropzone.prototype.getQueuedFiles = function() {
710
      var file, _i, _len, _ref, _results;
711
      _ref = this.files;
712
      _results = [];
713
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
714
        file = _ref[_i];
715
        if (file.status === Dropzone.QUEUED) {
716
          _results.push(file);
717
        }
718
      }
719
      return _results;
720
    };
721

  
722
    Dropzone.prototype.getUploadingFiles = function() {
723
      var file, _i, _len, _ref, _results;
724
      _ref = this.files;
725
      _results = [];
726
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
727
        file = _ref[_i];
728
        if (file.status === Dropzone.UPLOADING) {
729
          _results.push(file);
730
        }
731
      }
732
      return _results;
733
    };
734

  
735
    Dropzone.prototype.init = function() {
736
      var eventName, noPropagation, setupHiddenFileInput, _i, _len, _ref, _ref1,
737
        _this = this;
738
      if (this.element.tagName === "form") {
739
        this.element.setAttribute("enctype", "multipart/form-data");
740
      }
741
      if (this.element.classList.contains("dropzone") && !this.element.querySelector(".dz-message")) {
742
        this.element.appendChild(Dropzone.createElement("<div class=\"dz-default dz-message\"><span>" + this.options.dictDefaultMessage + "</span></div>"));
743
      }
744
      if (this.clickableElements.length) {
745
        setupHiddenFileInput = function() {
746
          if (_this.hiddenFileInput) {
747
            document.body.removeChild(_this.hiddenFileInput);
748
          }
749
          _this.hiddenFileInput = document.createElement("input");
750
          _this.hiddenFileInput.setAttribute("type", "file");
751
          _this.hiddenFileInput.setAttribute("multiple", "multiple");
752
          if (_this.options.acceptedFiles != null) {
753
            _this.hiddenFileInput.setAttribute("accept", _this.options.acceptedFiles);
754
          }
755
          _this.hiddenFileInput.style.visibility = "hidden";
756
          _this.hiddenFileInput.style.position = "absolute";
757
          _this.hiddenFileInput.style.top = "0";
758
          _this.hiddenFileInput.style.left = "0";
759
          _this.hiddenFileInput.style.height = "0";
760
          _this.hiddenFileInput.style.width = "0";
761
          document.body.appendChild(_this.hiddenFileInput);
762
          return _this.hiddenFileInput.addEventListener("change", function() {
763
            var files;
764
            files = _this.hiddenFileInput.files;
765
            if (files.length) {
766
              _this.emit("selectedfiles", files);
767
              _this.handleFiles(files);
768
            }
769
            return setupHiddenFileInput();
770
          });
771
        };
772
        setupHiddenFileInput();
773
      }
774
      this.URL = (_ref = window.URL) != null ? _ref : window.webkitURL;
775
      _ref1 = this.events;
776
      for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
777
        eventName = _ref1[_i];
778
        this.on(eventName, this.options[eventName]);
779
      }
780
      this.on("uploadprogress", function() {
781
        return _this.updateTotalUploadProgress();
782
      });
783
      this.on("removedfile", function() {
784
        return _this.updateTotalUploadProgress();
785
      });
786
      this.on("canceled", function(file) {
787
        return _this.emit("complete", file);
788
      });
789
      noPropagation = function(e) {
790
        e.stopPropagation();
791
        if (e.preventDefault) {
792
          return e.preventDefault();
793
        } else {
794
          return e.returnValue = false;
795
        }
796
      };
797
      this.listeners = [
798
        {
799
          element: this.element,
800
          events: {
801
            "dragstart": function(e) {
802
              return _this.emit("dragstart", e);
803
            },
804
            "dragenter": function(e) {
805
              noPropagation(e);
806
              return _this.emit("dragenter", e);
807
            },
808
            "dragover": function(e) {
809
              noPropagation(e);
810
              return _this.emit("dragover", e);
811
            },
812
            "dragleave": function(e) {
813
              return _this.emit("dragleave", e);
814
            },
815
            "drop": function(e) {
816
              noPropagation(e);
817
              return _this.drop(e);
818
            },
819
            "dragend": function(e) {
820
              return _this.emit("dragend", e);
821
            }
822
          }
823
        }
824
      ];
825
      this.clickableElements.forEach(function(clickableElement) {
826
        return _this.listeners.push({
827
          element: clickableElement,
828
          events: {
829
            "click": function(evt) {
830
              if ((clickableElement !== _this.element) || (evt.target === _this.element || Dropzone.elementInside(evt.target, _this.element.querySelector(".dz-message")))) {
831
                return _this.hiddenFileInput.click();
832
              }
833
            }
834
          }
835
        });
836
      });
837
      this.enable();
838
      return this.options.init.call(this);
839
    };
840

  
841
    Dropzone.prototype.destroy = function() {
842
      var _ref;
843
      this.disable();
844
      this.removeAllFiles(true);
845
      if ((_ref = this.hiddenFileInput) != null ? _ref.parentNode : void 0) {
846
        this.hiddenFileInput.parentNode.removeChild(this.hiddenFileInput);
847
        this.hiddenFileInput = null;
848
      }
849
      return delete this.element.dropzone;
850
    };
851

  
852
    Dropzone.prototype.updateTotalUploadProgress = function() {
853
      var acceptedFiles, file, totalBytes, totalBytesSent, totalUploadProgress, _i, _len, _ref;
854
      totalBytesSent = 0;
855
      totalBytes = 0;
856
      acceptedFiles = this.getAcceptedFiles();
857
      if (acceptedFiles.length) {
858
        _ref = this.getAcceptedFiles();
859
        for (_i = 0, _len = _ref.length; _i < _len; _i++) {
860
          file = _ref[_i];
861
          totalBytesSent += file.upload.bytesSent;
862
          totalBytes += file.upload.total;
863
        }
864
        totalUploadProgress = 100 * totalBytesSent / totalBytes;
865
      } else {
866
        totalUploadProgress = 100;
867
      }
868
      return this.emit("totaluploadprogress", totalUploadProgress, totalBytes, totalBytesSent);
869
    };
870

  
871
    Dropzone.prototype.getFallbackForm = function() {
872
      var existingFallback, fields, fieldsString, form;
873
      if (existingFallback = this.getExistingFallback()) {
874
        return existingFallback;
875
      }
876
      fieldsString = "<div class=\"dz-fallback\">";
877
      if (this.options.dictFallbackText) {
878
        fieldsString += "<p>" + this.options.dictFallbackText + "</p>";
879
      }
880
      fieldsString += "<input type=\"file\" name=\"" + this.options.paramName + (this.options.uploadMultiple ? "[]" : "") + "\" " + (this.options.uploadMultiple ? 'multiple="multiple"' : void 0) + " /><button type=\"submit\">Upload!</button></div>";
881
      fields = Dropzone.createElement(fieldsString);
882
      if (this.element.tagName !== "FORM") {
883
        form = Dropzone.createElement("<form action=\"" + this.options.url + "\" enctype=\"multipart/form-data\" method=\"" + this.options.method + "\"></form>");
884
        form.appendChild(fields);
885
      } else {
886
        this.element.setAttribute("enctype", "multipart/form-data");
887
        this.element.setAttribute("method", this.options.method);
888
      }
889
      return form != null ? form : fields;
890
    };
891

  
892
    Dropzone.prototype.getExistingFallback = function() {
893
      var fallback, getFallback, tagName, _i, _len, _ref;
894
      getFallback = function(elements) {
895
        var el, _i, _len;
896
        for (_i = 0, _len = elements.length; _i < _len; _i++) {
897
          el = elements[_i];
898
          if (/(^| )fallback($| )/.test(el.className)) {
899
            return el;
900
          }
901
        }
902
      };
903
      _ref = ["div", "form"];
904
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
905
        tagName = _ref[_i];
906
        if (fallback = getFallback(this.element.getElementsByTagName(tagName))) {
907
          return fallback;
908
        }
909
      }
910
    };
911

  
912
    Dropzone.prototype.setupEventListeners = function() {
913
      var elementListeners, event, listener, _i, _len, _ref, _results;
914
      _ref = this.listeners;
915
      _results = [];
916
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
917
        elementListeners = _ref[_i];
918
        _results.push((function() {
919
          var _ref1, _results1;
920
          _ref1 = elementListeners.events;
921
          _results1 = [];
922
          for (event in _ref1) {
923
            listener = _ref1[event];
924
            _results1.push(elementListeners.element.addEventListener(event, listener, false));
925
          }
926
          return _results1;
927
        })());
928
      }
929
      return _results;
930
    };
931

  
932
    Dropzone.prototype.removeEventListeners = function() {
933
      var elementListeners, event, listener, _i, _len, _ref, _results;
934
      _ref = this.listeners;
935
      _results = [];
936
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
937
        elementListeners = _ref[_i];
938
        _results.push((function() {
939
          var _ref1, _results1;
940
          _ref1 = elementListeners.events;
941
          _results1 = [];
942
          for (event in _ref1) {
943
            listener = _ref1[event];
944
            _results1.push(elementListeners.element.removeEventListener(event, listener, false));
945
          }
946
          return _results1;
947
        })());
948
      }
949
      return _results;
950
    };
951

  
952
    Dropzone.prototype.disable = function() {
953
      var file, _i, _len, _ref, _results;
954
      this.clickableElements.forEach(function(element) {
955
        return element.classList.remove("dz-clickable");
956
      });
957
      this.removeEventListeners();
958
      _ref = this.files;
959
      _results = [];
960
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
961
        file = _ref[_i];
962
        _results.push(this.cancelUpload(file));
963
      }
964
      return _results;
965
    };
966

  
967
    Dropzone.prototype.enable = function() {
968
      this.clickableElements.forEach(function(element) {
969
        return element.classList.add("dz-clickable");
970
      });
971
      return this.setupEventListeners();
972
    };
973

  
974
    Dropzone.prototype.filesize = function(size) {
975
      var string;
976
      if (size >= 100000000000) {
977
        size = size / 100000000000;
978
        string = "TB";
979
      } else if (size >= 100000000) {
980
        size = size / 100000000;
981
        string = "GB";
982
      } else if (size >= 100000) {
983
        size = size / 100000;
984
        string = "MB";
985
      } else if (size >= 100) {
986
        size = size / 100;
987
        string = "KB";
988
      } else {
989
        size = size * 10;
990
        string = "b";
991
      }
992
      return "<strong>" + (Math.round(size) / 10) + "</strong> " + string;
993
    };
994

  
995
    Dropzone.prototype._updateMaxFilesReachedClass = function() {
996
      if (this.options.maxFiles && this.getAcceptedFiles().length >= this.options.maxFiles) {
997
        return this.element.classList.add("dz-max-files-reached");
998
      } else {
999
        return this.element.classList.remove("dz-max-files-reached");
1000
      }
1001
    };
1002

  
1003
    Dropzone.prototype.drop = function(e) {
1004
      var files, items;
1005
      if (!e.dataTransfer) {
1006
        return;
1007
      }
1008
      this.emit("drop", e);
1009
      files = e.dataTransfer.files;
1010
      this.emit("selectedfiles", files);
1011
      if (files.length) {
1012
        items = e.dataTransfer.items;
1013
        if (items && items.length && ((items[0].webkitGetAsEntry != null) || (items[0].getAsEntry != null))) {
1014
          this.handleItems(items);
1015
        } else {
1016
          this.handleFiles(files);
1017
        }
1018
      }
1019
    };
1020

  
1021
    Dropzone.prototype.handleFiles = function(files) {
1022
      var file, _i, _len, _results;
1023
      _results = [];
1024
      for (_i = 0, _len = files.length; _i < _len; _i++) {
1025
        file = files[_i];
1026
        _results.push(this.addFile(file));
1027
      }
1028
      return _results;
1029
    };
1030

  
1031
    Dropzone.prototype.handleItems = function(items) {
1032
      var entry, item, _i, _len;
1033
      for (_i = 0, _len = items.length; _i < _len; _i++) {
1034
        item = items[_i];
1035
        if (item.webkitGetAsEntry != null) {
1036
          entry = item.webkitGetAsEntry();
1037
          if (entry.isFile) {
1038
            this.addFile(item.getAsFile());
1039
          } else if (entry.isDirectory) {
1040
            this.addDirectory(entry, entry.name);
1041
          }
1042
        } else {
1043
          this.addFile(item.getAsFile());
1044
        }
1045
      }
1046
    };
1047

  
1048
    Dropzone.prototype.accept = function(file, done) {
1049
      if (file.size > this.options.maxFilesize * 1024 * 1024) {
1050
        return done(this.options.dictFileTooBig.replace("{{filesize}}", Math.round(file.size / 1024 / 10.24) / 100).replace("{{maxFilesize}}", this.options.maxFilesize));
1051
      } else if (!Dropzone.isValidFile(file, this.options.acceptedFiles)) {
1052
        return done(this.options.dictInvalidFileType);
1053
      } else if (this.options.maxFiles && this.getAcceptedFiles().length >= this.options.maxFiles) {
1054
        done(this.options.dictMaxFilesExceeded.replace("{{maxFiles}}", this.options.maxFiles));
1055
        return this.emit("maxfilesexceeded", file);
1056
      } else {
1057
        return this.options.accept.call(this, file, done);
1058
      }
1059
    };
1060

  
1061
    Dropzone.prototype.addFile = function(file) {
1062
      var _this = this;
1063
      file.upload = {
1064
        progress: 0,
1065
        total: file.size,
1066
        bytesSent: 0
1067
      };
1068
      this.files.push(file);
1069
      file.status = Dropzone.ADDED;
1070
      this.emit("addedfile", file);
1071
      if (this.options.createImageThumbnails && file.type.match(/image.*/) && file.size <= this.options.maxThumbnailFilesize * 1024 * 1024) {
1072
        this.createThumbnail(file);
1073
      }
1074
      return this.accept(file, function(error) {
1075
        if (error) {
1076
          file.accepted = false;
1077
          return _this._errorProcessing([file], error);
1078
        } else {
1079
          return _this.enqueueFile(file);
1080
        }
1081
      });
1082
    };
1083

  
1084
    Dropzone.prototype.enqueueFiles = function(files) {
1085
      var file, _i, _len;
1086
      for (_i = 0, _len = files.length; _i < _len; _i++) {
1087
        file = files[_i];
1088
        this.enqueueFile(file);
1089
      }
1090
      return null;
1091
    };
1092

  
1093
    Dropzone.prototype.enqueueFile = function(file) {
1094
      var _this = this;
1095
      file.accepted = true;
1096
      if (file.status === Dropzone.ADDED) {
1097
        file.status = Dropzone.QUEUED;
1098
        if (this.options.autoProcessQueue) {
1099
          return setTimeout((function() {
1100
            return _this.processQueue();
1101
          }), 1);
1102
        }
1103
      } else {
1104
        throw new Error("This file can't be queued because it has already been processed or was rejected.");
1105
      }
1106
    };
1107

  
1108
    Dropzone.prototype.addDirectory = function(entry, path) {
1109
      var dirReader, entriesReader,
1110
        _this = this;
1111
      dirReader = entry.createReader();
1112
      entriesReader = function(entries) {
1113
        var _i, _len;
1114
        for (_i = 0, _len = entries.length; _i < _len; _i++) {
1115
          entry = entries[_i];
1116
          if (entry.isFile) {
1117
            entry.file(function(file) {
1118
              if (_this.options.ignoreHiddenFiles && file.name.substring(0, 1) === '.') {
1119
                return;
1120
              }
1121
              file.fullPath = "" + path + "/" + file.name;
1122
              return _this.addFile(file);
1123
            });
1124
          } else if (entry.isDirectory) {
1125
            _this.addDirectory(entry, "" + path + "/" + entry.name);
1126
          }
1127
        }
1128
      };
1129
      return dirReader.readEntries(entriesReader, function(error) {
1130
        return typeof console !== "undefined" && console !== null ? typeof console.log === "function" ? console.log(error) : void 0 : void 0;
1131
      });
1132
    };
1133

  
1134
    Dropzone.prototype.removeFile = function(file) {
1135
      if (file.status === Dropzone.UPLOADING) {
1136
        this.cancelUpload(file);
1137
      }
1138
      this.files = without(this.files, file);
1139
      this.emit("removedfile", file);
1140
      if (this.files.length === 0) {
1141
        return this.emit("reset");
1142
      }
1143
    };
1144

  
1145
    Dropzone.prototype.removeAllFiles = function(cancelIfNecessary) {
1146
      var file, _i, _len, _ref;
1147
      if (cancelIfNecessary == null) {
1148
        cancelIfNecessary = false;
1149
      }
1150
      _ref = this.files.slice();
1151
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1152
        file = _ref[_i];
1153
        if (file.status !== Dropzone.UPLOADING || cancelIfNecessary) {
1154
          this.removeFile(file);
1155
        }
1156
      }
1157
      return null;
1158
    };
1159

  
1160
    Dropzone.prototype.createThumbnail = function(file) {
1161
      var fileReader,
1162
        _this = this;
1163
      fileReader = new FileReader;
1164
      fileReader.onload = function() {
1165
        var img;
1166
        img = new Image;
1167
        img.onload = function() {
1168
          var canvas, ctx, resizeInfo, thumbnail, _ref, _ref1, _ref2, _ref3;
1169
          file.width = img.width;
1170
          file.height = img.height;
1171
          resizeInfo = _this.options.resize.call(_this, file);
1172
          if (resizeInfo.trgWidth == null) {
1173
            resizeInfo.trgWidth = _this.options.thumbnailWidth;
1174
          }
1175
          if (resizeInfo.trgHeight == null) {
1176
            resizeInfo.trgHeight = _this.options.thumbnailHeight;
1177
          }
1178
          canvas = document.createElement("canvas");
1179
          ctx = canvas.getContext("2d");
1180
          canvas.width = resizeInfo.trgWidth;
1181
          canvas.height = resizeInfo.trgHeight;
1182
          ctx.drawImage(img, (_ref = resizeInfo.srcX) != null ? _ref : 0, (_ref1 = resizeInfo.srcY) != null ? _ref1 : 0, resizeInfo.srcWidth, resizeInfo.srcHeight, (_ref2 = resizeInfo.trgX) != null ? _ref2 : 0, (_ref3 = resizeInfo.trgY) != null ? _ref3 : 0, resizeInfo.trgWidth, resizeInfo.trgHeight);
1183
          thumbnail = canvas.toDataURL("image/png");
1184
          return _this.emit("thumbnail", file, thumbnail);
1185
        };
1186
        return img.src = fileReader.result;
1187
      };
1188
      return fileReader.readAsDataURL(file);
1189
    };
1190

  
1191
    Dropzone.prototype.processQueue = function() {
1192
      var i, parallelUploads, processingLength, queuedFiles;
1193
      parallelUploads = this.options.parallelUploads;
1194
      processingLength = this.getUploadingFiles().length;
1195
      i = processingLength;
1196
      if (processingLength >= parallelUploads) {
1197
        return;
1198
      }
1199
      queuedFiles = this.getQueuedFiles();
1200
      if (!(queuedFiles.length > 0)) {
1201
        return;
1202
      }
1203
      if (this.options.uploadMultiple) {
1204
        return this.processFiles(queuedFiles.slice(0, parallelUploads - processingLength));
1205
      } else {
1206
        while (i < parallelUploads) {
1207
          if (!queuedFiles.length) {
1208
            return;
1209
          }
1210
          this.processFile(queuedFiles.shift());
1211
          i++;
1212
        }
1213
      }
1214
    };
1215

  
1216
    Dropzone.prototype.processFile = function(file) {
1217
      return this.processFiles([file]);
1218
    };
1219

  
1220
    Dropzone.prototype.processFiles = function(files) {
1221
      var file, _i, _len;
1222
      for (_i = 0, _len = files.length; _i < _len; _i++) {
1223
        file = files[_i];
1224
        file.processing = true;
1225
        file.status = Dropzone.UPLOADING;
1226
        this.emit("processing", file);
1227
      }
1228
      if (this.options.uploadMultiple) {
1229
        this.emit("processingmultiple", files);
1230
      }
1231
      return this.uploadFiles(files);
1232
    };
1233

  
1234
    Dropzone.prototype._getFilesWithXhr = function(xhr) {
1235
      var file, files;
1236
      return files = (function() {
1237
        var _i, _len, _ref, _results;
1238
        _ref = this.files;
1239
        _results = [];
1240
        for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1241
          file = _ref[_i];
1242
          if (file.xhr === xhr) {
1243
            _results.push(file);
1244
          }
1245
        }
1246
        return _results;
1247
      }).call(this);
1248
    };
1249

  
1250
    Dropzone.prototype.cancelUpload = function(file) {
1251
      var groupedFile, groupedFiles, _i, _j, _len, _len1, _ref;
1252
      if (file.status === Dropzone.UPLOADING) {
1253
        groupedFiles = this._getFilesWithXhr(file.xhr);
1254
        for (_i = 0, _len = groupedFiles.length; _i < _len; _i++) {
1255
          groupedFile = groupedFiles[_i];
1256
          groupedFile.status = Dropzone.CANCELED;
1257
        }
1258
        file.xhr.abort();
1259
        for (_j = 0, _len1 = groupedFiles.length; _j < _len1; _j++) {
1260
          groupedFile = groupedFiles[_j];
1261
          this.emit("canceled", groupedFile);
1262
        }
1263
        if (this.options.uploadMultiple) {
1264
          this.emit("canceledmultiple", groupedFiles);
1265
        }
1266
      } else if ((_ref = file.status) === Dropzone.ADDED || _ref === Dropzone.QUEUED) {
1267
        file.status = Dropzone.CANCELED;
1268
        this.emit("canceled", file);
1269
        if (this.options.uploadMultiple) {
1270
          this.emit("canceledmultiple", [file]);
1271
        }
1272
      }
1273
      if (this.options.autoProcessQueue) {
1274
        return this.processQueue();
1275
      }
1276
    };
1277

  
1278
    Dropzone.prototype.uploadFile = function(file) {
1279
      return this.uploadFiles([file]);
1280
    };
1281

  
1282
    Dropzone.prototype.uploadFiles = function(files) {
1283
      var file, formData, handleError, headerName, headerValue, headers, input, inputName, inputType, key, progressObj, response, updateProgress, value, xhr, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1, _ref2, _ref3,
1284
        _this = this;
1285
      xhr = new XMLHttpRequest();
1286
      for (_i = 0, _len = files.length; _i < _len; _i++) {
1287
        file = files[_i];
1288
        file.xhr = xhr;
1289
      }
1290
      xhr.open(this.options.method, this.options.url, true);
1291
      xhr.withCredentials = !!this.options.withCredentials;
1292
      response = null;
1293
      handleError = function() {
1294
        var _j, _len1, _results;
1295
        _results = [];
1296
        for (_j = 0, _len1 = files.length; _j < _len1; _j++) {
1297
          file = files[_j];
1298
          _results.push(_this._errorProcessing(files, response || _this.options.dictResponseError.replace("{{statusCode}}", xhr.status), xhr));
1299
        }
1300
        return _results;
1301
      };
1302
      updateProgress = function(e) {
1303
        var allFilesFinished, progress, _j, _k, _l, _len1, _len2, _len3, _results;
1304
        if (e != null) {
1305
          progress = 100 * e.loaded / e.total;
1306
          for (_j = 0, _len1 = files.length; _j < _len1; _j++) {
1307
            file = files[_j];
1308
            file.upload = {
1309
              progress: progress,
1310
              total: e.total,
1311
              bytesSent: e.loaded
1312
            };
1313
          }
1314
        } else {
1315
          allFilesFinished = true;
1316
          progress = 100;
1317
          for (_k = 0, _len2 = files.length; _k < _len2; _k++) {
1318
            file = files[_k];
1319
            if (!(file.upload.progress === 100 && file.upload.bytesSent === file.upload.total)) {
1320
              allFilesFinished = false;
1321
            }
1322
            file.upload.progress = progress;
1323
            file.upload.bytesSent = file.upload.total;
1324
          }
1325
          if (allFilesFinished) {
1326
            return;
1327
          }
1328
        }
1329
        _results = [];
1330
        for (_l = 0, _len3 = files.length; _l < _len3; _l++) {
1331
          file = files[_l];
1332
          _results.push(_this.emit("uploadprogress", file, progress, file.upload.bytesSent));
1333
        }
1334
        return _results;
1335
      };
1336
      xhr.onload = function(e) {
1337
        var _ref;
1338
        if (files[0].status === Dropzone.CANCELED) {
1339
          return;
1340
        }
1341
        if (xhr.readyState !== 4) {
1342
          return;
1343
        }
1344
        response = xhr.responseText;
1345
        if (xhr.getResponseHeader("content-type") && ~xhr.getResponseHeader("content-type").indexOf("application/json")) {
1346
          try {
1347
            response = JSON.parse(response);
1348
          } catch (_error) {
1349
            e = _error;
1350
            response = "Invalid JSON response from server.";
1351
          }
1352
        }
1353
        updateProgress();
1354
        if (!((200 <= (_ref = xhr.status) && _ref < 300))) {
1355
          return handleError();
1356
        } else {
1357
          return _this._finished(files, response, e);
1358
        }
1359
      };
1360
      xhr.onerror = function() {
1361
        if (files[0].status === Dropzone.CANCELED) {
1362
          return;
1363
        }
1364
        return handleError();
1365
      };
1366
      progressObj = (_ref = xhr.upload) != null ? _ref : xhr;
1367
      progressObj.onprogress = updateProgress;
1368
      headers = {
1369
        "Accept": "application/json",
1370
        "Cache-Control": "no-cache",
1371
        "X-Requested-With": "XMLHttpRequest"
1372
      };
1373
      if (this.options.headers) {
1374
        extend(headers, this.options.headers);
1375
      }
1376
      for (headerName in headers) {
1377
        headerValue = headers[headerName];
1378
        xhr.setRequestHeader(headerName, headerValue);
1379
      }
1380
      formData = new FormData();
1381
      if (this.options.params) {
1382
        _ref1 = this.options.params;
1383
        for (key in _ref1) {
1384
          value = _ref1[key];
1385
          formData.append(key, value);
1386
        }
1387
      }
1388
      for (_j = 0, _len1 = files.length; _j < _len1; _j++) {
1389
        file = files[_j];
1390
        this.emit("sending", file, xhr, formData);
1391
      }
1392
      if (this.options.uploadMultiple) {
1393
        this.emit("sendingmultiple", files, xhr, formData);
1394
      }
1395
      if (this.element.tagName === "FORM") {
1396
        _ref2 = this.element.querySelectorAll("input, textarea, select, button");
1397
        for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
1398
          input = _ref2[_k];
1399
          inputName = input.getAttribute("name");
1400
          inputType = input.getAttribute("type");
1401
          if (!inputType || ((_ref3 = inputType.toLowerCase()) !== "checkbox" && _ref3 !== "radio") || input.checked) {
1402
            formData.append(inputName, input.value);
1403
          }
1404
        }
1405
      }
1406
      for (_l = 0, _len3 = files.length; _l < _len3; _l++) {
1407
        file = files[_l];
1408
        formData.append("" + this.options.paramName + (this.options.uploadMultiple ? "[]" : ""), file, file.name);
1409
      }
1410
      return xhr.send(formData);
1411
    };
1412

  
1413
    Dropzone.prototype._finished = function(files, responseText, e) {
1414
      var file, _i, _len;
1415
      for (_i = 0, _len = files.length; _i < _len; _i++) {
1416
        file = files[_i];
1417
        file.status = Dropzone.SUCCESS;
1418
        this.emit("success", file, responseText, e);
1419
        this.emit("complete", file);
1420
      }
1421
      if (this.options.uploadMultiple) {
1422
        this.emit("successmultiple", files, responseText, e);
1423
        this.emit("completemultiple", files);
1424
      }
1425
      if (this.options.autoProcessQueue) {
1426
        return this.processQueue();
1427
      }
1428
    };
1429

  
1430
    Dropzone.prototype._errorProcessing = function(files, message, xhr) {
1431
      var file, _i, _len;
1432
      /*  
1433
      snf: In case of error, error message defaults to server response, i.e. the html page.
1434
      To overwrite it, var message='error message' was added
1435
      */
1436
      var message = 'error message';
1437
      for (_i = 0, _len = files.length; _i < _len; _i++) {
1438
        file = files[_i];
1439
        file.status = Dropzone.ERROR;
1440
        this.emit("error", file, message, xhr);
1441
        this.emit("complete", file);
1442
      }
1443
      if (this.options.uploadMultiple) {
1444
        this.emit("errormultiple", files, message, xhr);
1445
        this.emit("completemultiple", files);
1446
      }
1447
      if (this.options.autoProcessQueue) {
1448
        return this.processQueue();
1449
      }
1450
    };
1451

  
1452
    return Dropzone;
1453

  
1454
  })(Em);
1455

  
1456
  Dropzone.version = "3.7.1";
1457

  
1458
  Dropzone.options = {};
1459

  
1460
  Dropzone.optionsForElement = function(element) {
1461
    if (element.id) {
1462
      return Dropzone.options[camelize(element.id)];
1463
    } else {
1464
      return void 0;
1465
    }
1466
  };
1467

  
1468
  Dropzone.instances = [];
1469

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff