Search in sources :

Example 56 with Form

use of org.apache.wicket.markup.html.form.Form in project gitblit by gitblit.

the class NewRepositoryPage method onInitialize.

@Override
protected void onInitialize() {
    super.onInitialize();
    CompoundPropertyModel<RepositoryModel> rModel = new CompoundPropertyModel<>(repositoryModel);
    Form<RepositoryModel> form = new Form<RepositoryModel>("editForm", rModel) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit() {
            try {
                if (!namePanel.updateModel(repositoryModel)) {
                    return;
                }
                accessPolicyPanel.updateModel(repositoryModel);
                repositoryModel.owners = new ArrayList<String>();
                repositoryModel.owners.add(GitBlitWebSession.get().getUsername());
                // setup branch defaults
                boolean useGitFlow = addGitflowModel.getObject();
                repositoryModel.HEAD = Constants.R_MASTER;
                repositoryModel.mergeTo = Constants.MASTER;
                if (useGitFlow) {
                    // tickets normally merge to develop unless they are hotfixes
                    repositoryModel.mergeTo = Constants.DEVELOP;
                }
                repositoryModel.allowForks = app().settings().getBoolean(Keys.web.allowForking, true);
                // optionally generate an initial commit
                boolean addReadme = addReadmeModel.getObject();
                String gitignore = null;
                boolean addGitignore = addGitignoreModel.getObject();
                if (addGitignore) {
                    gitignore = gitignoreModel.getObject();
                    if (StringUtils.isEmpty(gitignore)) {
                        throw new GitBlitException(getString("gb.pleaseSelectGitIgnore"));
                    }
                }
                // init the repository
                app().gitblit().updateRepositoryModel(repositoryModel.name, repositoryModel, true);
                // optionally create an initial commit
                initialCommit(repositoryModel, addReadme, gitignore, useGitFlow);
            } catch (GitBlitException e) {
                error(e.getMessage());
                return;
            }
            setRedirect(true);
            setResponsePage(SummaryPage.class, WicketUtils.newRepositoryParameter(repositoryModel.name));
        }
    };
    // do not let the browser pre-populate these fields
    form.add(new SimpleAttributeModifier("autocomplete", "off"));
    namePanel = new RepositoryNamePanel("namePanel", repositoryModel);
    form.add(namePanel);
    // prepare the default access controls
    AccessRestrictionType defaultRestriction = AccessRestrictionType.fromName(app().settings().getString(Keys.git.defaultAccessRestriction, AccessRestrictionType.PUSH.name()));
    if (AccessRestrictionType.NONE == defaultRestriction) {
        defaultRestriction = AccessRestrictionType.PUSH;
    }
    AuthorizationControl defaultControl = AuthorizationControl.fromName(app().settings().getString(Keys.git.defaultAuthorizationControl, AuthorizationControl.NAMED.name()));
    if (AuthorizationControl.AUTHENTICATED == defaultControl) {
        defaultRestriction = AccessRestrictionType.PUSH;
    }
    repositoryModel.authorizationControl = defaultControl;
    repositoryModel.accessRestriction = defaultRestriction;
    accessPolicyPanel = new AccessPolicyPanel("accessPolicyPanel", repositoryModel);
    form.add(accessPolicyPanel);
    //
    // initial commit options
    //
    // add README
    addReadmeModel = Model.of(false);
    form.add(new BooleanOption("addReadme", getString("gb.initWithReadme"), getString("gb.initWithReadmeDescription"), addReadmeModel));
    // add .gitignore
    File gitignoreDir = app().runtime().getFileOrFolder(Keys.git.gitignoreFolder, "${baseFolder}/gitignore");
    File[] files = gitignoreDir.listFiles();
    if (files == null) {
        files = new File[0];
    }
    List<String> gitignores = new ArrayList<String>();
    for (File file : files) {
        if (file.isFile() && file.getName().endsWith(".gitignore")) {
            gitignores.add(StringUtils.stripFileExtension(file.getName()));
        }
    }
    Collections.sort(gitignores);
    gitignoreModel = Model.of("");
    addGitignoreModel = Model.of(false);
    form.add(new BooleanChoiceOption<String>("addGitIgnore", getString("gb.initWithGitignore"), getString("gb.initWithGitignoreDescription"), addGitignoreModel, gitignoreModel, gitignores).setVisible(gitignores.size() > 0));
    // TODO consider gitflow at creation (ticket-55)
    addGitflowModel = Model.of(false);
    form.add(new BooleanOption("addGitFlow", "Include a .gitflow file", "This will generate a config file which guides Git clients in setting up Gitflow branches.", addGitflowModel).setVisible(false));
    form.add(new Button("create"));
    add(form);
}
Also used : RepositoryNamePanel(com.gitblit.wicket.panels.RepositoryNamePanel) CompoundPropertyModel(org.apache.wicket.model.CompoundPropertyModel) Form(org.apache.wicket.markup.html.form.Form) ArrayList(java.util.ArrayList) GitBlitException(com.gitblit.GitBlitException) SimpleAttributeModifier(org.apache.wicket.behavior.SimpleAttributeModifier) RepositoryModel(com.gitblit.models.RepositoryModel) BooleanChoiceOption(com.gitblit.wicket.panels.BooleanChoiceOption) Button(org.apache.wicket.markup.html.form.Button) AccessRestrictionType(com.gitblit.Constants.AccessRestrictionType) AuthorizationControl(com.gitblit.Constants.AuthorizationControl) File(java.io.File) AccessPolicyPanel(com.gitblit.wicket.panels.AccessPolicyPanel) BooleanOption(com.gitblit.wicket.panels.BooleanOption)

