Search in sources :

Example 1 with AjaxRequestTarget

use of org.apache.wicket.ajax.AjaxRequestTarget in project wicket-dashboard by decebals.

the class SWFObject method getJavaScript.

public String getJavaScript() {
    final String id = component.getMarkupId();
    String parObj = buildDataObject(getParameters());
    String attObj = buildDataObject(getAttributes());
    // embedSWF: function(swfUrlStr, replaceElemIdStr, widthStr, heightStr, swfVersionStr, xiSwfUrlStr, flashvarsObj, parObj, attObj)
    String javascript = String.format("swfobject.embedSWF('%s','%s', '%s', '%s', '%s', '%s', %s, %s );", flashUrl, id, width, height, version, "expressInstall.swf", parObj, attObj);
    // see http://old.nabble.com/Re%3A-Graphs%2C-Charts-and-Wicket-p21987222.html
    AjaxRequestTarget target = RequestCycle.get().find(AjaxRequestTarget.class);
    if (target != null) {
        target.appendJavaScript(javascript);
    }
    return javascript;
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget)

Example 2 with AjaxRequestTarget

use of org.apache.wicket.ajax.AjaxRequestTarget in project gitblit by gitblit.

the class TicketPage method createMergePanel.

/**
	 * Adds a merge panel for the patchset to the markup container.  The panel
	 * may just a message if the patchset can not be merged.
	 *
	 * @param c
	 * @param user
	 * @param repository
	 */
