Locking documents on web - release lock problem

Please could you help a JS and Domino newbie?

I set up document locking for a web application.

It creates locking documents by running a LS agent in the WebQueryOpen event.

The locks are called by a closeDoc() function which runs a removeLock LS agent.

The locking docs are created as expected.

For testing I called the closeDoc() function in the ONUnload event of the form. This works nicely - even if the user closes the browser, the lock is removed - which is correct.

However, as we plan to add keywort type of fields, which require document reload on keyword change, having the closeDoc() function in the OnUnload event is a bad idea (docuent closing on doc refresh).

I tried using the OnFocus and OnBlur fields to set a flag then check the flag in OnUnload before running closeDoc(). The JS in OnFocus seems to run fine setting the flag and resulting in bypassing the closeDoc function in OnUnload.

However, the OnBlur JS code doesn’t seem to run - the flag is not reset resulting in closeDoc() function not running when the document needs to be closed.

Am I breaking any ‘rules’ by using this setup?

Is there a way to reset the flag? - maybe in another event…

Alternatively, I would consider a different approach to this problem… Any suggestions?

Code:

JS Header:

function closeDoc()

{

if (frm.mode.value==1)

{

window.location= frm.DBPath.value + "/RemoveLock?OpenAgent&user=" +  frm.originator.value  + "&unid=" + frm.UNID.value;

window.location = frm.DBPath.value  + "/main?OpenFrameset";

}

}

OnUnload:

var x=document.getElementById(“bypassClose”).value;

if(x = “”)

{

closeDoc();

}

document.getElementById(“bypassClose”).value=“”;

OnFocus (of the combobox field):

var x=document.getElementById(“bypassClose”).value;

document.getElementById(“bypassClose”).value=“Yes”;

OnBlur (of the combobox field):

var x=document.getElementById(“bypassClose”).value;

document.getElementById(“bypassClose”).value=“”;

Thanks

Subject: Locking documents on web - release lock problem.

I’ve never tried it from the onunload event, but the arguments to _doClick() should still be “live” when the document unloads if the unload is fired by the function. The second argument to _doClick() is always “this” (the element that caused the function to fire), so you should be able to test _doClick.arguments[1].name (or .id) to see what caused the unload. If the value is null, causes an error, or is an identifiable submit button/action, you can call your closeDoc(), otherwise the document is going back for a refresh.

Subject: RE: Locking documents on web - release lock problem.

I tried to find more references to this _doClick() but failed…

It looks like resetting the field cannot be done in the onChange event.

Fields containing keywords (comboboxes) will cause refresh of the whole document when the keywords are changed. “Refresh on keyword change” is ticked - I need this to be set this way.

So I set the flag in all the buttons that need to go through closeDoc(). A bit clumsy I guess, but it’ll do if it gets me past this project. Seems to work fine so far.

Where would I fond more references to _doClick()? I’d like to learn more about this and try to do similar things more efficiently.

Thank you

Subject: Locking documents on web - release lock problem.

Ramo,

I have a couple sugestions:

  1. Would you consider doing your window lock and unlock from an AJAX call? It would allow you to get your lock code out of the WebQueryOpen and remove the need for those window.location calls. A good intro can be found here: http://www.hunlock.com/blogs/AJAX_for_n00bs

  2. If you wanted to leave the lock code the way it is I have another idea. Populate your combo boxes with some ajax calls. Instead of having Domino do the “refresh choices” for you… call a “Dblookup” like script from javascript and then populate the following combo box yourself.

I have an example of a javascript @DBlookup here: http://codepress.net/b/2007/12/05/dblookup-in-javascript/

There are many different versions out there. The one above will return an array of strings.

First, get the selected value from your first control (combobox, textbox, radio buttons, etc) and use the DBLookup to get the list of choices for your next combobox.

Then, use some script like this to populate your combobox:

//target field is the actual field… not a string. newOptions should be a text list

function SetTargetFieldChoices(targetField,newOptions) {

var prevSelection = targetField.options[targetField.selectedIndex].text;

if (theNewOptions.length > 0) {

		targetField.options.length = 0;

		var optionName = new Option("--- Select One ---","", false, false)

		targetField.options[0] = optionName;

		for (var x =0;x < theNewOptions.length;x++) {

			optionName = new Option(theNewOptions[x], theNewOptions[x], false, false)

			targetField.options[x+1] = optionName;

			if (theNewOptions[x] == prevSelection) {

 				targetField.options[x+1].selected = true;

			}

		}

	

	}	else {

		targetField.options.length = 0;

		var optionName = new Option("--- No Choices Available ---","", false, false)

		targetField.options[0] = optionName;

	}

}

I hope I’ve provided a few ideas to get you past your problem.