Example 57 with Form

use of org.apache.wicket.markup.html.form.Form in project gitblit by gitblit.

the class CommentPanel method onInitialize.

@Override
protected void onInitialize() {
    super.onInitialize();
    Form<String> form = new Form<String>("editorForm");
    add(form);
    form.add(new AjaxButton("submit", new Model<String>(getString("gb.comment")), form) {

        private static final long serialVersionUID = 1L;

        @Override
        public void onSubmit(AjaxRequestTarget target, Form<?> form) {
            String txt = markdownEditor.getText();
            if (change == null) {
                // new comment
                Change newComment = new Change(user.username);
                newComment.comment(txt);
                if (!ticket.isWatching(user.username)) {
                    newComment.watch(user.username);
                }
                RepositoryModel repository = app().repositories().getRepositoryModel(ticket.repository);
                TicketModel updatedTicket = app().tickets().updateTicket(repository, ticket.number, newComment);
                if (updatedTicket != null) {
                    app().tickets().createNotifier().sendMailing(updatedTicket);
                    redirectTo(pageClass, WicketUtils.newObjectParameter(updatedTicket.repository, "" + ticket.number));
                } else {
                    error("Failed to add comment!");
                }
            } else {
            // TODO update comment
            }
        }

        /**
             * Steal from BasePage to realize redirection.
             * 
             * @see BasePage
             * @author krulls@GitHub; ECG Leipzig GmbH, Germany, 2015
             * 
             * @param pageClass
             * @param parameters
             * @return
             */
        private void redirectTo(Class<? extends BasePage> pageClass, PageParameters parameters) {
            String relativeUrl = urlFor(pageClass, parameters).toString();
            String canonicalUrl = RequestUtils.toAbsolutePath(relativeUrl);
            getRequestCycle().setRequestTarget(new RedirectRequestTarget(canonicalUrl));
        }
    }.setVisible(ticket != null && ticket.number > 0));
    final IModel<String> markdownPreviewModel = Model.of();
    markdownPreview = new Label("markdownPreview", markdownPreviewModel);
    markdownPreview.setEscapeModelStrings(false);
    markdownPreview.setOutputMarkupId(true);
    add(markdownPreview);
    markdownEditor = new MarkdownTextArea("markdownEditor", markdownPreviewModel, markdownPreview);
    markdownEditor.setRepository(repositoryName);
    WicketUtils.setInputPlaceholder(markdownEditor, getString("gb.leaveComment"));
    add(markdownEditor);
}
Also used : Form(org.apache.wicket.markup.html.form.Form) Label(org.apache.wicket.markup.html.basic.Label) TicketModel(com.gitblit.models.TicketModel) Change(com.gitblit.models.TicketModel.Change) RepositoryModel(com.gitblit.models.RepositoryModel) PageParameters(org.apache.wicket.PageParameters) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxButton(org.apache.wicket.ajax.markup.html.form.AjaxButton) RedirectRequestTarget(org.apache.wicket.request.target.basic.RedirectRequestTarget) BasePage(com.gitblit.wicket.pages.BasePage)