protected Component createMergePanel(UserModel user, RepositoryModel repository) {
    Patchset patchset = ticket.getCurrentPatchset();
    if (patchset == null) {
        // no patchset to merge
        return new Label("mergePanel");
    }
    boolean allowMerge;
    if (repository.requireApproval) {
        // repository requires approval
        allowMerge = ticket.isOpen() && ticket.isApproved(patchset);
    } else {
        // vetoes are binding
        allowMerge = ticket.isOpen() && !ticket.isVetoed(patchset);
    }
    MergeStatus mergeStatus = JGitUtils.canMerge(getRepository(), patchset.tip, ticket.mergeTo, repository.mergeType);
    if (allowMerge) {
        if (MergeStatus.MERGEABLE == mergeStatus) {
            // patchset can be cleanly merged to integration branch OR has already been merged
            Fragment mergePanel = new Fragment("mergePanel", "mergeableFragment", this);
            mergePanel.add(new Label("mergeTitle", MessageFormat.format(getString("gb.patchsetMergeable"), ticket.mergeTo)));
            if (user.canPush(repository)) {
                // user can merge locally
                SimpleAjaxLink<String> mergeButton = new SimpleAjaxLink<String>("mergeButton", Model.of(getString("gb.merge"))) {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public void onClick(AjaxRequestTarget target) {
                        // ensure the patchset is still current AND not vetoed
                        Patchset patchset = ticket.getCurrentPatchset();
                        final TicketModel refreshedTicket = app().tickets().getTicket(getRepositoryModel(), ticket.number);
                        if (patchset.equals(refreshedTicket.getCurrentPatchset())) {
                            // patchset is current, check for recent veto
                            if (!refreshedTicket.isVetoed(patchset)) {
                                // patchset is not vetoed
                                // execute the merge using the ticket service
                                app().tickets().exec(new Runnable() {

                                    @Override
                                    public void run() {
                                        PatchsetReceivePack rp = new PatchsetReceivePack(app().gitblit(), getRepository(), getRepositoryModel(), GitBlitWebSession.get().getUser());
                                        MergeStatus result = rp.merge(refreshedTicket);
                                        if (MergeStatus.MERGED == result) {
                                            // notify participants and watchers
                                            rp.sendAll();
                                        } else {
                                            // merge failure
                                            String msg = MessageFormat.format("Failed to merge ticket {0,number,0}: {1}", ticket.number, result.name());
                                            logger.error(msg);
                                            GitBlitWebSession.get().cacheErrorMessage(msg);
                                        }
                                    }
                                });
                            } else {
                                // vetoed patchset
                                String msg = MessageFormat.format("Can not merge ticket {0,number,0}, patchset {1,number,0} has been vetoed!", ticket.number, patchset.number);
                                GitBlitWebSession.get().cacheErrorMessage(msg);
                                logger.error(msg);
                            }
                        } else {
                            // not current patchset
                            String msg = MessageFormat.format("Can not merge ticket {0,number,0}, the patchset has been updated!", ticket.number);
                            GitBlitWebSession.get().cacheErrorMessage(msg);
                            logger.error(msg);
                        }
                        redirectTo(TicketsPage.class, getPageParameters());
                    }
                };
                mergePanel.add(mergeButton);
                Component instructions = getMergeInstructions(user, repository, "mergeMore", "gb.patchsetMergeableMore");
                mergePanel.add(instructions);
            } else {
                mergePanel.add(new Label("mergeButton").setVisible(false));
                mergePanel.add(new Label("mergeMore").setVisible(false));
            }
            return mergePanel;
        } else if (MergeStatus.ALREADY_MERGED == mergeStatus) {
            // patchset already merged
            Fragment mergePanel = new Fragment("mergePanel", "alreadyMergedFragment", this);
            mergePanel.add(new Label("mergeTitle", MessageFormat.format(getString("gb.patchsetAlreadyMerged"), ticket.mergeTo)));
            return mergePanel;
        } else if (MergeStatus.MISSING_INTEGRATION_BRANCH == mergeStatus) {
            // target/integration branch is missing
            Fragment mergePanel = new Fragment("mergePanel", "notMergeableFragment", this);
            mergePanel.add(new Label("mergeTitle", MessageFormat.format(getString("gb.patchsetNotMergeable"), ticket.mergeTo)));
            mergePanel.add(new Label("mergeMore", MessageFormat.format(getString("gb.missingIntegrationBranchMore"), ticket.mergeTo)));
            return mergePanel;
        } else {
            // patchset can not be cleanly merged
            Fragment mergePanel = new Fragment("mergePanel", "notMergeableFragment", this);
            mergePanel.add(new Label("mergeTitle", MessageFormat.format(getString("gb.patchsetNotMergeable"), ticket.mergeTo)));
            if (user.canPush(repository)) {
                // user can merge locally
                Component instructions = getMergeInstructions(user, repository, "mergeMore", "gb.patchsetNotMergeableMore");
                mergePanel.add(instructions);
            } else {
                mergePanel.add(new Label("mergeMore").setVisible(false));
            }
            return mergePanel;
        }
    } else {
        // merge not allowed
        if (MergeStatus.ALREADY_MERGED == mergeStatus) {
            // patchset already merged
            Fragment mergePanel = new Fragment("mergePanel", "alreadyMergedFragment", this);
            mergePanel.add(new Label("mergeTitle", MessageFormat.format(getString("gb.patchsetAlreadyMerged"), ticket.mergeTo)));
            return mergePanel;
        } else if (ticket.isVetoed(patchset)) {
            // patchset has been vetoed
            Fragment mergePanel = new Fragment("mergePanel", "vetoedFragment", this);
            mergePanel.add(new Label("mergeTitle", MessageFormat.format(getString("gb.patchsetNotMergeable"), ticket.mergeTo)));
            return mergePanel;
        } else if (repository.requireApproval) {
            // patchset has been not been approved for merge
            Fragment mergePanel = new Fragment("mergePanel", "notApprovedFragment", this);
            mergePanel.add(new Label("mergeTitle", MessageFormat.format(getString("gb.patchsetNotApproved"), ticket.mergeTo)));
            mergePanel.add(new Label("mergeMore", MessageFormat.format(getString("gb.patchsetNotApprovedMore"), ticket.mergeTo)));
            return mergePanel;
        } else {
            // other case
            return new Label("mergePanel");
        }
    }
}
Also used : PatchsetReceivePack(com.gitblit.git.PatchsetReceivePack) Label(org.apache.wicket.markup.html.basic.Label) TicketLabel(com.gitblit.tickets.TicketLabel) Patchset(com.gitblit.models.TicketModel.Patchset) TicketModel(com.gitblit.models.TicketModel) Fragment(org.apache.wicket.markup.html.panel.Fragment) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) SimpleAjaxLink(com.gitblit.wicket.panels.SimpleAjaxLink) MergeStatus(com.gitblit.utils.JGitUtils.MergeStatus) ShockWaveComponent(com.gitblit.wicket.panels.ShockWaveComponent) Component(org.apache.wicket.Component)

