Search in sources :

Example 1 with EntriesChosenEvent

use of org.olat.core.gui.control.generic.ajax.autocompletion.EntriesChosenEvent in project OpenOLAT by OpenOLAT.

the class TableController method event.

@Override
public void event(final UserRequest ureq, final Controller source, final Event event) {
    log.debug("dispatchEvent event=" + event + "  source=" + source);
    if (event instanceof EntriesChosenEvent) {
        EntriesChosenEvent ece = (EntriesChosenEvent) event;
        List<String> filterList = ece.getEntries();
        if (!filterList.isEmpty()) {
            table.setSearchString(filterList.get(0));
            modelChanged(false);
        } else {
            // reset filter search filter in modelChanged
            modelChanged();
        }
    } else if (event instanceof EmptyChosenEvent) {
        modelChanged(true);
    }
}
Also used : EmptyChosenEvent(org.olat.core.gui.control.generic.ajax.autocompletion.EmptyChosenEvent) EntriesChosenEvent(org.olat.core.gui.control.generic.ajax.autocompletion.EntriesChosenEvent)

Example 2 with EntriesChosenEvent

use of org.olat.core.gui.control.generic.ajax.autocompletion.EntriesChosenEvent in project OpenOLAT by OpenOLAT.

the class UserSearchController method event.

/**
 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
 */
public void event(UserRequest ureq, Controller source, Event event) {
    if (source == tableCtr) {
        if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
            TableEvent te = (TableEvent) event;
            if (te.getActionId().equals(ACTION_SINGLESELECT_CHOOSE)) {
                int rowid = te.getRowId();
                Identity foundIdentity = tdm.getObject(rowid);
                foundIdentities.add(foundIdentity);
                // Tell parentController that a subject has been found
                fireEvent(ureq, new SingleIdentityChosenEvent(foundIdentity));
            }
        } else if (event.getCommand().equals(Table.COMMAND_MULTISELECT)) {
            TableMultiSelectEvent tmse = (TableMultiSelectEvent) event;
            if (tmse.getAction().equals(ACTION_MULTISELECT_CHOOSE)) {
                foundIdentities = tdm.getObjects(tmse.getSelection());
                fireEvent(ureq, new MultiIdentityChosenEvent(foundIdentities));
            }
        }
    } else if (source == autocompleterC) {
        if (event instanceof EntriesChosenEvent) {
            EntriesChosenEvent ece = (EntriesChosenEvent) event;
            List<String> res = ece.getEntries();
            // if we get the event, we have a result or an incorrect selection see OLAT-5114 -> check for empty
            String mySel = res.isEmpty() ? null : (String) res.get(0);
            if ((mySel == null) || mySel.trim().equals("")) {
                getWindowControl().setWarning(translate("error.search.form.notempty"));
                return;
            }
            // default not found
            Long key = -1l;
            try {
                key = Long.valueOf(mySel);
                if (key > 0) {
                    Identity chosenIdent = BaseSecurityManager.getInstance().loadIdentityByKey(key);
                    // No need to check for null, exception is thrown when identity does not exist which really
                    // should not happen at all.
                    // Tell that an identity has been chosen
                    fireEvent(ureq, new SingleIdentityChosenEvent(chosenIdent));
                }
            } catch (NumberFormatException e) {
                getWindowControl().setWarning(translate("error.no.user.found"));
                return;
            }
        }
    } else if (source == searchform) {
        if (event == Event.DONE_EVENT) {
            // form validation was ok
            doSearch(ureq);
        } else if (event == Event.CANCELLED_EVENT) {
            fireEvent(ureq, Event.CANCELLED_EVENT);
        }
    }
}
Also used : TableEvent(org.olat.core.gui.components.table.TableEvent) TableMultiSelectEvent(org.olat.core.gui.components.table.TableMultiSelectEvent) SingleIdentityChosenEvent(org.olat.basesecurity.events.SingleIdentityChosenEvent) ArrayList(java.util.ArrayList) List(java.util.List) Identity(org.olat.core.id.Identity) MultiIdentityChosenEvent(org.olat.basesecurity.events.MultiIdentityChosenEvent) EntriesChosenEvent(org.olat.core.gui.control.generic.ajax.autocompletion.EntriesChosenEvent)

Example 3 with EntriesChosenEvent