Example 58 with Form

use of org.apache.wicket.markup.html.form.Form in project midpoint by Evolveum.

the class ExpressionEditorPanel method initLayout.

protected void initLayout(PageResourceWizard parentPage) {
    parentPage.addEditingEnabledBehavior(this);
    setOutputMarkupId(true);
    loadDtoModel();
    Label descriptionLabel = new Label(ID_LABEL_DESCRIPTION, createStringResource(getDescriptionLabelKey()));
    add(descriptionLabel);
    TextArea description = new TextArea<>(ID_DESCRIPTION, new PropertyModel<String>(dtoModel, ExpressionTypeDto.F_DESCRIPTION));
    description.setOutputMarkupId(true);
    //parentPage.addEditingEnabledBehavior(description);
    add(description);
    Label typeLabel = new Label(ID_LABEL_TYPE, createStringResource(getTypeLabelKey()));
    add(typeLabel);
    DropDownChoice type = new DropDownChoice<>(ID_TYPE, new PropertyModel<ExpressionUtil.ExpressionEvaluatorType>(dtoModel, ExpressionTypeDto.F_TYPE), WebComponentUtil.createReadonlyModelFromEnum(ExpressionUtil.ExpressionEvaluatorType.class), new EnumChoiceRenderer<ExpressionUtil.ExpressionEvaluatorType>(this));
    //parentPage.addEditingEnabledBehavior(type);
    type.add(new AjaxFormComponentUpdatingBehavior("change") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            dtoModel.getObject().updateExpressionType();
            //target.add(get(ID_LANGUAGE_CONTAINER), get(ID_POLICY_CONTAINER), get(ID_EXPRESSION));
            // because of ACE editor
            target.add(ExpressionEditorPanel.this);
        }
    });
    type.setOutputMarkupId(true);
    type.setOutputMarkupPlaceholderTag(true);
    type.setNullValid(true);
    add(type);
    WebMarkupContainer languageContainer = new WebMarkupContainer(ID_LANGUAGE_CONTAINER);
    languageContainer.setOutputMarkupId(true);
    languageContainer.setOutputMarkupPlaceholderTag(true);
    languageContainer.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return ExpressionUtil.ExpressionEvaluatorType.SCRIPT.equals(dtoModel.getObject().getType());
        }
    });
    //parentPage.addEditingEnabledBehavior(languageContainer);
    add(languageContainer);
    DropDownChoice language = new DropDownChoice<>(ID_LANGUAGE, new PropertyModel<ExpressionUtil.Language>(dtoModel, ExpressionTypeDto.F_LANGUAGE), WebComponentUtil.createReadonlyModelFromEnum(ExpressionUtil.Language.class), new EnumChoiceRenderer<ExpressionUtil.Language>(this));
    //parentPage.addEditingEnabledBehavior(language);
    language.add(new AjaxFormComponentUpdatingBehavior("change") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            dtoModel.getObject().updateExpressionLanguage();
            //target.add(get(ID_LANGUAGE_CONTAINER), get(ID_POLICY_CONTAINER), get(ID_EXPRESSION));
            // because of ACE editor
            target.add(ExpressionEditorPanel.this);
        }
    });
    language.setNullValid(false);
    languageContainer.add(language);
    WebMarkupContainer policyContainer = new WebMarkupContainer(ID_POLICY_CONTAINER);
    policyContainer.setOutputMarkupId(true);
    policyContainer.setOutputMarkupPlaceholderTag(true);
    policyContainer.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return ExpressionUtil.ExpressionEvaluatorType.GENERATE.equals(dtoModel.getObject().getType());
        }
    });
    add(policyContainer);
    DropDownChoice policyRef = new DropDownChoice<>(ID_POLICY_REF, new PropertyModel<ObjectReferenceType>(dtoModel, ExpressionTypeDto.F_POLICY_REF), new AbstractReadOnlyModel<List<ObjectReferenceType>>() {

        @Override
        public List<ObjectReferenceType> getObject() {
            return WebModelServiceUtils.createObjectReferenceList(ValuePolicyType.class, getPageBase(), policyMap);
        }
    }, new ObjectReferenceChoiceRenderer(policyMap));
    //parentPage.addEditingEnabledBehavior(policyRef);
    policyRef.add(new AjaxFormComponentUpdatingBehavior("change") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            dtoModel.getObject().updateExpressionValuePolicyRef();
            target.add(get(ID_LANGUAGE_CONTAINER), get(ID_POLICY_CONTAINER), get(ID_EXPRESSION));
        }
    });
    policyRef.setNullValid(true);
    policyContainer.add(policyRef);
    Label expressionLabel = new Label(ID_LABEL_EXPRESSION, createStringResource(getExpressionLabelKey()));
    add(expressionLabel);
    AceEditor expression = new AceEditor(ID_EXPRESSION, new PropertyModel<String>(dtoModel, ExpressionTypeDto.F_EXPRESSION));
    expression.setOutputMarkupId(true);
    //parentPage.addEditingEnabledBehavior(expression);
    add(expression);
    AjaxSubmitLink update = new AjaxSubmitLink(ID_BUTTON_UPDATE) {

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            updateExpressionPerformed(target);
        }
    };
    Label updateLabel = new Label(ID_LABEL_UPDATE, createStringResource(getUpdateLabelKey()));
    updateLabel.setRenderBodyOnly(true);
    update.add(updateLabel);
    parentPage.addEditingVisibleBehavior(update);
    add(update);
    add(WebComponentUtil.createHelp(ID_T_TYPE));
    languageContainer.add(WebComponentUtil.createHelp(ID_T_LANGUAGE));
    policyContainer.add(WebComponentUtil.createHelp(ID_T_POLICY));
    add(WebComponentUtil.createHelp(ID_T_EXPRESSION));
}
Also used : ValuePolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType) TextArea(org.apache.wicket.markup.html.form.TextArea) Form(org.apache.wicket.markup.html.form.Form) Label(org.apache.wicket.markup.html.basic.Label) AceEditor(com.evolveum.midpoint.web.component.AceEditor) AjaxSubmitLink(org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) List(java.util.List) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) AjaxFormComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) DropDownChoice(org.apache.wicket.markup.html.form.DropDownChoice)

