details:   /erp/devel/pi/rev/271dd023d1c8
changeset: 9735:271dd023d1c8
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Wed Jan 12 16:41:12 2011 +0100
summary:   [process] Change button label based on record values

details:   /erp/devel/pi/rev/beff16ac0034
changeset: 9736:beff16ac0034
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Wed Jan 12 17:37:50 2011 +0100
summary:   [process] Hide buttons when there's no exactly 1 selected record

diffstat:

 
modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-tab.js.ftl
 |   7 +-
 
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewTab.java
        |  38 +++++++++-
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-action-button.js
       |  16 ++++
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-standard-view.js
       |  10 ++
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-toolbar.js
             |  17 ++++-
 5 files changed, 85 insertions(+), 3 deletions(-)

diffs (171 lines):

diff -r 9f15a1dcb545 -r beff16ac0034 
modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-tab.js.ftl
--- 
a/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-tab.js.ftl
        Wed Jan 12 16:23:18 2011 +0100
+++ 
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-tab.js.ftl
        Wed Jan 12 17:37:50 2011 +0100
@@ -49,7 +49,12 @@
       {id: '${field.id?js_string}', 
        title: '${field.label?js_string}',
        obManualURL: '${field.url}',
-       command: '${field.command}'
+       command: '${field.command}',
+       property: '${field.propertyName?js_string}',
+       labelValue: {<#list field.labelValues as value>
+           '${value.value}': '${value.label?js_string}'<#if 
field_has_next>,</#if>
+       </#list>
+         }
       }<#if field_has_next>,</#if>
     </#list>],
     
diff -r 9f15a1dcb545 -r beff16ac0034 
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewTab.java
--- 
a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewTab.java
       Wed Jan 12 16:23:18 2011 +0100
+++ 
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewTab.java
       Wed Jan 12 17:37:50 2011 +0100
@@ -245,13 +245,17 @@
     private String id;
     private String label;
     private String url;
+    private String propertyName;
+    private List<Value> labelValues;
 
     public ButtonField(Field fld) {
       id = fld.getId();
       label = OBViewUtil.getLabel(fld);
+      Column column = fld.getColumn();
+
+      propertyName = 
KernelUtils.getInstance().getPropertyFromColumn(column).getName();
 
       // Define command
-      Column column = fld.getColumn();
       Process process = column.getProcess();
       if (process != null) {
         String manualProcessMapping = null;
@@ -282,6 +286,26 @@
           url = Utility.getTabURL(fld.getTab().getId(), "E", false);
         }
       }
+
+      labelValues = new ArrayList<Value>();
+      if (column.getReferenceSearchKey() != null) {
+        for (org.openbravo.model.ad.domain.List valueList : 
column.getReferenceSearchKey()
+            .getADListList()) {
+          Value value = new Value();
+          value.label = valueList.getName();
+          value.value = valueList.getSearchKey();
+
+          labelValues.add(value);
+        }
+      }
+    }
+
+    public String getPropertyName() {
+      return propertyName;
+    }
+
+    public List<Value> getLabelValues() {
+      return labelValues;
     }
 
     public String getUrl() {
@@ -318,5 +342,17 @@
       this.id = id;
     }
 
+    public class Value {
+      private String value;
+      private String label;
+
+      public String getValue() {
+        return value;
+      }
+
+      public String getLabel() {
+        return label;
+      }
+    }
   }
 }
diff -r 9f15a1dcb545 -r beff16ac0034 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-action-button.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-action-button.js
      Wed Jan 12 16:23:18 2011 +0100
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-action-button.js
      Wed Jan 12 17:37:50 2011 +0100
@@ -91,6 +91,22 @@
         };
       OB.Layout.ViewManager.openView('OBClassicWindow', windowParams);
     }
+  },
+  
+  refresh: function(record, hide) {
+    if (hide || !record) {
+      this.hide();
+      return;
+    }
+    
+    //TODO: implement display/read only logic
+    this.show();
+    
+    var label = this.labelValue[record[this.property]];
+    if (!label){
+      label = this.title;
+    }
+    this.setTitle(label);
   }
   
 });
diff -r 9f15a1dcb545 -r beff16ac0034 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-standard-view.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-standard-view.js
      Wed Jan 12 16:23:18 2011 +0100
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-standard-view.js
      Wed Jan 12 17:37:50 2011 +0100
@@ -771,6 +771,8 @@
     this.updateChildCount();
     this.updateTabTitle();
     this.lastRecordSelected = this.viewGrid.getSelectedRecord();
+    
+    this.toolBar.refreshToolbarButtons();
   },
   
   // ** {{{ parentRecordSelected }}} **
@@ -1109,6 +1111,14 @@
     }
   },
   
+  getCurrentValues: function() {
+    if (this.isShowingForm) {
+      return this.viewForm.getValues();
+    } else {
+      return this.viewGrid.getSelectedRecord();
+    }
+  },
+    
   //++++++++++++++++++ Reading context ++++++++++++++++++++++++++++++
   
   getContextInfo: function(onlySessionProperties, classicMode){
diff -r 9f15a1dcb545 -r beff16ac0034 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-toolbar.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-toolbar.js
    Wed Jan 12 16:23:18 2011 +0100
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-toolbar.js
    Wed Jan 12 17:37:50 2011 +0100
@@ -11,7 +11,7 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2010 Openbravo SLU
+ * All portions are Copyright (C) 2010-2011 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -553,6 +553,21 @@
     }
     return;
   },
+
+  // ** {{{ refreshToolbarButtons }}} **
+  //
+  // Refreshes all buttons in the toolbar based on current record selection
+  //
+  refreshToolbarButtons: function() {
+    var buttons = this.getRightMembers();
+    var hideAllButtons = this.view.viewGrid.getSelectedRecords().length !== 1;
+    
+    for (var i = 0; i < buttons.length; i++){
+      if (buttons[i].refresh){
+        buttons[i].refresh(this.view.getCurrentValues(), hideAllButtons);
+      }
+    }
+  },
   
   addMembers: 'null',
   

------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to