Upgrade to ExtJS 3.2.0 - Released 03/30/2010
[extjs.git] / examples / tasks / classes.js
index 0ba600d..cd0ead5 100644 (file)
 /*!
- * Ext JS Library 3.1.1
- * Copyright(c) 2006-2010 Ext JS, LLC
+ * Ext JS Library 3.2.0
+ * Copyright(c) 2006-2010 Ext JS, Inc.
  * licensing@extjs.com
  * http://www.extjs.com/license
  */
-Ext.BLANK_IMAGE_URL = 'images/s.gif';\r
-    \r
-Task = Ext.data.Record.create([\r
-    {name: 'taskId', type:'string'},\r
-    {name: 'title', type:'string'},\r
-    {name: 'category', type:'string'},\r
-    {name: 'description', type:'string'},\r
-    {name: 'dueDate', type:'date', dateFormat: 'Y-m-d H:i:s'},\r
-    {name: 'completed', type:'boolean'}\r
-]);\r
-\r
-Task.nextId = function(){\r
-       // if the time isn't unique enough, the addition \r
-       // of random chars should be\r
-       var t = String(new Date().getTime()).substr(4);\r
-       var s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';\r
-       for(var i = 0; i < 4; i++){\r
-               t += s.charAt(Math.floor(Math.random()*26));\r
-       }\r
-       return t;\r
-}\r
-\r
-// The main grid's store\r
-TaskStore = function(conn){\r
-       TaskStore.superclass.constructor.call(this, {\r
-        sortInfo:{field: 'dueDate', direction: "ASC"},\r
-        groupField:'dueDate',\r
-        taskFilter: 'all',\r
-        reader: new Ext.data.JsonReader({\r
-            idProperty: 'taskId'\r
-        }, Task)\r
-    });\r
-\r
-    this.proxy = new Ext.data.SqlDB.Proxy(conn, 'task', 'taskId', this);\r
-\r
-    if(window.google){ // google needs the table created\r
-        this.proxy.on('beforeload', this.prepareTable, conn);\r
-    }\r
-\r
-    this.addEvents({newcategory: true});\r
-};\r
-\r
-Ext.extend(TaskStore, Ext.data.GroupingStore, {\r
-    applyFilter : function(filter){\r
-       if(filter !== undefined){\r
-               this.taskFilter = filter;\r
-       }\r
-        var value = this.taskFilter;\r
-        if(value == 'all'){\r
-            return this.clearFilter();\r
-        }\r
-        return this.filterBy(function(item){\r
-            return item.data.completed === value;\r
-        });\r
-    },\r
-\r
-    addTask : function(data){\r
-        this.suspendEvents();\r
-        this.clearFilter();\r
-        this.resumeEvents();\r
-        this.loadData([data], true);\r
-        this.suspendEvents();\r
-        this.applyFilter();\r
-        this.applyGrouping(true);\r
-        this.resumeEvents();\r
-        this.fireEvent('datachanged', this);\r
-        this.fireEvent('newcategory', data.category);\r
-    },\r
-\r
-    prepareTable : function(){\r
-        try{\r
-        this.createTable({\r
-            name: 'task',\r
-            key: 'taskId',\r
-            fields: Task.prototype.fields\r
-        });\r
-        }catch(e){console.log(e)}\r
-    }\r
-});\r
-\r
-// The store for Categories\r
-CategoryStore = function(){\r
-    CategoryStore.superclass.constructor.call(this, {\r
-        expandData: true,\r
-        data: [],\r
-        fields:[{name: 'text', type:'string'}],\r
-        sortInfo:{field:'text', direction:'ASC'},\r
-        id: 0\r
-    });\r
-}\r
-\r
-Ext.extend(CategoryStore, Ext.data.ArrayStore, {\r
-    init : function(store){\r
-        var cats = store.collect('category', false, true);\r
-        this.loadData(cats);\r
-    },\r
-\r
-    addCategory : function(cat){\r
-        if(cat && this.indexOfId(cat) === -1){\r
-            this.clearFilter(true);\r
-            this.loadData([cat], true);\r
-            this.applySort();\r
-        }\r
-    }\r
-});\r
-\r
-// Grid column plugin that does the complete/active button in the left-most column\r
-CompleteColumn = function(){\r
-    var grid;\r
-\r
-    function getRecord(t){\r
-        var index = grid.getView().findRowIndex(t);\r
-        return grid.store.getAt(index);\r
-    }\r
-\r
-    function onMouseDown(e, t){\r
-        if(Ext.fly(t).hasClass('task-check')){\r
-            e.stopEvent();\r
-            var record = getRecord(t);\r
-            record.set('completed', !record.data.completed);\r
-            grid.store.applyFilter();\r
-        }\r
-    }\r
-\r
-    function onMouseOver(e, t){\r
-        if(Ext.fly(t).hasClass('task-check')){\r
-            Ext.fly(t.parentNode).addClass('task-check-over');\r
-        }\r
-    }\r
-\r
-    function onMouseOut(e, t){\r
-        if(Ext.fly(t).hasClass('task-check')){\r
-            Ext.fly(t.parentNode).removeClass('task-check-over');\r
-        }\r
-    }\r
-\r
-    Ext.apply(this, {\r
-        width: 22,\r
-        header: '<div class="task-col-hd"></div>',\r
-        menuDisabled:true,\r
-        fixed: true,\r
-        id: 'task-col',\r
-        renderer: function(){\r
-            return '<div class="task-check"></div>';\r
-        },\r
-        init : function(xg){\r
-            grid = xg;\r
-            grid.on('render', function(){\r
-                var view = grid.getView();\r
-                view.mainBody.on('mousedown', onMouseDown);\r
-                view.mainBody.on('mouseover', onMouseOver);\r
-                view.mainBody.on('mouseout', onMouseOut);\r
-            });\r
-        }\r
-    });\r
+Ext.BLANK_IMAGE_URL = 'images/s.gif';
+    
+Task = Ext.data.Record.create([
+    {name: 'taskId', type:'string'},
+    {name: 'title', type:'string'},
+    {name: 'category', type:'string'},
+    {name: 'description', type:'string'},
+    {name: 'dueDate', type:'date', dateFormat: 'Y-m-d H:i:s'},
+    {name: 'completed', type:'boolean'}
+]);
+
+Task.nextId = function(){
+       // if the time isn't unique enough, the addition 
+       // of random chars should be
+       var t = String(new Date().getTime()).substr(4);
+       var s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
+       for(var i = 0; i < 4; i++){
+               t += s.charAt(Math.floor(Math.random()*26));
+       }
+       return t;
+}
+
+// The main grid's store
+TaskStore = function(conn){
+       TaskStore.superclass.constructor.call(this, {
+        sortInfo:{field: 'dueDate', direction: "ASC"},
+        groupField:'dueDate',
+        taskFilter: 'all',
+        reader: new Ext.data.JsonReader({
+            idProperty: 'taskId'
+        }, Task)
+    });
+
+    this.proxy = new Ext.data.SqlDB.Proxy(conn, 'task', 'taskId', this);
+
+    if(window.google){ // google needs the table created
+        this.proxy.on('beforeload', this.prepareTable, conn);
+    }
+
+    this.addEvents({newcategory: true});
+};
+
+Ext.extend(TaskStore, Ext.data.GroupingStore, {
+    applyFilter : function(filter){
+       if(filter !== undefined){
+               this.taskFilter = filter;
+       }
+        var value = this.taskFilter;
+        if(value == 'all'){
+            return this.clearFilter();
+        }
+        return this.filterBy(function(item){
+            return item.data.completed === value;
+        });
+    },
+
+    addTask : function(data){
+        this.suspendEvents();
+        this.clearFilter();
+        this.resumeEvents();
+        this.loadData([data], true);
+        this.suspendEvents();
+        this.applyFilter();
+        this.applyGrouping(true);
+        this.resumeEvents();
+        this.fireEvent('datachanged', this);
+        this.fireEvent('newcategory', data.category);
+    },
+
+    prepareTable : function(){
+        try{
+        this.createTable({
+            name: 'task',
+            key: 'taskId',
+            fields: Task.prototype.fields
+        });
+        }catch(e){console.log(e)}
+    }
+});
+
+// The store for Categories
+CategoryStore = function(){
+    CategoryStore.superclass.constructor.call(this, {
+        expandData: true,
+        data: [],
+        fields:[{name: 'text', type:'string'}],
+        sortInfo:{field:'text', direction:'ASC'},
+        id: 0
+    });
+}
+
+Ext.extend(CategoryStore, Ext.data.ArrayStore, {
+    init : function(store){
+        var cats = store.collect('category', false, true);
+        this.loadData(cats);
+    },
+
+    addCategory : function(cat){
+        if(cat && this.indexOfId(cat) === -1){
+            this.clearFilter(true);
+            this.loadData([cat], true);
+            this.applySort();
+        }
+    }
+});
+
+// Grid column plugin that does the complete/active button in the left-most column
+CompleteColumn = function(){
+    var grid;
+
+    function getRecord(t){
+        var index = grid.getView().findRowIndex(t);
+        return grid.store.getAt(index);
+    }
+
+    function onMouseDown(e, t){
+        if(Ext.fly(t).hasClass('task-check')){
+            e.stopEvent();
+            var record = getRecord(t);
+            record.set('completed', !record.data.completed);
+            grid.store.applyFilter();
+        }
+    }
+
+    function onMouseOver(e, t){
+        if(Ext.fly(t).hasClass('task-check')){
+            Ext.fly(t.parentNode).addClass('task-check-over');
+        }
+    }
+
+    function onMouseOut(e, t){
+        if(Ext.fly(t).hasClass('task-check')){
+            Ext.fly(t.parentNode).removeClass('task-check-over');
+        }
+    }
+
+    Ext.apply(this, {
+        width: 22,
+        header: '<div class="task-col-hd"></div>',
+        menuDisabled:true,
+        fixed: true,
+        id: 'task-col',
+        renderer: function(){
+            return '<div class="task-check"></div>';
+        },
+        init : function(xg){
+            grid = xg;
+            grid.on('render', function(){
+                var view = grid.getView();
+                view.mainBody.on('mousedown', onMouseDown);
+                view.mainBody.on('mouseover', onMouseOver);
+                view.mainBody.on('mouseout', onMouseOut);
+            });
+        }
+    });
 };
\ No newline at end of file