Steps.js
1.13 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
define(function () {
'use strict';
function Steps() {
}
Steps.prototype = {
transferToVM: function (dm) {
var current = -1, getStatus = function(condition){
try{
var regex = new RegExp("(\\w+\\s*)=(\\s*\\w+)"), m;
while((m = regex.exec(condition)) != null) {
condition = condition.replace(m[0], m[1]+"=="+m[2]);
}
return eval(condition);
}catch(e){
return false;
}
};
dm.steps.forEach(function(step, i){
if(getStatus(decodeURIComponent(step.condition)) === true) current = i;
});
return {
direction: dm.direction,
steps: dm.steps.map(function(step, i){
return {
title: step.title,
desc: step.desc,
status: current == i ? "current" : (current > i ? "finish" : "wait")
}
})
};
}
};
return Steps;
});