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