aboutsummaryrefslogtreecommitdiff
path: root/node_modules/montage/ui/list.reel/list.js
blob: 2af99bf4d543208bc18eac96e8d875650259646e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
/* <copyright>
 This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
 No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
 (c) Copyright 2011 Motorola Mobility, Inc.  All Rights Reserved.
 </copyright> */
/**
	@module "montage/ui/list.reel"
    @requires montage/core/core
    @requires montage/ui/component
*/
var Montage = require("montage").Montage,
    Component = require("ui/component").Component;
/**
 @class module:"montage/ui/list.reel".List
 @extends module:montage/ui/component.Component
 */
var List = exports.List = Montage.create(Component,/** @lends module:"montage/ui/list.reel".List# */ {
/**
  Description TODO
  @private
*/
    _repetition: {
        enumerable: false,
        value: null
    },
/**
  Description TODO
  @private
*/
    _scrollview: {
        enumerable: false,
        value: null
    },
/**
  Description TODO
  @private
*/
    _orphanedChildren: {
        enumerable: false,
        value: null
    },
/**
        Description TODO
        @type {Property}
        @default null
    */
    delegate: {
        enumerable: false,
        value: null
    },

    //TODO make some convenient forwarding property or something, this is a little tedious

    // Properties to forward to the scrollview
 /**
  Description TODO
  @private
*/
    _axisForScrollview: {
        enumerable: false,
        value: null
    },
/**
        Description TODO
        @type {Function}
        @default null
    */
    axis: {
        enumerable: false,
        get: function() {
            if (this._scrollview) {
                return this._scrollview.axis;
            } else {
                return this._axisForScrollview;
            }
        },
        set: function(value) {
            if (this._scrollview) {
                this._scrollview.axis = value;
            } else {
                this._axisForScrollview = value;
            }
        }
    },

    //Properties to forward to the repetition
/**
  Description TODO
  @private
*/
    _objectsForRepetition: {
        enumerable: false,
        value: null
    },
/**
        Description TODO
        @type {Function}
        @default null
    */
    objects: {
        enumerable: false,
        get: function() {
            if (this._repetition) {
                return this._repetition.objects;
            } else {
                return this._objectsForRepetition;
            }
        },
        set: function(value) {
            if (this._repetition) {
                this._repetition.objects = value;
            } else {
                this._objectsForRepetition = value;
            }
        }
    },
/**
  Description TODO
  @private
*/
    _contentControllerForRepetition: {
        enumerable: false,
        value: null
    },
/**
        Description TODO
        @type {Function}
        @default null
    */
    contentController: {
        enumerable: false,
        get: function() {
            if (this._repetition) {
                return this._repetition.contentController;
            } else {
                return this._contentControllerForRepetition;
            }
        },
        set: function(value) {
            if (this._repetition) {
                this._repetition.contentController = value;
            } else {
                this._contentControllerForRepetition = value;
            }
        }
    },
/**
  Description TODO
  @private
*/
    _isSelectionEnabledForRepetition: {
        enumerable: false,
        value: null
    },
/**
        Description TODO
        @type {Function}
        @default null
    */
    isSelectionEnabled: {
        enumerable: false,
        get: function() {
            if (this._repetition) {
                return this._repetition.isSelectionEnabled;
            } else {
                return this._isSelectionEnabledForRepetition;
            }
        },
        set: function(value) {
            if (this._repetition) {
                this._repetition.isSelectionEnabled = value;
            } else {
                this._isSelectionEnabledForRepetition = value;
            }
        }
    },

    // Initialization

    // TODO we should probably support the programmatic initialization of a list; forwarding the childComponents
    // along to the repetition
    // I want to say that if somebody knows enough to do that they know enough to append the child components' elements
    // into the repetition, not the list
/**
    Description TODO
    @function
    @param {Property} type TODO
    @param {Property} listener TODO
    @param {Property} useCapture TODO
    @param {Property} atSignIndex TODO
    @param {Property} bindingOrigin TODO
    @param {Property} bindingPropertyPath TODO
    @param {Property} bindingDescriptor TODO
    @returns null or object
    */
    propertyChangeBindingListener: {
        value: function(type, listener, useCapture, atSignIndex, bindingOrigin, bindingPropertyPath, bindingDescriptor) {

            // TODO could forward along less-special bindings this way such as "objects" in general, just to reduce an extra
            // hop in the derived property path
            if (bindingDescriptor.boundObjectPropertyPath.match(/objectAtCurrentIteration/)) {
                if (this._repetition) {
                    // TODO not sure how safe this is, but I may want to use it in the repetition's oimplementation of
                    // this method as well as it looks like it should obviously be faster than replicating the descriptor
                    bindingDescriptor.boundObject = this._repetition;
                    return this._repetition.propertyChangeBindingListener.apply(this._repetition, arguments);
                } else {
                    // Don't install this binding; we'll deal with that when the children are actually used inside
                    // the repetition and try to bind to the list directly in the future
                    // TODO maybe we could rewrite the bindingDescriptor at this point on the bindingOrigin
                    // to prevent this man-in-the-middle game we're playing with the list later on
                    return null;
                }
            } else {
                return Object.prototype.propertyChangeBindingListener.apply(this, arguments);
            }
        }},

/**
    Description TODO
    @function
*/
    deserializedFromTemplate: {
        value: function() {
            // The childComponents of the list need to be pulled aside for a moment so we can give them to the repetition
            // This is logically where people think these components are ending up anyway
            this._orphanedChildren = this.childComponents;
            this.childComponents = null;
        }
    },

/**
    Description TODO
    @function
 */
    templateDidLoad: {
        value: function() {
            // Once we know that the template for the list itself has been deserialized we actually
            // move the orphaned children of the list into the repetition
            var orphanedFragment,
                currentContentRange = this.element.ownerDocument.createRange();
            currentContentRange.selectNodeContents(this.element);
            orphanedFragment = currentContentRange.extractContents();

            this._repetition.element.appendChild(orphanedFragment);
            this._repetition.childComponents = this._orphanedChildren;
            this._repetition.needsDraw = true;

            if (this._objectsForRepetition !== null) {
                this._repetition.objects = this._objectsForRepetition;
                this._objectsForRepetition = null;
            }

            if (this._contentControllerForRepetition !== null) {
                this._repetition.contentController = this._contentControllerForRepetition;
                this._contentControllerForRepetition = null;
            }

            if (this._isSelectionEnabledForRepetition !== null) {
                this._repetition.isSelectionEnabled = this._isSelectionEnabledForRepetition;
                this._isSelectionEnabledForRepetition = null;
            }

            // Don't forget to pass along properties to the scrollview
            if (this._axisForScrollview !== null) {
                this._scrollview.axis = this._axisForScrollview;
                this._axisForScrollview = null;
            }
        }
    }

});