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

The following examples show how to use org.apache.wicket.ajax.AjaxRequestTarget#appendJavaScript() . 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: SelectDialogPanel.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
private Command<ODocument> createSelectAndSearchCommand(OrienteerDataTable<ODocument, String> table, OClassSearchPanel searchPanel) {
	return new AbstractCheckBoxEnabledCommand<ODocument>(new ResourceModel("command.selectAndSearchMode"), table) {
		@Override
		protected void onInitialize() {
			super.onInitialize();
			setBootstrapType(BootstrapType.SUCCESS);
			setIcon(FAIconType.hand_o_right);
			setAutoNotify(false);
		}

		@Override
		protected void performMultiAction(AjaxRequestTarget target, List<ODocument> objects) {
			if (onSelect(target, objects, true)) {
				TextField<String> field = searchPanel.getQueryField();
				resetSelection();
				target.add(getTable());
				target.focusComponent(field);
				target.appendJavaScript(String.format("$('#%s').select()", field.getMarkupId()));
			}
		}
	};
}
 
Example 2
Source File: WidgetTabTemplate.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
private void updateData(AjaxRequestTarget target) {
	if(renderChart) {
		chartDataProvider.setReportDef(getChartReportDefinition());
		target.add(chart);
	}
	if(renderTable) {
		if(useChartReportDefinitionForTable()) {
			chartDataProvider.setReportDef(getChartReportDefinition());
		}else{
			tableDataProvider.setReportDef(getTableReportDefinition());
		}
		tableTd.remove(table);
		createTable();
		target.add(tableTd);
	}
	target.appendJavaScript("setMainFrameHeightNoScroll(window.name, 0, 300);");
}
 
Example 3
Source File: DrawerManager.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void eventPop(AbstractDrawer drawer, AjaxRequestTarget target) {
	ListItem item = null;
	ListItem lastClosed = null;

	// It's impossible for eventPop to be called with a drawer argument that's not in the stack.
	// Thus, drawers.peek() is never null. - JMMM
	do {
		item = drawers.peek();

		item.drawer.beforeClose(target);
		if (!item.drawer.isAllowClose()) {
			break;
		}

		lastClosed = drawers.pop();
		internalPop(lastClosed, target);
	} while (item.drawer != drawer);

	if ((lastClosed != null) && (lastClosed.previous != null)) {
		target.appendJavaScript("$('#"+lastClosed.previous.item.getMarkupId()+"').addClass('shown-modal');");
		target.appendJavaScript("$('#"+lastClosed.previous.item.getMarkupId()+"').removeClass('hidden-modal');");
	}
}
 
Example 4
Source File: WidgetTabTemplate.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
private void updateData(AjaxRequestTarget target) {
	if(renderChart) {
		chartDataProvider.setReportDef(getChartReportDefinition());
		target.add(chart);
	}
	if(renderTable) {
		if(useChartReportDefinitionForTable()) {
			chartDataProvider.setReportDef(getChartReportDefinition());
		}else{
			tableDataProvider.setReportDef(getTableReportDefinition());
		}
		tableTd.remove(table);
		createTable();
		target.add(tableTd);
	}
	target.appendJavaScript("setMainFrameHeightNoScroll(window.name, 0, 300);");
}
 
Example 5
Source File: TwitterPrefsPane.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Helper to switch content fragments for us
 * 
 * @param replacement	replacement Fragment
 * @param target		AjaxRequestTarget
 */
private void switchContentFragments(Fragment replacement, AjaxRequestTarget target) {
	
	replacement.setOutputMarkupId(true);
	currentFragment.replaceWith(replacement);
	if(target != null) {
		target.add(replacement);
		//resize iframe
		target.appendJavaScript("setMainFrameHeight(window.name);");
	}
	
	//must keep reference up to date
	currentFragment=replacement;
}
 
