List of usage examples for org.apache.wicket Component replaceWith
public Component replaceWith(Component replacement)
From source file:org.sakaiproject.profile2.tool.pages.panels.MyContactEdit.java
License:Educational Community License
public MyContactEdit(final String id, final UserProfile userProfile) { super(id);/*from w w w.j a va 2 s . com*/ log.debug("MyContactEdit()"); //this panel final Component thisPanel = this; //get userId final String userId = userProfile.getUserUuid(); //heading add(new Label("heading", new ResourceModel("heading.contact.edit"))); //setup form Form form = new Form("form", new Model(userProfile)); form.setOutputMarkupId(true); //form submit feedback final Label formFeedback = new Label("formFeedback"); formFeedback.setOutputMarkupPlaceholderTag(true); form.add(formFeedback); //add warning message if superUser and not editing own profile Label editWarning = new Label("editWarning"); editWarning.setVisible(false); if (sakaiProxy.isSuperUserAndProxiedToUser(userId)) { editWarning.setDefaultModel(new StringResourceModel("text.edit.other.warning", null, new Object[] { userProfile.getDisplayName() })); editWarning.setEscapeModelStrings(false); editWarning.setVisible(true); } form.add(editWarning); //We don't need to get the info from userProfile, we load it into the form with a property model //just make sure that the form element id's match those in the model // FeedbackPanel final FeedbackPanel feedback = new FeedbackPanel("feedback"); feedback.setOutputMarkupId(true); form.add(feedback); // filteredErrorLevels will not be shown in the FeedbackPanel int[] filteredErrorLevels = new int[] { FeedbackMessage.ERROR }; feedback.setFilter(new ErrorLevelsFeedbackMessageFilter(filteredErrorLevels)); //email WebMarkupContainer emailContainer = new WebMarkupContainer("emailContainer"); emailContainer.add(new Label("emailLabel", new ResourceModel("profile.email"))); final TextField email = new TextField("email", new PropertyModel(userProfile, "email")); email.setOutputMarkupId(true); email.setMarkupId("emailinput"); email.add(EmailAddressValidator.getInstance()); //readonly view Label emailReadOnly = new Label("emailReadOnly", new PropertyModel(userProfile, "email")); if (sakaiProxy.isAccountUpdateAllowed(userId)) { emailReadOnly.setVisible(false); } else { email.setVisible(false); } emailContainer.add(email); emailContainer.add(emailReadOnly); //email feedback final FeedbackLabel emailFeedback = new FeedbackLabel("emailFeedback", email); emailFeedback.setMarkupId("emailFeedback"); emailFeedback.setOutputMarkupId(true); emailContainer.add(emailFeedback); email.add(new ComponentVisualErrorBehaviour("onblur", emailFeedback)); form.add(emailContainer); //homepage WebMarkupContainer homepageContainer = new WebMarkupContainer("homepageContainer"); homepageContainer.add(new Label("homepageLabel", new ResourceModel("profile.homepage"))); final TextField homepage = new TextField("homepage", new PropertyModel(userProfile, "homepage")) { private static final long serialVersionUID = 1L; // add http:// if missing @Override protected void convertInput() { String input = getInput(); if (StringUtils.isNotBlank(input) && !(input.startsWith("http://") || input.startsWith("https://"))) { setConvertedInput("http://" + input); } else { setConvertedInput(StringUtils.isBlank(input) ? null : input); } } }; homepage.setMarkupId("homepageinput"); homepage.setOutputMarkupId(true); homepage.add(new UrlValidator()); homepageContainer.add(homepage); //homepage feedback final FeedbackLabel homepageFeedback = new FeedbackLabel("homepageFeedback", homepage); homepageFeedback.setMarkupId("homepageFeedback"); homepageFeedback.setOutputMarkupId(true); homepageContainer.add(homepageFeedback); homepage.add(new ComponentVisualErrorBehaviour("onblur", homepageFeedback)); form.add(homepageContainer); //workphone WebMarkupContainer workphoneContainer = new WebMarkupContainer("workphoneContainer"); workphoneContainer.add(new Label("workphoneLabel", new ResourceModel("profile.phone.work"))); final TextField workphone = new TextField("workphone", new PropertyModel(userProfile, "workphone")); workphone.setMarkupId("workphoneinput"); workphone.setOutputMarkupId(true); workphone.add(new PhoneNumberValidator()); workphoneContainer.add(workphone); //workphone feedback final FeedbackLabel workphoneFeedback = new FeedbackLabel("workphoneFeedback", workphone); workphoneFeedback.setMarkupId("workphoneFeedback"); workphoneFeedback.setOutputMarkupId(true); workphoneContainer.add(workphoneFeedback); workphone.add(new ComponentVisualErrorBehaviour("onblur", workphoneFeedback)); form.add(workphoneContainer); //homephone WebMarkupContainer homephoneContainer = new WebMarkupContainer("homephoneContainer"); homephoneContainer.add(new Label("homephoneLabel", new ResourceModel("profile.phone.home"))); final TextField homephone = new TextField("homephone", new PropertyModel(userProfile, "homephone")); homephone.setMarkupId("homephoneinput"); homephone.setOutputMarkupId(true); homephone.add(new PhoneNumberValidator()); homephoneContainer.add(homephone); //homephone feedback final FeedbackLabel homephoneFeedback = new FeedbackLabel("homephoneFeedback", homephone); homephoneFeedback.setMarkupId("homephoneFeedback"); homephoneFeedback.setOutputMarkupId(true); homephoneContainer.add(homephoneFeedback); homephone.add(new ComponentVisualErrorBehaviour("onblur", homephoneFeedback)); form.add(homephoneContainer); //mobilephone WebMarkupContainer mobilephoneContainer = new WebMarkupContainer("mobilephoneContainer"); mobilephoneContainer.add(new Label("mobilephoneLabel", new ResourceModel("profile.phone.mobile"))); final TextField mobilephone = new TextField("mobilephone", new PropertyModel(userProfile, "mobilephone")); mobilephone.setMarkupId("mobilephoneinput"); mobilephone.setOutputMarkupId(true); mobilephone.add(new PhoneNumberValidator()); mobilephoneContainer.add(mobilephone); //mobilephone feedback final FeedbackLabel mobilephoneFeedback = new FeedbackLabel("mobilephoneFeedback", mobilephone); mobilephoneFeedback.setMarkupId("mobilephoneFeedback"); mobilephoneFeedback.setOutputMarkupId(true); mobilephoneContainer.add(mobilephoneFeedback); mobilephone.add(new ComponentVisualErrorBehaviour("onblur", mobilephoneFeedback)); form.add(mobilephoneContainer); //facsimile WebMarkupContainer facsimileContainer = new WebMarkupContainer("facsimileContainer"); facsimileContainer.add(new Label("facsimileLabel", new ResourceModel("profile.phone.facsimile"))); final TextField facsimile = new TextField("facsimile", new PropertyModel(userProfile, "facsimile")); facsimile.setMarkupId("facsimileinput"); facsimile.setOutputMarkupId(true); facsimile.add(new PhoneNumberValidator()); facsimileContainer.add(facsimile); //facsimile feedback final FeedbackLabel facsimileFeedback = new FeedbackLabel("facsimileFeedback", facsimile); facsimileFeedback.setMarkupId("facsimileFeedback"); facsimileFeedback.setOutputMarkupId(true); facsimileContainer.add(facsimileFeedback); facsimile.add(new ComponentVisualErrorBehaviour("onblur", facsimileFeedback)); form.add(facsimileContainer); //submit button AjaxFallbackButton submitButton = new AjaxFallbackButton("submit", new ResourceModel("button.save.changes"), form) { protected void onSubmit(AjaxRequestTarget target, Form form) { //save() form, show message, then load display panel if (save(form)) { //post update event sakaiProxy.postEvent(ProfileConstants.EVENT_PROFILE_CONTACT_UPDATE, "/profile/" + userId, true); //post to wall if enabled if (true == sakaiProxy.isWallEnabledGlobally() && false == sakaiProxy.isSuperUserAndProxiedToUser(userId)) { wallLogic.addNewEventToWall(ProfileConstants.EVENT_PROFILE_CONTACT_UPDATE, sakaiProxy.getCurrentUserId()); } //repaint panel Component newPanel = new MyContactDisplay(id, userProfile); newPanel.setOutputMarkupId(true); thisPanel.replaceWith(newPanel); if (target != null) { target.add(newPanel); //resize iframe target.appendJavaScript("setMainFrameHeight(window.name);"); } } else { //String js = "alert('Failed to save information. Contact your system administrator.');"; //target.prependJavascript(js); formFeedback.setDefaultModel(new ResourceModel("error.profile.save.contact.failed")); formFeedback.add(new AttributeModifier("class", true, new Model<String>("save-failed-error"))); target.add(formFeedback); } } // This is called if the form validation fails, ie Javascript turned off, //or we had preexisting invalid data before this fix was introduced protected void onError(AjaxRequestTarget target, Form form) { //check which item didn't validate and update the class and feedback model for that component if (!email.isValid()) { email.add(new AttributeAppender("class", new Model<String>("invalid"), " ")); emailFeedback.setDefaultModel(new ResourceModel("EmailAddressValidator")); target.add(email); target.add(emailFeedback); } if (!homepage.isValid()) { homepage.add(new AttributeAppender("class", new Model<String>("invalid"), " ")); homepageFeedback.setDefaultModel(new ResourceModel("UrlValidator")); target.add(homepage); target.add(homepageFeedback); } if (!facsimile.isValid()) { facsimile.add(new AttributeAppender("class", new Model<String>("invalid"), " ")); facsimileFeedback.setDefaultModel(new ResourceModel("PhoneNumberValidator")); target.add(facsimile); target.add(facsimileFeedback); } if (!workphone.isValid()) { workphone.add(new AttributeAppender("class", new Model<String>("invalid"), " ")); workphoneFeedback.setDefaultModel(new ResourceModel("PhoneNumberValidator")); target.add(workphone); target.add(workphoneFeedback); } if (!homephone.isValid()) { homephone.add(new AttributeAppender("class", new Model<String>("invalid"), " ")); homephoneFeedback.setDefaultModel(new ResourceModel("PhoneNumberValidator")); target.add(homephone); target.add(homephoneFeedback); } if (!mobilephone.isValid()) { mobilephone.add(new AttributeAppender("class", new Model<String>("invalid"), " ")); mobilephoneFeedback.setDefaultModel(new ResourceModel("PhoneNumberValidator")); target.add(mobilephone); target.add(mobilephoneFeedback); } if (!facsimile.isValid()) { facsimile.add(new AttributeAppender("class", new Model<String>("invalid"), " ")); facsimileFeedback.setDefaultModel(new ResourceModel("PhoneNumberValidator")); target.add(facsimile); target.add(facsimileFeedback); } } }; form.add(submitButton); //cancel button AjaxFallbackButton cancelButton = new AjaxFallbackButton("cancel", new ResourceModel("button.cancel"), form) { private static final long serialVersionUID = 1L; protected void onSubmit(AjaxRequestTarget target, Form form) { Component newPanel = new MyContactDisplay(id, userProfile); newPanel.setOutputMarkupId(true); thisPanel.replaceWith(newPanel); if (target != null) { target.add(newPanel); //resize iframe target.appendJavaScript("setMainFrameHeight(window.name);"); } } }; cancelButton.setDefaultFormProcessing(false); form.add(cancelButton); //add form to page add(form); }
From source file:org.sakaiproject.profile2.tool.pages.panels.MyInfoDisplay.java
License:Educational Community License
public MyInfoDisplay(final String id, final UserProfile userProfile) { super(id);//from ww w . j a v a 2s .c o m log.debug("MyInfoDisplay()"); //this panel stuff final Component thisPanel = this; //get userId of this profile String userId = userProfile.getUserUuid(); //get info from userProfile since we need to validate it and turn things off if not set. //otherwise we could just use a propertymodel /* String firstName = userProfile.getFirstName(); String middleName = userProfile.getMiddleName(); String lastName = userProfile.getLastName(); */ String nickname = userProfile.getNickname(); String personalSummary = userProfile.getPersonalSummary(); Date dateOfBirth = userProfile.getDateOfBirth(); if (dateOfBirth != null) { //full value contains year regardless of privacy settings // Passing null as the format parameter forces a user locale based format birthday = ProfileUtils.convertDateToString(dateOfBirth, null); //get privacy on display of birthday year and format accordingly //note that this particular method doesn't need the second userId param but we send for completeness if (privacyLogic.isBirthYearVisible(userId)) { birthdayDisplay = birthday; } else { birthdayDisplay = ProfileUtils.convertDateToString(dateOfBirth, ProfileConstants.DEFAULT_DATE_FORMAT_HIDE_YEAR); } //set both values as they are used differently userProfile.setBirthdayDisplay(birthdayDisplay); userProfile.setBirthday(birthday); } //heading add(new Label("heading", new ResourceModel("heading.basic"))); //firstName /* WebMarkupContainer firstNameContainer = new WebMarkupContainer("firstNameContainer"); firstNameContainer.add(new Label("firstNameLabel", new ResourceModel("profile.name.first"))); firstNameContainer.add(new Label("firstName", firstName)); add(firstNameContainer); if(StringUtils.isBlank(firstName)) { firstNameContainer.setVisible(false); } else { visibleFieldCount++; } */ //middleName /* WebMarkupContainer middleNameContainer = new WebMarkupContainer("middleNameContainer"); middleNameContainer.add(new Label("middleNameLabel", new ResourceModel("profile.name.middle"))); middleNameContainer.add(new Label("middleName", middleName)); add(middleNameContainer); if(StringUtils.isBlank(middleName)) { middleNameContainer.setVisible(false); } else { visibleFieldCount++; } */ //lastName /* WebMarkupContainer lastNameContainer = new WebMarkupContainer("lastNameContainer"); lastNameContainer.add(new Label("lastNameLabel", new ResourceModel("profile.name.last"))); lastNameContainer.add(new Label("lastName", lastName)); add(lastNameContainer); if(StringUtils.isBlank(lastName)) { lastNameContainer.setVisible(false); } else { visibleFieldCount++; } */ //nickname WebMarkupContainer nicknameContainer = new WebMarkupContainer("nicknameContainer"); nicknameContainer.add(new Label("nicknameLabel", new ResourceModel("profile.nickname"))); nicknameContainer.add(new Label("nickname", nickname)); add(nicknameContainer); if (StringUtils.isBlank(nickname)) { nicknameContainer.setVisible(false); } else { visibleFieldCount++; } //birthday WebMarkupContainer birthdayContainer = new WebMarkupContainer("birthdayContainer"); birthdayContainer.add(new Label("birthdayLabel", new ResourceModel("profile.birthday"))); birthdayContainer.add(new Label("birthday", birthdayDisplay)); add(birthdayContainer); if (StringUtils.isBlank(birthdayDisplay)) { birthdayContainer.setVisible(false); } else { visibleFieldCount++; } //personal summary WebMarkupContainer personalSummaryContainer = new WebMarkupContainer("personalSummaryContainer"); personalSummaryContainer.add(new Label("personalSummaryLabel", new ResourceModel("profile.summary"))); personalSummaryContainer.add(new Label("personalSummary", ProfileUtils.processHtml(personalSummary)) .setEscapeModelStrings(false)); add(personalSummaryContainer); if (StringUtils.isBlank(personalSummary)) { personalSummaryContainer.setVisible(false); } else { visibleFieldCount++; } //edit button AjaxFallbackLink editButton = new AjaxFallbackLink("editButton", new ResourceModel("button.edit")) { private static final long serialVersionUID = 1L; public void onClick(AjaxRequestTarget target) { Component newPanel = new MyInfoEdit(id, userProfile); newPanel.setOutputMarkupId(true); thisPanel.replaceWith(newPanel); if (target != null) { target.add(newPanel); //resize iframe target.appendJavaScript("setMainFrameHeight(window.name);"); } } }; editButton.add(new Label("editButtonLabel", new ResourceModel("button.edit"))); editButton.setOutputMarkupId(true); if (userProfile.isLocked() && !sakaiProxy.isSuperUser()) { editButton.setVisible(false); } add(editButton); //no fields message Label noFieldsMessage = new Label("noFieldsMessage", new ResourceModel("text.no.fields")); add(noFieldsMessage); if (visibleFieldCount > 0) { noFieldsMessage.setVisible(false); } }
From source file:org.sakaiproject.profile2.tool.pages.panels.MyInfoEdit.java
License:Educational Community License
public MyInfoEdit(final String id, final UserProfile userProfile) { super(id);/* w w w .ja v a 2 s . c o m*/ log.debug("MyInfoEdit()"); //this panel final Component thisPanel = this; //get userId final String userId = userProfile.getUserUuid(); //updates back to Account for some fields allowed? //boolean updateAllowed = sakaiProxy.isAccountUpdateAllowed(userId); //heading add(new Label("heading", new ResourceModel("heading.basic.edit"))); //setup form Form form = new Form("form", new Model(userProfile)); form.setOutputMarkupId(true); //form submit feedback final Label formFeedback = new Label("formFeedback"); formFeedback.setOutputMarkupPlaceholderTag(true); form.add(formFeedback); //add warning message if superUser and not editing own profile Label editWarning = new Label("editWarning"); editWarning.setVisible(false); if (sakaiProxy.isSuperUserAndProxiedToUser(userId)) { editWarning.setDefaultModel(new StringResourceModel("text.edit.other.warning", null, new Object[] { userProfile.getDisplayName() })); editWarning.setEscapeModelStrings(false); editWarning.setVisible(true); } form.add(editWarning); //We don't need to get the info from userProfile, we load it into the form with a property model //just make sure that the form element id's match those in the model //firstName /* WebMarkupContainer firstNameContainer = new WebMarkupContainer("firstNameContainer"); firstNameContainer.add(new Label("firstNameLabel", new ResourceModel("profile.name.first"))); TextField firstName = new TextField("firstName", new PropertyModel(userProfile, "firstName")); //readonly view Label firstNameReadOnly = new Label("firstNameReadOnly", new PropertyModel(userProfile, "firstName")); if(updateAllowed) { firstNameReadOnly.setVisible(false); } else { firstName.setVisible(false); } firstNameContainer.add(firstName); firstNameContainer.add(firstNameReadOnly); form.add(firstNameContainer); */ //middleName /* WebMarkupContainer middleNameContainer = new WebMarkupContainer("middleNameContainer"); middleNameContainer.add(new Label("middleNameLabel", new ResourceModel("profile.name.middle"))); TextField middleName = new TextField("middleName", new PropertyModel(userProfile, "middleName")); middleNameContainer.add(middleName); form.add(middleNameContainer); */ //lastName /* WebMarkupContainer lastNameContainer = new WebMarkupContainer("lastNameContainer"); lastNameContainer.add(new Label("lastNameLabel", new ResourceModel("profile.name.last"))); TextField lastName = new TextField("lastName", new PropertyModel(userProfile, "lastName")); //readonly view Label lastNameReadOnly = new Label("lastNameReadOnly", new PropertyModel(userProfile, "lastName")); if(updateAllowed) { lastNameReadOnly.setVisible(false); } else { lastName.setVisible(false); } lastNameContainer.add(lastName); lastNameContainer.add(lastNameReadOnly); form.add(lastNameContainer); */ //nickname WebMarkupContainer nicknameContainer = new WebMarkupContainer("nicknameContainer"); nicknameContainer.add(new Label("nicknameLabel", new ResourceModel("profile.nickname"))); TextField nickname = new TextField("nickname", new PropertyModel(userProfile, "nickname")); nickname.setMarkupId("nicknameinput"); nickname.setOutputMarkupId(true); nicknameContainer.add(nickname); form.add(nicknameContainer); //birthday WebMarkupContainer birthdayContainer = new WebMarkupContainer("birthdayContainer"); birthdayContainer.add(new Label("birthdayLabel", new ResourceModel("profile.birthday"))); TextField birthday = new TextField("birthday", new PropertyModel(userProfile, "birthday")); birthday.setMarkupId("birthdayinput"); birthday.setOutputMarkupId(true); birthdayContainer.add(birthday); //tooltip birthdayContainer.add(new IconWithClueTip("birthdayToolTip", ProfileConstants.INFO_IMAGE, new ResourceModel("text.profile.birthyear.tooltip"))); form.add(birthdayContainer); //personal summary WebMarkupContainer personalSummaryContainer = new WebMarkupContainer("personalSummaryContainer"); personalSummaryContainer.add(new Label("personalSummaryLabel", new ResourceModel("profile.summary"))); TextArea personalSummary = new TextArea("personalSummary", new PropertyModel(userProfile, "personalSummary")); personalSummary.setMarkupId("summaryinput"); //personalSummary.setEditorConfig(CKEditorConfig.createCkConfig()); personalSummary.setOutputMarkupId(true); personalSummaryContainer.add(personalSummary); form.add(personalSummaryContainer); //submit button AjaxFallbackButton submitButton = new AjaxFallbackButton("submit", form) { protected void onSubmit(AjaxRequestTarget target, Form form) { //save() form, show message, then load display panel if (save(form)) { //post update event sakaiProxy.postEvent(ProfileConstants.EVENT_PROFILE_INFO_UPDATE, "/profile/" + userId, true); //post to wall if enabled if (true == sakaiProxy.isWallEnabledGlobally() && false == sakaiProxy.isSuperUserAndProxiedToUser(userId)) { wallLogic.addNewEventToWall(ProfileConstants.EVENT_PROFILE_INFO_UPDATE, sakaiProxy.getCurrentUserId()); } //repaint panel Component newPanel = new MyInfoDisplay(id, userProfile); newPanel.setOutputMarkupId(true); thisPanel.replaceWith(newPanel); if (target != null) { target.add(newPanel); //resize iframe target.appendJavaScript("setMainFrameHeight(window.name);"); } } else { //String js = "alert('Failed to save information. Contact your system administrator.');"; //target.prependJavascript(js); formFeedback.setDefaultModel(new ResourceModel("error.profile.save.info.failed")); formFeedback.add(new AttributeModifier("class", true, new Model<String>("save-failed-error"))); target.add(formFeedback); } } protected void updateAjaxAttributes(AjaxRequestAttributes attributes) { super.updateAjaxAttributes(attributes); AjaxCallListener myAjaxCallListener = new AjaxCallListener() { @Override public CharSequence getBeforeHandler(Component component) { return "doUpdateCK()"; } }; attributes.getAjaxCallListeners().add(myAjaxCallListener); } }; submitButton.setModel(new ResourceModel("button.save.changes")); form.add(submitButton); //cancel button AjaxFallbackButton cancelButton = new AjaxFallbackButton("cancel", new ResourceModel("button.cancel"), form) { private static final long serialVersionUID = 1L; protected void onSubmit(AjaxRequestTarget target, Form form) { Component newPanel = new MyInfoDisplay(id, userProfile); newPanel.setOutputMarkupId(true); thisPanel.replaceWith(newPanel); if (target != null) { target.add(newPanel); //resize iframe target.appendJavaScript("setMainFrameHeight(window.name);"); } } }; cancelButton.setDefaultFormProcessing(false); form.add(cancelButton); //feedback stuff - make this a class and instance it with diff params //WebMarkupContainer formFeedback = new WebMarkupContainer("formFeedback"); //formFeedback.add(new Label("feedbackMsg", "some message")); //formFeedback.add(new AjaxIndicator("feedbackImg")); //form.add(formFeedback); //add form to page add(form); }
From source file:org.sakaiproject.profile2.tool.pages.panels.MyInterestsDisplay.java
License:Educational Community License
public MyInterestsDisplay(final String id, final UserProfile userProfile) { super(id);// www. jav a2 s .c om //this panel stuff final Component thisPanel = this; //get userProfile from userProfileModel //UserProfile userProfile = (UserProfile) this.getModelObject(); //get info from userProfile since we need to validate it and turn things off if not set. //otherwise we could just use a propertymodel // favourites and other String favouriteBooks = userProfile.getFavouriteBooks(); String favouriteTvShows = userProfile.getFavouriteTvShows(); String favouriteMovies = userProfile.getFavouriteMovies(); String favouriteQuotes = userProfile.getFavouriteQuotes(); //heading add(new Label("heading", new ResourceModel("heading.interests"))); //favourite books WebMarkupContainer booksContainer = new WebMarkupContainer("booksContainer"); booksContainer.add(new Label("booksLabel", new ResourceModel("profile.favourite.books"))); booksContainer.add(new Label("favouriteBooks", favouriteBooks)); add(booksContainer); if (StringUtils.isBlank(favouriteBooks)) { booksContainer.setVisible(false); } else { visibleFieldCount++; } //favourite tv shows WebMarkupContainer tvContainer = new WebMarkupContainer("tvContainer"); tvContainer.add(new Label("tvLabel", new ResourceModel("profile.favourite.tv"))); tvContainer.add(new Label("favouriteTvShows", favouriteTvShows)); add(tvContainer); if (StringUtils.isBlank(favouriteTvShows)) { tvContainer.setVisible(false); } else { visibleFieldCount++; } //favourite movies WebMarkupContainer moviesContainer = new WebMarkupContainer("moviesContainer"); moviesContainer.add(new Label("moviesLabel", new ResourceModel("profile.favourite.movies"))); moviesContainer.add(new Label("favouriteMovies", favouriteMovies)); add(moviesContainer); if (StringUtils.isBlank(favouriteMovies)) { moviesContainer.setVisible(false); } else { visibleFieldCount++; } //favourite quotes WebMarkupContainer quotesContainer = new WebMarkupContainer("quotesContainer"); quotesContainer.add(new Label("quotesLabel", new ResourceModel("profile.favourite.quotes"))); quotesContainer.add(new Label("favouriteQuotes", favouriteQuotes)); add(quotesContainer); if (StringUtils.isBlank(favouriteQuotes)) { quotesContainer.setVisible(false); } else { visibleFieldCount++; } //edit button AjaxFallbackLink editButton = new AjaxFallbackLink("editButton", new ResourceModel("button.edit")) { private static final long serialVersionUID = 1L; public void onClick(AjaxRequestTarget target) { Component newPanel = new MyInterestsEdit(id, userProfile); newPanel.setOutputMarkupId(true); thisPanel.replaceWith(newPanel); if (target != null) { target.add(newPanel); //resize iframe target.appendJavaScript("setMainFrameHeight(window.name);"); } } }; editButton.add(new Label("editButtonLabel", new ResourceModel("button.edit"))); editButton.setOutputMarkupId(true); if (userProfile.isLocked() && !sakaiProxy.isSuperUser()) { editButton.setVisible(false); } add(editButton); //no fields message Label noFieldsMessage = new Label("noFieldsMessage", new ResourceModel("text.no.fields")); add(noFieldsMessage); if (visibleFieldCount > 0) { noFieldsMessage.setVisible(false); } }
From source file:org.sakaiproject.profile2.tool.pages.panels.MyInterestsEdit.java
License:Educational Community License
public MyInterestsEdit(final String id, final UserProfile userProfile) { super(id);//from w ww . j ava2s . c o m log.debug("MyInterestsEdit()"); //this panel final Component thisPanel = this; //get userId final String userId = userProfile.getUserUuid(); //heading add(new Label("heading", new ResourceModel("heading.interests.edit"))); //setup form Form form = new Form("form", new Model(userProfile)); form.setOutputMarkupId(true); //form submit feedback final Label formFeedback = new Label("formFeedback"); formFeedback.setOutputMarkupPlaceholderTag(true); form.add(formFeedback); //add warning message if superUser and not editing own profile Label editWarning = new Label("editWarning"); editWarning.setVisible(false); if (sakaiProxy.isSuperUserAndProxiedToUser(userId)) { editWarning.setDefaultModel(new StringResourceModel("text.edit.other.warning", null, new Object[] { userProfile.getDisplayName() })); editWarning.setEscapeModelStrings(false); editWarning.setVisible(true); } form.add(editWarning); //We don't need to get the info from userProfile, we load it into the form with a property model //just make sure that the form element id's match those in the model //favourite books WebMarkupContainer booksContainer = new WebMarkupContainer("booksContainer"); booksContainer.add(new Label("booksLabel", new ResourceModel("profile.favourite.books"))); TextArea favouriteBooks = new TextArea("favouriteBooks", new PropertyModel(userProfile, "favouriteBooks")); favouriteBooks.setMarkupId("favouritebooksinput"); favouriteBooks.setOutputMarkupId(true); booksContainer.add(favouriteBooks); form.add(booksContainer); //favourite tv shows WebMarkupContainer tvContainer = new WebMarkupContainer("tvContainer"); tvContainer.add(new Label("tvLabel", new ResourceModel("profile.favourite.tv"))); TextArea favouriteTvShows = new TextArea("favouriteTvShows", new PropertyModel(userProfile, "favouriteTvShows")); favouriteTvShows.setMarkupId("favouritetvinput"); favouriteTvShows.setOutputMarkupId(true); tvContainer.add(favouriteTvShows); form.add(tvContainer); //favourite movies WebMarkupContainer moviesContainer = new WebMarkupContainer("moviesContainer"); moviesContainer.add(new Label("moviesLabel", new ResourceModel("profile.favourite.movies"))); TextArea favouriteMovies = new TextArea("favouriteMovies", new PropertyModel(userProfile, "favouriteMovies")); favouriteMovies.setMarkupId("favouritemoviesinput"); favouriteMovies.setOutputMarkupId(true); moviesContainer.add(favouriteMovies); form.add(moviesContainer); //favourite quotes WebMarkupContainer quotesContainer = new WebMarkupContainer("quotesContainer"); quotesContainer.add(new Label("quotesLabel", new ResourceModel("profile.favourite.quotes"))); TextArea favouriteQuotes = new TextArea("favouriteQuotes", new PropertyModel(userProfile, "favouriteQuotes")); favouriteQuotes.setMarkupId("favouritequotesinput"); favouriteQuotes.setOutputMarkupId(true); quotesContainer.add(favouriteQuotes); form.add(quotesContainer); //submit button AjaxFallbackButton submitButton = new AjaxFallbackButton("submit", new ResourceModel("button.save.changes"), form) { private static final long serialVersionUID = 1L; protected void onSubmit(AjaxRequestTarget target, Form form) { //save() form, show message, then load display panel if (save(form)) { //post update event sakaiProxy.postEvent(ProfileConstants.EVENT_PROFILE_INTERESTS_UPDATE, "/profile/" + userId, true); //post to wall if enabled if (true == sakaiProxy.isWallEnabledGlobally() && false == sakaiProxy.isSuperUserAndProxiedToUser(userId)) { wallLogic.addNewEventToWall(ProfileConstants.EVENT_PROFILE_INTERESTS_UPDATE, sakaiProxy.getCurrentUserId()); } //repaint panel Component newPanel = new MyInterestsDisplay(id, userProfile); newPanel.setOutputMarkupId(true); thisPanel.replaceWith(newPanel); if (target != null) { target.add(newPanel); //resize iframe target.appendJavaScript("setMainFrameHeight(window.name);"); } } else { //String js = "alert('Failed to save information. Contact your system administrator.');"; //target.prependJavascript(js); formFeedback.setDefaultModel(new ResourceModel("error.profile.save.interests.failed")); formFeedback.add(new AttributeModifier("class", true, new Model<String>("save-failed-error"))); target.add(formFeedback); } } //@Override //protected IAjaxCallDecorator getAjaxCallDecorator() { // return CKEditorTextArea.getAjaxCallDecoratedToUpdateElementForAllEditorsOnPage(); //} }; form.add(submitButton); //cancel button AjaxFallbackButton cancelButton = new AjaxFallbackButton("cancel", new ResourceModel("button.cancel"), form) { private static final long serialVersionUID = 1L; protected void onSubmit(AjaxRequestTarget target, Form form) { Component newPanel = new MyInterestsDisplay(id, userProfile); newPanel.setOutputMarkupId(true); thisPanel.replaceWith(newPanel); if (target != null) { target.add(newPanel); //resize iframe target.appendJavaScript("setMainFrameHeight(window.name);"); //need a scrollTo action here, to scroll down the page to the section } } }; cancelButton.setDefaultFormProcessing(false); form.add(cancelButton); //feedback stuff - make this a class and insance it with diff params //WebMarkupContainer formFeedback = new WebMarkupContainer("formFeedback"); //formFeedback.add(new Label("feedbackMsg", "some message")); //formFeedback.add(new AjaxIndicator("feedbackImg")); //form.add(formFeedback); //add form to page add(form); }
From source file:org.sakaiproject.profile2.tool.pages.panels.MyStaffDisplay.java
License:Educational Community License
public MyStaffDisplay(final String id, final UserProfile userProfile) { super(id);/*from w w w . j a v a 2 s . c o m*/ //this panel stuff final Component thisPanel = this; //get info from userProfile String department = userProfile.getDepartment(); String position = userProfile.getPosition(); String school = userProfile.getSchool(); String room = userProfile.getRoom(); String staffProfile = userProfile.getStaffProfile(); String universityProfileUrl = userProfile.getUniversityProfileUrl(); String academicProfileUrl = userProfile.getAcademicProfileUrl(); String publications = userProfile.getPublications(); //heading add(new Label("heading", new ResourceModel("heading.staff"))); //department WebMarkupContainer departmentContainer = new WebMarkupContainer("departmentContainer"); departmentContainer.add(new Label("departmentLabel", new ResourceModel("profile.department"))); departmentContainer.add(new Label("department", department)); add(departmentContainer); if (StringUtils.isBlank(department)) { departmentContainer.setVisible(false); } else { visibleFieldCount++; } //position WebMarkupContainer positionContainer = new WebMarkupContainer("positionContainer"); positionContainer.add(new Label("positionLabel", new ResourceModel("profile.position"))); positionContainer.add(new Label("position", position)); add(positionContainer); if (StringUtils.isBlank(position)) { positionContainer.setVisible(false); } else { visibleFieldCount++; } //school WebMarkupContainer schoolContainer = new WebMarkupContainer("schoolContainer"); schoolContainer.add(new Label("schoolLabel", new ResourceModel("profile.school"))); schoolContainer.add(new Label("school", school)); add(schoolContainer); if (StringUtils.isBlank(school)) { schoolContainer.setVisible(false); } else { visibleFieldCount++; } //room WebMarkupContainer roomContainer = new WebMarkupContainer("roomContainer"); roomContainer.add(new Label("roomLabel", new ResourceModel("profile.room"))); roomContainer.add(new Label("room", room)); add(roomContainer); if (StringUtils.isBlank(room)) { roomContainer.setVisible(false); } else { visibleFieldCount++; } //staff profile WebMarkupContainer staffProfileContainer = new WebMarkupContainer("staffProfileContainer"); staffProfileContainer.add(new Label("staffProfileLabel", new ResourceModel("profile.staffprofile"))); staffProfileContainer.add( new Label("staffProfile", ProfileUtils.processHtml(staffProfile)).setEscapeModelStrings(false)); add(staffProfileContainer); if (StringUtils.isBlank(staffProfile)) { staffProfileContainer.setVisible(false); } else { visibleFieldCount++; } //university profile URL WebMarkupContainer universityProfileUrlContainer = new WebMarkupContainer("universityProfileUrlContainer"); universityProfileUrlContainer .add(new Label("universityProfileUrlLabel", new ResourceModel("profile.universityprofileurl"))); universityProfileUrlContainer .add(new ExternalLink("universityProfileUrl", universityProfileUrl, universityProfileUrl)); add(universityProfileUrlContainer); if (StringUtils.isBlank(universityProfileUrl)) { universityProfileUrlContainer.setVisible(false); } else { visibleFieldCount++; } //academic/research profile URL WebMarkupContainer academicProfileUrlContainer = new WebMarkupContainer("academicProfileUrlContainer"); academicProfileUrlContainer .add(new Label("academicProfileUrlLabel", new ResourceModel("profile.academicprofileurl"))); academicProfileUrlContainer .add(new ExternalLink("academicProfileUrl", academicProfileUrl, academicProfileUrl)); add(academicProfileUrlContainer); if (StringUtils.isBlank(academicProfileUrl)) { academicProfileUrlContainer.setVisible(false); } else { visibleFieldCount++; } //publications WebMarkupContainer publicationsContainer = new WebMarkupContainer("publicationsContainer"); publicationsContainer.add(new Label("publicationsLabel", new ResourceModel("profile.publications"))); publicationsContainer.add( new Label("publications", ProfileUtils.processHtml(publications)).setEscapeModelStrings(false)); add(publicationsContainer); if (StringUtils.isBlank(publications)) { publicationsContainer.setVisible(false); } else { visibleFieldCount++; } //edit button AjaxFallbackLink editButton = new AjaxFallbackLink("editButton", new ResourceModel("button.edit")) { private static final long serialVersionUID = 1L; public void onClick(AjaxRequestTarget target) { Component newPanel = new MyStaffEdit(id, userProfile); newPanel.setOutputMarkupId(true); thisPanel.replaceWith(newPanel); if (target != null) { target.add(newPanel); //resize iframe target.appendJavaScript("setMainFrameHeight(window.name);"); } } }; editButton.add(new Label("editButtonLabel", new ResourceModel("button.edit"))); editButton.setOutputMarkupId(true); if (userProfile.isLocked() && !sakaiProxy.isSuperUser()) { editButton.setVisible(false); } add(editButton); //no fields message Label noFieldsMessage = new Label("noFieldsMessage", new ResourceModel("text.no.fields")); add(noFieldsMessage); if (visibleFieldCount > 0) { noFieldsMessage.setVisible(false); } }
From source file:org.sakaiproject.profile2.tool.pages.panels.MyStaffEdit.java
License:Educational Community License
public MyStaffEdit(final String id, final UserProfile userProfile) { super(id);/*from w ww . j a va2 s. c om*/ log.debug("MyStaffEdit()"); //this panel final Component thisPanel = this; //get userId final String userId = userProfile.getUserUuid(); //heading add(new Label("heading", new ResourceModel("heading.staff.edit"))); //setup form Form form = new Form("form", new Model(userProfile)); form.setOutputMarkupId(true); //form submit feedback final Label formFeedback = new Label("formFeedback"); formFeedback.setOutputMarkupPlaceholderTag(true); form.add(formFeedback); //add warning message if superUser and not editing own profile Label editWarning = new Label("editWarning"); editWarning.setVisible(false); if (sakaiProxy.isSuperUserAndProxiedToUser(userId)) { editWarning.setDefaultModel(new StringResourceModel("text.edit.other.warning", null, new Object[] { userProfile.getDisplayName() })); editWarning.setEscapeModelStrings(false); editWarning.setVisible(true); } form.add(editWarning); //We don't need to get the info from userProfile, we load it into the form with a property model //just make sure that the form element id's match those in the model //position WebMarkupContainer positionContainer = new WebMarkupContainer("positionContainer"); positionContainer.add(new Label("positionLabel", new ResourceModel("profile.position"))); TextField position = new TextField("position", new PropertyModel(userProfile, "position")); position.setMarkupId("positioninput"); position.setOutputMarkupId(true); positionContainer.add(position); form.add(positionContainer); //department WebMarkupContainer departmentContainer = new WebMarkupContainer("departmentContainer"); departmentContainer.add(new Label("departmentLabel", new ResourceModel("profile.department"))); TextField department = new TextField("department", new PropertyModel(userProfile, "department")); department.setMarkupId("departmentinput"); department.setOutputMarkupId(true); departmentContainer.add(department); form.add(departmentContainer); //school WebMarkupContainer schoolContainer = new WebMarkupContainer("schoolContainer"); schoolContainer.add(new Label("schoolLabel", new ResourceModel("profile.school"))); TextField school = new TextField("school", new PropertyModel(userProfile, "school")); school.setMarkupId("schoolinput"); school.setOutputMarkupId(true); schoolContainer.add(school); form.add(schoolContainer); //room WebMarkupContainer roomContainer = new WebMarkupContainer("roomContainer"); roomContainer.add(new Label("roomLabel", new ResourceModel("profile.room"))); TextField room = new TextField("room", new PropertyModel(userProfile, "room")); room.setMarkupId("roominput"); room.setOutputMarkupId(true); roomContainer.add(room); form.add(roomContainer); //staffprofile WebMarkupContainer staffProfileContainer = new WebMarkupContainer("staffProfileContainer"); staffProfileContainer.add(new Label("staffProfileLabel", new ResourceModel("profile.staffprofile"))); TextArea staffProfile = new TextArea("staffProfile", new PropertyModel(userProfile, "staffProfile")); staffProfile.setMarkupId("staffprofileinput"); staffProfile.setOutputMarkupId(true); staffProfileContainer.add(staffProfile); form.add(staffProfileContainer); //university profile URL WebMarkupContainer universityProfileUrlContainer = new WebMarkupContainer("universityProfileUrlContainer"); universityProfileUrlContainer .add(new Label("universityProfileUrlLabel", new ResourceModel("profile.universityprofileurl"))); TextField universityProfileUrl = new TextField("universityProfileUrl", new PropertyModel(userProfile, "universityProfileUrl")) { private static final long serialVersionUID = 1L; // add http:// if missing @Override protected void convertInput() { String input = getInput(); if (StringUtils.isNotBlank(input) && !(input.startsWith("http://") || input.startsWith("https://"))) { setConvertedInput("http://" + input); } else { setConvertedInput(StringUtils.isBlank(input) ? null : input); } } }; universityProfileUrl.setMarkupId("universityprofileurlinput"); universityProfileUrl.setOutputMarkupId(true); universityProfileUrl.add(new UrlValidator()); universityProfileUrlContainer.add(universityProfileUrl); final FeedbackLabel universityProfileUrlFeedback = new FeedbackLabel("universityProfileUrlFeedback", universityProfileUrl); universityProfileUrlFeedback.setMarkupId("universityProfileUrlFeedback"); universityProfileUrlFeedback.setOutputMarkupId(true); universityProfileUrlContainer.add(universityProfileUrlFeedback); universityProfileUrl.add(new ComponentVisualErrorBehaviour("onblur", universityProfileUrlFeedback)); form.add(universityProfileUrlContainer); //academic/research profile URL WebMarkupContainer academicProfileUrlContainer = new WebMarkupContainer("academicProfileUrlContainer"); academicProfileUrlContainer .add(new Label("academicProfileUrlLabel", new ResourceModel("profile.academicprofileurl"))); TextField academicProfileUrl = new TextField("academicProfileUrl", new PropertyModel(userProfile, "academicProfileUrl")) { private static final long serialVersionUID = 1L; // add http:// if missing @Override protected void convertInput() { String input = getInput(); if (StringUtils.isNotBlank(input) && !(input.startsWith("http://") || input.startsWith("https://"))) { setConvertedInput("http://" + input); } else { setConvertedInput(StringUtils.isBlank(input) ? null : input); } } }; academicProfileUrl.setMarkupId("academicprofileurlinput"); academicProfileUrl.setOutputMarkupId(true); academicProfileUrl.add(new UrlValidator()); academicProfileUrlContainer.add(academicProfileUrl); final FeedbackLabel academicProfileUrlFeedback = new FeedbackLabel("academicProfileUrlFeedback", academicProfileUrl); academicProfileUrlFeedback.setMarkupId("academicProfileUrlFeedback"); academicProfileUrlFeedback.setOutputMarkupId(true); academicProfileUrlContainer.add(academicProfileUrlFeedback); academicProfileUrl.add(new ComponentVisualErrorBehaviour("onblur", academicProfileUrlFeedback)); form.add(academicProfileUrlContainer); //publications WebMarkupContainer publicationsContainer = new WebMarkupContainer("publicationsContainer"); publicationsContainer.add(new Label("publicationsLabel", new ResourceModel("profile.publications"))); TextArea publications = new TextArea("publications", new PropertyModel(userProfile, "publications")); publications.setMarkupId("publicationsinput"); publications.setOutputMarkupId(true); publicationsContainer.add(publications); form.add(publicationsContainer); //submit button AjaxFallbackButton submitButton = new AjaxFallbackButton("submit", new ResourceModel("button.save.changes"), form) { private static final long serialVersionUID = 1L; protected void onSubmit(AjaxRequestTarget target, Form form) { //save() form, show message, then load display panel if (save(form)) { //post update event sakaiProxy.postEvent(ProfileConstants.EVENT_PROFILE_STAFF_UPDATE, "/profile/" + userId, true); //post to wall if enabled if (true == sakaiProxy.isWallEnabledGlobally() && false == sakaiProxy.isSuperUserAndProxiedToUser(userProfile.getUserUuid())) { wallLogic.addNewEventToWall(ProfileConstants.EVENT_PROFILE_STAFF_UPDATE, sakaiProxy.getCurrentUserId()); } //repaint panel Component newPanel = new MyStaffDisplay(id, userProfile); newPanel.setOutputMarkupId(true); thisPanel.replaceWith(newPanel); if (target != null) { target.add(newPanel); //resize iframe target.appendJavaScript("setMainFrameHeight(window.name);"); } } else { //String js = "alert('Failed to save information. Contact your system administrator.');"; //target.prependJavascript(js); formFeedback.setDefaultModel(new ResourceModel("error.profile.save.academic.failed")); formFeedback.add(new AttributeModifier("class", true, new Model<String>("save-failed-error"))); target.add(formFeedback); } } protected void updateAjaxAttributes(AjaxRequestAttributes attributes) { super.updateAjaxAttributes(attributes); AjaxCallListener myAjaxCallListener = new AjaxCallListener() { @Override public CharSequence getBeforeHandler(Component component) { return "doUpdateCK()"; } }; attributes.getAjaxCallListeners().add(myAjaxCallListener); } }; form.add(submitButton); //cancel button AjaxFallbackButton cancelButton = new AjaxFallbackButton("cancel", new ResourceModel("button.cancel"), form) { private static final long serialVersionUID = 1L; protected void onSubmit(AjaxRequestTarget target, Form form) { Component newPanel = new MyStaffDisplay(id, userProfile); newPanel.setOutputMarkupId(true); thisPanel.replaceWith(newPanel); if (target != null) { target.add(newPanel); //resize iframe target.appendJavaScript("setMainFrameHeight(window.name);"); //need a scrollTo action here, to scroll down the page to the section } } }; cancelButton.setDefaultFormProcessing(false); form.add(cancelButton); //add form to page add(form); }
From source file:uk.ac.rdg.evoportal.pages.ComputeJobsDataView.java
License:Apache License
@Override protected void populateItem(final Item item) { ComputeJob job = (ComputeJob) item.getModelObject(); final int jobID = job.getJobID(); final BookmarkablePageLink<Void> link = new BookmarkablePageLink<Void>("details", ComputeJobDetail.class); link.setParameter("jobID", jobID); link.add(new Label("jobID", Integer.toString(jobID))); item.add(link);//from w w w .j a va2 s .com item.add(new Label("name", job.getLabel())); item.add(new Label("submitted", new Date(job.getSubmitTime()).toString())); char s = job.getStatus(); String status = "Undefined"; boolean isStopped = false; status = GlobalConstants.getStatusMsg(s); if (s == 'S') isStopped = true; Label statusLabel = new Label("status", status); item.add(statusLabel); item.add(new Label("nodes", job.getNodes() + " (" + job.getNodes() * 4 + ")")); item.add(new Label("timeRequested", TimeUtil.millisToLongDHMS(job.getTimeRequested()))); item.add(new Label("timeUsed", TimeUtil.millisToLongDHMS(job.getTimeUsed()))); StopOrDeleteLink stopLink = new StopOrDeleteLink("stopOrDeleteLink", isStopped, job.getOwner(), job.getJobID()); String stopOrDeleteLabel = "Stop"; if (isStopped) { stopOrDeleteLabel = "Delete"; } stopLink.add(new Label("stopOrDelete", stopOrDeleteLabel)); item.add(stopLink); if (!isStopped) { } item.setOutputMarkupId(true); AjaxSelfUpdatingTimerBehavior timer = new AjaxSelfUpdatingTimerBehavior(Duration.seconds(15)) { @Override protected void onPostProcessTarget(AjaxRequestTarget target) { ComputeJob refreshedJob = ComputeJobsDataProvider.get(jobID); item.get("status") .replaceWith(new Label("status", GlobalConstants.getStatusMsg(refreshedJob.getStatus()))); item.get("timeUsed") .replaceWith(new Label("timeUsed", TimeUtil.millisToLongDHMS(refreshedJob.getTimeUsed()))); if (refreshedJob.getStatus() == 'S') { Component c = item.get("stopOrDeleteLink"); if (c instanceof StopOrDeleteLink) { if (((StopOrDeleteLink) c).getJobID() == refreshedJob.getJobID()) { StopOrDeleteLink stopLink = new StopOrDeleteLink("stopOrDeleteLink", true, refreshedJob.getOwner(), refreshedJob.getJobID()); stopLink.add(new Label("stopOrDelete", "Delete")); c.replaceWith(stopLink); } } } } }; item.add(timer); }