Example usage for org.apache.wicket.ajax.markup.html.form AjaxFallbackButton setDefaultFormProcessing

List of usage examples for org.apache.wicket.ajax.markup.html.form AjaxFallbackButton setDefaultFormProcessing

Introduction

In this page you can find the example usage for org.apache.wicket.ajax.markup.html.form AjaxFallbackButton setDefaultFormProcessing.

Prototype

@Override
public final Button setDefaultFormProcessing(boolean defaultFormProcessing) 

Source Link

Document

Sets the defaultFormProcessing property.

Usage

From source file:org.sakaiproject.profile2.tool.pages.panels.MyBusinessEdit.java

License:Educational Community License

private AjaxFallbackButton createCancelChangesButton(final String id, final UserProfile userProfile,
        Form form) {/*from ww  w .  j a  va  2 s . c o m*/
    AjaxFallbackButton cancelButton = new AjaxFallbackButton("cancel", new ResourceModel("button.cancel"),
            form) {
        private static final long serialVersionUID = 1L;

        protected void onSubmit(AjaxRequestTarget target, Form form) {

            // undo any changes in progress
            for (CompanyProfile profile : companyProfilesToAdd) {
                userProfile.removeCompanyProfile(profile);
            }

            for (CompanyProfile profile : companyProfilesToRemove) {
                userProfile.addCompanyProfile(profile);
            }

            Component newPanel = new MyBusinessDisplay(id, userProfile);
            newPanel.setOutputMarkupId(true);
            MyBusinessEdit.this.replaceWith(newPanel);
            if (target != null) {
                target.add(newPanel);
                target.appendJavaScript("setMainFrameHeight(window.name);");
            }

        }
    };
    cancelButton.setDefaultFormProcessing(false);
    return cancelButton;
}

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);//  w ww .  ja  va2s  .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.MyInfoEdit.java

License:Educational Community License

