-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtranslationEntry.js
More file actions
40 lines (33 loc) · 1.16 KB
/
translationEntry.js
File metadata and controls
40 lines (33 loc) · 1.16 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
var TranslationEntry = function (expData) {
var self = this;
this.expData = expData;
this.namedEntity = null;
this.languages = ko.observableArray([]);
};
TranslationEntry.prototype.init = function (namedEntity) {
this.namedEntity = namedEntity;
};
TranslationEntry.prototype.addTranslation = function (translation) {
this.languages.push(translation);
};
TranslationEntry.prototype.setPointers = function (entitiesArr) {
if (this.namedEntity) {
this.namedEntity = entitiesArr.byId[this.namedEntity];
}
};
TranslationEntry.prototype.toJS = function () {
return {
namedEntity: this.namedEntity ? this.namedEntity.id() : null,
languages: jQuery.map(this.languages(), function (elem) {
return [elem()]; // use array so that null values are not removed
})
};
};
TranslationEntry.prototype.fromJS = function (data) {
this.namedEntity = data.namedEntity;
var purify_config = { ADD_TAGS: ['vars'], ADD_ATTR: ['globvarid'] };
this.languages(jQuery.map(data.languages, function (elem) {
var clean = DOMPurify.sanitize(elem, purify_config);
return ko.observable(clean);
}));
};