Permalink
Browse files

Using deep copy when extend parameters for inline edit

  • Loading branch information...
1 parent 9751318 commit df5193e9c278247afb4d634b204f66242aedd55f @tonytomov committed Dec 16, 2011
Showing with 4 additions and 4 deletions.
  1. +4 −4 js/grid.inlinedit.js
View
@@ -30,7 +30,7 @@ $.jgrid.extend({
args = $.makeArray(arguments).slice(1), o;
if(args[0] && typeof(args[0]) == "object" && !$.isFunction(args[0])) {
- o = $.extend($.jgrid.inlineEdit, settings, args[0]);
+ o = $.extend(true, $.jgrid.inlineEdit, settings, args[0]);
} else {
o = settings;
}
@@ -114,7 +114,7 @@ $.jgrid.extend({
args = $.makeArray(arguments).slice(1), o;
if(args[0] && typeof(args[0]) == "object" && !$.isFunction(args[0])) {
- o = $.extend($.jgrid.inlineEdit, settings, args[0]);
+ o = $.extend(true, $.jgrid.inlineEdit, settings, args[0]);
} else {
o = settings;
}
@@ -301,7 +301,7 @@ $.jgrid.extend({
args = $.makeArray(arguments).slice(1), o;
if(args[0] && typeof(args[0]) == "object" && !$.isFunction(args[0])) {
- o = $.extend($.jgrid.inlineEdit, settings, args[0]);
+ o = $.extend(true, $.jgrid.inlineEdit, settings, args[0]);
} else {
o = settings;
}
@@ -340,7 +340,7 @@ $.jgrid.extend({
});
},
addRow : function ( p ) {
- p = $.extend({
+ p = $.extend(true, {
rowID : "new_row",
initdata : {},
position :"first",

2 comments on commit df5193e

Contributor

OlegKi replied Dec 18, 2011

Hello Tony,

The changes still not fix the bug. The first problem is that settings will be initialized before with keys properties set as an object in case of editRow or with successfunc initialized as an object instead of function in case of saveRow. The next problem is that the settings $.jgrid.inlineEdit will be overwrite by default values from the settings.

I described here possible changes which will fix there.

I think that probably it will be better to rewrite the code at the beginning of the editRow, saveRow and restoreRow. The variable settings will be used only at the initialization steps and the variable o can be initialized directly. Moreover the current code allows not only the call of for example editRow in the form

jQuery("#grid_id").jqGrid('editRow',rowid, keys, oneditfunc, succesfunc, url, extraparam, aftersavefunc,errorfunc, afterrestorefunc);

or in the form

jQuery("#grid_id").jqGrid('editRow',rowid, {keys: true, oneditfunc: myFunc});

but also in the form

jQuery("#grid_id").jqGrid('editRow',rowid, {keys: true, oneditfunc: myFunc}, myEditFunc2, mySuccesFunc);

which make the logic more complex. Probably it would be better to ignore all other parameters if any exist if the key parameter will be object? I mean that one should use really empty parameters in case of typeof(args[0]) === "object". One can rewrite the first lines of the editRow for example to the following

var o;

if (typeof keys === "object" && !$.isFunction(keys)) {
    o = $.extend(true, {
            successfunc: null,
            url: null,
            extraparam: {},
            aftersavefunc: null,
            errorfunc: null,
            afterrestorefunc: null,
            restoreAfterError: true,
            mtype: "POST"
        }, $.jgrid.inlineEdit, keys);
} else {
    o = {};
    // don't set any default settings in o to prevent
    // ovewriting of the corresponding settings of $.jgrid.inlineEdit
    if (typeof keys !== "undefined") { o.keys = keys; }
    if ($.isFunction(oneditfunc)) { o.oneditfunc = oneditfunc; }
    if ($.isFunction(successfunc)) { o.successfunc = successfunc; }
    if (typeof url !== "undefined") { o.url = url; }
    if (typeof extraparam !== "undefined") { o.extraparam = extraparam; }
    if ($.isFunction(aftersavefunc)) { o.aftersavefunc = aftersavefunc; }
    if ($.isFunction(errorfunc)) { o.errorfunc = errorfunc; }
    if ($.isFunction(afterrestorefunc)) { o.afterrestorefunc = afterrestorefunc; }
    if (typeof restoreAfterError !== "undefined") { o.restoreAfterError = restoreAfterError; }
    if (typeof mtype !== "undefined") { o.mtype = mtype || "POST"; }

    o = $.extend(true, {
            successfunc: null,
            url: null,
            extraparam: {},
            aftersavefunc: null,
            errorfunc: null,
            afterrestorefunc: null,
            restoreAfterError: true,
            mtype: "POST"
        }, $.jgrid.inlineEdit, o);
}

Best regards
Oleg

Owner

tonytomov replied Dec 19, 2011

Oleg,
Thanks. I see the problem. I have fixed it (I hope). You can look at this in the last commits.
I hope later this day to publish the first bug fix for 4.3 version.
Thank you again

Tony

Please sign in to comment.