/**
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.bricket.plugin.user_role.web;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.StringResourceModel;
import org.apache.wicket.request.target.basic.RedirectRequestTarget;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.bricket.plugin.user_role.service.UserRoleService;
import org.bricket.service.BricketServiceException;
import org.bricket.web.BricketConfigAwarePanel;
import brix.jcr.wrapper.BrixNode;
import brix.web.nodepage.PageParametersCarryingLink;
/**
* @author Ingo Renner
* @author Henning Teek
*/
public class AcceptRolePanel extends BricketConfigAwarePanel<AcceptRoleConfig> {
@SpringBean
private UserRoleService userRoleService;
public AcceptRolePanel(String id, IModel<BrixNode> tileNode) {
super(id, tileNode, new AcceptRoleConfig());
}
@Override
protected void initGui() {
// OK
AjaxLink<Object> okLink = new AjaxLink<Object>("okLink") {
@Override
public void onClick(AjaxRequestTarget target) {
try {
userRoleService.assignRole(getUser(), getConfig().getRole());
getRequestCycle().setRequestTarget(new RedirectRequestTarget(getConfig().getOkUrl()));
} catch (BricketServiceException e) {
error(new StringResourceModel(e.getKey(), AcceptRolePanel.this, null).getString());
target.addComponent(getFeedback());
}
}
};
okLink.add(new Label("okLabel", getConfig().getOkLabel()));
add(okLink);
// Deny
PageParametersCarryingLink denyLink = new PageParametersCarryingLink("denyLink", getConfig()
.getDenyBrixNodeModel());
denyLink.add(new Label("denyLabel", getConfig().getDenyLabel()));
add(denyLink);
}
}