Search in sources :

Example 1 with ReferenceInfos

use of org.olat.resource.references.ReferenceInfos in project OpenOLAT by OpenOLAT.

the class ConfirmDeletePermanentlyController method applyDefaultToReferenceList.

private void applyDefaultToReferenceList() {
    for (ReferenceInfos reference : references) {
        String key = reference.getEntry().getKey().toString();
        boolean deletable = reference.isOwner() && reference.isOrphan() && !reference.isManaged();
        referencesEl.setEnabled(key, deletable);
        referencesEl.select(key, deletable);
    }
}
Also used : ReferenceInfos(org.olat.resource.references.ReferenceInfos)

Example 2 with ReferenceInfos

use of org.olat.resource.references.ReferenceInfos in project OpenOLAT by OpenOLAT.

the class ConfirmDeletePermanentlyController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    if (formLayout instanceof FormLayoutContainer) {
        FormLayoutContainer layout = (FormLayoutContainer) formLayout;
        layout.contextPut("notAllDeleteable", new Boolean(notAllDeleteable));
        layout.contextPut("numOfMembers", Integer.toString(numOfMembers));
        FormLayoutContainer layoutCont = FormLayoutContainer.createDefaultFormLayout("confirm", getTranslator());
        formLayout.add("confirm", layoutCont);
        layoutCont.setRootForm(mainForm);
        StringBuilder message = new StringBuilder();
        for (RepositoryEntry row : rows) {
            if (message.length() > 0)
                message.append(", ");
            message.append(StringHelper.escapeHtml(row.getDisplayname()));
        }
        uifactory.addStaticTextElement("rows", "details.delete.entries", message.toString(), layoutCont);
        String[] acknowledge = new String[] { translate("details.delete.acknowledge.msg") };
        acknowledgeEl = uifactory.addCheckboxesHorizontal("confirm", "details.delete.acknowledge", layoutCont, new String[] { "" }, acknowledge);
        int pos = 0;
        boolean hasOrphans = false;
        referenceKeys = new String[references.size()];
        String[] referenceValues = new String[references.size()];
        for (ReferenceInfos reference : references) {
            hasOrphans |= reference.isOrphan() && reference.isOwner() && !reference.isManaged();
            referenceKeys[pos] = reference.getEntry().getKey().toString();
            referenceValues[pos++] = getReferenceElValue(reference);
        }
        String[] yesNoValues = new String[] { translate("yes"), translate("no") };
        deleteReferencesEl = uifactory.addRadiosHorizontal("references.yesno", "details.delete.references", layoutCont, yesNo, yesNoValues);
        deleteReferencesEl.setVisible(hasOrphans);
        deleteReferencesEl.addActionListener(FormEvent.ONCHANGE);
        referencesEl = uifactory.addCheckboxesVertical("references.list", null, layoutCont, referenceKeys, referenceValues, 1);
        referencesEl.setVisible(false);
        applyDefaultToReferenceList();
        FormLayoutContainer buttonsCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
        layoutCont.add(buttonsCont);
        deleteButton = uifactory.addFormLink("details.delete", buttonsCont, Link.BUTTON);
        uifactory.addFormCancelButton("cancel", buttonsCont, ureq, getWindowControl());
    }
}
Also used : ReferenceInfos(org.olat.resource.references.ReferenceInfos) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) RepositoryEntry(org.olat.repository.RepositoryEntry)

Example 3 with ReferenceInfos

use of org.olat.resource.references.ReferenceInfos in project openolat by klemens.

