List of usage examples for org.apache.wicket.markup.html.form Radio setMarkupId
final void setMarkupId(Component comp)
From source file:org.sakaiproject.profile2.tool.pages.MyPreferences.java
License:Educational Community License
public MyPreferences() { log.debug("MyPreferences()"); disableLink(preferencesLink);//from ww w . ja va2s. c o m //get current user final String userUuid = sakaiProxy.getCurrentUserId(); //get the prefs record for this user from the database, or a default if none exists yet profilePreferences = preferencesLogic.getPreferencesRecordForUser(userUuid, false); //if null, throw exception if (profilePreferences == null) { throw new ProfilePreferencesNotDefinedException("Couldn't retrieve preferences record for " + userUuid); } //get email address for this user String emailAddress = sakaiProxy.getUserEmail(userUuid); //if no email, set a message into it fo display if (emailAddress == null || emailAddress.length() == 0) { emailAddress = new ResourceModel("preferences.email.none").getObject(); } Label heading = new Label("heading", new ResourceModel("heading.preferences")); add(heading); //feedback for form submit action final Label formFeedback = new Label("formFeedback"); formFeedback.setOutputMarkupPlaceholderTag(true); final String formFeedbackId = formFeedback.getMarkupId(); add(formFeedback); //create model CompoundPropertyModel<ProfilePreferences> preferencesModel = new CompoundPropertyModel<ProfilePreferences>( profilePreferences); //setup form Form<ProfilePreferences> form = new Form<ProfilePreferences>("form", preferencesModel); form.setOutputMarkupId(true); //EMAIL SECTION //email settings form.add(new Label("emailSectionHeading", new ResourceModel("heading.section.email"))); form.add(new Label("emailSectionText", new StringResourceModel("preferences.email.message", null, new Object[] { emailAddress })) .setEscapeModelStrings(false)); //on/off labels form.add(new Label("prefOn", new ResourceModel("preference.option.on"))); form.add(new Label("prefOff", new ResourceModel("preference.option.off"))); //request emails final RadioGroup<Boolean> emailRequests = new RadioGroup<Boolean>("requestEmailEnabled", new PropertyModel<Boolean>(preferencesModel, "requestEmailEnabled")); Radio requestsOn = new Radio<Boolean>("requestsOn", new Model<Boolean>(Boolean.valueOf(true))); requestsOn.setMarkupId("requestsoninput"); requestsOn.setOutputMarkupId(true); emailRequests.add(requestsOn); Radio requestsOff = new Radio<Boolean>("requestsOff", new Model<Boolean>(Boolean.valueOf(false))); requestsOff.setMarkupId("requestsoffinput"); requestsOff.setOutputMarkupId(true); emailRequests.add(requestsOff); emailRequests.add(new Label("requestsLabel", new ResourceModel("preferences.email.requests"))); form.add(emailRequests); //updater emailRequests.add(new AjaxFormChoiceComponentUpdatingBehavior() { private static final long serialVersionUID = 1L; protected void onUpdate(AjaxRequestTarget target) { target.appendJavaScript("$('#" + formFeedbackId + "').fadeOut();"); } }); //visibility for request emails emailRequests.setVisible(sakaiProxy.isConnectionsEnabledGlobally()); //confirm emails final RadioGroup<Boolean> emailConfirms = new RadioGroup<Boolean>("confirmEmailEnabled", new PropertyModel<Boolean>(preferencesModel, "confirmEmailEnabled")); Radio confirmsOn = new Radio<Boolean>("confirmsOn", new Model<Boolean>(Boolean.valueOf(true))); confirmsOn.setMarkupId("confirmsoninput"); confirmsOn.setOutputMarkupId(true); emailConfirms.add(confirmsOn); Radio confirmsOff = new Radio<Boolean>("confirmsOff", new Model<Boolean>(Boolean.valueOf(false))); confirmsOff.setMarkupId("confirmsoffinput"); confirmsOff.setOutputMarkupId(true); emailConfirms.add(confirmsOff); emailConfirms.add(new Label("confirmsLabel", new ResourceModel("preferences.email.confirms"))); form.add(emailConfirms); //updater emailConfirms.add(new AjaxFormChoiceComponentUpdatingBehavior() { private static final long serialVersionUID = 1L; protected void onUpdate(AjaxRequestTarget target) { target.appendJavaScript("$('#" + formFeedbackId + "').fadeOut();"); } }); //visibility for confirm emails emailConfirms.setVisible(sakaiProxy.isConnectionsEnabledGlobally()); //new message emails final RadioGroup<Boolean> emailNewMessage = new RadioGroup<Boolean>("messageNewEmailEnabled", new PropertyModel<Boolean>(preferencesModel, "messageNewEmailEnabled")); Radio messageNewOn = new Radio<Boolean>("messageNewOn", new Model<Boolean>(Boolean.valueOf(true))); messageNewOn.setMarkupId("messagenewoninput"); messageNewOn.setOutputMarkupId(true); emailNewMessage.add(messageNewOn); Radio messageNewOff = new Radio<Boolean>("messageNewOff", new Model<Boolean>(Boolean.valueOf(false))); messageNewOff.setMarkupId("messagenewoffinput"); messageNewOff.setOutputMarkupId(true); emailNewMessage.add(messageNewOff); emailNewMessage.add(new Label("messageNewLabel", new ResourceModel("preferences.email.message.new"))); form.add(emailNewMessage); //updater emailNewMessage.add(new AjaxFormChoiceComponentUpdatingBehavior() { private static final long serialVersionUID = 1L; protected void onUpdate(AjaxRequestTarget target) { target.appendJavaScript("$('#" + formFeedbackId + "').fadeOut();"); } }); emailNewMessage.setVisible(sakaiProxy.isMessagingEnabledGlobally()); //message reply emails final RadioGroup<Boolean> emailReplyMessage = new RadioGroup<Boolean>("messageReplyEmailEnabled", new PropertyModel<Boolean>(preferencesModel, "messageReplyEmailEnabled")); Radio messageReplyOn = new Radio<Boolean>("messageReplyOn", new Model<Boolean>(Boolean.valueOf(true))); messageReplyOn.setMarkupId("messagereplyoninput"); messageNewOn.setOutputMarkupId(true); emailReplyMessage.add(messageReplyOn); Radio messageReplyOff = new Radio<Boolean>("messageReplyOff", new Model<Boolean>(Boolean.valueOf(false))); messageReplyOff.setMarkupId("messagereplyoffinput"); messageNewOff.setOutputMarkupId(true); emailReplyMessage.add(messageReplyOff); emailReplyMessage.add(new Label("messageReplyLabel", new ResourceModel("preferences.email.message.reply"))); form.add(emailReplyMessage); //updater emailReplyMessage.add(new AjaxFormChoiceComponentUpdatingBehavior() { private static final long serialVersionUID = 1L; protected void onUpdate(AjaxRequestTarget target) { target.appendJavaScript("$('#" + formFeedbackId + "').fadeOut();"); } }); emailReplyMessage.setVisible(sakaiProxy.isMessagingEnabledGlobally()); // new wall item notification emails final RadioGroup<Boolean> wallItemNew = new RadioGroup<Boolean>("wallItemNewEmailEnabled", new PropertyModel<Boolean>(preferencesModel, "wallItemNewEmailEnabled")); Radio wallItemNewOn = new Radio<Boolean>("wallItemNewOn", new Model<Boolean>(Boolean.valueOf(true))); wallItemNewOn.setMarkupId("wallitemnewoninput"); wallItemNewOn.setOutputMarkupId(true); wallItemNew.add(wallItemNewOn); Radio wallItemNewOff = new Radio<Boolean>("wallItemNewOff", new Model<Boolean>(Boolean.valueOf(false))); wallItemNewOff.setMarkupId("wallitemnewoffinput"); wallItemNewOff.setOutputMarkupId(true); wallItemNew.add(wallItemNewOff); wallItemNew.add(new Label("wallItemNewLabel", new ResourceModel("preferences.email.wall.new"))); form.add(wallItemNew); //updater wallItemNew.add(new AjaxFormChoiceComponentUpdatingBehavior() { private static final long serialVersionUID = 1L; protected void onUpdate(AjaxRequestTarget target) { target.appendJavaScript("$('#" + formFeedbackId + "').fadeOut();"); } }); //visibility for wall items wallItemNew.setVisible(sakaiProxy.isWallEnabledGlobally()); // added to new worksite emails final RadioGroup<Boolean> worksiteNew = new RadioGroup<Boolean>("worksiteNewEmailEnabled", new PropertyModel<Boolean>(preferencesModel, "worksiteNewEmailEnabled")); Radio worksiteNewOn = new Radio<Boolean>("worksiteNewOn", new Model<Boolean>(Boolean.valueOf(true))); worksiteNewOn.setMarkupId("worksitenewoninput"); worksiteNewOn.setOutputMarkupId(true); worksiteNew.add(worksiteNewOn); Radio worksiteNewOff = new Radio<Boolean>("worksiteNewOff", new Model<Boolean>(Boolean.valueOf(false))); worksiteNewOff.setMarkupId("worksitenewoffinput"); worksiteNewOff.setOutputMarkupId(true); worksiteNew.add(worksiteNewOff); worksiteNew.add(new Label("worksiteNewLabel", new ResourceModel("preferences.email.worksite.new"))); form.add(worksiteNew); //updater worksiteNew.add(new AjaxFormChoiceComponentUpdatingBehavior() { private static final long serialVersionUID = 1L; protected void onUpdate(AjaxRequestTarget target) { target.appendJavaScript("$('#" + formFeedbackId + "').fadeOut();"); } }); // TWITTER SECTION //headings WebMarkupContainer twitterSectionHeadingContainer = new WebMarkupContainer( "twitterSectionHeadingContainer"); twitterSectionHeadingContainer .add(new Label("twitterSectionHeading", new ResourceModel("heading.section.twitter"))); twitterSectionHeadingContainer .add(new Label("twitterSectionText", new ResourceModel("preferences.twitter.message"))); form.add(twitterSectionHeadingContainer); //panel if (sakaiProxy.isTwitterIntegrationEnabledGlobally()) { form.add(new AjaxLazyLoadPanel("twitterPanel") { private static final long serialVersionUID = 1L; @Override public Component getLazyLoadComponent(String markupId) { return new TwitterPrefsPane(markupId, userUuid); } }); } else { form.add(new EmptyPanel("twitterPanel")); twitterSectionHeadingContainer.setVisible(false); } // IMAGE SECTION //only one of these can be selected at a time WebMarkupContainer is = new WebMarkupContainer("imageSettingsContainer"); is.setOutputMarkupId(true); // headings is.add(new Label("imageSettingsHeading", new ResourceModel("heading.section.image"))); is.add(new Label("imageSettingsText", new ResourceModel("preferences.image.message"))); officialImageEnabled = sakaiProxy.isUsingOfficialImageButAlternateSelectionEnabled(); gravatarEnabled = sakaiProxy.isGravatarImageEnabledGlobally(); //official image //checkbox WebMarkupContainer officialImageContainer = new WebMarkupContainer("officialImageContainer"); officialImageContainer .add(new Label("officialImageLabel", new ResourceModel("preferences.image.official"))); officialImage = new CheckBox("officialImage", new PropertyModel<Boolean>(preferencesModel, "useOfficialImage")); officialImage.setMarkupId("officialimageinput"); officialImage.setOutputMarkupId(true); officialImageContainer.add(officialImage); //updater officialImage.add(new AjaxFormComponentUpdatingBehavior("onchange") { private static final long serialVersionUID = 1L; protected void onUpdate(AjaxRequestTarget target) { //set gravatar to false since we can't have both active gravatarImage.setModelObject(false); if (gravatarEnabled) { target.add(gravatarImage); } target.appendJavaScript("$('#" + formFeedbackId + "').fadeOut();"); } }); is.add(officialImageContainer); //if using official images but alternate choice isn't allowed, hide this section if (!officialImageEnabled) { profilePreferences.setUseOfficialImage(false); //set the model false to clear data as well (doesnt really need to do this but we do it to keep things in sync) officialImageContainer.setVisible(false); } //gravatar //checkbox WebMarkupContainer gravatarContainer = new WebMarkupContainer("gravatarContainer"); gravatarContainer.add(new Label("gravatarLabel", new ResourceModel("preferences.image.gravatar"))); gravatarImage = new CheckBox("gravatarImage", new PropertyModel<Boolean>(preferencesModel, "useGravatar")); gravatarImage.setMarkupId("gravatarimageinput"); gravatarImage.setOutputMarkupId(true); gravatarContainer.add(gravatarImage); //updater gravatarImage.add(new AjaxFormComponentUpdatingBehavior("onchange") { private static final long serialVersionUID = 1L; protected void onUpdate(AjaxRequestTarget target) { //set gravatar to false since we can't have both active officialImage.setModelObject(false); if (officialImageEnabled) { target.add(officialImage); } target.appendJavaScript("$('#" + formFeedbackId + "').fadeOut();"); } }); is.add(gravatarContainer); //if gravatar's are disabled, hide this section if (!gravatarEnabled) { profilePreferences.setUseGravatar(false); //set the model false to clear data as well (doesnt really need to do this but we do it to keep things in sync) gravatarContainer.setVisible(false); } //if official image disabled and gravatar disabled, hide the entire container if (!officialImageEnabled && !gravatarEnabled) { is.setVisible(false); } form.add(is); // WIDGET SECTION WebMarkupContainer ws = new WebMarkupContainer("widgetSettingsContainer"); ws.setOutputMarkupId(true); int visibleWidgetCount = 0; //widget settings ws.add(new Label("widgetSettingsHeading", new ResourceModel("heading.section.widget"))); ws.add(new Label("widgetSettingsText", new ResourceModel("preferences.widget.message"))); //kudos WebMarkupContainer kudosContainer = new WebMarkupContainer("kudosContainer"); kudosContainer.add(new Label("kudosLabel", new ResourceModel("preferences.widget.kudos"))); CheckBox kudosSetting = new CheckBox("kudosSetting", new PropertyModel<Boolean>(preferencesModel, "showKudos")); kudosSetting.setMarkupId("kudosinput"); kudosSetting.setOutputMarkupId(true); kudosContainer.add(kudosSetting); //tooltip kudosContainer.add(new IconWithClueTip("kudosToolTip", ProfileConstants.INFO_IMAGE, new ResourceModel("preferences.widget.kudos.tooltip"))); //updater kudosSetting.add(new AjaxFormComponentUpdatingBehavior("onchange") { private static final long serialVersionUID = 1L; protected void onUpdate(AjaxRequestTarget target) { target.appendJavaScript("$('#" + formFeedbackId + "').fadeOut();"); } }); ws.add(kudosContainer); if (sakaiProxy.isMyKudosEnabledGlobally()) { visibleWidgetCount++; } else { kudosContainer.setVisible(false); } //gallery feed WebMarkupContainer galleryFeedContainer = new WebMarkupContainer("galleryFeedContainer"); galleryFeedContainer.add(new Label("galleryFeedLabel", new ResourceModel("preferences.widget.gallery"))); CheckBox galleryFeedSetting = new CheckBox("galleryFeedSetting", new PropertyModel<Boolean>(preferencesModel, "showGalleryFeed")); galleryFeedSetting.setMarkupId("galleryfeedsettinginput"); galleryFeedSetting.setOutputMarkupId(true); galleryFeedContainer.add(galleryFeedSetting); //tooltip galleryFeedContainer.add(new IconWithClueTip("galleryFeedToolTip", ProfileConstants.INFO_IMAGE, new ResourceModel("preferences.widget.gallery.tooltip"))); //updater galleryFeedSetting.add(new AjaxFormComponentUpdatingBehavior("onchange") { private static final long serialVersionUID = 1L; protected void onUpdate(AjaxRequestTarget target) { target.appendJavaScript("$('#" + formFeedbackId + "').fadeOut();"); } }); ws.add(galleryFeedContainer); if (sakaiProxy.isProfileGalleryEnabledGlobally()) { visibleWidgetCount++; } else { galleryFeedContainer.setVisible(false); } //online status WebMarkupContainer onlineStatusContainer = new WebMarkupContainer("onlineStatusContainer"); onlineStatusContainer .add(new Label("onlineStatusLabel", new ResourceModel("preferences.widget.onlinestatus"))); CheckBox onlineStatusSetting = new CheckBox("onlineStatusSetting", new PropertyModel<Boolean>(preferencesModel, "showOnlineStatus")); onlineStatusSetting.setMarkupId("onlinestatussettinginput"); onlineStatusSetting.setOutputMarkupId(true); onlineStatusContainer.add(onlineStatusSetting); //tooltip onlineStatusContainer.add(new IconWithClueTip("onlineStatusToolTip", ProfileConstants.INFO_IMAGE, new ResourceModel("preferences.widget.onlinestatus.tooltip"))); //updater onlineStatusSetting.add(new AjaxFormComponentUpdatingBehavior("onchange") { private static final long serialVersionUID = 1L; protected void onUpdate(AjaxRequestTarget target) { target.appendJavaScript("$('#" + formFeedbackId + "').fadeOut();"); } }); ws.add(onlineStatusContainer); if (sakaiProxy.isOnlineStatusEnabledGlobally()) { visibleWidgetCount++; } else { onlineStatusContainer.setVisible(false); } // Hide widget container if nothing to show if (visibleWidgetCount == 0) { ws.setVisible(false); } form.add(ws); //submit button IndicatingAjaxButton submitButton = new IndicatingAjaxButton("submit", form) { private static final long serialVersionUID = 1L; protected void onSubmit(AjaxRequestTarget target, Form<?> form) { //get the backing model ProfilePreferences profilePreferences = (ProfilePreferences) form.getModelObject(); formFeedback.setDefaultModel(new ResourceModel("success.preferences.save.ok")); formFeedback.add(new AttributeModifier("class", true, new Model<String>("success"))); //save if (preferencesLogic.savePreferencesRecord(profilePreferences)) { formFeedback.setDefaultModel(new ResourceModel("success.preferences.save.ok")); formFeedback.add(new AttributeModifier("class", true, new Model<String>("success"))); //post update event sakaiProxy.postEvent(ProfileConstants.EVENT_PREFERENCES_UPDATE, "/profile/" + userUuid, true); } else { formFeedback.setDefaultModel(new ResourceModel("error.preferences.save.failed")); formFeedback.add(new AttributeModifier("class", true, new Model<String>("alertMessage"))); } //resize iframe target.appendJavaScript("setMainFrameHeight(window.name);"); //PRFL-775 - set focus to feedback message so it is announced to screenreaders target.appendJavaScript("$('#" + formFeedbackId + "').focus();"); target.add(formFeedback); } }; submitButton.setModel(new ResourceModel("button.save.settings")); submitButton.setDefaultFormProcessing(false); form.add(submitButton); add(form); }
From source file:org.sakaiproject.profile2.tool.pages.MySearch.java
License:Educational Community License
public MySearch() { log.debug("MySearch()"); disableLink(searchLink);/*from w ww . j av a 2 s .c o m*/ //check for current search cookie CookieUtils utils = new CookieUtils(); searchCookie = utils.getCookie(ProfileConstants.SEARCH_COOKIE); //setup model to store the actions in the modal windows final FriendAction friendActionModel = new FriendAction(); //get current user info final String currentUserUuid = sakaiProxy.getCurrentUserId(); final String currentUserType = sakaiProxy.getUserType(currentUserUuid); /* * Combined search form */ //heading Label searchHeading = new Label("searchHeading", new ResourceModel("heading.search")); add(searchHeading); //setup form final StringModel searchStringModel = new StringModel(); Form<StringModel> searchForm = new Form<StringModel>("searchForm", new Model<StringModel>(searchStringModel)); searchForm.setOutputMarkupId(true); //search field searchForm.add(new Label("searchLabel", new ResourceModel("text.search.terms.label"))); searchField = new TextField<String>("searchField", new PropertyModel<String>(searchStringModel, "string")); searchField.setRequired(true); searchField.setMarkupId("searchinput"); searchField.setOutputMarkupId(true); searchForm.add(searchField); searchForm.add(new IconWithClueTip("searchToolTip", ProfileConstants.INFO_IMAGE, new ResourceModel("text.search.terms.tooltip"))); //by name or by interest radio group searchTypeRadioGroup = new RadioGroup<String>("searchTypeRadioGroup"); // so we can repaint after clicking on search history links searchTypeRadioGroup.setOutputMarkupId(true); searchTypeRadioGroup.setRenderBodyOnly(false); Radio<String> searchTypeRadioName = new Radio<String>("searchTypeName", new Model<String>(ProfileConstants.SEARCH_TYPE_NAME)); searchTypeRadioName.setMarkupId("searchtypenameinput"); searchTypeRadioName.setOutputMarkupId(true); searchTypeRadioName .add(new AttributeModifier("title", true, new ResourceModel("text.search.byname.tooltip"))); searchTypeRadioGroup.add(searchTypeRadioName); Radio<String> searchTypeRadioInterest = new Radio<String>("searchTypeInterest", new Model<String>(ProfileConstants.SEARCH_TYPE_INTEREST)); searchTypeRadioInterest.setMarkupId("searchtypeinterestinput"); searchTypeRadioInterest.setOutputMarkupId(true); searchTypeRadioInterest .add(new AttributeModifier("title", true, new ResourceModel("text.search.byinterest.tooltip"))); searchTypeRadioGroup.add(searchTypeRadioInterest); searchTypeRadioGroup.add(new Label("searchTypeNameLabel", new ResourceModel("text.search.byname.label"))); searchTypeRadioGroup .add(new Label("searchTypeInterestLabel", new ResourceModel("text.search.byinterest.label"))); searchForm.add(searchTypeRadioGroup); searchForm.add(new Label("connectionsLabel", new ResourceModel("text.search.include.connections"))); // model is true (include connections by default) connectionsCheckBox = new CheckBox("connectionsCheckBox", new Model<Boolean>(true)); connectionsCheckBox.setMarkupId("includeconnectionsinput"); connectionsCheckBox.setOutputMarkupId(true); //hide if connections disabled globally connectionsCheckBox.setVisible(sakaiProxy.isConnectionsEnabledGlobally()); searchForm.add(connectionsCheckBox); final List<Site> worksites = sakaiProxy.getUserSites(); final boolean hasWorksites = worksites.size() > 0; searchForm.add(new Label("worksiteLabel", new ResourceModel("text.search.include.worksite"))); // model is false (include all worksites by default) worksiteCheckBox = new CheckBox("worksiteCheckBox", new Model<Boolean>(false)); worksiteCheckBox.setMarkupId("limittositeinput"); worksiteCheckBox.setOutputMarkupId(true); worksiteCheckBox.setEnabled(hasWorksites); searchForm.add(worksiteCheckBox); final IModel<String> defaultWorksiteIdModel; if (hasWorksites) { defaultWorksiteIdModel = new Model<String>(worksites.get(0).getId()); } else { defaultWorksiteIdModel = new ResourceModel("text.search.no.worksite"); } final LinkedHashMap<String, String> worksiteMap = new LinkedHashMap<String, String>(); if (hasWorksites) { for (Site worksite : worksites) { worksiteMap.put(worksite.getId(), worksite.getTitle()); } } else { worksiteMap.put(defaultWorksiteIdModel.getObject(), defaultWorksiteIdModel.getObject()); } IModel worksitesModel = new Model() { public ArrayList<String> getObject() { return new ArrayList<String>(worksiteMap.keySet()); } }; worksiteChoice = new DropDownChoice("worksiteChoice", defaultWorksiteIdModel, worksitesModel, new HashMapChoiceRenderer(worksiteMap)); worksiteChoice.setMarkupId("worksiteselect"); worksiteChoice.setOutputMarkupId(true); worksiteChoice.setNullValid(false); worksiteChoice.setEnabled(hasWorksites); searchForm.add(worksiteChoice); /* * * RESULTS * */ //search results label/container numSearchResultsContainer = new WebMarkupContainer("numSearchResultsContainer"); numSearchResultsContainer.setOutputMarkupPlaceholderTag(true); numSearchResults = new Label("numSearchResults"); numSearchResults.setOutputMarkupId(true); numSearchResults.setEscapeModelStrings(false); numSearchResultsContainer.add(numSearchResults); //clear results button Form<Void> clearResultsForm = new Form<Void>("clearResults"); clearResultsForm.setOutputMarkupPlaceholderTag(true); clearButton = new AjaxButton("clearButton", clearResultsForm) { private static final long serialVersionUID = 1L; protected void onSubmit(AjaxRequestTarget target, Form<?> form) { // clear cookie if present if (null != searchCookie) { CookieUtils utils = new CookieUtils(); utils.remove(ProfileConstants.SEARCH_COOKIE); } //clear the fields, hide self, then repaint searchField.clearInput(); searchField.updateModel(); numSearchResultsContainer.setVisible(false); resultsContainer.setVisible(false); clearButton.setVisible(false); target.add(searchField); target.add(numSearchResultsContainer); target.add(resultsContainer); target.add(this); } }; clearButton.setOutputMarkupPlaceholderTag(true); if (null == searchCookie) { clearButton.setVisible(false); //invisible until we have something to clear } clearButton.setModel(new ResourceModel("button.search.clear")); clearResultsForm.add(clearButton); numSearchResultsContainer.add(clearResultsForm); add(numSearchResultsContainer); // model to wrap search results LoadableDetachableModel<List<Person>> resultsModel = new LoadableDetachableModel<List<Person>>() { private static final long serialVersionUID = 1L; protected List<Person> load() { return results; } }; //container which wraps list resultsContainer = new WebMarkupContainer("searchResultsContainer"); resultsContainer.setOutputMarkupPlaceholderTag(true); if (null == searchCookie) { resultsContainer.setVisible(false); //hide initially } //connection window final ModalWindow connectionWindow = new ModalWindow("connectionWindow"); //search results final PageableListView<Person> resultsListView = new PageableListView<Person>("searchResults", resultsModel, sakaiProxy.getMaxSearchResultsPerPage()) { private static final long serialVersionUID = 1L; protected void populateItem(final ListItem<Person> item) { Person person = (Person) item.getModelObject(); //get basic values final String userUuid = person.getUuid(); final String displayName = person.getDisplayName(); final String userType = person.getType(); //get connection status int connectionStatus = connectionsLogic.getConnectionStatus(currentUserUuid, userUuid); boolean friend = (connectionStatus == ProfileConstants.CONNECTION_CONFIRMED) ? true : false; //image wrapper, links to profile Link<String> friendItem = new Link<String>("searchResultPhotoWrap") { private static final long serialVersionUID = 1L; public void onClick() { setResponsePage(new ViewProfile(userUuid)); } }; //image ProfileImage searchResultPhoto = new ProfileImage("searchResultPhoto", new Model<String>(userUuid)); searchResultPhoto.setSize(ProfileConstants.PROFILE_IMAGE_THUMBNAIL); friendItem.add(searchResultPhoto); item.add(friendItem); //name and link to profile (if allowed or no link) Link<String> profileLink = new Link<String>("searchResultProfileLink", new Model<String>(userUuid)) { private static final long serialVersionUID = 1L; public void onClick() { //if user found themself, go to own profile, else show other profile if (userUuid.equals(currentUserUuid)) { setResponsePage(new MyProfile()); } else { //gets userUuid of other user from the link's model setResponsePage(new ViewProfile((String) getModelObject())); } } }; profileLink.add(new Label("searchResultName", displayName)); item.add(profileLink); //status component ProfileStatusRenderer status = new ProfileStatusRenderer("searchResultStatus", person, "search-result-status-msg", "search-result-status-date") { @Override public boolean isVisible() { return sakaiProxy.isProfileStatusEnabled(); } }; status.setOutputMarkupId(true); item.add(status); /* ACTIONS */ boolean isFriendsListVisible = privacyLogic.isActionAllowed(userUuid, currentUserUuid, PrivacyType.PRIVACY_OPTION_MYFRIENDS); boolean isConnectionAllowed = sakaiProxy.isConnectionAllowedBetweenUserTypes(userType, currentUserType); //ADD CONNECTION LINK final WebMarkupContainer c1 = new WebMarkupContainer("connectionContainer"); c1.setOutputMarkupId(true); if (!isConnectionAllowed && !sakaiProxy.isConnectionsEnabledGlobally()) { //add blank components - TODO turn this into an EmptyLink component AjaxLink<Void> emptyLink = new AjaxLink<Void>("connectionLink") { private static final long serialVersionUID = 1L; public void onClick(AjaxRequestTarget target) { } }; emptyLink.add(new Label("connectionLabel")); c1.add(emptyLink); c1.setVisible(false); } else { //render the link final Label connectionLabel = new Label("connectionLabel"); connectionLabel.setOutputMarkupId(true); final AjaxLink<String> connectionLink = new AjaxLink<String>("connectionLink", new Model<String>(userUuid)) { private static final long serialVersionUID = 1L; public void onClick(AjaxRequestTarget target) { //get this item, reinit some values and set content for modal final String userUuid = (String) getModelObject(); connectionWindow.setContent(new AddFriend(connectionWindow.getContentId(), connectionWindow, friendActionModel, currentUserUuid, userUuid)); // connection modal window handler connectionWindow.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() { private static final long serialVersionUID = 1L; public void onClose(AjaxRequestTarget target) { if (friendActionModel.isRequested()) { connectionLabel.setDefaultModel(new ResourceModel("text.friend.requested")); add(new AttributeModifier("class", true, new Model<String>("instruction icon connection-request"))); setEnabled(false); target.add(c1); } } }); //in preparation for the window being closed, update the text. this will only //be put into effect if its a successful model update from the window close //connectionLabel.setModel(new ResourceModel("text.friend.requested")); //this.add(new AttributeModifier("class", true, new Model("instruction"))); //this.setEnabled(false); //friendActionModel.setUpdateThisComponentOnSuccess(this); connectionWindow.show(target); target.appendJavaScript("fixWindowVertical();"); } }; connectionLink.add(connectionLabel); //setup 'add connection' link if (StringUtils.equals(userUuid, currentUserUuid)) { connectionLabel.setDefaultModel(new ResourceModel("text.friend.self")); connectionLink.add(new AttributeModifier("class", true, new Model<String>("instruction icon profile"))); connectionLink.setEnabled(false); } else if (friend) { connectionLabel.setDefaultModel(new ResourceModel("text.friend.confirmed")); connectionLink.add(new AttributeModifier("class", true, new Model<String>("instruction icon connection-confirmed"))); connectionLink.setEnabled(false); } else if (connectionStatus == ProfileConstants.CONNECTION_REQUESTED) { connectionLabel.setDefaultModel(new ResourceModel("text.friend.requested")); connectionLink.add(new AttributeModifier("class", true, new Model<String>("instruction icon connection-request"))); connectionLink.setEnabled(false); } else if (connectionStatus == ProfileConstants.CONNECTION_INCOMING) { connectionLabel.setDefaultModel(new ResourceModel("text.friend.pending")); connectionLink.add(new AttributeModifier("class", true, new Model<String>("instruction icon connection-request"))); connectionLink.setEnabled(false); } else { connectionLabel.setDefaultModel(new ResourceModel("link.friend.add")); } connectionLink.setOutputMarkupId(true); c1.add(connectionLink); } item.add(c1); //VIEW FRIENDS LINK WebMarkupContainer c2 = new WebMarkupContainer("viewFriendsContainer"); c2.setOutputMarkupId(true); final AjaxLink<String> viewFriendsLink = new AjaxLink<String>("viewFriendsLink") { private static final long serialVersionUID = 1L; public void onClick(AjaxRequestTarget target) { //if user found themself, go to MyFriends, else, ViewFriends if (userUuid.equals(currentUserUuid)) { setResponsePage(new MyFriends()); } else { setResponsePage(new ViewFriends(userUuid)); } } }; final Label viewFriendsLabel = new Label("viewFriendsLabel", new ResourceModel("link.view.friends")); viewFriendsLink.add(viewFriendsLabel); //hide if not allowed if (!isFriendsListVisible && !sakaiProxy.isConnectionsEnabledGlobally()) { viewFriendsLink.setEnabled(false); c2.setVisible(false); } viewFriendsLink.setOutputMarkupId(true); c2.add(viewFriendsLink); item.add(c2); WebMarkupContainer c3 = new WebMarkupContainer("emailContainer"); c3.setOutputMarkupId(true); ExternalLink emailLink = new ExternalLink("emailLink", "mailto:" + person.getProfile().getEmail(), new ResourceModel("profile.email").getObject()); c3.add(emailLink); if (StringUtils.isBlank(person.getProfile().getEmail()) || false == privacyLogic.isActionAllowed(person.getUuid(), currentUserUuid, PrivacyType.PRIVACY_OPTION_CONTACTINFO)) { c3.setVisible(false); } item.add(c3); WebMarkupContainer c4 = new WebMarkupContainer("websiteContainer"); c4.setOutputMarkupId(true); // TODO home page, university profile URL or academic/research URL (see PRFL-35) ExternalLink websiteLink = new ExternalLink("websiteLink", person.getProfile().getHomepage(), new ResourceModel("profile.homepage").getObject()).setPopupSettings(new PopupSettings()); c4.add(websiteLink); if (StringUtils.isBlank(person.getProfile().getHomepage()) || false == privacyLogic.isActionAllowed(person.getUuid(), currentUserUuid, PrivacyType.PRIVACY_OPTION_CONTACTINFO)) { c4.setVisible(false); } item.add(c4); // TODO personal, academic or business (see PRFL-35) if (true == privacyLogic.isActionAllowed(person.getUuid(), currentUserUuid, PrivacyType.PRIVACY_OPTION_BASICINFO)) { item.add(new Label("searchResultSummary", StringUtils .abbreviate(ProfileUtils.stripHtml(person.getProfile().getPersonalSummary()), 200))); } else { item.add(new Label("searchResultSummary", "")); } } }; resultsListView.add(new MySearchCookieBehavior(resultsListView)); resultsContainer.add(resultsListView); final PagingNavigator searchResultsNavigator = new PagingNavigator("searchResultsNavigator", resultsListView); searchResultsNavigator.setOutputMarkupId(true); searchResultsNavigator.setVisible(false); resultsContainer.add(searchResultsNavigator); add(connectionWindow); //add results container add(resultsContainer); /* * SEARCH HISTORY */ final WebMarkupContainer searchHistoryContainer = new WebMarkupContainer("searchHistoryContainer"); searchHistoryContainer.setOutputMarkupPlaceholderTag(true); Label searchHistoryLabel = new Label("searchHistoryLabel", new ResourceModel("text.search.history")); searchHistoryContainer.add(searchHistoryLabel); IModel<List<ProfileSearchTerm>> searchHistoryModel = new LoadableDetachableModel<List<ProfileSearchTerm>>() { private static final long serialVersionUID = 1L; @Override protected List<ProfileSearchTerm> load() { List<ProfileSearchTerm> searchHistory = searchLogic.getSearchHistory(currentUserUuid); if (null == searchHistory) { return new ArrayList<ProfileSearchTerm>(); } else { return searchHistory; } } }; ListView<ProfileSearchTerm> searchHistoryList = new ListView<ProfileSearchTerm>("searchHistoryList", searchHistoryModel) { private static final long serialVersionUID = 1L; @Override protected void populateItem(final ListItem<ProfileSearchTerm> item) { AjaxLink<String> link = new AjaxLink<String>("previousSearchLink") { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { if (null != target) { // post view event sakaiProxy.postEvent(ProfileConstants.EVENT_SEARCH_BY_NAME, "/profile/" + currentUserUuid, false); ProfileSearchTerm searchTerm = item.getModelObject(); // this will update its position in list searchLogic.addSearchTermToHistory(currentUserUuid, searchTerm); searchStringModel.setString(searchTerm.getSearchTerm()); searchTypeRadioGroup.setModel(new Model<String>(searchTerm.getSearchType())); connectionsCheckBox.setModel(new Model<Boolean>(searchTerm.isConnections())); if (null == searchTerm.getWorksite()) { worksiteCheckBox.setModel(new Model<Boolean>(false)); worksiteChoice.setModel(new Model(defaultWorksiteIdModel)); } else { worksiteCheckBox.setModel(new Model<Boolean>(true)); worksiteChoice.setModel(new Model(searchTerm.getWorksite())); } setSearchCookie(searchTerm.getSearchType(), searchTerm.getSearchTerm(), searchTerm.getSearchPageNumber(), searchTerm.isConnections(), searchTerm.getWorksite()); if (ProfileConstants.SEARCH_TYPE_NAME.equals(searchTerm.getSearchType())) { searchByName(resultsListView, searchResultsNavigator, searchHistoryContainer, target, searchTerm.getSearchTerm(), searchTerm.isConnections(), searchTerm.getWorksite()); } else if (ProfileConstants.SEARCH_TYPE_INTEREST.equals(searchTerm.getSearchType())) { searchByInterest(resultsListView, searchResultsNavigator, searchHistoryContainer, target, searchTerm.getSearchTerm(), searchTerm.isConnections(), searchTerm.getWorksite()); } } } }; link.add(new Label("previousSearchLabel", item.getModelObject().getSearchTerm())); item.add(link); } }; searchHistoryContainer.add(searchHistoryList); add(searchHistoryContainer); if (null == searchLogic.getSearchHistory(currentUserUuid)) { searchHistoryContainer.setVisible(false); } //clear button Form<Void> clearHistoryForm = new Form<Void>("clearHistory"); clearHistoryForm.setOutputMarkupPlaceholderTag(true); clearHistoryButton = new AjaxButton("clearHistoryButton", clearHistoryForm) { private static final long serialVersionUID = 1L; protected void onSubmit(AjaxRequestTarget target, Form<?> form) { searchLogic.clearSearchHistory(currentUserUuid); //clear the fields, hide self, then repaint searchField.clearInput(); searchField.updateModel(); searchHistoryContainer.setVisible(false); clearHistoryButton.setVisible(false); target.add(searchField); target.add(searchHistoryContainer); target.add(this); } }; clearHistoryButton.setOutputMarkupPlaceholderTag(true); if (null == searchLogic.getSearchHistory(currentUserUuid)) { clearHistoryButton.setVisible(false); //invisible until we have something to clear } clearHistoryButton.setModel(new ResourceModel("button.search.history.clear")); clearHistoryForm.add(clearHistoryButton); searchHistoryContainer.add(clearHistoryForm); /* * Combined search submit */ IndicatingAjaxButton searchSubmitButton = new IndicatingAjaxButton("searchSubmit", searchForm) { private static final long serialVersionUID = 1L; protected void onSubmit(AjaxRequestTarget target, Form<?> form) { if (target != null) { //get the model and text entered StringModel model = (StringModel) form.getModelObject(); //PRFL-811 - dont strip this down, we will lose i18n chars. //And there is no XSS risk since its only for the current user. String searchText = model.getString(); //get search type String searchType = searchTypeRadioGroup.getModelObject(); log.debug("MySearch search by " + searchType + ": " + searchText); if (StringUtils.isBlank(searchText)) { return; } // save search terms ProfileSearchTerm searchTerm = new ProfileSearchTerm(); searchTerm.setUserUuid(currentUserUuid); searchTerm.setSearchType(searchType); searchTerm.setSearchTerm(searchText); searchTerm.setSearchPageNumber(0); searchTerm.setSearchDate(new Date()); searchTerm.setConnections(connectionsCheckBox.getModelObject()); // set to worksite or empty depending on value of checkbox searchTerm.setWorksite( (worksiteCheckBox.getModelObject() == true) ? worksiteChoice.getValue() : null); searchLogic.addSearchTermToHistory(currentUserUuid, searchTerm); // set cookie for current search (page 0 when submitting new search) setSearchCookie(searchTerm.getSearchType(), URLEncoder.encode(searchTerm.getSearchTerm()), searchTerm.getSearchPageNumber(), searchTerm.isConnections(), searchTerm.getWorksite()); if (ProfileConstants.SEARCH_TYPE_NAME.equals(searchType)) { searchByName(resultsListView, searchResultsNavigator, searchHistoryContainer, target, searchTerm.getSearchTerm(), searchTerm.isConnections(), searchTerm.getWorksite()); //post view event sakaiProxy.postEvent(ProfileConstants.EVENT_SEARCH_BY_NAME, "/profile/" + currentUserUuid, false); } else if (ProfileConstants.SEARCH_TYPE_INTEREST.equals(searchType)) { searchByInterest(resultsListView, searchResultsNavigator, searchHistoryContainer, target, searchTerm.getSearchTerm(), searchTerm.isConnections(), searchTerm.getWorksite()); //post view event sakaiProxy.postEvent(ProfileConstants.EVENT_SEARCH_BY_INTEREST, "/profile/" + currentUserUuid, false); } } } }; searchSubmitButton.setModel(new ResourceModel("button.search.generic")); searchForm.add(searchSubmitButton); add(searchForm); if (null != searchCookie) { String searchString = getCookieSearchString(searchCookie.getValue()); searchStringModel.setString(searchString); Boolean filterConnections = getCookieFilterConnections(searchCookie.getValue()); String worksiteId = getCookieFilterWorksite(searchCookie.getValue()); Boolean filterWorksite = (null == worksiteId) ? false : true; connectionsCheckBox.setModel(new Model<Boolean>(filterConnections)); worksiteCheckBox.setModel(new Model<Boolean>(filterWorksite)); worksiteChoice.setModel(new Model((null == worksiteId) ? defaultWorksiteIdModel : worksiteId)); if (searchCookie.getValue().startsWith(ProfileConstants.SEARCH_TYPE_NAME)) { searchTypeRadioGroup.setModel(new Model<String>(ProfileConstants.SEARCH_TYPE_NAME)); searchByName(resultsListView, searchResultsNavigator, searchHistoryContainer, null, searchString, filterConnections, worksiteId); } else if (searchCookie.getValue().startsWith(ProfileConstants.SEARCH_TYPE_INTEREST)) { searchTypeRadioGroup.setModel(new Model<String>(ProfileConstants.SEARCH_TYPE_INTEREST)); searchByInterest(resultsListView, searchResultsNavigator, searchHistoryContainer, null, searchString, filterConnections, worksiteId); } } else { // default search type is name searchTypeRadioGroup.setModel(new Model<String>(ProfileConstants.SEARCH_TYPE_NAME)); } }