Clean up code
This commit is contained in:
parent
f213c5b104
commit
afcfa22b8e
14
js/lang.js
14
js/lang.js
|
@ -17,14 +17,14 @@ $(document).ready(function () {
|
||||||
|
|
||||||
function addLangLangs(langID, langName, langIDList) {
|
function addLangLangs(langID, langName, langIDList) {
|
||||||
if (langIDList != null) {
|
if (langIDList != null) {
|
||||||
for (var i = 0; i < langIDList.length; i++) {
|
langIDList.forEach(function (item) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "lang.php",
|
url: "lang.php",
|
||||||
type: "PUT",
|
type: "PUT",
|
||||||
data: {langID: langID, associatedLang: langIDList[i]},
|
data: {langID: langID, associatedLang: item},
|
||||||
error: displayError
|
error: displayError
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
successAlert("Successfully Added language: " + langName, "lang");
|
successAlert("Successfully Added language: " + langName, "lang");
|
||||||
|
@ -46,15 +46,15 @@ function loadLangs() {
|
||||||
|
|
||||||
function addLangs(langList) {
|
function addLangs(langList) {
|
||||||
var mainList = $("#mainList");
|
var mainList = $("#mainList");
|
||||||
for (var i = 0; i < langList.length; i++) {
|
langList.forEach(function (item) {
|
||||||
$("<div>").attr({ "id": "lang-" + langList[i].langID }).appendTo(mainList);
|
$("<div>").attr({ "id": "lang-" + item.langID }).appendTo(mainList);
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "lang.php?langID=" + langList[i].langID,
|
url: "lang.php?langID=" + item.langID,
|
||||||
type: "GET",
|
type: "GET",
|
||||||
success: function (result) { addLang(result) },
|
success: function (result) { addLang(result) },
|
||||||
error: function (result) { displayError(result) }
|
error: function (result) { displayError(result) }
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function addLang(lang) {
|
function addLang(lang) {
|
||||||
|
|
41
js/main.js
41
js/main.js
|
@ -7,7 +7,9 @@ $(document).ready(function () {
|
||||||
$("#addLangTab").tab("show");
|
$("#addLangTab").tab("show");
|
||||||
$(".addField").val("");
|
$(".addField").val("");
|
||||||
buildLangSelect();
|
buildLangSelect();
|
||||||
}).on("shown.bs.modal", function (e) { $("#txtLangName").focus(); });
|
}).on("shown.bs.modal", function (e) {
|
||||||
|
$("#txtLangName").focus();
|
||||||
|
});
|
||||||
|
|
||||||
$("#btnAddItem").click(addNewItem);
|
$("#btnAddItem").click(addNewItem);
|
||||||
$(".clearLangSelect").click(function () { $(".langSelect").val([]); });
|
$(".clearLangSelect").click(function () { $(".langSelect").val([]); });
|
||||||
|
@ -26,14 +28,14 @@ function buildLangSelect() {
|
||||||
function addSelectLangs(langList) {
|
function addSelectLangs(langList) {
|
||||||
var selectors = $(".langSelect");
|
var selectors = $(".langSelect");
|
||||||
selectors.empty();
|
selectors.empty();
|
||||||
for (let cur of langList) {
|
langList.forEach(function (cur) {
|
||||||
$("<option>").val(cur.langID).text(cur.langName).appendTo(selectors);
|
$("<option>").val(cur.langID).text(cur.langName).appendTo(selectors);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkBoxChange() {
|
function checkBoxChange() {
|
||||||
var me = $(this);
|
var chk = $(this);
|
||||||
$(me.data("for")).attr("disabled", !me.prop("checked"));
|
$(chk.data("for")).attr("disabled", !chk.prop("checked"));
|
||||||
}
|
}
|
||||||
|
|
||||||
function addNewItem() {
|
function addNewItem() {
|
||||||
|
@ -104,7 +106,7 @@ function addNewItem() {
|
||||||
function successAlert(text, type) {
|
function successAlert(text, type) {
|
||||||
var alert = $("#successAlert");
|
var alert = $("#successAlert");
|
||||||
|
|
||||||
if (alert.attr("display") == "none") {
|
if (alert.attr("display") != "none") {
|
||||||
alert.slideUp();
|
alert.slideUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,24 +147,27 @@ function buildCard(type, id, name, languageList, DescriptionText, body) {
|
||||||
|
|
||||||
var langString = [];
|
var langString = [];
|
||||||
if (languageList != null && languageList.length > 0) {
|
if (languageList != null && languageList.length > 0) {
|
||||||
for (var i = 0; i < languageList.length; i++) {
|
languageList.forEach(function (cur) {
|
||||||
var cur = languageList[i];
|
langString.push(cur.langID);
|
||||||
langString[i] = cur.langID;
|
|
||||||
$("<a>").attr({
|
$("<a>").attr({
|
||||||
"class": "card-link",
|
"class": "card-link",
|
||||||
"href": "#",
|
"href": "#",
|
||||||
"onClick": "handleLangClicked(event, " + cur.langID + ")"
|
"onClick": "handleLangClicked(event, " + cur.langID + ")"
|
||||||
}).text(cur.langName).appendTo(langList);
|
}).text(cur.langName).appendTo(langList);
|
||||||
}
|
});
|
||||||
card.attr("data-langs", JSON.stringify(langString));
|
card.attr("data-langs", JSON.stringify(langString));
|
||||||
} else {
|
} else {
|
||||||
card.attr("data-langs", "[]");
|
card.attr("data-langs", "[]");
|
||||||
}
|
}
|
||||||
|
|
||||||
$('<p>').attr("id", type + "-" + id + "-description").addClass("card-text").text(DescriptionText).appendTo(cardBody);
|
$('<p>').attr("id", type + "-" + id + "-description")
|
||||||
cardBody.append(body);
|
.addClass("card-text")
|
||||||
|
.text(DescriptionText)
|
||||||
|
.appendTo(cardBody);
|
||||||
|
|
||||||
|
cardBody.append(body);
|
||||||
card.append(cardBody);
|
card.append(cardBody);
|
||||||
|
|
||||||
card.appendTo($("#" + type + "-" + id));
|
card.appendTo($("#" + type + "-" + id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,7 +188,7 @@ function editClicked() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function manageAssocLang(type, action, id, langList) {
|
function manageAssocLang(type, action, id, langList) {
|
||||||
for (let item of langList) {
|
langList.forEach(function (item) {
|
||||||
var data = { langID: item };
|
var data = { langID: item };
|
||||||
data[type + "ID"] = id;
|
data[type + "ID"] = id;
|
||||||
$.ajax({
|
$.ajax({
|
||||||
|
@ -192,7 +197,7 @@ function manageAssocLang(type, action, id, langList) {
|
||||||
data: data,
|
data: data,
|
||||||
error: displayError
|
error: displayError
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteClicked() {
|
function deleteClicked() {
|
||||||
|
@ -224,16 +229,18 @@ function deselectNav() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function displayError(error, str) {
|
function displayError(error, str) {
|
||||||
console.log(error);
|
console.error(error);
|
||||||
$("#errorText").text(error.responseText);
|
$("#errorText").text(error.responseText);
|
||||||
$("#errorModal").modal('show');
|
$("#errorModal").modal('show');
|
||||||
}
|
}
|
||||||
|
|
||||||
function inANotInB(a, b) {
|
function inANotInB(a, b) {
|
||||||
var list = [];
|
var list = [];
|
||||||
for (let item of a) {
|
|
||||||
|
a.forEach(function (item) {
|
||||||
if (b.indexOf(item) == -1)
|
if (b.indexOf(item) == -1)
|
||||||
list.push(item);
|
list.push(item);
|
||||||
}
|
});
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue