Sha256: 9e1afc0a44cf7d56331b1dbdc36c20a9b46e3d8a4acad4405142634274592d24

Contents?: true

Size: 1.89 KB

Versions: 17

Compression:

Stored size: 1.89 KB

Contents

pageflow.UploaderView = Backbone.Marionette.View.extend({
  el: 'form#upload',

  ui: {
    input: 'input#image_file_attachment',
    authToken: 'input[name="authenticity_token"]'
  },

  initialize: function() {
    this.listenTo(pageflow.app, 'request-upload', this.openFileDialog);
  },

  render: function() {
    var that = this;

    this.bindUIElements();

    this.$el.fileupload({
      acceptFileTypes: /(\.|\/)(bmp|gif|jpe?g|png|ti?f|wmv|mp4|mpg|mov|asf|asx|avi|m?v|mpeg|qt|3g2|3gp|3ivx|divx|3vx|vob|flv|dvx|xvid|mkv)$/i,
      dataType: 'json',

      add: function(event, data) {
        try {
          data.record = pageflow.entry.addFileUpload(data.files[0]);
          var xhr = data.submit();

          that.listenTo(data.record, 'uploadCancelled', function() {
            xhr.abort();
          });
        }
        catch(e) {
          if (e instanceof pageflow.FileTypes.UnmatchedUploadError) {
            pageflow.app.trigger('error', e);
          }
          else {
            throw(e);
          }
        }
      },

      progress: function(event, data) {
        data.record.set('uploading_progress', parseInt(data.loaded / data.total * 100, 10));
      },

      submit: function(event, data) {
        var record = data.record;

        this.action = record.url();

        data.paramName = record.modelName + '[attachment]';
        data.formData = {
          authenticity_token: that.ui.authToken.attr('value')
        };
      },

      done: function(event, data) {
        data.record.unset('uploading_progress');
        data.record.set(data.result);
      },

      fail: function(event, data) {
        if (data.errorThrown !== 'abort') {
          data.record.uploadFailed();
        }
      },

      always: function(event, data) {
        that.stopListening(data.record);
      }
    });

    return this;
  },

  openFileDialog: function() {
    this.$('input:file').click();
  }
});

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
pageflow-0.11.4 app/assets/javascripts/pageflow/editor/views/uploader_view.js
pageflow-0.11.3 app/assets/javascripts/pageflow/editor/views/uploader_view.js
pageflow-0.11.2 app/assets/javascripts/pageflow/editor/views/uploader_view.js
pageflow-0.11.1 app/assets/javascripts/pageflow/editor/views/uploader_view.js
pageflow-0.11.0 app/assets/javascripts/pageflow/editor/views/uploader_view.js
pageflow-0.10.0 app/assets/javascripts/pageflow/editor/views/uploader_view.js
pageflow-0.9.2 app/assets/javascripts/pageflow/editor/views/uploader_view.js
pageflow-0.9.1 app/assets/javascripts/pageflow/editor/views/uploader_view.js
pageflow-0.9.0 app/assets/javascripts/pageflow/editor/views/uploader_view.js
pageflow-0.8.2 app/assets/javascripts/pageflow/editor/views/uploader_view.js
pageflow-0.8.1 app/assets/javascripts/pageflow/editor/views/uploader_view.js
pageflow-0.8.0 app/assets/javascripts/pageflow/editor/views/uploader_view.js
pageflow-0.7.2 app/assets/javascripts/pageflow/editor/views/uploader_view.js
pageflow-0.7.1 app/assets/javascripts/pageflow/editor/views/uploader_view.js
pageflow-0.7.0 app/assets/javascripts/pageflow/editor/views/uploader_view.js
pageflow-0.6.0 app/assets/javascripts/pageflow/editor/views/uploader_view.js
pageflow-0.5.0 app/assets/javascripts/pageflow/editor/views/uploader_view.js