This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

DEVELOPERS FORUM - Ask for Save and Unlock automatically after unload the form Part

Remi - Wednesday, August 5, 2009 11:19 AM:

Hi,

I want when someone is closing the Form Part to  ask the user if  he want to save in case of modifications without saving and  next unlocking the part whatever happens when someone is closing  :

So I add a method in the Part Form Event, I try something like that :


alert("new method OnUnLoad2");
var itm = new Item("tmp", "tmp");

itm.loadAML("<Item type='Method' action='unlockMe'/>");

itm = itm.apply();

 

With the method unlockMe :

unlockItem();

or this.apply("unlock")

But this doesn't work...

However I don't find anything in the documentation about Saving Item.

 

thanks a lot,

Regards,

 

 

 

 



SamsAn - Thursday, August 6, 2009 12:40 AM:

It whould be better to use internal client api to save/unlock the item (to have internal cache, items grid, etc. updated). Use javascript code lines below:

parent.onSaveUnlockAndExitCommand();

or

top.onSaveUnlockAndExitCommand();

SamsAn.
Original Mind Any Level Innovator Solutions Free-Lancer, http://sites.google.com/site/caraacc



Remi - Thursday, August 6, 2009 5:05 AM:

Hi,

 Thanks for the answer, What is for you the internal client api ?

 You mean modify directly the javascript code in the ~ArasInnovatorInnovatorClientscripts ?

If I am correct, I don't know where to put the additionnal code.

 

Regards,

Remi



SamsAn - Friday, August 7, 2009 1:05 AM:

You should add onLoad event handler to Part form with the method having code like below:

function MyFunc()
{
  top.onSaveUnlockAndExitCommand();
}
window.attachEvent("onbeforeunload", MyFunc);
top.MyFunc = MyFunc;


SamsAn.
Original Mind Any Level Innovator Solutions Free-Lancer, http://sites.google.com/site/caraacc



Remi - Friday, August 7, 2009 7:00 AM:

Thanks a lot for you help,

 It is working. For my final solution I use this method :

function MyFunc()
{

  if ( top.isEditMode )
  {    
                     top.onUnlockCommand();        
  }  
 
}
window.attachEvent("onbeforeunload", MyFunc);
top.MyFunc = MyFunc;

It is a pretty good solution because, if don't have modify the part : It automatically unlock it without saying anything and if you have proceeded modification it simply ask you if you want to keep it  or not.

Finally it's a normal behaviour like any other software.

Regards

 



Remi - Monday, August 10, 2009 5:29 AM:

Hum,

 

 Actually this is not a great solution, because there is conflict during the unlocking procedure. It displays that the item is not locked by you.

So I spoke too quickly.. The both solutions in the last two posts is not correct

 

Regards



SamsAn - Monday, August 10, 2009 12:27 PM:

In MyFunc, use code lines like:

var itm = document.thisItem;

if (itm.getAttribute("action")!="add" && !itm.getProperty("locked_by_id")) itm.setAttribute("action", "edit");

Not 100% sure, but it should help to resolve "not locked by you" issue.



Remi - Tuesday, August 11, 2009 4:59 AM:

Hum actually, it seems to be the same problem. I put here my code again :

function MyFunc()
{
   var itm = document.thisItem;
   if (itm.getAttribute("action")!="add" && !itm.getProperty("locked_by_id"))
   {
         itm.setAttribute("action", "edit");
   }
    top.onSaveUnlockAndExitCommand();
}
window.attachEvent("onunload", MyFunc);
top.MyFunc = MyFunc;


There is not error when I simply close the window. But When I click on save or on save,unclock and close I have this error :

"Update failed the part is not locked by you"

Maybe I can remove these two button and ask when the windows is closing if the user want to save or not.

Is there a flag to detect if the Item have been modified or not ? In order to make a test.

Thanks