source: trunk/web/addons/job_monarch/lib/extjs/air/samples/tasks/main.js @ 619

Last change on this file since 619 was 619, checked in by ramonb, 15 years ago

lib/:

  • added new AJAX dependancies: ExtJS, pChart, Lightbox2
File size: 10.3 KB
Line 
1/*
2 * Ext JS Library 0.30
3 * Copyright(c) 2006-2009, Ext JS, LLC.
4 * licensing@extjs.com
5 *
6 * http://extjs.com/license
7 */
8
9// Initialize the state provider
10Ext.state.Manager.setProvider(new Ext.air.FileProvider({
11        file: 'tasks.state',
12        // if first time running
13        defaultState : {
14                mainWindow : {
15                        width:780,
16                        height:580,
17                        x:10,
18                        y:10
19                },
20                defaultReminder: 480
21        }
22}));
23
24Ext.onReady(function(){
25    Ext.QuickTips.init();
26
27        // maintain window state automatically
28        var win = new Ext.air.NativeWindow({
29                id: 'mainWindow',
30                instance: window.nativeWindow,
31                minimizeToTray: true,
32                trayIcon: 'ext-air/resources/icons/extlogo16.png',
33                trayTip: 'Simple Tasks',
34                trayMenu : [{
35                        text: 'Open Simple Tasks',
36                        handler: function(){
37                                win.activate();
38                        }
39                }, '-', {
40                        text: 'Exit',
41                        handler: function(){
42                                air.NativeApplication.nativeApplication.exit();
43                        }
44                }]
45        });
46       
47    tx.data.conn.open('tasks.db');
48   
49    var grid = new TaskGrid();
50        var selections = grid.getSelectionModel();
51       
52       
53        // Shared actions used by Ext toolbars, menus, etc.
54        var actions = {
55                newTask: new Ext.Action({
56                        text: 'New Task',
57                        iconCls: 'icon-active',
58                        tooltip: 'New Task',
59                        handler: function(){
60                                taskHeader.ntTitle.focus();
61                        }
62                }),
63               
64                deleteTask: new Ext.Action({
65                        itemText: 'Delete',
66                        iconCls: 'icon-delete-task',
67                        tooltip: 'Delete Task',
68                        disabled: true,
69                        handler: function(){
70                                Ext.Msg.confirm('Confirm', 'Are you sure you want to delete the selected task(s)?', function(btn){
71                                        if (btn == 'yes') {
72                                                selections.each(function(s){
73                                                        tx.data.tasks.remove(s);
74                                                });
75                                        }
76                                });
77                        }
78                }),
79               
80                complete: new Ext.Action({
81                        itemText: 'Mark Complete',
82                        iconCls: 'icon-mark-complete',
83                        tooltip: 'Mark Complete',
84                        disabled: true,
85                        handler: function(){
86                                selections.each(function(s){
87                                        s.set('completed', true);
88                                });
89                                tx.data.tasks.applyFilter();
90                        }
91                }),
92               
93                active: new Ext.Action({
94                        itemText: 'Mark Active',
95                        tooltip: 'Mark Active',
96                        iconCls: 'icon-mark-active',
97                        disabled: true,
98                        handler: function(){
99                                selections.each(function(s){
100                                        s.set('completed', false);
101                                });
102                                tx.data.tasks.applyFilter();
103                        }
104                }),
105               
106                newList: new Ext.Action({
107                        itemText: 'New List',
108                        tooltip: 'New List',
109                        iconCls: 'icon-list-new',
110                        handler: function(){
111                                var id = tx.data.lists.newList(false, tree.getActiveFolderId()).id;
112                                tree.startEdit(id, true);
113                        }
114                }),
115               
116                deleteList: new Ext.Action({
117                        itemText: 'Delete',
118                        tooltip: 'Delete List',
119                        iconCls: 'icon-list-delete',
120                        disabled: true,
121                        handler: function(){
122                                tree.removeList(tree.getSelectionModel().getSelectedNode());
123                        }
124                }),
125               
126                newFolder: new Ext.Action({
127                        itemText: 'New Folder',
128                        tooltip: 'New Folder',
129                        iconCls: 'icon-folder-new',
130                        handler: function(){
131                                var id = tx.data.lists.newList(true, tree.getActiveFolderId()).id;
132                                tree.startEdit(id, true);
133                        }
134                }),
135               
136                deleteFolder: new Ext.Action({
137                        itemText: 'Delete',
138                        tooltip: 'Delete Folder',
139                        iconCls: 'icon-folder-delete',
140                        disabled: true,
141                        handler: function(s){
142                                tree.removeList(tree.getSelectionModel().getSelectedNode());
143                        }
144                }),
145               
146                quit : new Ext.Action({
147                        text: 'Exit',
148                        handler: function(){
149                                air.NativeApplication.nativeApplication.exit();
150                        }
151                }),
152               
153                pasteAsTask : new Ext.Action({
154                        itemText: 'Paste as New Task',
155                        tooltip: 'Paste as New Task',
156            iconCls: 'icon-paste-new',
157            handler: function(){
158                if(air.Clipboard.generalClipboard.hasFormat(air.ClipboardFormats.TEXT_FORMAT)){
159                                    var text = air.Clipboard.generalClipboard.getData(air.ClipboardFormats.TEXT_FORMAT);
160                                        tx.data.tasks.addTask({
161                            taskId: Ext.uniqueId(),
162                            title: Ext.util.Format.htmlEncode(text.replace(/[\n\r]/g, '')),
163                            dueDate: new Date(),
164                            description: '', 
165                            listId: tx.data.getActiveListId(),
166                            completed: false, 
167                                                reminder: ''
168                        });
169                                }else{
170                    Ext.Msg.alert('Warning', 'Could not create task. The clipboard is empty.');
171                }
172                        }
173                }) 
174        };
175    tx.actions = actions;
176
177    var menus = Ext.air.SystemMenu;
178       
179        menus.add('File', [
180                actions.newTask, 
181                actions.newList, 
182                actions.newFolder, 
183                '-',{
184                        text:'Import...',
185                        handler: function(){
186                                var importer = new tx.Importer();
187                                importer.doImport(function(){
188                                        tx.data.lists.load();
189                                        root.reload();
190                                        loadList('root');
191                                        Ext.Msg.hide();
192                                });
193                        }
194                },{
195                        text:'Export...',
196                        handler: function(){
197                                new tx.Exporter();
198                        }
199                },
200                '-', 
201                actions.quit
202        ]);
203
204        menus.add('Edit', [
205                actions.pasteAsTask
206        ]);
207
208       
209    var viewMenu = menus.add('View', [{
210        text: 'All Tasks',
211        checked: true,
212        handler: function(){
213            Ext.getCmp('filter').setActiveItem(0);
214        }
215    },{
216        text: 'Active Tasks',
217        checked: false,
218        handler: function(){
219            Ext.getCmp('filter').setActiveItem(1);
220        }
221    },{
222        text: 'Completed Tasks',
223        checked: false,
224        handler: function(){
225            Ext.getCmp('filter').setActiveItem(2);
226        }
227    }]);
228
229    menus.add('Help', [{
230        text: 'About',
231        handler: function(){
232            Ext.air.NativeWindowManager.getAboutWindow().activate();
233        }
234    }]);
235
236
237    var tree = new ListTree({
238                actions: actions,
239                store: tx.data.lists
240        });
241
242        var root = tree.getRootNode(); 
243
244        var listSm = tree.getSelectionModel();
245       
246    tx.data.lists.bindTree(tree);
247        tx.data.lists.on('update', function(){
248                tx.data.tasks.applyGrouping();
249                if(grid.titleNode){
250                        grid.setTitle(grid.titleNode.text);
251                }
252        });
253       
254        var tb = new Ext.Toolbar({
255                region:'north',
256                id:'main-tb',
257                height:26,
258                items: [{
259                                xtype:'splitbutton',
260                                iconCls:'icon-edit',
261                                text:'New',
262                                handler: actions.newTask.initialConfig.handler,
263                                menu: [actions.newTask, actions.newList, actions.newFolder]
264                        },'-',
265                        actions.deleteTask,
266                        actions.complete,
267                        actions.active,
268            '-',
269            actions.pasteAsTask,
270            '->',{
271                                xtype:'switch',
272                                id:'filter',
273                activeItem:0,
274                                items: [{
275                                tooltip:'All Tasks',
276                                        filter: 'all',
277                                iconCls:'icon-all',
278                                menuIndex: 0
279                },{
280                                tooltip:'Active Tasks',
281                                filter: false,
282                                iconCls:'icon-active',
283                    menuIndex: 1
284                            },{
285                                tooltip:'Completed Tasks',
286                                        filter: true,
287                                iconCls:'icon-complete',
288                    menuIndex: 2
289                            }],
290                                listeners: {
291                                        change: function(btn, item){
292                                                tx.data.tasks.applyFilter(item.filter);
293                                                for (var i = 0; i < 3; i++) {
294                                                        viewMenu.items[i].checked = item.menuIndex === i;
295                                                }
296                                        },
297                                        delay: 10 // delay gives user instant click feedback before filtering tasks
298                                }
299                        }, ' ', ' ', ' '               
300                ]
301        });
302
303        var viewport = new Ext.Viewport({
304        layout:'border',
305        items: [tb, tree, grid]
306    });
307       
308        grid.on('keydown', function(e){
309         if(e.getKey() == e.DELETE && !grid.editing){
310             actions.deleteTask.execute();
311         }
312    });
313
314    tree.el.on('keydown', function(e){
315         if(e.getKey() == e.DELETE && !tree.editor.editing){
316             actions.deleteList.execute();
317         }
318    });
319
320    selections.on('selectionchange', function(sm){
321        var disabled = sm.getCount() < 1;
322        actions.complete.setDisabled(disabled);
323        actions.active.setDisabled(disabled);
324        actions.deleteTask.setDisabled(disabled);
325    });
326
327        var taskHeader = new TaskHeader(grid);
328
329        win.show();
330        win.instance.activate();
331       
332        tx.data.tasks.init();
333
334        tree.root.select();
335
336        var loadList = function(listId){
337                var node = tree.getNodeById(listId);
338                if(node && !node.isSelected()){
339                        node.select();
340                        return;
341                }
342                actions.deleteList.setDisabled(!node || !node.attributes.editable);
343                actions.deleteFolder.setDisabled(!node || node.attributes.editable === false || !node.attributes.isFolder);
344                if(node){
345                        if (node.attributes.isFolder) {
346                                var lists = [];
347                                node.cascade(function(n){
348                                        if (!n.attributes.isFolder) {
349                                                lists.push(n.attributes.id);
350                                        }
351                                });
352                                tx.data.tasks.loadList(lists);
353                        }
354                        else {
355                                tx.data.tasks.loadList(node.id);
356                        }
357                        grid.titleNode = node;
358                        grid.setTitle(node.text);
359                        grid.setIconClass(node.attributes.iconCls);
360                }
361        }
362
363        listSm.on('selectionchange', function(t, node){
364                loadList(node ? node.id : null);
365        });
366       
367        root.reload();
368       
369        if(Ext.state.Manager.get('defaultReminder') === undefined){
370                Ext.state.Manager.set('defaultReminder', 9 * 60); // default to 9am
371        }
372       
373        win.on('closing', function(){
374                Ext.air.NativeWindowManager.closeAll();
375        });
376       
377        tx.ReminderManager.init();
378       
379        grid.body.on('dragover', function(e){
380                if(e.hasFormat(Ext.air.DragType.TEXT)){
381                        e.preventDefault();
382                }
383        });
384       
385        grid.body.on('drop', function(e){
386                if(e.hasFormat(Ext.air.DragType.TEXT)){
387                        var text = e.getData(Ext.air.DragType.TEXT);
388                        try{
389                                // from outlook
390                                if(text.indexOf("Subject\t") != -1){
391                                        var tasks = text.split("\n");
392                                        for(var i = 1, len = tasks.length; i < len; i++){
393                                                var data = tasks[i].split("\t");
394                                                var list = tx.data.lists.findList(data[2]);
395                                                tx.data.tasks.addTask({
396                                        taskId: Ext.uniqueId(),
397                                        title: Ext.util.Format.htmlEncode(data[0]),
398                                        dueDate: Date.parseDate(data[1], 'D n/j/Y') || '',
399                                        description: '', 
400                                        listId: list ? list.id : tx.data.getActiveListId(),
401                                        completed: false, 
402                                                        reminder: ''
403                                    });
404                                        }
405                                }else{
406                                        tx.data.tasks.addTask({
407                                taskId: Ext.uniqueId(),
408                                title: Ext.util.Format.htmlEncode(text),
409                                dueDate: new Date(),
410                                description: '', 
411                                listId: tx.data.getActiveListId(),
412                                completed: false, 
413                                                reminder: ''
414                            });
415                                }
416                        }catch(e){
417                                air.trace('An error occured trying to import drag drop tasks.');
418                        }
419                }
420        });
421});
422
423   
424
Note: See TracBrowser for help on using the repository browser.