DropDownChoice with Confirm Dialog

2013-07-24 Thread Marco Di Sabatino Di Diodoro
Hi all,

I like implement a DropDownChoice with an Confirm Dialog.
I used an AjaxFormComponentUpdatingBehavior(on change) to intercept the 
change in the DropDownChoice. 
In addition,  the user must first confirm the operation with a dialog before 
changing the value in the DropDownChoice. 

To do that I add an AjaxCallListeners:

@Override
protected void updateAjaxAttributes(final AjaxRequestAttributes 
attributes) {
super.updateAjaxAttributes(attributes);
final AjaxCallListener ajaxCallListener = new 
AjaxCallListener() {
private static final long serialVersionUID = 
7160235486520935153L;

@Override
public CharSequence getPrecondition(final Component 
component) {
return if (confirm(' + getString(confirmDelete) + 
')) return false;;
}  
};
attributes.getAjaxCallListeners().add(ajaxCallListener);
}});

When I click cancel on the Confirm Dialog, the DropDownChoice changes and I can 
not restore the old value. 
How I understand that the user clicked on Cancel? Is the correct way to 
implement this functionality?

Best Regards
M

-- 
Dott. Marco Di Sabatino Di Diodoro
Tel. +39 3939065570

Tirasa S.r.l.
Viale D'Annunzio 267 - 65127 Pescara
Tel +39 0859116307 / FAX +39 085973
http://www.tirasa.net

Apache Syncope PMC Member
http://people.apache.org/~mdisabatino/



Re: DropDownChoice with Confirm Dialog

2013-07-24 Thread Martin Grigorov
Hi,


