use of org.apache.wicket.ajax.markup.html.form.AjaxButton in project gitblit by gitblit.
the class UserPage method addPreferences.
private void addPreferences(UserModel user) {
// add preferences
Form<Void> prefs = new Form<Void>("prefsForm");
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;
}
}
}
List<Language> languages = getLanguages();
Language preferredLanguage = getPreferredLanguage(locale, languages);
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));
}
use of org.apache.wicket.ajax.markup.html.form.AjaxButton 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.sshKeyComment"), 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);
}
use of org.apache.wicket.ajax.markup.html.form.AjaxButton in project hippo by NHS-digital-website.
the class EarlyAccessKeyPlugin method getGenerateButton.
private AjaxButton getGenerateButton(JcrPropertyValueModel model, Item item) {
AjaxButton generate = new AjaxButton("generate") {
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
try {
model.getJcrPropertymodel().getProperty().setValue(generateKey());
target.add(item);
} catch (RepositoryException e) {
LOG.error(e.getMessage());
}
}
};
generate.setDefaultFormProcessing(false);
return generate;
}
use of org.apache.wicket.ajax.markup.html.form.AjaxButton in project hippo by NHS-digital-website.
the class EarlyAccessKeyPlugin method getDeleteButton.
private AjaxButton getDeleteButton(JcrPropertyValueModel model, Item item) {
AjaxButton delete = new AjaxButton("delete") {
@Override
public void onSubmit(AjaxRequestTarget target, Form<?> form) {
try {
model.getJcrPropertymodel().getProperty().setValue("");
target.add(item);
} catch (RepositoryException e) {
LOG.error(e.getMessage());
}
}
};
delete.setDefaultFormProcessing(false);
return delete;
}
use of org.apache.wicket.ajax.markup.html.form.AjaxButton in project sandbox by irof.
the class ButtonPanel method ajaxButtons.
private void ajaxButtons() {
Form<Void> form = new Form<>("ajaxForm");
add(form);
Model<String> left = Model.of("hoge");
Model<String> right = Model.of("fuga");
WebMarkupContainer p1 = new WebMarkupContainer("p1");
p1.add(new Label("leftLabel", left));
p1.add(new Label("rightLabel", right));
form.add(p1.setOutputMarkupId(true));
WebMarkupContainer p2 = new WebMarkupContainer("p2");
p2.add(new Label("leftLabel", left));
p2.add(new Label("rightLabel", right));
form.add(p2.setOutputMarkupId(true));
form.add(new AjaxButton("leftButton") {
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
left.setObject(left.getObject() + "e");
target.add(p1);
}
});
form.add(new AjaxButton("rightButton") {
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
right.setObject(right.getObject() + "a");
target.add(p2);
}
});
}
Aggregations