Java Code Examples for org.apache.wicket.ajax.AjaxRequestTarget#prependJavaScript()

The following examples show how to use org.apache.wicket.ajax.AjaxRequestTarget#prependJavaScript() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HtmlAnnotationEditor.java    From inception with Apache License 2.0 6 votes vote down vote up
private void create(AjaxRequestTarget aTarget, String payload)
    throws JsonParseException, JsonMappingException, IOException
{
    Annotation anno = JSONUtil.getObjectMapper().readValue(payload,
            Annotation.class);

    if (anno.getRanges().isEmpty()) {
        // Spurious creation event that is to be ignored.
        return;
    }

    String json = toJson(anno);
    // Since we cannot pass the JSON directly to Brat, we attach it to the HTML
    // element into which AnnotatorJS governs. In our modified annotator-full.js, we pick it
    // up from there and then pass it on to AnnotatorJS to do the rendering.
    aTarget.prependJavaScript("Wicket.$('" + vis.getMarkupId() + "').temp = " + json + ";");
}
 
Example 2
Source File: FloatingPanel.java    From onedev with MIT License 6 votes vote down vote up
public FloatingPanel(AjaxRequestTarget target, @Nullable Alignment alignment, 
		@Nullable Animation animation) {
	super(((BasePage)target.getPage()).getRootComponents().newChildId());
	
	this.alignment = alignment;
	this.animation = animation;
	
	BasePage page = (BasePage) target.getPage(); 
	page.getRootComponents().add(this);
	
	String script = String.format("$('body').append(\"<div id='%s'></div>\");", 
			getMarkupId());
	target.prependJavaScript(script);
	
	if (animation != null)
		add(new DisplayNoneBehavior());
	target.add(this);

	if (animation != null) {
		script = String.format("$('#%s').show('slide', {direction: '%s'}, 200);", 
				getMarkupId(true), animation.name().toLowerCase());	
		target.appendJavaScript(script);
	}
}
 
Example 3
Source File: AbstractSelect2Choice.java    From onedev with MIT License 6 votes vote down vote up
@Override
public void onEvent(IEvent<?> event) {
	super.onEvent(event);

	if (event.getPayload() instanceof AjaxRequestTarget) {

		AjaxRequestTarget target = (AjaxRequestTarget) event.getPayload();

		if (target.getComponents().contains(this)) {

			// if this component is being repainted by ajax, directly, we
			// must destroy Select2 so it removes
			// its elements from DOM

			target.prependJavaScript(JQuery.execute("$('#%s').select2('destroy');", getJquerySafeMarkupId()));
		}
	}
}
 
Example 4
Source File: BuildSpecEditPanel.java    From onedev with MIT License 6 votes vote down vote up
private void addJob(AjaxRequestTarget target, Job job) {
	Component nav = newJobNav(job);
	String script = String.format("$('.build-spec>.valid>.body>.jobs>.side>.navs').append(\"<div id='%s'></div>\");", 
			nav.getMarkupId());
	target.prependJavaScript(script);
	target.add(nav);

	Component content = newJobContent(job);
	script = String.format("$('.build-spec>.valid>.body>.jobs>.contents').append(\"<div id='%s'></div>\");", 
			content.getMarkupId());
	target.prependJavaScript(script);
	target.add(content);
	
	script = String.format(""
			+ "onedev.server.buildSpec.showJob(%d); "
			+ "$('#%s .select').mouseup(onedev.server.buildSpec.selectJob);" 
			+ "$('#%s .delete').mouseup(onedev.server.buildSpec.deleteJob);", 
			jobNavs.size() - 1, nav.getMarkupId(), nav.getMarkupId());
	target.appendJavaScript(script);
}
 
