Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

More `this` in form editing #306

Merged
merged 1 commit into from

2 participants

Oleg Kiriljuk Tony Tomov
Oleg Kiriljuk

Setting this in dataInit, buildSelect and custom_element.

Signed-off-by: Dr. Oleg Kiriljuk oleg.kiriljuk@ok-soft-gmbh.com

Oleg Kiriljuk OlegKi More this in form editing.
Setting this in `dataInit`, `buildSelect` and `custom_element`.

Signed-off-by: Dr. Oleg Kiriljuk <oleg.kiriljuk@ok-soft-gmbh.com>
ddd98b5
Tony Tomov tonytomov merged commit 4c8a595 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 19, 2012
  1. Oleg Kiriljuk

    More this in form editing.

    OlegKi authored
    Setting this in `dataInit`, `buildSelect` and `custom_element`.
    
    Signed-off-by: Dr. Oleg Kiriljuk <oleg.kiriljuk@ok-soft-gmbh.com>
This page is out of date. Refresh to see the latest.
2  js/grid.celledit.js
View
@@ -75,7 +75,7 @@ $.jgrid.extend({
if(tmp2 !== undefined ) {tmp = tmp2;}
}
var opt = $.extend({}, cm.editoptions || {} ,{id:iRow+"_"+nm,name:nm});
- var elc = $.jgrid.createEl(cm.edittype,opt,tmp,true,$.extend({},$.jgrid.ajaxOptions,$t.p.ajaxSelectOptions || {}));
+ var elc = $.jgrid.createEl.call($t,cm.edittype,opt,tmp,true,$.extend({},$.jgrid.ajaxOptions,$t.p.ajaxSelectOptions || {}));
$($t).triggerHandler("jqGridBeforeEditCell", [$t.rows[iRow].id, nm, tmp, iRow, iCol]);
if ($.isFunction($t.p.beforeEditCell)) {
$t.p.beforeEditCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
10 js/grid.common.js
View
@@ -262,10 +262,10 @@ $.extend($.jgrid,{
},
// Form Functions
createEl : function(eltype,options,vl,autowidth, ajaxso) {
- var elem = "";
+ var elem = "", $t = this;
function bindEv (el, opt) {
if($.isFunction(opt.dataInit)) {
- opt.dataInit(el);
+ opt.dataInit.call($t,el);
}
if(opt.dataEvents) {
$.each(opt.dataEvents, function() {
@@ -351,8 +351,8 @@ $.extend($.jgrid,{
var a, ovm = [], elem = this.elem, vl = this.vl,
options = $.extend({},this.options),
msl = options.multiple===true;
- if(typeof(options.buildSelect) != "undefined") {
- var b = options.buildSelect(data);
+ if($.isFunction(options.buildSelect)) {
+ var b = options.buildSelect.call($t,data);
a = $(b).html();
} else {
a = $(data).html();
@@ -456,7 +456,7 @@ $.extend($.jgrid,{
elem = document.createElement("span");
try {
if($.isFunction(options.custom_element)) {
- var celm = options.custom_element.call(this,vl,options);
+ var celm = options.custom_element.call($t,vl,options);
if(celm) {
celm = $(celm).addClass("customelement").attr({id:options.id,name:options.name});
$(elem).empty().append(celm);
64 js/grid.formedit.js
View
@@ -468,11 +468,11 @@ $.jgrid.extend({
rp = parseInt(frmopt.rowpos,10) || cnt+1,
cp = parseInt((parseInt(frmopt.colpos,10) || 1)*2,10);
if(rowid == "_empty" && opt.defaultValue ) {
- tmp = $.isFunction(opt.defaultValue) ? opt.defaultValue() : opt.defaultValue;
+ tmp = $.isFunction(opt.defaultValue) ? opt.defaultValue.call($t) : opt.defaultValue;
}
if(!this.edittype) {this.edittype = "text";}
if($t.p.autoencode) {tmp = $.jgrid.htmlDecode(tmp);}
- elc = $.jgrid.createEl(this.edittype,opt,tmp,false,$.extend({},$.jgrid.ajaxOptions,obj.p.ajaxSelectOptions || {}));
+ elc = $.jgrid.createEl.call($t,this.edittype,opt,tmp,false,$.extend({},$.jgrid.ajaxOptions,obj.p.ajaxSelectOptions || {}));
if(tmp === "" && this.edittype == "checkbox") {tmp = $(elc).attr("offval");}
if(tmp === "" && this.edittype == "select") {tmp = $("option:eq(0)",elc).text();}
if(rp_ge[$t.p.id].checkOnSubmit || rp_ge[$t.p.id].checkOnUpdate) {rp_ge[$t.p.id]._savedData[nm] = tmp;}
@@ -518,7 +518,7 @@ $.jgrid.extend({
if(fld && fld.length && fld[0] !== null) {
vl = "";
if(opt.defaultValue ) {
- vl = $.isFunction(opt.defaultValue) ? opt.defaultValue() : opt.defaultValue;
+ vl = $.isFunction(opt.defaultValue) ? opt.defaultValue.call($t) : opt.defaultValue;
if(fld[0].type=='checkbox') {
vlc = vl.toLowerCase();
if(vlc.search(/(false|0|no|off|undefined)/i)<0 && vlc!=="") {
@@ -650,7 +650,7 @@ $.jgrid.extend({
}
for( key in postdata ){
if(postdata.hasOwnProperty(key)) {
- ret = $.jgrid.checkValues(postdata[key],key,$t);
+ ret = $.jgrid.checkValues.call($t,postdata[key],key,$t);
if(ret[0] === false) {break;}
}
}
@@ -665,7 +665,7 @@ $.jgrid.extend({
ret = [true,"",""];
}
if( ret[0] && $.isFunction(rp_ge[$t.p.id].beforeSubmit)) {
- ret = rp_ge[$t.p.id].beforeSubmit(postdata,$("#"+frmgr));
+ ret = rp_ge[$t.p.id].beforeSubmit.call($t,postdata,$("#"+frmgr));
}
}
@@ -705,7 +705,7 @@ $.jgrid.extend({
var ajaxOptions = $.extend({
url: rp_ge[$t.p.id].url ? rp_ge[$t.p.id].url : $($t).jqGrid('getGridParam','editurl'),
type: rp_ge[$t.p.id].mtype,
- data: $.isFunction(rp_ge[$t.p.id].serializeEditData) ? rp_ge[$t.p.id].serializeEditData(postdata) : postdata,
+ data: $.isFunction(rp_ge[$t.p.id].serializeEditData) ? rp_ge[$t.p.id].serializeEditData.call($t,postdata) : postdata,
complete:function(data,Status){
postdata[idname] = $t.p.idPrefix + postdata[idname];
if(Status != "success") {
@@ -909,7 +909,7 @@ $.jgrid.extend({
showFrm = true;
}
if(showFrm && onBeforeInit) {
- showFrm = onBeforeInit.call($t, $("#"+frmgr));
+ showFrm = onBeforeInit.call($t,$("#"+frmgr));
}
if(showFrm === false) {return;}
restoreInline();
@@ -965,7 +965,7 @@ $.jgrid.extend({
showFrm = true;
}
if(showFrm && onBeforeInit) {
- showFrm = onBeforeInit.call($t, $("#"+frmgr));
+ showFrm = onBeforeInit.call($t,$("#"+frmgr));
}
if(showFrm === false) {return;}
restoreInline();
@@ -1102,7 +1102,7 @@ $.jgrid.extend({
}
// here initform - only once
$($t).triggerHandler("jqGridAddEditInitializeForm", [$("#"+frmgr), frmoper]);
- if(onInitializeForm) {onInitializeForm($("#"+frmgr));}
+ if(onInitializeForm) {onInitializeForm.call($t,$("#"+frmgr));}
if(rowid=="_empty" || !rp_ge[$t.p.id].viewPagerButtons) {$("#pData,#nData",frmtb+"_2").hide();} else {$("#pData,#nData",frmtb+"_2").show();}
$($t).triggerHandler("jqGridAddEditBeforeShowForm", [$("#"+frmgr), frmoper]);
if(onBeforeShow) { onBeforeShow.call($t, $("#"+frmgr));}
@@ -1349,7 +1349,7 @@ $.jgrid.extend({
if ( $("#"+$.jgrid.jqID(IDs.themodal)).html() !== null ) {
if(onBeforeInit) {
- showFrm = onBeforeInit($("#"+frmgr));
+ showFrm = onBeforeInit.call($t,$("#"+frmgr));
if(typeof(showFrm) == "undefined") {
showFrm = true;
}
@@ -1358,7 +1358,7 @@ $.jgrid.extend({
$(".ui-jqdialog-title","#"+$.jgrid.jqID(IDs.modalhead)).html(p.caption);
$("#FormError","#"+frmtb).hide();
fillData(rowid,$t);
- if($.isFunction(p.beforeShowForm)) {p.beforeShowForm($("#"+frmgr));}
+ if($.isFunction(p.beforeShowForm)) {p.beforeShowForm.call($t,$("#"+frmgr));}
$.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{gbox:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, jqM: false, overlay: p.overlay, modal:p.modal});
focusaref();
} else {
@@ -1366,7 +1366,7 @@ $.jgrid.extend({
var frm = $("<form name='FormPost' id='"+frmgr_id+"' class='FormGrid' style='width:100%;overflow:auto;position:relative;height:"+dh+";'></form>"),
tbl =$("<table id='"+frmtb_id+"' class='EditTable' cellspacing='1' cellpadding='2' border='0' style='table-layout:fixed'><tbody></tbody></table>");
if(onBeforeInit) {
- showFrm = onBeforeInit($("#"+frmgr));
+ showFrm = onBeforeInit.call($t,$("#"+frmgr));
if(typeof(showFrm) == "undefined") {
showFrm = true;
}
@@ -1437,7 +1437,7 @@ $.jgrid.extend({
$("#cData","#"+frmtb+"_2").addClass(p.closeicon[1] == "right" ? 'fm-button-icon-right' : 'fm-button-icon-left')
.append("<span class='ui-icon "+p.closeicon[2]+"'></span>");
}
- if($.isFunction(p.beforeShowForm)) {p.beforeShowForm($("#"+frmgr));}
+ if($.isFunction(p.beforeShowForm)) {p.beforeShowForm.call($t,$("#"+frmgr));}
$.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{gbox:"#gbox_"+$.jgrid.jqID(gID),jqm:p.jqModal, modal:p.modal});
$(".fm-button:not(.ui-state-disabled)","#"+frmtb+"_2").hover(
function(){$(this).addClass('ui-state-hover');},
@@ -1454,12 +1454,12 @@ $.jgrid.extend({
npos[0] = parseInt(npos[0],10);
if(npos[0] != -1 && npos[1][npos[0]+1]) {
if($.isFunction(p.onclickPgButtons)) {
- p.onclickPgButtons('next',$("#"+frmgr),npos[1][npos[0]]);
+ p.onclickPgButtons.call($t,'next',$("#"+frmgr),npos[1][npos[0]]);
}
fillData(npos[1][npos[0]+1],$t);
$($t).jqGrid("setSelection",npos[1][npos[0]+1]);
if($.isFunction(p.afterclickPgButtons)) {
- p.afterclickPgButtons('next',$("#"+frmgr),npos[1][npos[0]+1]);
+ p.afterclickPgButtons.call($t,'next',$("#"+frmgr),npos[1][npos[0]+1]);
}
updateNav(npos[0]+1,npos[1].length-1);
}
@@ -1471,12 +1471,12 @@ $.jgrid.extend({
var ppos = getCurrPos();
if(ppos[0] != -1 && ppos[1][ppos[0]-1]) {
if($.isFunction(p.onclickPgButtons)) {
- p.onclickPgButtons('prev',$("#"+frmgr),ppos[1][ppos[0]]);
+ p.onclickPgButtons.call($t,'prev',$("#"+frmgr),ppos[1][ppos[0]]);
}
fillData(ppos[1][ppos[0]-1],$t);
$($t).jqGrid("setSelection",ppos[1][ppos[0]-1]);
if($.isFunction(p.afterclickPgButtons)) {
- p.afterclickPgButtons('prev',$("#"+frmgr),ppos[1][ppos[0]-1]);
+ p.afterclickPgButtons.call($t,'prev',$("#"+frmgr),ppos[1][ppos[0]-1]);
}
updateNav(ppos[0]-1,ppos[1].length-1);
}
@@ -1535,7 +1535,7 @@ $.jgrid.extend({
if (jQuery.isArray(rowids)) {rowids = rowids.join();}
if ( $("#"+$.jgrid.jqID(IDs.themodal)).html() !== null ) {
if(onBeforeInit) {
- showFrm = onBeforeInit( $("#"+dtbl));
+ showFrm = onBeforeInit.call($t,$("#"+dtbl));
if(typeof(showFrm) == "undefined") {
showFrm = true;
}
@@ -1547,9 +1547,9 @@ $.jgrid.extend({
rp_ge[$t.p.id].processing=false;
$("#dData", "#"+dtbl).removeClass('ui-state-active');
}
- if(onBeforeShow) {rp_ge[$t.p.id].beforeShowForm($("#"+dtbl));}
+ if(onBeforeShow) {rp_ge[$t.p.id].beforeShowForm.call($t,$("#"+dtbl));}
$.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{gbox:"#gbox_"+$.jgrid.jqID(gID),jqm:rp_ge[$t.p.id].jqModal,jqM: false, overlay: rp_ge[$t.p.id].overlay, modal:rp_ge[$t.p.id].modal});
- if(onAfterShow) {rp_ge[$t.p.id].afterShowForm($("#"+dtbl));}
+ if(onAfterShow) {rp_ge[$t.p.id].afterShowForm.call($t,$("#"+dtbl));}
} else {
var dh = isNaN(rp_ge[$t.p.id].dataheight) ? rp_ge[$t.p.id].dataheight : rp_ge[$t.p.id].dataheight+"px";
var tbl = "<div id='"+dtbl_id+"' class='formdata' style='width:100%;overflow:auto;position:relative;height:"+dh+";'>";
@@ -1567,7 +1567,7 @@ $.jgrid.extend({
$.jgrid.createModal(IDs,tbl,p,"#gview_"+$.jgrid.jqID($t.p.id),$("#gview_"+$.jgrid.jqID($t.p.id))[0]);
if(onBeforeInit) {
- showFrm = onBeforeInit( $("#"+dtbl) );
+ showFrm = onBeforeInit.call($t,$("#"+dtbl));
if(typeof(showFrm) == "undefined") {
showFrm = true;
}
@@ -1591,8 +1591,8 @@ $.jgrid.extend({
$("#dData","#"+dtbl+"_2").click(function(){
var ret=[true,""];onCS = {};
var postdata = $("#DelData>td","#"+dtbl).text(); //the pair is name=val1,val2,...
- if( $.isFunction( rp_ge[$t.p.id].onclickSubmit ) ) {onCS = rp_ge[$t.p.id].onclickSubmit(rp_ge[$t.p.id], postdata) || {};}
- if( $.isFunction( rp_ge[$t.p.id].beforeSubmit ) ) {ret = rp_ge[$t.p.id].beforeSubmit(postdata);}
+ if( $.isFunction( rp_ge[$t.p.id].onclickSubmit ) ) {onCS = rp_ge[$t.p.id].onclickSubmit.call($t,rp_ge[$t.p.id], postdata) || {};}
+ if( $.isFunction( rp_ge[$t.p.id].beforeSubmit ) ) {ret = rp_ge[$t.p.id].beforeSubmit.call($t,postdata);}
if(ret[0] && !rp_ge[$t.p.id].processing) {
rp_ge[$t.p.id].processing = true;
opers = $t.p.prmNames;
@@ -1612,12 +1612,12 @@ $.jgrid.extend({
var ajaxOptions = $.extend({
url: rp_ge[$t.p.id].url ? rp_ge[$t.p.id].url : $($t).jqGrid('getGridParam','editurl'),
type: rp_ge[$t.p.id].mtype,
- data: $.isFunction(rp_ge[$t.p.id].serializeDelData) ? rp_ge[$t.p.id].serializeDelData(postd) : postd,
+ data: $.isFunction(rp_ge[$t.p.id].serializeDelData) ? rp_ge[$t.p.id].serializeDelData.call($t,postd) : postd,
complete:function(data,Status){
if(Status != "success") {
ret[0] = false;
if ($.isFunction(rp_ge[$t.p.id].errorTextFormat)) {
- ret[1] = rp_ge[$t.p.id].errorTextFormat(data);
+ ret[1] = rp_ge[$t.p.id].errorTextFormat.call($t,data);
} else {
ret[1] = Status + " Status: '" + data.statusText + "'. Error code: " + data.status;
}
@@ -1625,7 +1625,7 @@ $.jgrid.extend({
// data is posted successful
// execute aftersubmit with the returned data from server
if( $.isFunction( rp_ge[$t.p.id].afterSubmit ) ) {
- ret = rp_ge[$t.p.id].afterSubmit(data,postd);
+ ret = rp_ge[$t.p.id].afterSubmit.call($t,data,postd);
}
}
if(ret[0] === false) {
@@ -1646,7 +1646,7 @@ $.jgrid.extend({
$t.p.selarrrow = [];
}
if($.isFunction(rp_ge[$t.p.id].afterComplete)) {
- setTimeout(function(){rp_ge[$t.p.id].afterComplete(data,postdata);},500);
+ setTimeout(function(){rp_ge[$t.p.id].afterComplete.call($t,data,postdata);},500);
}
}
rp_ge[$t.p.id].processing=false;
@@ -1690,9 +1690,9 @@ $.jgrid.extend({
$.jgrid.hideModal("#"+$.jgrid.jqID(IDs.themodal),{gb:"#gbox_"+$.jgrid.jqID(gID),jqm:rp_ge[$t.p.id].jqModal, onClose: rp_ge[$t.p.id].onClose});
return false;
});
- if(onBeforeShow) {rp_ge[$t.p.id].beforeShowForm($("#"+dtbl));}
+ if(onBeforeShow) {rp_ge[$t.p.id].beforeShowForm.call($t,$("#"+dtbl));}
$.jgrid.viewModal("#"+$.jgrid.jqID(IDs.themodal),{gbox:"#gbox_"+$.jgrid.jqID(gID),jqm:rp_ge[$t.p.id].jqModal, overlay: rp_ge[$t.p.id].overlay, modal:rp_ge[$t.p.id].modal});
- if(onAfterShow) {rp_ge[$t.p.id].afterShowForm($("#"+dtbl));}
+ if(onAfterShow) {rp_ge[$t.p.id].afterShowForm.call($t,$("#"+dtbl));}
}
if(rp_ge[$t.p.id].closeOnEscape===true) {
setTimeout(function(){$(".ui-jqdialog-titlebar-close","#"+$.jgrid.jqID(IDs.modalhead)).focus();},0);
@@ -1931,13 +1931,13 @@ $.jgrid.extend({
.attr({"title":o.refreshtitle || "",id: "refresh_"+elemids})
.click(function(){
if (!$(this).hasClass('ui-state-disabled')) {
- if($.isFunction(o.beforeRefresh)) {o.beforeRefresh();}
+ if($.isFunction(o.beforeRefresh)) {o.beforeRefresh.call($t);}
$t.p.search = false;
try {
var gID = $t.p.id;
$t.p.postData.filters ="";
$("#fbox_"+$.jgrid.jqID(gID)).jqFilter('resetFilter');
- if($.isFunction($t.clearToolbar)) {$t.clearToolbar(false);}
+ if($.isFunction($t.clearToolbar)) {$t.clearToolbar.call($t,false);}
} catch (e) {}
switch (o.refreshstate) {
case 'firstpage':
@@ -1947,7 +1947,7 @@ $.jgrid.extend({
$($t).trigger("reloadGrid", [{current:true}]);
break;
}
- if($.isFunction(o.afterRefresh)) {o.afterRefresh();}
+ if($.isFunction(o.afterRefresh)) {o.afterRefresh.call($t);}
}
return false;
}).hover(
2  js/grid.inlinedit.js
View
@@ -75,7 +75,7 @@ $.jgrid.extend({
var opt = $.extend({},cm[i].editoptions || {},{id:rowid+"_"+nm,name:nm});
if(!cm[i].edittype) { cm[i].edittype = "text"; }
if(tmp == "&nbsp;" || tmp == "&#160;" || (tmp.length==1 && tmp.charCodeAt(0)==160) ) {tmp='';}
- var elc = $.jgrid.createEl(cm[i].edittype,opt,tmp,true,$.extend({},$.jgrid.ajaxOptions,$t.p.ajaxSelectOptions || {}));
+ var elc = $.jgrid.createEl.call($t,cm[i].edittype,opt,tmp,true,$.extend({},$.jgrid.ajaxOptions,$t.p.ajaxSelectOptions || {}));
$(elc).addClass("editable");
if(treeg) { $("span:first",this).append(elc); }
else { $(this).append(elc); }
Something went wrong with that request. Please try again.