<%--
/**
 * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
 *
 * The contents of this file are subject to the terms of the Liferay Enterprise
 * Subscription License ("License"). You may not use this file except in
 * compliance with the License. You can obtain a copy of the License by
 * contacting Liferay, Inc. See the License for the specific language governing
 * permissions and limitations under the License, including but not limited to
 * distribution rights of the Software.
 *
 *
 *
 */
--%>

<div class="entries">

	<%
	int flag = announcementsDisplayContext.isShowReadEntries() ? AnnouncementsFlagConstants.HIDDEN : AnnouncementsFlagConstants.NOT_HIDDEN;

	SearchContainer<AnnouncementsEntry> searchContainer = new SearchContainer(renderRequest, null, null, "cur1", announcementsDisplayContext.getPageDelta(), portletURL, null, "no-entries-were-found");

	LinkedHashMap<Long, long[]> scopes = announcementsDisplayContext.getAnnouncementScopes();

	int entriesCount = AnnouncementsEntryLocalServiceUtil.getEntriesCount(user.getUserId(), scopes, portletName.equals(AnnouncementsPortletKeys.ALERTS), flag);

	searchContainer.setTotal(entriesCount);

	List<AnnouncementsEntry> entries = AnnouncementsEntryLocalServiceUtil.getEntries(user.getUserId(), scopes, portletName.equals(AnnouncementsPortletKeys.ALERTS), flag, searchContainer.getStart(), searchContainer.getEnd());

	searchContainer.setResults(entries);

	for (AnnouncementsEntry entry : entries) {
		request.setAttribute(AnnouncementsWebKeys.ANNOUNCEMENTS_ENTRY, entry);
		request.setAttribute(AnnouncementsWebKeys.VIEW_ENTRY_FLAG_VALUE, flag);
	%>

		<liferay-util:include page="/announcements/view_entry.jsp" servletContext="<%= application %>" />

	<%
	}
	%>

</div>

<liferay-ui:search-paginator
	id="pageIteratorTop"
	markupView="lexicon"
	searchContainer="<%= searchContainer %>"
	type="article"
/>

<%
if ((entriesCount == 0) && portletName.equals(AnnouncementsPortletKeys.ALERTS) && !AnnouncementsEntryPermission.contains(permissionChecker, layout, AnnouncementsPortletKeys.ANNOUNCEMENTS_ADMIN, ActionKeys.VIEW)) {
	renderRequest.setAttribute(WebKeys.PORTLET_CONFIGURATOR_VISIBILITY, Boolean.TRUE);
}
%>

<aui:script>
	function <portlet:namespace />markEntry(entryId) {
		Liferay.Service(
			'/announcementsflag/add-flag',
			{
				entryId: entryId,
				value: <%= AnnouncementsFlagConstants.HIDDEN %>,
			},
			Liferay.Portlet.refresh.bind(
				Liferay.Portlet,
				'#p_p_id<portlet:namespace />'
			)
		);
	}

	function <portlet:namespace />unmarkEntry(entryId) {
		Liferay.Service(
			'/announcementsflag/get-flag',
			{
				entryId: entryId,
				value: <%= AnnouncementsFlagConstants.HIDDEN %>,
			},
			function (response) {
				Liferay.Service(
					'/announcementsflag/delete-flag',
					{
						flagId: response.flagId,
					},
					Liferay.Portlet.refresh.bind(
						Liferay.Portlet,
						'#p_p_id<portlet:namespace />'
					)
				);
			}
		);
	}
</aui:script>