Example 6
Source File: ServerWidePage.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@SuppressWarnings("serial")
private void makeSelectorLink(final String id, final String view) {
	IndicatingAjaxLink link = new IndicatingAjaxLink(id) {
		@Override
		public void onClick(AjaxRequestTarget target) {
			// select view
			report.setSelectedView(view);
			// make title, description & notes visible
			reportTitle.add(new AttributeModifier("style", new Model("display: block")));
			reportDescription.add(new AttributeModifier("style", new Model("display: block")));
			reportNotes.add(new AttributeModifier("style", new Model("display: block")));
			reportChart.renderImage(target, true);
			// toggle selectors link state
			for(Component lbl : labels.values()) {
				lbl.setVisible(false);
			}
			for(Component lnk : links) {
				lnk.setVisible(true);
			}
			this.setVisible(false);
			labels.get(this).setVisible(true);
			// mark component for rendering
			target.add(selectors);
			target.add(reportTitle);
			target.add(reportDescription);
			target.add(reportNotes);
			target.appendJavaScript("setMainFrameHeightNoScroll( window.name, 650 )");
		}
	};
	link.setVisible(true);
	links.add(link);
	selectors.add(link);
	makeSelectorLabel(link, id + "Lbl");
}
 
Example 7
Source File: MyWallPanel.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
protected void replaceSelf(AjaxRequestTarget target, String userUuid) {
	MyWallPanel newPanel;
	if (true == sakaiProxy.isSuperUser()) {
		newPanel= new MyWallPanel(MyWallPanel.this.getId(), userUuid);
	} else {
		newPanel= new MyWallPanel(MyWallPanel.this.getId());
	}
	newPanel.setOutputMarkupId(true);
	MyWallPanel.this.replaceWith(newPanel);
	if (null != target) {
		target.add(newPanel);
		target.appendJavaScript("setMainFrameHeight(window.name);");
	}
	
}
 
Example 8
Source File: FilterPanel.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(Optional<AjaxRequestTarget> targetOptional) {
    currentTab = this;
    if(targetOptional.isPresent()) {
    	AjaxRequestTarget target = targetOptional.get();
    	panel.focus(target);
    	target.appendJavaScript(showTabJs(containerId, currentTab.getMarkupId()));
    }
}
 
Example 9
Source File: DataSourcePanel.java    From nextreports-server with Apache License 2.0 5 votes vote down vote up
private void enableComponents(AjaxRequestTarget target) {
     	boolean isJNDI = DataSource.JNDI_VENDOR.equals(template.getType());
driverLabel.setVisible(!isJNDI);
driver.setVisible(!isJNDI);
usernameLabel.setVisible(!isJNDI);
username.setVisible(!isJNDI);
passwordLabel.setVisible(!isJNDI);
password.setVisible(!isJNDI);
minPoolSizeLabel.setVisible(!isJNDI);
minPool.setVisible(!isJNDI);
maxPoolSizeLabel.setVisible(!isJNDI);
maxPool.setVisible(!isJNDI);
incPoolLabel.setVisible(!isJNDI);
incPool.setVisible(!isJNDI);
idleTimePoolLabel.setVisible(!isJNDI);
idlePool.setVisible(!isJNDI);

if (isJNDI) {
	urlLabel.setDefaultModelObject(DataSource.JNDI_VENDOR + " " + getString("ActionContributor.DataSource.name") + " *");
} else {
	urlLabel.setDefaultModelObject(getString("ActionContributor.DataSource.url") + " *");
}

if (target != null) {
	target.appendJavaScript(getJavascriptCall());
}
     }
 
