Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / examples / message-box / msg-box.js
1 /*!
2  * Ext JS Library 3.0.0
3  * Copyright(c) 2006-2009 Ext JS, LLC
4  * licensing@extjs.com
5  * http://www.extjs.com/license
6  */
7 Ext.onReady(function(){\r
8     Ext.get('mb1').on('click', function(e){\r
9         Ext.MessageBox.confirm('Confirm', 'Are you sure you want to do that?', showResult);\r
10     });\r
11 \r
12     Ext.get('mb2').on('click', function(e){\r
13         Ext.MessageBox.prompt('Name', 'Please enter your name:', showResultText);\r
14     });\r
15 \r
16     Ext.get('mb3').on('click', function(e){\r
17         Ext.MessageBox.show({\r
18            title: 'Address',\r
19            msg: 'Please enter your address:',\r
20            width:300,\r
21            buttons: Ext.MessageBox.OKCANCEL,\r
22            multiline: true,\r
23            fn: showResultText,\r
24            animEl: 'mb3'\r
25        });\r
26     });\r
27 \r
28     Ext.get('mb4').on('click', function(e){\r
29         Ext.MessageBox.show({\r
30            title:'Save Changes?',\r
31            msg: 'You are closing a tab that has unsaved changes. <br />Would you like to save your changes?',\r
32            buttons: Ext.MessageBox.YESNOCANCEL,\r
33            fn: showResult,\r
34            animEl: 'mb4',\r
35            icon: Ext.MessageBox.QUESTION\r
36        });\r
37     });\r
38 \r
39     Ext.get('mb6').on('click', function(){\r
40         Ext.MessageBox.show({\r
41            title: 'Please wait',\r
42            msg: 'Loading items...',\r
43            progressText: 'Initializing...',\r
44            width:300,\r
45            progress:true,\r
46            closable:false,\r
47            animEl: 'mb6'\r
48        });\r
49 \r
50        // this hideous block creates the bogus progress\r
51        var f = function(v){\r
52             return function(){\r
53                 if(v == 12){\r
54                     Ext.MessageBox.hide();\r
55                     Ext.example.msg('Done', 'Your fake items were loaded!');\r
56                 }else{\r
57                     var i = v/11;\r
58                     Ext.MessageBox.updateProgress(i, Math.round(100*i)+'% completed');\r
59                 }\r
60            };\r
61        };\r
62        for(var i = 1; i < 13; i++){\r
63            setTimeout(f(i), i*500);\r
64        }\r
65     });\r
66 \r
67     Ext.get('mb7').on('click', function(){\r
68         Ext.MessageBox.show({\r
69            msg: 'Saving your data, please wait...',\r
70            progressText: 'Saving...',\r
71            width:300,\r
72            wait:true,\r
73            waitConfig: {interval:200},\r
74            icon:'ext-mb-download', //custom class in msg-box.html\r
75            animEl: 'mb7'\r
76        });\r
77         setTimeout(function(){\r
78             //This simulates a long-running operation like a database save or XHR call.\r
79             //In real code, this would be in a callback function.\r
80             Ext.MessageBox.hide();\r
81             Ext.example.msg('Done', 'Your fake data was saved!');\r
82         }, 8000);\r
83     });\r
84 \r
85     Ext.get('mb8').on('click', function(){\r
86         Ext.MessageBox.alert('Status', 'Changes saved successfully.', showResult);\r
87     });\r
88 \r
89     //Add these values dynamically so they aren't hard-coded in the html\r
90     Ext.fly('info').dom.value = Ext.MessageBox.INFO;\r
91     Ext.fly('question').dom.value = Ext.MessageBox.QUESTION;\r
92     Ext.fly('warning').dom.value = Ext.MessageBox.WARNING;\r
93     Ext.fly('error').dom.value = Ext.MessageBox.ERROR;\r
94 \r
95     Ext.get('mb9').on('click', function(){\r
96         Ext.MessageBox.show({\r
97            title: 'Icon Support',\r
98            msg: 'Here is a message with an icon!',\r
99            buttons: Ext.MessageBox.OK,\r
100            animEl: 'mb9',\r
101            fn: showResult,\r
102            icon: Ext.get('icons').dom.value\r
103        });\r
104     });\r
105 \r
106     function showResult(btn){\r
107         Ext.example.msg('Button Click', 'You clicked the {0} button', btn);\r
108     };\r
109 \r
110     function showResultText(btn, text){\r
111         Ext.example.msg('Button Click', 'You clicked the {0} button and entered the text "{1}".', btn, text);\r
112     };\r
113 });