term-view.js
3.79 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
114
115
116
117
118
119
/*globals labels, TaxonomyTranslation, _, jQuery, WPML_core */
(function () {
TaxonomyTranslation.views.TermView = Backbone.View.extend({
tagName: 'span',
template: WPML_core[ "templates/taxonomy-translation/term-translated.html" ],
model: TaxonomyTranslation.models.Term,
popUpView: false,
needsCorrection: false,
events: {
"click .icl_tt_term_name": "openPopUpTerm"
},
initialize: function () {
var self = this;
self.listenTo(self.model, 'translationSaved', self.render);
self.listenTo(self.model, 'translationSaved', function () {
jQuery('#tax-apply').prop('disabled', false);
});
},
loadSyncData: function () {
"use strict";
var self = this;
var syncData = TaxonomyTranslation.data.syncData;
var ttid = self.model.get('term_taxonomy_id');
var parent = self.model.get('parent');
var found = false;
var needsCorrection = false;
var correctParentText = false;
var parentName = TaxonomyTranslation.classes.taxonomy.getTermName(parent);
_.each(syncData, function (correction) {
if (correction.translated_id == ttid) {
found = true;
var oldParent = '';
if (parent !== 0) {
oldParent = '<span style="background-color:#F55959;">-' + TaxonomyTranslation.classes.taxonomy.getTermName(parent) + '</span>';
jQuery('.wpml-parent-removed').show();
}
var newParent = '';
if (correction.correct_parent !== 0) {
newParent = '<span style="background-color:#CCFF99;">+' + TaxonomyTranslation.classes.taxonomy.getTermName(correction.correct_parent) + '</span>';
jQuery('.wpml-parent-added').show();
}
parentName = oldParent + ' ' + newParent;
needsCorrection = true;
}
});
if (needsCorrection === true) {
self.template = WPML_core[ 'templates/taxonomy-translation/term-not-synced.html' ];
} else {
self.template = WPML_core[ 'templates/taxonomy-translation/term-synced.html' ];
}
self.$el.html(
self.template({
trid: self.model.get("trid"),
lang: self.model.get("language_code"),
name: self.model.get("name"),
level: self.model.get("level"),
correctedLevel: self.model.get("level"),
correctParent: correctParentText,
parent: parentName
})
);
self.needsCorrection = needsCorrection;
return self;
},
render: function () {
var self = this;
self.needsCorrection = false;
if ( ! self.model.get( "name" ) ) {
self.template = WPML_core[ "templates/taxonomy-translation/term-not-translated.html" ];
} else if ( self.model.isOriginal() ) {
self.template = WPML_core[ "templates/taxonomy-translation/term-original-disabled.html" ];
} else {
self.template = WPML_core[ "templates/taxonomy-translation/term-translated.html" ];
}
var html = self.template({
trid: self.model.get("trid"),
lang: self.model.get("language_code"),
name: self.model.get("name"),
level: self.model.get("level"),
correctedLevel: self.model.get("level"),
langs: TaxonomyTranslation.data.activeLanguages
});
self.$el.html( html );
return self;
},
openPopUpTerm: function (e) {
var self = this;
e.preventDefault();
var trid = self.model.get("trid");
var lang = self.model.get("language_code");
if (trid && lang) {
if (TaxonomyTranslation.classes.termPopUpView && typeof TaxonomyTranslation.classes.termPopUpView !== 'undefined') {
TaxonomyTranslation.classes.termPopUpView.close();
}
if ( self.model.isOriginal() ) {
TaxonomyTranslation.classes.termPopUpView = new TaxonomyTranslation.views.OriginalTermPopUpView( { model: self.model } );
} else {
TaxonomyTranslation.classes.termPopUpView = new TaxonomyTranslation.views.TermPopUpView( { model: self.model } );
}
TaxonomyTranslation.classes.termPopUpView.open( trid, lang );
}
}
});
})(TaxonomyTranslation);