]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dojox/grid/_data/fields.js
add Dojo 1.1.1
[eow] / static / dojo-release-1.1.1 / dojox / grid / _data / fields.js
1 if(!dojo._hasResource["dojox.grid._data.fields"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojox.grid._data.fields"] = true;
3 dojo.provide("dojox.grid._data.fields");
4
5 dojo.declare("dojox.grid.data.Mixer", null, {
6         // summary:
7         //      basic collection class that provides a default value for items
8         
9         constructor: function(){
10                 this.defaultValue = {};
11                 this.values = [];
12         },
13         count: function(){
14                 return this.values.length;
15         },
16         clear: function(){
17                 this.values = [];
18         },
19         build: function(inIndex){
20                 var result = dojo.mixin({owner: this}, this.defaultValue);
21                 result.key = inIndex;
22                 this.values[inIndex] = result;
23                 return result;
24         },
25         getDefault: function(){
26                 return this.defaultValue;
27         },
28         setDefault: function(inField /*[, inField2, ... inFieldN] */){
29                 for(var i=0, a; (a = arguments[i]); i++){
30                         dojo.mixin(this.defaultValue, a);
31                 }
32         },
33         get: function(inIndex){
34                 return this.values[inIndex] || this.build(inIndex);
35         },
36         _set: function(inIndex, inField /*[, inField2, ... inFieldN] */){
37                 // each field argument can be a single field object of an array of field objects
38                 var v = this.get(inIndex);
39                 for(var i=1; i<arguments.length; i++){
40                         dojo.mixin(v, arguments[i]);
41                 }
42                 this.values[inIndex] = v;
43         },
44         set: function(/* inIndex, inField [, inField2, ... inFieldN] | inArray */){
45                 if(arguments.length < 1){
46                         return;
47                 }
48                 var a = arguments[0];
49                 if(!dojo.isArray(a)){
50                         this._set.apply(this, arguments);
51                 }else{
52                         if(a.length && a[0]["default"]){
53                                 this.setDefault(a.shift());
54                         }
55                         for(var i=0, l=a.length; i<l; i++){
56                                 this._set(i, a[i]);
57                         }
58                 }
59         },
60         insert: function(inIndex, inProps){
61                 if (inIndex >= this.values.length){
62                         this.values[inIndex] = inProps;
63                 }else{
64                         this.values.splice(inIndex, 0, inProps);
65                 }
66         },
67         remove: function(inIndex){
68                 this.values.splice(inIndex, 1);
69         },
70         swap: function(inIndexA, inIndexB){
71                 dojox.grid.arraySwap(this.values, inIndexA, inIndexB);
72         },
73         move: function(inFromIndex, inToIndex){
74                 dojox.grid.arrayMove(this.values, inFromIndex, inToIndex);
75         }
76 });
77
78 dojox.grid.data.compare = function(a, b){
79         return (a > b ? 1 : (a == b ? 0 : -1));
80 }
81
82 dojo.declare('dojox.grid.data.Field', null, {
83         constructor: function(inName){
84                 this.name = inName;
85                 this.compare = dojox.grid.data.compare;
86         },
87         na: dojox.grid.na
88 });
89
90 dojo.declare('dojox.grid.data.Fields', dojox.grid.data.Mixer, {
91         constructor: function(inFieldClass){
92                 var fieldClass = inFieldClass ? inFieldClass : dojox.grid.data.Field;
93                 this.defaultValue = new fieldClass();
94         },
95         indexOf: function(inKey){
96                 for(var i=0; i<this.values.length; i++){
97                         var v = this.values[i];
98                         if(v && v.key == inKey){return i;}
99                 }
100                 return -1;
101         }
102 });
103
104 }