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