Example 59 with Form

use of org.apache.wicket.markup.html.form.Form in project midpoint by Evolveum.

the class SearchFilterPanel method initLayout.

protected void initLayout(NonEmptyModel<Boolean> readOnlyModel) {
    TextArea<String> description = new TextArea<>(ID_DESCRIPTION, new PropertyModel<String>(getModel(), SearchFilterType.F_DESCRIPTION.getLocalPart()));
    description.add(WebComponentUtil.enabledIfFalse(readOnlyModel));
    add(description);
    AceEditor clause = new AceEditor(ID_FILTER_CLAUSE, clauseStringModel);
    clause.add(WebComponentUtil.enabledIfFalse(readOnlyModel));
    add(clause);
    AjaxSubmitLink update = new AjaxSubmitLink(ID_BUTTON_UPDATE) {

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            updateClausePerformed(target);
        }
    };
    update.add(WebComponentUtil.visibleIfFalse(readOnlyModel));
    add(update);
    Label clauseTooltip = new Label(ID_T_CLAUSE);
    clauseTooltip.add(new InfoTooltipBehavior());
    add(clauseTooltip);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) InfoTooltipBehavior(com.evolveum.midpoint.web.util.InfoTooltipBehavior) TextArea(org.apache.wicket.markup.html.form.TextArea) Form(org.apache.wicket.markup.html.form.Form) Label(org.apache.wicket.markup.html.basic.Label) AceEditor(com.evolveum.midpoint.web.component.AceEditor) AjaxSubmitLink(org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink)

