dynamic-selection-workflow.js
3.24 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
(function(dynworkflow, $, undefined) {
var jsonWF = {};
var baseUrl = "";
var mainConfig = "";
var currentSubconfigParent = "";
var currentSubconfig = "";
var currentSubConfigName = "";
var currentStep = 0;
function _preprocessConfig(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 _getNextSubConfig() {
var attrs = _getAttributes(currentSubconfigParent);
for (var i = 0; i < attrs.length; i++) {
if (attrs[i] == currentSubConfigName && i < attrs.length - 1) {
return attrs[i+1];
}
}
return -1;
}
function _showCurrentSubconfig() {
_showSubconfiguration(currentSubConfigName, currentSubconfig[currentStep]);
}
function _showSubconfiguration(subconfig, step) {
var step = typeof step == "undefined" ? "passo-1" : step;
$(".selection-panel-body").hide();
dynengine.render(baseUrl, "/" + mainConfig + "/" + subconfig +
"/" + step + ".html", "#selection-panel", true);
}
dynworkflow.selectMainConfig = function(config) {
mainConfig = _preprocessConfig(config);
currentSubConfigName = _getFirstKey(jsonWF[mainConfig]);
currentSubconfig = jsonWF[mainConfig][currentSubConfigName];
currentSubconfigParent = jsonWF[mainConfig];
currentStep = 0;
_showCurrentSubconfig();
}
dynworkflow.selectMovement = function(movement) {
var subconfigJSON = currentSubconfig[movement]
currentSubConfigName = _getFirstKey(subconfigJSON);
currentSubconfigParent = subconfigJSON;
currentSubconfig = subconfigJSON[currentSubConfigName];
currentStep = 0;
_showCurrentSubconfig();
}
dynworkflow.selectSubConfig = function(config) {
currentSubConfigName = config;
currentSubconfig = currentSubconfigParent[currentSubConfigName];
currentStep = 0;
_showCurrentSubconfig();
}
dynworkflow.nextSubConfig = function() {
currentStep = currentStep + 1;
if (currentStep < currentSubconfig.length) {
_showCurrentSubconfig();
} else {
var nextSubConfig = _getNextSubConfig();
if (nextSubConfig != -1) {
dynworkflow.selectSubConfig(nextSubConfig);
} else {
wikilibras.hideSelectionPanel();
}
}
}
dynworkflow.setupTimeline = function() {
dynengine.render(baseUrl, "/" + mainConfig + "/timeline.html", "#selection-panel", false, function() {
$(".subconfiguration-options .icon_container").hide();
for (var name in currentSubconfigParent) {
$(".subconfiguration-options .icon_container[json_name=" + name + "]").show();
}
if (mainConfig == "hand") {
$(".subconfiguration-options .icon_container[json_name=movimento]").show();
}
$(".subconfiguration-panel").show();
});
}
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));