Example 10
Source File: SearchResultPanel.java    From onedev with MIT License 5 votes vote down vote up
@SuppressWarnings("deprecation")
private void onActiveIndexChange(AjaxRequestTarget target) {
	Component hitsContainer = blobsView.get(activeBlobIndex).get(HITS_ID);
	if (!hitsContainer.isVisibilityAllowed()) {
		hitsContainer.setVisibilityAllowed(true);
		target.add(hitsContainer);
		target.add(blobsView.get(activeBlobIndex).get(EXPAND_LINK_ID));
	} 

	String activeLinkId = getMarkupId() + "-" + activeBlobIndex; 
	if (activeHitIndex != -1)
		activeLinkId += "-" + activeHitIndex;

	String script = String.format(""
			+ "$('#%s').find('.selectable').removeClass('active');"
			+ "$('#%s').addClass('active');"
			+ "$('#%s>.search-result>.body a.selectable.active').scrollIntoView(25);", 
			getMarkupId(), activeLinkId, getMarkupId());
	target.appendJavaScript(script);
	
	target.add(prevMatchLink);
	target.add(nextMatchLink);
	
	MatchedBlob activeBlob = blobs.get(activeBlobIndex);
	
	QueryHit hit;
	if (activeHitIndex != -1)
		hit = activeBlob.getHits().get(activeHitIndex);
	else 
		hit = new FileHit(activeBlob.getBlobPath(), null);
	
	BlobIdent selected = new BlobIdent(context.getBlobIdent().revision, hit.getBlobPath(), 
			FileMode.REGULAR_FILE.getBits());
	context.onSelect(target, selected, SourceRendererProvider.getPosition(hit.getTokenPos()));
}
 
Example 11
Source File: SortBehavior.java    From onedev with MIT License 5 votes vote down vote up
@Override
protected void respond(AjaxRequestTarget target) {
	int fromList = RequestCycle.get().getRequest().getPostParameters()
			.getParameterValue("fromList").toInt();
	int fromItem = RequestCycle.get().getRequest().getPostParameters()
			.getParameterValue("fromItem").toInt();
	int toList = RequestCycle.get().getRequest().getPostParameters()
			.getParameterValue("toList").toInt();
	int toItem = RequestCycle.get().getRequest().getPostParameters()
			.getParameterValue("toItem").toInt();
	if (fromList != toList || fromItem != toItem) {
		onSort(target, new SortPosition(fromList, fromItem), new SortPosition(toList, toItem));
		String script = String.format("onedev.server.form.markDirty($('#%s').closest('form.leave-confirm'));", 
				getComponent().getMarkupId(true));
		target.appendJavaScript(script);
		
		for (Component each: target.getComponents()) {
			if (each == getComponent()) {
				target.appendJavaScript(getSortScript());
				break;
			}
			if (each instanceof MarkupContainer) {
				MarkupContainer container = (MarkupContainer) each;
				if (container.contains(getComponent(), true)) {
					target.appendJavaScript(getSortScript());
					break;
				}
			}
		}
	}
}
 
Example 12
Source File: MyNamePronunciationDisplay.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public MyNamePronunciationDisplay(final String id, final UserProfile userProfile) {
    super(id);

    log.debug("MyNamePronunciationDisplay()");

    final Component thisPanel = this;
    this.userProfile = userProfile;

    //heading
    add(new Label("heading", new ResourceModel("heading.name.pronunciation")));

    addPhoneticPronunciation();
    addNameRecord();

    AjaxFallbackLink editButton = new AjaxFallbackLink("editButton", new ResourceModel("button.edit")) {
        public void onClick(AjaxRequestTarget target) {
            Component newPanel = new MyNamePronunciationEdit(id, userProfile);
            newPanel.setOutputMarkupId(true);
            thisPanel.replaceWith(newPanel);
            if(target != null) {
                target.add(newPanel);
                target.appendJavaScript("setMainFrameHeight(window.name);");
            }
        }
    };
    editButton.add(new Label("editButtonLabel", new ResourceModel("button.edit")));
    editButton.setOutputMarkupId(true);
    if(userProfile.isLocked() && !sakaiProxy.isSuperUser()) {
        editButton.setVisible(false);
    }
    add(editButton);

    //no fields message
    Label noFieldsMessage = new Label("noFieldsMessage", new ResourceModel("text.no.fields"));
    add(noFieldsMessage);
    if(visibleFieldCount > 0) {
        noFieldsMessage.setVisible(false);
    }
}
 
Example 13
Source File: LoginModalPanel.java    From AppStash with Apache License 2.0 5 votes vote down vote up
private AjaxLink<Void> closeLink(String id) {
    return new AjaxLink<Void>(id) {
        @Override
        public void onClick(AjaxRequestTarget target) {
            target.appendJavaScript(generateToggleScript());
        }
    };
}
 
Example 14
Source File: GeneralErrorPage.java    From onedev with MIT License 4 votes vote down vote up
@Override
protected void onPopState(AjaxRequestTarget target, Serializable data) {
	super.onPopState(target, data);
	target.appendJavaScript("location.reload();");
}
 
Example 15
Source File: ConfirmBehavior.java    From onedev with MIT License 4 votes vote down vote up
public void confirm(AjaxRequestTarget target, String message) {
	target.appendJavaScript(String.format("if (confirm('%s')) {%s}", 
			JavaScriptEscape.escapeJavaScript(message), getCallbackScript()));
	target.appendJavaScript(getCallbackScript());
}
 
Example 16
Source File: AdministratePage.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public AdministratePage(){
	disableLink(administrateLink);
	
	//Form Feedback (Saved/Error)
	final Label formFeedback = new Label("formFeedback");
	formFeedback.setOutputMarkupPlaceholderTag(true);
	final String formFeedbackId = formFeedback.getMarkupId();
	add(formFeedback);
	
	//Add Delegated Access to My Workspaces:
	final Label addDaMyworkspaceStatusLabel = new Label("lastRanInfo", new AbstractReadOnlyModel<String>() {
		@Override
		public String getObject() {
			String lastRanInfoStr = projectLogic.getAddDAMyworkspaceJobStatus();
			if(lastRanInfoStr == null){
				lastRanInfoStr = new ResourceModel("addDaMyworkspace.job.status.none").getObject();
			}else{
				try{
					long lastRanInfoInt = Long.parseLong(lastRanInfoStr);
					if(lastRanInfoInt == -1){
						return new ResourceModel("addDaMyworkspace.job.status.failed").getObject();
					}else if(lastRanInfoInt == 0){
						return new ResourceModel("addDaMyworkspace.job.status.scheduled").getObject();
					}else{
						Date successDate = new Date(lastRanInfoInt);
						return new ResourceModel("addDaMyworkspace.job.status.success").getObject() + " " + format.format(successDate);
					}
				}catch (Exception e) {
					return new ResourceModel("na").getObject();
				}
			}
			return lastRanInfoStr;
		}
	});
	addDaMyworkspaceStatusLabel.setOutputMarkupPlaceholderTag(true);
	final String addDaMyworkspaceStatusLabelId = addDaMyworkspaceStatusLabel.getMarkupId();
	
	add(addDaMyworkspaceStatusLabel);
	
	Form<?> addDaMyworkspaceForm = new Form("addDaMyworkspaceForm");
	
	AjaxButton addDaMyworkspaceButton = new AjaxButton("addDaMyworkspace", new StringResourceModel("addDaMyworkspaceTitle", null)){
		@Override
		protected void onSubmit(AjaxRequestTarget target, Form<?> arg1) {
			projectLogic.scheduleAddDAMyworkspaceJobStatus();
			
			//display a "saved" message
			formFeedback.setDefaultModel(new ResourceModel("success.addDaMyworkspace"));
			formFeedback.add(new AttributeModifier("class", true, new Model("success")));
			target.add(formFeedback);
			
			target.appendJavaScript("hideFeedbackTimer('" + formFeedbackId + "');");
			
			target.add(addDaMyworkspaceStatusLabel,addDaMyworkspaceStatusLabelId);
		}
	};
	addDaMyworkspaceForm.add(addDaMyworkspaceButton);
	
	add(addDaMyworkspaceForm);
}
 
