1 | |
package org.kuali.student.core.comments.ui.client.widgets.commenttool; |
2 | |
|
3 | |
import java.text.DateFormat; |
4 | |
import java.text.SimpleDateFormat; |
5 | |
import java.util.ArrayList; |
6 | |
import java.util.Collections; |
7 | |
import java.util.Comparator; |
8 | |
import java.util.Date; |
9 | |
import java.util.HashMap; |
10 | |
import java.util.List; |
11 | |
import java.util.Map; |
12 | |
|
13 | |
import org.kuali.student.common.dto.DtoConstants.DtoState; |
14 | |
import org.kuali.student.common.dto.RichTextInfo; |
15 | |
import org.kuali.student.common.dto.StatusInfo; |
16 | |
import org.kuali.student.common.ui.client.application.Application; |
17 | |
import org.kuali.student.common.ui.client.application.KSAsyncCallback; |
18 | |
import org.kuali.student.common.ui.client.configurable.mvc.HasReferenceId; |
19 | |
import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle; |
20 | |
import org.kuali.student.common.ui.client.mvc.Callback; |
21 | |
import org.kuali.student.common.ui.client.mvc.Controller; |
22 | |
import org.kuali.student.common.ui.client.mvc.ModelRequestCallback; |
23 | |
import org.kuali.student.common.ui.client.mvc.dto.ReferenceModel; |
24 | |
import org.kuali.student.common.ui.client.widgets.KSButton; |
25 | |
import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle; |
26 | |
import org.kuali.student.common.ui.client.widgets.KSLabel; |
27 | |
import org.kuali.student.common.ui.client.widgets.KSLightBox; |
28 | |
import org.kuali.student.common.ui.client.widgets.KSTextArea; |
29 | |
import org.kuali.student.common.ui.client.widgets.buttongroups.ButtonEnumerations.OkEnum; |
30 | |
import org.kuali.student.common.ui.client.widgets.buttongroups.OkGroup; |
31 | |
import org.kuali.student.common.ui.client.widgets.dialog.ConfirmationDialog; |
32 | |
import org.kuali.student.common.ui.client.widgets.layout.VerticalFlowPanel; |
33 | |
import org.kuali.student.core.comment.dto.CommentInfo; |
34 | |
import org.kuali.student.core.comments.ui.client.service.CommentRpcService; |
35 | |
import org.kuali.student.core.comments.ui.client.service.CommentRpcServiceAsync; |
36 | |
|
37 | |
import com.google.gwt.core.client.GWT; |
38 | |
import com.google.gwt.dom.client.Style; |
39 | |
import com.google.gwt.event.dom.client.ClickEvent; |
40 | |
import com.google.gwt.event.dom.client.ClickHandler; |
41 | |
import com.google.gwt.event.dom.client.KeyUpEvent; |
42 | |
import com.google.gwt.event.dom.client.KeyUpHandler; |
43 | |
import com.google.gwt.user.client.Window; |
44 | |
import com.google.gwt.user.client.rpc.AsyncCallback; |
45 | |
import com.google.gwt.user.client.ui.FlexTable; |
46 | |
import com.google.gwt.user.client.ui.FlowPanel; |
47 | |
import com.google.gwt.user.client.ui.HTML; |
48 | |
import com.google.gwt.user.client.ui.HorizontalPanel; |
49 | |
import com.google.gwt.user.client.ui.Widget; |
50 | |
|
51 | 0 | public class CommentTool implements HasReferenceId { |
52 | |
|
53 | 0 | private CommentRpcServiceAsync commentServiceAsync = GWT.create(CommentRpcService.class); |
54 | |
private String referenceId; |
55 | |
private String referenceTypeKey; |
56 | |
private String referenceType; |
57 | |
private String referenceState; |
58 | |
private KSLightBox commentLightBox; |
59 | 0 | private HTML loggedInUserNameHTML = new HTML(); |
60 | |
private String loggedInUserId; |
61 | 0 | protected KSTextArea commentTextArea = new KSTextArea(); |
62 | 0 | protected KSButton cancelEditButton = new KSButton("Cancel"); |
63 | 0 | private KSButton submitCommentButton = new KSButton("Submit"); |
64 | 0 | private FlexTable commentsTableLayout = new FlexTable(); |
65 | |
|
66 | |
private Controller controller; |
67 | |
private Enum<?> viewEnum; |
68 | |
private String viewName; |
69 | 0 | VerticalFlowPanel loggedInLabelsPanel = new VerticalFlowPanel(); |
70 | 0 | VerticalFlowPanel commentEditPanel = new VerticalFlowPanel(); |
71 | 0 | KSLabel notAuthorizedToAddComments = new KSLabel("The document must be saved before Comments can be added."); |
72 | 0 | protected EditMode editMode = EditMode.ADD_COMMENT; |
73 | |
private CommentInfo selectedComment; |
74 | 0 | protected List<Callback<EditMode>> editControlsCallbacks = new ArrayList<Callback<EditMode>>(); |
75 | |
private String commentTypeKey; |
76 | |
private Map<String, String> referenceAttributes; |
77 | 0 | private KSLabel proposalTitle = new KSLabel(); |
78 | |
private String title; |
79 | |
protected HTML htmlLabel; |
80 | |
protected SectionTitle leaveACommentTitle; |
81 | |
protected HorizontalPanel commentSectionPanel; |
82 | 0 | protected Map<Integer, KSButton> editButtonMap = new HashMap<Integer, KSButton>(); |
83 | 0 | protected Map<Integer, KSButton> deleteButtonMap = new HashMap<Integer, KSButton>(); |
84 | |
|
85 | 0 | public enum EditMode { |
86 | 0 | ADD_COMMENT, UPDATE_COMMENT, VIEW_COMMENT |
87 | |
} |
88 | |
|
89 | 0 | public CommentTool(Enum<?> viewEnum, String viewName, String commentTypeKey, String title) { |
90 | 0 | this.viewName = viewName; |
91 | 0 | this.viewEnum = viewEnum; |
92 | 0 | this.commentTypeKey = commentTypeKey; |
93 | 0 | this.title = title; |
94 | 0 | init(); |
95 | |
|
96 | 0 | } |
97 | |
|
98 | |
public Controller getController() { |
99 | 0 | return this.controller; |
100 | |
} |
101 | |
|
102 | |
|
103 | |
public void setController(Controller controller){ |
104 | 0 | this.controller = controller; |
105 | 0 | } |
106 | |
|
107 | |
|
108 | |
public Widget asWidget(){ |
109 | 0 | return commentLightBox.getWidget(); |
110 | |
} |
111 | |
|
112 | 0 | private OkGroup buttonPanel = new OkGroup(new Callback<OkEnum>(){ |
113 | |
|
114 | |
@Override |
115 | |
public void exec(OkEnum result) { |
116 | 0 | if(result == OkEnum.Ok){ |
117 | |
} |
118 | |
|
119 | 0 | } |
120 | |
}); |
121 | |
|
122 | |
private void init() { |
123 | 0 | commentLightBox = new KSLightBox(); |
124 | 0 | VerticalFlowPanel contentPanel = new VerticalFlowPanel(); |
125 | |
|
126 | 0 | SectionTitle title = SectionTitle.generateH2Title(this.title); |
127 | 0 | title.addStyleName("ks-layout-header"); |
128 | 0 | htmlLabel = new HTML("<b>All comments posted here will be visible to authors, and " + |
129 | |
"to reviewers after you submit the proposal.</b>"); |
130 | 0 | title.setStyleName("cluProposalTitleSection"); |
131 | 0 | proposalTitle.setVisible(false); |
132 | 0 | contentPanel.add(proposalTitle); |
133 | 0 | commentLightBox.setNonCaptionHeader(title); |
134 | 0 | contentPanel.add(htmlLabel); |
135 | |
|
136 | |
|
137 | 0 | leaveACommentTitle = SectionTitle.generateH3Title("Leave a Comment"); |
138 | 0 | leaveACommentTitle.getElement().getStyle().setProperty("borderBottom", "1px solid #D8D8D8"); |
139 | 0 | leaveACommentTitle.getElement().getStyle().setProperty("marginTop", "2em"); |
140 | 0 | contentPanel.add(leaveACommentTitle); |
141 | |
|
142 | |
|
143 | 0 | HTML loggedInAsLabel = new HTML("<b>Logged in as:<b/>"); |
144 | 0 | loggedInLabelsPanel.add(loggedInAsLabel); |
145 | 0 | final String userId = Application.getApplicationContext().getSecurityContext().getUserId(); |
146 | 0 | commentServiceAsync.getUserRealName(userId, new AsyncCallback<String>() { |
147 | |
@Override |
148 | |
public void onFailure(Throwable caught) { |
149 | 0 | loggedInUserNameHTML.setHTML("<b>" + userId + "</b>"); |
150 | 0 | } |
151 | |
@Override |
152 | |
public void onSuccess(String result) { |
153 | 0 | if (result != null && !result.isEmpty()) { |
154 | 0 | loggedInUserNameHTML.setHTML("<b>" + result + "</b>"); |
155 | |
} else { |
156 | 0 | loggedInUserNameHTML.setHTML("<b>" + userId + "</b>"); |
157 | |
} |
158 | 0 | } |
159 | |
}); |
160 | |
|
161 | 0 | loggedInUserId = userId; |
162 | 0 | loggedInLabelsPanel.add(loggedInUserNameHTML); |
163 | 0 | commentTextArea.setSize("500", "100"); |
164 | 0 | commentEditPanel.add(commentTextArea); |
165 | 0 | FlowPanel buttonsPanel = new FlowPanel(); |
166 | 0 | buttonsPanel.add(cancelEditButton); |
167 | 0 | cancelEditButton.addClickHandler(new ClickHandler() { |
168 | |
@Override |
169 | |
public void onClick(ClickEvent event) { |
170 | 0 | setEditMode(EditMode.ADD_COMMENT); |
171 | 0 | } |
172 | |
}); |
173 | 0 | buttonsPanel.add(submitCommentButton); |
174 | 0 | submitCommentButton.setEnabled(false); |
175 | 0 | commentEditPanel.add(buttonsPanel); |
176 | 0 | buttonsPanel.addStyleName("KS-Comment-Button-Panel"); |
177 | |
|
178 | 0 | commentTextArea.addKeyUpHandler(new KeyUpHandler() { |
179 | |
@Override |
180 | |
public void onKeyUp(KeyUpEvent event) { |
181 | 0 | submitCommentButton.setEnabled(true); |
182 | 0 | } |
183 | |
}); |
184 | |
|
185 | |
|
186 | |
|
187 | 0 | submitCommentButton.addClickHandler(new ClickHandler() { |
188 | |
@Override |
189 | |
public void onClick(ClickEvent event) { |
190 | 0 | switch (editMode) { |
191 | |
case ADD_COMMENT: { |
192 | 0 | CommentInfo newComment = new CommentInfo(); |
193 | |
|
194 | 0 | RichTextInfo text = new RichTextInfo(); |
195 | 0 | text.setFormatted(commentTextArea.getText()); |
196 | 0 | text.setPlain(commentTextArea.getText()); |
197 | 0 | newComment.setType(commentTypeKey); |
198 | 0 | newComment.setReferenceId(referenceId); |
199 | 0 | newComment.setReferenceTypeKey(referenceTypeKey); |
200 | 0 | newComment.setState(DtoState.ACTIVE.toString()); |
201 | 0 | newComment.setCommentText(text); |
202 | |
|
203 | |
try { |
204 | 0 | commentServiceAsync.addComment(referenceId, referenceTypeKey, newComment, new KSAsyncCallback<CommentInfo>(){ |
205 | |
|
206 | |
@Override |
207 | |
public void handleFailure(Throwable caught) { |
208 | 0 | GWT.log("Add Comment Failed", caught); |
209 | 0 | } |
210 | |
|
211 | |
@Override |
212 | |
public void onSuccess(CommentInfo result) { |
213 | 0 | refreshComments(); |
214 | 0 | } |
215 | |
}); |
216 | 0 | } catch (Exception e) { |
217 | 0 | GWT.log("Add Comment Failed", e); |
218 | 0 | } |
219 | 0 | break; |
220 | |
} |
221 | |
case UPDATE_COMMENT: { |
222 | 0 | if (selectedComment != null) { |
223 | 0 | RichTextInfo text = new RichTextInfo(); |
224 | 0 | text.setFormatted(commentTextArea.getText()); |
225 | 0 | text.setPlain(commentTextArea.getText()); |
226 | 0 | selectedComment.setReferenceId(referenceId); |
227 | 0 | selectedComment.setReferenceTypeKey(referenceTypeKey); |
228 | 0 | selectedComment.setCommentText(text); |
229 | |
|
230 | 0 | selectedComment.setType(commentTypeKey); |
231 | |
} |
232 | |
|
233 | |
try { |
234 | 0 | commentServiceAsync.updateComment(referenceId, referenceTypeKey, selectedComment, new KSAsyncCallback<CommentInfo>(){ |
235 | |
|
236 | |
@Override |
237 | |
public void handleFailure(Throwable caught) { |
238 | 0 | GWT.log("Add Comment Failed", caught); |
239 | 0 | } |
240 | |
|
241 | |
@Override |
242 | |
public void onSuccess(CommentInfo result) { |
243 | 0 | refreshComments(); |
244 | 0 | setEditMode(EditMode.ADD_COMMENT); |
245 | 0 | } |
246 | |
}); |
247 | 0 | } catch (Exception e) { |
248 | 0 | GWT.log("Add Comment Failed", e); |
249 | 0 | } |
250 | |
break; |
251 | |
} |
252 | |
} |
253 | 0 | } |
254 | |
}); |
255 | |
|
256 | 0 | commentSectionPanel = new HorizontalPanel(); |
257 | 0 | commentSectionPanel.add(loggedInLabelsPanel); |
258 | 0 | commentSectionPanel.add(commentEditPanel); |
259 | 0 | commentSectionPanel.add(notAuthorizedToAddComments); |
260 | 0 | contentPanel.add(commentSectionPanel); |
261 | |
|
262 | |
|
263 | 0 | contentPanel.add(commentsTableLayout); |
264 | |
|
265 | |
|
266 | |
|
267 | |
|
268 | 0 | commentLightBox.setWidget(contentPanel); |
269 | 0 | setEditMode(EditMode.ADD_COMMENT); |
270 | 0 | } |
271 | |
|
272 | |
private void checkPermissionsAndRedrawTable(final List<CommentInfo> commentInfos) { |
273 | |
|
274 | 0 | commentServiceAsync.isAuthorizedAddComment(referenceId, referenceTypeKey, new KSAsyncCallback<Boolean>() { |
275 | |
|
276 | |
@Override |
277 | |
public void onFailure(Throwable caught) { |
278 | 0 | GWT.log("Error checking permission for adding comments: ", caught); |
279 | 0 | throw new RuntimeException("Error checking Permissions: ", caught); |
280 | |
} |
281 | |
|
282 | |
@Override |
283 | |
public void onSuccess(Boolean result) { |
284 | 0 | GWT.log("User is " + ((result) ? "" : "not ") + |
285 | |
"authorized to add comment.", null); |
286 | 0 | if(referenceId != null && !(referenceId.isEmpty())){ |
287 | 0 | notAuthorizedToAddComments.setVisible(false); |
288 | 0 | commentEditPanel.setVisible(result); |
289 | 0 | commentsTableLayout.setVisible(true); |
290 | 0 | redrawCommentsTable(commentInfos); |
291 | |
} |
292 | |
else{ |
293 | 0 | notAuthorizedToAddComments.setVisible(true); |
294 | 0 | commentEditPanel.setVisible(false); |
295 | 0 | commentsTableLayout.setVisible(false); |
296 | |
} |
297 | 0 | } |
298 | |
|
299 | |
}); |
300 | 0 | } |
301 | |
|
302 | |
protected void redrawCommentsTable(List<CommentInfo> commentInfos) { |
303 | 0 | commentsTableLayout.clear(); |
304 | 0 | editControlsCallbacks.clear(); |
305 | |
|
306 | 0 | if (commentInfos != null) { |
307 | 0 | int rowIndex = 0; |
308 | 0 | int commentCounter = 0; |
309 | 0 | for (final CommentInfo commentInfo : commentInfos) { |
310 | 0 | int columnIndex = 0; |
311 | 0 | final KSButton editButton = new KSButton("Edit", ButtonStyle.DEFAULT_ANCHOR); |
312 | 0 | final KSButton deleteButton = new KSButton("Delete", ButtonStyle.DEFAULT_ANCHOR); |
313 | 0 | if (commentInfo.getType() != null && |
314 | |
commentInfo.getType().startsWith("kuali.comment.type.workflowDecisionRationale")) { |
315 | |
|
316 | 0 | continue; |
317 | |
} |
318 | 0 | if (rowIndex == 0) { |
319 | 0 | StringBuilder titleTextSb = new StringBuilder(); |
320 | 0 | titleTextSb.append("Comments (").append(commentInfos.size()).append(")"); |
321 | 0 | SectionTitle commentsSectionHeader = SectionTitle.generateH3Title(titleTextSb.toString()); |
322 | 0 | commentsSectionHeader.getElement().getStyle().setProperty("borderBottom", "1px solid #D8D8D8"); |
323 | 0 | commentsTableLayout.setWidget(rowIndex, columnIndex, commentsSectionHeader); |
324 | 0 | commentsTableLayout.getFlexCellFormatter().setColSpan(rowIndex, columnIndex, 3); |
325 | 0 | rowIndex++; |
326 | |
} |
327 | 0 | if (commentCounter > 0) { |
328 | 0 | VerticalFlowPanel space = new VerticalFlowPanel(); |
329 | 0 | space.getElement().getStyle().setPaddingBottom(5d, Style.Unit.PX); |
330 | 0 | commentsTableLayout.setWidget(rowIndex, columnIndex, space); |
331 | 0 | commentsTableLayout.getFlexCellFormatter().setColSpan(rowIndex, columnIndex, 3); |
332 | 0 | rowIndex++; |
333 | |
} |
334 | 0 | VerticalFlowPanel userNameAndTime = new VerticalFlowPanel(); |
335 | 0 | final HTML userNameLabel = new HTML(); |
336 | 0 | final String principalId = commentInfo.getMetaInfo().getUpdateId(); |
337 | 0 | commentServiceAsync.getUserRealNameByPrincipalId(principalId, new AsyncCallback<String>() { |
338 | |
@Override |
339 | |
public void onFailure(Throwable caught) { |
340 | 0 | userNameLabel.setHTML("<b>" + principalId + "</b>"); |
341 | 0 | } |
342 | |
@Override |
343 | |
public void onSuccess(String result) { |
344 | 0 | if (result != null && !result.isEmpty()) { |
345 | 0 | userNameLabel.setHTML("<b>" + result + "</b>"); |
346 | |
} else { |
347 | 0 | userNameLabel.setHTML("<b>" + principalId + "</b>"); |
348 | |
} |
349 | 0 | } |
350 | |
}); |
351 | |
|
352 | 0 | Date createTime = commentInfo.getMetaInfo().getCreateTime(); |
353 | 0 | userNameAndTime.add(userNameLabel); |
354 | 0 | DateFormat df = new SimpleDateFormat("MMMM dd, yyyy - hh:mmaaa"); |
355 | 0 | userNameAndTime.add(new KSLabel(df.format(createTime))); |
356 | 0 | userNameAndTime.getElement().getStyle().setPaddingRight(20d, Style.Unit.PX); |
357 | 0 | commentsTableLayout.setWidget(rowIndex, columnIndex, userNameAndTime); |
358 | 0 | columnIndex++; |
359 | |
|
360 | 0 | RichTextInfo commentRT = commentInfo.getCommentText(); |
361 | 0 | String commentText = commentRT.getPlain(); |
362 | 0 | KSLabel commentTextLabel = new KSLabel(commentText); |
363 | 0 | commentTextLabel.getElement().getStyle().setPaddingRight(20d, Style.Unit.PX); |
364 | 0 | commentTextLabel.setWidth("120px"); |
365 | 0 | commentTextLabel.getElement().getStyle().setProperty("wordWrap", "break-word"); |
366 | 0 | commentsTableLayout.setWidget(rowIndex, columnIndex, commentTextLabel); |
367 | 0 | columnIndex++; |
368 | 0 | editButton.getElement().getStyle().setPadding(5d, Style.Unit.PX); |
369 | 0 | editControlsCallbacks.add(new Callback<EditMode>() { |
370 | |
@Override |
371 | |
public void exec(EditMode result) { |
372 | 0 | switch (editMode) { |
373 | |
case UPDATE_COMMENT: |
374 | |
|
375 | |
|
376 | 0 | editButton.setEnabled(false); |
377 | 0 | deleteButton.setEnabled(false); |
378 | 0 | break; |
379 | |
case ADD_COMMENT: |
380 | |
|
381 | |
|
382 | 0 | editButton.setEnabled(true); |
383 | 0 | deleteButton.setEnabled(true); |
384 | |
break; |
385 | |
} |
386 | 0 | } |
387 | |
}); |
388 | |
|
389 | 0 | editButton.addClickHandler(new ClickHandler() { |
390 | |
@Override |
391 | |
public void onClick(ClickEvent event) { |
392 | 0 | String commentText = (commentInfo == null || |
393 | |
commentInfo.getCommentText() == null)? "" : |
394 | |
commentInfo.getCommentText().getPlain(); |
395 | 0 | selectedComment = commentInfo; |
396 | 0 | commentTextArea.setText(commentText); |
397 | 0 | commentTextArea.setFocus(true); |
398 | 0 | setEditMode(EditMode.UPDATE_COMMENT); |
399 | 0 | } |
400 | |
}); |
401 | 0 | deleteButton.addClickHandler(new ClickHandler() { |
402 | |
@Override |
403 | |
public void onClick(ClickEvent event) { |
404 | 0 | final ConfirmationDialog confirmDeletion = |
405 | |
new ConfirmationDialog("Delete Comment", |
406 | |
"You are about to delete a comment. Are you sure?"); |
407 | 0 | confirmDeletion.getConfirmButton().addClickHandler(new ClickHandler(){ |
408 | |
@Override |
409 | |
public void onClick(ClickEvent event) { |
410 | |
try { |
411 | 0 | commentServiceAsync.removeComment(commentInfo.getId(), |
412 | |
referenceId, referenceTypeKey, |
413 | 0 | new KSAsyncCallback<StatusInfo>(){ |
414 | |
|
415 | |
@Override |
416 | |
public void handleFailure(Throwable caught) { |
417 | 0 | GWT.log("remove Comment Failed", caught); |
418 | 0 | } |
419 | |
|
420 | |
@Override |
421 | |
public void onSuccess(StatusInfo result) { |
422 | 0 | confirmDeletion.hide(); |
423 | 0 | refreshComments(); |
424 | 0 | } |
425 | |
|
426 | |
}); |
427 | 0 | } catch (Exception e) { |
428 | 0 | GWT.log("remove Comment Failed", e); |
429 | 0 | } |
430 | 0 | } |
431 | |
}); |
432 | 0 | confirmDeletion.show(); |
433 | 0 | } |
434 | |
}); |
435 | 0 | commentsTableLayout.setWidget(rowIndex, columnIndex, editButton); |
436 | 0 | editButtonMap.put(commentCounter, editButton); |
437 | 0 | columnIndex++; |
438 | 0 | commentsTableLayout.setWidget(rowIndex, columnIndex, deleteButton); |
439 | 0 | deleteButtonMap.put(commentCounter, deleteButton); |
440 | 0 | columnIndex++; |
441 | |
|
442 | 0 | commentServiceAsync.getPrincipalNameByPrincipalId(principalId, new AsyncCallback<String>() { |
443 | |
@Override |
444 | |
public void onFailure(Throwable caught) { |
445 | |
|
446 | 0 | String warning = "Unable to find PrincipalName via PrincipalId["+principalId+"]"; |
447 | 0 | } |
448 | |
@Override |
449 | |
public void onSuccess(String principalName) { |
450 | 0 | if (principalName == null || !principalName.equals(getLoggedInUserId())) { |
451 | 0 | editButton.setVisible(false); |
452 | 0 | deleteButton.setVisible(false); |
453 | |
} |
454 | 0 | } |
455 | |
}); |
456 | |
|
457 | |
|
458 | |
|
459 | 0 | rowIndex++; |
460 | |
|
461 | 0 | commentCounter++; |
462 | 0 | } |
463 | 0 | setEditMode(EditMode.ADD_COMMENT); |
464 | |
} |
465 | 0 | } |
466 | |
|
467 | |
public void setEditMode(EditMode editMode) { |
468 | 0 | this.editMode = editMode; |
469 | 0 | switch (editMode) { |
470 | |
case UPDATE_COMMENT: |
471 | 0 | cancelEditButton.setVisible(true); |
472 | 0 | if (editControlsCallbacks != null) { |
473 | 0 | for (Callback<EditMode> callback : editControlsCallbacks) { |
474 | 0 | callback.exec(EditMode.UPDATE_COMMENT); |
475 | |
} |
476 | |
} |
477 | |
break; |
478 | |
case ADD_COMMENT: |
479 | 0 | cancelEditButton.setVisible(false); |
480 | 0 | commentTextArea.setText(""); |
481 | 0 | if (editControlsCallbacks != null) { |
482 | 0 | for (Callback<EditMode> callback : editControlsCallbacks) { |
483 | 0 | callback.exec(EditMode.ADD_COMMENT); |
484 | |
} |
485 | |
} |
486 | |
break; |
487 | |
case VIEW_COMMENT: |
488 | 0 | htmlLabel.setVisible(false); |
489 | 0 | leaveACommentTitle.setVisible(false); |
490 | 0 | commentSectionPanel.setVisible(false); |
491 | |
|
492 | 0 | for (int i = 0; i < editButtonMap.size(); i++) { |
493 | 0 | editButtonMap.get(i).setVisible(false); |
494 | |
} |
495 | 0 | for (int i = 0; i < deleteButtonMap.size(); i++) { |
496 | 0 | deleteButtonMap.get(i).setVisible(false); |
497 | |
} |
498 | |
|
499 | |
break; |
500 | |
} |
501 | 0 | } |
502 | |
|
503 | |
public void refreshComments(){ |
504 | |
|
505 | |
try { |
506 | 0 | commentServiceAsync.getComments(referenceId, referenceTypeKey, new KSAsyncCallback<List<CommentInfo>>(){ |
507 | |
|
508 | |
@Override |
509 | |
public void handleFailure(Throwable caught) { |
510 | 0 | GWT.log("getComments failed", caught); |
511 | 0 | } |
512 | |
|
513 | |
@Override |
514 | |
public void onSuccess(List<CommentInfo> result) { |
515 | 0 | if (result != null && !result.isEmpty()) { |
516 | 0 | Collections.sort(result, new Comparator<CommentInfo>(){ |
517 | |
|
518 | |
@Override |
519 | |
public int compare(CommentInfo comment1, CommentInfo comment2) { |
520 | |
|
521 | 0 | if(comment1.getMetaInfo().getCreateTime().after(comment2.getMetaInfo().getCreateTime())){ |
522 | 0 | return -1; |
523 | |
} |
524 | 0 | else if(comment1.getMetaInfo().getCreateTime().before(comment2.getMetaInfo().getCreateTime())){ |
525 | 0 | return 1; |
526 | |
} |
527 | |
else{ |
528 | |
|
529 | 0 | return 0; |
530 | |
} |
531 | |
|
532 | |
} |
533 | |
}); |
534 | |
} |
535 | 0 | checkPermissionsAndRedrawTable(result); |
536 | 0 | } |
537 | |
}); |
538 | 0 | } catch (Exception e) { |
539 | 0 | Window.alert("Failed to refresh Comments"); |
540 | 0 | GWT.log("refresh Comments Failed",e); |
541 | 0 | } |
542 | |
|
543 | |
|
544 | 0 | } |
545 | |
|
546 | |
|
547 | |
|
548 | |
|
549 | |
|
550 | |
|
551 | |
|
552 | |
|
553 | |
|
554 | |
@Override |
555 | |
public String getReferenceId() { |
556 | 0 | return referenceId; |
557 | |
} |
558 | |
|
559 | |
@Override |
560 | |
public String getReferenceState() { |
561 | 0 | return referenceState; |
562 | |
} |
563 | |
|
564 | |
@Override |
565 | |
public String getReferenceType() { |
566 | 0 | return referenceType; |
567 | |
} |
568 | |
|
569 | |
@Override |
570 | |
public String getReferenceTypeKey() { |
571 | 0 | return referenceTypeKey; |
572 | |
} |
573 | |
|
574 | |
@Override |
575 | |
public void setReferenceId(String id) { |
576 | 0 | this.referenceId = id; |
577 | 0 | } |
578 | |
|
579 | |
@Override |
580 | |
public void setReferenceState(String state) { |
581 | 0 | this.referenceState = state; |
582 | 0 | } |
583 | |
|
584 | |
@Override |
585 | |
public void setReferenceType(String type) { |
586 | 0 | this.referenceType = type; |
587 | 0 | } |
588 | |
|
589 | |
@Override |
590 | |
public void setReferenceTypeKey(String key) { |
591 | 0 | this.referenceTypeKey = key; |
592 | 0 | } |
593 | |
|
594 | |
public void setReferenceAttributes(Map<String, String> referenceAttributes) { |
595 | 0 | this.referenceAttributes = referenceAttributes; |
596 | 0 | } |
597 | |
|
598 | |
public void show() { |
599 | 0 | controller.requestModel(ReferenceModel.class, |
600 | 0 | new ModelRequestCallback<ReferenceModel>(){ |
601 | |
public void onModelReady(ReferenceModel model) { |
602 | 0 | String proposalTitleString = null; |
603 | 0 | setReferenceId(model.getReferenceId()); |
604 | 0 | setReferenceTypeKey(model.getReferenceTypeKey()); |
605 | 0 | setReferenceType(model.getReferenceType()); |
606 | 0 | setReferenceState(model.getReferenceState()); |
607 | 0 | setReferenceAttributes(model.getReferenceAttributes()); |
608 | 0 | proposalTitleString = (model.getReferenceAttributes() == null)? null : |
609 | |
model.getReferenceAttributes().get("name"); |
610 | 0 | if (proposalTitleString != null && !proposalTitleString.trim().isEmpty()) { |
611 | 0 | proposalTitle.setText(proposalTitleString); |
612 | 0 | proposalTitle.setVisible(true); |
613 | |
} else { |
614 | 0 | proposalTitle.setText(""); |
615 | 0 | proposalTitle.setVisible(false); |
616 | |
} |
617 | 0 | refreshComments(); |
618 | 0 | commentLightBox.show(); |
619 | 0 | } |
620 | |
|
621 | |
public void onRequestFail(Throwable cause) { |
622 | 0 | Window.alert(cause.toString()); |
623 | 0 | } |
624 | |
}); |
625 | 0 | } |
626 | |
|
627 | |
public String getLoggedInUserId() { |
628 | 0 | return loggedInUserId; |
629 | |
} |
630 | |
|
631 | |
} |