Skip to content
Snippets Groups Projects
Commit 101f7ff5 authored by Benjamin Bertrand's avatar Benjamin Bertrand
Browse files

Format javascript files

parent 1de56520
No related branches found
No related tags found
No related merge requests found
$(document).ready(function() {
$(document).ready(function () {
var attributes_table = $("#attributes_table").DataTable({
ajax: function(data, callback, settings) {
ajax: function (data, callback, settings) {
var kind = $("li a.nav-link.active").text();
$.getJSON(
$SCRIPT_ROOT + "/inventory/_retrieve_attributes/" + kind,
function(json) {
function (json) {
callback(json);
}
);
......@@ -15,49 +15,49 @@ $(document).ready(function() {
targets: [0],
orderable: false,
className: "text-center align-middle",
render: function(data, type, row) {
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 + ">"
);
},
width: "5%"
width: "5%",
},
{
targets: [1],
orderable: false,
render: function(data, type, row) {
render: function (data, type, row) {
// render QR code from base64 string
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() {
$("#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,
data: JSON.stringify({
id: $(this).val(),
checked: this.checked
checked: this.checked,
}),
contentType: "application/json"
contentType: "application/json",
});
});
var attributes_favorites_table = $("#attributes_favorites_table").DataTable({
ajax: function(data, callback, settings) {
ajax: function (data, callback, settings) {
$.getJSON(
$SCRIPT_ROOT + "/inventory/_retrieve_attributes_favorites",
function(json) {
function (json) {
callback(json);
}
);
......@@ -67,15 +67,15 @@ $(document).ready(function() {
{
targets: [0],
orderable: false,
render: function(data, type, row) {
render: function (data, type, row) {
// render QR code from base64 string
return (
'<img class="img-fluid" src="data:image/png;base64,' + data + '">'
);
},
width: "10%"
}
width: "10%",
},
],
paging: false
paging: false,
});
});
$(document).ready(function() {
$.fn.focusWithoutScrolling = function() {
$(document).ready(function () {
$.fn.focusWithoutScrolling = function () {
var x = window.scrollX,
y = window.scrollY;
this.focus();
......@@ -15,7 +15,7 @@ $(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) {
$("#ics_id").keydown(function (event) {
if (event.keyCode == 13) {
event.preventDefault();
var value = $(this).val();
......@@ -28,7 +28,7 @@ $(document).ready(function() {
// Prevent enter key to submit the form when scanning serial number
// 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) {
$("#serial_number").keydown(function (event) {
if (event.keyCode == 13) {
event.preventDefault();
$("#submit").focusWithoutScrolling();
......@@ -36,13 +36,13 @@ $(document).ready(function() {
}
});
$("#clear").click(function() {
$("#clear").click(function () {
// clear all select fields
$("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();
});
});
......@@ -5,14 +5,11 @@ function flash_alert(message, category) {
'<button type="button" class="close" data-dismiss="alert" aria-label="Close">';
htmlString +=
'<span aria-hidden="true">&times;</span></button>' + message + "</div>";
$(htmlString)
.prependTo("#mainContent")
.hide()
.slideDown();
$(htmlString).prependTo("#mainContent").hide().slideDown();
}
function remove_alerts() {
$(".alert").slideUp("normal", function() {
$(".alert").slideUp("normal", function () {
$(this).remove();
});
}
......@@ -33,7 +30,7 @@ function check_job_status(status_url, $modal) {
dataType: "json",
url: status_url,
cache: false,
success: function(data, status, request) {
success: function (data, status, request) {
switch (data.status) {
case "unknown":
$modal.modal("hide");
......@@ -58,11 +55,11 @@ function check_job_status(status_url, $modal) {
}
default:
// queued/started/deferred
setTimeout(function() {
setTimeout(function () {
check_job_status(status_url, $modal);
}, 500);
}
}
},
});
}
......@@ -70,17 +67,13 @@ function check_job_status(status_url, $modal) {
function update_selectfield(field_id, data, selected_value) {
var $field = $(field_id);
$field.empty();
$.map(data, function(option, index) {
$.map(data, function (option, index) {
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 == "") {
$field.prop("disabled", true);
......@@ -98,9 +91,9 @@ function update_stack_member() {
$.getJSON(
$SCRIPT_ROOT + "/inventory/_retrieve_free_stack_members/" + host_id,
{
ics_id: $("#ics_id").val()
ics_id: $("#ics_id").val(),
},
function(json) {
function (json) {
update_selectfield(
"#stack_member",
json.data.stack_members,
......@@ -111,13 +104,13 @@ function update_stack_member() {
);
}
$(document).ready(function() {
$(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
// When starting to type again, we want to remove the error
// message to not confuse the user
$('input[type="text"]').keyup(function(event) {
$('input[type="text"]').keyup(function (event) {
$(this).removeClass("is-invalid");
});
......
$(document).ready(function() {
$(document).ready(function () {
var domains_table = $("#domains_table").DataTable({
paging: false
paging: false,
});
});
$(document).ready(function() {
$(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();
});
});
$(document).ready(function() {
$(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
var scope_id = $("#scope_id").val();
$.getJSON(
$SCRIPT_ROOT + "/network/_retrieve_scope_defaults/" + scope_id,
function(json) {
function (json) {
update_selectfield(
"#vlan_id",
json.data.vlans,
......@@ -29,7 +29,7 @@ $(document).ready(function() {
var prefix = $("#prefix").val();
$.getJSON(
$SCRIPT_ROOT + "/network/_retrieve_subnets/" + scope_id + "/" + prefix,
function(json) {
function (json) {
update_selectfield(
"#address",
json.data.subnets,
......@@ -44,7 +44,7 @@ $(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(
$.getJSON($SCRIPT_ROOT + "/network/_retrieve_ips/" + address, function (
json
) {
update_selectfield("#first_ip", json.data.ips, json.data.selected_first);
......@@ -63,21 +63,21 @@ $(document).ready(function() {
}
// 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
paging: false,
});
});
$(document).ready(function() {
$(document).ready(function () {
var $copyTokenBtn = $("#copyToken");
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) {
clipboard.on("success", function (e) {
$copyTokenBtn.tooltip("enable");
$copyTokenBtn.tooltip("show");
});
// disable tooltip when leaving button
$copyTokenBtn.on("mouseleave", function() {
$copyTokenBtn.on("mouseleave", function () {
$copyTokenBtn.tooltip("disable");
});
}
......
$(document).ready(function() {
$(document).ready(function () {
var scopes_table = $("#scopes_table").DataTable({
paging: false
paging: false,
});
});
$(document).ready(function() {
$(document).ready(function () {
function render_task_link(data) {
// render funtion to create link to Task view page
if (data === null) {
......@@ -8,17 +8,17 @@ $(document).ready(function() {
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) {
ajax: function (data, callback, settings) {
var allTasks = $("#allTasks").prop("checked");
$.getJSON(
$SCRIPT_ROOT + "/task/_retrieve_tasks?all=" + allTasks,
function(json) {
function (json) {
callback(json);
}
);
......@@ -27,15 +27,15 @@ $(document).ready(function() {
pageLength: 20,
lengthMenu: [
[20, 50, 100, -1],
[20, 50, 100, "All"]
[20, 50, 100, "All"],
],
order: [[2, "desc"]],
columns: [
{
data: "id",
render: function(data, type, row) {
render: function (data, type, row) {
return render_task_link(data);
}
},
},
{ data: "name" },
{ data: "created_at" },
......@@ -43,22 +43,22 @@ $(document).ready(function() {
{ data: "status" },
{
data: null,
render: function(data, type, row) {
render: function (data, type, row) {
// render link to AWX job
if (row.awx_job_id === null) {
return null;
}
return '<a href="' + row.awx_job_url + '">' + row.awx_job_id + "</a>";
}
},
},
{
data: "depends_on",
render: function(data, type, row) {
render: function (data, type, row) {
return render_task_link(data);
}
},
},
{ data: "command" },
{ data: "user" }
]
{ data: "user" },
],
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment