use of org.jboss.hal.ballroom.Alert in project console by hal.
the class StoresPresenter method verifyRenewCertificate.
void verifyRenewCertificate(Metadata metadata, String name, String alias) {
metadata = metadata.forOperation(SHOULD_RENEW_CERTIFICATE);
String id = Ids.build(KEY_STORE, SHOULD_RENEW_CERTIFICATE, FORM);
Form<ModelNode> form = new ModelNodeForm.Builder<>(id, metadata).build();
form.setSaveCallback((form1, changedValues) -> {
ResourceAddress address = KEY_STORE_TEMPLATE.resolve(statementContext, name);
Operation operation = new Operation.Builder(address, SHOULD_RENEW_CERTIFICATE).payload(form.getModel()).build();
dispatcher.execute(operation, result -> {
int days = result.get("days-to-expiry").asInt();
Date dueDate = new Date();
CalendarUtil.addDaysToDate(dueDate, days);
HTMLElement content;
if (days < 1) {
Alert warning = new Alert(Icons.WARNING, resources.messages().certificateExpired(alias));
content = div().add(warning).element();
} else {
SafeHtml description = resources.messages().certificateShouldRenew(days, alias, Format.mediumDateTime(dueDate));
content = p().innerHtml(description).element();
}
new Dialog.Builder(resources.constants().verifyRenewCertificate()).primary(resources.constants().ok(), null).size(Dialog.Size.MEDIUM).add(content).build().show();
}, (operation1, failure) -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().verifyRenewError(alias, name, failure))), (operation1, ex) -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().verifyRenewError(alias, name, ex.getMessage()))));
});
Dialog dialog = new Dialog.Builder(resources.constants().verifyRenewCertificate()).add(p().textContent(metadata.getDescription().getDescription()).element()).add(form.element()).primary(resources.constants().verifyRenew(), form::save).size(Dialog.Size.MEDIUM).closeOnEsc(true).cancel().build();
dialog.registerAttachable(form);
dialog.show();
ModelNode model = new ModelNode();
model.get(ALIAS).set(alias);
form.getFormItem(ALIAS).setEnabled(false);
form.edit(model);
}
use of org.jboss.hal.ballroom.Alert in project console by hal.
the class ModelNodeForm method attach.
@Override
@JsMethod
public void attach() {
super.attach();
if (Iterables.isEmpty(getFormItems())) {
Alert alert = new Alert(Icons.INFO, MESSAGES.emptyModelNodeForm());
Elements.removeChildrenFrom(element());
element().appendChild(alert.element());
}
if (singleton && ping != null && ping.get() != null) {
Core.INSTANCE.dispatcher().execute(ping.get(), result -> {
if (!result.isDefined()) {
flip(EMPTY);
} else {
flip(READONLY);
}
}, (op, failure) -> flip(READONLY));
}
}
use of org.jboss.hal.ballroom.Alert in project console by hal.
the class ServerActions method editUrl.
public void editUrl(Server server, Callback callback) {
Alert alert = new Alert(Icons.ERROR, resources.messages().serverUrlError());
HTMLElement info = p().element();
TextBoxItem urlItem = new TextBoxItem(URL, Names.URL);
Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.SERVER_URL_FORM, Metadata.empty()).unboundFormItem(urlItem).addOnly().onSave((f, changedValues) -> {
String url = urlItem.getValue();
if (Strings.isNullOrEmpty(url)) {
serverUrlStorage.remove(server.getHost(), server.getName());
} else {
serverUrlStorage.save(server.getHost(), server.getName(), url);
}
callback.execute();
}).build();
Dialog dialog = new Dialog.Builder(resources.constants().editURL()).add(alert.element()).add(info).add(form.element()).primary(form::save).cancel().closeIcon(true).closeOnEsc(true).build();
dialog.registerAttachable(form);
Elements.setVisible(alert.element(), false);
Elements.setVisible(info, false);
readUrl(server, new AsyncCallback<ServerUrl>() {
@Override
public void onFailure(Throwable caught) {
Elements.setVisible(alert.element(), true);
show(null);
}
@Override
public void onSuccess(ServerUrl serverUrl) {
if (serverUrl.isCustom()) {
info.innerHTML = resources.messages().serverUrlCustom().asString();
} else {
info.innerHTML = resources.messages().serverUrlManagementModel().asString();
}
Elements.setVisible(info, true);
show(serverUrl);
}
private void show(ServerUrl serverUrl) {
dialog.show();
form.edit(new ModelNode());
if (serverUrl != null) {
urlItem.setValue(serverUrl.getUrl());
}
}
});
}
Aggregations