List of usage examples for org.apache.wicket.ajax AjaxRequestTarget appendJavaScript
void appendJavaScript(CharSequence javascript);
If the javascript needs to do something asynchronously (i.e.
From source file:org.apache.syncope.client.console.panels.ImplementationModalPanel.java
License:Apache License
public ImplementationModalPanel(final BaseModal<ImplementationTO> modal, final ImplementationTO implementation, final PageReference pageRef) { super(modal, pageRef); this.implementation = implementation; this.viewMode = implementation.getEngine() == ImplementationEngine.GROOVY ? ViewMode.GROOVY_BODY : implementation.getType() == ImplementationType.REPORTLET || implementation.getType() == ImplementationType.ACCOUNT_RULE || implementation.getType() == ImplementationType.PASSWORD_RULE || implementation.getType() == ImplementationType.PULL_CORRELATION_RULE ? ViewMode.JSON_BODY : ViewMode.JAVA_CLASS; this.create = implementation.getKey() == null; add(new AjaxTextFieldPanel("key", "key", new PropertyModel<>(implementation, "key"), false) .addRequiredLabel().setEnabled(create)); List<String> classes = Collections.emptyList(); if (viewMode == ViewMode.JAVA_CLASS) { Optional<JavaImplInfo> javaClasses = SyncopeConsoleSession.get().getPlatformInfo() .getJavaImplInfo(implementation.getType()); classes = javaClasses.isPresent() ? new ArrayList<>(javaClasses.get().getClasses()) : new ArrayList<>(); } else if (viewMode == ViewMode.JSON_BODY) { ClassPathScanImplementationLookup implementationLookup = (ClassPathScanImplementationLookup) SyncopeConsoleApplication .get().getServletContext().getAttribute(ConsoleInitializer.CLASSPATH_LOOKUP); switch (implementation.getType()) { case REPORTLET: classes = implementationLookup.getReportletConfs().keySet().stream().collect(Collectors.toList()); break; case ACCOUNT_RULE: classes = implementationLookup.getAccountRuleConfs().keySet().stream().collect(Collectors.toList()); break; case PASSWORD_RULE: classes = implementationLookup.getPasswordRuleConfs().keySet().stream() .collect(Collectors.toList()); break; case PULL_CORRELATION_RULE: classes = implementationLookup.getPullCorrelationRuleConfs().keySet().stream() .collect(Collectors.toList()); break; default://from w ww.ja v a 2 s . co m } } Collections.sort(classes); AjaxDropDownChoicePanel<String> javaClass = new AjaxDropDownChoicePanel<>("javaClass", "Class", new PropertyModel<>(implementation, "body")); javaClass.setNullValid(false); javaClass.setChoices(classes); javaClass.addRequiredLabel(); javaClass.setOutputMarkupId(true).setOutputMarkupPlaceholderTag(true); javaClass.setVisible(viewMode == ViewMode.JAVA_CLASS); add(javaClass); AjaxDropDownChoicePanel<String> jsonClass = new AjaxDropDownChoicePanel<>("jsonClass", "Class", new Model<>()); jsonClass.setNullValid(false); jsonClass.setChoices(classes); jsonClass.addRequiredLabel(); jsonClass.setOutputMarkupId(true).setOutputMarkupPlaceholderTag(true); jsonClass.setVisible(viewMode == ViewMode.JSON_BODY); if (viewMode == ViewMode.JSON_BODY && StringUtils.isNotBlank(implementation.getBody())) { try { JsonNode node = MAPPER.readTree(implementation.getBody()); if (node.has("@class")) { jsonClass.setModelObject(node.get("@class").asText()); } } catch (IOException e) { LOG.error("Could not parse as JSON payload: {}", implementation.getBody(), e); } } jsonClass.setReadOnly(jsonClass.getModelObject() != null); add(jsonClass); WebMarkupContainer groovyClassContainer = new WebMarkupContainer("groovyClassContainer"); groovyClassContainer.setOutputMarkupId(true).setOutputMarkupPlaceholderTag(true); groovyClassContainer.setVisible(viewMode != ViewMode.JAVA_CLASS); add(groovyClassContainer); if (StringUtils.isBlank(implementation.getBody()) && implementation.getEngine() == ImplementationEngine.GROOVY) { String templateClassName = null; switch (implementation.getType()) { case REPORTLET: templateClassName = "MyReportlet"; break; case ACCOUNT_RULE: templateClassName = "MyAccountRule"; break; case PASSWORD_RULE: templateClassName = "MyPasswordRule"; break; case ITEM_TRANSFORMER: templateClassName = "MyItemTransformer"; break; case TASKJOB_DELEGATE: templateClassName = "MySchedTaskJobDelegate"; break; case RECON_FILTER_BUILDER: templateClassName = "MyReconFilterBuilder"; break; case LOGIC_ACTIONS: templateClassName = "MyLogicActions"; break; case PROPAGATION_ACTIONS: templateClassName = "MyPropagationActions"; break; case PULL_ACTIONS: templateClassName = "MyPullActions"; break; case PUSH_ACTIONS: templateClassName = "MyPushActions"; break; case PULL_CORRELATION_RULE: templateClassName = "MyPullCorrelationRule"; break; case VALIDATOR: templateClassName = "MyValidator"; break; case RECIPIENTS_PROVIDER: templateClassName = "MyRecipientsProvider"; break; default: } if (templateClassName != null) { try { implementation.setBody(StringUtils.substringAfter(IOUtils.toString( getClass().getResourceAsStream("/org/apache/syncope/client/console/implementations/" + templateClassName + ".groovy")), "*/\n")); } catch (IOException e) { LOG.error("Could not load the expected Groovy template {} for {}", templateClassName, implementation.getType(), e); } } } TextArea<String> groovyClass = new TextArea<>("groovyClass", new PropertyModel<>(implementation, "body")); groovyClass.setMarkupId("groovyClass").setOutputMarkupPlaceholderTag(true); groovyClass.setVisible(viewMode != ViewMode.JAVA_CLASS); groovyClass.setRequired(true); groovyClassContainer.add(groovyClass); jsonClass.add(new AjaxEventBehavior(Constants.ON_CHANGE) { private static final long serialVersionUID = 5538299138211283825L; @Override protected void onEvent(final AjaxRequestTarget target) { ClassPathScanImplementationLookup implementationLookup = (ClassPathScanImplementationLookup) SyncopeConsoleApplication .get().getServletContext().getAttribute(ConsoleInitializer.CLASSPATH_LOOKUP); Class<?> clazz = null; switch (implementation.getType()) { case REPORTLET: clazz = implementationLookup.getReportletConfs().get(jsonClass.getModelObject()); break; case ACCOUNT_RULE: clazz = implementationLookup.getAccountRuleConfs().get(jsonClass.getModelObject()); break; case PASSWORD_RULE: clazz = implementationLookup.getPasswordRuleConfs().get(jsonClass.getModelObject()); break; case PULL_CORRELATION_RULE: clazz = implementationLookup.getPullCorrelationRuleConfs().get(jsonClass.getModelObject()); break; default: } if (clazz != null) { try { target.appendJavaScript("editor.getDoc().setValue('" + MAPPER.writeValueAsString(clazz.newInstance()) + "');"); } catch (Exception e) { LOG.error("Could not generate a value for {}", jsonClass.getModelObject(), e); } } } }); }
From source file:org.apache.syncope.client.console.panels.TogglePanel.java
License:Apache License
/** * Force toggle via java. To be used when the onclick has been intercepted before. * * @param target ajax request target./*w w w. java2s.c o m*/ * @param toggle toggle action. */ public void toggle(final AjaxRequestTarget target, final boolean toggle) { final String selector = String.format("$(\"div#%s\")", activeId); if (toggle) { if (status == Status.INACTIVE) { target.add(TogglePanel.this.container); target.appendJavaScript(selector + ".toggle(\"slow\");" + selector + ".attr(\"class\", \"topology-menu active-topology-menu\");"); status = Status.ACTIVE; } } else if (status == Status.ACTIVE) { target.appendJavaScript(selector + ".toggle(\"slow\");" + selector + ".attr(\"class\", \"topology-menu inactive-topology-menu\");"); status = Status.INACTIVE; } }
From source file:org.apache.syncope.client.console.topology.Topology.java
License:Apache License
public Topology() { modal = new BaseModal<>("resource-modal"); body.add(modal.size(Modal.Size.Large)); modal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() { private static final long serialVersionUID = 8804221891699487139L; @Override/*from w ww . ja va 2s.c o m*/ public void onClose(final AjaxRequestTarget target) { modal.show(false); } }); body.add(new TopologyWebSocketBehavior()); togglePanel = new TopologyTogglePanel("toggle", getPageReference()); body.add(togglePanel); // ----------------------------------------- // Add Zoom panel // ----------------------------------------- final ActionLinksPanel.Builder<Serializable> zoomActionPanel = ActionLinksPanel.builder(); zoomActionPanel.setDisableIndicator(true); zoomActionPanel.add(new ActionLink<Serializable>() { private static final long serialVersionUID = -3722207913631435501L; @Override public void onClick(final AjaxRequestTarget target, final Serializable ignore) { target.appendJavaScript("zoomIn($('#drawing')[0]);"); } }, ActionLink.ActionType.ZOOM_IN, StandardEntitlement.RESOURCE_LIST).add(new ActionLink<Serializable>() { private static final long serialVersionUID = -3722207913631435501L; @Override public void onClick(final AjaxRequestTarget target, final Serializable ignore) { target.appendJavaScript("zoomOut($('#drawing')[0]);"); } }, ActionLink.ActionType.ZOOM_OUT, StandardEntitlement.RESOURCE_LIST); body.add(zoomActionPanel.build("zoom")); // ----------------------------------------- // ----------------------------------------- // Add Syncope (root topologynode) // ----------------------------------------- final TopologyNode syncopeTopologyNode = new TopologyNode(ROOT_NAME, ROOT_NAME, TopologyNode.Kind.SYNCOPE); syncopeTopologyNode.setX(origX); syncopeTopologyNode.setY(origY); final URI uri = WebClient.client(BaseRestClient.getSyncopeService()).getBaseURI(); syncopeTopologyNode.setHost(uri.getHost()); syncopeTopologyNode.setPort(uri.getPort()); body.add(topologyNodePanel("syncope", syncopeTopologyNode)); final Map<Serializable, Map<Serializable, TopologyNode>> connections = new HashMap<>(); final Map<Serializable, TopologyNode> syncopeConnections = new HashMap<>(); connections.put(syncopeTopologyNode.getKey(), syncopeConnections); // required to retrieve parent positions final Map<String, TopologyNode> servers = new HashMap<>(); final Map<String, TopologyNode> connectors = new HashMap<>(); // ----------------------------------------- // ----------------------------------------- // Add Connector Servers // ----------------------------------------- final ListView<URI> connectorServers = new ListView<URI>("connectorServers", csModel.getObject().getLeft()) { private static final long serialVersionUID = 6978621871488360380L; private final int size = csModel.getObject().getLeft().size() + 1; @Override protected void populateItem(final ListItem<URI> item) { int kx = size >= 4 ? 800 : (200 * size); int x = (int) Math.round(origX + kx * Math.cos(Math.PI + Math.PI * (item.getIndex() + 1) / size)); int y = (int) Math.round(origY + 100 * Math.sin(Math.PI + Math.PI * (item.getIndex() + 1) / size)); final URI location = item.getModelObject(); final String url = location.toASCIIString(); final TopologyNode topologynode = new TopologyNode(url, url, TopologyNode.Kind.CONNECTOR_SERVER); topologynode.setHost(location.getHost()); topologynode.setPort(location.getPort()); topologynode.setX(x); topologynode.setY(y); servers.put(String.class.cast(topologynode.getKey()), topologynode); item.add(topologyNodePanel("cs", topologynode)); syncopeConnections.put(url, topologynode); connections.put(url, new HashMap<Serializable, TopologyNode>()); } }; connectorServers.setOutputMarkupId(true); body.add(connectorServers); // ----------------------------------------- // ----------------------------------------- // Add File Paths // ----------------------------------------- final ListView<URI> filePaths = new ListView<URI>("filePaths", csModel.getObject().getRight()) { private static final long serialVersionUID = 6978621871488360380L; private final int size = csModel.getObject().getRight().size() + 1; @Override protected void populateItem(final ListItem<URI> item) { int kx = size >= 4 ? 800 : (200 * size); int x = (int) Math.round(origX + kx * Math.cos(Math.PI * (item.getIndex() + 1) / size)); int y = (int) Math.round(origY + 100 * Math.sin(Math.PI * (item.getIndex() + 1) / size)); final URI location = item.getModelObject(); final String url = location.toASCIIString(); final TopologyNode topologynode = new TopologyNode(url, url, TopologyNode.Kind.FS_PATH); topologynode.setHost(location.getHost()); topologynode.setPort(location.getPort()); topologynode.setX(x); topologynode.setY(y); servers.put(String.class.cast(topologynode.getKey()), topologynode); item.add(topologyNodePanel("fp", topologynode)); syncopeConnections.put(url, topologynode); connections.put(url, new HashMap<Serializable, TopologyNode>()); } }; filePaths.setOutputMarkupId(true); body.add(filePaths); // ----------------------------------------- // ----------------------------------------- // Add Connector Intances // ----------------------------------------- final List<List<ConnInstanceTO>> allConns = new ArrayList<>(connModel.getObject().values()); final ListView<List<ConnInstanceTO>> conns = new ListView<List<ConnInstanceTO>>("conns", allConns) { private static final long serialVersionUID = 697862187148836036L; @Override protected void populateItem(final ListItem<List<ConnInstanceTO>> item) { final int size = item.getModelObject().size() + 1; final ListView<ConnInstanceTO> conns = new ListView<ConnInstanceTO>("conns", item.getModelObject()) { private static final long serialVersionUID = 6978621871488360381L; @Override protected void populateItem(final ListItem<ConnInstanceTO> item) { final ConnInstanceTO conn = item.getModelObject(); final TopologyNode topologynode = new TopologyNode(conn.getKey(), conn.getDisplayName(), TopologyNode.Kind.CONNECTOR); // Define the parent note final TopologyNode parent = servers.get(conn.getLocation()); // Set the position int kx = size >= 6 ? 800 : (130 * size); final double hpos; if (conn.getLocation().startsWith(CONNECTOR_SERVER_LOCATION_PREFIX)) { hpos = Math.PI; } else { hpos = 0.0; } int x = (int) Math.round((parent == null ? origX : parent.getX()) + kx * Math.cos(hpos + Math.PI * (item.getIndex() + 1) / size)); int y = (int) Math.round((parent == null ? origY : parent.getY()) + 100 * Math.sin(hpos + Math.PI * (item.getIndex() + 1) / size)); topologynode.setConnectionDisplayName(conn.getBundleName()); topologynode.setX(x); topologynode.setY(y); connectors.put(String.class.cast(topologynode.getKey()), topologynode); item.add(topologyNodePanel("conn", topologynode)); // Update connections final Map<Serializable, TopologyNode> remoteConnections; if (connections.containsKey(conn.getLocation())) { remoteConnections = connections.get(conn.getLocation()); } else { remoteConnections = new HashMap<>(); connections.put(conn.getLocation(), remoteConnections); } remoteConnections.put(conn.getKey(), topologynode); } }; conns.setOutputMarkupId(true); item.add(conns); } }; conns.setOutputMarkupId(true); body.add(conns); // ----------------------------------------- // ----------------------------------------- // Add Resources // ----------------------------------------- final List<String> connToBeProcessed = new ArrayList<>(); for (ResourceTO resourceTO : resModel.getObject()) { final TopologyNode topologynode = new TopologyNode(resourceTO.getKey(), resourceTO.getKey(), TopologyNode.Kind.RESOURCE); final Map<Serializable, TopologyNode> remoteConnections; if (connections.containsKey(resourceTO.getConnector())) { remoteConnections = connections.get(resourceTO.getConnector()); } else { remoteConnections = new HashMap<>(); connections.put(resourceTO.getConnector(), remoteConnections); } remoteConnections.put(topologynode.getKey(), topologynode); if (!connToBeProcessed.contains(resourceTO.getConnector())) { connToBeProcessed.add(resourceTO.getConnector()); } } final ListView<String> resources = new ListView<String>("resources", connToBeProcessed) { private static final long serialVersionUID = 697862187148836038L; @Override protected void populateItem(final ListItem<String> item) { final String connectorKey = item.getModelObject(); final ListView<TopologyNode> innerListView = new ListView<TopologyNode>("resources", new ArrayList<>(connections.get(connectorKey).values())) { private static final long serialVersionUID = 1L; private final int size = getModelObject().size() + 1; @Override protected void populateItem(final ListItem<TopologyNode> item) { final TopologyNode topologynode = item.getModelObject(); final TopologyNode parent = connectors.get(connectorKey); // Set position int kx = size >= 16 ? 800 : (48 * size); int ky = size < 4 ? 100 : size < 6 ? 350 : 750; final double hpos; if (parent == null || parent.getY() < syncopeTopologyNode.getY()) { hpos = Math.PI; } else { hpos = 0.0; } int x = (int) Math.round((parent == null ? origX : parent.getX()) + kx * Math.cos(hpos + Math.PI * (item.getIndex() + 1) / size)); int y = (int) Math.round((parent == null ? origY : parent.getY()) + ky * Math.sin(hpos + Math.PI * (item.getIndex() + 1) / size)); topologynode.setX(x); topologynode.setY(y); item.add(topologyNodePanel("res", topologynode)); } }; innerListView.setOutputMarkupId(true); item.add(innerListView); } }; resources.setOutputMarkupId(true); body.add(resources); // ----------------------------------------- // ----------------------------------------- // Create connections // ----------------------------------------- final WebMarkupContainer jsPlace = new WebMarkupContainerNoVeil("jsPlace"); jsPlace.setOutputMarkupId(true); body.add(jsPlace); jsPlace.add(new Behavior() { private static final long serialVersionUID = 2661717818979056044L; @Override public void renderHead(final Component component, final IHeaderResponse response) { final StringBuilder jsPlumbConf = new StringBuilder(); jsPlumbConf.append(String.format(Locale.US, "activate(%.2f);", 0.68f)); for (String str : createConnections(connections)) { jsPlumbConf.append(str); } response.render(OnDomReadyHeaderItem.forScript(jsPlumbConf.toString())); } }); jsPlace.add(new AbstractAjaxTimerBehavior(Duration.seconds(2)) { private static final long serialVersionUID = 1L; @Override protected void onTimer(final AjaxRequestTarget target) { target.appendJavaScript("checkConnection()"); if (getUpdateInterval().seconds() < 5.0) { setUpdateInterval(Duration.seconds(5)); } else if (getUpdateInterval().seconds() < 10.0) { setUpdateInterval(Duration.seconds(10)); } else if (getUpdateInterval().seconds() < 15.0) { setUpdateInterval(Duration.seconds(15)); } else if (getUpdateInterval().seconds() < 20.0) { setUpdateInterval(Duration.seconds(20)); } else if (getUpdateInterval().seconds() < 30.0) { setUpdateInterval(Duration.seconds(30)); } else if (getUpdateInterval().seconds() < 60.0) { setUpdateInterval(Duration.seconds(60)); } } }); // ----------------------------------------- newlyCreatedContainer = new WebMarkupContainer("newlyCreatedContainer"); newlyCreatedContainer.setOutputMarkupId(true); body.add(newlyCreatedContainer); newlyCreated = new ListView<TopologyNode>("newlyCreated", new ArrayList<TopologyNode>()) { private static final long serialVersionUID = 1L; @Override protected void populateItem(final ListItem<TopologyNode> item) { item.add(topologyNodePanel("el", item.getModelObject())); } }; newlyCreated.setOutputMarkupId(true); newlyCreated.setReuseItems(true); newlyCreatedContainer.add(newlyCreated); }
From source file:org.apache.syncope.client.console.topology.Topology.java
License:Apache License
private TopologyNodePanel topologyNodePanel(final String id, final TopologyNode node) { final TopologyNodePanel panel = new TopologyNodePanel(id, node); panel.setMarkupId(String.valueOf(node.getKey())); panel.setOutputMarkupId(true);/* ww w . ja va 2s . co m*/ final List<Behavior> behaviors = new ArrayList<>(); behaviors.add(new Behavior() { private static final long serialVersionUID = 1L; @Override public void renderHead(final Component component, final IHeaderResponse response) { response.render(OnDomReadyHeaderItem.forScript( String.format("setPosition('%s', %d, %d)", node.getKey(), node.getX(), node.getY()))); } }); behaviors.add(new AjaxEventBehavior(Constants.ON_CLICK) { private static final long serialVersionUID = -9027652037484739586L; @Override protected String findIndicatorId() { return StringUtils.EMPTY; } @Override protected void onEvent(final AjaxRequestTarget target) { togglePanel.toggleWithContent(target, node); target.appendJavaScript( String.format( "$('.window').removeClass(\"active-window\").addClass(\"inactive-window\"); " + "$(document.getElementById('%s'))." + "removeClass(\"inactive-window\").addClass(\"active-window\");", node.getKey())); } }); panel.add(behaviors.toArray(new Behavior[] {})); return panel; }
From source file:org.apache.syncope.client.console.topology.TopologyTogglePanel.java
License:Apache License
private Fragment getConnectorFragment(final TopologyNode node, final PageReference pageRef) { Fragment fragment = new Fragment("actions", "connectorActions", this); AjaxLink<String> delete = new IndicatingOnConfirmAjaxLink<String>("delete", true) { private static final long serialVersionUID = 3776750333491622263L; @Override//from w w w . ja va 2 s . c o m public void onClick(final AjaxRequestTarget target) { try { connectorRestClient.delete(String.class.cast(node.getKey())); target.appendJavaScript(String.format("jsPlumb.remove('%s');", node.getKey())); SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED)); toggle(target, false); } catch (SyncopeClientException e) { LOG.error("While deleting resource {}", node.getKey(), e); SyncopeConsoleSession.get() .error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage()); } ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target); } }; MetaDataRoleAuthorizationStrategy.authorize(delete, RENDER, StandardEntitlement.CONNECTOR_DELETE); fragment.add(delete); AjaxLink<String> create = new IndicatingAjaxLink<String>("create") { private static final long serialVersionUID = 3776750333491622263L; @Override public void onClick(final AjaxRequestTarget target) { final ResourceTO modelObject = new ResourceTO(); modelObject.setConnector(String.class.cast(node.getKey())); modelObject.setConnectorDisplayName(node.getDisplayName()); final IModel<ResourceTO> model = new CompoundPropertyModel<>(modelObject); modal.setFormModel(model); target.add(modal.setContent(new ResourceWizardBuilder(modelObject, pageRef) .build(BaseModal.CONTENT_ID, AjaxWizard.Mode.CREATE))); modal.header(new Model<>(MessageFormat.format(getString("resource.new"), node.getKey()))); MetaDataRoleAuthorizationStrategy.authorize(modal.getForm(), RENDER, StandardEntitlement.RESOURCE_CREATE); modal.show(true); } }; MetaDataRoleAuthorizationStrategy.authorize(create, RENDER, StandardEntitlement.RESOURCE_CREATE); fragment.add(create); AjaxLink<String> edit = new IndicatingAjaxLink<String>("edit") { private static final long serialVersionUID = 3776750333491622263L; @Override public void onClick(final AjaxRequestTarget target) { final ConnInstanceTO modelObject = connectorRestClient.read(String.class.cast(node.getKey())); final IModel<ConnInstanceTO> model = new CompoundPropertyModel<>(modelObject); modal.setFormModel(model); target.add(modal.setContent(new ConnectorWizardBuilder(modelObject, pageRef) .build(BaseModal.CONTENT_ID, AjaxWizard.Mode.EDIT))); modal.header(new Model<>(MessageFormat.format(getString("connector.edit"), node.getDisplayName()))); MetaDataRoleAuthorizationStrategy.authorize(modal.getForm(), RENDER, StandardEntitlement.CONNECTOR_UPDATE); modal.show(true); } }; MetaDataRoleAuthorizationStrategy.authorize(edit, RENDER, StandardEntitlement.CONNECTOR_UPDATE); fragment.add(edit); return fragment; }
From source file:org.apache.syncope.client.console.topology.TopologyTogglePanel.java
License:Apache License
private Fragment getResurceFragment(final TopologyNode node, final PageReference pageRef) { Fragment fragment = new Fragment("actions", "resourceActions", this); AjaxLink<String> delete = new IndicatingOnConfirmAjaxLink<String>("delete", true) { private static final long serialVersionUID = 3776750333491622263L; @Override//ww w. j a va2s . co m public void onClick(final AjaxRequestTarget target) { try { resourceRestClient.delete(node.getKey()); target.appendJavaScript(String.format("jsPlumb.remove('%s');", node.getKey())); SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED)); toggle(target, false); } catch (SyncopeClientException e) { LOG.error("While deleting resource {}", node.getKey(), e); SyncopeConsoleSession.get() .error(StringUtils.isBlank(e.getMessage()) ? e.getClass().getName() : e.getMessage()); } ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target); } }; MetaDataRoleAuthorizationStrategy.authorize(delete, RENDER, StandardEntitlement.RESOURCE_DELETE); fragment.add(delete); AjaxLink<String> edit = new IndicatingAjaxLink<String>("edit") { private static final long serialVersionUID = 3776750333491622263L; @Override public void onClick(final AjaxRequestTarget target) { ResourceTO modelObject = resourceRestClient.read(node.getKey()); IModel<ResourceTO> model = new CompoundPropertyModel<>(modelObject); modal.setFormModel(model); target.add(modal.setContent(new ResourceWizardBuilder(modelObject, pageRef) .build(BaseModal.CONTENT_ID, AjaxWizard.Mode.EDIT))); modal.header(new Model<>(MessageFormat.format(getString("resource.edit"), node.getKey()))); MetaDataRoleAuthorizationStrategy.authorize(modal.getForm(), RENDER, StandardEntitlement.RESOURCE_UPDATE); modal.show(true); } }; MetaDataRoleAuthorizationStrategy.authorize(edit, RENDER, StandardEntitlement.RESOURCE_UPDATE); fragment.add(edit); AjaxLink<String> status = new IndicatingAjaxLink<String>("status") { private static final long serialVersionUID = 3776750333491622263L; @Override public void onClick(final AjaxRequestTarget target) { ResourceTO modelObject = resourceRestClient.read(node.getKey()); target.add(propTaskModal.setContent(new ResourceStatusModal(propTaskModal, pageRef, modelObject))); propTaskModal.header(new ResourceModel("resource.provisioning.status", "Provisioning Status")); propTaskModal.show(true); } }; MetaDataRoleAuthorizationStrategy.authorize(status, RENDER, StandardEntitlement.USER_UPDATE); fragment.add(status); AjaxLink<String> provision = new IndicatingAjaxLink<String>("provision") { private static final long serialVersionUID = 3776750333491622263L; @Override public void onClick(final AjaxRequestTarget target) { ResourceTO modelObject = resourceRestClient.read(node.getKey()); IModel<ResourceTO> model = new CompoundPropertyModel<>(modelObject); provisionModal.setFormModel(model); target.add(provisionModal .setContent(new ResourceProvisionPanel(provisionModal, modelObject, pageRef))); provisionModal.header(new Model<>(MessageFormat.format(getString("resource.edit"), node.getKey()))); MetaDataRoleAuthorizationStrategy.authorize(provisionModal.getForm(), RENDER, StandardEntitlement.RESOURCE_UPDATE); provisionModal.show(true); } }; MetaDataRoleAuthorizationStrategy.authorize(edit, RENDER, StandardEntitlement.RESOURCE_UPDATE); fragment.add(provision); AjaxLink<String> explore = new IndicatingAjaxLink<String>("explore") { private static final long serialVersionUID = 3776750333491622263L; @Override public void onClick(final AjaxRequestTarget target) { target.add(propTaskModal.setContent(new ConnObjects(propTaskModal, node.getKey(), pageRef))); propTaskModal.header(new StringResourceModel("resource.explore.list", Model.of(node))); propTaskModal.show(true); } }; MetaDataRoleAuthorizationStrategy.authorize(explore, RENDER, StandardEntitlement.RESOURCE_LIST_CONNOBJECT); fragment.add(explore); AjaxLink<String> propagation = new IndicatingAjaxLink<String>("propagation") { private static final long serialVersionUID = 3776750333491622263L; @Override @SuppressWarnings("unchecked") public void onClick(final AjaxRequestTarget target) { target.add(propTaskModal.setContent(new PropagationTasks(propTaskModal, node.getKey(), pageRef))); propTaskModal.header(new ResourceModel("task.propagation.list")); propTaskModal.show(true); } }; MetaDataRoleAuthorizationStrategy.authorize(propagation, RENDER, StandardEntitlement.TASK_LIST); fragment.add(propagation); AjaxLink<String> pull = new IndicatingAjaxLink<String>("pull") { private static final long serialVersionUID = 3776750333491622263L; @Override public void onClick(final AjaxRequestTarget target) { target.add(schedTaskModal.setContent(new PullTasks(schedTaskModal, pageRef, node.getKey()))); schedTaskModal.header(new ResourceModel("task.pull.list")); schedTaskModal.show(true); } }; MetaDataRoleAuthorizationStrategy.authorize(pull, RENDER, StandardEntitlement.TASK_LIST); fragment.add(pull); AjaxLink<String> push = new IndicatingAjaxLink<String>("push") { private static final long serialVersionUID = 3776750333491622263L; @Override public void onClick(final AjaxRequestTarget target) { target.add(schedTaskModal.setContent(new PushTasks(schedTaskModal, pageRef, node.getKey()))); schedTaskModal.header(new ResourceModel("task.push.list")); schedTaskModal.show(true); } }; MetaDataRoleAuthorizationStrategy.authorize(push, RENDER, StandardEntitlement.TASK_LIST); fragment.add(push); return fragment; }
From source file:org.apache.syncope.client.console.wicket.ajax.form.AbstractAjaxDownloadBehavior.java
License:Apache License
/** * Call this method to initiate the download. * * @param target request target./*www . j a v a2 s.c o m*/ */ public void initiate(final AjaxRequestTarget target) { CharSequence url = getCallbackUrl(); target.appendJavaScript("window.location.href='" + url + "'"); }
From source file:org.apache.syncope.client.console.wicket.markup.html.form.AjaxDownload.java
License:Apache License
public void initiate(final AjaxRequestTarget target) { String url = getCallbackUrl().toString(); if (addAntiCache) { url = url + (url.contains("?") ? "&" : "?"); url = url + "antiCache=" + System.currentTimeMillis(); }/*from w ww. j av a 2s . c om*/ target.appendJavaScript("setTimeout(\"window.location.href='" + url + "'\", 100);"); }
From source file:org.apache.syncope.console.pages.panels.NotificationPanel.java
License:Apache License
public NotificationPanel(final String id, final String additionalCSSClass, final IFeedbackMessageFilter feedbackMessageFilter) { super(id, feedbackMessageFilter); this.add(new AjaxEventBehavior(Constants.ON_CLICK) { private static final long serialVersionUID = -7133385027739964990L; @Override//from w w w. j ava2s. co m protected void onEvent(final AjaxRequestTarget target) { target.appendJavaScript("setTimeout(\"$('div#" + getMarkupId() + "').fadeOut('normal')\", 0);"); } }); this.additionalCSSClass = StringUtils.isBlank(additionalCSSClass) ? DEFAULT_ADDITIONAL_CSS_CLASS : additionalCSSClass; // set custom markup id and ouput it, to find the component later on in the js function setMarkupId(id); setOutputMarkupId(true); // Add the additional cssClass and hide the element by default add(new AttributeModifier("class", new Model<String>(CSS_CLASS + " " + this.additionalCSSClass))); add(new AttributeModifier("style", new Model<String>("opacity: 0;"))); }
From source file:org.apache.syncope.console.pages.panels.NotificationPanel.java
License:Apache License
/** * Method to refresh the notification panel. * * If there are any feedback messages for the user, find the gravest level, format the notification panel * accordingly and show it./*from w w w . j ava 2 s . c o m*/ * * @param target AjaxRequestTarget to add panel and the calling javascript function */ public void refresh(final AjaxRequestTarget target) { // any feedback at all in the current form? if (anyMessage()) { int highestFeedbackLevel = FeedbackMessage.INFO; // any feedback with the given level? if (anyMessage(FeedbackMessage.WARNING)) { highestFeedbackLevel = FeedbackMessage.WARNING; } if (anyMessage(FeedbackMessage.ERROR)) { highestFeedbackLevel = FeedbackMessage.ERROR; } // add the css classes to the notification panel, // including the border css which represents the highest level of feedback add(new AttributeModifier("class", new Model<String>( CSS_CLASS + " " + additionalCSSClass + " notificationpanel_border_" + highestFeedbackLevel))); // refresh the panel and call the js function with the panel markup id // and the total count of messages target.add(this); if (anyMessage(FeedbackMessage.ERROR)) { target.appendJavaScript("$('div#" + getMarkupId() + "').fadeTo('normal', 1.0);"); } else { target.appendJavaScript( "showNotification('" + getMarkupId() + "', " + getCurrentMessages().size() + ");"); } } }