use of org.olat.core.gui.control.generic.ajax.autocompletion.EntriesChosenEvent in project openolat by klemens.

the class EMailCalloutCtrl method event.

@Override
public void event(UserRequest ureq, Controller source, Event event) {
    if (source == autocompleterC) {
        if (event instanceof EntriesChosenEvent) {
            EntriesChosenEvent ce = (EntriesChosenEvent) event;
            List<String> entries = ce.getEntries();
            if (entries != null && entries.size() == 1) {
                processSelection(ureq, entries.get(0));
            }
        }
    }
    super.event(ureq, source, event);
}
Also used : EntriesChosenEvent(org.olat.core.gui.control.generic.ajax.autocompletion.EntriesChosenEvent)

Example 4 with EntriesChosenEvent

use of org.olat.core.gui.control.generic.ajax.autocompletion.EntriesChosenEvent in project openolat by klemens.

the class UserSearchController method event.

/**
 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
 */
public void event(UserRequest ureq, Controller source, Event event) {
    if (source == tableCtr) {
        if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
            TableEvent te = (TableEvent) event;
            if (te.getActionId().equals(ACTION_SINGLESELECT_CHOOSE)) {
                int rowid = te.getRowId();
                Identity foundIdentity = tdm.getObject(rowid);
                foundIdentities.add(foundIdentity);
                // Tell parentController that a subject has been found
                fireEvent(ureq, new SingleIdentityChosenEvent(foundIdentity));
            }
        } else if (event.getCommand().equals(Table.COMMAND_MULTISELECT)) {
            TableMultiSelectEvent tmse = (TableMultiSelectEvent) event;
            if (tmse.getAction().equals(ACTION_MULTISELECT_CHOOSE)) {
                foundIdentities = tdm.getObjects(tmse.getSelection());
                fireEvent(ureq, new MultiIdentityChosenEvent(foundIdentities));
            }
        }
    } else if (source == autocompleterC) {
        if (event instanceof EntriesChosenEvent) {
            EntriesChosenEvent ece = (EntriesChosenEvent) event;
            List<String> res = ece.getEntries();
            // if we get the event, we have a result or an incorrect selection see OLAT-5114 -> check for empty
            String mySel = res.isEmpty() ? null : (String) res.get(0);
            if ((mySel == null) || mySel.trim().equals("")) {
                getWindowControl().setWarning(translate("error.search.form.notempty"));
                return;
            }
            // default not found
            Long key = -1l;
            try {
                key = Long.valueOf(mySel);
                if (key > 0) {
                    Identity chosenIdent = BaseSecurityManager.getInstance().loadIdentityByKey(key);
                    // No need to check for null, exception is thrown when identity does not exist which really
                    // should not happen at all.
                    // Tell that an identity has been chosen
                    fireEvent(ureq, new SingleIdentityChosenEvent(chosenIdent));
                }
            } catch (NumberFormatException e) {
                getWindowControl().setWarning(translate("error.no.user.found"));
                return;
            }
        }
    } else if (source == searchform) {
        if (event == Event.DONE_EVENT) {
            // form validation was ok
            doSearch(ureq);
        } else if (event == Event.CANCELLED_EVENT) {
            fireEvent(ureq, Event.CANCELLED_EVENT);
        }
    }
}
Also used : TableEvent(org.olat.core.gui.components.table.TableEvent) TableMultiSelectEvent(org.olat.core.gui.components.table.TableMultiSelectEvent) SingleIdentityChosenEvent(org.olat.basesecurity.events.SingleIdentityChosenEvent) ArrayList(java.util.ArrayList) List(java.util.List) Identity(org.olat.core.id.Identity) MultiIdentityChosenEvent(org.olat.basesecurity.events.MultiIdentityChosenEvent) EntriesChosenEvent(org.olat.core.gui.control.generic.ajax.autocompletion.EntriesChosenEvent)

Example 5 with EntriesChosenEvent

use of org.olat.core.gui.control.generic.ajax.autocompletion.EntriesChosenEvent in project OpenOLAT by OpenOLAT.

the class GUIDemoMainController method handleOwnMenuTreeEvent.