Example 60 with Form

use of org.apache.wicket.markup.html.form.Form in project midpoint by Evolveum.

the class DefinitionStagesPanel method initLayout.

private void initLayout() {
    List<ITab> tabs = new ArrayList<>();
    createTabs(tabs);
    tabPanel = WebComponentUtil.createTabPanel(ID_TAB_PANEL, parentPage, tabs, null);
    add(tabPanel);
    AjaxSubmitButton addNewStage = new AjaxSubmitButton(ID_ADD_NEW_STAGE, createStringResource("StageDefinitionPanel.addNewStageButton")) {

        @Override
        public void onSubmit(AjaxRequestTarget target, Form form) {
            super.onSubmit(target, form);
            addPerformed(target);
        }
    };
    add(addNewStage);
    // use the same isVisible for all buttons to avoid changing buttons' placement (especially dangerous is "delete stage" one)
    // we also don't use isEnabled as it seems to have no visual effect
    VisibleEnableBehaviour visibleIfMoreTabs = new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return getModelObject().size() > 1;
        }
    };
    AjaxSubmitButton moveLeft = new AjaxSubmitButton(ID_MOVE_STAGE_LEFT, createStringResource("StageDefinitionPanel.moveStageLeftButton")) {

        @Override
        public void onSubmit(AjaxRequestTarget target, Form form) {
            super.onSubmit(target, form);
            moveLeftPerformed(target);
        }
    };
    moveLeft.add(visibleIfMoreTabs);
    add(moveLeft);
    AjaxSubmitButton moveRight = new AjaxSubmitButton(ID_MOVE_STAGE_RIGHT, createStringResource("StageDefinitionPanel.moveStageRightButton")) {

        @Override
        public void onSubmit(AjaxRequestTarget target, Form form) {
            super.onSubmit(target, form);
            moveRightPerformed(target);
        }
    };
    moveRight.add(visibleIfMoreTabs);
    add(moveRight);
    AjaxSubmitButton delete = new AjaxSubmitButton(ID_DELETE_STAGE, createStringResource("StageDefinitionPanel.deleteStageButton")) {

        @Override
        public void onSubmit(AjaxRequestTarget target, Form form) {
            super.onSubmit(target, form);
            deletePerformed(target);
        }
    };
    delete.add(visibleIfMoreTabs);
    add(delete);
    setOutputMarkupId(true);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxSubmitButton(com.evolveum.midpoint.web.component.AjaxSubmitButton) Form(org.apache.wicket.markup.html.form.Form) ArrayList(java.util.ArrayList) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) ITab(org.apache.wicket.extensions.markup.html.tabs.ITab)

Aggregations

Form (org.apache.wicket.markup.html.form.Form)109 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)78 AjaxSubmitButton (com.evolveum.midpoint.web.component.AjaxSubmitButton)37 ArrayList (java.util.ArrayList)26 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)25 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)21 Label (org.apache.wicket.markup.html.basic.Label)18 List (java.util.List)16 AjaxButton (com.evolveum.midpoint.web.component.AjaxButton)13 AjaxLink (org.apache.wicket.ajax.markup.html.AjaxLink)11 TextField (org.apache.wicket.markup.html.form.TextField)11 DropDownChoice (org.apache.wicket.markup.html.form.DropDownChoice)10 InlineMenuItem (com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem)9 AbstractReadOnlyModel (org.apache.wicket.model.AbstractReadOnlyModel)9 IModel (org.apache.wicket.model.IModel)9 PropertyModel (org.apache.wicket.model.PropertyModel)9 AceEditor (com.evolveum.midpoint.web.component.AceEditor)8 AjaxSubmitLink (org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink)8 ListItem (org.apache.wicket.markup.html.list.ListItem)8 ListView (org.apache.wicket.markup.html.list.ListView)8