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