On Wed, Jul 24, 2013 at 11:54 AM, Marco Di Sabatino Di Diodoro 
marco.disabat...@tirasa.net wrote:

 Hi all,

 I like implement a DropDownChoice with an Confirm Dialog.
 I used an AjaxFormComponentUpdatingBehavior(on change) to intercept the
 change in the DropDownChoice.
 In addition,  the user must first confirm the operation with a dialog
 before changing the value in the DropDownChoice.

 To do that I add an AjaxCallListeners:

 @Override
 protected void updateAjaxAttributes(final
 AjaxRequestAttributes attributes) {
 super.updateAjaxAttributes(attributes);
 final AjaxCallListener ajaxCallListener = new
 AjaxCallListener() {
 private static final long serialVersionUID =
 7160235486520935153L;

 @Override
 public CharSequence getPrecondition(final Component
 component) {
 return if (confirm(' +
 getString(confirmDelete) + ')) return false;;


Try with: return if (confirm(' + getString(confirmDelete) +
')) { attrs.event.preventDefault(); return false;};

The precondition just stops the Ajax call, but it has no logic to do
anything else.


 }
 };
 attributes.getAjaxCallListeners().add(ajaxCallListener);
 }});

 When I click cancel on the Confirm Dialog, the DropDownChoice changes and
 I can not restore the old value.
 How I understand that the user clicked on Cancel? Is the correct way to
 implement this functionality?

 Best Regards
 M

 --
 Dott. Marco Di Sabatino Di Diodoro
 Tel. +39 3939065570

 Tirasa S.r.l.
 Viale D'Annunzio 267 - 65127 Pescara
 Tel +39 0859116307 / FAX +39 085973
 http://www.tirasa.net

 Apache Syncope PMC Member
 http://people.apache.org/~mdisabatino/




Re: DropDownChoice with Confirm Dialog

2013-07-24 Thread Marco Di Sabatino Di Diodoro
Hi Martin,

attrs.event.preventDefault() not work. My DropDownChoice changes always.

M 

Il giorno 24/lug/2013, alle ore 10:59, Martin Grigorov mgrigo...@apache.org 
ha scritto:

 Hi,
 
 
 On Wed, Jul 24, 2013 at 11:54 AM, Marco Di Sabatino Di Diodoro 
 marco.disabat...@tirasa.net wrote:
 
 Hi all,
 
 I like implement a DropDownChoice with an Confirm Dialog.
 I used an AjaxFormComponentUpdatingBehavior(on change) to intercept the
 change in the DropDownChoice.
 In addition,  the user must first confirm the operation with a dialog
 before changing the value in the DropDownChoice.
 
 To do that I add an AjaxCallListeners:
 
@Override
protected void updateAjaxAttributes(final
 AjaxRequestAttributes attributes) {
super.updateAjaxAttributes(attributes);
final AjaxCallListener ajaxCallListener = new
 AjaxCallListener() {
private static final long serialVersionUID =
 7160235486520935153L;
 
@Override
public CharSequence getPrecondition(final Component
 component) {
return if (confirm(' +
 getString(confirmDelete) + ')) return false;;
 
 
 Try with: return if (confirm(' + getString(confirmDelete) +
 ')) { attrs.event.preventDefault(); return false;};
 
 The precondition just stops the Ajax call, but it has no logic to do
 anything else.
 
 
}
};
attributes.getAjaxCallListeners().add(ajaxCallListener);
}});
 
 When I click cancel on the Confirm Dialog, the DropDownChoice changes and
 I can not restore the old value.
 How I understand that the user clicked on Cancel? Is the correct way to
 implement this functionality?
 
 Best Regards
 M
 
 --
 Dott. Marco Di Sabatino Di Diodoro
 Tel. +39 3939065570
 
 Tirasa S.r.l.
 Viale D'Annunzio 267 - 65127 Pescara
 Tel +39 0859116307 / FAX +39 085973
 http://www.tirasa.net
 
 Apache Syncope PMC Member
 http://people.apache.org/~mdisabatino/
 
 

-- 
Dott. Marco Di Sabatino Di Diodoro
Tel. +39 3939065570

Tirasa S.r.l.
Viale D'Annunzio 267 - 65127 Pescara
Tel +39 0859116307 / FAX +39 085973
http://www.tirasa.net

Apache Syncope PMC Member
http://people.apache.org/~mdisabatino/



Re: DropDownChoice with Confirm Dialog

2013-07-24 Thread Martin Grigorov
This is purely JS problem.
I don't find anything in the web that can do this automatically for you.
Here is a possible solution:
store the previous selected value in a custom attribute, e.g.
data-prev-index=...
then in the precondition code replace attrs.event.preventDefault() with :
var $select = $('#'+attrs.c); $select[0].selectedIndex =
$select.data(prev-index);


On Wed, Jul 24, 2013 at 2:10 PM, Marco Di Sabatino Di Diodoro 
marco.disabat...@tirasa.net wrote:

 Hi Martin,

 attrs.event.preventDefault() not work. My DropDownChoice changes always.

 M

 Il giorno 24/lug/2013, alle ore 10:59, Martin Grigorov 
 mgrigo...@apache.org ha scritto:

  Hi,
 
 
  On Wed, Jul 24, 2013 at 11:54 AM, Marco Di Sabatino Di Diodoro 
  marco.disabat...@tirasa.net wrote:
 
  Hi all,
 
  I like implement a DropDownChoice with an Confirm Dialog.
  I used an AjaxFormComponentUpdatingBehavior(on change) to intercept
 the
  change in the DropDownChoice.
  In addition,  the user must first confirm the operation with a dialog
  before changing the value in the DropDownChoice.
 
  To do that I add an AjaxCallListeners:
 
 @Override
 protected void updateAjaxAttributes(final
  AjaxRequestAttributes attributes) {
 super.updateAjaxAttributes(attributes);
 final AjaxCallListener ajaxCallListener = new
  AjaxCallListener() {
 private static final long serialVersionUID =
  7160235486520935153L;
 
 @Override
 public CharSequence getPrecondition(final Component
  component) {
 return if (confirm(' +
  getString(confirmDelete) + ')) return false;;
 
 
  Try with: return if (confirm(' +
 getString(confirmDelete) +
  ')) { attrs.event.preventDefault(); return false;};
 
  The precondition just stops the Ajax call, but it has no logic to do
  anything else.
 
 
 }
 };
 attributes.getAjaxCallListeners().add(ajaxCallListener);
 }});
 
  When I click cancel on the Confirm Dialog, the DropDownChoice changes
 and
  I can not restore the old value.
  How I understand that the user clicked on Cancel? Is the correct way to
  implement this functionality?
 
  Best Regards
  M
 
  --
  Dott. Marco Di Sabatino Di Diodoro
  Tel. +39 3939065570
 
  Tirasa S.r.l.
  Viale D'Annunzio 267 - 65127 Pescara
  Tel +39 0859116307 / FAX +39 085973
  http://www.tirasa.net
 
  Apache Syncope PMC Member
  http://people.apache.org/~mdisabatino/
 
 

 --
 Dott. Marco Di Sabatino Di Diodoro
 Tel. +39 3939065570

 Tirasa S.r.l.
 Viale D'Annunzio 267 - 65127 Pescara
 Tel +39 0859116307 / FAX +39 085973
 http://www.tirasa.net

 Apache Syncope PMC Member
 http://people.apache.org/~mdisabatino/