dynamic-selection-workflow.js
8.97 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
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
(function(dynworkflow, $, undefined) {
// Workflow configuration
var jsonWF = {};
var baseUrl = '';
// Main configurations: right-hand, left-hand and facial
var mainConfig = '';
// The converted Main Config (right/left-hand) to hand for using the same configuration
var preprocessedMainConfig = '';
// Subconfigurations: movimento, articulacao, configuracao, orientacao, etc
var currentSubconfig = '';
var currentSubConfigName = '';
var currentSubconfigParent = '';
var currentStep = 0;
function _preprocessMainConfig(config) {
config = config.replace('right-hand', 'hand');
config = config.replace('left-hand', 'hand');
return config;
}
function _getFirstKey(json) {
var first_key = undefined;
for (first_key in json) break;
return first_key;
}
function _getAttributes(json) {
var result = [];
for (attr in json) {
result.push(attr);
}
return result;
}
function _updateAndGetFirstMovementSubConfig() {
var selectedMovement = movement.getPreviousSelectedMovement(mainConfig);
if (typeof selectedMovement == "undefined") return -1;
currentSubconfigParent = jsonWF[preprocessedMainConfig]["movimento"][selectedMovement];
currentSubConfigName = _getFirstKey(currentSubconfigParent);
return currentSubConfigName;
}
function _updateAndGetMovementConfig() {
currentSubconfigParent = jsonWF[preprocessedMainConfig];
currentSubConfigName = _getFirstKey(currentSubconfigParent);
return currentSubConfigName;
}
function _getNextSubConfig(toForward) {
var attrs = _getAttributes(currentSubconfigParent);
for (var i = 0; i < attrs.length; i++) {
if (toForward && attrs[i] == currentSubConfigName && i < attrs.length - 1) {
return attrs[i + 1];
} else if (!toForward && attrs[i] == currentSubConfigName && i >= 1) {
return attrs[i - 1];
}
}
if (toForward && currentSubConfigName == "movimento") {
return _updateAndGetFirstMovementSubConfig();
} else if (!toForward && preprocessedMainConfig == "hand") {
return _updateAndGetMovementConfig();
} else if (!toForward) {
return currentSubConfigName;
} else {
return -1;
}
}
function _showCurrentSubconfig() {
_showSubconfiguration(mainConfig, currentSubConfigName, currentStep);
}
// It checks if a selection panel is already loaded
function _isSubconfigurationPanelLoaded(mainConfig, subConfig, stepNumber) {
var stepNumber = stepNumber + 1;
return $(".selection-panel-body[mainConfig=" + mainConfig + "][subConfig=" + subConfig +
"][step=" + stepNumber + "]").length > 0;
}
function _showLoadedSubconfigurationPanel(mainConfig, subConfig, stepNumber) {
var stepNumber = stepNumber + 1;
return $(".selection-panel-body[mainConfig=" + mainConfig + "][subConfig=" + subConfig +
"][step=" + stepNumber + "]").show();
}
// It renders or shows the requested selection panel
function _showSubconfiguration(mainConfig, subConfig, stepNumber) {
$(".selection-panel-body").hide();
if (_isSubconfigurationPanelLoaded(mainConfig, subConfig, stepNumber)) {
_showLoadedSubconfigurationPanel(mainConfig, subConfig, stepNumber);
} else {
var step = currentSubconfig[stepNumber];
step = typeof step == "undefined" ? "passo-1" : step;
dynengine.render(baseUrl, "/" + preprocessedMainConfig + "/" + subConfig +
"/" + step + ".html", "#selection-panel", true);
}
_selectTimelineIcon(mainConfig, subConfig, true);
}
function _selectSubConfig(subConfig) {
if (currentSubConfigName == "movimento") {
_updateAndGetFirstMovementSubConfig();
}
currentSubConfigName = subConfig;
currentSubconfig = currentSubconfigParent[currentSubConfigName];
currentStep = 0;
_showCurrentSubconfig();
}
// It shows the next selection panel on the workflow
function _showNextSubConfig() {
_walkOnTheWorklow(true);
}
function _showPreviousSubConfig() {
_walkOnTheWorklow(false);
}
function _walkOnTheWorklow(toForward) {
currentStep = toForward ? currentStep + 1 : currentStep - 1;
if (currentStep >= 0 && currentStep < currentSubconfig.length) {
_showCurrentSubconfig();
} else {
var nextSubConfig = _getNextSubConfig(toForward);
if (nextSubConfig != -1) {
dynworkflow.selectSubConfig(nextSubConfig);
} else {
wikilibras.hideSelectionPanel();
}
}
}
// A callback function to be called when the user selects a option on a panel
function _userSelectedAnOption() {
if (currentStep == currentSubconfig.length - 1) {
_setupCheckIcon(mainConfig, currentSubConfigName);
}
_showNextSubConfig();
}
// Timeline functions
function _selectTimelineIcon(mainConfig, subConfig) {
var icon_id = ".subconfiguration-panel[mainConfig=" + mainConfig +
"] .icon_container[json_name=" + subConfig + "]";
var previousSelected = $(".subconfiguration-panel[mainConfig=" + mainConfig
+
"] .icon_container[select=true]").attr("json_name");
if (typeof previousSelected != "undefined") {
_deselectTimelineIcon(mainConfig, previousSelected);
}
wikilibras.enableIconHover($(icon_id), true);
$(icon_id).attr("select", true);
}
function _deselectTimelineIcon(mainConfig, subConfig) {
var icon_id = ".subconfiguration-panel[mainConfig=" + mainConfig +
"] .icon_container[json_name=" + subConfig + "]";
if ($(icon_id + "[complete=true]").length > 0) {
_setupCheckIcon(mainConfig, subConfig);
} else {
wikilibras.enableIconHover($(icon_id), false);
$(icon_id).attr("select", false);
}
}
function _setupCheckIcon(mainConfig, subConfig) {
var icon_id = $(".subconfiguration-panel[mainConfig=" + mainConfig +
"] .icon_container[json_name=" + subConfig + "]");
wikilibras.enableIconCheck(icon_id, true);
$(icon_id).attr("complete", true);
$(icon_id).attr("select", false);
}
function _isTimelineLoaded() {
return $(".subconfiguration-panel[mainConfig=" + mainConfig + "]").length > 0;
}
function _setupTimelineListeners(timelineBaseId) {
$(timelineBaseId + " .icon_container[json_name]").off("click").on("click",
function() {
var subConfig = $(this).attr("json_name");
_selectSubConfig(subConfig);
});
$(timelineBaseId + " .arrow[name=right-arrow]").off("click").on("click", function() {
_showNextSubConfig();
});
$(timelineBaseId + " .arrow[name=left-arrow]").off("click").on("click", function() {
_showPreviousSubConfig();
});
}
function _setupTimelineIcons(timelineBaseId) {
$(timelineBaseId + " .icon_container[json_name]").hide();
for (var name in currentSubconfigParent) {
$(timelineBaseId + " .icon_container[json_name=" + name + "]").show();
}
if (preprocessedMainConfig == "hand") {
$(timelineBaseId + " .icon_container[json_name=movimento]").show();
_setupCheckIcon(mainConfig, "movimento");
_selectTimelineIcon(mainConfig, currentSubConfigName);
}
_setupTimelineListeners(timelineBaseId);
$(timelineBaseId).show();
}
function _setupTimeline() {
var timelineBaseId = ".subconfiguration-panel[mainConfig=" + mainConfig + "]";
if (_isTimelineLoaded()) {
$(timelineBaseId).show();
} else {
dynengine.render(baseUrl, "/" + preprocessedMainConfig +
"/timeline.html", "#selection-panel", false, function() {
_setupTimelineIcons(timelineBaseId);
});
}
}
// Public methods
dynworkflow.selectMainConfig = function(config) {
mainConfig = config;
preprocessedMainConfig = _preprocessMainConfig(mainConfig);
currentSubconfigParent = jsonWF[preprocessedMainConfig];
currentSubConfigName = _getFirstKey(currentSubconfigParent);
currentSubconfig = currentSubconfigParent[currentSubConfigName];
currentStep = 0;
_showCurrentSubconfig();
// hide the timeline on the first subconfiguration for "hand"
if (preprocessedMainConfig != "hand" || _isTimelineLoaded()) {
_setupTimeline();
}
}
dynworkflow.selectMovement = function(movement) {
var subconfigJSON = currentSubconfig[movement]
currentSubConfigName = _getFirstKey(subconfigJSON);
currentSubconfigParent = subconfigJSON;
currentSubconfig = subconfigJSON[currentSubConfigName];
currentStep = 0;
_showCurrentSubconfig();
_setupTimeline();
}
dynworkflow.selectSubConfig = function(subConfig) {
_selectSubConfig(subConfig);
}
dynworkflow.userSelectedAnOption = function() {
_userSelectedAnOption();
}
dynworkflow.getFacialParameters = function() {
return _getAttributes(jsonWF["facial"]);
}
dynworkflow.getMovementParameters = function(movementName) {
return _getAttributes(jsonWF["hand"]["movimento"][movementName]);
}
dynworkflow.load = function() {
baseUrl = $('#server-url').data('url');
$.get(baseUrl + "/conf/selection-workflow-json", function(result) {
jsonWF = $.parseJSON(result);
}).fail(function() {
console.log("Failed to load the workflow configuration");
});
}
}(window.dynworkflow = window.dynworkflow || {}, jQuery));