-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectizeLibraryViewBridge.js
More file actions
81 lines (68 loc) · 2.54 KB
/
Copy pathSelectizeLibraryViewBridge.js
File metadata and controls
81 lines (68 loc) · 2.54 KB
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
rhubarb.vb.create('SelectizeLibraryViewBridge', function (parent) {
return {
selectize: null,
originalValues:{},
attachEvents: function () {
parent.attachEvents.call(this);
this.initialiseSelectize();
},
initialiseSelectize: function(){
var self = this,
$selectize = $(this.viewNode).selectize(
{
options: [],
create: false,
loadThrottle: 150,
labelField: 'name',
searchField: 'name',
allowEmptyOption: true,
plugins: ['remove_button'],
onChange:function(value) {
self.setValue(value, true);
}
}
);
this.selectize = $selectize[0].selectize;
var options = [];
for (var op in this.selectize.options) {
options.push({name:this.selectize.options[op].name, value:op});
}
this.originalValues = options;
},
onReattached: function () {
parent.onReattached.call(this);
this.refreshSelectize();
this.selectize.onSearchChange('uniqueSearchQueryOrElseCacheWillBeUsed');
},
getValue: function () {
return this.selectize.getValue();
},
setValue: function (value, preventSelectizeReload) {
parent.setValue.call(this, value);
if (!preventSelectizeReload) {
this.reloadSelectize();
}
$(this.viewNode).val(value);
this.valueChanged();
},
reloadSelectize: function () {
var self = this;
this.selectize.clear();
this.selectize.clearOptions();
this.selectize.load(function (callback) {
callback(self.originalValues);
})
},
refreshSelectize: function () {
var options = [];
for( var i = 0; i < this.viewNode.options.length; i++ ) {
options.push({name: this.viewNode.options[i].text, value: this.viewNode.options[i].value});
}
this.selectize.clear();
this.selectize.clearOptions();
this.selectize.load(function(options, callback) {
callback(options);
}.bind(this, options))
}
};
}, window.rhubarb.viewBridgeClasses.DropDownViewBridge);