Merge release-7.1 into master

This commit is contained in:
Carlos Ruiz 2020-03-10 18:30:52 +01:00
commit b38452321f
6 changed files with 226 additions and 47 deletions

View File

@ -90,4 +90,8 @@ public class MToolBarButton extends X_AD_ToolBarButton {
return buttons;
}
public boolean isSearchQueryComponent() {
return "b01e8ec6-1a3c-4f94-928b-4582e2c33f81".equals(getAD_ToolBarButton_UU());
}
}

View File

@ -30,6 +30,7 @@ import org.adempiere.webui.ClientInfo;
import org.adempiere.webui.LayoutUtils;
import org.adempiere.webui.action.Actions;
import org.adempiere.webui.action.IAction;
import org.adempiere.webui.component.Combobox;
import org.adempiere.webui.component.FToolbar;
import org.adempiere.webui.component.Menupopup;
import org.adempiere.webui.component.Tabpanel;
@ -43,6 +44,7 @@ import org.adempiere.webui.window.FDialog;
import org.compiere.model.GridTab;
import org.compiere.model.MRole;
import org.compiere.model.MToolBarButton;
import org.compiere.model.MUserQuery;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
@ -62,6 +64,7 @@ import org.zkoss.zk.ui.event.KeyEvent;
import org.zkoss.zk.ui.event.OpenEvent;
import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zul.A;
import org.zkoss.zul.Comboitem;
import org.zkoss.zul.Menuitem;
import org.zkoss.zul.Popup;
import org.zkoss.zul.Separator;
@ -91,6 +94,10 @@ public class ADWindowToolbar extends FToolbar implements EventListener<Event>
private static final CLogger log = CLogger.getCLogger(ADWindowToolbar.class);
private Combobox fQueryName;
private MUserQuery[] userQueries;
private MUserQuery selectedUserQuery;
private ToolBarButton btnIgnore;
private ToolBarButton btnHelp, btnNew, btnCopy, btnDelete, btnSave;
@ -187,7 +194,15 @@ public class ADWindowToolbar extends FToolbar implements EventListener<Event>
//Show more menu pop up
menupopup = new Menupopup();
this.appendChild(menupopup);
//IDEMPIERE-4085
fQueryName = new Combobox();
fQueryName.setTooltiptext(Msg.getMsg(Env.getCtx(),"QueryName"));
fQueryName.setPlaceholder(Msg.getMsg(Env.getCtx(),"QueryName"));
fQueryName.setId(BTNPREFIX + "SearchQuery");
fQueryName.addEventListener(Events.ON_SELECT, this);
LayoutUtils.addSclass("toolbar-searchbox", fQueryName);
btnIgnore = createButton("Ignore", "Ignore", "Ignore");
btnIgnore.setTooltiptext(btnIgnore.getTooltiptext()+ " Alt+Z");
btnHelp = createButton("Help", "Help","Help");
@ -318,7 +333,8 @@ public class ADWindowToolbar extends FToolbar implements EventListener<Event>
this.appendChild(new Separator("vertical"));
}
}
}
} else if (button.isSearchQueryComponent())
this.appendChild(fQueryName);
}
}
if (!ClientInfo.isMobile() && !menuItems.isEmpty()) {
@ -504,14 +520,30 @@ public class ADWindowToolbar extends FToolbar implements EventListener<Event>
}
this.onCtrlKeyEvent(keyEvent);
}
} else if (Events.ON_SELECT.equals(eventName))
{
int index = fQueryName.getSelectedIndex();
if (index < 0) return;
if (index == 0) // no query - refresh
setSelectedUserQuery(null);
else
setSelectedUserQuery(userQueries[index-1]);
doOnClick(event);
}
}
private void doOnClick(Event event) {
this.event = event;
ToolBarButton cComponent = (ToolBarButton) event.getTarget();
String compName = cComponent.getName();
String methodName = "on" + compName.substring(3);
String compName;
String methodName;
if (event.getTarget() == fQueryName) {
methodName = "onSearchQuery";
} else {
ToolBarButton cComponent = (ToolBarButton) event.getTarget();
compName = cComponent.getName();
methodName = "on" + compName.substring(3);
}
Iterator<ToolbarListener> listenerIter = listeners.iterator();
while(listenerIter.hasNext())
{
@ -1172,4 +1204,31 @@ public class ADWindowToolbar extends FToolbar implements EventListener<Event>
{
this.quickFormTabHrchyLevel = quickFormHrchyTabLevel;
}
public void refreshUserQuery(int AD_Tab_ID, int AD_UserQuery_ID) {
fQueryName.getItems().clear();
userQueries = MUserQuery.get(Env.getCtx(), AD_Tab_ID);
fQueryName.appendItem("");
for (int i = 0; i < userQueries.length; i++) {
Comboitem li = fQueryName.appendItem(userQueries[i].getName());
li.setValue(userQueries[i].getAD_UserQuery_ID());
if (AD_UserQuery_ID == userQueries[i].getAD_UserQuery_ID())
fQueryName.setSelectedItem(li);
}
if (AD_UserQuery_ID <= 0 || fQueryName.getItemCount() <= 1)
fQueryName.setValue("");
}
public void setSelectedUserQuery(MUserQuery selectedUserQuery) {
this.selectedUserQuery = selectedUserQuery;
if (selectedUserQuery != null)
fQueryName.setValue(selectedUserQuery.getName());
}
public int getAD_UserQuery_ID() {
if (selectedUserQuery == null)
return 0;
return selectedUserQuery.getAD_UserQuery_ID();
}
}

View File

@ -17,9 +17,9 @@
package org.adempiere.webui.adwindow;
import static org.compiere.model.MSysConfig.ZK_GRID_AFTER_FIND;
import static org.compiere.model.SystemIDs.PROCESS_AD_CHANGELOG_REDO;
import static org.compiere.model.SystemIDs.PROCESS_AD_CHANGELOG_UNDO;
import static org.compiere.model.MSysConfig.ZK_GRID_AFTER_FIND;
import java.text.MessageFormat;
import java.util.ArrayList;
@ -1427,7 +1427,8 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
toolbar.setPressed("Find",adTabbox.getSelectedGridTab().isQueryActive() ||
(!isNewRow && (m_onlyCurrentRows || m_onlyCurrentDays > 0)));
toolbar.refreshUserQuery(adTabbox.getSelectedGridTab().getAD_Tab_ID(), findWindow != null ? findWindow.getAD_UserQuery_ID() : 0);
}
/**
@ -1807,6 +1808,7 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
toolbar.enableRequests(!isNewRow);
toolbar.setPressed("Find", adTabbox.getSelectedGridTab().isQueryActive() ||
(!isNewRow && (m_onlyCurrentRows || m_onlyCurrentDays > 0)));
toolbar.refreshUserQuery(adTabbox.getSelectedGridTab().getAD_Tab_ID(), findWindow != null ? findWindow.getAD_UserQuery_ID() : 0);
toolbar.enablePrint(adTabbox.getSelectedGridTab().isPrinted() && !isNewRow);
toolbar.enableReport(!isNewRow);
@ -2169,6 +2171,7 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
adTabbox.getSelectedTabpanel().switchRowPresentation();
}
}
toolbar.refreshUserQuery(adTabbox.getSelectedGridTab().getAD_Tab_ID(), findWindow.getAD_UserQuery_ID());
}
else
{
@ -2879,6 +2882,67 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
CSVImportAction action = new CSVImportAction(this);
action.fileImport();
}
@Override
public void onSearchQuery() {
if (adTabbox.getSelectedGridTab() == null)
return;
clearTitleRelatedContext();
// The record was not changed locally
if (adTabbox.getDirtyADTabpanel() == null) {
doOnQueryChange();
} else {
onSave(false, false, new Callback<Boolean>() {
@Override
public void onCallback(Boolean result) {
if (result) {
doOnQueryChange();
}
}
});
}
}
/**
* Simulate opening the Find Window, selecting a user query and click ok
*/
public void doOnQueryChange() {
// Gets Fields from AD_Field_v
GridField[] findFields = adTabbox.getSelectedGridTab().getFields();
if (findWindow == null || !findWindow.validate(adTabbox.getSelectedGridTab().getWindowNo(), adTabbox.getSelectedGridTab().getName(),
adTabbox.getSelectedGridTab().getAD_Table_ID(), adTabbox.getSelectedGridTab().getTableName(),
adTabbox.getSelectedGridTab().getWhereExtended(), findFields, 1, adTabbox.getSelectedGridTab().getAD_Tab_ID())) {
findWindow = new FindWindow (adTabbox.getSelectedGridTab().getWindowNo(), adTabbox.getSelectedGridTab().getName(),
adTabbox.getSelectedGridTab().getAD_Table_ID(), adTabbox.getSelectedGridTab().getTableName(),
adTabbox.getSelectedGridTab().getWhereExtended(), findFields, 1, adTabbox.getSelectedGridTab().getAD_Tab_ID());
setupEmbeddedFindwindow();
if (!findWindow.initialize()) {
if (findWindow.getTotalRecords() == 0) {
FDialog.info(curWindowNo, getComponent(), "NoRecordsFound");
}
return;
}
}
findWindow.setAD_UserQuery_ID(toolbar.getAD_UserQuery_ID());
findWindow.advancedOkClick();
MQuery query = findWindow.getQuery();
// Confirmed query
if (query != null) {
m_onlyCurrentRows = false;
adTabbox.getSelectedGridTab().setQuery(query);
adTabbox.getSelectedTabpanel().query(m_onlyCurrentRows, m_onlyCurrentDays, MRole.getDefault().getMaxQueryRecords()); // autoSize
}
adTabbox.getSelectedGridTab().dataRefresh(false);
focusToActivePanel();
findWindow.dispose();
}
/**************************************************************************
* Start Button Process

View File

@ -176,4 +176,9 @@ public interface ToolbarListener
public void onCustomize();
public void onProcess();
/**
* Select query from the user query list
*/
public void onSearchQuery();
}

