summaryrefslogtreecommitdiffstats
path: root/src/templates/workflow/viewport-base.html
blob: 4608ef9c0910c6a44e90ada26075a153c22ac9ac (plain)
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
{% extends "base.html" %}
{% load staticfiles %}

{% load bootstrap3 %}

{% block content %}

<style>
    .go_btn{

        position: absolute;
        width: 100px;
        top: 170px;
        height: calc(100% - 170px);

    }
    .go_btn_disabled{
            background-color: #ffffff;
    }
    .go_forward{
        right: 0px;
        border-left: none;
    }

    .go_back{
        left: 251px;
        border-right: none;
    }


    .btn_wrapper{
        text-align: center;
        margin-bottom: 5px;

    }

    {% if DEBUG %}

    .add_btn_wrapper{
        right: 130px;
        top: 10px;
        position: absolute;
    }
    {% endif %}



    .options{
        position: absolute;
        top: 60px;
        right: 20px;
    }

    #breadcrumbs {
        margin-bottom: 0;
    }

    .btn_wrapper {
        margin: 0;
    }

    .step{
        display: inline;
        padding: 7px;
        margin: 1px;
        font-size: 14pt;
        cursor: default;
    }
    .step:active {
        -webkit-box-shadow: inherit;
        box-shadow: inherit;
    }
    .step_active:active {
        -webkit-box-shadow: inherit;
        box-shadow: inherit;
    }

    .step_active{
        display: inline;
        padding: 7px;
        margin: 1px;
        cursor: default;
        font-size: 14pt;
        padding-bottom: 4px !important;
        border-bottom: 4px solid #41ba78 !important;
    }

    .step_hidden
    {
        background: #EFEFEF;
        color: #999999;
    }

    .step_invalid::after
    {
        content: " \2612";
        color: #CC3300;
    }

    .step_valid::after
    {
        content: " \2611";
        color: #41ba78;
    }

    .step_untouched::after
    {
        content: " \2610";
    }

    .iframe_div {
        width: calc(100% - 450px);
        margin-left: 70px;
        height: calc(100vh - 155px);
        position: absolute;
        border: none;
    }

    .iframe_elem {
        width: 100%;
        height: calc(100vh - 155px);
        border: none;
    }

    #breadcrumbs {
        background-color: inherit;
    }

    #breadcrumbs.breadcrumb > li {
        border: 1px solid #cccccc;
        border-left: none;
    }
    #breadcrumbs.breadcrumb > li:first-child {
        border-left: 1px solid #cccccc;
    }
    #breadcrumbs.breadcrumb > li + li:before {
        content: "";
        width: 0;
        margin: 0;
        padding: 0;
    }
</style>

<button id="gof" onclick="go('next')" class="btn go_btn go_forward">Go Forward</button>
<button id="gob" onclick="go('prev')" class="btn go_btn go_back">Go Back</button>

<div class="options">
    <button id="cancel_btn" class="btn btn-primary" onclick="cancel_wf()">Cancel</button>
</div>
<div class="btn_wrapper">
<ol id="breadcrumbs" class="btn-group breadcrumb">
</ol>
</div>
{% csrf_token %}