Example 5
Source File: GetOClassesBehavior.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
@Override
protected void respond(AjaxRequestTarget target) {
    IRequestParameters params = RequestCycle.get().getRequest().getRequestParameters();
    String json = params.getParameterValue(EXISTS_CLASSES_VAR).toString("[]");
    boolean classesList = params.getParameterValue(CLASSES_LIST_VAR).toBoolean(false);
    if (classesList) {
        target.appendJavaScript(String.format("app.executeCallback('%s');", getAllClassesAsJson()));
    } else {
        target.prependJavaScript(OArchitectJsUtils.switchPageScroll(true));
        widget.onModalWindowEvent(
                new OpenModalWindowEvent(
                        target,
                        createModalWindowTitle(),
                        id -> createPanel(id, new ListModel<>(JsonUtil.fromJSON(json)))
                )
        );
    }
}
 
Example 6
Source File: ApplyEditorChangesBehavior.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
@Override
protected void respond(AjaxRequestTarget target) {
    if (actionActive)
        return;
    actionActive = true;
    IRequestParameters params = RequestCycle.get().getRequest().getRequestParameters();
    String json = params.getParameterValue(JSON_VAR).toString("[]");
    List<OArchitectOClass> classes;
    classes = JsonUtil.fromJSON(json);
    try {
        addClassesToSchema(classes);
        target.prependJavaScript("app.executeCallback({apply: true}); " +
                "app.checksAboutClassesChanges(function() {app.saveEditorConfig(mxUtils.getXml(OArchitectUtil.getEditorXmlNode(app.editor.graph)),null);}); ");
    } catch (Exception ex) {
        LOG.error("Can't apply editor changes: ", ex);
        target.prependJavaScript("app.executeCallback({apply: false});");
    }
    actionActive = false;
}
 
Example 7
Source File: HtmlAnnotationEditor.java    From inception with Apache License 2.0 5 votes vote down vote up
private void read(AjaxRequestTarget aTarget)
    throws JsonParseException, JsonMappingException, IOException
{
    AnnotatorState aState = getModelObject();
    CAS cas = getCasProvider().get();

    VDocument vdoc = new VDocument();
    preRenderer.render(vdoc, aState.getWindowBeginOffset(), aState.getWindowEndOffset(),
            cas, getLayersToRender());

    List<Annotation> annotations = new ArrayList<>();

    // Render visible (custom) layers
    // Map<String[], Queue<String>> colorQueues = new HashMap<>();
    for (AnnotationLayer layer : vdoc.getAnnotationLayers()) {
        // ColoringStrategy coloringStrategy = ColoringStrategy.getBestStrategy(
        // annotationService, layer, aState.getPreferences(), colorQueues);

        TypeAdapter typeAdapter = annotationService.getAdapter(layer);

        for (VSpan vspan : vdoc.spans(layer.getId())) {
            String bratLabelText = getUiLabelText(typeAdapter, vspan);

            Annotation anno = new Annotation();
            anno.setId(vspan.getVid().toString());
            anno.setText(bratLabelText);
            // Looks like the "quote" is not really required for AnnotatorJS to render the
            // annotation.
            anno.setQuote("");
            anno.setRanges(toRanges(vspan.getRanges()));
            annotations.add(anno);
        }
    }

    String json = toJson(annotations);
    // Since we cannot pass the JSON directly to Brat, we attach it to the HTML
    // element into which AnnotatorJS governs. In our modified annotator-full.js, we pick it
    // up from there and then pass it on to AnnotatorJS to do the rendering.
    aTarget.prependJavaScript("Wicket.$('" + vis.getMarkupId() + "').temp = " + json + ";");
}
 
Example 8
Source File: GridsterDashboardSupport.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Override
public void ajaxDeleteWidget(AbstractWidget<?> widget, AjaxRequestTarget target) {
	DashboardPanel<?> dashboard = widget.getDashboardPanel();
	target.prependJavaScript("var gridster = $('#"+dashboard.getMarkupId()+" > ul').data('gridster');\n"
					+ "gridster.remove_widget($('#"+widget.getMarkupId()+"'));\n"
					+ "gridster.gridsterChanged();");
}
 
