Commit | Line | Data |
---|---|---|
2aa91ff2 S |
1 | $(document).ready(function(){ |
2 | function showError (msg) { | |
3 | $('#errorConfirmModal').remove(); | |
4 | $('#page-wrapper').append('<div class="modal fade" id="errorConfirmModal" tabindex="-1" role="dialog" aria-hidden="true"><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true" ><i class="fa fa-times-circle"></i></button><h4 class="modal-title">' + language['javascript.error.title'] + '</h4></div><div class="modal-body"></div><div class="modal-footer"><button class="btn" data-dismiss="modal" aria-hidden="true">' + language['javascript.close'] + '</button></div></div></div></div>'); | |
5 | $('#errorConfirmModal').find('.modal-body').text(msg); | |
6 | $('#errorConfirmModal').modal({show:true}); | |
7 | } | |
8 | ||
9 | /* delete box */ | |
10 | (function(){ | |
11 | var t = undefined; | |
12 | $('span[delete-confirm]').unbind('click'); | |
13 | $('span[delete-confirm]').on('click', function(ev) { | |
14 | ev.preventDefault(); | |
15 | t = $(this); | |
16 | ||
17 | $('#dataConfirmModal').remove(); | |
18 | $('body').append('<div class="modal fade" id="dataConfirmModal" tabindex="-1" role="dialog" aria-hidden="true"><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true" ><i class="fa fa-times-circle"></i></button><h4 class="modal-title">' + language['javascript.confirm'] + '</h4></div><div class="modal-body"></div><div class="modal-footer"><a class="btn btn-primary" id="dataConfirmOK">OK</a><button class="btn" data-dismiss="modal" aria-hidden="true">' + language['javascript.close'] + '</button></div></div></div></div>'); | |
19 | $('#dataConfirmModal').find('.modal-body').text(t.attr('delete-confirm')); | |
20 | ||
21 | $("#dataConfirmOK").unbind('click'); | |
22 | $("#dataConfirmOK").on('click', function(e){ | |
23 | e.preventDefault(); | |
24 | $('#dataConfirmModal').modal('hide'); | |
25 | var action = undefined; | |
26 | var deleteID = t.attr('delete-id'); | |
27 | if (deleteID) { | |
28 | if (t.hasClass('deleteDomain')) { | |
29 | action = 'deleteDomain'; | |
30 | } | |
31 | else if (t.hasClass('deleteRecord')) { | |
32 | action = 'deleteRecord'; | |
33 | } | |
34 | else if (t.hasClass('deleteSec')) { | |
35 | action = 'deleteSec'; | |
36 | } | |
37 | else if (t.hasClass('deleteUser')) { | |
38 | action = 'deleteUser'; | |
39 | } | |
40 | else { | |
41 | showError(language['javascript.error']); | |
42 | return false; | |
43 | } | |
44 | ||
45 | $.ajax({ | |
ff49a0be | 46 | url: 'index.php?Action', |
2aa91ff2 S |
47 | data: { |
48 | action: action, | |
49 | dataID: deleteID | |
50 | }, | |
51 | type: 'post', | |
52 | success: function(output) { | |
53 | if (output == 'success') { | |
2aa91ff2 S |
54 | t.parent().parent().remove(); |
55 | } | |
56 | else { | |
57 | showError(language['javascript.error']); | |
58 | } | |
59 | } | |
60 | }); | |
61 | } | |
62 | else { | |
63 | showError(language['javascript.error']); | |
64 | } | |
65 | ||
66 | return false; | |
67 | }); | |
68 | ||
69 | $('#dataConfirmModal').modal({show:true}); | |
70 | return false; | |
71 | }); | |
72 | })(); | |
73 | ||
74 | /* API key */ | |
75 | (function(){ | |
76 | $('#requestApiKey').unbind('click'); | |
77 | $("#requestApiKey").on('click', function(e){ | |
78 | $.ajax({ | |
ff49a0be | 79 | url: 'index.php?Action', |
2aa91ff2 S |
80 | data: { |
81 | action: 'requestApiKey', | |
82 | dataID: 1 | |
83 | }, | |
84 | type: 'post', | |
85 | success: function(output) { | |
86 | if (output == 'failure') { | |
87 | showError(language['javascript.error']); | |
88 | } | |
89 | else { | |
90 | $('#apiKey').text(output); | |
91 | } | |
92 | } | |
93 | }); | |
94 | }); | |
95 | })(); | |
96 | ||
97 | /* toggle */ | |
98 | (function(){ | |
99 | $('span[toggle-id]').unbind('click'); | |
100 | $('span[toggle-id]').on('click', function(ev) { | |
101 | ev.preventDefault(); | |
102 | var t = $(this); | |
103 | var action = undefined; | |
104 | var dataID = t.attr('toggle-id'); | |
105 | if (dataID) { | |
106 | if (t.hasClass('toggleDomain')) { | |
107 | action = 'toggleDomain'; | |
108 | } | |
109 | else if (t.hasClass('toggleRecord')) { | |
110 | action = 'toggleRecord'; | |
111 | } | |
112 | else if (t.hasClass('toggleSec')) { | |
113 | action = 'toggleSec'; | |
114 | } | |
115 | else if (t.hasClass('toggleUser')) { | |
116 | action = 'toggleUser'; | |
117 | } | |
118 | else { | |
119 | showError(language['javascript.error']); | |
120 | return false; | |
121 | } | |
122 | ||
123 | $.ajax({ | |
ff49a0be | 124 | url: 'index.php?Action', |
2aa91ff2 S |
125 | data: { |
126 | action: action, | |
127 | dataID: dataID | |
128 | }, | |
129 | type: 'post', | |
130 | success: function(output) { | |
131 | if (output == 'success') { | |
132 | // toggle | |
133 | if (t.hasClass('fa-square-o')) { | |
134 | // set enabled | |
135 | t.removeClass('fa-square-o').addClass('fa-check-square-o'); | |
136 | t.tooltip('hide').attr('data-original-title', t.attr('data-disable-message')).tooltip('fixTitle').tooltip('show'); | |
137 | t.parent().parent().children().first().next().find("span.badge").remove(); | |
138 | } | |
139 | else if (t.hasClass('fa-check-square-o')) { | |
140 | // set disabled | |
141 | t.removeClass('fa-check-square-o').addClass('fa-square-o'); | |
142 | t.tooltip('hide').attr('data-original-title', t.attr('data-enable-message')).tooltip('fixTitle').tooltip('show'); | |
143 | t.parent().parent().children().first().next().prepend('<span class="badge badge-red">' + language['domain.disabled'] + '</span> '); | |
144 | } | |
145 | else { | |
146 | showError(language['javascript.error']); | |
147 | } | |
148 | } | |
149 | else { | |
150 | showError(language['javascript.error']); | |
151 | } | |
152 | } | |
153 | }); | |
154 | } | |
155 | else { | |
156 | showError(language['javascript.error']); | |
157 | } | |
158 | ||
159 | return false; | |
160 | }); | |
161 | })(); | |
162 | ||
6d1c8140 S |
163 | /* Bootstrap Tooltips */ |
164 | (function(){ | |
165 | $('.ttips').each(function(e) { | |
166 | $(this).tooltip(); | |
167 | }); | |
168 | })(); | |
169 | ||
2aa91ff2 S |
170 | /* dns input fields */ |
171 | (function(){ | |
172 | $('#type').unbind('keyup keydown keypress change'); | |
173 | $('#type').on('keyup keydown keypress change', function () { | |
174 | var val = $.trim($(this).val()); | |
175 | // default data | |
176 | $('dl#aux').find('dt').text('Prio'); | |
177 | $('dl#weight').find('dt').text('weight'); | |
178 | $('dl#port').find('dt').text('port'); | |
179 | $('dl#data').find('dt').text('Data'); | |
180 | $("dl#aux").hide(); | |
181 | $("dl#weight").hide(); | |
182 | $("dl#port").hide(); | |
183 | $("dl#data").hide(); | |
184 | ||
185 | switch (val) { | |
186 | case "A": | |
187 | case "AAAA": | |
188 | case "CNAME": | |
189 | case "TXT": | |
190 | case "NS": | |
191 | case "PTR": | |
192 | $("dl#data").show(); | |
193 | break; | |
194 | ||
195 | case "DS": | |
196 | $("dl#aux").show(); // key tag | |
197 | $("dl#weight").show(); // algorithm | |
198 | $("dl#port").show(); // algorithm type | |
199 | $("dl#data").show(); // digest | |
200 | $('dl#aux').find('dt').text('Key-ID'); | |
201 | $('dl#weight').find('dt').text('Algorithm'); | |
202 | $('dl#port').find('dt').text('Digest Type'); | |
203 | $('dl#data').find('dt').text('Digest'); | |
204 | break; | |
205 | ||
206 | case "TLSA": | |
207 | $("dl#aux").show(); // Usages | |
208 | $("dl#weight").show(); // Selectors | |
209 | $("dl#port").show(); // Types | |
210 | $("dl#data").show(); // Hash | |
211 | $('dl#aux').find('dt').text('Usage'); | |
212 | $('dl#weight').find('dt').text('Selector'); | |
213 | $('dl#port').find('dt').text('Hash Type'); | |
214 | $('dl#data').find('dt').text('Hash'); | |
215 | break; | |
216 | ||
217 | case "MX": | |
218 | /*case "DNSKEY":*/ | |
219 | $("dl#aux").show(); | |
220 | $("dl#data").show(); | |
221 | break; | |
222 | ||
223 | case "SRV": | |
224 | $("dl#aux").show(); // priority | |
225 | $("dl#weight").show(); // weight | |
226 | $("dl#port").show(); // port | |
227 | $("dl#data").show(); // target | |
228 | break; | |
229 | } | |
230 | ||
231 | }); | |
232 | })(); | |
233 | ||
234 | /* export */ | |
235 | (function(){ | |
236 | $('#export').unbind('click'); | |
237 | $('#export').on('click', function(e) { | |
238 | console.log('click'); | |
239 | var t = $(this); | |
240 | var dataID = t.attr('export-id'); | |
241 | $.ajax({ | |
ff49a0be | 242 | url: 'index.php?Action', |
2aa91ff2 S |
243 | data: { |
244 | action: 'export', | |
245 | dataID: dataID | |
246 | }, | |
247 | type: 'post', | |
248 | success: function(output) { | |
249 | console.log(output); | |
250 | if (output == 'failure') { | |
251 | //do nothing | |
252 | /*showError(language['javascript.error']);*/ | |
253 | } | |
254 | else { | |
255 | /* show modal with zone file */ | |
256 | $('#exportModal').remove(); | |
257 | $('#page-wrapper').append('<div class="modal fade" id="exportModal" tabindex="-1" role="dialog" aria-hidden="true">' + | |
258 | '<div class="modal-dialog">' + | |
259 | '<div class="modal-content">' + | |
260 | '<div class="modal-header">' + | |
261 | '<button type="button" class="close" data-dismiss="modal" aria-hidden="true" ><i class="fa fa-times-circle"></i></button>' + | |
262 | '<h4 class="modal-title">Zone File Export</h4>' + | |
263 | '</div>' + | |
264 | '<div class="modal-body">' + | |
265 | '<textarea id="exportTextarea" style="width: 569px; height: 552px;">' + output + '</textarea>' + | |
266 | '</div>' + | |
267 | '<div class="modal-footer">' + | |
268 | '<button class="btn" data-dismiss="modal" aria-hidden="true">' + language['javascript.close'] + '</button>' + | |
269 | '</div>' + | |
270 | '</div>' + | |
271 | '</div>' + | |
272 | '</div>'); | |
273 | $('#exportModal').modal({show:true}); | |
274 | setTimeout(function() { | |
275 | $('#exportTextarea').focus(); | |
276 | }, 700); | |
277 | } | |
278 | } | |
279 | }); | |
280 | }); | |
281 | })(); | |
282 | ||
283 | /* import */ | |
284 | (function(){ | |
285 | $('#import').unbind('click'); | |
286 | $('#import').on('click', function(e) { | |
287 | var t = $(this); | |
288 | var dataID = t.attr('import-id'); | |
289 | $('#importModal').remove(); | |
290 | $('#page-wrapper').append('<div class="modal fade" id="importModal" tabindex="-1" role="dialog" aria-hidden="true">' + | |
291 | '<div class="modal-dialog">' + | |
292 | '<div class="modal-content">' + | |
293 | '<div class="modal-header">' + | |
294 | '<button type="button" class="close" data-dismiss="modal" aria-hidden="true" ><i class="fa fa-times-circle"></i></button>' + | |
295 | '<h4 class="modal-title">Zone File Import</h4>' + | |
296 | '</div>' + | |
297 | '<div class="modal-body">' + | |
298 | (dataID ? '' : '<input type="text" id="importOrigin" value="" placeholder="example.com." style="width: 100%;"/>') + | |
299 | '<textarea id="importTextarea" style="width: 569px; height: 552px;"></textarea>' + | |
300 | '</div>' + | |
301 | '<div class="modal-footer">' + | |
302 | '<button class="btn" id="importSubmit" aria-hidden="true">OK</button>' + | |
303 | '<button class="btn" data-dismiss="modal" aria-hidden="true">' + language['javascript.close'] + '</button>' + | |
304 | '</div>' + | |
305 | '</div>' + | |
306 | '</div>' + | |
307 | '</div>'); | |
308 | $('#importModal').modal({show:true}); | |
309 | ||
310 | setTimeout(function() { | |
311 | $('#importTextarea').focus(); | |
312 | }, 700); | |
313 | ||
314 | $("#importSubmit").unbind('click'); | |
315 | $("#importSubmit").on('click', function(e){ | |
316 | var origin = $('#importModal').find('.modal-body').find('#importOrigin').val(); | |
317 | var zone = $('#importModal').find('.modal-body').find('#importTextarea').val(); | |
318 | $.ajax({ | |
ff49a0be | 319 | url: 'index.php?Action', |
2aa91ff2 S |
320 | data: { |
321 | action: 'import', | |
322 | dataID: dataID ? dataID : 0, /* 0 for new zone otherwise soaID for existing zone*/ | |
323 | origin: origin ? origin : '', | |
324 | zone: zone | |
325 | }, | |
326 | type: 'post', | |
327 | success: function(output) { | |
328 | $('#importModal').modal('hide'); | |
329 | if (output == 'failure') { | |
330 | showError(language['javascript.error']); | |
331 | } | |
332 | else { | |
333 | if (!dataID) { | |
334 | // redirect to main page on success | |
ff49a0be | 335 | $(location).attr('href','index.php?DomainList'); |
2aa91ff2 S |
336 | } |
337 | else { | |
338 | // redirect to record list on success | |
ff49a0be | 339 | $(location).attr('href','index.php?RecordList/' + dataID); |
2aa91ff2 S |
340 | } |
341 | } | |
342 | } | |
343 | }); | |
344 | }); | |
345 | ||
346 | }); | |
347 | })(); | |
348 | ||
349 | /* metis Menu */ | |
350 | (function(){ | |
351 | $('#side-menu').metisMenu(); | |
352 | })(); | |
353 | }); | |
354 | ||
355 | $(window).load(function(){ | |
356 | // Loads the correct sidebar on window load, | |
357 | // collapses the sidebar on window resize. | |
358 | // Sets the min-height of #page-wrapper to window size | |
359 | (function(){ | |
360 | $(window).bind("load resize", function() { | |
361 | topOffset = 50; | |
362 | width = (this.window.innerWidth > 0) ? this.window.innerWidth : this.screen.width; | |
363 | if (width < 768) { | |
364 | $('div.navbar-collapse').addClass('collapse'); | |
365 | topOffset = 100; // 2-row-menu | |
366 | } else { | |
367 | $('div.navbar-collapse').removeClass('collapse'); | |
368 | } | |
369 | ||
370 | height = ((this.window.innerHeight > 0) ? this.window.innerHeight : this.screen.height) - 1; | |
371 | height = height - topOffset; | |
372 | if (height < 1) height = 1; | |
373 | if (height > topOffset) { | |
374 | $("#page-wrapper").css("min-height", (height) + "px"); | |
375 | } | |
376 | }); | |
377 | })(); | |
2aa91ff2 | 378 | }); |