<script type="text/javascript">


    update_context();
    var step = 0;
    var page_count = 0;
    var context_data = false;

    function go(to)
    {
        step_on_leave();
        request_leave(to);
    }

    function request_leave(to)
    {
        $.ajax({
            type: "GET",
            url: "/wf/manager/",
            beforeSend: function(request) {
                request.setRequestHeader("X-CSRFToken",
                $('input[name="csrfmiddlewaretoken"]').val());
            },
            success: function (data) {
                confirm_permission(to, data);
                update_page(data);
            }
        });
    }

    function confirm_permission(to, data)
    {
        if( errors_exist(data) )
        {
            if( to != "prev" )
            {
                return;
            }
        }

        var problem = function() {
            alert("There was a problem");
        }
        //makes an asynch request
        req = new XMLHttpRequest();
        url = "/wf/workflow/?step=" + to;
        req.open("GET", url, true);
        req.onload = function(e) {
            if(req.readyState === 4){
                if(req.status < 300){
                    document.getElementById("viewport-iframe").srcdoc = this.responseText;
                } else { problem(); }
            } else { problem(); }
        }
        req.onerror = problem;
        req.send();
    }

    function step_on_leave()
    {
        document.getElementById("viewport-iframe").contentWindow.step_on_leave();
    }

    function errors_exist(data)
    {
        var stat = data['steps'][data['active']]['valid'];
        if( stat >= 100 && stat < 200 )
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    function update_context() {
        $.ajax({
            type: "GET",
            url: "/wf/manager/",
            beforeSend: function(request) {
                request.setRequestHeader("X-CSRFToken",
                $('input[name="csrfmiddlewaretoken"]').val());
            },
            success: function (data) {
                update_page(data);
            }
        });
    }

    function update_page(data)
    {
        context_data = data;
        update_breadcrumbs(data);
        if(data["workflow_count"] == 1)
        {
                document.getElementById("cancel_btn").innerText = "Exit Workflow";
        }
        else
        {
                document.getElementById("cancel_btn").innerText = "Return to Parent";
        }
    }

    function update_breadcrumbs(meta_json) {
        step = meta_json['active'];
        page_count = meta_json['steps'].length;
        if( step == 0 )
        {
                var btn = document.getElementById("gob");
                btn.classList.add("go_btn_disabled");
                btn.disabled = true;
        }
        else
        {
                var btn = document.getElementById("gob");
                btn.classList.remove("go_btn_disabled");
                btn.disabled = false;
        }
        if( step == page_count - 1 )
        {
                var btn = document.getElementById("gof");
                btn.classList.add("go_btn_disabled");
                btn.disabled = true;
        }
        else
        {
                var btn = document.getElementById("gof");
                btn.classList.remove("go_btn_disabled");
                btn.disabled = false;
        }
        //remove all children of breadcrumbs so we can redraw
        var container = document.getElementById("breadcrumbs");
        while(container.firstChild){
            container.removeChild(container.firstChild);
        }

        draw_steps(meta_json);
    }

    function draw_steps(meta_json){
        for( var i = 0; i < meta_json["steps"].length; i++ )
        {
            meta_json["steps"][i]["index"] = i;
            var step_btn = create_step(meta_json["steps"][i], i == meta_json["active"]);
            document.getElementById("breadcrumbs").appendChild(step_btn);
        }
    }

    function create_step(step_json, active){
        var step_dom = document.createElement("li");
        if(active){
            step_dom.className = "step_active";

        } else{
            step_dom.className = "step";
        }
        step_dom.appendChild(document.createTextNode(step_json['title']));
        var code = step_json['valid'];
        stat = "";
        msg = "";
        if( code < 100 )
        {
            step_dom.classList.add("step_untouched");

            stat = "";
            msg = "";
        }
        else if( code < 200 )
        {
            step_dom.classList.add("step_invalid");
            stat = "invalid";
            msg = step_json['message'];
        }
        else if( code < 300 )
        {
            step_dom.classList.add("step_valid");
            stat = "valid";
            msg = step_json['message'];
        }
        if( step_json['enabled'] == false )
        {
            step_dom.classList.add("step_hidden");
        }
        if(active)
        {
            update_message(msg, stat);
        }
        step_dom.classList.add("btn");

        var step_number = step_json['index'];
        return step_dom;
    }

    function cancel_wf(){
        var form = $("#workflow_pop_form");
        var formData = form.serialize();
        var req = new XMLHttpRequest();
        req.open("POST", "/wf/workflow/finish/", false);
        req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        req.onerror = function() { alert("problem occurred while trying to cancel current workflow"); }
        req.onreadystatechange = function() { if(req.readyState === 4){
            refresh_iframe();
        }};
        req.send(formData);
    }

    function refresh_iframe() {
        req = new XMLHttpRequest();
        url = "/wf/workflow/";
        req.open("GET", url, true);
        req.onload = function(e) {
            var doc = document.getElementById("viewport-iframe").contentWindow.document;
            doc.open(); doc.write(this.responseText); doc.close();
        }
        req.send();
    }

    function write_iframe(contents)
    {
        document.getElementById("viewport-iframe").contentWindow.document.innerHTML= contents;
    }

    function redirect_root()
    {
        window.location.replace('/wf/');
    }

    function add_wf(type){
        add_wf_internal(type, false);
    }

    function add_edit_wf(type, target){
        add_wf_internal(type, target);
    }

    function add_wf_internal(type, itemid){
        data = {"add": type};
        if(itemid){
            data['target'] = itemid;
        }
        $.ajax({
            type: "POST",
            url: "/wf/manager/",
            data: data,
            beforeSend: function(request) {
                request.setRequestHeader("X-CSRFToken",
                $('input[name="csrfmiddlewaretoken"]').val()
                );
            },
            success: refresh_wf_iframe()
        });
    }

    function refresh_wf_iframe() {
        window.location=window.location;
    }
</script>
<div id="iframe_header" class="row view-header">
    <div class="col-lg-12 step_header">
        <h1 class="step_title" id="view_title"></h1>
        <p class="description" id="view_desc"></p>
        <p class="step_message" id="view_message"></p>
    </div>
    <style>
        #view_desc{
            margin-bottom: 15px;
            margin-top: 5px;
            margin-left: 30px;
            display: inline;
        }
        #view_title{
            margin-top: 5px;
            margin-bottom: 0px;
            display: inline;
        }
        #view_message{
            margin-top: 10px;
            margin-bottom: 5px;
            float: right;
        }
        .message_invalid{
            color: #ff4400;
        }
        .message_valid{
            color: #44cc00;
        }
        .step_header{
            border-bottom: 1px solid #eee;
            border-top: 1px solid #eee;
            left: 101px;
            width: calc(100% - 202px);
        }
    </style>
    <script>
        function update_description(title, desc){
            document.getElementById("view_title").innerText = title;
            document.getElementById("view_desc").innerText = desc;
        }
        function update_message(message, stepstatus){
            document.getElementById("view_message").innerText = message;
            document.getElementById("view_message").className = "step_message";
            document.getElementById("view_message").classList.add("message_" + stepstatus);
        }

    </script>
    <!-- /.col-lg-12 -->
</div>
<div style="display: none;" id="workflow_pop_form_div">
<form id="workflow_pop_form" action="/wf/workflow/finish/" method="post">
    {% csrf_token %}
</form>
</div>

<div class="iframe_div">
        <iframe src="/wf/workflow" class="iframe_elem" scrolling="yes" id="viewport-iframe"></iframe>
</div>
{% endblock content %}