1 {% extends "base.html" %}
14 height: calc(100% - 170px);
18 background-color: #ffffff;
89 height: calc(100vh - 450);
95 <button id="gof" onclick="go(step+1)" class="btn go_btn go_forward">Go Forward</button>
96 <button id="gob" onclick="go(step-1)" class="btn btn go_btn go_back">Go Back</button>
99 <button id="cancel_btn" class="btn" onclick="cancel_wf()">Cancel</button>
101 <div class="btn_wrapper">
102 <div id="breadcrumbs" class="btn-group">
103 <div class="btn-group" id="breadcrumb-wrapper">
109 <script type="text/javascript">
115 var context_data = false;
123 function request_leave(to)
128 beforeSend: function(request) {
129 request.setRequestHeader("X-CSRFToken",
130 $('input[name="csrfmiddlewaretoken"]').val());
132 success: function (data) {
133 confirm_permission(to, data);
139 function confirm_permission(to, data)
141 if( errors_exist(data) )
143 var continueanyway = confirm("The current step has errors that will prevent it from saving. Continue anyway?");
144 if( !continueanyway )
149 if( to >= page_count )
157 var problem = function() {
158 alert("There was a problem");
160 //makes an asynch request
161 req = new XMLHttpRequest();
162 url = "/wf/workflow/?step=" + to;
163 req.open("GET", url, true);
164 req.onload = function(e) {
165 if(req.readyState === 4){
166 if(req.status < 300){
167 document.getElementById("viewport-iframe").srcdoc = this.responseText;
168 } else { problem(); }
169 } else { problem(); }
171 req.onerror = problem;
175 function step_on_leave()
177 document.getElementById("viewport-iframe").contentWindow.step_on_leave();
180 function errors_exist(data)
182 var stat = data['steps'][data['active']]['valid'];
183 if( stat >= 100 && stat < 200 )
193 function update_context() {
197 beforeSend: function(request) {
198 request.setRequestHeader("X-CSRFToken",
199 $('input[name="csrfmiddlewaretoken"]').val());
201 success: function (data) {
207 function update_page(data)
210 update_breadcrumbs(data);
211 if(data["workflow_count"] == 1)
213 document.getElementById("cancel_btn").innerText = "Exit Workflow";
217 document.getElementById("cancel_btn").innerText = "Return to Parent";
221 function update_breadcrumbs(meta_json) {
222 step = meta_json['active'];
223 page_count = meta_json['steps'].length;
226 var btn = document.getElementById("gob");
227 btn.classList.add("go_btn_disabled");
232 var btn = document.getElementById("gob");
233 btn.classList.remove("go_btn_disabled");
234 btn.disabled = false;
236 if( step == page_count - 1 )
238 var btn = document.getElementById("gof");
239 btn.classList.add("go_btn_disabled");
244 var btn = document.getElementById("gof");
245 btn.classList.remove("go_btn_disabled");
246 btn.disabled = false;
248 //remove all children of breadcrumbs so we can redraw
249 var container = document.getElementById("breadcrumbs");
250 while(container.firstChild){
251 container.removeChild(container.firstChild);
254 draw_steps(meta_json);
257 function draw_steps(meta_json){
258 for( var i = 0; i < meta_json["steps"].length; i++ )
260 meta_json["steps"][i]["index"] = i;
261 var step_btn = create_step(meta_json["steps"][i], i == meta_json["active"]);
262 document.getElementById("breadcrumbs").appendChild(step_btn);
266 function create_step(step_json, active){
267 var step_dom = document.createElement("DIV");
269 step_dom.className = "step_active";
272 step_dom.className = "step";
274 step_dom.appendChild(document.createTextNode(step_json['title']));
275 var code = step_json['valid'];
280 step_dom.classList.add("step_untouched");
285 else if( code < 200 )
287 step_dom.classList.add("step_invalid");
289 msg = step_json['message'];
291 else if( code < 300 )
293 step_dom.classList.add("step_valid");
295 msg = step_json['message'];
299 update_message(msg, stat);
301 step_dom.classList.add("btn");
303 var step_number = step_json['index'];
304 step_dom.onclick = function(){ go(step_number); }
308 function cancel_wf(){
309 var form = $("#workflow_pop_form");
310 var formData = form.serialize();
311 var req = new XMLHttpRequest();
312 req.open("POST", "/wf/workflow/finish/", false);
313 req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
314 req.onerror = function() { alert("problem occurred while trying to cancel current workflow"); }
315 req.onreadystatechange = function() { if(req.readyState === 4){
321 function refresh_iframe() {
322 req = new XMLHttpRequest();
323 url = "/wf/workflow/";
324 req.open("GET", url, true);
325 req.onload = function(e) {
326 var doc = document.getElementById("viewport-iframe").contentWindow.document;
327 doc.open(); doc.write(this.responseText); doc.close();
332 function write_iframe(contents)
334 document.getElementById("viewport-iframe").contentWindow.document.innerHTML= contents;
337 function redirect_root()
339 window.location.replace('/wf/');
342 function add_wf(type){
343 add_wf_internal(type, false);
346 function add_edit_wf(type, target){
347 add_wf_internal(type, target);
350 function add_wf_internal(type, itemid){
351 data = {"add": type};
353 data['target'] = itemid;
359 beforeSend: function(request) {
360 request.setRequestHeader("X-CSRFToken",
361 $('input[name="csrfmiddlewaretoken"]').val()
364 success: refresh_wf_iframe()
368 function refresh_wf_iframe() {
369 window.location=window.location;
372 <div id="iframe_header" class="row view-header">
373 <div class="col-lg-12 step_header">
374 <h1 class="step_title" id="view_title"></h1>
375 <p class="description" id="view_desc"></p>
376 <p class="step_message" id="view_message"></p>
402 border-bottom: 1px solid #eee;
403 border-top: 1px solid #eee;
405 width: calc(100% - 202px);
409 function update_description(title, desc){
410 document.getElementById("view_title").innerText = title;
411 document.getElementById("view_desc").innerText = desc;
413 function update_message(message, stepstatus){
414 document.getElementById("view_message").innerText = message;
415 document.getElementById("view_message").className = "step_message";
416 document.getElementById("view_message").classList.add("message_" + stepstatus);
418 function resize_iframe(){
419 var page_rect = document.getElementById("wrapper").getBoundingClientRect();
420 var title_rect = document.getElementById("iframe_header").getBoundingClientRect();
421 var iframe_height = page_rect.bottom - title_rect.bottom;
422 console.log("setting height to " + iframe_height);
423 document.getElementById("viewport-iframe").height = iframe_height;
426 window.addEventListener('load', resize_iframe);
427 window.addEventListener('resize', resize_iframe);
431 <div style="display: none;" id="workflow_pop_form_div">
432 <form id="workflow_pop_form" action="/wf/workflow/finish/" method="post">
437 <iframe src="/wf/workflow" style="position: absolute; left: 351px; right: 105px; width: calc(100% - 450px); border-style: none; border-width: 1px; border-color: #888888;" scrolling="yes" id="viewport-iframe" onload="resize_iframe();"></iframe>
438 {% endblock content %}