IDEMPIERE-2556 User preferences window configurable / peer review

This commit is contained in:
Carlos Ruiz 2015-04-24 12:08:56 -05:00
parent 0a5a14eb51
commit 6be02013d7
5 changed files with 78 additions and 69 deletions

View File

@ -335,10 +335,6 @@ INSERT INTO AD_Sequence (Name,CurrentNext,IsAudited,StartNewYear,Description,IsA
UPDATE AD_Tab SET WhereClause='AD_User_ID=@#AD_User_ID@ AND AD_Client_ID=@#AD_Client_ID@',Updated=TO_DATE('2015-04-20 22:11:12','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Tab_ID=200189 UPDATE AD_Tab SET WhereClause='AD_User_ID=@#AD_User_ID@ AND AD_Client_ID=@#AD_Client_ID@',Updated=TO_DATE('2015-04-20 22:11:12','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Tab_ID=200189
; ;
-- Apr 20, 2015 10:11:23 PM CEST
UPDATE C_AcctProcessor SET DateLastRun=TO_DATE('2015-04-20 22:11:22','YYYY-MM-DD HH24:MI:SS'), DateNextRun=TO_DATE('2015-04-20 22:21:22','YYYY-MM-DD HH24:MI:SS'),Updated=TO_DATE('2015-04-20 22:11:23','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE C_AcctProcessor_ID=100
;
-- Apr 20, 2015 10:11:33 PM CEST -- Apr 20, 2015 10:11:33 PM CEST
UPDATE AD_Column SET DefaultValue='Y',Updated=TO_DATE('2015-04-20 22:11:33','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Column_ID=212173 UPDATE AD_Column SET DefaultValue='Y',Updated=TO_DATE('2015-04-20 22:11:33','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Column_ID=212173
; ;
@ -371,6 +367,6 @@ INSERT INTO AD_IndexColumn (AD_Client_ID,AD_Org_ID,AD_IndexColumn_ID,AD_IndexCol
CREATE UNIQUE INDEX ad_userpreference_user_idx ON AD_UserPreference (AD_User_ID,AD_Client_ID) CREATE UNIQUE INDEX ad_userpreference_user_idx ON AD_UserPreference (AD_User_ID,AD_Client_ID)
; ;
SELECT register_migration_script('201504180139_IDEMPIERE-2556.sql') FROM dual SELECT register_migration_script('201504231737_IDEMPIERE-2556.sql') FROM dual
; ;

View File

@ -331,10 +331,6 @@ INSERT INTO AD_Sequence (Name,CurrentNext,IsAudited,StartNewYear,Description,IsA
UPDATE AD_Tab SET WhereClause='AD_User_ID=@#AD_User_ID@ AND AD_Client_ID=@#AD_Client_ID@',Updated=TO_TIMESTAMP('2015-04-20 22:11:12','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Tab_ID=200189 UPDATE AD_Tab SET WhereClause='AD_User_ID=@#AD_User_ID@ AND AD_Client_ID=@#AD_Client_ID@',Updated=TO_TIMESTAMP('2015-04-20 22:11:12','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Tab_ID=200189
; ;
-- Apr 20, 2015 10:11:23 PM CEST
UPDATE C_AcctProcessor SET DateLastRun=TO_TIMESTAMP('2015-04-20 22:11:22','YYYY-MM-DD HH24:MI:SS'), DateNextRun=TO_TIMESTAMP('2015-04-20 22:21:22','YYYY-MM-DD HH24:MI:SS'),Updated=TO_TIMESTAMP('2015-04-20 22:11:23','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE C_AcctProcessor_ID=100
;
-- Apr 20, 2015 10:11:33 PM CEST -- Apr 20, 2015 10:11:33 PM CEST
UPDATE AD_Column SET DefaultValue='Y',Updated=TO_TIMESTAMP('2015-04-20 22:11:33','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Column_ID=212173 UPDATE AD_Column SET DefaultValue='Y',Updated=TO_TIMESTAMP('2015-04-20 22:11:33','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Column_ID=212173
; ;
@ -367,6 +363,6 @@ INSERT INTO AD_IndexColumn (AD_Client_ID,AD_Org_ID,AD_IndexColumn_ID,AD_IndexCol
CREATE UNIQUE INDEX ad_userpreference_user_idx ON AD_UserPreference (AD_User_ID,AD_Client_ID) CREATE UNIQUE INDEX ad_userpreference_user_idx ON AD_UserPreference (AD_User_ID,AD_Client_ID)
; ;
SELECT register_migration_script('201504180139_IDEMPIERE-2556.sql') FROM dual SELECT register_migration_script('201504231737_IDEMPIERE-2556.sql') FROM dual
; ;

View File

@ -1,3 +1,28 @@
/**********************************************************************
* This file is part of iDempiere ERP Open Source *
* http://www.idempiere.org *
* *
* Copyright (C) Contributors *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *
* MA 02110-1301, USA. *
* *
* Contributors: *
* - Diego Ruiz - BX Service GmbH *
**********************************************************************/
package org.compiere.model; package org.compiere.model;
import java.sql.ResultSet; import java.sql.ResultSet;
@ -6,16 +31,11 @@ import java.util.Properties;
import org.compiere.util.Env; import org.compiere.util.Env;
public class MUserPreference extends X_AD_UserPreference{ public class MUserPreference extends X_AD_UserPreference{
/** Auto Commit */
public static final String P_AUTO_COMMIT = "AutoCommit";
public static final String P_AUTO_NEW = "AutoNew";
/** /**
* *
*/ */
private static final long serialVersionUID = 2406291562249262021L; private static final long serialVersionUID = 4653362918831026642L;
public MUserPreference(Properties ctx, int AD_UserPreference_ID, public MUserPreference(Properties ctx, int AD_UserPreference_ID,
String trxName) { String trxName) {
super(ctx, AD_UserPreference_ID, trxName); super(ctx, AD_UserPreference_ID, trxName);
@ -45,7 +65,7 @@ public class MUserPreference extends X_AD_UserPreference{
} //createUserPreferences } //createUserPreferences
public static MUserPreference getUserPreference(int AD_User_ID, int AD_Client_ID){ public static MUserPreference getUserPreference(int AD_User_ID, int AD_Client_ID){
Query query = new Query(Env.getCtx(), MUserPreference.Table_Name, "NVL(AD_User_ID,0) = ? AND NVL(AD_Client_ID,0) = ?", null); Query query = new Query(Env.getCtx(), MUserPreference.Table_Name, "AD_User_ID=? AND AD_Client_ID=?", null);
MUserPreference preferences = query.setParameters(new Object[]{AD_User_ID, AD_Client_ID}).firstOnly(); MUserPreference preferences = query.setParameters(new Object[]{AD_User_ID, AD_Client_ID}).firstOnly();
if(preferences==null){ if(preferences==null){
@ -70,18 +90,38 @@ public class MUserPreference extends X_AD_UserPreference{
return ""; return "";
} }
public void fillPreferences(){
MTable t = new MTable(Env.getCtx(), MUserPreference.Table_ID, null);
for (MColumn c: t.getColumns(false)){
if( !c.getColumnName().equals("AD_Client_ID") && !c.getColumnName().equals("AD_Org_ID") &&
!c.getColumnName().equals("AD_User_ID") && !c.getColumnName().equals("AD_UserPreference_ID") &&
!c.getColumnName().equals("AD_UserPreference_UU") && !c.getColumnName().equals("Created") &&
!c.getColumnName().equals("CreatedBy") && !c.getColumnName().equals("Updated") &&
!c.getColumnName().equals("UpdatedBy") && !c.getColumnName().equals("IsActive") )
Env.getCtx().setProperty(c.getColumnName(), getPreference(c.getColumnName())); public void fillPreferences(){
for (int i=0; i < get_ColumnCount(); i++) {
String colName = get_ColumnName(i);
if (! ( "AD_Client_ID".equals(colName)
|| "AD_Org_ID".equals(colName)
|| "AD_User_ID".equals(colName)
|| "AD_UserPreference_ID".equals(colName)
|| "AD_UserPreference_UU".equals(colName)
|| "Created".equals(colName)
|| "CreatedBy".equals(colName)
|| "Updated".equals(colName)
|| "UpdatedBy".equals(colName)
|| "IsActive".equals(colName))) {
Env.setContext(getCtx(), colName, getPreference(colName));
Env.setContext(getCtx(), "P|" + colName, getPreference(colName));
}
} }
} }
@Override
protected boolean beforeSave(boolean newRecord) {
if (getAD_Org_ID() != 0)
setAD_Org_ID(0);
return true;
}
@Override
protected boolean afterSave(boolean newRecord, boolean success) {
if (success)
fillPreferences();
return success;
}
} }

View File

@ -28,12 +28,14 @@ import org.compiere.util.Language;
* @author hengsin * @author hengsin
* @author Teo Sarca, www.arhipac.ro * @author Teo Sarca, www.arhipac.ro
* <li>FR [ 2694043 ] Query. first/firstOnly usage best practice * <li>FR [ 2694043 ] Query. first/firstOnly usage best practice
*
* IDEMPIERE-2556 - this class is now for global code-managed preferences - user selectable preferences are managed in table AD_UserPreference
*/ */
public final class UserPreference implements Serializable { public final class UserPreference implements Serializable {
/** /**
* *
*/ */
private static final long serialVersionUID = -9128019013390545760L; private static final long serialVersionUID = -2619860653017483658L;
/** Language */ /** Language */
public static final String P_LANGUAGE = "Language"; public static final String P_LANGUAGE = "Language";
@ -52,17 +54,9 @@ public final class UserPreference implements Serializable {
public static final String P_WAREHOUSE = "Warehouse"; public static final String P_WAREHOUSE = "Warehouse";
private static final String DEFAULT_WAREHOUSE = ""; private static final String DEFAULT_WAREHOUSE = "";
/** Auto Commit */
public static final String P_AUTO_COMMIT = "AutoCommit";
private static final String DEFAULT_AUTO_COMMIT = "Y";
/** Language Name Context **/ /** Language Name Context **/
public static final String LANGUAGE_NAME = "#LanguageName"; public static final String LANGUAGE_NAME = "#LanguageName";
/** Auto New **/
public static final String P_AUTO_NEW = "AutoNew";
public static final String DEFAULT_AUTO_NEW = "Y";
/** Menu Collapsed **/ /** Menu Collapsed **/
public static final String P_MENU_COLLAPSED = "MenuCollapsed"; public static final String P_MENU_COLLAPSED = "MenuCollapsed";
public static final String DEFAULT_MENU_COLLAPSED = "N"; public static final String DEFAULT_MENU_COLLAPSED = "N";
@ -82,8 +76,6 @@ public final class UserPreference implements Serializable {
P_CLIENT, P_CLIENT,
P_ORG, P_ORG,
P_WAREHOUSE, P_WAREHOUSE,
P_AUTO_COMMIT,
P_AUTO_NEW,
P_MENU_COLLAPSED, P_MENU_COLLAPSED,
P_HELP_COLLAPSED, P_HELP_COLLAPSED,
P_HEADER_COLLAPSED}; P_HEADER_COLLAPSED};
@ -94,8 +86,6 @@ public final class UserPreference implements Serializable {
DEFAULT_CLIENT, DEFAULT_CLIENT,
DEFAULT_ORG, DEFAULT_ORG,
DEFAULT_WAREHOUSE, DEFAULT_WAREHOUSE,
DEFAULT_AUTO_COMMIT,
DEFAULT_AUTO_NEW,
DEFAULT_MENU_COLLAPSED, DEFAULT_MENU_COLLAPSED,
DEFAULT_HELP_COLLAPSED, DEFAULT_HELP_COLLAPSED,
DEFAULT_HEADER_COLLAPSED}; DEFAULT_HEADER_COLLAPSED};

View File

@ -32,7 +32,6 @@ import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events; import org.zkoss.zk.ui.event.Events;
import org.zkoss.zul.A; import org.zkoss.zul.A;
import org.zkoss.zul.Div; import org.zkoss.zul.Div;
import org.zkoss.zul.Separator;
/** /**
* *
* @author hengsin * @author hengsin
@ -92,6 +91,12 @@ public class WPreference extends WQuickEntry implements EventListener<Event> {
private void init() { private void init() {
Div div = new Div(); Div div = new Div();
div.setStyle("background-color: transparent !important; border: none; margin: 5px;");
morePreferences= new A();
morePreferences.setLabel(Msg.translate(Env.getCtx(), "MorePreferences"));
morePreferences.addEventListener(Events.ON_CLICK, this);
div.appendChild(morePreferences);
this.appendChild(div);
if (Env.getAD_Client_ID(Env.getCtx()) <= 20 && Env.getAD_User_ID(Env.getCtx()) <= 102) { if (Env.getAD_Client_ID(Env.getCtx()) <= 20 && Env.getAD_User_ID(Env.getCtx()) <= 102) {
adempiereSys = new WYesNoEditor("AdempiereSys", Msg.getMsg(Env.getCtx(), "AdempiereSys", true), adempiereSys = new WYesNoEditor("AdempiereSys", Msg.getMsg(Env.getCtx(), "AdempiereSys", true),
@ -113,29 +118,6 @@ public class WPreference extends WQuickEntry implements EventListener<Event> {
logMigrationScript.setValue(Env.getCtx().getProperty("LogMigrationScript")); logMigrationScript.setValue(Env.getCtx().getProperty("LogMigrationScript"));
} }
div = new Div();
div.setStyle("background-color: transparent !important; border: none; margin: 5px;");
addgadgets= new A();
addgadgets.setLabel( Msg.translate(Env.getCtx(), "ManageGadgets"));
addgadgets.addEventListener(Events.ON_CLICK, this);
div.appendChild(addgadgets);
this.appendChild(div);
div = new Div();
div.setStyle("background-color: transparent !important; border: none; margin: 5px;");
morePreferences= new A();
morePreferences.setLabel(Msg.translate(Env.getCtx(), "MorePreferences"));
morePreferences.addEventListener(Events.ON_CLICK, this);
div.appendChild(morePreferences);
this.appendChild(div);
Separator separator = new Separator();
separator.setSpacing("20px");
div = new Div();
div.setStyle("background-color: transparent !important; border: none; margin: 5px;");
div.appendChild(separator);
this.appendChild(div);
ToolBar toolbar = new ToolBar(); ToolBar toolbar = new ToolBar();
toolbar.setAlign("end"); toolbar.setAlign("end");
this.appendChild(toolbar); this.appendChild(toolbar);
@ -147,6 +129,14 @@ public class WPreference extends WQuickEntry implements EventListener<Event> {
toolbar.appendChild(btn); toolbar.appendChild(btn);
toolbar.setStyle("border: none"); toolbar.setStyle("border: none");
div = new Div();
div.setStyle("background-color: transparent !important; border: none; margin: 5px;");
addgadgets= new A();
addgadgets.setLabel( Msg.translate(Env.getCtx(), "ManageGadgets"));
addgadgets.addEventListener(Events.ON_CLICK, this);
div.appendChild(addgadgets);
this.appendChild(div);
} //init } //init
public void onEvent(Event event) throws Exception { public void onEvent(Event event) throws Exception {
@ -179,9 +169,6 @@ public class WPreference extends WQuickEntry implements EventListener<Event> {
private void onSave() { private void onSave() {
actionSave(); actionSave();
//Set all preferences in the Context
preferences.fillPreferences();
// Log Migration Script and AdempiereSys are just in-memory preferences, must not be saved // Log Migration Script and AdempiereSys are just in-memory preferences, must not be saved
if (logMigrationScript != null) if (logMigrationScript != null)
Env.getCtx().setProperty("LogMigrationScript", (Boolean)logMigrationScript.getValue() ? "Y" : "N"); Env.getCtx().setProperty("LogMigrationScript", (Boolean)logMigrationScript.getValue() ? "Y" : "N");