~cdparra/gelee/trunk

« back to all changes in this revision

Viewing changes to webui/ecosystem/workspace/extjs/docs/source/main.html

  • Committer: parra
  • Date: 2010-03-15 15:56:56 UTC
  • Revision ID: svn-v4:ac5bba68-f036-4e09-846e-8f32731cc928:trunk/gelee:1448
merged gelee at svn

Show diffs side-by-side

added added

removed removed

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