Example 9
Source File: GridsterDashboardSupport.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Override
public void ajaxAddWidget(AbstractWidget<?> widget, AjaxRequestTarget target) {
	DashboardPanel<?> dashboard = widget.getDashboardPanel();
	target.prependJavaScript("$('#"+dashboard.getMarkupId()+" > ul').append('<li id=\\'"+widget.getMarkupId()+"\\'></li>')");
	target.add(widget);
	target.appendJavaScript("var gridster = $('#"+dashboard.getMarkupId()+" > ul').data('gridster');\n"
			+ "gridster.add_widget($('#"+widget.getMarkupId()+"'));\n"
			+ "gridster.gridsterChanged();");
}
 
Example 10
Source File: CollectionInputPanel.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
private void saveInput(AjaxRequestTarget target, List<CollectionInputPanel<T>> components) {
    List<String> ids = Lists.newArrayList();
    for (CollectionInputPanel<T> panel : components) {
        ids.addAll(panel.getInputIds());
    }
    target.prependJavaScript(String.format("saveInput('%s', %s);", parent.getContainerId(),
            new JSONArray(ids).toString()));
}
 
Example 11
Source File: GenerateJavaSourcesBehavior.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Override
protected void respond(AjaxRequestTarget target) {
    IRequestParameters params = RequestCycle.get().getRequest().getRequestParameters();
    String json = params.getParameterValue(JSON_VAR).toString("[]");
    target.prependJavaScript(OArchitectJsUtils.switchPageScroll(true));
    widget.onModalWindowEvent(
            new OpenModalWindowEvent(
                    target,
                    new ResourceModel("widget.architect.editor.java.sources"),
                    id -> new JavaSourcesPanel(id, new ListModel<>(JsonUtil.fromJSON(json)))
            )
    );
}
 
Example 12
Source File: PropertyEditor.java    From onedev with MIT License 5 votes vote down vote up
protected void markFormDirty(AjaxRequestTarget target) {
	String script = String.format(""
			+ "var $form = $('#%s').closest('form');"
			+ "if ($form.closest('.blob-edit').length == 0)"
			+ "  onedev.server.form.markDirty($form);", 
			getMarkupId());
	target.prependJavaScript(script);
}
 
Example 13
Source File: RunTaskBehavior.java    From onedev with MIT License 5 votes vote down vote up
@Override
protected void respond(AjaxRequestTarget target) {
	target.prependJavaScript(String.format(""
			+ "var $button = $('#%s');"
			+ "if ($button.length != 0) {"
			+ "$button.removeAttr('disabled');"
			+ "$button.val($button[0].prevValue);"
			+ "$button.html($button[0].prevHtml);"
			+ "}",
			getComponent().getMarkupId()));
	runTask(target);
}
 
Example 14
Source File: JQueryDashboardSupport.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
@Override
public void ajaxAddWidget(AbstractWidget<?> widget, AjaxRequestTarget target) {
	DashboardPanel<?> dashboard = widget.getDashboardPanel();
	target.prependJavaScript("$('#"+dashboard.getMarkupId()+" > ul').append('<li id=\\'"+widget.getMarkupId()+"\\'></li>')");
	target.add(widget);
}
 
Example 15
Source File: JQueryDashboardSupport.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
@Override
public void ajaxDeleteWidget(AbstractWidget<?> widget,
		AjaxRequestTarget target) {
	target.prependJavaScript("$('#"+widget.getMarkupId()+"').remove();");
}
 
Example 16
Source File: AbstractAjaxCallbackWithClientsideRevert.java    From projectforge-webapp with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected final void respond(AjaxRequestTarget target) {
	boolean result = onEvent(target);
	target.prependJavaScript(String.format("$.data(document, '%s', %s);", uuid, String.valueOf(result)));
}
 
Example 17
Source File: BootstrapModal.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Hide the modal. Just sends the javascript to close the modal
 *
 * @param target the AjaxRequestTarget
 */
public void hide(AjaxRequestTarget target){
	target.prependJavaScript("$('#"+getMarkupId()+"').modal('hide');");
}