File: /var/www/vhost/disk-apps/demo.sports-crowd.com/public/js/positions.js
/**
* metodos para administrar Positions
*
*/
function create() {
$("#form_create").validator("update");
$("#form_create")
.validator("update")
.on("submit", function (e) {
if (e.isDefaultPrevented()) {
} else {
e.preventDefault();
$("#btn-create").addClass("displayNone");
$("#spinnerButton").removeClass("displayNone");
var info = {
name: $(" #form_create input[name='name']").val(),
order_by: $(" #form_create input[name='order_by']").val(),
};
swal(Lang.get("messagesClient.positions.tag_1"), {
buttons: {
cancel: "No",
Ok: true
}
}).then(val => {
if (val == "Ok") {
$.ajax({
url: "/positions",
type: "POST",
contentType: "application/json",
headers: {
"X-CSRF-TOKEN": $(
'meta[name="csrf-token"]'
).attr("content"),
"Content-Type": "application/json"
},
data: JSON.stringify(info),
success: function (r) {
if (r.r) {
swal(r.m, {
icon: "success",
buttons: {
Ok: true
}
}).then(val => {
if (val == "Ok") {
$(location).attr("href", "/positions");
}
});
} else {
swal("Error", r.m, "error");
$("#btn-create").removeClass("displayNone");
$("#spinnerButton").addClass("displayNone");
}
},
error: function (e) {
swal("Error", "¡Hubo un Error al crear!", "error");
$("#btn-create").removeClass("displayNone");
$("#spinnerButton").addClass("displayNone");
}
});
} else {
$("#btn-create").removeClass("displayNone");
$("#spinnerButton").addClass("displayNone");
}
});
}
});
}
function addRequiredCreate() {
$("#image").attr("required", "true");
}
function clickEdit(value) {
$(location).attr("href", "/positions/" + value + "/edit");
}
function edit() {
$("#form_edit").validator("update");
$("#form_edit")
.validator("update")
.on("submit", function (e) {
if (e.isDefaultPrevented()) {
} else {
e.preventDefault();
$("#btn-edit").addClass("displayNone");
$("#spinnerButton").removeClass("displayNone");
var info = {
_method: $("input[name=_method]").val(),
name: $(" #form_edit input[name='name']").val(),
order_by: $(" #form_edit input[name='order_by']").val()
};
var id = $("#form_edit").attr("position_id");
swal(Lang.get("messagesClient.positions.tag_2"), {
buttons: {
cancel: "No",
Ok: true
}
}).then(val => {
if (val == "Ok") {
$.ajax({
url: "/positions/" + id,
type: "PUT",
contentType: "application/json",
headers: {
"X-CSRF-TOKEN": $(
'meta[name="csrf-token"]'
).attr("content"),
"Content-Type": "application/json"
},
data: JSON.stringify(info),
success: function (r) {
if (r.r) {
swal(r.m, {
icon: "success",
buttons: {
Ok: true
}
}).then(val => {
if (val == "Ok") {
$(location).attr("href", "/positions");
}
});
} else {
swal("Error", r.m, "error");
$("#btn-edit").removeClass("displayNone");
$("#spinnerButton").addClass("displayNone");
}
},
error: function (e) {
swal("Error", "¡Hubo un Error al actualizar!", "error");
$("#btn-edit").removeClass("displayNone");
$("#spinnerButton").addClass("displayNone");
}
});
} else {
$("#btn-edit").removeClass("displayNone");
$("#spinnerButton").addClass("displayNone");
}
});
}
});
}
function setPageTable() {
$(location).attr("href", "/positions");
}
function chk(value) {
var state;
if ($("#Checkactive" + value).is(":checked")) {
state = 1;
} else {
state = 0;
}
var info = {
id: value,
state: state
};
$.ajax({
url: "/positions/active",
type: "POST",
contentType: "application/json",
headers: {
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
"Content-Type": "application/json"
},
data: JSON.stringify(info),
success: function (r) {
if (r.r) {
swal("Ok", r.m);
} else {
swal("Error", r.m, "error");
}
},
error: function (e) {
swal(
"Error",
Lang.get("messagesClient.positions.error_update_active"),
"error"
);
}
});
}
function clickDelete(value) {
swal(Lang.get("messagesClient.positions.tag_3"), {
buttons: {
cancel: "No",
Ok: true
}
}).then(val => {
if (val == "Ok") {
var info = {
_method: "DELETE"
};
$.ajax({
url: "/positions/" + value,
type: "POST",
contentType: "application/json",
headers: {
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr(
"content"
),
"Content-Type": "application/json"
},
data: JSON.stringify(info),
success: function (r) {
if (r.r) {
swal(r.m, {
icon: "success",
buttons: {
Ok: true
}
}).then(val => {
if (val == "Ok") {
$(location).attr("href", "/positions");
}
});
} else {
swal("Error", r.m, { icon: "error" });
}
},
error: function (e) {
swal(
"Error",
Lang.get("messagesClient.positions.error_delete"),
"error"
);
}
});
}
});
}