Example 3 with AjaxRequestTarget

use of org.apache.wicket.ajax.AjaxRequestTarget in project gitblit by gitblit.

the class UserPage method addPreferences.

private void addPreferences(UserModel user) {
    // add preferences
    Form<Void> prefs = new Form<Void>("prefsForm");
    List<Language> languages = getLanguages();
    Locale locale = user.getPreferences().getLocale();
    if (locale == null) {
        // user has not specified language preference
        // try server default preference
        String lc = app().settings().getString(Keys.web.forceDefaultLocale, null);
        if (StringUtils.isEmpty(lc)) {
            // server default language is not configured
            // try browser preference
            Locale sessionLocale = GitBlitWebSession.get().getLocale();
            if (sessionLocale != null) {
                locale = sessionLocale;
            }
        } else {
        }
    }
    Language preferredLanguage = null;
    if (locale != null) {
        String localeCode = locale.getLanguage();
        if (!StringUtils.isEmpty(locale.getCountry())) {
            localeCode += "_" + locale.getCountry();
        }
        for (Language language : languages) {
            if (language.code.equals(localeCode)) {
                // language_COUNTRY match
                preferredLanguage = language;
            } else if (preferredLanguage != null && language.code.startsWith(locale.getLanguage())) {
                // language match
                preferredLanguage = language;
            }
        }
    }
    final IModel<String> displayName = Model.of(user.getDisplayName());
    final IModel<String> emailAddress = Model.of(user.emailAddress == null ? "" : user.emailAddress);
    final IModel<Language> language = Model.of(preferredLanguage);
    final IModel<Boolean> emailMeOnMyTicketChanges = Model.of(user.getPreferences().isEmailMeOnMyTicketChanges());
    final IModel<Transport> transport = Model.of(user.getPreferences().getTransport());
    prefs.add(new TextOption("displayName", getString("gb.displayName"), getString("gb.displayNameDescription"), displayName).setVisible(app().authentication().supportsDisplayNameChanges(user)));
    prefs.add(new TextOption("emailAddress", getString("gb.emailAddress"), getString("gb.emailAddressDescription"), emailAddress).setVisible(app().authentication().supportsEmailAddressChanges(user)));
    prefs.add(new ChoiceOption<Language>("language", getString("gb.languagePreference"), getString("gb.languagePreferenceDescription"), language, languages));
    prefs.add(new BooleanOption("emailMeOnMyTicketChanges", getString("gb.emailMeOnMyTicketChanges"), getString("gb.emailMeOnMyTicketChangesDescription"), emailMeOnMyTicketChanges).setVisible(app().notifier().isSendingMail()));
    List<Transport> availableTransports = new ArrayList<>();
    if (app().services().isServingSSH()) {
        availableTransports.add(Transport.SSH);
    }
    if (app().services().isServingHTTP()) {
        availableTransports.add(Transport.HTTP);
    }
    if (app().services().isServingHTTPS()) {
        availableTransports.add(Transport.HTTPS);
    }
    if (app().services().isServingGIT()) {
        availableTransports.add(Transport.GIT);
    }
    prefs.add(new ChoiceOption<Transport>("transport", getString("gb.transportPreference"), getString("gb.transportPreferenceDescription"), transport, availableTransports));
    prefs.add(new AjaxButton("save") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            UserModel user = GitBlitWebSession.get().getUser();
            user.displayName = displayName.getObject();
            user.emailAddress = emailAddress.getObject();
            Language lang = language.getObject();
            if (lang != null) {
                user.getPreferences().setLocale(lang.code);
            }
            user.getPreferences().setEmailMeOnMyTicketChanges(emailMeOnMyTicketChanges.getObject());
            user.getPreferences().setTransport(transport.getObject());
            try {
                app().gitblit().reviseUser(user.username, user);
                setRedirect(true);
                setResponsePage(UserPage.class, WicketUtils.newUsernameParameter(user.username));
            } catch (GitBlitException e) {
            // logger.error("Failed to update user " + user.username, e);
            // error(getString("gb.failedToUpdateUser"), false);
            }
        }
    });
    // add the preferences tab
    add(new Fragment("preferencesLink", "preferencesLinkFragment", this).setRenderBodyOnly(true));
    Fragment fragment = new Fragment("preferencesTab", "preferencesTabFragment", this);
    fragment.add(prefs);
    add(fragment.setRenderBodyOnly(true));
}
Also used : Locale(java.util.Locale) Form(org.apache.wicket.markup.html.form.Form) ArrayList(java.util.ArrayList) TextOption(com.gitblit.wicket.panels.TextOption) GitBlitException(com.gitblit.GitBlitException) Fragment(org.apache.wicket.markup.html.panel.Fragment) UserModel(com.gitblit.models.UserModel) AjaxButton(org.apache.wicket.ajax.markup.html.form.AjaxButton) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) Transport(com.gitblit.Constants.Transport) BooleanOption(com.gitblit.wicket.panels.BooleanOption)

Example 4 with AjaxRequestTarget

use of org.apache.wicket.ajax.AjaxRequestTarget in project gitblit by gitblit.

the class SshKeysPanel method onInitialize.

@Override
protected void onInitialize() {
    super.onInitialize();
    setOutputMarkupId(true);
    final List<SshKey> keys = new ArrayList<SshKey>(app().keys().getKeys(user.username));
    final ListDataProvider<SshKey> dp = new ListDataProvider<SshKey>(keys);
    final DataView<SshKey> keysView = new DataView<SshKey>("keys", dp) {

        private static final long serialVersionUID = 1L;

        @Override
        public void populateItem(final Item<SshKey> item) {
            final SshKey key = item.getModelObject();
            item.add(new Label("comment", key.getComment()));
            item.add(new Label("fingerprint", key.getFingerprint()));
            item.add(new Label("permission", key.getPermission().toString()));
            item.add(new Label("algorithm", key.getAlgorithm()));
            AjaxLink<Void> delete = new AjaxLink<Void>("delete") {

                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(AjaxRequestTarget target) {
                    if (app().keys().removeKey(user.username, key)) {
                        // reset the keys list
                        keys.clear();
                        keys.addAll(app().keys().getKeys(user.username));
                        // update the panel
                        target.addComponent(SshKeysPanel.this);
                    }
                }
            };
            if (!canWriteKeys) {
                delete.setVisibilityAllowed(false);
            }
            item.add(delete);
        }
    };
    add(keysView);
    Form<Void> addKeyForm = new Form<Void>("addKeyForm");
    final IModel<String> keyData = Model.of("");
    addKeyForm.add(new TextAreaOption("addKeyData", getString("gb.key"), null, "span5", keyData));
    final IModel<AccessPermission> keyPermission = Model.of(AccessPermission.PUSH);
    addKeyForm.add(new ChoiceOption<AccessPermission>("addKeyPermission", getString("gb.permission"), getString("gb.sshKeyPermissionDescription"), keyPermission, Arrays.asList(AccessPermission.SSHPERMISSIONS)));
    final IModel<String> keyComment = Model.of("");
    addKeyForm.add(new TextOption("addKeyComment", getString("gb.comment"), getString("gb.sshKeyCommentDescription"), "span5", keyComment));
    addKeyForm.add(new AjaxButton("addKeyButton") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            UserModel user = GitBlitWebSession.get().getUser();
            String data = keyData.getObject();
            if (StringUtils.isEmpty(data)) {
                // do not submit empty key
                return;
            }
            SshKey key = new SshKey(data);
            try {
                key.getPublicKey();
            } catch (Exception e) {
                // failed to parse the key
                return;
            }
            AccessPermission permission = keyPermission.getObject();
            key.setPermission(permission);
            String comment = keyComment.getObject();
            if (!StringUtils.isEmpty(comment)) {
                key.setComment(comment);
            }
            if (app().keys().addKey(user.username, key)) {
                // reset add key fields
                keyData.setObject("");
                keyPermission.setObject(AccessPermission.PUSH);
                keyComment.setObject("");
                // reset the keys list
                keys.clear();
                keys.addAll(app().keys().getKeys(user.username));
                // update the panel
                target.addComponent(SshKeysPanel.this);
            }
        }
    });
    if (!canWriteKeys) {
        addKeyForm.setVisibilityAllowed(false);
    }
    add(addKeyForm);
}
Also used : ListDataProvider(org.apache.wicket.markup.repeater.data.ListDataProvider) Form(org.apache.wicket.markup.html.form.Form) ArrayList(java.util.ArrayList) Label(org.apache.wicket.markup.html.basic.Label) UserModel(com.gitblit.models.UserModel) Item(org.apache.wicket.markup.repeater.Item) AjaxButton(org.apache.wicket.ajax.markup.html.form.AjaxButton) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) AccessPermission(com.gitblit.Constants.AccessPermission) SshKey(com.gitblit.transport.ssh.SshKey) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) DataView(org.apache.wicket.markup.repeater.data.DataView)

