Confirming with popup window

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Confirming with popup window

Nikolaj de Fine Licht
Hello list,

I have been looking at the JavaScript-solution used in the Lasso
Administration where Delete-actions (and other critical actions) have
to be confirmed in a popup-window, which then again, upon confirmation,
disappears while sending data back and initiating the action in the
main window.

I found a similar question searching the list but not quite what
LassoAdmin uses...

I'm not good at JavaScript, I have been staring at it for some time
now; I understand some of it but not the essential part:

I don't get how the popup-window, upon confirmation, communicates to
the main window that it has been triggered, telling that the
(delete-)action can take place, and how the main page receives this and
envokes the action.

In other words, how do the following functions "do the job" and what's
in the main page that receives this:

                        function form_submit(param) {
                                var f = opener.document.forms[1];
                                f.dialog_action.value=param;
                                f.submit();
                                self.close();
                        }
                        function datasource_submit(param,param2) {
                                var f = opener.document.forms[1];
                                f.dialog_action.value=param;
                                f.table_action.value=param2;
                                f.submit();
                                self.close();
                        }
                        function logout_submit() {
                                window.opener.location='Delete Record';
                                window.close();
                        }

I would love to use this kind of confirmation before critical actions...

Thanks in advance for any hint :)

/nikolaj


--
------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: Confirming with popup window

Fletcher Sandbeck
On 6/6/05 at 2:33 AM by [hidden email] (Nikolaj de Fine Licht):

>Hello list,
>
>I have been looking at the JavaScript-solution used in the Lasso
>Administration where Delete-actions (and other critical actions) have
>to be confirmed in a popup-window, which then again, upon confirmation,
>disappears while sending data back and initiating the action in the
>main window.
>
>I found a similar question searching the list but not quite what
>LassoAdmin uses...
>
>I'm not good at JavaScript, I have been staring at it for some time
>now; I understand some of it but not the essential part:
>
>I don't get how the popup-window, upon confirmation, communicates to
>the main window that it has been triggered, telling that the
>(delete-)action can take place, and how the main page receives this and
>envokes the action.
>
>In other words, how do the following functions "do the job" and what's
>in the main page that receives this:
>
> function form_submit(param) {
> var f = opener.document.forms[1];
> f.dialog_action.value=param;
> f.submit();
> self.close();
> }
> function datasource_submit(param,param2) {
> var f = opener.document.forms[1];
> f.dialog_action.value=param;
> f.table_action.value=param2;
> f.submit();
> self.close();
> }
> function logout_submit() {
> window.opener.location='Delete Record';
> window.close();
> }
>
>I would love to use this kind of confirmation before critical actions...
>
>Thanks in advance for any hint :)

A much easier way to do a simple confirmation is as follows.  "confirm" shows a dialog box with the message you set and OK and Cancel buttons to the user.  If the user hits OK the form is submitted.  If they hit Cancel then it's as if the button was never clicked.

<input type="submit" value="Delete" name="datasource_action"
    onClick="return confirm('Are you sure?');" class="small" />

But, I'll also describe how the admin dialog boxes work.  They are useful if you want to have more options than OK and Cancel or if you want to display more information than the built-in confirm dialog box allows.  They're also a bit prettier.

The function "form_submit" does four things.  First, it locates the form from the page that opened up the popup window.  "opener" refers to the window that opened the popup window so "opener.document.forms[1]" refers to the second form defined in this window (JavaScript indexes start at 0 for the first form so 1 refers to the second form).  The second form corresponds to the right panel in the main admin window.

Then, "f.dialog_action.value=param" sets the value of the hidden input "dialog_action" from the second form to the value sent in to the function.  And, "f.submit()" submits the second form causing the main window to reload.  Finally, self.close() closes the dialog box window.  The net result is that the original window has the form on the right hand side submitted with the appropriate value set in a hidden input.

The logic which runs after the form has been submitted looks for the value of [Action_Param: 'dialog_action'].  If dialog_action is e.g. "Delete" then the current host, database, table, etc. is deleted.

Another key aspect is the function that opens the dialog window.  If you look the function that does this always returns "false".  When this function is called in the onclick handler of the delete button the fact that it returns false presents that button from actually submitting the form.

function showalert(action) {
  window.open('dialog.lasso?dialog_pane=setup/datasources/host/dialog.lasso&action='+escape(action),
    'help','status=yes,menubar=no,scrollbars=yes,resizable=yes,width=460,height=336');
  return false;
}

<input type="submit" value="Delete" name="datasource_action"
    onClick="return showalert(this.value);" class="small" />

Hope this helps,

[fletcher]
--
Fletcher Sandbeck                         [hidden email]
Lasso Product Specialist              [hidden email]
OmniPilot Software, Inc.                http://www.omnipilot.com

--
------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: Confirming with popup window

Steffan A. Cline
In reply to this post by Nikolaj de Fine Licht
Here is an easy one

<input type="submit" name="submit" value="Delete" onclick="return
confirm('Are you sure you want to delete this?');">

It will ask if they are sure. If they click Cancel or No then the form will
not submit. If they click OK then it will submit with the value of that
submit button.





Thanks

Steffan

---------------------------------------------------------------
T E L  6 0 2 . 5 7 9 . 4 2 3 0 | F A X  6 0 2 . 9 7 1 . 1 6 9 4
Steffan A. Cline
[hidden email]                             Phoenix, Az
http://www.ExecuChoice.net                                  USA
AIM : SteffanC          ICQ : 57234309
The Executive's Choice in Lasso driven Internet Applications
                                  Lasso Partner Alliance Member
---------------------------------------------------------------


