Sha256: 6571019480591863b54b6a92a2cab90023c032151b74fd2d21b0be64e650887a

Contents?: true

Size: 1.28 KB

Versions: 149

Compression:

Stored size: 1.28 KB

Contents

Spree.Views.Images.UploadProgress = Backbone.View.extend({
  tagName: "div",

  // Cache the template function for a single item.
  template: HandlebarsTemplates["products/upload_progress"],

  initialize: function() {
    this.listenTo(this.model, 'change:progress', this.updateProgressBar);
    this.listenTo(this.model, 'change', this.render);
    this.listenTo(this.model, 'destroy', this.remove);
  },

  events: {
    "clear" : "clear"
  },

  className: 'col-sm-6 col-md-4 mb-3',

  attributes: function() {
    return {
      "data-upload-id": this.model.cid
    }
  },

  render: function() {
    // Skip progress bar update for better performance
    var changedAttrs = Object.keys(this.model.changed);
    if(changedAttrs.length === 1 && changedAttrs[0] == 'progress') return this;

    this.el.innerHTML = this.template(this.model.toJSON());
    this.updateProgressBar();
    return this;
  },

  updateProgressBar: function() {
    var progressBar = this.el.querySelector('.progress-bar');
    var percent = this.model.get('progress');
    progressBar.setAttribute('aria-valuenow', percent);
    progressBar.style.width = percent + '%';
    progressBar.innerHTML = percent + '%';
    return this;
  },

  // Remove the item, destroy the model
  clear: function() {
    this.model.destroy();
  }
});

Version data entries

149 entries across 149 versions & 2 rubygems

Version Path
solidus_backend-2.11.13 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-3.0.4 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-3.1.4 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-2.11.12 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-3.0.3 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-3.1.3 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-3.1.2 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-3.1.1 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-3.1.0 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-2.11.11 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-3.0.2 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-2.10.5 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-2.11.10 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-3.0.1 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-3.0.0 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-2.11.9 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-2.11.8 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-2.11.7 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-2.11.6 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-3.0.0.rc2 app/assets/javascripts/spree/backend/views/images/upload_progress.js