65 lines
2.3 KiB
JavaScript
65 lines
2.3 KiB
JavaScript
function changeResourceSelection(popupId, url, listId, listItemIdPrefix, checkBoxIdPrefix) {
|
|
var selectedOids = [];
|
|
var oidString = "";
|
|
|
|
$("#" + popupId + " input:checked").each(function () {
|
|
var id = $(this).attr("id");
|
|
|
|
selectedOids.push(id.split("-")[1]);
|
|
});
|
|
|
|
for (var i = 0; i < selectedOids.length; i++) {
|
|
oidString += selectedOids[i] + ",";
|
|
}
|
|
|
|
$.get(url, { resourceOids: oidString }).done(function (jsonResult) {
|
|
updateSelectedResourceList(jsonResult, listId, listItemIdPrefix, popupId, checkBoxIdPrefix, url);
|
|
});
|
|
}
|
|
|
|
function updateSelectedResourceList(jsonResult, listId, listItemIdPrefix, popupId, checkBoxIdPrefix, url) {
|
|
var list = $("#" + listId);
|
|
|
|
list.empty();
|
|
|
|
if (isEmptyOrSpaces(jsonResult)) {
|
|
return;
|
|
}
|
|
|
|
var resourceList = $.parseJSON(jsonResult);
|
|
|
|
$.each(resourceList, function (index, customListItem) {
|
|
var listItemId = listItemIdPrefix + customListItem.ResourceOid;
|
|
var checkBoxId = "resource-" + customListItem.ResourceOid + checkBoxIdPrefix + "";
|
|
|
|
var html =
|
|
"<div class=\"list-group-item my-auto\" id=\"" + listItemId + "\">" +
|
|
"<div class=\"row\">" +
|
|
"<div class=\"input-group\">" +
|
|
"<div class=\"input-group-prepend\">" +
|
|
"<i class=\"fas fa-cubes text-bewo-resource h-100\"></i>" +
|
|
"</div>" +
|
|
"<p class=\"form-control border-0 bg-transparent text-truncate\">" + customListItem.Name + "<p>" +
|
|
"<div class=\"input-group-append\">" +
|
|
"<button class=\"btn btn-primary\" type=\"button\" onclick=\"removeSelectedResource('" + listItemId + "', '" + checkBoxId + "', '" + popupId + "', '" + url + "', '" + listId + "')\"><span class=\"fas fa-times-circle\"></span></button>" +
|
|
"</div>" +
|
|
"</div>" +
|
|
"</div>" +
|
|
"</div>";
|
|
|
|
list.append(html);
|
|
});
|
|
}
|
|
|
|
function removeSelectedResource(listItemId, checkBoxId, popupId, url, listId) {
|
|
$("#" + listItemId).remove();
|
|
|
|
var checkbox = $("#" + checkBoxId);
|
|
|
|
if (checkbox.length) {
|
|
checkbox.prop("checked", false);
|
|
}
|
|
|
|
changeResourceSelection(popupId, url, listId);
|
|
}
|