-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackbone.kendowidget.js
84 lines (69 loc) · 1.92 KB
/
backbone.kendowidget.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
Backbone.KendoWidget = Backbone.View.extend({
initialize: function() {
var _this = this, widget;
var widget = this.getElement();
this.$el.html(widget);
if(typeof this.setData === 'function') {
this.options.dataSource = this.setData();
}
widget = widget[this.widget](this.options).data(this.widget);
if(widget.enable && this.dataBind) {
widget.enable(false);
this.enable = _.bind(widget.enable, widget);
if(this.model) {
widget.value(this.model.get(this.dataBind));
widget.bind('change', function(e) {
var value = e.value || e._value || e.sender._value;
_this.model.set(_this.dataBind, value);
_this.model.save();
});
this.model.on('change:' + _this.dataBind, function(model, value) {
console.log(value);
widget.value(value);
});
this.model.on('change:isOn', function(model, isOn) {
widget.enable(isOn);
});
}
}
if(this.emitter) {
widget.enable(false);
this.enable = _.bind(widget.enable, widget);
if(this.model) {
this.model.on('change:isOn', function(model, isOn) {
widget.enable(isOn);
});
widget.bind('change', function() {
_this.model.goToBookmark(widget.value());
});
if(Drupal.admin) {
require(['bookmarkr'], function(bookmarkr) {
bookmarkr.initialize(widget).render();
});
}
}
}
if(widget.dataSource) {
widget.dataSource.read();
}
},
getElement: function() {
switch(this.widget) {
case 'kendoSlider':
return $('<div />', { id: 'widget-' + this.boundTo });
case 'kendoNumericTextBox':
return $('<input />', { id: 'widget-' + this.boundTo });
case 'kendoDropDownList':
return $('<input />', { id: 'widget-' + this.boundTo });
default:
return $('<div />', { id: 'widget-' + this.boundTo });
}
},
remove: function() {
this.undelegateEvents();
if(this.$el.data(this.widget)) {
this.$el.data(this.widget).remove();
}
delete this.model;
}
});