2 // JavaScript for mason/util/workflow.mas
5 "init": function(init_target){ //Initializes a workflow with a given ID
6 var wf = document.querySelector(init_target);
7 var prog_steps = document.querySelectorAll(init_target+'>.workflow-prog>li');
8 prog_steps.forEach(function(ele,i){
9 ele.onclick = Workflow.prog_click(i);
14 "prog_click": function(step_index){ // onclick for progress markers
15 //on progress marker click, change the focus to show that page
18 while (!wf.classList.contains('workflow')){
22 //if the previous workflows have not been complete, do not do anything!
23 if (!this.classList.contains('workflow-complete')
24 && this!==wf.querySelector('.workflow-prog>li:not(.workflow-complete)')){
28 //change focus and check for completion
29 Workflow.focus(wf,step_index);
30 Workflow.check_complete(wf);
35 "focus":function(wf,step_index){ // changes workflow focus page
36 wf = wf instanceof Element ? wf : document.querySelector(wf);
37 function change_focus(ele,i){
39 ele.classList.add('workflow-focus');
41 ele.classList.remove('workflow-focus');
46 var progs = wf.querySelectorAll('.workflow-prog>li');
47 var conts = wf.querySelectorAll('.workflow-content>li');
49 progs.forEach(change_focus);
50 conts.forEach(change_focus);
53 "check_complete":function(wf){ // checks if the endscreens should be shown and acts accordingly
54 wf = wf instanceof Element ? wf : document.querySelector(wf);
55 var progs = wf.querySelectorAll('.workflow-prog>li');
56 var conts = wf.querySelectorAll('.workflow-content>li');
58 var all_complete = Array.prototype.every.call(progs, function(ele){
59 return ele.classList.contains('workflow-complete');
61 var any_pending = Array.prototype.some.call(progs, function(ele){
62 return ele.classList.contains('workflow-pending');
64 var any_focused = Array.prototype.some.call(progs, function(ele){
65 return ele.classList.contains('workflow-focus');
68 if(all_complete && any_pending && !any_focused){
69 wf.querySelector(".workflow-pending-message").classList.add("workflow-message-show");
71 else if (all_complete && !any_focused){
72 wf.querySelector(".workflow-pending-message").classList.remove("workflow-message-show");
73 wf.querySelector(".workflow-complete-message").classList.add("workflow-message-show");
75 wf.querySelector(".workflow-pending-message").classList.remove("workflow-message-show");
76 wf.querySelector(".workflow-complete-message").classList.remove("workflow-message-show");
80 "complete":function(wf_child,set_focus,status){ // completes a step
81 set_focus = set_focus===false?false:true;
82 wf_child = wf_child instanceof Element ? wf_child : document.querySelector(wf_child);
84 var content_li = wf_child;
85 while (!wf.classList.contains('workflow')){
86 if(wf.parentNode.classList.contains('workflow-content')){
91 var step_index = Array.prototype.indexOf.call(wf.querySelectorAll('.workflow-content>li'),content_li);
92 var all_steps = wf.querySelectorAll('.workflow-prog>li');
93 var prog = all_steps[step_index];
95 content_li.classList.add('workflow-complete');
96 prog.classList.add('workflow-complete');
99 if (status=="skipped"){
100 content_li.classList.add('workflow-skipped');
101 prog.classList.add('workflow-skipped');
104 content_li.classList.remove('workflow-skipped');
105 prog.classList.remove('workflow-skipped');
108 if (status=="pending"){
109 content_li.classList.add('workflow-pending');
110 prog.classList.add('workflow-pending');
113 content_li.classList.remove('workflow-pending');
114 prog.classList.remove('workflow-pending');
118 Workflow.focus(wf,step_index+1);
120 Workflow.check_complete(wf);
124 "skip":function(wf_child,set_focus){ //completes a step with skipped status
125 Workflow.complete(wf_child,set_focus,"skipped");
128 "pending":function(wf_child,set_focus){ //completes a step with pending status
129 Workflow.complete(wf_child,set_focus,"pending");