Sha256: 6b1dd516ba4394b2838d35cdd787458640e90a9300ab1baa223543865b9b8061

Contents?: true

Size: 1.8 KB

Versions: 4

Compression:

Stored size: 1.8 KB

Contents

pageflow.FileStage = Backbone.Model.extend({
  initialize: function(attributes,  options) {
    this.file = options.file;

    this.activeStates = options.activeStates;
    this.finishedStates = options.finishedStates;
    this.failedStates = options.failedStates;
    this.actionRequiredStates = options.actionRequiredStates || [];

    this.update();
    this.listenTo(this.file, 'change:state', this.update);
    this.listenTo(this.file, 'change:encoding_progress', this.update);
    this.listenTo(this.file, 'change:uploading_progress', this.update);
  },

  update: function() {
    this.updateState();
    this.updateProgress();
    this.updateErrorMessage();
  },

  updateState: function() {
    var state = this.file.get('state');

    this.set('active', this.activeStates.indexOf(state) >= 0);
    this.set('finished', this.finishedStates.indexOf(state) >= 0);
    this.set('failed', this.failedStates.indexOf(state) >= 0);
    this.set('action_required', this.actionRequiredStates.indexOf(state) >= 0);

    if (this.get('active')) {
      this.set('state', 'active');
    }
    else if (this.get('finished')) {
      this.set('state', 'finished');
    }
    else if (this.get('failed')) {
      this.set('state', 'failed');
    }
    else if (this.get('action_required')) {
      this.set('state', 'action_required');
    }
    else {
      this.set('state', 'pending');
    }
  },

  updateProgress: function() {
    this.set('progress', this.file.get(this.get('name') + '_progress'));
  },

  updateErrorMessage: function() {
    var errorMessageAttribute = this.get('name').replace('_failed', '') + '_error_message';
    this.set('error_message', this.file.get(errorMessageAttribute));
  },

  localizedDescription: function() {
    return I18n.t('editor.files.stages.' + this.get('name') + '.' + this.get('state'));
  }
});

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pageflow-0.4.0 app/assets/javascripts/pageflow/editor/models/file_stage.js
pageflow-0.3.0 app/assets/javascripts/pageflow/editor/models/file_stage.js
pageflow-0.2.1 app/assets/javascripts/pageflow/editor/models/file_stage.js
pageflow-0.2.0 app/assets/javascripts/pageflow/editor/models/file_stage.js