From: Tim Otten Date: Fri, 2 Aug 2013 22:41:33 +0000 (-0700) Subject: CRM-12911 - CRM.Backbone.sync - Add mechanism for API-assisted duplication of entities X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=f0e1e747b2c36a78c362f5617d816e1e1faaeb3e;p=civicrm-core.git CRM-12911 - CRM.Backbone.sync - Add mechanism for API-assisted duplication of entities ---------------------------------------- * CRM-12911: Implement "Duplicate" feature for Jobs http://issues.civicrm.org/jira/browse/CRM-12911 --- diff --git a/js/crm.backbone.js b/js/crm.backbone.js index f159c9e053..6d02cc246f 100644 --- a/js/crm.backbone.js +++ b/js/crm.backbone.js @@ -70,7 +70,11 @@ switch (method) { case 'create': // pass-through case 'update': - CRM.api(model.crmEntityName, 'create', model.toJSON(), apiOptions); + if (!model._isDuplicate) { + CRM.api(model.crmEntityName, 'create', model.toJSON(), apiOptions); + } else { + CRM.api(model.crmEntityName, 'duplicate', model.toJSON(), apiOptions); + } break; case 'read': case 'delete': @@ -111,6 +115,16 @@ crmEntityName: crmEntityName, toCrmCriteria: function() { return (this.get('id')) ? {id: this.get('id')} : {}; + }, + duplicate: function() { + var newModel = new ModelClass(this.toJSON()); + newModel._isDuplicate = true; + if (newModel.setModified) newModel.setModified(); + newModel.listenTo(newModel, 'sync', function(){ + // may get called on subsequent resaves -- don't care! + delete newModel._isDuplicate; + }); + return newModel; } }); // Overrides - if specified in ModelClass, replace