Merge pull request #4757 from davecivicrm/CRM-15409
[civicrm-core.git] / js / crm.backbone.js
index 4913abfbe9d114a4f328e01796ad8f36895ff50d..eb45249c1717e9fd3ac194efdfc7d0a811baabb0 100644 (file)
@@ -1,5 +1,4 @@
-(function($) {
-  var CRM = (window.CRM) ? (window.CRM) : (window.CRM = {});
+(function($, _) {
   if (!CRM.Backbone) CRM.Backbone = {};
 
   /**
     _.defaults(ModelClass.prototype, {
       crmEntityName: crmEntityName,
       crmActions: {}, // map: string backboneActionName => string serverSideActionName
+      crmReturn: null, // array: list of fields to return
       toCrmAction: function(action) {
         return this.crmActions[action] ? this.crmActions[action] : action;
       },
       toCrmCriteria: function() {
-        return (this.get('id')) ? {id: this.get('id')} : {};
+        var result = (this.get('id')) ? {id: this.get('id')} : {};
+        if (this.crmReturn != null) {
+          result.return = this.crmReturn;
+        }
+        return result;
       },
       duplicate: function() {
         var newModel = new ModelClass(this.toJSON());
         return this.crmActions[action] ? this.crmActions[action] : action;
       },
       toCrmCriteria: function() {
-        return (this.crmCriteria) ? _.extend({}, this.crmCriteria) : {};
+        var result = (this.crmCriteria) ? _.extend({}, this.crmCriteria) : {};
+        if (this.crmReturn != null) {
+          result.return = this.crmReturn;
+        } else if (this.model && this.model.prototype.crmReturn != null) {
+          result.return = this.model.prototype.crmReturn;
+        }
+        return result;
       },
 
       /**
 
       debouncedFetch: _.debounce(function() {
         this.fetch({reset: true});
-      }, 500),
+      }, 100),
 
       /**
        * Reconcile the server's collection with the client's collection.
   var wrapError = function (model, options) {
     var error = options.error;
     options.error = function(resp) {
-      if (error) error(model, resp, options);
+      if (error) error(model, resp, optio)
       model.trigger('error', model, resp, options);
     };
   };
-})(cj);
+})(CRM.$, CRM._);