Skip to content
Snippets Groups Projects
Commit e616294e authored by srosse's avatar srosse
Browse files

OO-1385: quick search empty field as reset of the table

parent d09fc733
No related branches found
No related tags found
No related merge requests found
......@@ -246,27 +246,29 @@ public class UserSearchController extends BasicController {
}
}
} else if (source == autocompleterC) {
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;
}
Long key = -1l; // default not found
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));
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;
}
Long key = -1l; // default not found
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;
}
} catch (NumberFormatException e) {
getWindowControl().setWarning(translate("error.no.user.found"));
return;
}
} else if (source == searchform) {
if (event == Event.DONE_EVENT) {
......
......@@ -44,6 +44,7 @@ import org.olat.core.gui.control.Event;
import org.olat.core.gui.control.WindowControl;
import org.olat.core.gui.control.controller.BasicController;
import org.olat.core.gui.control.generic.ajax.autocompletion.AutoCompleterController;
import org.olat.core.gui.control.generic.ajax.autocompletion.EmptyChosenEvent;
import org.olat.core.gui.control.generic.ajax.autocompletion.EntriesChosenEvent;
import org.olat.core.gui.control.generic.ajax.autocompletion.ListProvider;
import org.olat.core.gui.control.generic.closablewrapper.CloseableCalloutWindowController;
......@@ -141,7 +142,7 @@ public class TableController extends BasicController {
private boolean tablePrefsInitialized = false;
private CloseableCalloutWindowController cmc;
private Controller tableSearchController;
private AutoCompleterController tableSearchController;
private TableSort tableSort;
private Link resetLink;
......@@ -296,11 +297,12 @@ public class TableController extends BasicController {
}
}
private Controller createTableSearchController(final UserRequest ureq, final WindowControl wControl) {
private AutoCompleterController createTableSearchController(final UserRequest ureq, final WindowControl wControl) {
ListProvider genericProvider = new TableListProvider(table);
removeAsListenerAndDispose(tableSearchController);
tableSearchController = new AutoCompleterController(ureq, wControl, genericProvider, null, false, 60, 3, translate("table.filter.label"));
listenTo(tableSearchController); // TODO:CG 02.09.2010 Test Tablesearch Performance, remove
tableSearchController.setEmptyAsReset(true);
listenTo(tableSearchController);
return tableSearchController;
}
......@@ -414,7 +416,9 @@ public class TableController extends BasicController {
// reset filter search filter in modelChanged
modelChanged();
}
}
} else if(event instanceof EmptyChosenEvent) {
modelChanged(true);
}
}
public int getRowCount() {
......
......@@ -36,7 +36,6 @@ import org.olat.core.gui.UserRequest;
import org.olat.core.gui.components.Component;
import org.olat.core.gui.components.htmlheader.jscss.CustomJSComponent;
import org.olat.core.gui.components.velocity.VelocityContainer;
import org.olat.core.gui.control.Controller;
import org.olat.core.gui.control.Event;
import org.olat.core.gui.control.WindowControl;
import org.olat.core.gui.control.controller.BasicController;
......@@ -72,6 +71,7 @@ public class AutoCompleterController extends BasicController {
private Mapper mapper;
private final ListProvider gprovider;
private final String noResults;
private boolean emptyAsReset;
private String datastoreName;
private String comboboxName;
......@@ -133,12 +133,21 @@ public class AutoCompleterController extends BasicController {
putInitialPanel(myContent);
}
public boolean isEmptyAsReset() {
return emptyAsReset;
}
public void setEmptyAsReset(boolean emptyAsReset) {
this.emptyAsReset = emptyAsReset;
}
/**
* This dispatches component events...
*
* @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
* org.olat.core.gui.components.Component, org.olat.core.gui.control.Event)
*/
@Override
public void event(UserRequest ureq, Component source, Event event) {
if (source == myContent) {
if (event.getCommand().equals(COMMAND_SELECT)) {
......@@ -153,6 +162,12 @@ public class AutoCompleterController extends BasicController {
logError("Auto complete JS code must always send 'key' or the autocomplete parameter!", null);
getWindowControl().setError(translate("autocomplete.error"));
return;
} else if (searchValue.equals("")) {
if(!isEmptyAsReset()) {
getWindowControl().setWarning(translate("autocomplete.not.enough.chars"));
}
fireEvent(ureq, new EmptyChosenEvent());
return;
} else if (searchValue.equals("") || searchValue.length() < 3) {
getWindowControl().setWarning(translate("autocomplete.not.enough.chars"));
return;
......@@ -187,19 +202,7 @@ public class AutoCompleterController extends BasicController {
}
}
/**
* This dispatches controller events...
*
* @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) {
// Nothing to dispatch
}
/**
* @see org.olat.core.gui.control.DefaultController#doDispose()
*/
@Override
protected void doDispose() {
// Cleanup javascript objects on browser side by triggering dispose
// function
......
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.core.gui.control.generic.ajax.autocompletion;
import org.olat.core.gui.control.Event;
/**
*
* Initial date: 14.01.2015<br>
* @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
*
*/
public class EmptyChosenEvent extends Event {
private static final long serialVersionUID = -7054150729828549832L;
public EmptyChosenEvent() {
super("emptyentries");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment