diff --git a/app/static/js/attributes.js b/app/static/js/attributes.js index 4764121ab86e7254827506efa4319f14f55052a7..fd397b67fa4f487996a6c1cc6b862a1a5e93e4f3 100644 --- a/app/static/js/attributes.js +++ b/app/static/js/attributes.js @@ -1,75 +1,81 @@ $(document).ready(function() { - - var attributes_table = $("#attributes_table").DataTable({ - "ajax": function(data, callback, settings) { - var kind = $('li a.nav-link.active').text(); + var attributes_table = $("#attributes_table").DataTable({ + ajax: function(data, callback, settings) { + var kind = $("li a.nav-link.active").text(); $.getJSON( $SCRIPT_ROOT + "/inventory/_retrieve_attributes/" + kind, function(json) { callback(json); - }); + } + ); }, - "order": [[2, 'asc']], - "columnDefs": [ + order: [[2, "asc"]], + columnDefs: [ { - "targets": [0], - "orderable": false, - 'className': 'text-center align-middle', - "render": function(data, type, row) { + targets: [0], + orderable: false, + className: "text-center align-middle", + render: function(data, type, row) { // render a checkbox to add/remove the attribute to the user's favorites - var checked = data.favorite ? "checked" : "" - return '<input type="checkbox" value="' + data.id + '" ' + checked + '>' + var checked = data.favorite ? "checked" : ""; + return ( + '<input type="checkbox" value="' + data.id + '" ' + checked + ">" + ); }, - "width": "5%", + width: "5%" }, { - "targets": [1], - "orderable": false, - "render": function(data, type, row) { + targets: [1], + orderable: false, + render: function(data, type, row) { // render QR code from base64 string - return '<img class="img-fluid" src="data:image/png;base64,' + data + '">'; + return ( + '<img class="img-fluid" src="data:image/png;base64,' + data + '">' + ); }, - "width": "10%", + width: "10%" } ], - "paging": false + paging: false }); // update the user favorites - $("#attributes_table").on('change', 'input[type="checkbox"]', function() { - var kind = $('li a.nav-link.active').text(); + $("#attributes_table").on("change", 'input[type="checkbox"]', function() { + var kind = $("li a.nav-link.active").text(); $.ajax({ type: "POST", - url: $SCRIPT_ROOT + "/inventory/_update_favorites/" + kind , + url: $SCRIPT_ROOT + "/inventory/_update_favorites/" + kind, data: JSON.stringify({ id: $(this).val(), checked: this.checked }), - contentType : 'application/json' + contentType: "application/json" }); }); - var attributes_favorites_table = $("#attributes_favorites_table").DataTable({ - "ajax": function(data, callback, settings) { + var attributes_favorites_table = $("#attributes_favorites_table").DataTable({ + ajax: function(data, callback, settings) { $.getJSON( $SCRIPT_ROOT + "/inventory/_retrieve_attributes_favorites", function(json) { callback(json); - }); + } + ); }, - "order": [[1, 'asc']], - "columnDefs": [ + order: [[1, "asc"]], + columnDefs: [ { - "targets": [0], - "orderable": false, - "render": function(data, type, row) { + targets: [0], + orderable: false, + render: function(data, type, row) { // render QR code from base64 string - return '<img class="img-fluid" src="data:image/png;base64,' + data + '">'; + return ( + '<img class="img-fluid" src="data:image/png;base64,' + data + '">' + ); }, - "width": "10%", + width: "10%" } ], - "paging": false + paging: false }); - }); diff --git a/app/static/js/create_item.js b/app/static/js/create_item.js index 2d7a1a5e55bbe35ab6ab4b443f2f365b2e1ac6f4..edb04e5d884a7cc9cbe9becb60efb2112393aeef 100644 --- a/app/static/js/create_item.js +++ b/app/static/js/create_item.js @@ -1,7 +1,7 @@ $(document).ready(function() { - - $.fn.focusWithoutScrolling = function(){ - var x = window.scrollX, y = window.scrollY; + $.fn.focusWithoutScrolling = function() { + var x = window.scrollX, + y = window.scrollY; this.focus(); window.scrollTo(x, y); return this; //chainability @@ -16,10 +16,10 @@ $(document).ready(function() { // Prevent enter key to submit the form when scanning a label // and remove the ICS:ics_id: prefix $("#ics_id").keydown(function(event) { - if(event.keyCode == 13) { + if (event.keyCode == 13) { event.preventDefault(); var value = $(this).val(); - $(this).val(value.replace('CSE:ics_id:', '')); + $(this).val(value.replace("CSE:ics_id:", "")); $("#serial_number").focus(); return false; } @@ -29,7 +29,7 @@ $(document).ready(function() { // Focus on the submit button so that scanning the Submit action // will submit the form (due to the CR sent by the scanner) $("#serial_number").keydown(function(event) { - if(event.keyCode == 13) { + if (event.keyCode == 13) { event.preventDefault(); $("#submit").focusWithoutScrolling(); return false; @@ -38,12 +38,11 @@ $(document).ready(function() { $("#clear").click(function() { // clear all select fields - $("select").val(''); + $("select").val(""); }); // Update the stack member field linked to the host when changing it - $("#host_id").on('change', function() { + $("#host_id").on("change", function() { update_stack_member(); }); - }); diff --git a/app/static/js/csentry.js b/app/static/js/csentry.js index d23fe0e018b330572645c20e9a43601b647b4fed..87ba457dd95b6a015c983ca5dbe459084b2797a0 100644 --- a/app/static/js/csentry.js +++ b/app/static/js/csentry.js @@ -1,8 +1,14 @@ function flash_alert(message, category) { - var htmlString = '<div class="alert alert-' + category + ' alert-dismissible" role="alert">' - htmlString += '<button type="button" class="close" data-dismiss="alert" aria-label="Close">' - htmlString += '<span aria-hidden="true">×</span></button>' + message + '</div>' - $(htmlString).prependTo("#mainContent").hide().slideDown(); + var htmlString = + '<div class="alert alert-' + category + ' alert-dismissible" role="alert">'; + htmlString += + '<button type="button" class="close" data-dismiss="alert" aria-label="Close">'; + htmlString += + '<span aria-hidden="true">×</span></button>' + message + "</div>"; + $(htmlString) + .prependTo("#mainContent") + .hide() + .slideDown(); } function remove_alerts() { @@ -30,23 +36,24 @@ function check_job_status(status_url, $modal) { success: function(data, status, request) { switch (data.status) { case "unknown": - $modal.modal('hide'); + $modal.modal("hide"); flash_alert("Unknown job id", "danger"); break; case "finished": - $modal.modal('hide'); + $modal.modal("hide"); switch (data.func_name) { case "generate_items_excel_file": - window.location.href = $SCRIPT_ROOT + "/static/files/" + data.result; + window.location.href = + $SCRIPT_ROOT + "/static/files/" + data.result; break; } break; case "failed": - $modal.modal('hide'); + $modal.modal("hide"); flash_alert(data.message, "danger"); break; case "started": - if( data.progress !== null ) { + if (data.progress !== null) { update_progress_bar(data.progress); } default: @@ -64,14 +71,18 @@ function update_selectfield(field_id, data, selected_value) { var $field = $(field_id); $field.empty(); $.map(data, function(option, index) { - if( option == "None" ) { + if (option == "None") { var text = ""; } else { var text = option; } - $field.append($("<option></option>").attr("value", option).text(text)); + $field.append( + $("<option></option>") + .attr("value", option) + .text(text) + ); }); - if( selected_value == "" ) { + if (selected_value == "") { $field.prop("disabled", true); } else { $field.val(selected_value); @@ -90,14 +101,17 @@ function update_stack_member() { ics_id: $("#ics_id").val() }, function(json) { - update_selectfield("#stack_member", json.data.stack_members, json.data.selected_member); + update_selectfield( + "#stack_member", + json.data.stack_members, + json.data.selected_member + ); $("#stack_member").prop("disabled", json.data.disabled); } ); } $(document).ready(function() { - // When an invalid input was submitted, the server // adds the "is-invalid" class to form fields to display // them in red with an error message @@ -111,5 +125,4 @@ $(document).ready(function() { // for all Select and MultiSelect fields with the // selectize-default class $(".selectize-default").selectize(); - }); diff --git a/app/static/js/domains.js b/app/static/js/domains.js index 777943f696a1a2977fdd7b99591612cbbccafe4e..a8894630f4df9cdfd7fb71a97a129750c2f10304 100644 --- a/app/static/js/domains.js +++ b/app/static/js/domains.js @@ -1,7 +1,5 @@ $(document).ready(function() { - - var domains_table = $("#domains_table").DataTable({ - "paging": false + var domains_table = $("#domains_table").DataTable({ + paging: false }); - }); diff --git a/app/static/js/edit_item.js b/app/static/js/edit_item.js index b1fdc39defdb58ab55c340ec61e3ef739007d3a3..6dd458960d51c20a600f30a5ff87b8169cf3f4d5 100644 --- a/app/static/js/edit_item.js +++ b/app/static/js/edit_item.js @@ -1,11 +1,9 @@ $(document).ready(function() { - // Populate the stack member field linked to the host on first page load update_stack_member(); // Update the stack member field linked to the host when changing it - $("#host_id").on('change', function() { + $("#host_id").on("change", function() { update_stack_member(); }); - }); diff --git a/app/static/js/groups.js b/app/static/js/groups.js index d3f690e2f23481cfb298d07368eefe82bd698fb0..ceeb6b8c3213ddd7dd7e66277d33fd0d227ce02c 100644 --- a/app/static/js/groups.js +++ b/app/static/js/groups.js @@ -1,8 +1,7 @@ $(document).ready(function() { - function group_type_update() { var hosts_selectize = $("#hosts")[0].selectize; - if( $("#type option:selected").text() == "STATIC" ) { + if ($("#type option:selected").text() == "STATIC") { hosts_selectize.enable(); } else { hosts_selectize.clear(); @@ -11,69 +10,74 @@ $(document).ready(function() { } // Disable or enable hosts on group type update - $("#type").on('change', function() { + $("#type").on("change", function() { group_type_update(); }); // Disable or enable hosts on page load depending on group type - if( $("#groupForm").length || $("#editGroupForm").length ) { + if ($("#groupForm").length || $("#editGroupForm").length) { group_type_update(); } - if( $("#groupForm").length || $("#editGroupForm").length ) { + if ($("#groupForm").length || $("#editGroupForm").length) { var groupVarsEditor = CodeMirror.fromTextArea(vars, { - lineNumbers: true, - mode: "yaml" + lineNumbers: true, + mode: "yaml" }); groupVarsEditor.setSize(null, 120); var handle = cmResize(groupVarsEditor, { minHeight: 120, resizableWidth: false, - resizableHeight: true, + resizableHeight: true }); } - var groups_table = $("#groups_table").DataTable({ - "ajax": function(data, callback, settings) { - $.getJSON( - $SCRIPT_ROOT + "/network/_retrieve_groups", - function(json) { - callback(json); - }); + var groups_table = $("#groups_table").DataTable({ + ajax: function(data, callback, settings) { + $.getJSON($SCRIPT_ROOT + "/network/_retrieve_groups", function(json) { + callback(json); + }); }, - "paging": true, - "pagingType": "full_numbers", - "columns": [ - { data: 'name', + paging: true, + pagingType: "full_numbers", + columns: [ + { + data: "name", render: function(data, type, row) { // render funtion to create link to group view page - if ( data === null ) { + if (data === null) { return data; } var url = $SCRIPT_ROOT + "/network/groups/view/" + data; - return '<a href="' + url + '">' + data + '</a>'; + return '<a href="' + url + '">' + data + "</a>"; } }, - { data: 'vars', + { + data: "vars", render: function(data, type, row) { - if ( data === null ) { + if (data === null) { return ""; } - return '<pre style="max-width:300px;">' + JSON.stringify(data, null, 2) + '</pre>'; + return ( + '<pre style="max-width:300px;">' + + JSON.stringify(data, null, 2) + + "</pre>" + ); } }, - { data: 'type' }, - { data: 'children', + { data: "type" }, + { + data: "children", render: function(data, type, row) { return data.join(", "); } }, - { data: 'hosts', + { + data: "hosts", render: function(data, type, row) { return data.join(", "); } } ] }); - }); diff --git a/app/static/js/hosts.js b/app/static/js/hosts.js index 78bac16547a39db47a81899eec87bca19ad815c3..3f9e5602cdec6873f8f7af2c3f2d398465c07c2c 100644 --- a/app/static/js/hosts.js +++ b/app/static/js/hosts.js @@ -1,33 +1,32 @@ $(document).ready(function() { - function render_host_link(data) { // render funtion to create link to Host view page - if ( data === null ) { + if (data === null) { return data; } var url = $SCRIPT_ROOT + "/network/hosts/view/" + data; - return '<a href="'+ url + '">' + data + '</a>'; + return '<a href="' + url + '">' + data + "</a>"; } function render_network_link(data) { // render funtion to create link to Network view page - if ( data === null ) { + if (data === null) { return data; } var url = $SCRIPT_ROOT + "/network/networks/view/" + data; - return '<a href="'+ url + '">' + data + '</a>'; + return '<a href="' + url + '">' + data + "</a>"; } - if( $("#hostForm").length || $("#editHostForm").length ) { + if ($("#hostForm").length || $("#editHostForm").length) { var hostVarsEditor = CodeMirror.fromTextArea(ansible_vars, { - lineNumbers: true, - mode: "yaml" + lineNumbers: true, + mode: "yaml" }); hostVarsEditor.setSize(null, 120); var handle = cmResize(hostVarsEditor, { minHeight: 120, resizableWidth: false, - resizableHeight: true, + resizableHeight: true }); } @@ -35,7 +34,7 @@ $(document).ready(function() { // Retrieve the first available IP for the selected network // and update the IP field var network_id = $("#network_id").val(); - if ( network_id !== "" ) { + if (network_id !== "") { $("#ip").removeClass("is-invalid"); $.getJSON( $SCRIPT_ROOT + "/network/_retrieve_first_available_ip/" + network_id, @@ -49,24 +48,25 @@ $(document).ready(function() { // And check / uncheck random_mac checkbox function update_device_type_attributes() { var device_type = $("#device_type_id option:selected").text(); - if( device_type.startsWith("Virtual") ) { - $("#random_mac").prop("checked", true).change(); + if (device_type.startsWith("Virtual")) { + $("#random_mac") + .prop("checked", true) + .change(); } else { - $("#random_mac").prop("checked", false).change(); + $("#random_mac") + .prop("checked", false) + .change(); } } // If random_mac is checked, generate a random address // Empty the field otherwise function fill_mac_address() { - if( $("#random_mac").prop("checked") ) { - $.getJSON( - $SCRIPT_ROOT + "/network/_generate_random_mac", - function(json) { - $("#mac").val(json.data.mac); - $("#mac").prop("readonly", true); - } - ); + if ($("#random_mac").prop("checked")) { + $.getJSON($SCRIPT_ROOT + "/network/_generate_random_mac", function(json) { + $("#mac").val(json.data.mac); + $("#mac").prop("readonly", true); + }); } else { $("#mac").val(""); $("#mac").prop("readonly", false); @@ -80,105 +80,123 @@ $(document).ready(function() { // (we have to keep the existing IP) // Do NOT replace the IP if the form was submitted and an error was raised // (we should display the same value that was submitted) - if( ($("#hostForm").length || $("#interfaceForm").length) && ! $("input").hasClass("is-invalid") ) { + if ( + ($("#hostForm").length || $("#interfaceForm").length) && + !$("input").hasClass("is-invalid") + ) { set_default_ip(); } // On page load if the network_id is invalid, it's because an empty entry was submitted // remove the default value to make it clear - if( ($("#hostForm").length || $("#interfaceForm").length) && $("#network_id").hasClass("is-invalid") ) { + if ( + ($("#hostForm").length || $("#interfaceForm").length) && + $("#network_id").hasClass("is-invalid") + ) { var network_id_selectize = $("#network_id")[0].selectize; network_id_selectize.clear(true); } // Clear the default value so that the user can start typing directly // or click a dropdown item - $("#network_id").next(".selectize-control").on( 'click', function () { - var network_id_selectize = $("#network_id")[0].selectize; - network_id_selectize.clear(true); - }); + $("#network_id") + .next(".selectize-control") + .on("click", function() { + var network_id_selectize = $("#network_id")[0].selectize; + network_id_selectize.clear(true); + }); // Set the default IP when changing network - $("#network_id").on('change', function() { + $("#network_id").on("change", function() { $(this).removeClass("is-invalid"); - $(this).next(".selectize-control").removeClass("is-invalid"); + $(this) + .next(".selectize-control") + .removeClass("is-invalid"); set_default_ip(); }); // Only for register new host form - if( $("#hostForm").length ) { + if ($("#hostForm").length) { // On first page load update_device_type_attributes(); // And change - $("#device_type_id").on('change', function() { + $("#device_type_id").on("change", function() { update_device_type_attributes(); }); } // Fill MAC address on page load - if( $("#random_mac").length ) { + if ($("#random_mac").length) { fill_mac_address(); } // Fill or clear MAC address depending on random_mac checkbox - $("#random_mac").on('change', function() { + $("#random_mac").on("change", function() { fill_mac_address(); }); - var hosts_table = $("#hosts_table").DataTable({ - dom: "<'row'<'col-sm-12 col-md-6'l><'col-sm-12 col-md-3 text-right'><'col-sm-12 col-md-3'f>>" + - "<'row'<'col-sm-12'tr>>" + - "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>", - "ajax": { - "url": $SCRIPT_ROOT + "/network/_retrieve_hosts", - "type": "POST" + var hosts_table = $("#hosts_table").DataTable({ + dom: + "<'row'<'col-sm-12 col-md-6'l><'col-sm-12 col-md-3 text-right'><'col-sm-12 col-md-3'f>>" + + "<'row'<'col-sm-12'tr>>" + + "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>", + ajax: { + url: $SCRIPT_ROOT + "/network/_retrieve_hosts", + type: "POST" }, - "processing": true, - "serverSide": true, - "searchDelay": 500, - "stateSave": true, - "orderMulti": false, - "aaSorting": [], - "pagingType": "full_numbers", - "pageLength": 20, - "lengthMenu": [[20, 50, 100], [20, 50, 100]], - "columns": [ - { data: 'name', + processing: true, + serverSide: true, + searchDelay: 500, + stateSave: true, + orderMulti: false, + aaSorting: [], + pagingType: "full_numbers", + pageLength: 20, + lengthMenu: [ + [20, 50, 100], + [20, 50, 100] + ], + columns: [ + { + data: "name", render: function(data, type, row) { return render_host_link(data); } }, - { data: 'device_type' }, - { data: 'description', - orderable: false }, - { data: 'interfaces.0.ip', - defaultContent: "", - orderable: false }, - { data: 'interfaces.0.network', + { data: "device_type" }, + { data: "description", orderable: false }, + { data: "interfaces.0.ip", defaultContent: "", orderable: false }, + { + data: "interfaces.0.network", render: function(data, type, row) { return render_network_link(data); }, defaultContent: "", - orderable: false } + orderable: false + } ] }); - if( $("#hosts_table").length ) { + if ($("#hosts_table").length) { new $.fn.dataTable.Buttons(hosts_table, { buttons: [ { - text: 'Reset', + text: "Reset", className: "btn-outline-secondary", - action: function ( e, dt, node, conf ) { + action: function(e, dt, node, conf) { dt.state.clear(); - dt.search('').order([]).draw(); + dt.search("") + .order([]) + .draw(); } } ] }); - hosts_table.buttons().container().appendTo("#hosts_table_wrapper .col-md-3:eq(0)"); + hosts_table + .buttons() + .container() + .appendTo("#hosts_table_wrapper .col-md-3:eq(0)"); } - }); diff --git a/app/static/js/items.js b/app/static/js/items.js index 2aebc493e0c0154f463d46470ded48a43f7a3439..8406013280ee4f78c393de85dd0d0ea9f20b82c6 100644 --- a/app/static/js/items.js +++ b/app/static/js/items.js @@ -1,12 +1,11 @@ $(document).ready(function() { - function render_item_link(data) { // render funtion to create link to Item view page - if ( data === null ) { + if (data === null) { return data; } var url = $SCRIPT_ROOT + "/inventory/items/view/" + data; - return '<a href="'+ url + '">' + data + '</a>'; + return '<a href="' + url + '">' + data + "</a>"; } // scroll up to avoid having the form input @@ -17,19 +16,19 @@ $(document).ready(function() { // Showdown extension to render links to JIRA TAG project var jira_tag = { - type: 'lang', - regex: /(TAG-\d+)/g, - replace: '[$1](https://jira.esss.lu.se/browse/$1)' + type: "lang", + regex: /(TAG-\d+)/g, + replace: "[$1](https://jira.esss.lu.se/browse/$1)" }; // Register the extension - showdown.extension('jira_tag', jira_tag); + showdown.extension("jira_tag", jira_tag); var converter = new showdown.Converter({ - extensions: ['jira_tag'], + extensions: ["jira_tag"], simplifiedAutoLink: true }); - if( $("#commentLivePreview").length ) { + if ($("#commentLivePreview").length) { // Render comment when editing one $("#commentLivePreview").html(converter.makeHtml($("#body").val())); @@ -46,7 +45,6 @@ $(document).ready(function() { $(this).html(converter.makeHtml(raw)); }); - // export all items to excel file function download_excel() { var $modal = $("#downloadExcelModal"); @@ -58,48 +56,54 @@ $(document).ready(function() { backdrop: "static", keyboard: false }); - status_url = request.getResponseHeader('Location'); + status_url = request.getResponseHeader("Location"); check_job_status(status_url, $modal); }, error: function(jqXHR, textStatus, errorThrown) { - $modal.modal('hide'); + $modal.modal("hide"); flash_alert(JSON.parse(jqXHR.responseText).message, "danger", false); } - }); + }); } - var items_table = $("#items_table").DataTable({ - dom: "<'row'<'col-sm-12 col-md-6'l><'col-sm-12 col-md-3 text-right'><'col-sm-12 col-md-3'f>>" + - "<'row'<'col-sm-12'tr>>" + - "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>", - "ajax": { - "url": $SCRIPT_ROOT + "/inventory/_retrieve_items", - "type": "POST" + var items_table = $("#items_table").DataTable({ + dom: + "<'row'<'col-sm-12 col-md-6'l><'col-sm-12 col-md-3 text-right'><'col-sm-12 col-md-3'f>>" + + "<'row'<'col-sm-12'tr>>" + + "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>", + ajax: { + url: $SCRIPT_ROOT + "/inventory/_retrieve_items", + type: "POST" }, - "processing": true, - "serverSide": true, - "searchDelay": 500, - "stateSave": true, - "orderMulti": false, - "aaSorting": [], - "pagingType": "full_numbers", - "pageLength": 20, - "lengthMenu": [[20, 50, 100], [20, 50, 100]], - "columns": [ - { data: 'ics_id', + processing: true, + serverSide: true, + searchDelay: 500, + stateSave: true, + orderMulti: false, + aaSorting: [], + pagingType: "full_numbers", + pageLength: 20, + lengthMenu: [ + [20, 50, 100], + [20, 50, 100] + ], + columns: [ + { + data: "ics_id", render: function(data, type, row) { return render_item_link(data); } }, - { data: 'created_at' }, - { data: 'updated_at' }, - { data: 'serial_number' }, - { data: 'quantity' }, - { data: 'manufacturer' }, - { data: 'model' }, - { data: 'location' }, - { data: 'status' }, - { data: 'parent', + { data: "created_at" }, + { data: "updated_at" }, + { data: "serial_number" }, + { data: "quantity" }, + { data: "manufacturer" }, + { data: "model" }, + { data: "location" }, + { data: "status" }, + { + data: "parent", render: function(data, type, row) { return render_item_link(data); } @@ -107,28 +111,33 @@ $(document).ready(function() { ] }); - if( $("#items_table").length ) { + if ($("#items_table").length) { new $.fn.dataTable.Buttons(items_table, { buttons: [ { - text: '<span class="oi oi-data-transfer-download" title="Export to excel file" aria-hidden="true"></span> Excel', + text: + '<span class="oi oi-data-transfer-download" title="Export to excel file" aria-hidden="true"></span> Excel', className: "btn-outline-secondary", - action: function ( e, dt, node, conf ) { + action: function(e, dt, node, conf) { download_excel(); } }, { - text: 'Reset', + text: "Reset", className: "btn-outline-secondary", - action: function ( e, dt, node, conf ) { + action: function(e, dt, node, conf) { dt.state.clear(); - dt.search('').order([]).draw(); + dt.search("") + .order([]) + .draw(); } } ] }); - items_table.buttons().container().appendTo("#items_table_wrapper .col-md-3:eq(0)"); + items_table + .buttons() + .container() + .appendTo("#items_table_wrapper .col-md-3:eq(0)"); } - }); diff --git a/app/static/js/networks.js b/app/static/js/networks.js index 58d1b1cbffeaf8cecd66569452346bcc1e4c44a2..634c7a153c7a94a8178e72d5a856650af9b0dcfc 100644 --- a/app/static/js/networks.js +++ b/app/static/js/networks.js @@ -1,5 +1,4 @@ $(document).ready(function() { - function update_scope_defaults() { // Retrieve available vlans, subnet prefixes and default domain // for the selected network scope and update the linked select fields @@ -7,9 +6,17 @@ $(document).ready(function() { $.getJSON( $SCRIPT_ROOT + "/network/_retrieve_scope_defaults/" + scope_id, function(json) { - update_selectfield("#vlan_id", json.data.vlans, json.data.selected_vlan); - update_selectfield("#prefix", json.data.prefixes, json.data.selected_prefix); - $('#domain_id').val(json.data.domain_id); + update_selectfield( + "#vlan_id", + json.data.vlans, + json.data.selected_vlan + ); + update_selectfield( + "#prefix", + json.data.prefixes, + json.data.selected_prefix + ); + $("#domain_id").val(json.data.domain_id); update_address(); } ); @@ -23,7 +30,11 @@ $(document).ready(function() { $.getJSON( $SCRIPT_ROOT + "/network/_retrieve_subnets/" + scope_id + "/" + prefix, function(json) { - update_selectfield("#address", json.data.subnets, json.data.selected_subnet); + update_selectfield( + "#address", + json.data.subnets, + json.data.selected_subnet + ); update_gateway_first_and_last_ip(); } ); @@ -33,38 +44,40 @@ $(document).ready(function() { // Retrieve IPs for the selected subnet // and update the first and last ip select field var address = $("#address").val(); - $.getJSON( - $SCRIPT_ROOT + "/network/_retrieve_ips/" + address, - function(json) { - update_selectfield("#first_ip", json.data.ips, json.data.selected_first); - update_selectfield("#last_ip", json.data.ips.slice().reverse(), json.data.selected_last); - update_selectfield("#gateway", json.data.ips, json.data.selected_gateway); - } - ); + $.getJSON($SCRIPT_ROOT + "/network/_retrieve_ips/" + address, function( + json + ) { + update_selectfield("#first_ip", json.data.ips, json.data.selected_first); + update_selectfield( + "#last_ip", + json.data.ips.slice().reverse(), + json.data.selected_last + ); + update_selectfield("#gateway", json.data.ips, json.data.selected_gateway); + }); } // Populate the default values linked to the scope on first page load - if( $("#scope_id").length ) { + if ($("#scope_id").length) { update_scope_defaults(); } // Update the default values linked to the scope when changing it - $("#scope_id").on('change', function() { + $("#scope_id").on("change", function() { update_scope_defaults(); }); // Update address select field when changing prefix - $("#prefix").on('change', function() { + $("#prefix").on("change", function() { update_address(); }); // Update first and last ip select field when changing address - $("#address").on('change', function() { + $("#address").on("change", function() { update_gateway_first_and_last_ip(); }); - var networks_table = $("#networks_table").DataTable({ - "paging": false + var networks_table = $("#networks_table").DataTable({ + paging: false }); - }); diff --git a/app/static/js/profile.js b/app/static/js/profile.js index 9d2c67a74741da3c61ea3158746de5f667087a00..d358d8deae759b54098019688b6c91d920da3931 100644 --- a/app/static/js/profile.js +++ b/app/static/js/profile.js @@ -1,20 +1,18 @@ $(document).ready(function() { - var $copyTokenBtn = $("#copyToken"); - if( $copyTokenBtn.length ) { + if ($copyTokenBtn.length) { // Instantiate the clipboard only if the copyToken button exists var clipboard = new Clipboard($copyTokenBtn[0]); // show tooltip "Copied!" on success - clipboard.on('success', function(e) { - $copyTokenBtn.tooltip('enable'); - $copyTokenBtn.tooltip('show'); + clipboard.on("success", function(e) { + $copyTokenBtn.tooltip("enable"); + $copyTokenBtn.tooltip("show"); }); // disable tooltip when leaving button - $copyTokenBtn.on('mouseleave', function () { - $copyTokenBtn.tooltip('disable'); + $copyTokenBtn.on("mouseleave", function() { + $copyTokenBtn.tooltip("disable"); }); } - }); diff --git a/app/static/js/scopes.js b/app/static/js/scopes.js index 4bb63058d6424904982715b71fd25d640b1c218b..6a0c2519012b7fec5e23fcdd666cf7cc363a18ee 100644 --- a/app/static/js/scopes.js +++ b/app/static/js/scopes.js @@ -1,7 +1,5 @@ $(document).ready(function() { - - var scopes_table = $("#scopes_table").DataTable({ - "paging": false + var scopes_table = $("#scopes_table").DataTable({ + paging: false }); - }); diff --git a/app/static/js/tasks.js b/app/static/js/tasks.js index 80a75d0809e135b300fcad23c0330d5511229218..32291038ab37e51f15894dc090970a3e92bbb9c1 100644 --- a/app/static/js/tasks.js +++ b/app/static/js/tasks.js @@ -1,59 +1,64 @@ $(document).ready(function() { - function render_task_link(data) { // render funtion to create link to Task view page - if ( data === null ) { + if (data === null) { return data; } var url = $SCRIPT_ROOT + "/task/tasks/view/" + data; - return '<a href="' + url + '">' + data + '</a>'; + return '<a href="' + url + '">' + data + "</a>"; } - $("#allTasks").on('change', function() { + $("#allTasks").on("change", function() { // reload the data from the Ajax source tasks_table.ajax.reload(); }); - var tasks_table = $("#tasks_table").DataTable({ - "ajax": function(data, callback, settings) { - var allTasks = $('#allTasks').prop("checked"); + var tasks_table = $("#tasks_table").DataTable({ + ajax: function(data, callback, settings) { + var allTasks = $("#allTasks").prop("checked"); $.getJSON( $SCRIPT_ROOT + "/task/_retrieve_tasks?all=" + allTasks, function(json) { callback(json); - }); + } + ); }, - "pagingType": "full_numbers", - "pageLength": 20, - "lengthMenu": [[20, 50, 100, -1], [20, 50, 100, "All"]], - "order": [[2, 'desc']], - "columns": [ - { data: 'id', + pagingType: "full_numbers", + pageLength: 20, + lengthMenu: [ + [20, 50, 100, -1], + [20, 50, 100, "All"] + ], + order: [[2, "desc"]], + columns: [ + { + data: "id", render: function(data, type, row) { return render_task_link(data); } }, - { data: 'name' }, - { data: 'created_at' }, - { data: 'ended_at' }, - { data: 'status' }, - { data: null, + { data: "name" }, + { data: "created_at" }, + { data: "ended_at" }, + { data: "status" }, + { + data: null, render: function(data, type, row) { // render link to AWX job - if ( row.awx_job_id === null ) { + if (row.awx_job_id === null) { return null; } - return '<a href="' + row.awx_job_url + '">' + row.awx_job_id + '</a>'; + return '<a href="' + row.awx_job_url + '">' + row.awx_job_id + "</a>"; } }, - { data: 'depends_on', + { + data: "depends_on", render: function(data, type, row) { return render_task_link(data); } }, - { data: 'command' }, - { data: 'user' }, + { data: "command" }, + { data: "user" } ] }); - });