]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | Ext.require([\r |
2 | 'Ext.panel.Panel',\r | |
3 | 'Ext.button.Button',\r | |
4 | 'Ext.window.Window',\r | |
5 | 'Ext.ux.statusbar.StatusBar',\r | |
6 | 'Ext.toolbar.TextItem',\r | |
7 | 'Ext.menu.Menu',\r | |
8 | 'Ext.toolbar.Spacer',\r | |
9 | 'Ext.button.Split',\r | |
10 | 'Ext.form.field.TextArea'\r | |
11 | ]);\r | |
12 | \r | |
13 | Ext.onReady(function(){\r | |
14 | \r | |
15 | // This is a shared function that simulates a load action on a StatusBar.\r | |
16 | // It is reused by most of the example panels.\r | |
17 | var loadFn = function(btn, statusBar){\r | |
18 | btn = Ext.getCmp(btn);\r | |
19 | statusBar = Ext.getCmp(statusBar);\r | |
20 | \r | |
21 | btn.disable();\r | |
22 | statusBar.showBusy();\r | |
23 | \r | |
24 | Ext.defer(function(){\r | |
25 | statusBar.clearStatus({useDefaults:true});\r | |
26 | btn.enable();\r | |
27 | }, 2000);\r | |
28 | };\r | |
29 | \r | |
30 | /*\r | |
31 | * ================ Basic StatusBar example =======================\r | |
32 | */\r | |
33 | Ext.create('Ext.Panel', {\r | |
34 | title: 'Basic StatusBar',\r | |
35 | renderTo: 'basic',\r | |
36 | width: 550,\r | |
37 | manageHeight: false,\r | |
38 | bodyPadding: 10,\r | |
39 | items:[{\r | |
40 | xtype: 'button',\r | |
41 | id: 'basic-button',\r | |
42 | text: 'Do Loading',\r | |
43 | handler: Ext.Function.pass(loadFn, ['basic-button', 'basic-statusbar'])\r | |
44 | }],\r | |
45 | bbar: Ext.create('Ext.ux.StatusBar', {\r | |
46 | id: 'basic-statusbar',\r | |
47 | \r | |
48 | // defaults to use when the status is cleared:\r | |
49 | defaultText: 'Default status text',\r | |
50 | //defaultIconCls: 'default-icon',\r | |
51 | \r | |
52 | // values to set initially:\r | |
53 | text: 'Ready',\r | |
54 | iconCls: 'x-status-valid',\r | |
55 | \r | |
56 | // any standard Toolbar items:\r | |
57 | items: [\r | |
58 | {\r | |
59 | xtype: 'button',\r | |
60 | text: 'Show Warning & Clear',\r | |
61 | handler: function (){\r | |
62 | var sb = Ext.getCmp('basic-statusbar');\r | |
63 | sb.setStatus({\r | |
64 | text: 'Oops!',\r | |
65 | iconCls: 'x-status-error',\r | |
66 | clear: true // auto-clear after a set interval\r | |
67 | });\r | |
68 | }\r | |
69 | },\r | |
70 | {\r | |
71 | xtype: 'button',\r | |
72 | text: 'Show Busy',\r | |
73 | handler: function (){\r | |
74 | var sb = Ext.getCmp('basic-statusbar');\r | |
75 | // Set the status bar to show that something is processing:\r | |
76 | sb.showBusy();\r | |
77 | }\r | |
78 | },\r | |
79 | {\r | |
80 | xtype: 'button',\r | |
81 | text: 'Clear status',\r | |
82 | handler: function (){\r | |
83 | var sb = Ext.getCmp('basic-statusbar');\r | |
84 | // once completed\r | |
85 | sb.clearStatus(); \r | |
86 | }\r | |
87 | },\r | |
88 | '-',\r | |
89 | 'Plain Text'\r | |
90 | ]\r | |
91 | })\r | |
92 | });\r | |
93 | \r | |
94 | /*\r | |
95 | * ================ Right-aligned StatusBar example =======================\r | |
96 | */\r | |
97 | Ext.create('Ext.Panel', {\r | |
98 | title: 'Right-aligned StatusBar',\r | |
99 | renderTo: 'right-aligned',\r | |
100 | width: 550,\r | |
101 | manageHeight: false,\r | |
102 | bodyPadding: 10,\r | |
103 | items:[{\r | |
104 | xtype: 'button',\r | |
105 | id: 'right-button',\r | |
106 | text: 'Do Loading',\r | |
107 | handler: Ext.Function.pass(loadFn, ['right-button', 'right-statusbar'])\r | |
108 | }],\r | |
109 | bbar: Ext.create('Ext.ux.StatusBar', {\r | |
110 | defaultText: 'Default status',\r | |
111 | id: 'right-statusbar',\r | |
112 | statusAlign: 'right', // the magic config\r | |
113 | items: [{\r | |
114 | text: 'A Button'\r | |
115 | }, '-', 'Plain Text', ' ', ' ']\r | |
116 | })\r | |
117 | });\r | |
118 | \r | |
119 | /*\r | |
120 | * ================ StatusBar Window example =======================\r | |
121 | */\r | |
122 | var win = Ext.create('Ext.Window', {\r | |
123 | title: 'StatusBar Window',\r | |
124 | width: 410,\r | |
125 | minWidth: 350,\r | |
126 | height: 150,\r | |
127 | modal: true,\r | |
128 | closeAction: 'hide',\r | |
129 | bodyPadding: 10,\r | |
130 | items:[{\r | |
131 | xtype: 'button',\r | |
132 | id: 'win-button',\r | |
133 | text: 'Do Loading',\r | |
134 | handler: Ext.Function.pass(loadFn, ['win-button', 'win-statusbar'])\r | |
135 | }],\r | |
136 | bbar: Ext.create('Ext.ux.StatusBar', {\r | |
137 | id: 'win-statusbar',\r | |
138 | defaultText: 'Ready',\r | |
139 | items: [{\r | |
140 | xtype: 'button',\r | |
141 | text: 'A Button'\r | |
142 | }, '-',\r | |
143 | Ext.Date.format(new Date(), 'n/d/Y'), ' ', ' ', '-', {\r | |
144 | xtype:'splitbutton',\r | |
145 | text:'Status Menu',\r | |
146 | menuAlign: 'br-tr?',\r | |
147 | menu: Ext.create('Ext.menu.Menu', {\r | |
148 | items: [{text: 'Item 1'}, {text: 'Item 2'}]\r | |
149 | })\r | |
150 | }]\r | |
151 | })\r | |
152 | });\r | |
153 | \r | |
154 | Ext.create('Ext.Button', {\r | |
155 | text: 'Show Window',\r | |
156 | renderTo: 'window',\r | |
157 | handler: function(){\r | |
158 | win.show();\r | |
159 | }\r | |
160 | });\r | |
161 | \r | |
162 | /*\r | |
163 | * ================ Ext Word Processor example =======================\r | |
164 | *\r | |
165 | * The StatusBar used in this example is completely standard. What is\r | |
166 | * customized are the styles and event handling to make the example a\r | |
167 | * lot more dynamic and application-oriented.\r | |
168 | *\r | |
169 | */\r | |
170 | // Create these explicitly so we can manipulate them later\r | |
171 | var wordCount = Ext.create('Ext.toolbar.TextItem', {text: 'Words: 0'}),\r | |
172 | charCount = Ext.create('Ext.toolbar.TextItem', {text: 'Chars: 0'}), \r | |
173 | clock = Ext.create('Ext.toolbar.TextItem', {text: Ext.Date.format(new Date(), 'g:i:s A')}),\r | |
174 | event = Ext.isOpera ? 'keypress' : 'keydown'; // opera behaves a little weird with keydown\r | |
175 | \r | |
176 | Ext.create('Ext.Panel', {\r | |
177 | title: 'Ext Word Processor',\r | |
178 | renderTo: 'word-proc',\r | |
179 | width: 500,\r | |
180 | bodyPadding: 5,\r | |
181 | layout: 'fit',\r | |
182 | bbar: Ext.create('Ext.ux.StatusBar', {\r | |
183 | id: 'word-status',\r | |
184 | // These are just the standard toolbar TextItems we created above. They get\r | |
185 | // custom classes below in the render handler which is what gives them their\r | |
186 | // customized inset appearance.\r | |
187 | items: [wordCount, ' ', charCount, ' ', clock, ' ']\r | |
188 | }),\r | |
189 | items: {\r | |
190 | xtype: 'textarea',\r | |
191 | id: 'word-textarea',\r | |
192 | enableKeyEvents: true,\r | |
193 | hideLabel: true,\r | |
194 | grow: true,\r | |
195 | growMin: 100,\r | |
196 | growMax: 200\r | |
197 | },\r | |
198 | listeners: {\r | |
199 | render: {\r | |
200 | fn: function(){\r | |
201 | // Add a class to the parent TD of each text item so we can give them some custom inset box\r | |
202 | // styling. Also, since we are using a greedy spacer, we have to add a block level element\r | |
203 | // into each text TD in order to give them a fixed width (TextItems are spans). Insert a\r | |
204 | // spacer div into each TD using createChild() so that we can give it a width in CSS.\r | |
205 | Ext.fly(wordCount.getEl().parent()).addCls('x-status-text-panel').createChild({cls:'spacer'});\r | |
206 | Ext.fly(charCount.getEl().parent()).addCls('x-status-text-panel').createChild({cls:'spacer'});\r | |
207 | Ext.fly(clock.getEl().parent()).addCls('x-status-text-panel').createChild({cls:'spacer'});\r | |
208 | \r | |
209 | // Kick off the clock timer that updates the clock el every second:\r | |
210 | Ext.TaskManager.start({\r | |
211 | run: function(){\r | |
212 | Ext.fly(clock.getEl()).update(Ext.Date.format(new Date(), 'g:i:s A'));\r | |
213 | },\r | |
214 | interval: 1000\r | |
215 | });\r | |
216 | },\r | |
217 | delay: 100\r | |
218 | }\r | |
219 | }\r | |
220 | });\r | |
221 | \r | |
222 | // This sets up a fake auto-save function. It monitors keyboard activity and after no typing\r | |
223 | // has occurred for 1.5 seconds, it updates the status message to indicate that it's saving.\r | |
224 | // After a fake delay so that you can see the save activity it will update again to indicate\r | |
225 | // that the action succeeded.\r | |
226 | Ext.getCmp('word-textarea').on(event, function(){\r | |
227 | var sb = Ext.getCmp('word-status');\r | |
228 | sb.showBusy('Saving draft...');\r | |
229 | Ext.defer(function(){\r | |
230 | sb.setStatus({\r | |
231 | iconCls: 'x-status-saved',\r | |
232 | text: 'Draft auto-saved at ' + Ext.Date.format(new Date(), 'g:i:s A')\r | |
233 | });\r | |
234 | }, 4000);\r | |
235 | }, null, {buffer:1500});\r | |
236 | \r | |
237 | // Set up our event for updating the word/char count\r | |
238 | Ext.getCmp('word-textarea').on(event, function(comp){\r | |
239 | var v = comp.getValue(),\r | |
240 | wc = 0, \r | |
241 | cc = v.length ? v.length : 0;\r | |
242 | \r | |
243 | if (cc > 0) {\r | |
244 | wc = v.match(/\b/g);\r | |
245 | wc = wc ? wc.length / 2 : 0;\r | |
246 | }\r | |
247 | wordCount.update('Words: ' + wc);\r | |
248 | charCount.update('Chars: ' + cc);\r | |
249 | }, null, {buffer: 1});\r | |
250 | \r | |
251 | });\r |