1 | 2 | simandl | {% set datepickers = [] %} |
2 | | | <script> |
3 | | | function sendForm() { |
4 | | | showLoading(); |
5 | | | tinymce.triggerSave(); |
6 | | | $.post("{{ form.action|raw }}", $("#{{ form.name }}").serialize()) |
7 | | | .done(function(data) { |
8 | | | $("#{{ form.name }}").replaceWith(data); |
9 | | | $("#btnSendFormAjax").feedback("Data odeslĂĄna.", {duration: 3000, right: true}); |
10 | | | hideLoading(); |
11 | | | }); |
12 | | | return false; |
13 | | | } |
14 | | | /* inicializace tinyMCE */ |
15 | | | $(function() { |
16 | | | $("form textarea").each(function() { |
17 | | | var id = $(this).attr('id'); |
18 | | | if (id != '') |
19 | | | { |
20 | | | textareaToTinymce(id); |
21 | | | } |
22 | | | }); |
23 | | | tinymce.init({ |
24 | | | selector: "textarea", |
25 | | | entity_encoding: "raw", |
26 | | | forced_root_block: '', |
27 | | | convert_urls: false, |
28 | | | plugins: [ |
29 | | | "link image code" |
30 | | | ], |
31 | | | }); |
32 | | | |
33 | | | |
34 | | | }); |
35 | | | </script> |
36 | | | <form class="form-horizontal" action="{{ form.action }}" method="{{ form.method }}" name="{{ form.name }}" id="{{ form.name }}" enctype="multipart/form-data"> |
37 | | | {% for group in form.groups %} |
38 | | | <div class="page-header"> |
39 | | | <h4>{{ group.caption }}</h4> |
40 | | | </div> |
41 | | | {% for field in group.fields %} |
42 | | | {% if field.type != "hidden" %} |
43 | | | <div class="form-group"> |
44 | | | <label class="control-label col-lg-3" for="{{ field.name }}">{{ field.caption }}</label> |
45 | | | <div class="col-lg-9"> |
46 | | | {% if field.type == "select" %} |
47 | | | <select class="form-control input-sm" id="{{ field.name }}" name="{{ field.name }}"> |
48 | | | <option value="">Vyberte hodnotu</option> |
49 | | | {% for key, value in field.options %} |
50 | | | <option value="{{ key }}" {% if field.value == key %}selected="selected"{% endif %}>{{ value }}</option> |
51 | | | {% endfor %} |
52 | | | </select> |
53 | | | {% elseif field.type == "text" %} |
54 | | | <input class="form-control input-sm {{ field.class}}" id="{{ field.name }}" name="{{ field.name }}" type="text" placeholder="{{ field.caption }}" value="{{ field.value }}" {% if field.readOnly %}readonly="readonly"{% endif %}/> |
55 | | | {% elseif field.type == "textarea" %} |
56 | | | <textarea class="form-control" id="{{ field.name}}" name="{{ field.name }}" style="width: 100%" {% if field.readOnly %}readonly="readonly"{% endif %}>{{ field.value }}</textarea> |
57 | | | {% elseif field.type == "password" %} |
58 | | | <input class="form-control input-sm" id="{{ field.name }}" name="{{ field.name }}" type="password"/> |
59 | | | {% elseif field.type == "file" %} |
60 | | | <input class="form-control input-sm" id="{{ field.name }}" name="{{ field.name }}" type="file"/> |
61 | | | {% elseif field.type == "date" %} |
62 | | | <input class="form-control input-sm" id="{{ field.name }}" name="{{ field.name }}" type="text" value="{{ field.value }}"/> |
63 | | | {% set datepickers = datepickers|merge([field.name]) %} |
64 | | | {% elseif field.type == "datetime" %} |
65 | | | <div class='input-group date {{ form.name }}_datetimepicker' data-date-format="YYYY-MM-DD hh:mm"> |
66 | | | <input class="form-control input-sm" id="{{ field.name }}" name="{{ field.name }}" type="text" value="{{ field.value }}"/> |
67 | | | <span class="input-group-addon input-sm"><span class="glyphicon glyphicon-calendar"></span></span> |
68 | | | </div> |
69 | | | {% elseif field.type == "checkbox" %} |
70 | | | <input class="form-control input-sm" id="{{ field.name }}" onclick="if ($(this).is(':checked')) { |
71 | | | $('#{{ field.name }}_hidden').val(1); |
72 | | | } else { |
73 | | | $('#{{ field.name }}_hidden').val(0); |
74 | | | }" name="checkbox_{{ field.name }}" type="checkbox" {% if field.value == true %}checked="checked"{% endif %}/> |
75 | | | <input class="form-control input-sm" type="hidden" id="{{ field.name }}_hidden" name="{{ field.name }}" value="{% if field.value%}1{% else %}0{% endif %}"/> |
76 | | | {% endif %} |
77 | | | </div> |
78 | | | </div> |
79 | | | {# <div class="form-error" style="text-align:left;color:red;">{{ errors.get(field.name) }}</div> #} |
80 | | | {% else %} |
81 | | | <input name="{{ field.name }}" type="hidden" value="{{ field.value }}"/> |
82 | | | {% endif %} |
83 | | | {% endfor %} |
84 | | | {% endfor %} |
85 | | | |
86 | | | {% if form.submittedButton %} |
87 | | | <div class="form-group"> |
88 | | | <div class="col-sm-offset-3 col-lg-9"> |
89 | | | {% if form.ajax == false %} |
90 | | | <input class="btn btn-sm btn-default" type="submit" value="Odeslat"/> |
91 | | | {% else %} |
92 | | | <input class="btn btn-sm btn-default" type="button" id="btnSendFormAjax" value="Odeslat" onclick="sendForm(); |
93 | | | return false;"/> |
94 | | | {% endif %} |
95 | | | </div> |
96 | | | </div> |
97 | | | {% endif %} |
98 | | | </form> |
99 | | | |
100 | | | <script> |
101 | | | |
102 | | | {% for datepicker in datepickers %} |
103 | | | $("#{{ datepicker }}").datepicker({ |
104 | | | dateFormat: "dd.mm.yy", |
105 | | | changeMonth: true, |
106 | | | changeYear: true |
107 | | | }); |
108 | | | {% endfor %} |
109 | | | |
110 | | | |
111 | | | $('form[name="{{ form.name }}"] legend').bind('click', function() { |
112 | | | $(this).parent().find("table").toggle(); |
113 | | | }); |
114 | | | |
115 | | | {% for key, criticalField in form.criticalFields %} |
116 | | | $("#{{ key }}").bind("change", updateForm); |
117 | | | {% endfor %} |
118 | | | |
119 | | | function updateForm() { |
120 | | | console.log("updateForm"); |
121 | | | var postData = "name={{ form.name }}&" + $('form[name="{{ form.name }}"]').serialize(); |
122 | | | $.post("{{ updateFormUrl|raw }}", postData, function(data) { |
123 | | | $('form[name="{{ form.name }}"]').replaceWith(data); |
124 | | | }); |
125 | | | } |
126 | | | |
127 | | | $(function(){ |
128 | | | /* inicializace datetimepickeru */ |
129 | | | $(".{{ form.name }}_datetimepicker").datetimepicker({ |
130 | | | language: 'cs' |
131 | | | }); |
132 | | | }); |
133 | | | </script> |