From e32d748a7da7e14cc3bf959c928b377b4ed45d76 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 13 Mar 2013 12:04:15 -0700 Subject: [PATCH] Introduce 'context' param to CRM.api CRM-12029 --- js/jquery/jquery.crmeditable.js | 7 ++++--- js/rest.js | 16 ++++++++-------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/js/jquery/jquery.crmeditable.js b/js/jquery/jquery.crmeditable.js index f4a32c0096..41adf8d751 100644 --- a/js/jquery/jquery.crmeditable.js +++ b/js/jquery/jquery.crmeditable.js @@ -98,8 +98,8 @@ return false; params['value']=checked?'1':'0';//seems that the ajax backend gets lost with boolean - //CRM.api.call(this,entity,'create',params,{ create is still too buggy & perf - CRM.api.call(this,entity,'setvalue',params,{ + CRM.api(entity,'setvalue',params,{ + context: this, error: function (data) { editableSettings.error.call(this,entity,fieldName,checked,data); }, @@ -249,7 +249,8 @@ } else { action="setvalue"; } - CRM.api.call(this,entity,action,params,{ + CRM.api(entity, action, params, { + context: this, error: function (data) { editableSettings.error.call(this,entity,fieldName,value,data); }, diff --git a/js/rest.js b/js/rest.js index 8cec7c8167..0cdb94f71c 100644 --- a/js/rest.js +++ b/js/rest.js @@ -86,7 +86,9 @@ var CRM = CRM || {}; */ CRM.api = function(entity, action, params, options) { // Default settings - var settings = { + var json = false, + settings = { + context: null, success: function(result, settings) { return true; }, @@ -120,8 +122,6 @@ var CRM = CRM || {}; return true; }; } - $.extend(settings, options); - var json = false; for (var i in params) { if (i.slice(0, 4) == 'api.' || typeof(params[i]) == 'Object') { json = true; @@ -141,17 +141,17 @@ var CRM = CRM || {}; params.json = 1; } // Pass copy of settings into closure to preserve its value during multiple requests - (function(stg, that) { + (function(stg) { $.ajax({ url: stg.ajaxURL.indexOf('http') === 0 ? stg.ajaxURL : CRM.url(stg.ajaxURL), dataType: 'json', data: params, type: action.indexOf('get') < 0 ? 'POST' : 'GET', success: function(result) { - stg.callBack.call(that, result, stg); + stg.callBack.call(stg.context, result, stg); } }); - })($.extend({}, settings), this); + })($.extend({}, settings, options)); }; // Backwards compatible with jQuery fn @@ -163,11 +163,11 @@ var CRM = CRM || {}; $.fn.crmAutocomplete = function (params, options) { if (typeof params == 'undefined') params = {}; if (typeof options == 'undefined') options = {}; - params = $().extend( { + params = $().extend({ rowCount:35, json:1, entity:'Contact', - action:'getquick', + action:'getquick', sequential:1 }, params); -- 2.25.1