File: base.html

package info (click to toggle)
coreschema 0.0.4-2~bpo9%2B1
  • links: PTS, VCS
  • area: main
  • in suites: stretch-backports
  • size: 176 kB
  • sloc: python: 743; makefile: 3
file content (161 lines) | stat: -rw-r--r-- 6,451 bytes parent folder | download | duplicates (3)
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

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../../favicon.ico">

    <title>Theme Template for Bootstrap</title>

    <!-- Bootstrap core CSS -->
    <link href="../../dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Bootstrap theme -->
    <link href="../../dist/css/bootstrap-theme.min.css" rel="stylesheet">
    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <link href="../../assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="theme.css" rel="stylesheet">
    <link href="chosen.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->

    <style>
        .checkbox label.control-label {font-weight: bold}
        body {padding-top: 0}
    </style>
  </head>

  <body>
    <div class="container col-md-4 col-md-offset-4" role="main">
        <h1>CoreSchema</h1>
        <form id="coreschema" novalidate>
            {% for key, schema in parent.properties.items() %}
                {% set template_path = determine_html_template(schema) %}
                {% set required = key in parent.required %}
                {% include template_path %}
            {% endfor %}
        </form>
        <pre>
        </pre>
    </div> <!-- /container -->


    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="../../assets/js/vendor/jquery.min.js"></script>
    <script src="../../dist/js/bootstrap.min.js"></script>
    <script src="../../assets/js/docs.min.js"></script>
    <script src="chosen.jquery.js"></script>
    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <script src="../../assets/js/ie10-viewport-bug-workaround.js"></script>
    <script>
        const options = {
            placeholder_text_single: '',
            placeholder_text_multiple: '',
            allow_single_deselect: true
        }
        $('select').chosen(options)

        $('#coreschema :input').on('input propertychange', function() {
            const form = $(this).closest('form')
            formToData(form)
        })
        $('#coreschema :input').change(function() {
            const form = $(this).closest('form')
            formToData(form)
        })

        function formToData(form) {
            const formData = new FormData(form.get()[0])
            var params = new Map()
            var errors = []
            var inputElements = {}

            // Initially iterate through all the inputs
            form.find(':input').each(function(key, value) {
                var elem = $(this)
                var name = elem.attr('name')
                if (name !== undefined) {
                    inputElements[name] = elem
                    var emptyValue = elem.data('empty')
                    if (emptyValue !== undefined) {
                        params[name] = emptyValue
                    }
                }
            })

            // Now iterate through all the supplied form values
            for (let [paramKey, paramValue] of formData.entries()) {
                let inputElement = inputElements[paramKey]
                let dataType = inputElement.data('type')
                try {
                    if (!inputElement[0].checkValidity()) {
                        // Invalid inputs return paramValue of '',
                        // so we need to differentiate between that
                        // and an actually empty input
                        throw Error()
                    } else if (dataType === 'integer') {
                        if (!paramValue) {
                            params[paramKey] = null
                        } else {
                            if (paramValue.includes('.')) {
                                throw Error()
                            }
                            paramValue = parseInt(paramValue)
                            if (paramValue != paramValue) {
                                throw Error()
                            }
                            params[paramKey] = paramValue
                        }
                    } else if (dataType === 'number') {
                        if (!paramValue) {
                            params[paramKey] = null
                        } else {
                            paramValue = parseFloat(paramValue)
                            if (paramValue != paramValue) {
                                throw Error()
                            }
                            params[paramKey] = paramValue
                        }
                    } else if (dataType === 'boolean') {
                        params[paramKey] = true
                    } else if (dataType === 'array') {
                        if (inputElement.is('select')) {
                            params[paramKey] = params[paramKey].concat([paramValue])
                        } else {
                            params[paramKey] = JSON.parse(paramValue)
                        }
                    } else if (dataType === 'object') {
                        params[paramKey] = JSON.parse(paramValue)
                    } else {
                        params[paramKey] = paramValue
                    }
                } catch(e) {
                    errors.push(paramKey)
                }
            }

            form.find('.form-group').removeClass('has-error')
            for (let name of errors) {
                let inputElement = inputElements[name]
                let formGroup = inputElement.closest('.form-group')
                formGroup.addClass('has-error')
            }

            const text = JSON.stringify(params, null, 2)
            form.next('pre').text(text)
        }
    </script>
  </body>
</html>