Example 5 with AjaxRequestTarget

use of org.apache.wicket.ajax.AjaxRequestTarget in project midpoint by Evolveum.

the class H3Header method initLayout.

@Override
protected void initLayout() {
    Label title = new Label(ID_TITLE, new AbstractReadOnlyModel<String>() {

        @Override
        public String getObject() {
            return getDisplayName();
        }
    });
    add(title);
    final IModel<List<InlineMenuItem>> items = new Model((Serializable) createMenuItems());
    BootstrapLabel status = new BootstrapLabel(ID_STATUS, createStringResource("H3Header.label.error"), new Model(BootstrapLabel.State.DANGER));
    status.add(createFetchErrorVisibleBehaviour());
    add(status);
    AjaxLink showMore = new AjaxLink(ID_SHOW_MORE) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            onShowMorePerformed(target);
        }
    };
    showMore.add(createFetchErrorVisibleBehaviour());
    add(showMore);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) BootstrapLabel(com.evolveum.midpoint.web.component.BootstrapLabel) Label(org.apache.wicket.markup.html.basic.Label) BootstrapLabel(com.evolveum.midpoint.web.component.BootstrapLabel) AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) Model(org.apache.wicket.model.Model) IModel(org.apache.wicket.model.IModel) ArrayList(java.util.ArrayList) List(java.util.List) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink)

Aggregations

AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)379 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)116 Label (org.apache.wicket.markup.html.basic.Label)103 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)102 ArrayList (java.util.ArrayList)88 AjaxLink (org.apache.wicket.ajax.markup.html.AjaxLink)80 Form (org.apache.wicket.markup.html.form.Form)75 IModel (org.apache.wicket.model.IModel)71 AbstractReadOnlyModel (org.apache.wicket.model.AbstractReadOnlyModel)69 AjaxButton (com.evolveum.midpoint.web.component.AjaxButton)65 List (java.util.List)53 AjaxSubmitButton (com.evolveum.midpoint.web.component.AjaxSubmitButton)48 Model (org.apache.wicket.model.Model)43 PropertyModel (org.apache.wicket.model.PropertyModel)42 ListItem (org.apache.wicket.markup.html.list.ListItem)41 InlineMenuItem (com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem)37 IColumn (org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn)34 AjaxFormComponentUpdatingBehavior (org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior)32 TextField (org.apache.wicket.markup.html.form.TextField)30 ListView (org.apache.wicket.markup.html.list.ListView)30