the class ConfirmDeletePermanentlyController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    if (formLayout instanceof FormLayoutContainer) {
        FormLayoutContainer layout = (FormLayoutContainer) formLayout;
        layout.contextPut("notAllDeleteable", new Boolean(notAllDeleteable));
        layout.contextPut("numOfMembers", Integer.toString(numOfMembers));
        FormLayoutContainer layoutCont = FormLayoutContainer.createDefaultFormLayout("confirm", getTranslator());
        formLayout.add("confirm", layoutCont);
        layoutCont.setRootForm(mainForm);
        StringBuilder message = new StringBuilder();
        for (RepositoryEntry row : rows) {
            if (message.length() > 0)
                message.append(", ");
            message.append(StringHelper.escapeHtml(row.getDisplayname()));
        }
        uifactory.addStaticTextElement("rows", "details.delete.entries", message.toString(), layoutCont);
        String[] acknowledge = new String[] { translate("details.delete.acknowledge.msg") };
        acknowledgeEl = uifactory.addCheckboxesHorizontal("confirm", "details.delete.acknowledge", layoutCont, new String[] { "" }, acknowledge);
        int pos = 0;
        boolean hasOrphans = false;
        referenceKeys = new String[references.size()];
        String[] referenceValues = new String[references.size()];
        for (ReferenceInfos reference : references) {
            hasOrphans |= reference.isOrphan() && reference.isOwner() && !reference.isManaged();
            referenceKeys[pos] = reference.getEntry().getKey().toString();
            referenceValues[pos++] = getReferenceElValue(reference);
        }
        String[] yesNoValues = new String[] { translate("yes"), translate("no") };
        deleteReferencesEl = uifactory.addRadiosHorizontal("references.yesno", "details.delete.references", layoutCont, yesNo, yesNoValues);
        deleteReferencesEl.setVisible(hasOrphans);
        deleteReferencesEl.addActionListener(FormEvent.ONCHANGE);
        referencesEl = uifactory.addCheckboxesVertical("references.list", null, layoutCont, referenceKeys, referenceValues, 1);
        referencesEl.setVisible(false);
        applyDefaultToReferenceList();
        FormLayoutContainer buttonsCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
        layoutCont.add(buttonsCont);
        deleteButton = uifactory.addFormLink("details.delete", buttonsCont, Link.BUTTON);
        uifactory.addFormCancelButton("cancel", buttonsCont, ureq, getWindowControl());
    }
}
Also used : ReferenceInfos(org.olat.resource.references.ReferenceInfos) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) RepositoryEntry(org.olat.repository.RepositoryEntry)

Example 4 with ReferenceInfos

use of org.olat.resource.references.ReferenceInfos in project OpenOLAT by OpenOLAT.

the class ConfirmDeletePermanentlyController method doCompleteDelete.

private void doCompleteDelete(UserRequest ureq) {
    List<ErrorList> errorList = new ArrayList<>();
    boolean allOk = deleteEntries(ureq, rows, errorList);
    if (allOk && deleteReferencesEl.isVisible() && deleteReferencesEl.isEnabled() && deleteReferencesEl.isOneSelected() && deleteReferencesEl.isSelected(0)) {
        Map<Long, ReferenceInfos> referencesMap = new HashMap<>();
        for (ReferenceInfos reference : references) {
            referencesMap.put(reference.getEntry().getKey(), reference);
        }
        Collection<String> selectedKeys = referencesEl.getSelectedKeys();
        List<RepositoryEntry> referencesToDelete = new ArrayList<>(selectedKeys.size());
        for (String selectedRefKey : selectedKeys) {
            Long key = new Long(selectedRefKey);
            ReferenceInfos refInfos = referencesMap.get(key);
            if (refInfos != null && refInfos.isOrphan() && refInfos.isOwner() && !refInfos.isManaged()) {
                referencesToDelete.add(referencesMap.get(key).getEntry());
            }
        }
        allOk &= deleteEntries(ureq, referencesToDelete, errorList);
    }
    if (allOk) {
        showInfo("info.entry.deleted");
    } else {
        List<String> msgs = new ArrayList<>();
        for (ErrorList error : errorList) {
            if (StringHelper.containsNonWhitespace(error.getFirstError())) {
                msgs.add(error.getFirstError());
            }
        }
        if (msgs.size() == 1) {
            getWindowControl().setWarning(msgs.get(0));
        } else if (msgs.size() > 1) {
            StringBuilder sb = new StringBuilder();
            sb.append("<ul>");
            for (String msg : msgs) {
                sb.append("<li>").append(msg).append("</li>");
            }
            sb.append("</ul>");
            getWindowControl().setWarning(sb.toString());
        } else {
            showWarning("info.could.not.delete.entry");
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) ErrorList(org.olat.repository.ErrorList) ReferenceInfos(org.olat.resource.references.ReferenceInfos)

Example 5 with ReferenceInfos

use of org.olat.resource.references.ReferenceInfos in project openolat by klemens.

the class ConfirmDeletePermanentlyController method applyDefaultToReferenceList.

private void applyDefaultToReferenceList() {
    for (ReferenceInfos reference : references) {
        String key = reference.getEntry().getKey().toString();
        boolean deletable = reference.isOwner() && reference.isOrphan() && !reference.isManaged();
        referencesEl.setEnabled(key, deletable);
        referencesEl.select(key, deletable);
    }
}
Also used : ReferenceInfos(org.olat.resource.references.ReferenceInfos)

Aggregations

ReferenceInfos (org.olat.resource.references.ReferenceInfos)6 RepositoryEntry (org.olat.repository.RepositoryEntry)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2 ErrorList (org.olat.repository.ErrorList)2