-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquestionnaireEditorData.js
More file actions
106 lines (83 loc) · 3.07 KB
/
questionnaireEditorData.js
File metadata and controls
106 lines (83 loc) · 3.07 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
// � by Caspar Goeke and Holger Finger
var QuestionnaireEditorData = function (expData) {
var self = this;
this.expData = expData;
this.parent = null;
// serialized
this.editorX = ko.observable(0);
this.editorY = ko.observable(0);
this.editorWidth = ko.observable(120);
this.editorHeight = ko.observable(60);
this.id = ko.observable(guid());
this.type = "QuestionnaireEditorData";
this.name = ko.observable("Questionnaire");
this.isActive = ko.observable(false);
// not serialized
this.shape = "square";
this.label = "Questionnaire";
this.portTypes = ["executeIn", "executeOut"];
// sub-Structures (serialized below)
this.elements = ko.observableArray([]).extend({ sortById: null });
this.progressBar = ko.observable(false);
this.portHandler = new PortHandler(this);
};
QuestionnaireEditorData.prototype.addNewSubElement = function (elem) {
this.elements.push(elem);
this.expData.entities.insertIfNotExist(elem);
elem.parent = this;
};
QuestionnaireEditorData.prototype.doubleClick = function () {
// this block was double clicked in the parent Experiment editor:
uc.questionnaireEditorData = this;
page("/page/editors/questionnaireEditor/" + uc.experiment.exp_id() + "/" + this.id());
};
QuestionnaireEditorData.prototype.setPointers = function (entitiesArr) {
var self = this;
// convert ids to actual pointers:
this.elements(jQuery.map(this.elements(), function (id) {
var elem = entitiesArr.byId[id];
elem.parent = self;
return elem;
}));
};
QuestionnaireEditorData.prototype.getElementById = function (id) {
return this.elements.byId[id];
};
QuestionnaireEditorData.prototype.reAddEntities = function (entitiesArr) {
var self = this;
// add the direct child nodes:
jQuery.each(this.elements(), function (index, elem) {
// check if they are not already in the list:
if (!entitiesArr.byId.hasOwnProperty(elem.id()))
entitiesArr.push(elem);
// recursively make sure that all deep tree nodes are in the entities list:
if (elem.reAddEntities)
elem.reAddEntities(entitiesArr);
});
};
QuestionnaireEditorData.prototype.fromJS = function (data) {
this.id(data.id);
this.name(data.name);
this.portHandler.fromJS(data.portHandler); // order is important: first portHandler then canvasElement!
this.editorX(data.editorX);
this.editorY(data.editorY);
this.editorWidth(data.editorWidth);
this.editorHeight(data.editorHeight);
this.isActive(data.isActive);
this.elements(data.elements);
return this;
};
QuestionnaireEditorData.prototype.toJS = function () {
return {
id: this.id(),
type: this.type,
name: this.name(),
portHandler: this.portHandler.toJS(),
editorX: this.editorX(),
editorY: this.editorY(),
editorWidth: this.editorWidth(),
editorHeight: this.editorHeight(),
isActive: this.isActive(),
elements: jQuery.map(this.elements(), function (elem) { return elem.id(); })
};
};