term-rows-view.js
3.13 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
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
(function () {
TaxonomyTranslation.views.TermRowsView = Backbone.View.extend({
tagName: 'tbody',
collection: TaxonomyTranslation.data.termRowsCollection,
rowViews: [],
start: 0,
end: 10,
count: -1,
initialize: function (data, options) {
var self = this;
self.end = options.end;
self.start = options.start;
},
getDisplayedRows: function () {
var self = this;
var displayedRows = self.collection;
if (!displayedRows) {
self.count = -1;
return false;
}
if (TaxonomyTranslation.mainView.mode === 'sync') {
displayedRows = displayedRows.filter(function (row) {
"use strict";
return row.unSyncFilter();
});
}
var parentFilter = TaxonomyTranslation.mainView.filterView.parent ? TaxonomyTranslation.mainView.filterView.parent : false;
if (parentFilter) {
displayedRows = displayedRows.filter(function (row) {
return row.parentOf(parentFilter);
});
}
var untranslatedFilter = TaxonomyTranslation.mainView.filterView.untranslated ? TaxonomyTranslation.mainView.filterView.untranslated : false;
if (untranslatedFilter) {
displayedRows = displayedRows.filter(function (row) {
return !row.allTermsTranslated();
});
}
var langFilter = TaxonomyTranslation.mainView.filterView.lang && TaxonomyTranslation.mainView.filterView.lang !== 'all' ? TaxonomyTranslation.mainView.filterView.lang : false;
if (langFilter && langFilter != 'all' && (untranslatedFilter || parentFilter)) {
displayedRows = displayedRows.filter(function (row) {
return !row.translatedIn(langFilter);
});
}
var searchFilter = false;
if (TaxonomyTranslation.mainView.filterView.search && TaxonomyTranslation.mainView.filterView.search !== '') {
searchFilter = TaxonomyTranslation.mainView.filterView.search;
}
if (searchFilter) {
displayedRows = displayedRows.filter(function (row) {
if (langFilter && langFilter !== 'all') {
return row.matchesInLang(searchFilter, langFilter);
} else {
return row.matches(searchFilter);
}
});
}
self.count = displayedRows.length;
return displayedRows;
},
getDisplayCount: function(){
return this.count;
},
render: function () {
var self = this,
output = document.createDocumentFragment(),
displayedRows = self.getDisplayedRows();
self.rowViews = [];
if ( displayedRows && displayedRows.length > 0 ) {
displayedRows = displayedRows.slice(self.start, self.end);
displayedRows.forEach(function (row) {
var newView = new TaxonomyTranslation.views.TermRowView({model: row });
self.rowViews.push(newView);
output.appendChild(newView.render().el);
newView.delegateEvents();
});
self.$el.html(output);
} else {
var taxonomy = TaxonomyTranslation.classes.taxonomy.get("taxonomy"),
taxonomyPluralLabel = TaxonomyTranslation.data.taxonomies[taxonomy].label,
message = labels.noTermsFound.replace( '%taxonomy%', taxonomyPluralLabel );
self.$el.html(
WPML_core[ 'templates/taxonomy-translation/no-terms-found.html' ] ({
message: message
})
);
}
return self;
}
});
})(TaxonomyTranslation);