|
1 | 1 | {% load static %} |
2 | 2 |
|
3 | | -<style> |
4 | | - .form-block { |
5 | | - margin-left: 170px; |
6 | | - } |
7 | | - |
8 | | - .jsonwidgetbutton { |
9 | | - padding: 10px 15px; |
10 | | - } |
11 | | - |
12 | | - .cursor { |
13 | | - cursor: pointer; |
14 | | - } |
15 | | -</style> |
| 3 | +<link rel="stylesheet" type="text/css" href="{% static 'json_model_widget/css/styles.css' %}"> |
16 | 4 |
|
17 | 5 | <div class="form-block"> |
18 | | - |
19 | 6 | <div id="fieldjson"> |
20 | 7 | {% for k,v in json.items %} |
21 | | - <p id="jsonrow{{ name }}{{ forloop.counter }}"> |
22 | | - <select name="jsonkey{{ name }}"> |
23 | | - {% for pair in col1 %} |
24 | | - <option value="{{ pair.id }}" |
25 | | - {% if pair.id== k|add: |
26 | | - "0" %}selected{% endif %}>{{ pair }}</option> |
27 | | - {% endfor %} |
28 | | - </select> |
29 | | - <select name="jsonvalue{{ name }}"> |
30 | | - {% for pair in col2 %} |
31 | | - <option value="{{ pair.id }}" {% if pair.id== v %}selected{% endif %}>{{ pair }}</option> |
32 | | - {% endfor %} |
33 | | - </select> |
34 | | - <img class="delete-row-button cursor" src="{% static 'json_model_widget/images/icon-deletepair.svg' %}" |
35 | | - alt="False"> |
36 | | - </p> |
37 | | - |
| 8 | + <p id="jsonrow{{ name }}{{ forloop.counter }}"> |
| 9 | + <select name="jsonkey{{ name }}"> |
| 10 | + {% for pair in col1 %} |
| 11 | + <option value="{{ pair.id }}" {% if pair.id == k|add:0 %}selected{% endif %}>{{ pair }}</option> |
| 12 | + {% endfor %} |
| 13 | + </select> |
| 14 | + <select name="jsonvalue{{ name }}"> |
| 15 | + {% for pair in col2 %} |
| 16 | + <option value="{{ pair.id }}" {% if pair.id == v|add:0 %}selected{% endif %}>{{ pair }}</option> |
| 17 | + {% endfor %} |
| 18 | + </select> |
| 19 | + <img class="delete-row-button cursor" src="{% static 'json_model_widget/images/icon-deletepair.svg' %}" |
| 20 | + alt="False"> |
| 21 | + </p> |
38 | 22 | {% endfor %} |
39 | 23 | </div> |
40 | 24 |
|
41 | | - <input class="jsonwidgetbutton" type="button" id="but" onclick="addrow()" value="Добавить пару"/> |
| 25 | + <input class="jsonwidgetbutton" type="button" id="but" value="Добавить пару"/> |
42 | 26 |
|
43 | 27 | <script type="text/javascript"> |
44 | 28 | if (!$) { |
|
49 | 33 | $(this).parent('p').remove() |
50 | 34 | }) |
51 | 35 |
|
| 36 | + $(".jsonwidgetbutton").on("click", addrow) |
| 37 | + |
| 38 | + $(document).on('change click', '#fieldjson', function () { |
| 39 | + console.log("kk") |
| 40 | + if ($(this).children("p").length == 1) { |
| 41 | + $(this).find('p:first > img').hide() |
| 42 | + } else { |
| 43 | + $(this).find('p:first > img').show() |
| 44 | + } |
| 45 | + }) |
| 46 | + |
| 47 | + $("#fieldjson").change() |
| 48 | + |
52 | 49 | function addrow() { |
53 | | - console.log("ok"); |
54 | | - $("#fieldjson").append(`<p><select name="jsonkey{{ name }}"> |
| 50 | + $("#fieldjson").append(` |
| 51 | + <p><select name="jsonkey{{ name }}"> |
55 | 52 | {% for pair in col1 %} |
56 | 53 | <option value="{{ pair.id }}">{{ pair }}</option> |
57 | 54 | {% endfor %} |
58 | | - </select> |
59 | | - <select name="jsonvalue{{ name }}"> |
60 | | - {% for pair in col2 %} |
61 | | - <option value="{{ pair.id }}">{{ pair }}</option> |
62 | | - {% endfor %} |
63 | | - </select> |
64 | | - <img class="delete-row-button cursor" src="{% static 'json_model_widget/images/icon-deletepair.svg' %}" alt="False"> |
65 | | - </p>`) |
| 55 | + </select> |
| 56 | + <select name="jsonvalue{{ name }}"> |
| 57 | + {% for pair in col2 %} |
| 58 | + <option value="{{ pair.id }}">{{ pair }}</option> |
| 59 | + {% endfor %} |
| 60 | + </select> |
| 61 | + <img class="delete-row-button cursor" src="{% static 'json_model_widget/images/icon-deletepair.svg' %}" alt="False"> |
| 62 | + </p>`) |
| 63 | + |
| 64 | + $("#fieldjson").change() |
66 | 65 | }; |
67 | 66 | </script> |
68 | 67 |
|
|
0 commit comments