Forum
23:57
29/05/2013
In my system, I need to obtain a lock on a record before I can edit it.
My primary key is a column in the jqGrid with the following params ,hidden: true, editable: true, editrules:{edithiddend:true}
I need to call out to the server with the table name and primary key id. The response will come back in JSON as OK or a message.
Where should I put the lock code so that it will gets called while browsing in the edit form? beforeShowForm?
How do I access the primary key in the beforeShowForm function?
In the onclickSubmit function, I can access the primary key by using var $sid = posdata['results.security_id']
I only need to obtain a lock on edits not adds, so how do I tell if the beforeShowForm is add or edit?
Thanks in advance.
02:29
29/05/2013
Progress report... ok I have partially figured it out for myself. The code below does request a lock and if the lock_id comes back then the record it ok to edit. If not the Submit button is hidden (disabled would be better). But I still don't know here this code should go in the event the user uses the page button. I guess I can cut out the locking code into another function and call it from the onclickPgButton function.
Any thoughts??
$gridSecurity.jqGrid(
"navGrid"
,"#grid-security-pager"
,{view:false, edit:true, add:true, del:false, refresh:true, search:false} // options
,dialogParams(true) // edit options
,dialogParams(false) // add options
,{} // search options
);
function dialogParams(editMode) {
var $properties = {
modal: true
,width: 600
,closeOnEscape: true
,closeAfterAdd: true
,closeAfterEdit: true
,reloadAfterSubmit: true
,beforeShowForm: function (formid){
if (editMode) {
var lockObtained = false,
id = $gridSecurity.jqGrid ('getGridParam', 'selrow'),
$sid = $gridSecurity.jqGrid ('getCell', id, 'results.security_id');
$.ajax({
url: "/iproc?exec=wp_security_set_properties&Server=Portfolio&fmt=json&mode=lock&security_id=" + $sid,
dataType: 'json',
async: false,
success: function( data ) {
lockObtained = (data.results[0].lock_id>0);
}
});
if (!lockObtained) {
formid.parent().find('#sData').hide();
}
}
}
}
return $properties;
};
02:50
29/05/2013
ok, here is the completed code that seems to work ok. I put in a few alerts to show me how it was working.
Note: I left out the onclickSubmit code for clarity.
Paul
--------------------------------------------------------------------------------------------------------------------------------------------------
function lockRequest(LockURL){
var lockObtained = false;
$.ajax({
url: LockURL,
dataType: 'json',
async: false,
success: function( data ) {
lockObtained = (data.results[0].lock_id>0);
}
});
return lockObtained;
};
$gridSecurity.jqGrid(
"navGrid"
,"#grid-security-pager"
,{view:false, edit:true, add:true, del:false, refresh:true, search:false} // options
,dialogParams(true) // edit options
,dialogParams(false) // add options
,{} // search options
);
function dialogParams(editMode) {
var $properties = {
modal: true
,width: 600
,closeOnEscape: true
,closeAfterAdd: true
,closeAfterEdit: true
,reloadAfterSubmit: true
,beforeShowForm: function (formid){
if (editMode) {
var id = $gridSecurity.jqGrid ('getGridParam', 'selrow'),
$sid = $gridSecurity.jqGrid ('getCell', id, 'results.security_id'),
lockObtained = lockRequest("/iproc?exec=wp_security_set_properties&Server=Portfolio&fmt=json&mode=lock&security_id=" + $sid)
;
if (!lockObtained) {
formid.parent().find('#sData').hide();
} else {
alert('Lock request granted')
}
}
}
,onclickPgButtons: function( whichbutton, formid, rowid){
var $sid = $gridSecurity.jqGrid ('getCell', rowid, 'results.security_id'),
lockObtained = lockRequest("/iproc?exec=wp_security_set_properties&Server=Portfolio&fmt=json&mode=lock&security_id=" + $sid)
;
if (!lockObtained) {
formid.parent().find('#sData').hide();
} else {
alert('Lock request granted')
}
}
}
return $properties;
};
Most Users Ever Online: 715
Currently Online:
40 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66