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-4.4.2 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-4.4.1 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-4.4.0 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-4.3.4 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-4.2.4 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-4.1.5 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-4.3.3 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-4.3.2 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-4.1.4 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-4.3.1 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-4.3.0 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-4.2.3 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-4.1.3 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-4.0.4 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-3.4.6 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-4.0.3 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-4.1.2 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-4.2.2 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-3.4.5 app/assets/javascripts/spree/backend/views/images/upload_progress.js
solidus_backend-4.2.1 app/assets/javascripts/spree/backend/views/images/upload_progress.js