Example usage for org.apache.wicket Component setOutputMarkupId

List of usage examples for org.apache.wicket Component setOutputMarkupId

Introduction

In this page you can find the example usage for org.apache.wicket Component setOutputMarkupId.

Prototype

public final Component setOutputMarkupId(final boolean output) 

Source Link

Document

Sets whether or not component will output id attribute into the markup.

Usage

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);/*  ww w .  j av  a2s .c om*/

    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   w ww.  j  ava2 s  . 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);//from  www  .  ja va 2  s  .c  om

    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);//from www  .ja  va  2s  .co  m

    //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);/* w  ww .  j  a v a2s . com*/

    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.MySocialNetworkingDisplay.java

License:Educational Community License

public MySocialNetworkingDisplay(final String id, final UserProfile userProfile) {
    super(id);//  w  w  w .j a v a2s . c o  m

    log.debug("MySocialNetworkingDisplay()");

    add(new Label("heading", new ResourceModel("heading.social")));

    // social networking
    String facebookUrl = userProfile.getSocialInfo().getFacebookUrl();
    String linkedinUrl = userProfile.getSocialInfo().getLinkedinUrl();
    String myspaceUrl = userProfile.getSocialInfo().getMyspaceUrl();
    String skypeUsername = userProfile.getSocialInfo().getSkypeUsername();
    String twitterUrl = userProfile.getSocialInfo().getTwitterUrl();

    int visibleFieldCount = 0;

    //facebook
    WebMarkupContainer facebookContainer = new WebMarkupContainer("facebookContainer");
    facebookContainer.add(new Label("facebookLabel", new ResourceModel("profile.socialnetworking.facebook")));
    facebookContainer.add(new ExternalLink("facebookLink", facebookUrl, facebookUrl));
    add(facebookContainer);
    if (StringUtils.isBlank(facebookUrl)) {
        facebookContainer.setVisible(false);
    } else {
        visibleFieldCount++;
    }

    //linkedin
    WebMarkupContainer linkedinContainer = new WebMarkupContainer("linkedinContainer");
    linkedinContainer.add(new Label("linkedinLabel", new ResourceModel("profile.socialnetworking.linkedin")));
    linkedinContainer.add(new ExternalLink("linkedinLink", linkedinUrl, linkedinUrl));
    add(linkedinContainer);
    if (StringUtils.isBlank(linkedinUrl)) {
        linkedinContainer.setVisible(false);
    } else {
        visibleFieldCount++;
    }

    //myspace
    WebMarkupContainer myspaceContainer = new WebMarkupContainer("myspaceContainer");
    myspaceContainer.add(new Label("myspaceLabel", new ResourceModel("profile.socialnetworking.myspace")));
    myspaceContainer.add(new ExternalLink("myspaceLink", myspaceUrl, myspaceUrl));
    add(myspaceContainer);
    if (StringUtils.isBlank(myspaceUrl)) {
        myspaceContainer.setVisible(false);
    } else {
        visibleFieldCount++;
    }

    //twitter
    WebMarkupContainer twitterContainer = new WebMarkupContainer("twitterContainer");
    twitterContainer.add(new Label("twitterLabel", new ResourceModel("profile.socialnetworking.twitter")));
    twitterContainer.add(new ExternalLink("twitterLink", twitterUrl, twitterUrl));
    add(twitterContainer);
    if (StringUtils.isBlank(twitterUrl)) {
        twitterContainer.setVisible(false);
    } else {
        visibleFieldCount++;
    }

    //skypeme (no URL, as we don't want user skyping themselves)
    WebMarkupContainer skypeContainer = new WebMarkupContainer("skypeContainer");
    skypeContainer.add(new Label("skypeLabel", new ResourceModel("profile.socialnetworking.skype")));
    skypeContainer.add(new Label("skypeLink", skypeUsername));
    add(skypeContainer);
    if (StringUtils.isBlank(skypeUsername)) {
        skypeContainer.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 MySocialNetworkingEdit(id, userProfile);
            newPanel.setOutputMarkupId(true);
            MySocialNetworkingDisplay.this.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.MySocialNetworkingEdit.java

License:Educational Community License

public MySocialNetworkingEdit(final String id, final UserProfile userProfile) {
    super(id);// w w  w . j  av a 2 s.  co m

    log.debug("MySocialNetworkingEdit()");

    // heading
    add(new Label("heading", new ResourceModel("heading.social.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(userProfile.getUserUuid())) {
        editWarning.setDefaultModel(new StringResourceModel("text.edit.other.warning", null,
                new Object[] { userProfile.getDisplayName() }));
        editWarning.setEscapeModelStrings(false);
        editWarning.setVisible(true);
    }
    form.add(editWarning);

    //facebook
    WebMarkupContainer facebookContainer = new WebMarkupContainer("facebookContainer");
    facebookContainer
            .add(new Label("facebookLabel", new ResourceModel("profile.socialnetworking.facebook.edit")));
    final TextField<String> facebookUrl = new TextField<String>("facebookUrl",
            new PropertyModel<String>(userProfile, "socialInfo.facebookUrl")) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void convertInput() {
            validateUrl(this);
        }
    };
    facebookUrl.setMarkupId("facebookurlinput");
    facebookUrl.setOutputMarkupId(true);
    facebookUrl.add(new UrlValidator());
    facebookContainer.add(facebookUrl);
    facebookContainer.add(new IconWithClueTip("facebookToolTip", ProfileConstants.INFO_IMAGE,
            new ResourceModel("text.profile.facebook.tooltip")));

    //feedback
    final FeedbackLabel facebookUrlFeedback = new FeedbackLabel("facebookUrlFeedback", facebookUrl);
    facebookUrlFeedback.setOutputMarkupId(true);
    facebookUrlFeedback.setMarkupId("facebookUrlFeedback");
    facebookContainer.add(facebookUrlFeedback);
    facebookUrl.add(new ComponentVisualErrorBehaviour("onblur", facebookUrlFeedback));

    form.add(facebookContainer);

    //linkedin
    WebMarkupContainer linkedinContainer = new WebMarkupContainer("linkedinContainer");
    linkedinContainer
            .add(new Label("linkedinLabel", new ResourceModel("profile.socialnetworking.linkedin.edit")));
    final TextField<String> linkedinUrl = new TextField<String>("linkedinUrl",
            new PropertyModel<String>(userProfile, "socialInfo.linkedinUrl")) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void convertInput() {
            validateUrl(this);
        }
    };
    linkedinUrl.setMarkupId("linkedinurlinput");
    linkedinUrl.setOutputMarkupId(true);
    linkedinUrl.add(new UrlValidator());
    linkedinContainer.add(linkedinUrl);
    linkedinContainer.add(new IconWithClueTip("linkedinToolTip", ProfileConstants.INFO_IMAGE,
            new ResourceModel("text.profile.linkedin.tooltip")));

    //feedback
    final FeedbackLabel linkedinUrlFeedback = new FeedbackLabel("linkedinUrlFeedback", linkedinUrl);
    linkedinUrlFeedback.setMarkupId("linkedinUrlFeedback");
    linkedinUrlFeedback.setOutputMarkupId(true);
    linkedinContainer.add(linkedinUrlFeedback);
    linkedinUrl.add(new ComponentVisualErrorBehaviour("onblur", linkedinUrlFeedback));

    form.add(linkedinContainer);

    //myspace
    WebMarkupContainer myspaceContainer = new WebMarkupContainer("myspaceContainer");
    myspaceContainer.add(new Label("myspaceLabel", new ResourceModel("profile.socialnetworking.myspace.edit")));
    final TextField<String> myspaceUrl = new TextField<String>("myspaceUrl",
            new PropertyModel<String>(userProfile, "socialInfo.myspaceUrl")) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void convertInput() {
            validateUrl(this);
        }
    };
    myspaceUrl.setMarkupId("myspaceurlinput");
    myspaceUrl.setOutputMarkupId(true);
    myspaceUrl.add(new UrlValidator());
    myspaceContainer.add(myspaceUrl);
    myspaceContainer.add(new IconWithClueTip("myspaceToolTip", ProfileConstants.INFO_IMAGE,
            new ResourceModel("text.profile.myspace.tooltip")));

    //feedback
    final FeedbackLabel myspaceUrlFeedback = new FeedbackLabel("myspaceUrlFeedback", myspaceUrl);
    myspaceUrlFeedback.setMarkupId("myspaceUrlFeedback");
    myspaceUrlFeedback.setOutputMarkupId(true);
    myspaceContainer.add(myspaceUrlFeedback);
    myspaceUrl.add(new ComponentVisualErrorBehaviour("onblur", myspaceUrlFeedback));

    form.add(myspaceContainer);

    //twitter
    WebMarkupContainer twitterContainer = new WebMarkupContainer("twitterContainer");
    twitterContainer.add(new Label("twitterLabel", new ResourceModel("profile.socialnetworking.twitter.edit")));
    final TextField<String> twitterUrl = new TextField<String>("twitterUrl",
            new PropertyModel<String>(userProfile, "socialInfo.twitterUrl")) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void convertInput() {
            validateUrl(this);
        }
    };
    twitterUrl.setMarkupId("twitterurlinput");
    twitterUrl.setOutputMarkupId(true);
    twitterUrl.add(new UrlValidator());
    twitterContainer.add(twitterUrl);
    twitterContainer.add(new IconWithClueTip("twitterToolTip", ProfileConstants.INFO_IMAGE,
            new ResourceModel("text.profile.twitter.tooltip")));

    //feedback
    final FeedbackLabel twitterUrlFeedback = new FeedbackLabel("twitterUrlFeedback", twitterUrl);
    twitterUrlFeedback.setMarkupId("twitterUrlFeedback");
    twitterUrlFeedback.setOutputMarkupId(true);
    twitterContainer.add(twitterUrlFeedback);
    twitterUrl.add(new ComponentVisualErrorBehaviour("onblur", twitterUrlFeedback));

    form.add(twitterContainer);

    //skype
    WebMarkupContainer skypeContainer = new WebMarkupContainer("skypeContainer");
    skypeContainer.add(new Label("skypeLabel", new ResourceModel("profile.socialnetworking.skype.edit")));
    TextField skypeUsername = new TextField("skypeUsername",
            new PropertyModel(userProfile, "socialInfo.skypeUsername"));
    skypeUsername.setMarkupId("skypeusernameinput");
    skypeUsername.setOutputMarkupId(true);
    skypeContainer.add(skypeUsername);
    form.add(skypeContainer);

    //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) {

            if (save(form)) {

                // post update event
                sakaiProxy.postEvent(ProfileConstants.EVENT_PROFILE_SOCIAL_NETWORKING_UPDATE,
                        "/profile/" + userProfile.getUserUuid(), true);

                //post to wall if enabled
                if (true == sakaiProxy.isWallEnabledGlobally()
                        && false == sakaiProxy.isSuperUserAndProxiedToUser(userProfile.getUserUuid())) {
                    wallLogic.addNewEventToWall(ProfileConstants.EVENT_PROFILE_SOCIAL_NETWORKING_UPDATE,
                            sakaiProxy.getCurrentUserId());
                }

                // repaint panel
                Component newPanel = new MySocialNetworkingDisplay(id, userProfile);
                newPanel.setOutputMarkupId(true);
                MySocialNetworkingEdit.this.replaceWith(newPanel);
                if (target != null) {
                    target.add(newPanel);
                    // resize iframe
                    target.appendJavaScript("setMainFrameHeight(window.name);");
                }

            } else {
                formFeedback.setDefaultModel(new ResourceModel("error.profile.save.business.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 (!facebookUrl.isValid()) {
                facebookUrl.add(new AttributeAppender("class", new Model<String>("invalid"), " "));
                target.add(facebookUrl);
                target.add(facebookUrlFeedback);
            }
            if (!linkedinUrl.isValid()) {
                linkedinUrl.add(new AttributeAppender("class", new Model<String>("invalid"), " "));
                target.add(linkedinUrl);
                target.add(linkedinUrlFeedback);
            }
            if (!myspaceUrl.isValid()) {
                myspaceUrl.add(new AttributeAppender("class", new Model<String>("invalid"), " "));
                target.add(myspaceUrl);
                target.add(myspaceUrlFeedback);
            }
            if (!twitterUrl.isValid()) {
                twitterUrl.add(new AttributeAppender("class", new Model<String>("invalid"), " "));
                target.add(twitterUrl);
                target.add(twitterUrlFeedback);
            }
        }

    };
    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 MySocialNetworkingDisplay(id, userProfile);
            newPanel.setOutputMarkupId(true);
            MySocialNetworkingEdit.this.replaceWith(newPanel);
            if (target != null) {
                target.add(newPanel);
                target.appendJavaScript("setMainFrameHeight(window.name);");
            }

        }

    };
    cancelButton.setDefaultFormProcessing(false);
    form.add(cancelButton);

    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 av  a  2s  .  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 w  w.ja  va2s . c  o  m

    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:org.sakaiproject.profile2.tool.pages.panels.MyStudentDisplay.java

License:Educational Community License

public MyStudentDisplay(final String id, final UserProfile userProfile) {

    super(id);//from  ww w .  j  a  v  a  2s  .  c o  m

    //heading
    add(new Label("heading", new ResourceModel("heading.student")));

    String course = userProfile.getCourse();
    String subjects = userProfile.getSubjects();

    int visibleFieldCount = 0;

    //course
    WebMarkupContainer courseContainer = new WebMarkupContainer("courseContainer");
    courseContainer.add(new Label("courseLabel", new ResourceModel("profile.course")));
    courseContainer.add(new Label("course", course));
    add(courseContainer);
    if (StringUtils.isBlank(course)) {
        courseContainer.setVisible(false);
    } else {
        visibleFieldCount++;
    }

    //subjects
    WebMarkupContainer subjectsContainer = new WebMarkupContainer("subjectsContainer");
    subjectsContainer.add(new Label("subjectsLabel", new ResourceModel("profile.subjects")));
    subjectsContainer.add(new Label("subjects", subjects));
    add(subjectsContainer);
    if (StringUtils.isBlank(subjects)) {
        subjectsContainer.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 MyStudentEdit(id, userProfile);
            newPanel.setOutputMarkupId(true);
            MyStudentDisplay.this.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);
    }
}