IDEMPIERE-4101 [Chosenbox] Multi select don't work in Firefox (#435)

- add display of button
- fix dropdown doesn't render properly at Firefox
This commit is contained in:
hengsin 2020-12-05 00:52:10 +08:00 committed by GitHub
parent b9964ce7ab
commit 894ceb8c4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 92 additions and 27 deletions

View File

@ -51,6 +51,7 @@ Copyright (C) 2007 Ashley G Ramdass (ADempiere WebUI).
<javascript-module name="org.idempiere.commons" version="202012030330"/> <javascript-module name="org.idempiere.commons" version="202012030330"/>
<javascript-module name="jquery.maskedinput" version="1.4.1" /> <javascript-module name="jquery.maskedinput" version="1.4.1" />
<javascript-module name="photobooth" version="0.7-rsd3" /> <javascript-module name="photobooth" version="0.7-rsd3" />
<javascript-module name="chosenbox" version="202012041500"/>
<!-- this js module doesn't actually exists and it is here for default theme version --> <!-- this js module doesn't actually exists and it is here for default theme version -->
<!-- since loading of js module is on demand, it doesn't cause any error as long as you don't try to load it --> <!-- since loading of js module is on demand, it doesn't cause any error as long as you don't try to load it -->

View File

@ -38,6 +38,18 @@ public class ChosenSearchBox extends Div {
protected Chosenbox<ValueNamePair> chosenbox; protected Chosenbox<ValueNamePair> chosenbox;
protected Button btn; protected Button btn;
/**
*
* @param chosenbox custom implementation of Chosenbox
*/
public ChosenSearchBox(Chosenbox<ValueNamePair> chosenbox) {
this.chosenbox = chosenbox;
initComponents();
}
/**
* default constructor
*/
public ChosenSearchBox() { public ChosenSearchBox() {
initComponents(); initComponents();
} }
@ -50,7 +62,8 @@ public class ChosenSearchBox extends Div {
} }
private void initComponents() { private void initComponents() {
chosenbox = new Chosenbox<>(); if (chosenbox == null)
chosenbox = new Chosenbox<>();
chosenbox.setSclass("editor-input"); chosenbox.setSclass("editor-input");
chosenbox.setWidth("100%"); chosenbox.setWidth("100%");
appendChild(chosenbox); appendChild(chosenbox);

View File

@ -21,9 +21,11 @@ import java.util.Properties;
import java.util.Set; import java.util.Set;
import org.adempiere.webui.ValuePreference; import org.adempiere.webui.ValuePreference;
import org.adempiere.webui.component.ChosenSearchBox;
import org.adempiere.webui.event.ContextMenuEvent; import org.adempiere.webui.event.ContextMenuEvent;
import org.adempiere.webui.event.ContextMenuListener; import org.adempiere.webui.event.ContextMenuListener;
import org.adempiere.webui.event.ValueChangeEvent; import org.adempiere.webui.event.ValueChangeEvent;
import org.adempiere.webui.theme.ThemeManager;
import org.adempiere.webui.window.WFieldRecordInfo; import org.adempiere.webui.window.WFieldRecordInfo;
import org.compiere.model.GridField; import org.compiere.model.GridField;
import org.compiere.model.Lookup; import org.compiere.model.Lookup;
@ -59,7 +61,7 @@ public class WChosenboxListEditor extends WEditor implements ContextMenuListener
static static
{ {
logger = CLogger.getCLogger(WTableDirEditor.class); logger = CLogger.getCLogger(WChosenboxListEditor.class);
} }
private Lookup lookup; private Lookup lookup;
@ -88,7 +90,7 @@ public class WChosenboxListEditor extends WEditor implements ContextMenuListener
*/ */
public WChosenboxListEditor(GridField gridField, boolean tableEditor, IEditorConfiguration editorConfiguration) public WChosenboxListEditor(GridField gridField, boolean tableEditor, IEditorConfiguration editorConfiguration)
{ {
this(new ChosenboxEditor(), gridField, tableEditor, editorConfiguration); this(new ChosenSearchBox(new ChosenboxEditor()), gridField, tableEditor, editorConfiguration);
} }
private WChosenboxListEditor(Component comp, GridField gridField, boolean tableEditor, IEditorConfiguration editorConfiguration) private WChosenboxListEditor(Component comp, GridField gridField, boolean tableEditor, IEditorConfiguration editorConfiguration)
@ -113,9 +115,19 @@ public class WChosenboxListEditor extends WEditor implements ContextMenuListener
this(lookup, label, description, mandatory, readonly, updateable, false); this(lookup, label, description, mandatory, readonly, updateable, false);
} }
/**
*
* @param lookup
* @param label
* @param description
* @param mandatory
* @param readonly
* @param updateable
* @param autocomplete
*/
public WChosenboxListEditor(Lookup lookup, String label, String description, boolean mandatory, boolean readonly, boolean updateable, boolean autocomplete) public WChosenboxListEditor(Lookup lookup, String label, String description, boolean mandatory, boolean readonly, boolean updateable, boolean autocomplete)
{ {
this(new ChosenboxEditor(), lookup, label, description, mandatory, readonly, updateable); this(new ChosenSearchBox(new ChosenboxEditor()), lookup, label, description, mandatory, readonly, updateable);
} }
private WChosenboxListEditor(Component comp, Lookup lookup, String label, String description, boolean mandatory, boolean readonly, boolean updateable) private WChosenboxListEditor(Component comp, Lookup lookup, String label, String description, boolean mandatory, boolean readonly, boolean updateable)
@ -145,9 +157,18 @@ public class WChosenboxListEditor extends WEditor implements ContextMenuListener
this(columnName, mandatory, isReadOnly, isUpdateable, lookup, false); this(columnName, mandatory, isReadOnly, isUpdateable, lookup, false);
} }
/**
*
* @param columnName
* @param mandatory
* @param isReadOnly
* @param isUpdateable
* @param lookup
* @param autocomplete
*/
public WChosenboxListEditor(String columnName, boolean mandatory, boolean isReadOnly, boolean isUpdateable, Lookup lookup, boolean autocomplete) public WChosenboxListEditor(String columnName, boolean mandatory, boolean isReadOnly, boolean isUpdateable, Lookup lookup, boolean autocomplete)
{ {
this(new ChosenboxEditor(), columnName, mandatory, isReadOnly, isUpdateable, lookup); this(new ChosenSearchBox(new ChosenboxEditor()), columnName, mandatory, isReadOnly, isUpdateable, lookup);
} }
private WChosenboxListEditor(Component comp, String columnName, boolean mandatory, boolean isReadOnly, boolean isUpdateable, Lookup lookup) private WChosenboxListEditor(Component comp, String columnName, boolean mandatory, boolean isReadOnly, boolean isUpdateable, Lookup lookup)
@ -164,9 +185,27 @@ public class WChosenboxListEditor extends WEditor implements ContextMenuListener
private void init() private void init()
{ {
getComponent().setHflex("true"); getComponent().setHflex("true");
getComponent().editor = this; ((ChosenboxEditor)getComponent().getChosenbox()).editor = this;
getComponent().setModel(model); getComponent().getChosenbox().setModel(model);
String imageUrl;
if (ThemeManager.isUseFontIconForImage())
imageUrl = "z-icon-More";
else
imageUrl = ThemeManager.getThemeResource("images/ShowMore16.png");
if (ThemeManager.isUseFontIconForImage())
getComponent().getButton().setIconSclass(imageUrl);
else
getComponent().getButton().setImage(imageUrl);
getComponent().getButton().addEventListener(Events.ON_CLICK, e -> {
if (getComponent().isEnabled()) {
if (!getComponent().getChosenbox().isOpen()) {
getComponent().getChosenbox().setOpen(true);
getComponent().getChosenbox().focus();
}
}
});
if (lookup != null) if (lookup != null)
{ {
lookup.setMandatory(true); lookup.setMandatory(true);
@ -189,6 +228,9 @@ public class WChosenboxListEditor extends WEditor implements ContextMenuListener
} }
} }
/**
* refresh lookup list
*/
protected void refreshLookup() { protected void refreshLookup() {
lookup.refresh(); lookup.refresh();
updateModel(); updateModel();
@ -198,7 +240,7 @@ public class WChosenboxListEditor extends WEditor implements ContextMenuListener
public String getDisplay() public String getDisplay()
{ {
StringBuilder display = new StringBuilder(); StringBuilder display = new StringBuilder();
LinkedHashSet<ValueNamePair> selected = getComponent().getSelectedObjects(); LinkedHashSet<ValueNamePair> selected = getComponent().getChosenbox().getSelectedObjects();
if (selected != null && selected.size() > 0) if (selected != null && selected.size() > 0)
{ {
for(ValueNamePair pair : selected) for(ValueNamePair pair : selected)
@ -220,7 +262,7 @@ public class WChosenboxListEditor extends WEditor implements ContextMenuListener
private String getValueFromComponent() private String getValueFromComponent()
{ {
StringBuilder retVal = new StringBuilder(); StringBuilder retVal = new StringBuilder();
LinkedHashSet<ValueNamePair> selected = getComponent().getSelectedObjects(); LinkedHashSet<ValueNamePair> selected = getComponent().getChosenbox().getSelectedObjects();
if (selected != null && selected.size() > 0) if (selected != null && selected.size() > 0)
{ {
for(ValueNamePair pair : selected) for(ValueNamePair pair : selected)
@ -239,6 +281,9 @@ public class WChosenboxListEditor extends WEditor implements ContextMenuListener
return retVal.length() > 0 ? retVal.toString() : null; return retVal.length() > 0 ? retVal.toString() : null;
} }
/**
* @param value
*/
public void setValue(Object value) public void setValue(Object value)
{ {
if (onselecting) { if (onselecting) {
@ -259,8 +304,8 @@ public class WChosenboxListEditor extends WEditor implements ContextMenuListener
selected.add(pair); selected.add(pair);
} }
} }
getComponent().setSelectedObjects(selected); getComponent().getChosenbox().setSelectedObjects(selected);
if (getComponent().getSelectedObjects().size() != selected.size()) if (getComponent().getChosenbox().getSelectedObjects().size() != selected.size())
{ {
Object curValue = oldValue; Object curValue = oldValue;
oldValue = value; oldValue = value;
@ -273,12 +318,12 @@ public class WChosenboxListEditor extends WEditor implements ContextMenuListener
{ {
updateModel(); updateModel();
} }
getComponent().setSelectedObjects(selected); getComponent().getChosenbox().setSelectedObjects(selected);
//still not in list, reset to zero //still not in list, reset to zero
if (getComponent().getSelectedObjects().size() != selected.size()) if (getComponent().getChosenbox().getSelectedObjects().size() != selected.size())
{ {
getComponent().setSelectedObjects(new LinkedHashSet<ValueNamePair>()); getComponent().getChosenbox().setSelectedObjects(new LinkedHashSet<ValueNamePair>());
if (curValue == null) if (curValue == null)
curValue = value; curValue = value;
ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), curValue, null); ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), curValue, null);
@ -293,14 +338,14 @@ public class WChosenboxListEditor extends WEditor implements ContextMenuListener
} }
else else
{ {
getComponent().setSelectedObjects(new LinkedHashSet<ValueNamePair>()); getComponent().getChosenbox().setSelectedObjects(new LinkedHashSet<ValueNamePair>());
oldValue = value; oldValue = value;
} }
} }
@Override @Override
public ChosenboxEditor getComponent() { public ChosenSearchBox getComponent() {
return (ChosenboxEditor) component; return (ChosenSearchBox) component;
} }
@Override @Override
@ -364,6 +409,9 @@ public class WChosenboxListEditor extends WEditor implements ContextMenuListener
model.addAll(list); model.addAll(list);
} }
/**
* @param event
*/
public void onEvent(Event event) public void onEvent(Event event)
{ {
if (Events.ON_SELECT.equalsIgnoreCase(event.getName())) if (Events.ON_SELECT.equalsIgnoreCase(event.getName()))
@ -394,12 +442,16 @@ public class WChosenboxListEditor extends WEditor implements ContextMenuListener
|| ((oldValue != null && newValue != null) && !oldValue.equals(newValue)); || ((oldValue != null && newValue != null) && !oldValue.equals(newValue));
} }
@Override
public String[] getEvents() public String[] getEvents()
{ {
return LISTENER_EVENTS; return LISTENER_EVENTS;
} }
public void actionRefresh() /**
* action for requery menu
*/
protected void actionRefresh()
{ {
if (lookup != null) if (lookup != null)
{ {
@ -416,11 +468,16 @@ public class WChosenboxListEditor extends WEditor implements ContextMenuListener
} }
} }
/**
*
* @return {@link Lookup}
*/
public Lookup getLookup() public Lookup getLookup()
{ {
return lookup; return lookup;
} }
@Override
public void onMenu(ContextMenuEvent evt) public void onMenu(ContextMenuEvent evt)
{ {
if (WEditorPopupMenu.REQUERY_EVENT.equals(evt.getContextEvent())) if (WEditorPopupMenu.REQUERY_EVENT.equals(evt.getContextEvent()))
@ -439,6 +496,7 @@ public class WChosenboxListEditor extends WEditor implements ContextMenuListener
} }
} }
@Override
public void propertyChange(PropertyChangeEvent evt) public void propertyChange(PropertyChangeEvent evt)
{ {
if ("FieldValue".equals(evt.getPropertyName())) if ("FieldValue".equals(evt.getPropertyName()))
@ -455,7 +513,7 @@ public class WChosenboxListEditor extends WEditor implements ContextMenuListener
((MLookup) lookup).getLookupInfo().ctx = ctx; ((MLookup) lookup).getLookupInfo().ctx = ctx;
} }
if ((lookup != null) && (!lookup.isValidated() || !lookup.isLoaded() if ((lookup != null) && (!lookup.isValidated() || !lookup.isLoaded()
|| (isReadWrite() && lookup.getSize() != getComponent().getModel().getSize()))) || (isReadWrite() && lookup.getSize() != getComponent().getChosenbox().getModel().getSize())))
this.actionRefresh(); this.actionRefresh();
super.dynamicDisplay(ctx); super.dynamicDisplay(ctx);
@ -484,14 +542,6 @@ public class WChosenboxListEditor extends WEditor implements ContextMenuListener
protected ChosenboxEditor() { protected ChosenboxEditor() {
} }
public void setEnabled(boolean readWrite) {
setDisabled(readWrite==false);
}
public boolean isEnabled() {
return isDisabled() == false;
}
@Override @Override
public void setPage(Page page) { public void setPage(Page page) {
super.setPage(page); super.setPage(page);

View File

@ -873,6 +873,7 @@ it will be useful, but WITHOUT ANY WARRANTY.
this.setFloating_(true); this.setFloating_(true);
this.setTopmost(); this.setTopmost();
ppstyle.zIndex = n.style.zIndex; ppstyle.zIndex = n.style.zIndex;
ppstyle.display = 'block';
if (opts) { if (opts) {
var inp = this.$n(); var inp = this.$n();
zk(pp).position(inp, "after_start"); zk(pp).position(inp, "after_start");