View File

@ -247,6 +247,9 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
/** IDEMPIERE-2836 User Query Where */
private String m_whereUserQuery;
private ToolBar advancedPanelToolBar;
/**IDEMPIERE-4085*/
private int m_AD_UserQuery_ID = 0;
/**
* FindPanel Constructor
@ -619,7 +622,7 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
//user query
userQueries = MUserQuery.get(Env.getCtx(), m_AD_Tab_ID);
for (int i = 0; i < userQueries.length; i++)
fQueryName.appendItem(userQueries[i].getName());
fQueryName.appendItem(userQueries[i].getName(), userQueries[i].getAD_UserQuery_ID());
fQueryName.setValue("");
fQueryName.addEventListener(Events.ON_SELECT, this);
@ -1255,7 +1258,7 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
public void onEvent(Event event) throws Exception
{
m_createNew = false;
m_createNew = false;
if (Events.ON_CHANGE.equals(event.getName()))
{
if (event.getTarget() == historyCombo)
@ -1320,41 +1323,7 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
}
else if (event.getTarget() == fQueryName)
{
m_whereUserQuery = null;
showAdvanced();
btnSave.setDisabled(false);
btnShare.setDisabled(false);
int index = fQueryName.getSelectedIndex();
if(index < 0) return;
if (winMain.getComponent().getSelectedIndex() != 1)
{
winMain.getComponent().setSelectedIndex(1);
btnSave.setDisabled(m_AD_Tab_ID <= 0);
btnShare.setDisabled(m_AD_Tab_ID <= 0);
historyCombo.setSelectedItem(null);
fQueryName.setReadonly(false);
}
msgLabel.setText("");
if(index == 0)
{ // no query - wipe and start over.
List<?> rowList = advancedPanel.getChildren();
for (int rowIndex = rowList.size() - 1; rowIndex >= 1; rowIndex--)
rowList.remove(rowIndex);
createFields();
}
else {
MUserQuery uq = userQueries[index-1];
// If global query do not allow other users to save the query
if (uq.getAD_User_ID() != Env.getAD_User_ID(Env.getCtx())) {
if (!MRole.PREFERENCETYPE_Client.equals(MRole.getDefault().getPreferenceType()) ||
uq.getAD_Client_ID() != Env.getAD_Client_ID(Env.getCtx())) {
btnSave.setDisabled(true);
btnShare.setDisabled(true);
}
}
parseUserQuery(userQueries[index-1]);
}
onSelectedQueryChanged();
}
else if (event.getTarget() instanceof Tab) {
if (winMain.getComponent().getSelectedIndex() == 1) {
@ -1404,8 +1373,8 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
if ("btnOkSimple".equals(btn.getName()))
{
fQueryName.setSelectedIndex(0);
cmd_ok_Simple();
fQueryName.setValue("");
if (advancedPanel != null) {
advancedPanel.getItems().clear();
}
@ -1477,6 +1446,44 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
}
} // onEvent
public void onSelectedQueryChanged() {
m_whereUserQuery = null;
showAdvanced();
btnSave.setDisabled(false);
btnShare.setDisabled(false);
int index = fQueryName.getSelectedIndex();
if(index < 0) return;
if (winMain.getComponent().getSelectedIndex() != 1)
{
winMain.getComponent().setSelectedIndex(1);
btnSave.setDisabled(m_AD_Tab_ID <= 0);
btnShare.setDisabled(m_AD_Tab_ID <= 0);
historyCombo.setSelectedItem(null);
fQueryName.setReadonly(false);
}
msgLabel.setText("");
if(index == 0)
{ // no query - wipe and start over.
List<?> rowList = advancedPanel.getChildren();
for (int rowIndex = rowList.size() - 1; rowIndex >= 1; rowIndex--)
rowList.remove(rowIndex);
createFields();
}
else {
MUserQuery uq = userQueries[index-1];
// If global query do not allow other users to save the query
if (uq.getAD_User_ID() != Env.getAD_User_ID(Env.getCtx())) {
if (!MRole.PREFERENCETYPE_Client.equals(MRole.getDefault().getPreferenceType()) ||
uq.getAD_Client_ID() != Env.getAD_Client_ID(Env.getCtx())) {
btnSave.setDisabled(true);
btnShare.setDisabled(true);
}
}
parseUserQuery(userQueries[index-1]);
}
}
private void onSimpleTabSelected() {
historyCombo.setDisabled(false);
@ -1491,6 +1498,9 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
private void parseUserQuery(MUserQuery userQuery)
{
if (userQuery == null)
return;
String code = userQuery.getCode();
if (code.startsWith("@SQL=")) {
m_whereUserQuery = "(" + code.substring(code.indexOf("=")+1, code.length()) + ")";
@ -1992,10 +2002,11 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
userQueries = MUserQuery.get(Env.getCtx(), m_AD_Tab_ID);
fQueryName.getItems().clear();
boolean selected = false;
fQueryName.appendItem(m_sNew);
fQueryName.appendItem(m_sNew, 0);
for (int i = 0; i < userQueries.length; i++)
{
Comboitem ci = fQueryName.appendItem(userQueries[i].getName());
ci.setValue(userQueries[i].getAD_UserQuery_ID());
if(value.equals(userQueries[i].getName()))
{
fQueryName.setSelectedItem(ci);
@ -2305,7 +2316,14 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
if (getNoOfRecords(m_query, true) != 0)
dispose();
} // cmd_ok_Advanced
/**
* Simulate the user query selection and click ok
*/
public void advancedOkClick() {
onSelectedQueryChanged();
cmd_ok_Advanced();
}
/**
* Get the number of records of target tab
@ -2736,5 +2754,22 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
advancedPanelToolBar.setVisible(true);
advancedPanel.setVisible(true);
}
public int getAD_UserQuery_ID() {
if (fQueryName.getSelectedIndex() <= 0 || userQueries[fQueryName.getSelectedIndex()-1] == null)
m_AD_UserQuery_ID = 0;
else if (m_AD_UserQuery_ID != userQueries[fQueryName.getSelectedIndex()-1].getAD_UserQuery_ID())
m_AD_UserQuery_ID = userQueries[fQueryName.getSelectedIndex()-1].getAD_UserQuery_ID();
return m_AD_UserQuery_ID;
}
public void setAD_UserQuery_ID(int AD_UserQuery_ID) {
m_AD_UserQuery_ID = AD_UserQuery_ID;
for (Comboitem li : fQueryName.getItems()) {
if (m_AD_UserQuery_ID == (Integer) li.getValue()) {
fQueryName.setSelectedItem(li);
break;
}
}
}
} // FindPanel

View File

@ -94,4 +94,16 @@
}
.font-icon-menuitem i {
vertical-align: middle;
}
.toolbar-searchbox {
margin-right: 10px;
margin-left: 10px;
border: 1px;
padding: 1px;
}
@media screen and (max-width: 768px) {
.toolbar-searchbox {
display: none;
width: 0px;
}
}