").attr({
"id": "resource-" + resourceID,
"class": "card-link",
"href": "#",
"data-resourceID": resourceID,
"onclick": "handleResourceClicked(event, " + resourceID + ")"
}).text(cur.resourceName).appendTo(body);
}
}
buildCard("lang", lang.langID, lang.langName, lang.languages, lang.langDescription, body);
}
function showLang(langID) {
deselectNav();
$("#mainList").empty();
$("").attr("id", "lang-" + langID).appendTo($("#mainList"));
$.ajax({
url: "lang.php?langID=" + langID,
type: "GET",
success: function (result) { addLang(result) },
error: function (result) { displayError(result) }
});
}
function initEditLang(langID) {
$("#editLangID").val(langID);
$("#txtEditLangName").val($("#lang-" + langID + "-name").text());
$("#txtEditLangDesc").val($("#lang-" + langID + "-description").text());
buildLangSelect();
selectList = $("#lang-" + langID + "-card").data("langs");
$("#editLangModal").modal('show');
}
function saveLang() {
var changeName = $("#editLangNameChk").prop("checked");
var changeLang = $("#editLangLangsChk").prop("checked");
var changeDesc = $("#editLangDescChk").prop("checked");
if (!changeName && !changeDesc && !changeLang)
return;
var langID = $("#editLangID").val();
var langName = $("#txtEditLangName").val().trim();
var data = { langID: langID };
if (changeName && langName == "") {
displayError({responseText: "Name cannot be empty"});
return;
}
if (changeName && langName != "")
data['langName'] = langName;
if (changeDesc)
data['langDescription'] = $("#txtEditLangDesc").val();
if (changeName || changeDesc) {
$.ajax({
url: "lang.php",
type: "PUT",
data: data,
success: function () { successAlert("Successfully saved language: " + langName, "lang") },
error: displayError
});
}
if (changeLang) {
var curLangsList = $("#lang-" + langID + "-card").data("langs");
var newLangsList = $("#selectEditLangLangs").val().map(function (item) {
return parseInt(item, 10);
});
var langsToAdd = inANotInB(newLangsList, curLangsList);
manageAssocLang("lang", "PUT", langID, langsToAdd);
var langsToDelete = inANotInB(curLangsList, newLangsList);
manageAssocLang("lang", "DELETE", langID, langsToDelete);
}
}
function handleLangClicked(evt, langID) {
// TODO: show related snippets and resources
evt.preventDefault();
showLang(langID);
}