-
Notifications
You must be signed in to change notification settings - Fork 1
/
workflows.js
89 lines (71 loc) · 2.79 KB
/
workflows.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
define([
'jquery',
'underscore',
'backbone',
'app',
'collections/workflows',
'text!templates/workflow.html'
], function ($, _, Backbone, app, WorkflowsCollection, workflowTpl) {
var WorkflowsView = Backbone.View.extend({
template: _.template(workflowTpl),
events: {
'keyup .search-text': 'searchKeyUp',
'click .search-btn': 'runSearch',
'change .filter-input-btn': 'filterByInput',
'change .filter-class-btn': 'filterByClass',
'click .reset-btn': 'clearFilters'
},
initialize: function () {
this.clearFilters();
},
render: function () {
this.$el.html(this.template({definitions : this.collection.toJSON(), infoImg : app.assetsUrl + "images/info.png"}));
// get dom element for search text box and substitute the search terms set in the filter
if (this.filter['search'] != '') {
$('.search-text').val(this.filter['search']);
}
// get the dom element that matches the values of input and dwcclass currently set as the filter
var $inputToggle = $('.filter-input-btn[value=' + this.filter['input'] + ']');
var $classToggle = $('.filter-class-btn[value=' + this.filter['dwcclass'] + ']');
$inputToggle.parent().addClass('active');
$inputToggle.prop('checked', true);
$classToggle.parent().addClass('active');
$classToggle.prop('checked', true);
// Enable all tooltips
$('[data-toggle="tooltip"]').tooltip();
return this;
},
filterByInput: function (event) {
this.filter['input'] = $(event.target).val();
this.fetchWorkflows();
},
filterByClass: function (event) {
this.filter['dwcclass'] = $(event.target).val();
this.fetchWorkflows();
},
searchKeyUp: function (event) {
if (event.which == 13) {
// enter key triggers a button click event
$('.search-btn').click();
}
},
runSearch: function (event) {
this.filter['search'] = $('.search-text').val();
this.fetchWorkflows();
},
clearFilters: function (event) {
this.filter = {
'search': '',
'input': 'any',
'dwcclass': 'any'
};
this.fetchWorkflows();
},
fetchWorkflows: function () {
this.collection = new WorkflowsCollection(this.filter['search'], this.filter['input'], this.filter['dwcclass']);
this.listenTo(this.collection, 'sync', this.render);
this.collection.fetch();
}
});
return WorkflowsView;
});