0
|
1 <%
|
|
2 package nabble.view.web.catalog;
|
|
3
|
|
4 import fschmidt.util.servlet.AuthorizingServlet;
|
|
5 import nabble.model.Node;
|
|
6 import nabble.model.NodeIterator;
|
|
7 import nabble.model.Person;
|
|
8 import nabble.model.Site;
|
|
9 import nabble.view.lib.Jtp;
|
|
10 import nabble.view.lib.Shared;
|
|
11 import nabble.view.lib.help.Help;
|
|
12
|
|
13 import javax.servlet.ServletException;
|
|
14 import javax.servlet.http.HttpServlet;
|
|
15 import javax.servlet.http.HttpServletRequest;
|
|
16 import javax.servlet.http.HttpServletResponse;
|
|
17 import java.io.IOException;
|
|
18 import java.io.PrintWriter;
|
|
19 import java.util.ArrayList;
|
|
20 import java.util.List;
|
|
21
|
|
22
|
|
23 public class ChangePinOrder extends HttpServlet implements AuthorizingServlet {
|
|
24
|
|
25 public String getAuthorizationKey(HttpServletRequest request) throws ServletException {
|
|
26 return Jtp.getReadAuthorizationKey( Jtp.getSiteNotNull(request).getNode(Jtp.getLong(request,"forum")) );
|
|
27 }
|
|
28
|
|
29 public boolean authorize(String key,HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
|
|
30 return Jtp.authorizeForRead(key,request,response);
|
|
31 }
|
|
32
|
|
33 protected void service(HttpServletRequest request, HttpServletResponse response)
|
|
34 throws ServletException, IOException
|
|
35 {
|
|
36 PrintWriter out = response.getWriter();
|
|
37 String context = request.getContextPath();
|
|
38 Site site = Jtp.getSiteNotNull(request);
|
|
39 Node forum = site.getNode(Jtp.getLong(request,"forum"));
|
|
40 if (forum == null) {
|
|
41 response.sendError(HttpServletResponse.SC_GONE, "This app has been deleted.");
|
|
42 return;
|
|
43 }
|
|
44
|
|
45 String what = request.getParameter("what");
|
|
46
|
|
47 boolean pinnedThreads = "threads".equals(what);
|
|
48 String title = pinnedThreads? "Pinned Threads" : "Manage " + Jtp.childName(forum, true);
|
|
49
|
|
50 Person visitor = Jtp.getVisitor(request, response);
|
|
51
|
|
52 if (!Jtp.canBeEditedBy(forum,visitor)) {
|
|
53 Jtp.login("Only administrators can proceed in this area.", request, response);
|
|
54 return;
|
|
55 }
|
|
56
|
|
57 List<Node> others = new ArrayList<Node>();
|
|
58 List<Node> pinned = new ArrayList<Node>();
|
|
59
|
|
60 NodeIterator<? extends Node> children = forum.getChildren();
|
|
61 for (Node node : children) {
|
|
62 if( !node.isPinned() )
|
|
63 break;
|
|
64
|
|
65 if (node.getKind()==Node.Kind.POST && pinnedThreads)
|
|
66 pinned.add(node);
|
|
67 else if (node.getKind()==Node.Kind.APP && !pinnedThreads)
|
|
68 pinned.add(node);
|
|
69 else
|
|
70 others.add(node);
|
|
71 }
|
|
72 children.close();
|
|
73
|
|
74 String action = request.getParameter("action");
|
|
75 boolean up = "up".equals(action);
|
|
76 boolean down = "down".equals(action);
|
|
77 if (up || down) {
|
|
78 long id = Long.parseLong(request.getParameter("id"));
|
|
79 Node node = site.getNode(id);
|
|
80 if (pinned.contains(node)) {
|
|
81 int index = pinned.indexOf(node);
|
|
82 pinned.remove(node);
|
|
83 index = up? index-1 : index+1;
|
|
84 if (index < 0)
|
|
85 index = 0;
|
|
86 else if (index > pinned.size())
|
|
87 index = pinned.size();
|
|
88 pinned.add(index, node);
|
|
89
|
|
90 List<Node> all = new ArrayList<Node>();
|
|
91 // Ensure that forums come first
|
|
92 if (pinnedThreads) {
|
|
93 all.addAll(others);
|
|
94 all.addAll(pinned);
|
|
95 } else {
|
|
96 all.addAll(pinned);
|
|
97 all.addAll(others);
|
|
98 }
|
|
99 forum.pin(all.toArray(new Node[0]));
|
|
100
|
|
101 Jtp.sendRedirect(request,response,"/catalog/ChangePinOrder.jtp?forum=" + forum.getId() + "&what=" + what);
|
|
102 return;
|
|
103 }
|
|
104 }
|
|
105
|
|
106 %>
|
|
107 <html>
|
|
108 <head>
|
|
109 <% Shared.title(request, response, "Manage " + title); %>
|
|
110 </head>
|
|
111 <body>
|
|
112 <% Shared.minHeader(request,response, forum); %>
|
|
113 <% Shared.editHeader(forum.getSubjectHtml(), title, out); %>
|
|
114 <style>
|
|
115 table.pin {
|
|
116 width: 40em;
|
|
117 border-collapse:collapse;
|
|
118 }
|
|
119
|
|
120 table.pin td {
|
|
121 padding: .4em;
|
|
122 }
|
|
123
|
|
124 .title-row {
|
|
125 margin-top:2em;
|
|
126 padding:.2em;
|
|
127 border-bottom-width:2px;
|
|
128 border-bottom-style:solid;
|
|
129 font-weight:bold;
|
|
130 }
|
|
131 </style>
|
|
132
|
|
133 <div class="title-row light-border-color">
|
|
134 <%=pinnedThreads? "Pinned Topics" : "Pinned " + Jtp.childName(forum, true)%>
|
|
135 </div>
|
|
136
|
|
137 <% if (!pinnedThreads) { %>
|
|
138 <div class="weak-color" style="margin:0 0 .3em .2em">Pinned <%=Jtp.childName(forum, true).toLowerCase()%> are created or approved by a forum owner to always appear under a forum.</div>
|
|
139 <% } %>
|
|
140 <div style="padding-left:2em">
|
|
141 <%
|
|
142 if (pinned.size() > 1) {
|
|
143 %>
|
|
144 <table id="table-pin" class="pin">
|
|
145 <%
|
|
146 for (int i = 0; i < pinned.size(); i++) {
|
|
147 Node node = pinned.get(i);
|
|
148 boolean isFirst = i == 0;
|
|
149 boolean isLast = i == pinned.size() - 1;
|
|
150 %>
|
|
151 <tr>
|
|
152 <td style="width:24px"><img src="/images/<%=pinnedThreads? "pin.png" : "forum_pin.png"%>"></td>
|
|
153 <td style="padding-left: .4em;width:100%"><a href="<%=Jtp.path(node)%>"><%=node.getSubjectHtml()%></a></td>
|
|
154 <td style="width:24px">
|
|
155 <a class="up" style="<%=isFirst? "display:none" : ""%>" href="/catalog/ChangePinOrder.jtp?forum=<%=forum.getId()%>&what=<%=what%>&action=up&id=<%=node.getId()%>"><img src="<%=context%>/images/icon_up.png" style="border:none;margin:5px" title="Move up"/></a>
|
|
156 </td>
|
|
157 <td style="width:24px">
|
|
158 <a class="down" style="<%=isLast? "display:none" : ""%>" href="/catalog/ChangePinOrder.jtp?forum=<%=forum.getId()%>&what=<%=what%>&action=down&id=<%=node.getId()%>"><img src="<%=context%>/images/icon_down.png" style="border:none;margin:5px" title="Move down"/></a>
|
|
159 </td>
|
|
160 <td style="width:5em"><a href="/catalog/SetPin.jtp?node=<%=node.getId()%>&value=unpin">Unpin</a></td>
|
|
161 </tr>
|
|
162 <%
|
|
163 }
|
|
164 %>
|
|
165 </table>
|
|
166 <%
|
|
167 } else if (pinned.size() == 1) {
|
|
168 Node node = pinned.get(0);
|
|
169 %>
|
|
170 <table class="pin">
|
|
171 <tr>
|
|
172 <td style="width:24px"><img src="/images/<%=pinnedThreads? "pin.png" : "forum_pin.png"%>"></td>
|
|
173 <td><a href="<%=Jtp.path(node)%>"><%=node.getSubjectHtml()%></a></td>
|
|
174 <td style="width:5em"><a href="/catalog/SetPin.jtp?node=<%=node.getId()%>&value=unpin">Unpin</a></td>
|
|
175 </tr>
|
|
176 </table>
|
|
177 <%
|
|
178 } else {
|
|
179 %>
|
|
180 <div style="margin-top:1em">
|
|
181 No <%=pinnedThreads? "pinned topics" : "pinned " + Jtp.childName(forum, true).toLowerCase()%>.
|
|
182 </div>
|
|
183 <%
|
|
184 }
|
|
185 %>
|
|
186 </div>
|
|
187
|
|
188 <%
|
|
189 if (!pinnedThreads) {
|
|
190 // Search for unpinned child forums
|
|
191 List<Node> childForums = forum.getChildApps().get(0, 1000);
|
|
192 List<Node> unpinned = new ArrayList<Node>();
|
|
193 for (Node child : childForums) {
|
|
194 if (!child.isPinned())
|
|
195 unpinned.add(child);
|
|
196 }
|
|
197
|
|
198 if (!unpinned.isEmpty()) {
|
|
199 %>
|
|
200 <div class="title-row light-border-color">Unpinned Sub-forums</div>
|
|
201 <div class="weak-color" style="margin:0 0 .3em .2em">Unpinned sub-forums are user-created categories which float under a forum like a thread.</div>
|
|
202 <div style="padding-left:2em">
|
|
203 <table class="pin">
|
|
204 <%
|
|
205 for (Node node : unpinned) {
|
|
206 %>
|
|
207 <tr>
|
|
208 <td style="width:30px"><img src="/images/forum.png"></td>
|
|
209 <td style="width:100%"><a href="<%=Jtp.path(node)%>"><%=node.getSubjectHtml()%></a></td>
|
|
210 <td style="width:24px"><img src="/images/unpin.png"/></td>
|
|
211 <td style="width:5em"><a href="/catalog/SetPin.jtp?node=<%=node.getId()%>&value=pin">Pin</a></td>
|
|
212 </tr>
|
|
213 <%
|
|
214 }
|
|
215 %>
|
|
216 </table>
|
|
217 </div>
|
|
218 <%
|
|
219 }
|
|
220 }
|
|
221 %>
|
|
222
|
|
223 <div class="light-bg-color" style="padding: .5em;margin:1.5em 0 0">
|
|
224 <div class="second-font field-title" style="margin-top:0">Related Help Article</div>
|
|
225 <%=Help.pinned_subapps.link()%>
|
|
226 </div>
|
|
227
|
|
228 <% Shared.footer(request, response); %>
|
|
229 <% Shared.analytics(request,response); %>
|
|
230 </body>
|
|
231 </html>
|
|
232 <%
|
|
233 }
|
|
234 }
|
|
235 %> |