aboutsummaryrefslogtreecommitdiffstats
path: root/web/js/nms-template.js
blob: 0f25367cb7977da601e7ad891ab057126d2a6c78 (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
"use strict";

var nmsTemplate = nmsTemplate || {
}

nmsTemplate.test = function() {
        var input = document.getElementById("template-input");
        var output = document.getElementById("template-output");
        var qp = document.getElementById("template-query-params");
        $.ajax({
                type: "POST",
                url: "/api/templates/test" + qp.value,
                async: false,
                data: input.value,
                dataType: "text",
                success: function (indata, textStatus, jqXHR) {
                        var output = document.getElementById("template-output");
                        output.value = jqXHR.responseText;
                },
                error: function (jqXHR, textStatus) {
                        var output = document.getElementById("template-output");
                        output.value = jqXHR.responseText;
                }
        });
}

nmsTemplate.fromFile = function(template) {
        if(template == '') { return; }
        $.ajax({
                type: "GET",
                url: "/templates/" + template,
                async: false,
                dataType: "text",
                success: function (indata, textStatus, jqXHR) {
                        var output = document.getElementById("template-input");
                        output.value = indata;
                }
        });
        nmsTemplate.test();
}

nmsTemplate.getTemplates = function() {
        $.ajax({
                type: "GET",
                url: "/api/read/template-list",
                async: false,
                dataType: "json",
                success: function (indata, textStatus, jqXHR) {
                        $.each( indata['templates'], function( value ) {
                                $('#nmsTemplate-select').append($("<option></option>").attr("value",indata['templates'][value]['file']).text(indata['templates'][value]['file']));
                        });
                }
        });
}
//nmsTemplate.getTemplates();