|
10 | 10 | schema: {{ schema|json_dumps }}
|
11 | 11 | };
|
12 | 12 |
|
13 |
| - var {{ name }}_editor; |
| 13 | + var {{ js_name }}_editor; |
14 | 14 |
|
15 |
| - var {{ name }}_changees = 0; |
| 15 | + var {{ js_name }}_changees = 0; |
16 | 16 |
|
17 |
| - function {{ name }}_init(container, options) { |
18 |
| - {{ name }}_changees = 0; |
| 17 | + function {{ js_name }}_init(container, options) { |
| 18 | + {{ js_name }}_changees = 0; |
19 | 19 | JSONEditor.defaults.options = {{ default_options|json_dumps }};
|
20 |
| - {{ name }}_editor = new JSONEditor(container, options); |
| 20 | + {{ js_name }}_editor = new JSONEditor(container, options); |
21 | 21 | JSONEditor.plugins.sceditor.emoticonsEnabled = {{ sceditor }};
|
22 |
| - {{ name }}_editor.on('change', function () { |
23 |
| - {{ name }}_changees ++; |
24 |
| - var errors = {{ name }}_editor.validate(); |
| 22 | + {{ js_name }}_editor.on('change', function () { |
| 23 | + {{ js_name }}_changees ++; |
| 24 | + var errors = {{ js_name }}_editor.validate(); |
25 | 25 | if (errors.length) {
|
26 | 26 | console.log(errors);
|
27 | 27 | }
|
28 | 28 | else {
|
29 |
| - var json = {{ name }}_editor.getValue(); |
| 29 | + var json = {{ js_name }}_editor.getValue(); |
30 | 30 | document.getElementById("id_{{ name }}").value = JSON.stringify(json);
|
31 | 31 | }
|
32 | 32 | });
|
33 | 33 | }
|
34 | 34 |
|
35 |
| - {{ name }}_init(container, options); |
| 35 | + {{ js_name }}_init(container, options); |
36 | 36 |
|
37 | 37 | {% if data %}
|
38 | 38 | var initial_json = {{ data|safe }};
|
39 | 39 | if (initial_json !== null) {
|
40 |
| - {{ name }}_editor.setValue(initial_json); |
| 40 | + {{ js_name }}_editor.setValue(initial_json); |
41 | 41 | }
|
42 | 42 | {% endif %}
|
43 | 43 |
|
44 | 44 | {% if schema_choice_field_name and schema_choices %}
|
45 | 45 | var schema_choices = {{ schema_choices|json_dumps }};
|
46 |
| - let ${{ schema_choice_field_name }}_{{ name }} = $('#id_{{ schema_choice_field_name }}'); |
47 |
| - if ( ${{ schema_choice_field_name }}_{{ name }}.length ) { |
48 |
| - $.data(${{ schema_choice_field_name }}_{{ name }}, "current", ${{ schema_choice_field_name }}_{{ name }}.val()); // store the current value |
| 46 | + let ${{ schema_choice_field_name }}_{{ js_name }} = $('#id_{{ schema_choice_field_name }}'); |
| 47 | + if ( ${{ schema_choice_field_name }}_{{ js_name }}.length ) { |
| 48 | + $.data(${{ schema_choice_field_name }}_{{ js_name }}, "current", ${{ schema_choice_field_name }}_{{ js_name }}.val()); // store the current value |
49 | 49 |
|
50 |
| - ${{ schema_choice_field_name }}_{{ name }}.change(function(event) { |
| 50 | + ${{ schema_choice_field_name }}_{{ js_name }}.change(function(event) { |
51 | 51 | let changeSchema = true;
|
52 |
| - if ({{ name }}_changees > 1) { |
| 52 | + if ({{ js_name }}_changees > 1) { |
53 | 53 | // only fire this alert if we have made changes.
|
54 | 54 | changeSchema = confirm("Changing '{{ schema_choice_field_name }}' will clear any data in '{{ name }}'. Do you still want to change '{{ schema_choice_field_name }}'?");
|
55 | 55 | }
|
|
63 | 63 | iconlib: "fontawesome4",
|
64 | 64 | schema: schemaToSet
|
65 | 65 | };
|
66 |
| - if ({{ name }}_editor) { |
67 |
| - {{ name }}_editor.destroy(); |
| 66 | + if ({{ js_name }}_editor) { |
| 67 | + {{ js_name }}_editor.destroy(); |
68 | 68 | }
|
69 |
| - {{ name }}_init(container, newOptions); |
70 |
| - $.data(${{ schema_choice_field_name }}_{{ name }}, "current", ${{ schema_choice_field_name }}_{{ name }}.val()); // update current value |
| 69 | + {{ js_name }}_init(container, newOptions); |
| 70 | + $.data(${{ schema_choice_field_name }}_{{ js_name }}, "current", ${{ schema_choice_field_name }}_{{ js_name }}.val()); // update current value |
71 | 71 | } else {
|
72 | 72 | // undo the category change
|
73 |
| - ${{ schema_choice_field_name }}_{{ name }}.val( $.data(${{ schema_choice_field_name }}_{{ name }}, "current")); // rollback to the old value |
| 73 | + ${{ schema_choice_field_name }}_{{ js_name }}.val( $.data(${{ schema_choice_field_name }}_{{ js_name }}, "current")); // rollback to the old value |
74 | 74 | event.preventDefault();
|
75 | 75 |
|
76 | 76 | }
|
|
0 commit comments