Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_Related Related Topics sp_TopicIcon
Disabling submit button on edit form if lock is not obtained
30/05/2013
23:57
Avatar
trendready
Annandale, VA
Member
Members
Forum Posts: 5
Member Since:
29/05/2013
sp_UserOfflineSmall Offline

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.

31/05/2013
02:29
Avatar
trendready
Annandale, VA
Member
Members
Forum Posts: 5
Member Since:
29/05/2013
sp_UserOfflineSmall Offline

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;
    };

31/05/2013
02:50
Avatar
trendready
Annandale, VA
Member
Members
Forum Posts: 5
Member Since:
29/05/2013
sp_UserOfflineSmall Offline

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;
    };

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
42 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.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information