app.us cleanup, some refactor using GPT

This commit is contained in:
Hash Borgir 2023-05-30 14:24:18 -06:00
parent 1f7ac14963
commit 64bd1caa03

View File

@ -89,25 +89,22 @@ $(document).ready(function () {
$('[data-toggle="tooltip"]').tooltip()
})
// armor/misc/weapons select dropdown chagne function
$('.w-select').change(function () {
$('.a-select,.m-select').each(function (i, v) {
v.value = '';
v.required = '';
});
x = $(this).find(':selected').text();
y = document.getElementById('item');
y.value = x;
});
$('.a-select').change(function () {
$('.w-select,.m-select').each(function (i, v) {
v.value = '';
v.required = '';
});
x = $(this).find(':selected').text();
y = document.getElementById('item');
y.value = x;
@ -117,8 +114,6 @@ $(document).ready(function () {
v.value = '';
v.required = '';
});
x = $(this).find(':selected').text();
y = document.getElementById('item');
y.value = x;
@ -142,46 +137,16 @@ $(document).ready(function () {
})
});
// $('.help').prev().hover(function () {
// $(".fa-help").remove();
// $(this).next().next().fadeToggle().focus().css({
// "position": "absolute",
// "z-index": "1000",
// "background": "#eee",
// "color": "black !important",
// "border": "1px solid #aaa",
// "width": "300px",
// })
// });
$('.form-text').click(function () {
$(this).fadeOut("slow");
});
$('').change(function () {
if (this.checked) {
$('option[disabled="disabled"]').hide();
} else {
$('option[disabled="disabled"]').show();
}
});
$('input[name="invfile"]').keyup(function () {
invImg = docpath + '/img/items/' + this.value + ".png";
$(".item").attr("src", invImg);
});
// every time we change a prop dropdown,
//
// 1 send to server,
// 2 grab string,
// 3 update item display
// every time we change a prop dropdown,send to server, grab string, update item display
$('select[name^="prop"]').change(function () {
prop = capitalizeFirstLetter($(this).attr("name"));
propNum = prop.substring(4);
@ -196,233 +161,28 @@ $(document).ready(function () {
});
});
// Properties's par/min/max onchange function, updated item string stats
function createChangeHandler(propNumber) {
var prop = "Prop" + propNumber;
/*
* Properties/par/min/max onchange function, updated item string stats
*
*
*
*
*
*
*
*
return function () {
var par = $('.par' + propNumber).val() || 0;
var min = $('.min' + propNumber).val();
var max = $('.max' + propNumber).val();
var val = escape($("*[name='prop" + propNumber + "'").val());
**/
$('.par1, .min1, .max1').change(function () {
prop = "Prop1";
par = $('.par1').val();
if (par == '')
par = 0;
min = $('.min1').val();
max = $('.max1').val();
val = escape($("*[name='prop1'").val());
$.get(`/ajax/uniqueitems.php?cmd=getString&prop=${val}&par=${par}&min=${min}&max=${max}`, function (data) {
console.log(data);
$(`.item_stats ul .${prop}`).html(data);
});
});
$('.par2, .min2, .max2').change(function () {
prop = "Prop2";
par = $('.par2').val();
if (par == '')
par = 0;
min = $('.min2').val();
max = $('.max2').val();
val = escape($("*[name='prop2'").val());
$.get(`/ajax/uniqueitems.php?cmd=getString&prop=${val}&par=${par}&min=${min}&max=${max}`, function (data) {
console.log(data);
$(`.item_stats ul .${prop}`).html(data);
});
});
$('.par3, .min3, .max3').change(function () {
prop = "Prop3";
par = $('.par3').val();
if (par == '')
par = 0;
min = $('.min3').val();
max = $('.max3').val();
val = escape($("*[name='prop3'").val());
$.get(`/ajax/uniqueitems.php?cmd=getString&prop=${val}&par=${par}&min=${min}&max=${max}`, function (data) {
console.log(data);
$(`.item_stats ul .${prop}`).html(data);
});
});
$('.par4, .min4, .max4').change(function () {
prop = "Prop4";
par = $('.par4').val();
if (par == '')
par = 0;
min = $('.min4').val();
max = $('.max4').val();
val = escape($("*[name='prop4'").val());
$.get(`/ajax/uniqueitems.php?cmd=getString&prop=${val}&par=${par}&min=${min}&max=${max}`, function (data) {
console.log(data);
$(`.item_stats ul .${prop}`).html(data);
});
});
$('.par5, .min5, .max5').change(function () {
prop = "Prop5";
par = $('.par5').val();
if (par == '')
par = 0;
min = $('.min5').val();
max = $('.max5').val();
val = escape($("*[name='prop5'").val());
$.get(`/ajax/uniqueitems.php?cmd=getString&prop=${val}&par=${par}&min=${min}&max=${max}`, function (data) {
console.log(data);
$(`.item_stats ul .${prop}`).html(data);
});
});
$('.par6, .min6, .max6').change(function () {
prop = "Prop6";
par = $('.par6').val();
if (par == '')
par = 0;
min = $('.min6').val();
max = $('.max6').val();
val = escape($("*[name='prop6'").val());
$.get(`/ajax/uniqueitems.php?cmd=getString&prop=${val}&par=${par}&min=${min}&max=${max}`, function (data) {
console.log(data);
$(`.item_stats ul .${prop}`).html(data);
});
});
$('.par7, .min7, .max7').change(function () {
prop = "Prop7";
par = $('.par7').val();
if (par == '')
par = 0;
min = $('.min7').val();
max = $('.max7').val();
val = escape($("*[name='prop7'").val());
$.get(`/ajax/uniqueitems.php?cmd=getString&prop=${val}&par=${par}&min=${min}&max=${max}`, function (data) {
console.log(data);
$(`.item_stats ul .${prop}`).html(data);
});
});
$('.par8, .min8, .max8').change(function () {
prop = "Prop8";
par = $('.par8').val();
if (par == '')
par = 0;
min = $('.min8').val();
max = $('.max8').val();
val = escape($("*[name='prop8'").val());
$.get(`/ajax/uniqueitems.php?cmd=getString&prop=${val}&par=${par}&min=${min}&max=${max}`, function (data) {
console.log(data);
$(`.item_stats ul .${prop}`).html(data);
});
});
$('.par9, .min9, .max9').change(function () {
prop = "Prop9";
par = $('.par9').val();
if (par == '')
par = 0;
min = $('.min9').val();
max = $('.max9').val();
val = escape($("*[name='prop9'").val());
$.get(`/ajax/uniqueitems.php?cmd=getString&prop=${val}&par=${par}&min=${min}&max=${max}`, function (data) {
console.log(data);
$(`.item_stats ul .${prop}`).html(data);
});
});
$('.par10, .min10, .max10').change(function () {
prop = "Prop10";
par = $('.par10').val();
if (par == '')
par = 0;
min = $('.min10').val();
max = $('.max10').val();
val = escape($("*[name='prop10'").val());
$.get(`/ajax/uniqueitems.php?cmd=getString&prop=${val}&par=${par}&min=${min}&max=${max}`, function (data) {
console.log(data);
$(`.item_stats ul .${prop}`).html(data);
});
});
$('.par11, .min11, .max11').change(function () {
prop = "Prop11";
par = $('.par11').val();
if (par == '')
par = 0;
min = $('.min11').val();
max = $('.max11').val();
val = escape($("*[name='prop11'").val());
$.get(`/ajax/uniqueitems.php?cmd=getString&prop=${val}&par=${par}&min=${min}&max=${max}`, function (data) {
console.log(data);
$(`.item_stats ul .${prop}`).html(data);
});
});
$('.par12, .min12, .max12').change(function () {
prop = "Prop12";
par = $('.par12').val();
if (par == '')
par = 0;
min = $('.min12').val();
max = $('.max12').val();
val = escape($("*[name='prop12'").val());
$.get(`/ajax/uniqueitems.php?cmd=getString&prop=${val}&par=${par}&min=${min}&max=${max}`, function (data) {
console.log(data);
$(`.item_stats ul .${prop}`).html(data);
});
});
/*
*
* END on change for inputs
*
*
*
* update item index, lvl, lvl req
*
*
*
**/
};
}
// Run the loop 12 times for 12 props, and handle the change event
for (var i = 1; i <= 12; i++) {
$('.par' + i + ', .min' + i + ', .max' + i).change(createChangeHandler(i));
}
// index, lvl, lvl req change functions
$("input[name='index']").keyup(function () {
$(".itemindex").html($(this).val());
});
@ -441,15 +201,10 @@ $(document).ready(function () {
$(".item").attr("src", "/img/items/1.png");
$(".item_debug_link").attr('href', "/ajax/uniqueitems.php?cmd=getUniqueItem&index=" + this.value)
$.get("/ajax/uniqueitems.php?cmd=getUniqueItem&index=" + this.value, function (data) {
debugData = (JSON.stringify(data, null, 4));
$('.debug, .debug_preview').html(syntaxHighlight(debugData));
props = data.props;
// update preview
//$('.item_stats div').hide().html("<p></p>");
invImg = docpath + '/img/items/' + data.invfile + ".png";
$(".item").attr("src", invImg);
$(".item").onerror = function () {
@ -459,14 +214,12 @@ $(document).ready(function () {
type = data["*type"];
lvlreq = data["lvl req"];
base = data.baseItemInfo;
$('.item_stats ul .itemindex').html(data.index);
$('.item_stats ul .itemtype').html(`(${type})`);
$('.item_stats ul .itemlvl').html(`Level: ${base.level}`);
$('.item_stats ul .itemlvlreq').html(`Level Required: ${lvlreq}`);
$('.item_stats ul .itemcode').html(`Item Code: (${base.code})`);
if (base.reqstr) {
@ -477,19 +230,12 @@ $(document).ready(function () {
}
if (base['gemsockets']) {
$('.item_stats ul .itemgemsockets').html(`Max Sockets: (${base.gemsockets})`);
}
/*
* THIS LINE BREAKS hidden fields and set them to blank.
*
*/
// THIS LINE BREAKS hidden fields and set them to blank.
$('.props-container select, .props-container input').val('');
// clear some blue text, I forgot what
$('.item_stats ul .blue').each(function (i, v) {
$(v).html("");
});
@ -501,20 +247,6 @@ $(document).ready(function () {
}
});
// add the rest of the prop li's here
// var i;
// for (i = 1; i <= 12; i++) {
// if (props['Prop' + i]['string'] && props['Prop' + i]['string'] !== '') {
// $(`.item_stats ul .Prop${i}`).html(`${data.index}`);
// }
// }
//$('.item_stats div').show();
//console.log(data['lvl req']);
$.each(data, function (i, v) {
$('*[name="' + i + '"]').val(v);
if (i == 'code') {
@ -525,11 +257,11 @@ $(document).ready(function () {
});
});
// Debug preview slide down box
$(".btnDebug").click(function () {
$(".debug_preview").slideToggle();
});
// cmd = sortBy
$('input[name="sort"]').change(function () {
$.get("/ajax/uniqueitems.php?cmd=sortBy&sort=" + this.value, function (data) {
@ -547,29 +279,19 @@ $(document).ready(function () {
searchbox = document.getElementById('search');
searchbox.addEventListener('input', search);
$('input[name="theme"]').change(function () {
modname = $('input[name="modname"]').val();
$.get("/res/css.php?theme=" + this.value + "&modname=" + modname, function (data) {
location.reload();
});
// $('body').toggleClass("body-dark");
// $('.container-top').toggleClass("container-top-dark");
// $('input').toggleClass("input-dark");
// $('select').toggleClass("select-dark");
// $('option').toggleClass("option-dark");
// $('.col-2,.col-3,.col-4').attr({"style":""});
});
//genDocUniqueItems
$("#Unique .btnDocs").click(function () {
window.open('/genDocs.php?cmd=genDocUniqueItems', '_blank');
});
// Delete button event
$('.btn-delete').click(function (event) {
event.preventDefault(); // Prevent default button click behavior
@ -582,16 +304,13 @@ $(document).ready(function () {
});
});
// Save button event
$('.btn-save').click(function (event) {
event.preventDefault(); // Prevent default button click behavior
// Get form data
var formData = $(".uniqueform").serialize();
// delete item index
$.get('/ajax/uniqueitems.php?cmd=save&' + formData, function (response) {
// Handle the response from the server