Newer
Older
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
/**
* Created by Helena on 02.10.2015.
*/
function createUnit() {
/* if loaded sceanrio */
// get last id number
var max = 0;
$("#stm").children("div.w").each(function() {
var id = parseInt($(this)[0].getAttribute("id").slice(-1));
if (id > max) {
max = id;
}
});
// prevent that two unit have the same id
max = max + 1;
// build unit DOM
var newState = $('<div>').attr('id', 'state' + max).addClass('w');
var title = $('<div>').addClass('title').css("padding", "0px 7px");
var stateName = $('<input>').attr('type', 'text').css("color", "#34495e");
title.append(stateName);
// add div for context information icons
var divContextIcons = $("<div>").addClass("unit-icons");
// create connection point
var ep = $('<div>').addClass('ep');
window.jsp = inst;
var windows = jsPlumb.getSelector("#stm .w");
// add elements to unit DOM
newState.append(divContextIcons);
newState.append(title);
newState.append(ep);
// add unit DOM to state machine
$('#stm').append(newState);
var nameSet = false;
// if the unit name was written and enter was clicked
stateName.keyup(function(e) {
if (e.keyCode === 13) {
// prevent unnamed units
alert("[Fehler] Bitte geben Sie einen Namen ein.\n");
return false;
}
// set unit name
$(this).parent().text(global_currentInputUnitName);
// set event listeners
activateFunctionalities(newState);
// lname := scenario name in navBar
var nameCurrentScenario = $("#lname")[0].innerText;
// add learning unit in menu bar
addUnitToMenu(nameCurrentScenario)
// update JSON structure: get new unit in its scenario
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// hide tabs because all units will be unmarked
$(".tabContents").hide();
nameSet = true;
}
// to set the source and target points, it is necessary to wait until the name was entered
// --> prevent the wrong placement of the dots
if (nameSet) {
plumbUnit(newState, ep);
nameSet = false;
}
});
// set focus on input field
stateName.focus();
}
/**
* Function loads
* Hint: The website will be new loaded.
* @param {Object} unit Contains all information about the unit
* @param {String} j Contains the running ID number
* @return {Object} Contains the unit DOM element
* */
function loadUnit(unit, j) {
window.jsp = inst;
// build unit DOM
var newState = $('<div>').attr('id', 'state' + j).addClass('w');
var title = $('<div>').addClass('title').css("padding", "0px 7px");
title.html(unit.name);
var ep = $('<div>').addClass('ep');
// add div for context information icons
var divContextIcons = $("<div>").addClass("unit-icons");
// add elements to unit DOM
newState.append(divContextIcons);
newState.append(title);
newState.append(ep);
// add unit to state machine
$('#stm').append(newState);
// get all context information
for (var k= 0; k<unit["contextInformations"].length; k++) {
var divContextIcon = $("<div>")
.addClass("unit-icon")
.attr("id", unit["contextInformations"][k]["name"] + k + "icon");
var icon = unit["contextInformations"][k]["icon"];
// add icon und div to unit
divContextIcon.append(icon);
divContextIcons.append(divContextIcon);
// get state of satisfiability
if (unit["sat"] == "all") {
divContextIcons.css("border", "2px solid #adadad");
divContextIcons.attr("ci", "all");
} else {
divContextIcons.css("border", "2px dotted #adadad");
divContextIcons.attr("ci", "one");
}
// design for icons
divContextIcons.css("border-radius", "4px");
newState.css("padding-top", "10px");
divContextIcons.css("height", "23px");
divContextIcons.css("display", "inline-block");
}
// get all meta data
for (var l= 0; l<unit["metaData"].length; l++) {
var divMetaIcon = $("<div>").addClass("unit-meta-icons").attr("id", unit["name"] + l + "metaIcon");
var metaIcon = chooseMetaIcon(unit["metaData"][l]["name"]);
divMetaIcon.attr("title", unit["metaData"][l]["name"]);
// add meta icon to unit DOM
var bMetaIcon = $("<b>").addClass(metaIcon);
divMetaIcon.append(bMetaIcon);
newState.append(divMetaIcon);
// change size of learning unit
newState.css("padding-bottom", "5px");
}
// place unit in state machine
$(newState).css("top", unit.posY + "px");
$(newState).css("left", unit.posX + "px");
plumbUnit(newState, ep);
return newState;
}
function plumbUnit(newState, ep) {
// make the unit draggable
inst.draggable(newState, {
//containment: 'parent'
containment: '.body'
});
// set target point
inst.makeTarget(newState, {
anchor: "Continuous",
dropOptions: { hoverClass: "dragHover" },
allowLoopback: false
});
// set source point
inst.makeSource(ep, {
parent: newState,
anchor: "Continuous",
connector: [ "StateMachine", { curviness: 20 } ],
connectorStyle: {
strokeStyle: "#5c96bc",
lineWidth: 2,
outlineColor: "transparent",
outlineWidth: 4
}
});
}