File: /var/www/vhost/disk-apps/teamdemo.sports-crowd.com/public/js/attributes.js
function create() {
$("#form_create").validator("update");
$("#form_create")
.validator("update")
.on("submit", function (e) {
if (e.isDefaultPrevented()) {
} else {
e.preventDefault();
var attribute_type_id = $(
" #form_create select[name='attribute_type_id']"
).val();
if (!attribute_type_id) {
swal(Lang.get("messagesClient.attribute_required"), {
icon: "error",
});
return;
}
$("#btn-create").addClass("displayNone");
$("#spinnerButton").removeClass("displayNone");
var info = {
name: $(" #form_create input[name='name']").val(),
display_name: $(
" #form_create input[name='display_name']"
).val(),
is_more_one: $("#is_more_one").is(":checked"),
required: $("#required").is(":checked"),
attribute_type_id,
active: $(" #form_create select[name='active']").val(),
store_type: localStorage.getItem("storeType")
};
swal(Lang.get("messagesClient.create_register"), {
buttons: {
cancel: "No",
Ok: true,
},
}).then((val) => {
if (val == "Ok") {
$.ajax({
url: "/attributes",
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",
"/attributes/" + localStorage.getItem("storeType")
);
}
});
} else {
swal(r.m, {
icon: "error",
});
$("#btn-create").removeClass("displayNone");
$("#spinnerButton").addClass("displayNone");
}
},
error: function (e) {
swal("¡Hubo un Error al crear registro!", {
icon: "error",
});
$("#btn-create").removeClass("displayNone");
$("#spinnerButton").addClass("displayNone");
},
});
} else {
$("#btn-create").removeClass("displayNone");
$("#spinnerButton").addClass("displayNone");
}
});
}
});
}
function clickEdit(value) {
_table = $("#example2").DataTable();
index = _table.page();
localStorage.setItem("attributesTableIndex", index);
$(location).attr("href", "/attributes/" + localStorage.getItem("storeType") + "/edit/" + value);
}
function edit() {
$("#form_edit").validator("update");
$("#form_edit")
.validator("update")
.on("submit", function (e) {
if (e.isDefaultPrevented()) {
} else {
e.preventDefault();
var attribute_type_id = $(
" #form_edit select[name='attribute_type_id']"
).val();
if (!attribute_type_id) {
swal(Lang.get("messagesClient.attribute_required"), {
icon: "error",
});
return;
}
$("#btn-edit").addClass("displayNone");
$("#spinnerButton").removeClass("displayNone");
var info = {
_method: $("input[name=_method]").val(),
name: $(" #form_edit input[name='name']").val(),
display_name: $(
" #form_edit input[name='display_name']"
).val(),
is_more_one: $("#is_more_one").is(":checked"),
required: $("#required").is(":checked"),
attribute_type_id,
active: $(" #form_edit select[name='active']").val(),
store_type: localStorage.getItem("storeType")
};
var id = $("#form_edit").attr("attribute_id");
swal(Lang.get("messagesClient.update_register"), {
buttons: {
cancel: "No",
Ok: true,
},
}).then((val) => {
if (val == "Ok") {
$.ajax({
url: "/attributes/" + 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",
"/attributes/" + localStorage.getItem("storeType")
);
}
});
} else {
swal(r.m, {
icon: "error",
});
$("#btn-edit").removeClass("displayNone");
$("#spinnerButton").addClass("displayNone");
}
},
error: function (e) {
swal("¡Hubo un Error al actualizar!", {
icon: "error",
});
$("#btn-edit").removeClass("displayNone");
$("#spinnerButton").addClass("displayNone");
},
});
} else {
$("#btn-edit").removeClass("displayNone");
$("#spinnerButton").addClass("displayNone");
}
});
}
});
}
/**Activar/Desactivar Banner usando switch*/
function chk(value) {
var state;
if ($("#Checkactive" + value).is(":checked")) {
state = 1;
} else {
state = 0;
}
var info = {
id: value,
state: state,
};
$.ajax({
url: "/attributes/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(r.m, {
icon: "success",
buttons: {
Ok: true,
},
});
} else {
swal(r.m, {
icon: "error",
});
}
},
error: function (e) {
swal("Error al actualizar registro", {
icon: "error",
});
},
});
}
function importFile() {
var fExcel = document.getElementById("importAttributes");
fExcel = fExcel.files[0];
if (fExcel) {
var formData = new FormData();
formData.append("importAttributes", fExcel);
formData.append("store_type", localStorage.getItem("storeType"));
$("#button-import").addClass("displayNone");
$("#spinner-button").removeClass("displayNone");
$.ajax({
type: "POST",
dataType: "json",
processData: false,
contentType: false,
headers: {
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
},
data: formData,
url: "/attributes/import",
success: function (r) {
if (r.r) {
swal(r.m, {
icon: "success",
buttons: {
Ok: true,
},
}).then((val) => {
if (val == "Ok") {
$(location).attr("href", "/attributes"+localStorage.getItem("storeType"));
}
});
} else {
swal("Error", r.m, "error");
$("#button-import").removeClass("displayNone");
$("#spinner-button").addClass("displayNone");
}
},
});
} else {
alert("No hay archivo.");
}
}