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