~lutostag/ubuntu/utopic/maas/1.5.2

« back to all changes in this revision

Viewing changes to src/maasserver/static/jslibs/yui/3.4.1/build/recordset-sort/recordset-sort-debug.js

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2012-03-15 18:14:08 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20120315181408-zgl94hzo0x4n99an
Tags: 0.1+bzr295+dfsg-0ubuntu2
* debian/patches:
  - 01-fix-database-settings.patch: Update to set PSERV_URL.
  - 02-pserv-config.patch: Set port to 8001.
* debian/maas.postinst: Run maas-import-isos on install.
* debian/control: Depends on rabbitmq-server.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
YUI 3.4.1 (build 4118)
 
3
Copyright 2011 Yahoo! Inc. All rights reserved.
 
4
Licensed under the BSD License.
 
5
http://yuilibrary.com/license/
 
6
*/
 
7
YUI.add('recordset-sort', function(Y) {
 
8
 
 
9
/**
 
10
 * Adds default and custom sorting functionality to the Recordset utility
 
11
 * @module recordset
 
12
 * @submodule recordset-sort
 
13
 */
 
14
 
 
15
var Compare = Y.ArraySort.compare,
 
16
isValue = Y.Lang.isValue;
 
17
 
 
18
/**
 
19
 * Plugin that adds default and custom sorting functionality to the Recordset utility
 
20
 * @class RecordsetSort
 
21
 */
 
22
 
 
23
function RecordsetSort(field, desc, sorter) {
 
24
    RecordsetSort.superclass.constructor.apply(this, arguments);
 
25
}
 
26
 
 
27
Y.mix(RecordsetSort, {
 
28
    NS: "sort",
 
29
 
 
30
    NAME: "recordsetSort",
 
31
 
 
32
    ATTRS: {
 
33
 
 
34
        /**
 
35
        * @description The last properties used to sort. Consists of an object literal with the keys "field", "desc", and "sorter"
 
36
        *
 
37
        * @attribute lastSortProperties
 
38
        * @public
 
39
        * @type object
 
40
        */
 
41
        lastSortProperties: {
 
42
            value: {
 
43
                field: undefined,
 
44
                desc: true,
 
45
                sorter: undefined
 
46
            },
 
47
            validator: function(v) {
 
48
                return (isValue(v.field) && isValue(v.desc) && isValue(v.sorter));
 
49
            }
 
50
        },
 
51
 
 
52
        /**
 
53
        * @description Default sort function to use if none is specified by the user.
 
54
        * Takes two records, the key to sort by, and whether sorting direction is descending or not (boolean).
 
55
        * If two records have the same value for a given key, the ID is used as the tie-breaker.
 
56
        *
 
57
        * @attribute defaultSorter
 
58
        * @public
 
59
        * @type function
 
60
        */
 
61
        defaultSorter: {
 
62
            value: function(recA, recB, field, desc) {
 
63
                var sorted = Compare(recA.getValue(field), recB.getValue(field), desc);
 
64
                if (sorted === 0) {
 
65
                    return Compare(recA.get("id"), recB.get("id"), desc);
 
66
                }
 
67
                else {
 
68
                    return sorted;
 
69
                }
 
70
            }
 
71
        },
 
72
 
 
73
        /**
 
74
        * @description A boolean telling if the recordset is in a sorted state.
 
75
        *
 
76
        * @attribute defaultSorter
 
77
        * @public
 
78
        * @type function
 
79
        */
 
80
        isSorted: {
 
81
            value: false
 
82
        }
 
83
    }
 
84
});
 
85
 
 
86
Y.extend(RecordsetSort, Y.Plugin.Base, {
 
87
 
 
88
    /**
 
89
     * @description Sets up the default function to use when the "sort" event is fired.
 
90
     *
 
91
     * @method initializer
 
92
     * @protected
 
93
     */
 
94
    initializer: function(config) {
 
95
 
 
96
        var self = this,
 
97
        host = this.get('host');
 
98
 
 
99
 
 
100
        this.publish("sort", {
 
101
            defaultFn: Y.bind("_defSortFn", this)
 
102
        });
 
103
 
 
104
        //Toggle the isSorted ATTR based on events.
 
105
        //Remove events dont affect isSorted, as they are just popped/sliced out
 
106
        this.on("sort",
 
107
        function() {
 
108
            self.set('isSorted', true);
 
109
        });
 
110
 
 
111
        this.onHostEvent('add',
 
112
        function() {
 
113
            self.set('isSorted', false);
 
114
        },
 
115
        host);
 
116
        this.onHostEvent('update',
 
117
        function() {
 
118
            self.set('isSorted', false);
 
119
        },
 
120
        host);
 
121
 
 
122
    },
 
123
 
 
124
    destructor: function(config) {
 
125
        },
 
126
 
 
127
    /**
 
128
     * @description Method that all sort calls go through. 
 
129
     * Sets up the lastSortProperties object with the details of the sort, and passes in parameters 
 
130
     * to the "defaultSorter" or a custom specified sort function.
 
131
     *
 
132
     * @method _defSortFn
 
133
     * @private
 
134
     */
 
135
    _defSortFn: function(e) {
 
136
        //have to work directly with _items here - changing the recordset.
 
137
        this.get("host")._items.sort(function(a, b) {
 
138
            return (e.sorter)(a, b, e.field, e.desc);
 
139
        });
 
140
        
 
141
        this.set('lastSortProperties', e);
 
142
    },
 
143
 
 
144
    /**
 
145
     * @description Sorts the recordset.
 
146
     *
 
147
     * @method sort
 
148
     * @param field {string} A key to sort by.
 
149
     * @param desc {boolean} True if you want sort order to be descending, false if you want sort order to be ascending
 
150
     * @public
 
151
     */
 
152
    sort: function(field, desc, sorter) {
 
153
        this.fire("sort", {
 
154
            field: field,
 
155
            desc: desc,
 
156
            sorter: sorter || this.get("defaultSorter")
 
157
        });
 
158
    },
 
159
 
 
160
    /**
 
161
     * @description Resorts the recordset based on the last-used sort parameters (stored in 'lastSortProperties' ATTR)
 
162
     *
 
163
     * @method resort
 
164
     * @public
 
165
     */
 
166
    resort: function() {
 
167
        var p = this.get('lastSortProperties');
 
168
        this.fire("sort", {
 
169
            field: p.field,
 
170
            desc: p.desc,
 
171
            sorter: p.sorter || this.get("defaultSorter")
 
172
        });
 
173
    },
 
174
 
 
175
    /**
 
176
     * @description Reverses the recordset calling the standard array.reverse() method.
 
177
     *
 
178
     * @method reverse
 
179
     * @public
 
180
     */
 
181
    reverse: function() {
 
182
        this.get('host')._items.reverse();
 
183
    },
 
184
 
 
185
    /**
 
186
     * @description Sorts the recordset based on the last-used sort parameters, but flips the order. (ie: Descending becomes ascending, and vice versa).
 
187
     *
 
188
     * @method flip
 
189
     * @public
 
190
     */
 
191
    flip: function() {
 
192
        var p = this.get('lastSortProperties');
 
193
 
 
194
        //If a predefined field is not provided by which to sort by, throw an error
 
195
        if (isValue(p.field)) {
 
196
            this.fire("sort", {
 
197
                field: p.field,
 
198
                desc: !p.desc,
 
199
                sorter: p.sorter || this.get("defaultSorter")
 
200
            });
 
201
        }
 
202
        else {
 
203
            Y.log('You called flip before setting a field by which to sort by. Maybe you meant to call reverse().');
 
204
        }
 
205
    }
 
206
});
 
207
 
 
208
Y.namespace("Plugin").RecordsetSort = RecordsetSort;
 
209
 
 
210
 
 
211
 
 
212
}, '3.4.1' ,{requires:['arraysort','recordset-base','plugin']});