From f0e1e747b2c36a78c362f5617d816e1e1faaeb3e Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 2 Aug 2013 15:41:33 -0700 Subject: [PATCH] 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 --- js/crm.backbone.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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 -- 2.25.1