-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.js
74 lines (60 loc) · 2.02 KB
/
controller.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
// I'm gonna try and do roughly the same trick as I did with tooltips.
// However, I'm probably going to try to cache them since you shouldn't be able to have more than one up at the same time.
// (Maybe.)
Controller = Ice.$extend('Controller', {
__init__: function(obj) {
this.$super();
// We don't really have to construct these, since I probably already have them open somewhere.
this.obj = obj;
this.$dialog = null;
this.is_open = false;
this.obj.$el.on('click', _.bind(this.open, this));
},
open: function() {
if(!this.$dialog) {
this.obtain_dialog();
}
// We don't stay bound to the element unless
// we're being shown.
this.bind_to_obj();
this.render_controller();
//obj.render_controller(this, this.$dialog);
if(Controller.active_controller) {
Controller.active_controller.close();
}
this.$dialog.dialog({
resize: false,
//Title defaults to $dialog's title attr,
// which construct_controller will set.
closeOnEscape: true,
width: '360px',
height: 280,
close: _.bind(this.onClose, this)
});
Controller.active_controller = this;
},
close: function() {
this.$dialog.dialog("destroy");
},
onClose: function() {
this.obj.unsub(this);
},
obtain_dialog: function() {
this.$dialog = TEMPLATES.clone('controller_dialog', this);
this.construct_controller();
},
construct_controller: function() {
this.obj.construct_controller(this, this.$dialog);
},
render_controller: function() {
//console.log(this.obj.pretty());
this.obj.render_controller(this, this.$dialog);
},
bind_to_obj: function() {
this.obj.evChanged.sub(this.onObjChange, this);
},
onObjChange: function(obj, obs, eargs) {
this.render_controller();
//this.obj.render_controller(this, this.$dialog);
}
});