public MyInfoEdit(final String id, final UserProfile userProfile) {
    super(id);/*from  w w w. j av a2s  .  c o m*/

    log.debug("MyInfoEdit()");

    //this panel
    final Component thisPanel = this;

    //get userId
    final String userId = userProfile.getUserUuid();

    //updates back to Account for some fields allowed?
    //boolean updateAllowed = sakaiProxy.isAccountUpdateAllowed(userId);

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

    //setup form      
    Form form = new Form("form", new Model(userProfile));
    form.setOutputMarkupId(true);

    //form submit feedback
    final Label formFeedback = new Label("formFeedback");
    formFeedback.setOutputMarkupPlaceholderTag(true);
    form.add(formFeedback);

    //add warning message if superUser and not editing own profile
    Label editWarning = new Label("editWarning");
    editWarning.setVisible(false);
    if (sakaiProxy.isSuperUserAndProxiedToUser(userId)) {
        editWarning.setDefaultModel(new StringResourceModel("text.edit.other.warning", null,
                new Object[] { userProfile.getDisplayName() }));
        editWarning.setEscapeModelStrings(false);
        editWarning.setVisible(true);
    }
    form.add(editWarning);

    //We don't need to get the info from userProfile, we load it into the form with a property model
    //just make sure that the form element id's match those in the model

    //firstName
    /*
    WebMarkupContainer firstNameContainer = new WebMarkupContainer("firstNameContainer");
    firstNameContainer.add(new Label("firstNameLabel", new ResourceModel("profile.name.first")));
    TextField firstName = new TextField("firstName", new PropertyModel(userProfile, "firstName"));
    //readonly view
    Label firstNameReadOnly = new Label("firstNameReadOnly", new PropertyModel(userProfile, "firstName"));
    if(updateAllowed) {
       firstNameReadOnly.setVisible(false);
    } else {
       firstName.setVisible(false);
    }
    firstNameContainer.add(firstName);
    firstNameContainer.add(firstNameReadOnly);
    form.add(firstNameContainer);
    */

    //middleName
    /*
    WebMarkupContainer middleNameContainer = new WebMarkupContainer("middleNameContainer");
    middleNameContainer.add(new Label("middleNameLabel", new ResourceModel("profile.name.middle")));
    TextField middleName = new TextField("middleName", new PropertyModel(userProfile, "middleName"));
    middleNameContainer.add(middleName);
    form.add(middleNameContainer);
    */

    //lastName
    /*
    WebMarkupContainer lastNameContainer = new WebMarkupContainer("lastNameContainer");
    lastNameContainer.add(new Label("lastNameLabel", new ResourceModel("profile.name.last")));
    TextField lastName = new TextField("lastName", new PropertyModel(userProfile, "lastName"));
    //readonly view
    Label lastNameReadOnly = new Label("lastNameReadOnly", new PropertyModel(userProfile, "lastName"));
    if(updateAllowed) {
       lastNameReadOnly.setVisible(false);
    } else {
       lastName.setVisible(false);
    }
    lastNameContainer.add(lastName);
    lastNameContainer.add(lastNameReadOnly);
    form.add(lastNameContainer);
    */

    //nickname
    WebMarkupContainer nicknameContainer = new WebMarkupContainer("nicknameContainer");
    nicknameContainer.add(new Label("nicknameLabel", new ResourceModel("profile.nickname")));
    TextField nickname = new TextField("nickname", new PropertyModel(userProfile, "nickname"));
    nickname.setMarkupId("nicknameinput");
    nickname.setOutputMarkupId(true);
    nicknameContainer.add(nickname);
    form.add(nicknameContainer);

    //birthday
    WebMarkupContainer birthdayContainer = new WebMarkupContainer("birthdayContainer");
    birthdayContainer.add(new Label("birthdayLabel", new ResourceModel("profile.birthday")));
    TextField birthday = new TextField("birthday", new PropertyModel(userProfile, "birthday"));
    birthday.setMarkupId("birthdayinput");
    birthday.setOutputMarkupId(true);
    birthdayContainer.add(birthday);
    //tooltip
    birthdayContainer.add(new IconWithClueTip("birthdayToolTip", ProfileConstants.INFO_IMAGE,
            new ResourceModel("text.profile.birthyear.tooltip")));
    form.add(birthdayContainer);

    //personal summary
    WebMarkupContainer personalSummaryContainer = new WebMarkupContainer("personalSummaryContainer");
    personalSummaryContainer.add(new Label("personalSummaryLabel", new ResourceModel("profile.summary")));
    TextArea personalSummary = new TextArea("personalSummary",
            new PropertyModel(userProfile, "personalSummary"));
    personalSummary.setMarkupId("summaryinput");
    //personalSummary.setEditorConfig(CKEditorConfig.createCkConfig());
    personalSummary.setOutputMarkupId(true);
    personalSummaryContainer.add(personalSummary);
    form.add(personalSummaryContainer);

    //submit button
    AjaxFallbackButton submitButton = new AjaxFallbackButton("submit", form) {
        protected void onSubmit(AjaxRequestTarget target, Form form) {
            //save() form, show message, then load display panel

            if (save(form)) {

                //post update event
                sakaiProxy.postEvent(ProfileConstants.EVENT_PROFILE_INFO_UPDATE, "/profile/" + userId, true);

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

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

            } else {
                //String js = "alert('Failed to save information. Contact your system administrator.');";
                //target.prependJavascript(js);

                formFeedback.setDefaultModel(new ResourceModel("error.profile.save.info.failed"));
                formFeedback.add(new AttributeModifier("class", true, new Model<String>("save-failed-error")));
                target.add(formFeedback);
            }

        }

        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            AjaxCallListener myAjaxCallListener = new AjaxCallListener() {
                @Override
                public CharSequence getBeforeHandler(Component component) {
                    return "doUpdateCK()";
                }
            };
            attributes.getAjaxCallListeners().add(myAjaxCallListener);
        }

    };
    submitButton.setModel(new ResourceModel("button.save.changes"));
    form.add(submitButton);

    //cancel button
    AjaxFallbackButton cancelButton = new AjaxFallbackButton("cancel", new ResourceModel("button.cancel"),
            form) {
        private static final long serialVersionUID = 1L;

        protected void onSubmit(AjaxRequestTarget target, Form form) {
            Component newPanel = new MyInfoDisplay(id, userProfile);
            newPanel.setOutputMarkupId(true);
            thisPanel.replaceWith(newPanel);
            if (target != null) {
                target.add(newPanel);
                //resize iframe
                target.appendJavaScript("setMainFrameHeight(window.name);");
            }

        }

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

    //feedback stuff - make this a class and instance it with diff params
    //WebMarkupContainer formFeedback = new WebMarkupContainer("formFeedback");
    //formFeedback.add(new Label("feedbackMsg", "some message"));
    //formFeedback.add(new AjaxIndicator("feedbackImg"));
    //form.add(formFeedback);

    //add form to page
    add(form);

}

From source file:org.sakaiproject.profile2.tool.pages.panels.MyInterestsEdit.java