> From: Nikolaj de Fine Licht <[hidden email]>
> Reply-To: <[hidden email]>
> Date: Mon, 6 Jun 2005 02:33:06 +0200
> To: <[hidden email]>
> Subject: Confirming with popup window
>
> Hello list,
>
> I have been looking at the JavaScript-solution used in the Lasso
> Administration where Delete-actions (and other critical actions) have
> to be confirmed in a popup-window, which then again, upon confirmation,
> disappears while sending data back and initiating the action in the
> main window.
>
> I found a similar question searching the list but not quite what
> LassoAdmin uses...
>
> I'm not good at JavaScript, I have been staring at it for some time
> now; I understand some of it but not the essential part:
>
> I don't get how the popup-window, upon confirmation, communicates to
> the main window that it has been triggered, telling that the
> (delete-)action can take place, and how the main page receives this and
> envokes the action.
>
> In other words, how do the following functions "do the job" and what's
> in the main page that receives this:
>
> function form_submit(param) {
> var f = opener.document.forms[1];
> f.dialog_action.value=param;
> f.submit();
> self.close();
> }
> function datasource_submit(param,param2) {
> var f = opener.document.forms[1];
> f.dialog_action.value=param;
> f.table_action.value=param2;
> f.submit();
> self.close();
> }
> function logout_submit() {
> window.opener.location='Delete Record';
> window.close();
> }
>
> I would love to use this kind of confirmation before critical actions...
>
> Thanks in advance for any hint :)
>
> /nikolaj
>
>
> --
> ------------------------------
> Lasso Support: http://support.omnipilot.com/
> Search the list archives: http://www.listsearch.com/lassotalk.lasso
> Manage your list subscription:
> http://www.listsearch.com/lassotalk.lasso?manage


--
------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: Confirming with popup window

Nikolaj de Fine Licht
In reply to this post by Nikolaj de Fine Licht
Thanks Fletcher, and thanks to Steffan too. I didn't know of the easy  
one, and I'm glad to know how to make the advanced one :)

/nikolaj

On 6. jun 2005, at 3:38, Fletcher Sandbeck wrote:

> On 6/6/05 at 2:33 AM by [hidden email] (Nikolaj de Fine Licht):
>
>> Hello list,
>>
>> I have been looking at the JavaScript-solution used in the Lasso
>> Administration where Delete-actions (and other critical actions) have
>> to be confirmed in a popup-window, which then again, upon  
>> confirmation,
>> disappears while sending data back and initiating the action in the
>> main window.
>>
>> I found a similar question searching the list but not quite what
>> LassoAdmin uses...
>>
>> I'm not good at JavaScript, I have been staring at it for some time
>> now; I understand some of it but not the essential part:
>>
>> I don't get how the popup-window, upon confirmation, communicates to
>> the main window that it has been triggered, telling that the
>> (delete-)action can take place, and how the main page receives this  
>> and
>> envokes the action.
>>
>> In other words, how do the following functions "do the job" and what's
>> in the main page that receives this:
>>
>> function form_submit(param) {
>> var f = opener.document.forms[1];
>> f.dialog_action.value=param;
>> f.submit();
>> self.close();
>> }
>> function datasource_submit(param,param2) {
>> var f = opener.document.forms[1];
>> f.dialog_action.value=param;
>> f.table_action.value=param2;
>> f.submit();
>> self.close();
>> }
>> function logout_submit() {
>> window.opener.location='Delete Record';
>> window.close();
>> }
>>
>> I would love to use this kind of confirmation before critical  
>> actions...
>>
>> Thanks in advance for any hint :)
>
> A much easier way to do a simple confirmation is as follows.  
> "confirm" shows a dialog box with the message you set and OK and  
> Cancel buttons to the user.  If the user hits OK the form is  
> submitted.  If they hit Cancel then it's as if the button was never  
> clicked.
>
> <input type="submit" value="Delete" name="datasource_action"
>     onClick="return confirm('Are you sure?');" class="small" />
>
> But, I'll also describe how the admin dialog boxes work.  They are  
> useful if you want to have more options than OK and Cancel or if you  
> want to display more information than the built-in confirm dialog box  
> allows.  They're also a bit prettier.
>
> The function "form_submit" does four things.  First, it locates the  
> form from the page that opened up the popup window.  "opener" refers  
> to the window that opened the popup window so  
> "opener.document.forms[1]" refers to the second form defined in this  
> window (JavaScript indexes start at 0 for the first form so 1 refers  
> to the second form).  The second form corresponds to the right panel  
> in the main admin window.
>
> Then, "f.dialog_action.value=param" sets the value of the hidden input  
> "dialog_action" from the second form to the value sent in to the  
> function.  And, "f.submit()" submits the second form causing the main  
> window to reload.  Finally, self.close() closes the dialog box window.  
>  The net result is that the original window has the form on the right  
> hand side submitted with the appropriate value set in a hidden input.
>
> The logic which runs after the form has been submitted looks for the  
> value of [Action_Param: 'dialog_action'].  If dialog_action is e.g.  
> "Delete" then the current host, database, table, etc. is deleted.
>
> Another key aspect is the function that opens the dialog window.  If  
> you look the function that does this always returns "false".  When  
> this function is called in the onclick handler of the delete button  
> the fact that it returns false presents that button from actually  
> submitting the form.
>
> function showalert(action) {
>    
> window.open('dialog.lasso?dialog_pane=setup/datasources/host/
> dialog.lasso&action='+escape(action),
>      
> 'help','status=yes,menubar=no,scrollbars=yes,resizable=yes,width=460,he
> ight=336');
>   return false;
> }
>
> <input type="submit" value="Delete" name="datasource_action"
>     onClick="return showalert(this.value);" class="small" />
>
> Hope this helps,
>
> [fletcher]


--
------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage