List of usage examples for org.apache.wicket.ajax AjaxRequestTarget getPage
@Override Page getPage();
From source file:org.sakaiproject.delegatedaccess.tool.pages.EditablePanelDate.java
License:Educational Community License
public EditablePanelDate(String id, IModel inputModel, final NodeModel nodeModel, final TreeNode node, final boolean startDate) { super(id);/*from w w w.j av a 2 s .c o m*/ final DateTextField date = new DateTextField("dateTextField", inputModel, format.toPattern()) { @Override public boolean isVisible() { return nodeModel.isDirectAccess() && nodeModel.getNodeShoppingPeriodAdmin(); } @Override protected void onComponentTag(ComponentTag tag) { super.onComponentTag(tag); tag.append("size", "8", ""); tag.append("readonly", "readonly", ""); tag.append("class", "formInputField", " "); tag.append("class", "datePicker", " "); } }; date.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { DateTextField newDate = date; if (startDate) { nodeModel.setShoppingPeriodStartDate(date.getModelObject()); } else { nodeModel.setShoppingPeriodEndDate(date.getModelObject()); } //In order for the models to refresh, you have to call "expand" or "collapse" then "updateTree", //since I don't want to expand or collapse, I just call whichever one the node is already //Refreshing the tree will update all the models and information (like role) will be generated onClick if (((BaseTreePage) target.getPage()).getTree().getTreeState().isNodeExpanded(node)) { ((BaseTreePage) target.getPage()).getTree().getTreeState().expandNode(node); } else { ((BaseTreePage) target.getPage()).getTree().getTreeState().collapseNode(node); } ((BaseTreePage) target.getPage()).getTree().updateTree(target); } }); add(date); }
From source file:org.sakaiproject.delegatedaccess.tool.pages.EditablePanelDropdown.java
License:Educational Community License
public EditablePanelDropdown(String id, IModel inputModel, final NodeModel nodeModel, final TreeNode node, final Map<String, String> roleMap, final int type, String[] subAdminRoles) { super(id);/*w w w . ja v a 2s . com*/ this.nodeModel = nodeModel; this.node = node; SelectOption[] options = new SelectOption[roleMap.size()]; int i = 0; //now sort the map List<String> sortList = new ArrayList<String>(roleMap.values()); Collections.sort(sortList, new Comparator<String>() { public int compare(String o1, String o2) { return o1.compareToIgnoreCase(o2); } }); Map<String, String> sortedReturnMap = new HashMap<String, String>(); for (String value : sortList) { for (Entry<String, String> entry : roleMap.entrySet()) { if (value.equals(entry.getValue())) { options[i] = new SelectOption(entry.getValue(), entry.getKey()); if (entry.getKey().equals(nodeModel.getRealm() + ":" + nodeModel.getRole())) { nodeModel.setRoleOption(options[i]); } i++; break; } } } //sub admins should only be able to update up to their level granted to them List<String> restrictedRoles = new ArrayList<String>(); if (subAdminRoles != null) { //this is a node where we need to restrict based on the sub admin's role String[] realmRole = null; if (nodeModel.getNodeSubAdminSiteAccess() != null) { realmRole = nodeModel.getNodeSubAdminSiteAccess(); } String subAdminRole = ""; if (realmRole != null && realmRole.length == 2 && !"".equals(realmRole[0]) && !"".equals(realmRole[1])) { subAdminRole = realmRole[0] + ":" + realmRole[1]; } for (String level : subAdminRoles) { //each level consists of "realm:role;realm:role;..." String[] splitRoles = level.split(";"); boolean foundRole = false; for (String levelRole : splitRoles) { if (!"".equals(subAdminRole) && subAdminRole.equals(levelRole)) { foundRole = true; break; } } if (foundRole) { break; } else { restrictedRoles.addAll(Arrays.asList(splitRoles)); } } } final List<String> restrictedRolesFinal = restrictedRoles; ChoiceRenderer choiceRenderer = new ChoiceRenderer("label", "value"); final DropDownChoice choice = new DropDownChoice("roleChoices", inputModel, Arrays.asList(options), choiceRenderer) { @Override public boolean isVisible() { if (DelegatedAccessConstants.TYPE_ACCESS_SHOPPING_PERIOD_USER == type) { return nodeModel.isDirectAccess() && nodeModel.getNodeShoppingPeriodAdmin(); } else { return nodeModel.isDirectAccess(); } } @Override protected boolean isDisabled(Object object, int index, String selected) { for (String role : restrictedRolesFinal) { if (role.equals(((SelectOption) object).getValue())) { return true; } } return super.isDisabled(object, index, selected); } }; choice.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { String value = ((SelectOption) choice.getModelObject()).getValue(); String[] realmRoleSplit = value.split(":"); if (realmRoleSplit.length == 2) { nodeModel.setRealm(realmRoleSplit[0]); nodeModel.setRole(realmRoleSplit[1]); } //In order for the models to refresh, you have to call "expand" or "collapse" then "updateTree", //since I don't want to expand or collapse, I just call whichever one the node is already //Refreshing the tree will update all the models and information (like role) will be generated onClick if (((BaseTreePage) target.getPage()).getTree().getTreeState().isNodeExpanded(node)) { ((BaseTreePage) target.getPage()).getTree().getTreeState().expandNode(node); } else { ((BaseTreePage) target.getPage()).getTree().getTreeState().collapseNode(node); } ((BaseTreePage) target.getPage()).getTree().updateTree(target); } }); add(choice); }
From source file:org.sakaiproject.delegatedaccess.tool.pages.EditablePanelList.java
License:Educational Community License
public EditablePanelList(String id, IModel inputModel, final NodeModel nodeModel, final TreeNode node, final int userType, final int fieldType) { super(id);/*from w w w .java 2 s . co m*/ this.nodeModel = nodeModel; this.node = node; final WebMarkupContainer editableSpan = new WebMarkupContainer("editableSpan"); editableSpan.setOutputMarkupId(true); final String editableSpanId = editableSpan.getMarkupId(); add(editableSpan); AjaxLink<Void> saveEditableSpanLink = new AjaxLink<Void>("saveEditableSpanLink") { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { target.appendJavascript("document.getElementById('" + editableSpanId + "').style.display='none';"); //In order for the models to refresh, you have to call "expand" or "collapse" then "updateTree", //since I don't want to expand or collapse, I just call whichever one the node is already //Refreshing the tree will update all the models and information (like role) will be generated onClick if (((BaseTreePage) target.getPage()).getTree().getTreeState().isNodeExpanded(node)) { ((BaseTreePage) target.getPage()).getTree().getTreeState().expandNode(node); } else { ((BaseTreePage) target.getPage()).getTree().getTreeState().collapseNode(node); } ((BaseTreePage) target.getPage()).getTree().updateTree(target); } }; editableSpan.add(saveEditableSpanLink); Label editableSpanLabel = new Label("editableNodeTitle", nodeModel.getNode().title); editableSpan.add(editableSpanLabel); WebMarkupContainer toolTableHeader = new WebMarkupContainer("toolTableHeader") { @Override public boolean isVisible() { return DelegatedAccessConstants.TYPE_ACCESS_SHOPPING_PERIOD_USER == userType; } }; editableSpan.add(toolTableHeader); List<ListOptionSerialized[]> listOptions = new ArrayList<ListOptionSerialized[]>(); final ListView<ListOptionSerialized[]> listView = new ListView<ListOptionSerialized[]>("list", listOptions) { private static final long serialVersionUID = 1L; @Override protected void populateItem(ListItem<ListOptionSerialized[]> item) { ListOptionSerialized wrapper = item.getModelObject()[0]; item.add(new Label("name", wrapper.getName())); //Auth Checkbox: final CheckBox checkBox = new CheckBox("authCheck", new PropertyModel(wrapper, "selected")); checkBox.setOutputMarkupId(true); checkBox.setOutputMarkupPlaceholderTag(true); final String checkBoxId = checkBox.getMarkupId(); final String toolId = wrapper.getId(); checkBox.add(new AjaxFormComponentUpdatingBehavior("onClick") { protected void onUpdate(AjaxRequestTarget target) { if (DelegatedAccessConstants.TYPE_LISTFIELD_TOOLS == fieldType) { nodeModel.setAuthToolRestricted(toolId, isChecked()); } } private boolean isChecked() { final String value = checkBox.getValue(); if (value != null) { try { return Strings.isTrue(value); } catch (Exception e) { return false; } } return false; } }); item.add(checkBox); if (nodeModel.isPublicToolRestricted(toolId) && !nodeModel.isAuthToolRestricted(toolId)) { //disable the auth option because public is already selected (only disable if it's not already selected) checkBox.setEnabled(false); } //Public Checkbox: ListOptionSerialized publicWrapper = item.getModelObject()[1]; final CheckBox publicCheckBox = new CheckBox("publicCheck", new PropertyModel(publicWrapper, "selected")) { @Override public boolean isVisible() { return DelegatedAccessConstants.TYPE_ACCESS_SHOPPING_PERIOD_USER == userType; } }; publicCheckBox.setOutputMarkupId(true); final String publicToolId = publicWrapper.getId(); publicCheckBox.add(new AjaxFormComponentUpdatingBehavior("onClick") { protected void onUpdate(AjaxRequestTarget target) { boolean checked = isPublicChecked(); if (DelegatedAccessConstants.TYPE_LISTFIELD_TOOLS == fieldType) { nodeModel.setPublicToolRestricted(publicToolId, checked); } if (checked) { //if public is checked, we don't need the "auth" checkbox enabled (or selected). Disabled and De-select it checkBox.setModelValue(new String[] { "false" }); checkBox.setEnabled(false); if (DelegatedAccessConstants.TYPE_LISTFIELD_TOOLS == fieldType) { nodeModel.setAuthToolRestricted(toolId, false); } } else { checkBox.setEnabled(true); } target.addComponent(checkBox, checkBoxId); } private boolean isPublicChecked() { final String value = publicCheckBox.getValue(); if (value != null) { try { return Strings.isTrue(value); } catch (Exception e) { return false; } } return false; } }); item.add(publicCheckBox); } }; editableSpan.add(listView); AjaxLink<Void> restrictToolsLink = new AjaxLink<Void>("restrictToolsLink") { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { if (!loadedFlag) { loadedFlag = true; List<ListOptionSerialized[]> listOptions = null; if (DelegatedAccessConstants.TYPE_LISTFIELD_TOOLS == fieldType) { listOptions = getNodeModelToolsList(nodeModel); } listView.setDefaultModelObject(listOptions); target.addComponent(editableSpan); } target.appendJavascript("document.getElementById('" + editableSpanId + "').style.display='';"); } }; add(restrictToolsLink); add(new WebComponent("noToolsSelectedWarning") { @Override public boolean isVisible() { return DelegatedAccessConstants.TYPE_ACCESS_SHOPPING_PERIOD_USER == userType && nodeModel.getSelectedRestrictedAuthTools().isEmpty() && nodeModel.getSelectedRestrictedPublicTools().isEmpty(); } @Override protected void onComponentTag(ComponentTag tag) { super.onComponentTag(tag); tag.put("title", new ResourceModel("noToolsSelected").getObject()); } }); Label restrictToolsLinkLabel = new Label("restrictToolsSpan"); if (DelegatedAccessConstants.TYPE_LISTFIELD_TOOLS == fieldType) { if (DelegatedAccessConstants.TYPE_ACCESS_SHOPPING_PERIOD_USER == userType) { restrictToolsLinkLabel.setDefaultModel(new StringResourceModel("showToolsHeader", null)); } else { restrictToolsLinkLabel.setDefaultModel(new StringResourceModel("restrictedToolsHeader", null)); } } restrictToolsLink.add(restrictToolsLinkLabel); Label editToolsTitle = new Label("editToolsTitle"); if (DelegatedAccessConstants.TYPE_LISTFIELD_TOOLS == fieldType) { if (DelegatedAccessConstants.TYPE_ACCESS_SHOPPING_PERIOD_USER == userType) { editToolsTitle.setDefaultModel(new StringResourceModel("editableShowToolsTitle", null)); } else { editToolsTitle.setDefaultModel(new StringResourceModel("editableRestrictedToolsTitle", null)); } } editableSpan.add(editToolsTitle); Label editToolsInstructions = new Label("editToolsInstructions"); if (DelegatedAccessConstants.TYPE_LISTFIELD_TOOLS == fieldType) { if (DelegatedAccessConstants.TYPE_ACCESS_SHOPPING_PERIOD_USER == userType) { editToolsInstructions .setDefaultModel(new StringResourceModel("editableShowToolsDescription", null)); } else { editToolsInstructions .setDefaultModel(new StringResourceModel("editableRestrictedToolsDescription", null)); } } editableSpan.add(editToolsInstructions); }
From source file:org.sakaiproject.gradebookng.tool.actions.DeleteAssignmentAction.java
License:Educational Community License
@Override public ActionResponse handleEvent(final JsonNode params, final AjaxRequestTarget target) { final String assignmentId = params.get("assignmentId").asText(); final GradebookPage gradebookPage = (GradebookPage) target.getPage(); final GbModalWindow window = gradebookPage.getDeleteItemWindow(); window.setTitle(gradebookPage.getString("delete.label")); window.setAssignmentToReturnFocusTo(assignmentId); window.setContent(new DeleteItemPanel(window.getContentId(), Model.of(Long.valueOf(assignmentId)), window)); window.showUnloadConfirmation(false); window.show(target);// ww w . j a v a 2 s . co m return new EmptyOkResponse(); }
From source file:org.sakaiproject.gradebookng.tool.actions.EditAssignmentAction.java
License:Educational Community License
@Override public ActionResponse handleEvent(final JsonNode params, final AjaxRequestTarget target) { final String assignmentId = params.get("assignmentId").asText(); final GradebookPage gradebookPage = (GradebookPage) target.getPage(); final GbModalWindow window = gradebookPage.getAddOrEditGradeItemWindow(); window.setTitle(gradebookPage.getString("heading.editgradeitem")); window.setAssignmentToReturnFocusTo(assignmentId); window.setContent(//from ww w . j av a 2 s .c om new AddOrEditGradeItemPanel(window.getContentId(), window, Model.of(Long.valueOf(assignmentId)))); window.showUnloadConfirmation(false); window.show(target); return new EmptyOkResponse(); }
From source file:org.sakaiproject.gradebookng.tool.actions.EditCommentAction.java
License:Educational Community License
@Override public ActionResponse handleEvent(final JsonNode params, final AjaxRequestTarget target) { final String assignmentId = params.get("assignmentId").asText(); final String studentUuid = params.get("studentId").asText(); final Map<String, Object> model = new HashMap<>(); model.put("assignmentId", Long.valueOf(assignmentId)); model.put("studentUuid", studentUuid); final GradebookPage gradebookPage = (GradebookPage) target.getPage(); final GbModalWindow window = gradebookPage.getGradeCommentWindow(); final EditGradeCommentPanel panel = new EditGradeCommentPanel(window.getContentId(), Model.ofMap(model), window);/*from www. j a v a 2 s.c o m*/ window.setContent(panel); window.showUnloadConfirmation(false); window.clearWindowClosedCallbacks(); window.setAssignmentToReturnFocusTo(assignmentId); window.setStudentToReturnFocusTo(studentUuid); window.addWindowClosedCallback(new ModalWindow.WindowClosedCallback() { private static final long serialVersionUID = 1L; @Override public void onClose(final AjaxRequestTarget target) { final String comment = panel.getComment(); target.appendJavaScript(String.format("GbGradeTable.updateComment('%s', '%s', '%s');", assignmentId, studentUuid, comment == null ? "" : comment)); } }); window.show(target); return new EmptyOkResponse(); }
From source file:org.sakaiproject.gradebookng.tool.actions.EditSettingsAction.java
License:Educational Community License
@Override public ActionResponse handleEvent(final JsonNode params, final AjaxRequestTarget target) { target.getPage().setResponsePage(SettingsPage.class); return new EmptyOkResponse(); }
From source file:org.sakaiproject.gradebookng.tool.actions.GradeUpdateAction.java
License:Educational Community License
@Override public ActionResponse handleEvent(final JsonNode params, final AjaxRequestTarget target) { final GradebookPage page = (GradebookPage) target.getPage(); // clear the feedback message at the top of the page target.addChildren(page, FeedbackPanel.class); final String rawOldGrade = params.get("oldScore").textValue(); final String rawNewGrade = params.get("newScore").textValue(); if (StringUtils.isNotBlank(rawNewGrade) && (!NumberUtil.isValidLocaleDouble(rawNewGrade) || FormatHelper.validateDouble(rawNewGrade) < 0)) { target.add(page.updateLiveGradingMessage(page.getString("feedback.error"))); return new ArgumentErrorResponse("Grade not valid"); }/*from w w w .j a v a 2s.c o m*/ final String oldGrade = FormatHelper.formatGradeFromUserLocale(rawOldGrade); final String newGrade = FormatHelper.formatGradeFromUserLocale(rawNewGrade); final String assignmentId = params.get("assignmentId").asText(); final String studentUuid = params.get("studentId").asText(); final String categoryId = params.has("categoryId") ? params.get("categoryId").asText() : null; // We don't pass the comment from the use interface, // but the service needs it otherwise it will assume 'null' // so pull it back from the service and poke it in there! final String comment = businessService.getAssignmentGradeComment(Long.valueOf(assignmentId), studentUuid); // for concurrency, get the original grade we have in the UI and pass it into the service as a check final GradeSaveResponse result = businessService.saveGrade(Long.valueOf(assignmentId), studentUuid, oldGrade, newGrade, comment); if (result.equals(GradeSaveResponse.NO_CHANGE)) { target.add(page.updateLiveGradingMessage(page.getString("feedback.saved"))); return new SaveGradeNoChangeResponse(); } if (!result.equals(GradeSaveResponse.OK) && !result.equals(GradeSaveResponse.OVER_LIMIT)) { target.add(page.updateLiveGradingMessage(page.getString("feedback.error"))); return new SaveGradeErrorResponse(result); } final CourseGrade studentCourseGrade = businessService.getCourseGrade(studentUuid); boolean isOverride = false; String grade = "-"; String points = "0"; if (studentCourseGrade != null) { final GradebookUiSettings uiSettings = page.getUiSettings(); final Gradebook gradebook = businessService.getGradebook(); final CourseGradeFormatter courseGradeFormatter = new CourseGradeFormatter(gradebook, page.getCurrentRole(), businessService.isCourseGradeVisible(businessService.getCurrentUser().getId()), uiSettings.getShowPoints(), true); grade = courseGradeFormatter.format(studentCourseGrade); if (studentCourseGrade.getPointsEarned() != null) { points = FormatHelper.formatDoubleToDecimal(studentCourseGrade.getPointsEarned()); } if (studentCourseGrade.getEnteredGrade() != null) { isOverride = true; } } Optional<CategoryScoreData> catData = categoryId == null ? Optional.empty() : businessService.getCategoryScoreForStudent(Long.valueOf(categoryId), studentUuid, true); String categoryScore = catData.map(c -> String.valueOf(c.score)).orElse("-"); List<Long> droppedItems = catData.map(c -> c.droppedItems).orElse(Collections.emptyList()); target.add(page.updateLiveGradingMessage(page.getString("feedback.saved"))); return new GradeUpdateResponse(result.equals(GradeSaveResponse.OVER_LIMIT), grade, points, isOverride, categoryScore, droppedItems); }
From source file:org.sakaiproject.gradebookng.tool.actions.MoveAssignmentLeftAction.java
License:Educational Community License
@Override public ActionResponse handleEvent(final JsonNode params, final AjaxRequestTarget target) { final GradebookPage gradebookPage = (GradebookPage) target.getPage(); final Long assignmentId = Long.valueOf(params.get("assignmentId").asText()); GradebookUiSettings settings = gradebookPage.getUiSettings(); if (settings == null) { settings = new GradebookUiSettings(); gradebookPage.setUiSettings(settings); }//w w w . j a v a 2s. c om if (settings.isCategoriesEnabled() && settings.isGroupedByCategory()) { try { final Integer order = calculateCurrentCategorizedSortOrder(assignmentId); MoveAssignmentLeftAction.this.businessService.updateAssignmentCategorizedOrder(assignmentId, (order.intValue() - 1)); } catch (final Exception e) { return new ArgumentErrorResponse("Error reordering within category: " + e.getMessage()); } } else { final int order = MoveAssignmentLeftAction.this.businessService .getAssignmentSortOrder(assignmentId.longValue()); MoveAssignmentLeftAction.this.businessService.updateAssignmentOrder(assignmentId.longValue(), (order - 1)); } // refresh the page target.appendJavaScript("location.reload();"); return new EmptyOkResponse(); }
From source file:org.sakaiproject.gradebookng.tool.actions.MoveAssignmentRightAction.java
License:Educational Community License
@Override public ActionResponse handleEvent(final JsonNode params, final AjaxRequestTarget target) { final GradebookPage gradebookPage = (GradebookPage) target.getPage(); final Long assignmentId = Long.valueOf(params.get("assignmentId").asText()); GradebookUiSettings settings = gradebookPage.getUiSettings(); if (settings == null) { settings = new GradebookUiSettings(); gradebookPage.setUiSettings(settings); }/*from w w w .j a v a 2 s . c om*/ if (settings.isCategoriesEnabled() && settings.isGroupedByCategory()) { try { final Integer order = calculateCurrentCategorizedSortOrder(assignmentId); MoveAssignmentRightAction.this.businessService.updateAssignmentCategorizedOrder(assignmentId, (order.intValue() + 1)); } catch (final Exception e) { return new ArgumentErrorResponse("Error reordering within category: " + e.getMessage()); } } else { final int order = MoveAssignmentRightAction.this.businessService .getAssignmentSortOrder(assignmentId.longValue()); MoveAssignmentRightAction.this.businessService.updateAssignmentOrder(assignmentId.longValue(), (order + 1)); } // refresh the page target.appendJavaScript("location.reload();"); return new EmptyOkResponse(); }