File: /var/www/vhost/disk-apps/qas.sports-crowd.com/public/js/welcome_logo.js
/**
* metodos para administrar Welcome Logo
*
*/
function saveImage(id) {
console.log("llamando imagen");
var fImage = document.getElementById("image");
fImage = fImage.files[0];
if (fImage) {
var formData = new FormData();
formData.append("id", id);
formData.append("image", fImage);
$.ajax({
type: "POST",
dataType: "json",
processData: false,
contentType: false,
headers: {
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
},
data: formData,
url: "/welcome_logo/saveImage",
success: function (r) {
if (r.r) {
swal(r.m, {
icon: "success",
buttons: {
Ok: true,
},
}).then((val) => {
if (val == "Ok") {
$(location).attr("href", "/welcome_logo");
}
});
} else {
swal("Ok", "¡Error al cargar imagen del welcome_logo!", "error");
$("#btn-create-category").prop("disabled", false);
}
},
error: function (e) {
swal("Ok", "¡Error al cargar imagen del welcome_logo!", "error");
$("#btn-create-category").prop("disabled", false);
},
});
}
}
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(),
active: $(" #active").val()
};
swal(Lang.get("messagesClient.welcome_logo.tag_1"), {
buttons: {
cancel: "No",
Ok: true,
},
}).then((val) => {
if (val == "Ok") {
$.ajax({
url: "/welcome_logo",
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) {
var id = r.data;
var img = document.getElementById("image");
var img = img.files[0];
console.log(img);
if (img != null) {
saveImage(id);
} else {
swal(r.m, {
icon: "success",
buttons: {
Ok: true,
},
}).then((val) => {
if (val == "Ok") {
$(location).attr(
"href",
"/welcome_logo"
);
}
});
}
} else {
swal(r.m, "error");
$("#btn-create").removeClass("displayNone");
$("#spinnerButton").addClass("displayNone");
}
},
error: function (e) {
swal("¡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", "/welcome_logo/" + 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(),
active: $(" #active").val()
};
var id = $("#form_edit").attr("welcome_logo_id");
swal(Lang.get("messagesClient.welcome_logo.tag_2"), {
buttons: {
cancel: "No",
Ok: true,
},
}).then((val) => {
if (val == "Ok") {
$.ajax({
url: "/welcome_logo/" + 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) {
var img = document.getElementById("image");
var img = img.files[0];
if (img != null) {
saveImage(id);
} else {
swal(r.m, {
icon: "success",
buttons: {
Ok: true,
},
}).then((val) => {
if (val == "Ok") {
$(location).attr(
"href",
"/welcome_logo"
);
}
});
}
} else {
swal(r.m, "error");
$("#btn-edit").removeClass("displayNone");
$("#spinnerButton").addClass("displayNone");
}
},
error: function (e) {
swal("¡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", "/welcome_logo");
}
function chk(value) {
var state;
if ($("#Checkactive" + value).is(":checked")) {
state = 1;
} else {
state = 0;
}
var info = {
id: value,
state: state,
};
$.ajax({
url: "/welcome_logo/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.welcome_logo.error_update_active"),
"error"
);
},
});
}
function clickDelete(value) {
swal(Lang.get("messagesClient.welcome_logo.tag_6"), {
buttons: {
cancel: "No",
Ok: true,
},
}).then((val) => {
if (val == "Ok") {
var info = {
_method: "DELETE",
};
$.ajax({
url: "/welcome_logo/" + 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", "/welcome_logo");
}
});
} else {
swal(r.m, { icon: "error" });
}
},
error: function (e) {
swal(
"Error",
Lang.get("messagesClient.welcome_logo.error_delete"),
"error"
);
},
});
}
});
}