License:Educational Community License

public MyInterestsEdit(final String id, final UserProfile userProfile) {
    super(id);//from  ww  w .  j a v  a  2  s  .c  o m

    log.debug("MyInterestsEdit()");

    //this panel
    final Component thisPanel = this;

    //get userId
    final String userId = userProfile.getUserUuid();

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

    //setup form      
    Form form = new Form("form", new Model(userProfile));
    form.setOutputMarkupId(true);

    //form submit feedback
    final Label formFeedback = new Label("formFeedback");
    formFeedback.setOutputMarkupPlaceholderTag(true);
    form.add(formFeedback);

    //add warning message if superUser and not editing own profile
    Label editWarning = new Label("editWarning");
    editWarning.setVisible(false);
    if (sakaiProxy.isSuperUserAndProxiedToUser(userId)) {
        editWarning.setDefaultModel(new StringResourceModel("text.edit.other.warning", null,
                new Object[] { userProfile.getDisplayName() }));
        editWarning.setEscapeModelStrings(false);
        editWarning.setVisible(true);
    }
    form.add(editWarning);

    //We don't need to get the info from userProfile, we load it into the form with a property model
    //just make sure that the form element id's match those in the model

    //favourite books
    WebMarkupContainer booksContainer = new WebMarkupContainer("booksContainer");
    booksContainer.add(new Label("booksLabel", new ResourceModel("profile.favourite.books")));
    TextArea favouriteBooks = new TextArea("favouriteBooks", new PropertyModel(userProfile, "favouriteBooks"));
    favouriteBooks.setMarkupId("favouritebooksinput");
    favouriteBooks.setOutputMarkupId(true);
    booksContainer.add(favouriteBooks);
    form.add(booksContainer);

    //favourite tv shows
    WebMarkupContainer tvContainer = new WebMarkupContainer("tvContainer");
    tvContainer.add(new Label("tvLabel", new ResourceModel("profile.favourite.tv")));
    TextArea favouriteTvShows = new TextArea("favouriteTvShows",
            new PropertyModel(userProfile, "favouriteTvShows"));
    favouriteTvShows.setMarkupId("favouritetvinput");
    favouriteTvShows.setOutputMarkupId(true);
    tvContainer.add(favouriteTvShows);
    form.add(tvContainer);

    //favourite movies
    WebMarkupContainer moviesContainer = new WebMarkupContainer("moviesContainer");
    moviesContainer.add(new Label("moviesLabel", new ResourceModel("profile.favourite.movies")));
    TextArea favouriteMovies = new TextArea("favouriteMovies",
            new PropertyModel(userProfile, "favouriteMovies"));
    favouriteMovies.setMarkupId("favouritemoviesinput");
    favouriteMovies.setOutputMarkupId(true);
    moviesContainer.add(favouriteMovies);
    form.add(moviesContainer);

    //favourite quotes
    WebMarkupContainer quotesContainer = new WebMarkupContainer("quotesContainer");
    quotesContainer.add(new Label("quotesLabel", new ResourceModel("profile.favourite.quotes")));
    TextArea favouriteQuotes = new TextArea("favouriteQuotes",
            new PropertyModel(userProfile, "favouriteQuotes"));
    favouriteQuotes.setMarkupId("favouritequotesinput");
    favouriteQuotes.setOutputMarkupId(true);
    quotesContainer.add(favouriteQuotes);
    form.add(quotesContainer);

    //submit button
    AjaxFallbackButton submitButton = new AjaxFallbackButton("submit", new ResourceModel("button.save.changes"),
            form) {
        private static final long serialVersionUID = 1L;

        protected void onSubmit(AjaxRequestTarget target, Form form) {
            //save() form, show message, then load display panel
            if (save(form)) {

                //post update event
                sakaiProxy.postEvent(ProfileConstants.EVENT_PROFILE_INTERESTS_UPDATE, "/profile/" + userId,
                        true);

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

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

            } else {
                //String js = "alert('Failed to save information. Contact your system administrator.');";
                //target.prependJavascript(js);

                formFeedback.setDefaultModel(new ResourceModel("error.profile.save.interests.failed"));
                formFeedback.add(new AttributeModifier("class", true, new Model<String>("save-failed-error")));
                target.add(formFeedback);
            }
        }

        //@Override
        //protected IAjaxCallDecorator getAjaxCallDecorator() {
        //   return CKEditorTextArea.getAjaxCallDecoratedToUpdateElementForAllEditorsOnPage();
        //}
    };
    form.add(submitButton);

    //cancel button
    AjaxFallbackButton cancelButton = new AjaxFallbackButton("cancel", new ResourceModel("button.cancel"),
            form) {
        private static final long serialVersionUID = 1L;

        protected void onSubmit(AjaxRequestTarget target, Form form) {
            Component newPanel = new MyInterestsDisplay(id, userProfile);
            newPanel.setOutputMarkupId(true);
            thisPanel.replaceWith(newPanel);
            if (target != null) {
                target.add(newPanel);
                //resize iframe
                target.appendJavaScript("setMainFrameHeight(window.name);");
                //need a scrollTo action here, to scroll down the page to the section
            }

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

    //feedback stuff - make this a class and insance it with diff params
    //WebMarkupContainer formFeedback = new WebMarkupContainer("formFeedback");
    //formFeedback.add(new Label("feedbackMsg", "some message"));
    //formFeedback.add(new AjaxIndicator("feedbackImg"));
    //form.add(formFeedback);

    //add form to page
    add(form);

}

From source file:org.sakaiproject.profile2.tool.pages.panels.MySocialNetworkingEdit.java

License:Educational Community License

public MySocialNetworkingEdit(final String id, final UserProfile userProfile) {
    super(id);// w  ww  . j a v a  2  s  .c  om

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

License:Educational Community License

public MyStaffEdit(final String id, final UserProfile userProfile) {
    super(id);/*from ww  w .  ja  v  a2 s  . 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.MyStudentEdit.java

License:Educational Community License

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

    super(id);/*  w ww .  ja v  a  2 s  .  c  om*/

    //heading
    add(new Label("heading", new ResourceModel("heading.student.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);

    //course
    WebMarkupContainer courseContainer = new WebMarkupContainer("courseContainer");
    courseContainer.add(new Label("courseLabel", new ResourceModel("profile.course")));
    TextField course = new TextField("course", new PropertyModel(userProfile, "course"));
    course.setMarkupId("courseinput");
    course.setOutputMarkupId(true);
    courseContainer.add(course);
    form.add(courseContainer);

    //subjects
    WebMarkupContainer subjectsContainer = new WebMarkupContainer("subjectsContainer");
    subjectsContainer.add(new Label("subjectsLabel", new ResourceModel("profile.subjects")));
    TextField subjects = new TextField("subjects", new PropertyModel(userProfile, "subjects"));
    subjects.setMarkupId("subjectsinput");
    subjects.setOutputMarkupId(true);
    subjectsContainer.add(subjects);
    form.add(subjectsContainer);

    //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_STUDENT_UPDATE,
                        "/profile/" + userProfile.getUserUuid(), true);

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

                // repaint panel
                Component newPanel = new MyStudentDisplay(id, userProfile);
                newPanel.setOutputMarkupId(true);
                MyStudentEdit.this.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);
            }
        }
    };
    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 MyStudentDisplay(id, userProfile);
            newPanel.setOutputMarkupId(true);
            MyStudentEdit.this.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.WallItemPostCommentPanel.java

License:Educational Community License

public WallItemPostCommentPanel(String id, final String userUuid, final WallItem wallItem,
        final WallItemPanel wallItemPanel, final MyWallPanel myWallPanel) {

    super(id);// w w w.  java2  s  .  c o m

    String commentString = "";
    IModel<String> commentModel = new Model<String>(commentString);
    Form<String> form = new Form<String>("form", commentModel);
    form.setOutputMarkupId(true);
    add(form);

    // form submit feedback
    final Label formFeedback = new Label("formFeedback");
    formFeedback.setOutputMarkupPlaceholderTag(true);
    form.add(formFeedback);

    WebMarkupContainer commentContainer = new WebMarkupContainer("commentContainer");
    final TextArea<String> commentTextArea = new TextArea<String>("comment", commentModel);

    commentContainer.add(commentTextArea);

    form.add(commentContainer);

    IndicatingAjaxButton submitButton = new IndicatingAjaxButton("submit",
            new ResourceModel("button.wall.comment"), form) {
        private static final long serialVersionUID = 1L;

        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {

            // don't allow empty posts
            if (null == form.getModelObject()) {
                formFeedback.setVisible(true);
                formFeedback.setDefaultModel(new ResourceModel("error.wall.comment.empty"));
                formFeedback.add(new AttributeModifier("class", true, new Model<String>("alertMessage")));
                target.add(formFeedback);
                return;
            }

            // create and add comment to wall item
            WallItemComment wallItemComment = new WallItemComment();
            // always post as current user
            wallItemComment.setCreatorUuid(sakaiProxy.getCurrentUserId());
            wallItemComment.setDate(new Date());
            wallItemComment.setText(form.getModelObject().toString());
            wallItemComment.setWallItem(wallItem);
            wallItem.addComment(wallItemComment);

            // update wall item
            if (false == wallLogic.addNewCommentToWallItem(wallItemComment)) {
                formFeedback.setVisible(true);
                formFeedback.setDefaultModel(new ResourceModel("error.wall.comment.failed"));
                formFeedback.add(new AttributeModifier("class", true, new Model<String>("alertMessage")));
                target.add(formFeedback);
                return;
            }

            // replace wall item panel now comment has been added
            WallItemPanel newPanel = new WallItemPanel(wallItemPanel.getId(), userUuid, wallItem, myWallPanel);
            newPanel.setOutputMarkupId(true);
            wallItemPanel.replaceWith(newPanel);
            if (null != target) {
                target.add(newPanel);
                target.appendJavaScript("setMainFrameHeight(window.name);");
            }
        }
    };
    //submitButton.add(new FocusOnLoadBehaviour());

    AttributeModifier accessibilityLabel = new AttributeModifier("title", true,
            new StringResourceModel("accessibility.wall.comment", null,
                    new Object[] { sakaiProxy.getUserDisplayName(wallItem.getCreatorUuid()) }));

    submitButton.add(accessibilityLabel);
    form.add(submitButton);

    AjaxFallbackButton cancelButton = new AjaxFallbackButton("cancel", new ResourceModel("button.cancel"),
            form) {
        private static final long serialVersionUID = 1L;

        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            commentTextArea.clearInput();
            formFeedback.setVisible(false);
            target.appendJavaScript("$('#" + WallItemPostCommentPanel.this.getMarkupId() + "').slideUp();");
        }
    };

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

From source file:org.sakaiproject.profile2.tool.pages.windows.AddFriend.java

License:Educational Community License

public AddFriend(String id, final ModalWindow window, final FriendAction friendActionModel, final String userX,
        final String userY) {
    super(id);//from   w  w w  .j a v a2  s.c om

    //get friendName
    final String friendName = FormattedText.processFormattedText(sakaiProxy.getUserDisplayName(userY),
            new StringBuffer());

    //window setup
    window.setTitle(new StringResourceModel("title.friend.add", null, new Object[] { friendName }));
    window.setInitialHeight(150);
    window.setInitialWidth(500);
    window.setResizable(false);

    //prefs and privacy
    ProfilePreferences prefs = preferencesLogic.getPreferencesRecordForUser(userY);
    ProfilePrivacy privacy = privacyLogic.getPrivacyRecordForUser(userY);

    //image
    ProfileImage image = new ProfileImage("image", new Model<String>(userY));
    image.setSize(ProfileConstants.PROFILE_IMAGE_THUMBNAIL);
    add(image);

    //text
    final Label text = new Label("text",
            new StringResourceModel("text.friend.add", null, new Object[] { friendName }));
    text.setEscapeModelStrings(false);
    text.setOutputMarkupId(true);
    add(text);

    //setup form      
    Form form = new Form("form");
    form.setOutputMarkupId(true);

    //submit button
    AjaxFallbackButton submitButton = new AjaxFallbackButton("submit", new ResourceModel("button.friend.add"),
            form) {
        private static final long serialVersionUID = 1L;

        protected void onSubmit(AjaxRequestTarget target, Form form) {

            /* double checking */

            //friend?
            if (connectionsLogic.isUserXFriendOfUserY(userX, userY)) {
                text.setDefaultModel(new StringResourceModel("error.friend.already.confirmed", null,
                        new Object[] { friendName }));
                this.setEnabled(false);
                this.add(new AttributeModifier("class", true, new Model("disabled")));
                target.add(text);
                target.add(this);
                return;
            }

            //has a friend request already been made to this person?
            if (connectionsLogic.isFriendRequestPending(userX, userY)) {
                text.setDefaultModel(new StringResourceModel("error.friend.already.pending", null,
                        new Object[] { friendName }));
                this.setEnabled(false);
                this.add(new AttributeModifier("class", true, new Model("disabled")));
                target.add(text);
                target.add(this);
                return;
            }

            //has a friend request been made from this person to the current user?
            if (connectionsLogic.isFriendRequestPending(userY, userX)) {
                text.setDefaultModel(new StringResourceModel("error.friend.already.pending", null,
                        new Object[] { friendName }));
                this.setEnabled(false);
                this.add(new AttributeModifier("class", true, new Model("disabled")));
                target.add(text);
                target.add(this);
                return;
            }

            //if ok, request friend
            if (connectionsLogic.requestFriend(userX, userY)) {
                friendActionModel.setRequested(true);

                //post event
                sakaiProxy.postEvent(ProfileConstants.EVENT_FRIEND_REQUEST, "/profile/" + userY, true);

                window.close(target);
            } else {
                text.setDefaultModel(
                        new StringResourceModel("error.friend.add.failed", null, new Object[] { friendName }));
                this.setEnabled(false);
                this.add(new AttributeModifier("class", true, new Model("disabled")));
                target.add(text);
                target.add(this);
                return;
            }

        }
    };
    //submitButton.add(new FocusOnLoadBehaviour());
    submitButton.add(new AttributeModifier("title", true,
            new StringResourceModel("accessibility.connection.add", null, new Object[] { friendName })));
    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) {
            friendActionModel.setRequested(false);
            window.close(target);
        }
    };
    cancelButton.setDefaultFormProcessing(false);
    form.add(cancelButton);

    //add form
    add(form);
}

