haproxy-wi/app/static/js/configshow.js

86 lines
2.6 KiB
JavaScript
Raw Normal View History

2018-04-10 06:24:33 +00:00
$( function() {
2024-08-02 09:50:02 +00:00
$("input[type=submit], button").button();
$(".configShow").accordion({
2018-09-14 14:15:17 +00:00
collapsible: true,
heightStyle: "content",
2024-08-02 09:50:02 +00:00
icons: {"header": "ui-icon-plus", "activeHeader": "ui-icon-minus"}
2018-04-10 06:24:33 +00:00
});
2024-08-02 09:50:02 +00:00
$('#raw').click(function () {
2018-09-14 14:15:17 +00:00
$(".configShow").accordion("destroy");
$('#raw').css('display', 'none');
$('.numRow').css('display', 'none');
$('#according').css('display', 'inline-block');
$('.accordion-expand-all').css('display', 'none');
});
2024-08-02 09:50:02 +00:00
$('#according').click(function () {
$(".configShow").accordion({
2018-09-14 14:15:17 +00:00
collapsible: true,
heightStyle: "content",
2024-08-02 09:50:02 +00:00
icons: {"header": "ui-icon-plus", "activeHeader": "ui-icon-minus"}
2018-09-14 14:15:17 +00:00
});
$('#raw').css('display', 'inline-block');
$('.numRow').css('display', 'inline-block');
$('#according').css('display', 'none');
$('.accordion-expand-all').css('display', 'inline-block');
});
let headers = $('.configShow .accordion-header');
let contentAreas = $('.configShow .ui-accordion-content ').hide()
2024-08-02 09:50:02 +00:00
.first().show().end();
let expandLink = $('.accordion-expand-all');
2024-08-02 09:50:02 +00:00
headers.click(function () {
2018-04-10 06:24:33 +00:00
// close all panels
contentAreas.slideUp();
// open the appropriate panel
$(this).next().slideDown();
// reset Expand all button
expandLink.text('Expand all')
.data('isAllOpen', false);
// stop page scroll
return false;
2024-08-02 09:50:02 +00:00
});
2018-04-10 06:24:33 +00:00
// hook up the expand/collapse all
2024-08-02 09:50:02 +00:00
expandLink.click(function () {
let isAllOpen = !$(this).data('isAllOpen');
2018-04-10 06:24:33 +00:00
console.log({isAllOpen: isAllOpen, contentAreas: contentAreas})
2024-08-02 09:50:02 +00:00
contentAreas[isAllOpen ? 'slideDown' : 'slideUp']();
expandLink.text(isAllOpen ? 'Collapse All' : 'Expand all')
.data('isAllOpen', isAllOpen);
});
$(".accordion-link a").on("click", function (event) {
window.location.href = $(this).attr("href");
event.preventDefault();
2018-04-10 06:24:33 +00:00
});
2024-08-02 09:50:02 +00:00
$("#saveconfig").on("click", ":submit", function (e) {
let frm = $('#saveconfig');
myCodeMirror.save();
2024-08-02 09:50:02 +00:00
let unindexed_array = frm.serializeArray();
let indexed_array = {};
$.map(unindexed_array, function (n, i) {
if (n['value'] != 'undefined') {
indexed_array[n['name']] = n['value'];
}
});
indexed_array['action'] = $(this).val();
$.ajax({
url: frm.attr('action'),
2024-08-02 09:50:02 +00:00
dataType: 'json',
data: JSON.stringify(indexed_array),
type: frm.attr('method'),
2024-08-02 09:50:02 +00:00
contentType: "application/json; charset=UTF-8",
success: function (data) {
toastr.clear();
2024-08-02 09:50:02 +00:00
data.data = data.data.replace(/\n/g, "<br>");
returnNiceCheckingConfig(data.data);
$(window).unbind('beforeunload');
2024-08-02 09:50:02 +00:00
if (data.status === 'failed') {
toastr.warning(data.error)
}
}
});
2024-08-02 09:50:02 +00:00
e.preventDefault();
});
})