Sha256: 5064b89bb74259024c9a060b1463de65ea6c06aee6f140d530ff767422ff83c5

Contents?: true

Size: 1.54 KB

Versions: 4

Compression:

Stored size: 1.54 KB

Contents

exoskeleton.models.base_model = Backbone.Model.extend({

  __fetchStatus: new exoskeleton.models.load_status,

  fetchStatus: function(){
    return this.__fetchStatus
  },

  parse: function(response){
    var data = _.isUndefined(response.data) ? response : response.data
    return data
  },

  fetch: function(options){
    var _this = this ;
    this.__fetchStatus = new exoskeleton.models.load_status()
    Backbone.Model.prototype.fetch.call(this,{
      success: function(model, response){
        _this.__fetchStatus.set_completed()
        _this.__fetchStatus.set_message(response.message)
        if(response.success){
          _this.__fetchStatus.set_successful()
          _this._original_attributes = _.clone(model.attributes);
          _this.trigger('fetch:successful', model, response.data, response.message)
        } else {
          _this.trigger('fetch:unsuccessful', model, response.data, response.message)
        }
        if(options && options.success){
          options.success(model, response)
        }
        _this.trigger('fetch:complete', model, response.data, response.message)
      },
      error: function(model, response) {
        _this.__fetchStatus.set_completed()
        _this.__fetchStatus.set_message(response.message)
        _this.__fetchStatus.set_system_error()
        _this.trigger('fetch:error', model, response.data, response.message)
        if(options && options.error){
          options.error(model, response)
        }
        _this.trigger('fetch:complete', model, response.data, response.message)
      }
    })
  },


})

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
exoskeleton-0.0.6 app/assets/javascripts/exoskeleton/models/base_model.js
exoskeleton-0.0.5 app/assets/javascripts/exoskeleton/models/base_model.js
exoskeleton-0.0.4 app/assets/javascripts/exoskeleton/models/base_model.js
exoskeleton-0.0.3 app/assets/javascripts/exoskeleton/models/base_model.js