File: upload.html

package info (click to toggle)
json-editor.js 1.3.2%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 1,692 kB
  • sloc: perl: 39; makefile: 5
file content (121 lines) | stat: -rw-r--r-- 3,194 bytes parent folder | download | duplicates (2)
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
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>JSON Editor Upload Example</title>
    <script src="../../../javascript/json-editor/jsoneditor.min.js"></script>
  </head>
  <body>
    <h1>JSON Editor Upload Example</h1>
    
    <div id='editor_holder'></div>
    <button id='submit'>Submit (console.log)</button>
    
    <script>
      // Specify theme
      JSONEditor.defaults.options.theme = 'html';

      // Specify upload handler
      JSONEditor.defaults.options.upload = function(type, file, cbs) {
        if (type === 'root.upload_fail') cbs.failure('Upload failed');
        else {
          var tick = 0;

          var tickFunction = function() {
            tick += 1;
            console.log('progress: ' + tick);

            if (tick < 100) {
              cbs.updateProgress(tick);
              window.setTimeout(tickFunction, 50)
            } else if (tick == 100) {
              cbs.updateProgress();
              window.setTimeout(tickFunction, 500)
            } else {
              cbs.success('http://www.example.com/images/' + file.name);
            }
          };

          window.setTimeout(tickFunction)
        }
      };

      // Initialize the editor with a JSON schema
      var editor = new JSONEditor(document.getElementById('editor_holder'),{
        schema: {
          type: "object",
          title: "Image",
          properties: {
            upload_default: {
              type: "string",
              format: "url",
              options: {
                upload: true
              },
              "links": [
                {
                    "href": "{{self}}"
                }
              ]
            },
            upload_custom_link: {
              type: "string",
              format: "url",
              options: {
                upload: true
              },
              "links": [
                {
                  "href": "{{self}}",
                  "rel": "view"
                }
              ]
            },
            upload_readonly: {
              readonly: true,
              type: "string",
              format: "url",
              options: {
                upload: true
              },
              "links": [
                {
                  "href": "{{self}}"
                }
              ]
            },
            upload_fail: {
              type: "string",
              format: "url",
              options: {
                upload: true
              },
              "links": [
                {
                  "href": "{{self}}"
                }
              ]
            },
            name: {
              type: "string"
            }
          }
        }
      });

      editor.setValue({
        upload_default: "",
        upload_custom_link: "",
        upload_readonly: "http://www.example.com/images/image.jpg",
        upload_fail: "",
        name: ""
      });
      
      // Hook up the submit button to log to the console
      document.getElementById('submit').addEventListener('click',function() {
        // Get the value from the editor
        console.log(editor.getValue());
      });
    </script>
  </body>
</html>