Example 17
Source File: ExcuseGradeAction.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
@Override
public ActionResponse handleEvent(final JsonNode params, final AjaxRequestTarget target) {
    final GradebookPage page = (GradebookPage) target.getPage();

    target.addChildren(page, FeedbackPanel.class);

    final String assignmentId = params.get("assignmentId").asText();
    final String studentUuid = params.get("studentId").asText();
    String excuse = params.get("excuseBit").asText();
    final String categoryId = params.has("categoryId") ? params.get("categoryId").asText() : null;

    boolean hasExcuse = false;
    if (StringUtils.equals(excuse, "1")) {
        excuse = "0";
    } else if (StringUtils.equals(excuse, "0")) {
        excuse = "1";
        hasExcuse = true;
    }

    final GradeSaveResponse result = businessService.saveExcuse(Long.valueOf(assignmentId),
            studentUuid, hasExcuse);

    if (result.equals(GradeSaveResponse.NO_CHANGE)) {
        target.add(page.updateLiveGradingMessage(page.getString("feedback.saved")));
    }

    target.appendJavaScript(
            String.format("GbGradeTable.updateExcuse('%s', '%s', '%s');", assignmentId, studentUuid, excuse));


    final CourseGrade studentCourseGrade = businessService.getCourseGrade(studentUuid);

    boolean isOverride = false;
    String grade = getGrade(studentCourseGrade, page);
    String points = "0";

    if (studentCourseGrade != null) {
        if (studentCourseGrade.getPointsEarned() != null) {
            points = FormatHelper.formatDoubleToDecimal(studentCourseGrade.getPointsEarned());
        }
        if (studentCourseGrade.getEnteredGrade() != null) {
            isOverride = true;
        }
    }

    String categoryScore = getCategoryScore(categoryId, studentUuid);
    List<Long> droppedItems = getDroppedItems(categoryId, studentUuid);
    target.add(page.updateLiveGradingMessage(page.getString("feedback.saved")));

    return new ExcuseGradeAction.ExcuseGradeResponse(
            grade,
            points,
            isOverride,
            categoryScore,
            droppedItems);
}
 
Example 18
Source File: SchemaOClassesModalPanel.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
private void executeCallback(AjaxRequestTarget target, String json) {
    target.appendJavaScript(String.format(OArchitectJsUtils.callback(), json));
}
 
Example 19
Source File: AnnotationPage.java    From webanno with Apache License 2.0 4 votes vote down vote up
@Override
public void onTargetRespond(AjaxRequestTarget aTarget)
{
    AnnotatorState state = getModelObject();
    
    if (state.getDocument() == null) {
        return;
    }
    
    Long currentProjectId = state.getDocument().getProject().getId();
    Long currentDocumentId = state.getDocument().getId();
    int currentFocusUnitIndex = state.getFocusUnitIndex();
    
    // Check if the relevant parameters have actually changed since the URL parameters were
    // last set - if this is not the case, then let's not set the parameters because that
    // triggers another AJAX request telling us that the parameters were updated (stupid,
    // right?)
    if (
            Objects.equals(urlFragmentLastProjectId, currentProjectId) &&
            Objects.equals(urlFragmentLastDocumentId, currentDocumentId) &&
            urlFragmentLastFocusUnitIndex == currentFocusUnitIndex
    ) {
        return;
    }
    
    UrlFragment fragment = new UrlFragment(aTarget);

    fragment.putParameter(PAGE_PARAM_PROJECT_ID, currentProjectId);
    fragment.putParameter(PAGE_PARAM_DOCUMENT_ID, currentDocumentId);
    if (state.getFocusUnitIndex() > 0) {
        fragment.putParameter(PAGE_PARAM_FOCUS, currentFocusUnitIndex);
    }
    else {
        fragment.removeParameter(PAGE_PARAM_FOCUS);
    }

    urlFragmentLastProjectId = currentProjectId;
    urlFragmentLastDocumentId = currentDocumentId;
    urlFragmentLastFocusUnitIndex = currentFocusUnitIndex;
    
    // If we do not manually set editedFragment to false, then changing the URL
    // manually or using the back/forward buttons in the browser only works every
    // second time. Might be a bug in wicketstuff urlfragment... not sure.
    aTarget.appendJavaScript(
            "try{if(window.UrlUtil){window.UrlUtil.editedFragment = false;}}catch(e){}");

}
 
Example 20
Source File: AjaxDownloadBehavior.java    From syncope with Apache License 2.0 2 votes vote down vote up
/**
 * Call this method to initiate the download.
 *
 * @param target request target.
 */
public void initiate(final AjaxRequestTarget target) {
    CharSequence url = getCallbackUrl();
    target.appendJavaScript("window.location.href='" + url + "'");
}