List of usage examples for com.google.gwt.safehtml.shared SafeHtmlUtils fromSafeConstant
public static SafeHtml fromSafeConstant(String s)
From source file:net.scran24.common.client.WidgetFactory.java
License:Apache License
public static Panel createDefaultErrorMessage() { FlowPanel result = new FlowPanel(); result.add(new HTMLPanel(SafeHtmlUtils.fromSafeConstant(messages.serverError()))); return result; }
From source file:net.scran24.common.client.WidgetFactory.java
License:Apache License
public static Anchor createBackLink() { Anchor back = new Anchor(SafeHtmlUtils.fromSafeConstant(messages.backLink())); back.addClickHandler(new ClickHandler() { @Override/*from ww w .j a v a 2s . co m*/ public void onClick(ClickEvent event) { History.back(); } }); return back; }
From source file:net.scran24.frontpage.client.FrontPage.java
License:Apache License
public void onModuleLoad() { if (Location.getParameter("genUser") != null) { genUserService.autoCreateUser(EmbeddedData.surveyId(), new AsyncCallback<UserRecord>() { @Override//from w w w. ja v a2s. c o m public void onSuccess(final UserRecord userRecord) { loginService.login(EmbeddedData.surveyId(), userRecord.username, userRecord.password, new AsyncCallback<UserInfo>() { @Override public void onSuccess(UserInfo arg0) { RootPanel.get("loading").getElement().removeFromParent(); final String url = Location.createUrlBuilder().removeParameter("genUser") .buildString(); FlowPanel userInfo = new FlowPanel(); userInfo.addStyleName("intake24-user-info-panel"); userInfo.add(new HTMLPanel( SafeHtmlUtils.fromSafeConstant(commonMessages.genUserWelcome()))); userInfo.add(new HTMLPanel( SafeHtmlUtils.fromSafeConstant(commonMessages.genUserSaveInfo()))); String surveyUrl = Location.getProtocol() + "//" + Location.getHost() + Location.getPath().replace("/login/", "/"); Grid userInfoTable = new Grid(2, 2); userInfoTable.addStyleName("intake24-user-info-table"); userInfoTable.setWidget(0, 0, new Label(commonMessages.loginForm_userNameLabel())); userInfoTable.setWidget(0, 1, new Label(userRecord.username)); userInfoTable.setWidget(1, 0, new Label(commonMessages.loginForm_passwordLabel())); userInfoTable.setWidget(1, 1, new Label(userRecord.password)); userInfo.add(userInfoTable); userInfo.add(new HTMLPanel( SafeHtmlUtils.fromSafeConstant(commonMessages.genUserSurveyLink()))); FlowPanel urlDiv = new FlowPanel(); urlDiv.add(new Anchor(surveyUrl, surveyUrl)); userInfo.add(urlDiv); userInfo.add(new HTMLPanel( SafeHtmlUtils.fromSafeConstant(commonMessages.genUserOneSitting()))); Button cont = WidgetFactory.createGreenButton(commonMessages.genUserContinue(), new ClickHandler() { @Override public void onClick(ClickEvent event) { Location.replace(url); } }); userInfo.add(WidgetFactory.createButtonsPanel(cont)); replaceHeader(); RootPanel.get("loginForm").add(userInfo); } @Override public void onFailure(Throwable arg0) { RootPanel.get("loading").getElement().removeFromParent(); FlowPanel errorPanel = new FlowPanel(); errorPanel.addStyleName("intake24-error-panel"); errorPanel.add(new HTMLPanel( SafeHtmlUtils.fromSafeConstant(commonMessages.serverError()))); RootPanel.get("loginForm").add(errorPanel); } }); } @Override public void onFailure(Throwable arg0) { RootPanel.get("loading").getElement().removeFromParent(); FlowPanel errorPanel = new FlowPanel(); errorPanel.addStyleName("intake24-error-panel"); errorPanel.add(new HTMLPanel(SafeHtmlUtils.fromSafeConstant(commonMessages.serverError()))); RootPanel.get("loginForm").add(errorPanel); } }); } else { RootPanel.get("loading").getElement().removeFromParent(); LoginForm login = new LoginForm(new Callback1<UserInfo>() { @Override public void call(UserInfo info) { Location.reload(); } }, SafeHtmlUtils.fromSafeConstant(commonMessages.loginForm_logInToContinue())); replaceHeader(); RootPanel.get("loginForm").add(login); } initComplete(); }
From source file:net.scran24.staff.client.StaffPage.java
private void showSurveyStatus() { content.clear();//from w w w .ja va 2 s . c om switch (parameters.state) { case SUSPENDED: content.add(new HTMLPanel("<h1>Survey is suspended</h1>")); content.add(new HTMLPanel( "<h2>Reason</h2><p>" + SafeHtmlUtils.htmlEscape(parameters.suspensionReason) + "</p>")); Button resumeButton = WidgetFactory.createButton("Resume", new ClickHandler() { @Override public void onClick(ClickEvent event) { surveyControl.setParameters(parameters.withState(SurveyState.ACTIVE).withSuspensionReason(""), new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { content.clear(); content.add(new HTMLPanel("<p>Server error: </p>" + caught.getMessage())); } @Override public void onSuccess(Void result) { Location.reload(); } }); } }); resumeButton.getElement().addClassName("scran24-admin-button"); content.add(resumeButton); break; case NOT_INITIALISED: content.add(new HTMLPanel("<h1>Survey has not yet been activated</h1>")); content.add(new HTMLPanel("<p>Follow the instructions below to activate the survey.")); FlowPanel initDiv = new FlowPanel(); content.add(initDiv); initStage1(initDiv); break; case ACTIVE: Date now = new Date(); boolean showSuspend = true; if (now.getTime() < parameters.startDate) content.add(new HTMLPanel("<h1>Survey is active, but not yet started</h1>")); else if (now.getTime() > parameters.endDate) { content.add(new HTMLPanel("<h1>Survey is finished</h1>")); showSuspend = false; } else content.add(new HTMLPanel("<h1>Survey is running</h1>")); content.add(new HTMLPanel("<h2>Start date (inclusive)</h2>")); content.add(new HTMLPanel( "<p>" + DateTimeFormat.getFormat("EEE, MMMM d, yyyy").format(new Date(parameters.startDate)) + "</p>")); content.add(new HTMLPanel("<h2>End date (exclusive)</h2>")); content.add(new HTMLPanel("<p>" + DateTimeFormat.getFormat("EEE, MMMM d, yyyy").format(new Date(parameters.endDate)) + "</p>")); if (showSuspend) { content.add(new HTMLPanel(SafeHtmlUtils.fromSafeConstant("<h3>Suspend survey</h3>"))); content.add(new HTMLPanel(SafeHtmlUtils.fromSafeConstant("<p>Reason for suspension:</p>"))); final TextBox reason = new TextBox(); reason.getElement().getStyle().setWidth(600, Unit.PX); Button suspend = WidgetFactory.createButton("Suspend", new ClickHandler() { @Override public void onClick(ClickEvent event) { if (reason.getText().isEmpty()) { Window.alert("Please give a reason for suspension."); } else { surveyControl.setParameters(parameters.withSuspensionReason(reason.getText()) .withState(SurveyState.SUSPENDED), new AsyncCallback<Void>() { @Override public void onSuccess(Void result) { Location.reload(); } @Override public void onFailure(Throwable caught) { Window.alert("Server error: " + caught.getMessage()); } }); } } }); suspend.getElement().addClassName("scran24-admin-button"); content.add(reason); content.add(new HTMLPanel("<p></p>")); content.add(suspend); } break; } }
From source file:net.scran24.staff.client.SuspendSurvey.java
public SuspendSurvey(final SurveyParameters parameters, final SurveyControlServiceAsync surveyControl) { FlowPanel contents = new FlowPanel(); HTMLPanel label = new HTMLPanel(SafeHtmlUtils.fromSafeConstant("<h3>Reason for suspension:</h3>")); final TextBox reason = new TextBox(); Button suspend = WidgetFactory.createButton("Suspend", new ClickHandler() { @Override//from w w w. j a va 2s. c o m public void onClick(ClickEvent event) { if (reason.getText().isEmpty()) { Window.alert("Please give a reason for suspension."); } else { surveyControl.setParameters( parameters.withSuspensionReason(reason.getText()).withState(SurveyState.SUSPENDED), new AsyncCallback<Void>() { @Override public void onSuccess(Void result) { Location.reload(); } @Override public void onFailure(Throwable caught) { Window.alert("Server error: " + caught.getMessage()); } }); } } }); suspend.getElement().addClassName("scran24-admin-button"); contents.add(label); contents.add(reason); contents.add(suspend); initWidget(contents); }
From source file:net.scran24.user.client.CallbackRequestForm.java
private void doRequest() { requestCallbackButton.setEnabled(false); errorMessage.clear();/*w w w . ja va2s.c o m*/ if (nameTextBox.getText().isEmpty() || phoneNumberTextBox.getText().isEmpty()) { errorMessage .add(new HTMLPanel(SafeHtmlUtils.fromSafeConstant(messages.callbackRequestForm_fieldsEmpty()))); errorMessage.getElement().addClassName("intake24-login-error-message"); requestCallbackButton.setEnabled(true); return; } if (CurrentUser.userInfo.surveyId.equals("demo")) { errorMessage.add(new HTMLPanel(SafeHtmlUtils .fromSafeConstant(messages.callbackRequestForm_disabledForDemo("support@intake24.co.uk")))); errorMessage.getElement().addClassName("intake24-login-error-message"); requestCallbackButton.setEnabled(true); return; } errorMessage.add(new LoadingWidget()); helpService.requestCall(nameTextBox.getText(), phoneNumberTextBox.getText(), new AsyncCallback<Boolean>() { @Override public void onFailure(Throwable caught) { errorMessage.clear(); errorMessage.add(new HTMLPanel(SafeHtmlUtils.fromSafeConstant(messages.serverError()))); errorMessage.getElement().addClassName("intake24-login-error-message"); requestCallbackButton.setEnabled(true); } @Override public void onSuccess(Boolean result) { if (result) { errorMessage.clear(); errorMessage.getElement().addClassName("intake24-login-success-message"); errorMessage.add( new HTMLPanel(SafeHtmlUtils.fromSafeConstant(messages.callbackRequestForm_success()))); GoogleAnalytics.trackHelpCallbackAccepted(); } else { errorMessage.clear(); errorMessage.getElement().addClassName("intake24-login-error-message"); errorMessage.add( new HTMLPanel(SafeHtmlUtils.fromSafeConstant(messages.callbackRequestForm_tooSoon()))); GoogleAnalytics.trackHelpCallbackRejected(); } } }); }
From source file:net.scran24.user.client.CallbackRequestForm.java
public CallbackRequestForm(final Callback onComplete) { Grid g = new Grid(2, 2); g.setCellPadding(5);//from ww w .jav a2 s. c om Label nameLabel = new Label(messages.callbackRequestForm_nameLabel()); Label phoneNumberLabel = new Label(messages.callbackRequestForm_phoneNumberLabel()); this.nameTextBox = new TextBox(); this.phoneNumberTextBox = new TextBox(); g.setWidget(0, 0, nameLabel); g.setWidget(1, 0, phoneNumberLabel); g.setWidget(0, 1, nameTextBox); g.setWidget(1, 1, phoneNumberTextBox); VerticalPanel p = new VerticalPanel(); p.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); FlowPanel videoLinkDiv = new FlowPanel(); videoLinkDiv.add(WidgetFactory.createTutorialVideoLink()); p.add(new HTMLPanel(messages.callbackRequestForm_watchWalkthrough())); p.add(videoLinkDiv); HTMLPanel pp = new HTMLPanel(SafeHtmlUtils.fromSafeConstant(messages.callbackRequestForm_promptText())); pp.getElement().addClassName("intake24-login-prompt-text"); p.add(pp); p.add(g); errorMessage = new FlowPanel(); p.add(errorMessage); requestCallbackButton = WidgetFactory .createButton(messages.callbackRequestForm_requestCallbackButtonLabel(), new ClickHandler() { @Override public void onClick(ClickEvent event) { doRequest(); } }); hideFormButton = WidgetFactory.createButton(messages.callbackRequestForm_hideButtonLabel(), new ClickHandler() { @Override public void onClick(ClickEvent event) { onComplete.call(); } }); requestCallbackButton.getElement().setId("intake24-login-button"); nameTextBox.addKeyPressHandler(new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent event) { if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) doRequest(); } }); phoneNumberTextBox.addKeyPressHandler(new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent event) { if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) doRequest(); } }); p.add(WidgetFactory.createButtonsPanel(requestCallbackButton, hideFormButton)); p.addStyleName("intake24-login-form"); initWidget(p); }
From source file:net.scran24.user.client.Scran24.java
License:Apache License
public void initPage(final UserInfo userInfo) { final RootPanel links = RootPanel.get("navigation-bar"); Anchor watchTutorial = new Anchor(surveyMessages.navBar_tutorialVideo(), TutorialVideo.url, "_blank"); Anchor logOut = new Anchor(surveyMessages.navBar_logOut(), "../../common/logout" + Location.getQueryString()); // These divs are no longer used for content, but this code is left here // to handle legacy survey files Element se = Document.get().getElementById("suspended"); if (se != null) se.removeFromParent();//from w w w . j av a 2 s . co m Element ae = Document.get().getElementById("active"); if (ae != null) ae.removeFromParent(); Element fe = Document.get().getElementById("finished"); if (fe != null) fe.removeFromParent(); Element ee = Document.get().getElementById("serverError"); if (ee != null) ee.removeFromParent(); Element fpe = Document.get().getElementById("finalPage"); if (fpe != null) fpe.removeFromParent(); mainContent = Document.get().getElementById("main-content"); mainContent.setInnerHTML(""); HTMLPanel mainContentPanel = HTMLPanel.wrap(mainContent); switch (userInfo.surveyParameters.state) { case NOT_INITIALISED: mainContentPanel .add(new HTMLPanel(SafeHtmlUtils.fromSafeConstant(surveyMessages.survey_notInitialised()))); links.add(new NavigationBar(watchTutorial, logOut)); break; case SUSPENDED: mainContentPanel.add(new HTMLPanel(SafeHtmlUtils.fromSafeConstant(surveyMessages .survey_suspended(SafeHtmlUtils.htmlEscape(userInfo.surveyParameters.suspensionReason))))); links.add(new NavigationBar(watchTutorial, logOut)); break; case ACTIVE: Date now = new Date(); if (now.getTime() > userInfo.surveyParameters.endDate) { mainContentPanel .add(new HTMLPanel(SafeHtmlUtils.fromSafeConstant(surveyMessages.survey_finished()))); } else { SurveyInterfaceManager surveyInterfaceManager = new SurveyInterfaceManager(mainContentPanel); SurveyScheme scheme = SurveySchemeMap.initScheme( SurveySchemes.schemeForId(userInfo.surveyParameters.schemeName), LocaleInfo.getCurrentLocale().getLocaleName(), surveyInterfaceManager); links.add(new NavigationBar(scheme.navBarLinks(), watchTutorial, logOut)); scheme.showNextPage(); } break; } RootPanel.get("loading").getElement().removeFromParent(); initComplete(); }
From source file:net.scran24.user.client.survey.flat.FlatFinalPage.java
License:Apache License
@Override public SimpleSurveyStageInterface getInterface(Callback1<Survey> onComplete, Callback2<Survey, Boolean> onIntermediateStateChange) { final CompletedSurvey finalData = data.finalise(log); final FlowPanel contents = new FlowPanel(); contents.addStyleName("intake24-survey-content-container"); contents.add(new LoadingPanel(messages.submitPage_loadingMessage())); AsyncRequestAuthHandler.execute(new AsyncRequest<Void>() { @Override//from ww w . j a v a 2 s . co m public void execute(AsyncCallback<Void> callback) { processingService.submit(finalData, callback); } }, new AsyncCallback<Void>() { @Override public void onFailure(final Throwable caught) { contents.clear(); caught.printStackTrace(); if (caught instanceof RequestTimeoutException) { final AsyncCallback<Void> outer = this; contents.add(new HTMLPanel(SafeHtmlUtils.fromSafeConstant(messages.submitPage_timeout()))); contents.add(WidgetFactory.createGreenButton(messages.submitPage_tryAgainButton(), new ClickHandler() { @Override public void onClick(ClickEvent event) { processingService.submit(finalData, outer); } })); } else { contents.add(new HTMLPanel(SafeHtmlUtils.fromSafeConstant(messages.submitPage_error()))); } contents.add(new HTMLPanel(finalPageHtml)); } @Override public void onSuccess(Void result) { contents.clear(); contents.add(new HTMLPanel(SafeHtmlUtils.fromSafeConstant(messages.submitPage_success()))); CurrentUser.userInfo.surveyParameters.surveyMonkeyUrl .accept(new Option.SideEffectVisitor<String>() { @Override public void visitSome(final String url) { FlowPanel surveyMonkeyDiv = new FlowPanel(); surveyMonkeyDiv.add(WidgetFactory.createGreenButton( surveyMessages.finalPage_continueToSurveyMonkey(), new ClickHandler() { @Override public void onClick(ClickEvent clickEvent) { Window.Location.replace(url.replace("[intake24_username_value]", CurrentUser.userInfo.userName)); } })); contents.add(surveyMonkeyDiv); } @Override public void visitNone() { } }); contents.add(new HTMLPanel(finalPageHtml)); StateManagerUtil.clearLatestState(CurrentUser.userInfo.userName); } }); return new SimpleSurveyStageInterface(contents); }
From source file:net.scran24.user.client.survey.flat.NavigationPanel.java
License:Apache License
public void stateChanged(final Survey state) { mealsPanel.clear();//www. j av a 2s . c o m Button addMealButton = WidgetFactory.createButton(messages.addMealLabel(), new ClickHandler() { @Override public void onClick(ClickEvent event) { addMealClickedJS(); requestAddMeal.call(); } }); addMealButton.getElement().setId("intake24-add-meal-button"); UnorderedList<MealPanel> mealList = new UnorderedList<MealPanel>(); mealList.addStyleName("intake24-meal-list"); for (WithIndex<Meal> m : state.mealsSortedByTime) { MealPanel p = new MealPanel(m.value, m.index, state.selectedElement, new Callback1<Selection>() { @Override public void call(Selection arg1) { requestSelection.call(arg1); } }); mealList.addItem(p); } FlowPanel headerContainer = new FlowPanel(); headerContainer.addStyleName("intake24-meals-panel-header-container"); FlowPanel headerButton = new FlowPanel(); headerButton.addStyleName("intake24-meals-panel-header-button"); HTMLPanel header = new HTMLPanel(SafeHtmlUtils.fromSafeConstant(messages.navPanelHeader())); header.addStyleName("intake24-meals-panel-header"); headerContainer.add(headerButton); headerContainer.add(header); mealsPanel.add(headerContainer); mealsPanel.add(mealList); mealsPanel.add(addMealButton); stateChangedJS(); }