@Override
protected Controller handleOwnMenuTreeEvent(Object uobject, final UserRequest ureq) {
    if (uobject.equals("guidemo-autocompletion")) {
        // for a demo of autocompletion, do a user search
        ListProvider provider = new ListProvider() {

            public void getResult(String searchValue, ListReceiver receiver) {
                Map<String, String> userProperties = new HashMap<String, String>();
                // We can only search in mandatory User-Properties due to problems
                // with hibernate query with join and not existing rows
                userProperties.put(UserConstants.FIRSTNAME, searchValue);
                userProperties.put(UserConstants.LASTNAME, searchValue);
                userProperties.put(UserConstants.EMAIL, searchValue);
                List<Identity> res = BaseSecurityManager.getInstance().getVisibleIdentitiesByPowerSearch(searchValue, userProperties, false, null, null, null, null, null);
                int maxEntries = 15;
                boolean hasMore = false;
                for (Iterator<Identity> it_res = res.iterator(); (hasMore = it_res.hasNext()) && maxEntries > 0; ) {
                    maxEntries--;
                    Identity ident = it_res.next();
                    User u = ident.getUser();
                    String key = ident.getKey().toString();
                    String displayKey = ident.getName();
                    String first = u.getProperty(UserConstants.FIRSTNAME, getLocale());
                    String last = u.getProperty(UserConstants.LASTNAME, getLocale());
                    String displayText = last + " " + first;
                    receiver.addEntry(key, displayKey, displayText, CSSHelper.CSS_CLASS_USER);
                }
                if (hasMore) {
                    receiver.addEntry("-1", ".....");
                }
            }
        };
        Controller c = new AutoCompleterController(ureq, getWindowControl(), provider, null, true, 60, 3, null);
        // for demo only, normally use in parent controller
        c.addControllerListener(new ControllerEventListener() {

            public void dispatchEvent(UserRequest uureq, Controller source, Event event) {
                EntriesChosenEvent ece = (EntriesChosenEvent) event;
                String sel = ece.getEntries().toString();
                getWindowControl().setInfo("selected entrie(s):" + sel);
            }
        });
        return c;
    }
    return null;
}
Also used : User(org.olat.core.id.User) HashMap(java.util.HashMap) ListProvider(org.olat.core.gui.control.generic.ajax.autocompletion.ListProvider) Controller(org.olat.core.gui.control.Controller) AutoCompleterController(org.olat.core.gui.control.generic.ajax.autocompletion.AutoCompleterController) GenericMainController(org.olat.core.gui.control.generic.layout.GenericMainController) ControllerEventListener(org.olat.core.gui.control.ControllerEventListener) Event(org.olat.core.gui.control.Event) EntriesChosenEvent(org.olat.core.gui.control.generic.ajax.autocompletion.EntriesChosenEvent) AutoCompleterController(org.olat.core.gui.control.generic.ajax.autocompletion.AutoCompleterController) Identity(org.olat.core.id.Identity) ListReceiver(org.olat.core.gui.control.generic.ajax.autocompletion.ListReceiver) EntriesChosenEvent(org.olat.core.gui.control.generic.ajax.autocompletion.EntriesChosenEvent) UserRequest(org.olat.core.gui.UserRequest)

Aggregations

EntriesChosenEvent (org.olat.core.gui.control.generic.ajax.autocompletion.EntriesChosenEvent)8 Identity (org.olat.core.id.Identity)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 MultiIdentityChosenEvent (org.olat.basesecurity.events.MultiIdentityChosenEvent)2 SingleIdentityChosenEvent (org.olat.basesecurity.events.SingleIdentityChosenEvent)2 UserRequest (org.olat.core.gui.UserRequest)2 TableEvent (org.olat.core.gui.components.table.TableEvent)2 TableMultiSelectEvent (org.olat.core.gui.components.table.TableMultiSelectEvent)2 Controller (org.olat.core.gui.control.Controller)2 ControllerEventListener (org.olat.core.gui.control.ControllerEventListener)2 Event (org.olat.core.gui.control.Event)2 AutoCompleterController (org.olat.core.gui.control.generic.ajax.autocompletion.AutoCompleterController)2 EmptyChosenEvent (org.olat.core.gui.control.generic.ajax.autocompletion.EmptyChosenEvent)2 ListProvider (org.olat.core.gui.control.generic.ajax.autocompletion.ListProvider)2 ListReceiver (org.olat.core.gui.control.generic.ajax.autocompletion.ListReceiver)2 GenericMainController (org.olat.core.gui.control.generic.layout.GenericMainController)2 User (org.olat.core.id.User)2