use of com.helger.html.jscode.JSStatementList in project peppol-practical by phax.
the class CommentUI method getCreateComment.
@Nonnull
public static IHCNode getCreateComment(@Nonnull final ILayoutExecutionContext aLEC, @Nonnull final String sResultDivID, @Nonnull final ITypedObject<String> aObject, @Nullable final ICommentThread aCommentThread, @Nullable final IComment aParentComment, @Nullable final CommentFormErrors aFormErrors, @Nullable final IHCNode aMessageBox) {
final IRequestWebScopeWithoutResponse aRequestScope = aLEC.getRequestScope();
final Locale aDisplayLocale = aLEC.getDisplayLocale();
final IUser aLoggedInUser = LoggedInUserManager.getInstance().getCurrentUser();
final boolean bIsCreateNewThread = aCommentThread == null || aParentComment == null;
final HCDiv aFormContainer = new HCDiv();
if (bIsCreateNewThread)
if (aFormErrors == null || aFormErrors.isEmpty())
aFormContainer.addStyle(CCSSProperties.DISPLAY_NONE);
aFormContainer.addClass(CCommentCSS.CSS_CLASS_COMMENT_CREATE);
if (aFormErrors != null && !aFormErrors.isEmpty())
aFormContainer.addChild(new BootstrapErrorBox().addChild(EPhotonCoreText.ERR_INCORRECT_INPUT.getDisplayText(aDisplayLocale)));
final BootstrapViewForm aForm = aFormContainer.addAndReturnChild(new BootstrapViewForm());
aForm.setTitle(ECommentText.MSG_CREATE_COMMENT.getDisplayText(aDisplayLocale));
HCEdit aEditAuthor = null;
if (aLoggedInUser != null) {
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory(ECommentText.MSG_FIELD_AUTHOR.getDisplayText(aDisplayLocale)).setCtrl(aLoggedInUser.getDisplayName()));
} else {
aEditAuthor = new HCEdit(new RequestField(FIELD_COMMENT_AUTHOR));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory(ECommentText.MSG_FIELD_AUTHOR.getDisplayText(aDisplayLocale)).setCtrl(aEditAuthor).setHelpText(ECommentText.DESC_FIELD_AUTHOR.getDisplayText(aDisplayLocale)).setErrorList(aFormErrors == null ? null : aFormErrors.getListOfField(FIELD_COMMENT_AUTHOR)));
}
final HCEdit aEditTitle = new HCEdit(new RequestField(FIELD_COMMENT_TITLE));
aForm.addFormGroup(new BootstrapFormGroup().setLabel(ECommentText.MSG_FIELD_TITLE.getDisplayText(aDisplayLocale)).setCtrl(aEditTitle).setHelpText(ECommentText.DESC_FIELD_TITLE.getDisplayText(aDisplayLocale)).setErrorList(aFormErrors == null ? null : aFormErrors.getListOfField(FIELD_COMMENT_TITLE)));
final HCTextAreaAutosize aTextAreaContent = new HCTextAreaAutosize(new RequestField(FIELD_COMMENT_TEXT)).setRows(5);
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory(ECommentText.MSG_FIELD_TEXT.getDisplayText(aDisplayLocale)).setCtrl(aTextAreaContent).setHelpText(ECommentText.DESC_FIELD_TEXT.getDisplayText(aDisplayLocale)).setErrorList(aFormErrors == null ? null : aFormErrors.getListOfField(FIELD_COMMENT_TEXT)));
final BootstrapButtonToolbar aToolbar = new BootstrapButtonToolbar(aLEC);
// What to do on save?
{
final JSAnonymousFunction aOnSuccess = new JSAnonymousFunction();
final JSVar aJSData = aOnSuccess.param("data");
aOnSuccess.body().add(JQuery.idRef(sResultDivID).replaceWith(aJSData.ref(PhotonUnifiedResponse.HtmlHelper.PROPERTY_HTML)));
JQueryInvocation aSaveAction;
if (bIsCreateNewThread) {
// Create a new thread
aSaveAction = new JQueryAjaxBuilder().url(CAjax.COMMENT_CREATE_THREAD.getInvocationURL(aRequestScope)).data(new JSAssocArray().add(AjaxExecutorCommentCreateThread.PARAM_OBJECT_TYPE, aObject.getObjectType().getName()).add(AjaxExecutorCommentCreateThread.PARAM_OBJECT_ID, aObject.getID()).add(AjaxExecutorCommentCreateThread.PARAM_AUTHOR, aLoggedInUser != null ? JSExpr.lit("") : JQuery.idRef(aEditAuthor).val()).add(AjaxExecutorCommentCreateThread.PARAM_TITLE, JQuery.idRef(aEditTitle).val()).add(AjaxExecutorCommentCreateThread.PARAM_TEXT, JQuery.idRef(aTextAreaContent).val())).success(JSJQueryHelper.jqueryAjaxSuccessHandler(aOnSuccess, null)).build();
} else {
// Reply to a previous comment
aSaveAction = new JQueryAjaxBuilder().url(CAjax.COMMENT_ADD.getInvocationURL(aRequestScope)).data(new JSAssocArray().add(AjaxExecutorCommentAdd.PARAM_OBJECT_TYPE, aObject.getObjectType().getName()).add(AjaxExecutorCommentAdd.PARAM_OBJECT_ID, aObject.getID()).add(AjaxExecutorCommentAdd.PARAM_COMMENT_THREAD_ID, aCommentThread.getID()).add(AjaxExecutorCommentAdd.PARAM_COMMENT_ID, aParentComment.getID()).add(AjaxExecutorCommentAdd.PARAM_OBJECT_ID, aObject.getID()).add(AjaxExecutorCommentAdd.PARAM_AUTHOR, aLoggedInUser != null ? JSExpr.lit("") : JQuery.idRef(aEditAuthor).val()).add(AjaxExecutorCommentAdd.PARAM_TITLE, JQuery.idRef(aEditTitle).val()).add(AjaxExecutorCommentAdd.PARAM_TEXT, JQuery.idRef(aTextAreaContent).val())).success(JSJQueryHelper.jqueryAjaxSuccessHandler(aOnSuccess, null)).build();
}
aToolbar.addButtonSave(aDisplayLocale, aSaveAction);
}
BootstrapButton aButtonCreate = null;
if (bIsCreateNewThread) {
// The create button
aButtonCreate = new BootstrapButton().addChild(ECommentText.MSG_CREATE_COMMENT.getDisplayText(aDisplayLocale));
aButtonCreate.setOnClick(new JSStatementList(JQuery.idRef(aFormContainer).show(), JQuery.jQueryThis().disable()));
}
// What to do on cancel?
{
final JSStatementList aCancelAction = new JSStatementList(JQuery.idRefMultiple(aEditTitle, aTextAreaContent).val(""), JQuery.idRef(aFormContainer).hide());
if (aButtonCreate != null)
aCancelAction.add(JQuery.idRef(aButtonCreate).enable());
if (aEditAuthor != null)
aCancelAction.add(JQuery.idRef(aEditAuthor).val(""));
aToolbar.addButtonCancel(aDisplayLocale, aCancelAction);
}
aFormContainer.addChild(aToolbar);
// Show create comment button
final HCNodeList ret = new HCNodeList();
ret.addChild(aButtonCreate);
ret.addChild(aFormContainer);
ret.addChild(aMessageBox);
return ret;
}
Aggregations