From source file:org.sakaiproject.profile2.tool.pages.windows.ConfirmFriend.java

License:Educational Community License

public ConfirmFriend(String id, final ModalWindow window, final FriendAction friendActionModel,
        final String userX, final String userY) {
    super(id);//www .j a v a  2s. com

    //get friendName
    final String friendName = FormattedText.processFormattedText(sakaiProxy.getUserDisplayName(userY),
            new StringBuffer());

    //window setup
    window.setTitle(new StringResourceModel("title.friend.confirm", null, new Object[] { friendName }));
    window.setInitialHeight(150);
    window.setInitialWidth(500);
    window.setResizable(false);

    //prefs and privacy
    ProfilePreferences prefs = preferencesLogic.getPreferencesRecordForUser(userY);
    ProfilePrivacy privacy = privacyLogic.getPrivacyRecordForUser(userY);

    //image
    ProfileImage image = new ProfileImage("image", new Model<String>(userY));
    image.setSize(ProfileConstants.PROFILE_IMAGE_THUMBNAIL);
    add(image);

    //text
    final Label text = new Label("text",
            new StringResourceModel("text.friend.confirm", null, new Object[] { friendName }));
    text.setEscapeModelStrings(false);
    text.setOutputMarkupId(true);
    add(text);

    //setup form      
    Form form = new Form("form");
    form.setOutputMarkupId(true);

    //submit button
    AjaxFallbackButton submitButton = new AjaxFallbackButton("submit",
            new ResourceModel("button.friend.confirm"), form) {
        private static final long serialVersionUID = 1L;

        protected void onSubmit(AjaxRequestTarget target, Form form) {

            /* double checking */

            //must exist a pending friend request FROM userY to userX in order to confirm it
            boolean friendRequestFromThisPerson = connectionsLogic.isFriendRequestPending(userY, userX);

            if (!friendRequestFromThisPerson) {
                text.setDefaultModel(new StringResourceModel("error.friend.not.pending.confirm", null,
                        new Object[] { friendName }));
                this.setEnabled(false);
                this.add(new AttributeModifier("class", true, new Model("disabled")));
                target.add(text);
                target.add(this);
                return;
            }

            //if ok, request friend
            if (connectionsLogic.confirmFriendRequest(userY, userX)) {
                friendActionModel.setConfirmed(true);

                //post event
                sakaiProxy.postEvent(ProfileConstants.EVENT_FRIEND_CONFIRM, "/profile/" + userY, true);

                window.close(target);
            } else {
                text.setDefaultModel(new StringResourceModel("error.friend.confirm.failed", null,
                        new Object[] { friendName }));
                this.setEnabled(false);
                this.add(new AttributeModifier("class", true, new Model("disabled")));
                target.add(text);
                target.add(this);
                return;
            }

        }
    };
    //submitButton.add(new FocusOnLoadBehaviour());
    submitButton.add(new AttributeModifier("title", true,
            new StringResourceModel("accessibility.connection.confirm", null, new Object[] { friendName })));
    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) {
            friendActionModel.setConfirmed(false);
            window.close(target);
        }
    };
    cancelButton.setDefaultFormProcessing(false);
    form.add(cancelButton);

    //add form
    add(form);

}