-
Notifications
You must be signed in to change notification settings - Fork 15
/
mixin.js
1213 lines (1039 loc) · 31.3 KB
/
mixin.js
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
define('Mixin', [
'underscore',
'Backbone.Advice'
], function(_) {
var Mixin = {
view: {},
ComponentView: {},
model: {},
collection: {},
all: {}
};
/**
* MIXIN
* add anything in the options to the object
*/
Mixin.all.overrideWithOptions = function overrideWithOptions() {
this.after('initialize', function(options, options2) {
var obj = options2;
if (this instanceof Backbone.View)
obj = options;
_.each(_.keys(obj || {}), function(key) {
this[key] = obj[key];
}, this);
});
};
/**
* MIXIN
* add in a decorate method (like render but sets the element)
*/
Mixin.view.decorate = function() {
this.setDefaults({
wasDecorated_: false,
decorate: function(el) {
if (this.canDecorate(el))
this.setElement(el);
else
return false;
this.render();
this.wasDecorated_ = true;
},
canDecorate: function() {
return true;
}
});
this.before('render', function() {
this.wasDecorated_ = false;
});
};
/**
* MIXIN
* adds on a selected paramenter for a view as well as methods to deal with
* selected state and changes to the state.
*/
Mixin.view.makeSelectable = function() {
this.setDefaults({
selectable: true,
selected: false,
select: function(sel) {
if (!this.isSelectable())
return;
var temp = this.selected;
this.selected = sel === undefined || !!sel;
if (temp != this.selected) {
if (this.selected)
this.onSelect();
else
this.onDeselect();
}
},
deselect: function() {
this.select(false);
},
toggleSelect: function() {
this.select(!this.selected);
},
isSelected: function() {
return this.selected && this.isSelectable();
},
isSelectable: function() {
return this.selectable;
},
onSelect: function() {},
onDeselect: function() {}
});
};
/**
* MIXIN
* will attempt to set focus to the views element when it is selected and
* will blur if deselected.
*/
Mixin.view.focusOnSelect = function() {
this.mixin([
Mixin.view.makeSelectable,
Mixin.view.makeFocusable
]);
this.after('onSelect', function() {
this.setFocus();
});
this.after('onDeselect', function() {
this.setBlur();
});
};
/**
* MIXIN
* Allows the setting of the expanded attribute and will add an expanded
* class the the parent element.
*/
Mixin.view.expandable = function() {
this.setDefaults({
expanded: false,
isExpanded: function() {
return this.expanded;
}
});
this.after('initialize', function() {
if (this.expanded)
this.expand();
});
this.around('expand', function(orig, exp) {
var temp = this.expanded;
this.expanded = exp === undefined || exp;
if (temp == this.expanded)
return;
orig();
if (this.expanded)
this.onExpand();
else
this.onCollapse();
});
this.before('collapse', function() {
this.expand(false);
});
this.after('onExpand', function() {
this.$el.addClass('expanded');
});
this.after('onCollapse', function() {
this.$el.removeClass('expanded');
});
};
/**
* MIXIN
* allows you to see the status of the collection updating
*/
Mixin.collection.updateStatus = function() {
this.setDefaults({
UpdateStatus: {
init: 0,
loading: 1,
loaded: 2,
updating: 3
},
setUpdateStatus: function(status) {
if (status == this.updateStatus)
return;
this.updateState = status;
this.trigger('updateStatus', status, this);
},
getUpdateStatus: function() {
return this.updateState;
},
isRequesting: function() {
return this.updateState == 1 || this.updateState == 3;
}
});
this.before('initialize', function() {
this.setUpdateStatus(0);
});
this.around('fetch', function(orig, options) {
if (options.add)
this.setUpdateStatus(this.UpdateStatus.updating);
else
this.setUpdateStatus(this.UpdateStatus.loading);
options.success =
Backbone.Advice.after(options.success || function(){},
_.bind(function() {
this.setUpdateStatus(this.UpdateStatus.loaded);
}, this));
orig(options);
});
};
/**
* MIXIN
* allows you to hide or show the list element
* @param {{listElem: string|Element}} options the element or selector for
* the list
*/
Mixin.view.showList = function(options) {
this.setDefaults({
showList: function(vis) {
if (vis === false)
this.$(options.listElem).hide();
else
this.$(options.listElem).show();
}
});
};
/**
* MIXIN
* will display a spinner on initial load.
* @param {{
* loadingElem: string|Element,
* ?showAll: boolean
* }} options loadingElem is the loading element container to show,
* showAll will show that element on all loads, not just initial
*/
Mixin.view.showCollectionLoading = function(options) {
this.mixin([
Mixin.view.showList
], options);
this.before('initialize', function() {
this.collection.on('updateStatus', this.updateStatusChange, this);
this.updateStatusChange();
});
this.setDefaults({
updateStatusChange: function(status) {
if (!status)
status = this.collection.updateStatus;
if (status == this.collection.UpdateStatus.loading ||
status == this.collection.UpdateStatus.updating && options.showAll)
this.showLoading();
if (status == this.collection.UpdateStatus.loaded) {
this.showList();
}
},
showLoading: function() {
if (options.loadingElem) {
this.$(options.loadingElem).show();
if (!options.showAll)
this.showList(false);
}
},
hideLoading: function() {
this.$(options.loadingElem).hide();
}
});
this.after('showList', function(vis) {
if (vis !== false) {
this.hideLoading();
}
});
};
/**
* MIXIN
* will display a spinner on initial load.
* @param {{
* noResultsElem: string|Element
* }} options noResultsElem is the element to show when no results
*/
Mixin.view.showNoResults = function(options) {
this.mixin([
Mixin.view.showList
], options);
this.around('showList', function(orig, vis) {
if (vis === false || this.collection.length) {
$(options.noResultsElem).hide();
return orig(vis);
}
this.$(options.noResultsElem).show();
return orig(false);
});
};
/**
* MIXIN
* loads both showNoResults and showLoading mixins
*/
Mixin.view.showLoadAndNoResults = function(options) {
this.mixin([
Mixin.view.showNoResults,
Mixin.view.showCollectionLoading
], options);
};
/**
* MIXIN
* Will automatically set expansion state based on selection state.
*/
Mixin.view.expandWhenSelected = function() {
this.mixin([
Mixin.view.makeSelectable,
Mixin.view.expandable
]);
this.after('onSelect', function() {
this.expand();
});
this.after('onDeselect', function() {
this.collapse();
});
};
/**
* MIXIN
* toggle selection state on click.
*/
Mixin.view.clickSelect = function() {
this.mixin(Mixin.view.makeSelectable);
this.addToObj({
events: {
'click': 'onClick'
}
});
this.after('onClick', function(event) {
if (!document.getSelection().isCollapsed)
return;
if (this.selectableElement(event.target))
this.toggleSelect();
});
this.around('selectableElement', function(fn, el) {
return fn(el) ||
el == this.el ||
this.$el.contains(el);
});
};
/**
* MIXIN
* Allow the view to be focusable by adding a tabindex and add in handlers
* for focus state changes.
*/
Mixin.view.makeFocusable = function() {
this.after('initialize', function() {
if (this.$el.prop('tabindex') === undefined)
this.$el.prop('tabindex', 0);
});
this.addToObj({
events: {
'focus': 'onFocus',
'blur' : 'onBlur'
}
});
this.clobber({
isFocusable: true,
inFocus: false,
setFocus: function(arg) {
if (arg === undefined || arg)
this.el.focus();
else
this.el.blur();
},
isFocused: function() {
return this.inFocus;
},
setBlur: function() {
this.setFocus(false);
}
});
this.before('onFocus', function() {
this.inFocus = true;
});
this.before('onBlur', function() {
this.inFocus = false;
});
};
/**
* MIXIN
* add in a handler for keyup.
*/
Mixin.view.handleKeyboard = function(options) {
this.mixin([
Mixin.view.makeFocusable
], options);
this.setDefaults({
onKeyup: function(){},
onKeydown: function(){}
});
this.addToObj({
events: {
'keyup': 'onKeyup',
'keydown': 'onKeydown'
}
});
};
/**
* MIXIN
* add in a function to handle additions to the collection.
*/
Mixin.view.handleAdd = function() {
this.after('initialize', function() {
this.collection.on('add', _.bind(function(item, collection, options) {
this.onAdd(item, collection, options);
}, this));
});
this.setDefaults({
onAdd: function(item) {
this.trigger('add', item);
}
});
};
/**
* MIXIN
* add in a function to handle removing from the collection.
*/
Mixin.view.handleRemove = function() {
this.after('initialize', function() {
this.collection.on('remove', _.bind(function(item, collection, options) {
this.onRemove(item, collection, options);
}, this));
});
this.setDefaults({
onRemove: function(item) {
this.trigger('remove', item);
}
});
};
/**
* MIXIN
* add in a function to handle resetting the collection.
*/
Mixin.view.handleReset = function() {
this.after('initialize', function() {
this.collection.on('reset', _.bind(function(collection, options) {
this.onReset(collection, options);
}, this));
});
this.setDefaults({
onReset: function(collection) {
this.trigger('reset', collection);
}
});
};
Mixin.view.handleEvents = function() {
this.mixin([
Mixin.view.handleAdd,
Mixin.view.handleRemove,
Mixin.view.handleReset
]);
};
/**
* MIXIN
* use when adding elements to the top, will keep scroll in position.
* @param {{scrollEl: string|Element}} opt scrollEl is the scroll element
*/
Mixin.view.keepScroll = function(opt) {
this.around('onAdd', function(fn, item, collection, options) {
var scrollEl = this.$(opt.scrollEl);
if (!scrollEl.length)
scrollEl = null;
var el = scrollEl || this.$el;
var bottom = el[0].scrollHeight - el.scrollTop();
if (el.scrollTop() === 0)
bottom = null;
fn(item, collection, options);
if (bottom !== null)
el.scrollTop(el[0].scrollHeight - bottom);
});
};
/**
* MIXIN
* register a collection with a model store and use that to check for models
* before creating them. works with Backbone.ModelStore
* @param {{modelStore: Backbone.ModelRegistry}} options the store with which
* keep the models
*/
Mixin.collection.modelStore = function(options) {
this.setDefaults({
idAttribute: 'index',
modelStore: options.modelStore || { getModel: function() {} }
});
this.before('initialize', function(models, options) {
if (options && options.modelStore)
this.modelStore = options.modelStore;
this.modelStore.registerCollection(this);
});
this.around('_prepareModel', function(fn, model, options) {
var a = model;
if (!(model instanceof Backbone.Model)) {
model = this.modelStore.getModel(model[this.idAttribute]) || model;
}
var mod = fn(model, options);
mod.set(a);
return mod;
});
};
/**
* MIXIN
* toggle selection state on click.
*/
Mixin.view.clickSelect = function() {
this.mixin(Mixin.view.makeSelectable);
this.addToObj({
events: {
'click': 'onClick'
}
});
this.setDefaults({
selectableElement: function() {return true;}
});
this.after('onClick', function(event) {
if (!document.getSelection().isCollapsed)
return;
if (this.selectableElement(event.target))
this.toggleSelect();
});
};
/**
* MIXIN
* scroll the scrollEl to top of child on selectChild
* @param {{scrollEl: string|Element}} opt scrollEl is the scroll element
*/
Mixin.view.scrollToSelectedChild = function(options) {
this.after('selectChild', function(child, select) {
if (select === false)
return;
var el;
if (_.isFunction(options.scrollEl)) {
el = $(options.scrollEl(this));
} else {
el = this.$(options.scrollEl);
}
el.scrollTop(
el.scrollTop() +
child.$el.offset().top -
el.offset().top
);
});
};
/**
* MIXIN
* Allow the list to keep track of select state on children and toggle their
* states.
* NB: you may have to create this.getChildren
*/
Mixin.view.allowSelectableChildren = function() {
this.clobber({
selectedChildren: [],
selectChild: function(child, select) {
if (select === false) {
this.deselectChild(child);
return;
}
if (!_.contains(this.getChildren(), child))
return;
if (!_.contains(this.selectedChildren, child))
this.selectedChildren.push(child);
if (child.hasMixin(Mixin.view.makeSelectable))
child.select();
return child;
},
deselectChild: function(child) {
if (!_.contains(this.selectedChildren, child))
return;
this.selectedChildren = _.without(this.selectedChildren, child);
if (child.hasMixin(Mixin.view.makeSelectable))
child.deselect();
return child;
}
});
};
/**
* MIXIN
* Only allow one child at a time to be selected.
* NB: you may have to create this.getChildren ()
* @param {{?stopAtEnds: boolean}} options whether selection wraps.
*/
Mixin.view.singleSelectChild = function(options) {
this.mixin([
// Mixin.view.getChildren,
Mixin.view.allowSelectableChildren
], options);
this.after('initialize', function() {
if (this.collection && this.collection instanceof Backbone.Collection)
this.listenTo(this.collection, 'reset', _.bind(function(){
this.selectedChild = null;
this.selectedChildren = [];
}, this));
});
this.before('selectChild', function(child, select) {
var children = this.getChildren();
if (!_.contains(children, child))
return;
if (select === false) {
if (this.selectedChild == child) {
this.selectedChild = null;
this.selectedChildren = [];
}
return;
}
_.chain(children).difference([child]).filter(function(child) {
return child.hasMixin(Mixin.view.makeSelectable);
}).each(function(child) {
child.deselect();
});
this.selectedChildren = [];
this.selectedChild = child;
});
this.after('deselectChild', function(child) {
if (this.selectedChild == child)
this.selectedChild = null;
});
this.clobber({
selectNextChild: function() {
this.selectRelativeChild(-1);
},
hasNextChild:function(){
if (!this.selectedChild)
return;
var children = _.filter(this.getChildren(), function(view) {
return view.selectable && view.isSelectable();
});
var currInd = _.indexOf(children, this.selectedChild);
return currInd - 1 >= 0;
},
selectPreviousChild: function() {
this.selectRelativeChild(1);
},
selectRelativeChild: function(rel) {
if (!this.selectedChild)
return;
var children = _.filter(this.getChildren(), function(view) {
return view.selectable && view.isSelectable();
});
var child = this.selectedChild;
var length = children.length;
var next = null;
var nextInd = 0;
var currInd = _.indexOf(children, child);
if (!length)
return;
if (options.stopAtEnds && rel + currInd > length - 1) {
nextInd = length - 1;
} else if (options.stopAtEnds && rel + currInd < 0) {
nextInd = 0;
} else {
// make sure relative is within limits
rel = rel % length;
// the index of the relative child (allows negatives)
nextInd = (currInd + rel + length) % length;
}
next = children[nextInd];
return this.selectChild(next);
},
selectFirstChild: function() {
var children = this.getChildren();
if (children.length)
return this.selectChild(children[0]);
},
selectLastChild: function() {
var children = this.getChildren();
if (children.length)
return this.selectChild(children[children.length - 1]);
}
});
};
/****************************************
** For use with Backbone.ComponentView **
****************************************/
/**
* MIXIN
* @param {{
* ?itemTemplate: string,
* ?contentElement: string|Element,
* ?setup: Object
* }} options itemTemplate to override template of items,
* contentElement to override where list is placed,
* setup object to be passed in to new item's constructor
*/
Mixin.ComponentView.autoBigList = function(options) {
if (options.contentElement)
this.clobber({
getContentElement: function() {
return this.$el.find(options.contentElement);
}
});
var createEl = function(tagName, className, attributes, id, innerHTML) {
var html = '<' + tagName;
html += (className ? ' class="' + className + '"' : '');
if (attributes) {
_.each(attributes, function(val, key) {
html += ' ' + key + '="' + val + '"';
});
}
html += (id ? ' id="' + id + '"' : '');
html += '>' + innerHTML + '</' + tagName + '>';
return html;
};
this.after('initialize', function() {
var iv = this.itemView.prototype;
this._autobiglist = {
html: '',
template: Handlebars.compile(
createEl(
iv.tagName, iv.className, iv.attributes, iv.id,
(options.itemTemplate || iv.template)
)
),
toAdd: []
};
});
this.after('enterDocument', function() {
this.collection.on('reset', this.autolist_, this);
this.collection.on('add', this.autolist_, this);
this.collection.on('remove', this.rem_, this);
this.doneListing_ = _.debounce(this.doneListing_, 100);
this.autolist_();
});
this.setDefaults({
autolist_: function(model, silent) {
var toAdd = this._autobiglist.toAdd;
var template = this._autobiglist.template;
if (model instanceof Backbone.Model) {
var setup = _.extend({}, options.setup);
setup.model = model;
var item = new this.itemView(setup);
toAdd.push(item);
this._autobiglist.html += template(item.serialize());
} else if(model) {
$(this.getContentElement()).empty();
_.each(model.models, function(mod) {
this.autolist_(mod, true);
}, this);
}
if (silent !== true)
this.doneListing_();
},
doneListing_: function() {
var html = this._autobiglist.html;
var toAdd = this._autobiglist.toAdd;
if (!html)
return;
var div = document.createElement('div');
div.innerHTML = html;
var els = _.toArray(div.childNodes);
var l = els.length;
html = '';
var frag = document.createDocumentFragment();
for (var i = 0; i < l; i++) {
frag.appendChild(els[i]);
}
this.getContentElement().appendChild(frag);
for (i = 0; i < l; i++) {
toAdd[i].decorate(els[i]);
}
this._autobiglist.toAdd = [];
}
});
};
/**
* MIXIN
* @param {{
* ?contentElement: string|Element
* }} options contentElement to override where list is placed
*/
Mixin.ComponentView.autolist = function(options) {
if (options.contentElement)
this.clobber({
getContentElement: function() {
return this.$el.find(options.contentElement);
}
});
this.after('enterDocument', function() {
if(this.collection instanceof Array)
this.collection = new Backbone.Collection(this.collection);
this.listenTo(this.collection, 'reset', this.autolist_);
this.listenTo(this.collection, 'sort', this.autolist_);
this.listenTo(this.collection, 'add', this.autolist_);
this.listenTo(this.collection, 'remove', this.autolist_);
this.autolist_();
});
this.after('initialize', function() {
_.bindAll(this, 'autolist_');
});
this.setDefaults({
itemViewSetup: {},
autolist_: function() {
// var frag = document.createDocumentFragment();
this.beforeList(this.getContentElement());
// var el = this.getContentElement();
var model = this.collection;
var models = model.models;
var children = this._children || [];
var childModels = _.map(children, function(child) {
return child.getModel();
});
var removed = _.filter(children, function(child) {
return !_.contains(models, child.getModel());
});
if (children.length === 0) {
_.each(models, function(model) {
var setup = _.extend({}, this.itemViewSetup);
if (model instanceof Backbone.Model)
setup.model = model;
if (model instanceof Backbone.Collection)
setup.collection = model;
var newChild = new this.itemView(setup);
this.addChild(newChild, true);
}, this);
} else {
_.each(removed, function(child) {
if (!_.chain(this.views)
.values()
.flatten()
.contains(child)
.value()) {
this.removeChild(child, true);
child.dispose();
}
}, this);
_.each(models, function(model, ind) {
var child;
if(!_.contains(childModels, model)) {
var setup = _.extend({}, this.itemViewSetup);
if (model instanceof Backbone.Model)
setup.model = model;
if (model instanceof Backbone.Collection)
setup.collection = model;
child = new this.itemView(setup);
child.createDom();
this.addChildAt(child, ind, true);
} else {
child = _.find(children, function(c) {
return c.getModel() == model;
});
if (this.getChildAt(ind) != child)
this.addChildAt(child, ind);
}
}, this);
}
this.afterList(this.getContentElement());
},
afterList: function() {},
beforeList: function() {}
});
};
/*******************************
** For use with LayoutManager **
*******************************/
/**
* MIXIN
* adds in getChildren method
* NB: there are already getView and getViews methods
*/
Mixin.view.getChildren = function(options) {
options = options || {};
this.setDefaults({
defaultChildContainer: '.content',
getChildren: function(container) {
return this.views[
container ||
options.childContainer ||
this.defaultChildContainer
] || [];
},
getAllChildren: function() {
return _.uniq(_.flatten(_.values(this.views)));
}
});
};
/**
* MIXIN
* can call getParent() on view insteand of __manager__.parent
*/
Mixin.view.getParent = function() {
this.setDefaults({
getParent: function() {
return this.__manager__ &&
this.__manager__.parent;
}