details:   https://code.openbravo.com/erp/devel/pi/rev/42769e4ae8b0
changeset: 13818:42769e4ae8b0
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Fri Sep 23 06:01:16 2011 +0200
summary:   Implement workaround for showing &nbsp;

details:   https://code.openbravo.com/erp/devel/pi/rev/e359ca670fb6
changeset: 13819:e359ca670fb6
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Fri Sep 23 06:10:57 2011 +0200
summary:   Fixes issue 18588: Implement new callout functionality
Implement new callout functionality
Solve small issue when closing window that js error occurs

diffstat:

 
modules/org.openbravo.client.application/src/org/openbravo/client/application/ApplicationComponentProvider.java
        |   2 +
 
modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-field.js.ftl
           |   3 +
 
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewFieldHandler.java
           |  17 +
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-textarea.js
 |  22 ++-
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-onchange-registry.js
          |  98 ++++++++++
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js
                  |  81 ++++++-
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-view.js
              |  15 +
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-tab.js
                        |   3 +
 src-db/database/model/tables/AD_FIELD.xml                                      
                                        |   4 +
 src-db/database/model/triggers/AD_FIELD_MOD_TRG.xml                            
                                        |   1 +
 src-db/database/sourcedata/AD_COLUMN.xml                                       
                                        |  34 +++-
 src-db/database/sourcedata/AD_ELEMENT.xml                                      
                                        |  12 +
 src-db/database/sourcedata/AD_FIELD.xml                                        
                                        |  25 ++
 13 files changed, 301 insertions(+), 16 deletions(-)

diffs (truncated from 555 to 300 lines):

diff -r 1912a8ab2d98 -r e359ca670fb6 
modules/org.openbravo.client.application/src/org/openbravo/client/application/ApplicationComponentProvider.java
--- 
a/modules/org.openbravo.client.application/src/org/openbravo/client/application/ApplicationComponentProvider.java
   Thu Sep 22 16:32:46 2011 +0200
+++ 
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/ApplicationComponentProvider.java
   Fri Sep 23 06:10:57 2011 +0200
@@ -195,6 +195,8 @@
     globalResources.add(createStaticResource(
         "web/org.openbravo.client.application/js/grid/ob-view-grid.js", 
false));
     globalResources.add(createStaticResource(
+        
"web/org.openbravo.client.application/js/form/ob-onchange-registry.js", false));
+    globalResources.add(createStaticResource(
         
"web/org.openbravo.client.application/js/utilities/ob-keyboard-manager.js", 
false));
     globalResources.add(createStaticResource(
         "web/org.openbravo.client.application/js/classic/ob-classic-popup.js", 
false));
diff -r 1912a8ab2d98 -r e359ca670fb6 
modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-field.js.ftl
--- 
a/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-field.js.ftl
      Thu Sep 22 16:32:46 2011 +0200
+++ 
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-field.js.ftl
      Fri Sep 23 06:10:57 2011 +0200
@@ -38,6 +38,9 @@
     <#if !field.updatable>
         updatable: false,
     </#if>
+    <#if field.onChangeFunction??>
+        onChangeFunction: '${field.onChangeFunction?js_string}',
+    </#if>
     <#if field.sessionProperty>
         sessionProperty: true,
     </#if>
diff -r 1912a8ab2d98 -r e359ca670fb6 
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewFieldHandler.java
--- 
a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewFieldHandler.java
      Thu Sep 22 16:32:46 2011 +0200
+++ 
b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewFieldHandler.java
      Fri Sep 23 06:10:57 2011 +0200
@@ -331,6 +331,8 @@
   interface OBViewFieldDefinition {
     public int getGridSort();
 
+    public String getOnChangeFunction();
+
     public boolean getShowColSpan();
 
     public boolean getShowStartRow();
@@ -406,6 +408,10 @@
     private String refEntity;
     private Element element;
 
+    public String getOnChangeFunction() {
+      return null;
+    }
+
     public boolean getShowColSpan() {
       return getColSpan() != 1;
     }
@@ -621,6 +627,10 @@
     private String readOnlyIf = "";
     private int gridSort = 0;
 
+    public String getOnChangeFunction() {
+      return field.getOnChangeFunction();
+    }
+
     public boolean getShowColSpan() {
       return getColSpan() != 1;
     }
@@ -944,6 +954,10 @@
 
   public class DefaultVirtualField implements OBViewFieldDefinition {
 
+    public String getOnChangeFunction() {
+      return null;
+    }
+
     public boolean getShowColSpan() {
       return getColSpan() != 4;
     }
@@ -1370,6 +1384,9 @@
   }
 
   public class OBViewFieldSpacer implements OBViewFieldDefinition {
+    public String getOnChangeFunction() {
+      return null;
+    }
 
     public boolean getHasChildren() {
       return false;
diff -r 1912a8ab2d98 -r e359ca670fb6 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-textarea.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-textarea.js
    Thu Sep 22 16:32:46 2011 +0200
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-textarea.js
    Fri Sep 23 06:10:57 2011 +0200
@@ -27,6 +27,10 @@
   validateOnExit: true,
 
   selectOnFocus: false,
+  
+  isDisabled: function() {
+    this.Super('isDisabled', arguments);
+  },
 
   itemHoverHTML: function(item, form) {
     if (this.isDisabled()) {
@@ -41,7 +45,23 @@
 isc.OBPopUpTextAreaItem.addProperties({
   validateOnExit: true,
   canFocus: true,
-  popUpOnEnter: true
+  popUpOnEnter: true,
+  
+  // workaround for this:
+  // http://forums.smartclient.com/showthread.php?p=73173
+  mapValueToDisplay : function (internalValue, a,b,c,d) {
+    var value = this.invokeSuper(isc.StaticTextItem, "mapValueToDisplay", 
+                                 internalValue, a,b,c,d);
+    var asHTML = this.escapeHTML || this.outputAsHTML || this.asHTML;
+    
+    // Don't escape &nbsp; unless that's actually the data value!  
+    if (asHTML && (internalValue === null || internalValue === isc.emptyString)
+        && value === '&nbsp;') {
+      return value;
+    }
+    return this.Super('mapValueToDisplay', arguments);
+  }
+
 });
 
 // hack until this gets answered:
diff -r 1912a8ab2d98 -r e359ca670fb6 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-onchange-registry.js
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-onchange-registry.js
     Fri Sep 23 06:10:57 2011 +0200
@@ -0,0 +1,98 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use. this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo SLU
+ * All portions are Copyright (C) 2011 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+// == OB.CalloutRegistry ==
+// A registry which can be used to register callouts for a certain
+// tab and field combination. Multiple callouts can be registered
+// for one field.
+OB.OnChangeRegistry = {
+    registry: [],
+    
+    register: function(tabId, field, callback, id) {
+      var tabEntry, fieldEntry, i, overwritten = false;
+      
+      if (!this.registry[tabId]) {
+        this.registry[tabId] = {};
+      }
+      
+      tabEntry = this.registry[tabId];
+      if (!tabEntry[field]) {
+        tabEntry[field] = [];
+      }
+      
+      if (id && !callback.id) {
+        callback.id = id;
+      }
+      
+      // just set a default sort if not defined
+      if (callback.sort !== 0 && !callback.sort) {
+        callback.sort = 100;
+      }
+      
+      // check if there is one with the same name
+      for (i = 0; i < tabEntry[field].length; i++) {
+        if (tabEntry[field][i] && tabEntry[field][i].id === callback.id) {
+          tabEntry[field][i] = callback;
+          overwritten = true;
+          break;
+        }
+      }
+      
+      // add
+      if (!overwritten) {
+        tabEntry[field].push(callback);        
+      }
+      
+      // and sort according to the sort property
+      tabEntry[field].sortByProperty('sort', true);
+    },
+    
+    hasOnChange: function(tabId, item) {
+      return this.getFieldEntry(tabId, item);
+    },
+    
+    getFieldEntry: function(tabId, item) {
+      var tabEntry, field = item.name;
+      if (!this.registry[tabId]) {
+        return;
+      }
+      tabEntry = this.registry[tabId];
+      return tabEntry[field];  
+    },
+    
+    call: function(tabId, item, view, form, grid) {
+      var callResult, fieldEntry = this.getFieldEntry(tabId, item), i; 
+
+      if (!fieldEntry) {
+        return;
+      }
+      for (i = 0; i < fieldEntry.length; i++) {
+        if (fieldEntry[i]) {
+          callResult = fieldEntry[i](item, view, form, grid);
+          if (callResult === false) {
+            return;
+          }
+        }
+      }
+    }
+};
+
+OB.OnChangeRegistry.TestFunction = function(item) {
+  alert('You changed ' + item.name);
+};
\ No newline at end of file
diff -r 1912a8ab2d98 -r e359ca670fb6 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js
     Thu Sep 22 16:32:46 2011 +0200
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js
     Fri Sep 23 06:10:57 2011 +0200
@@ -862,9 +862,9 @@
       (isc.SimpleType.getType(field.type).inheritsFrom === 'date' ||
       isc.SimpleType.getType(field.type).inheritsFrom === 'datetime');
       if (isDate) {
-        this.setValue(field.name, isc.Date.parseSchemaDate(columnValue.value));
+        this.setItemValue(field.name, 
isc.Date.parseSchemaDate(columnValue.value));
       } else if(columnValue.hasDateDefault){
-        this.setValue(field.name, columnValue.classicValue);
+        this.setItemValue(field.name, columnValue.classicValue);
       } else {
         
         // set the identifier/display field if the identifier is passed also
@@ -888,21 +888,21 @@
             // datasource and the field displayfield contains a dot, otherwise 
             // it is a direct field
             if (field.displayField && field.displayField.contains('.') && 
!this.getField(field.displayField) && !field.optionDataSource && 
!field.getDataSource()) {
-              field.form.setValue(field.displayField, identifier);
+              field.form.setItemValue(field.displayField, identifier);
             } else if (!field.displayField) {
-              field.form.setValue(field.name + '.' + OB.Constants.IDENTIFIER, 
identifier);
+              field.form.setItemValue(field.name + '.' + 
OB.Constants.IDENTIFIER, identifier);
             }
           }
         }
         
-        this.setValue(field.name, assignValue);
+        this.setItemValue(field.name, assignValue);
       }
     } else {
       // note: do not use clearvalue as this removes the value from the form
       // which results it to not be sent to the server anymore
       this.setValue(field.name, null);
       if (this.getValue(field.name + '.' + OB.Constants.IDENTIFIER)) {
-        this.setValue(field.name + '.' + OB.Constants.IDENTIFIER, null);
+        this.setItemValue(field.name + '.' + OB.Constants.IDENTIFIER, null);
       }
     }
     
@@ -1005,9 +1005,42 @@
     this.setValue(fldName + '_textualValue', textValue);
   },
   
+  // calls setValue and the onchange handling
+  setItemValue: function(item, value) {
+    var currentValue;
+
+    if (isc.isA.String(item)) {
+       
+      // not an item, set and bail
+      if (!this.getField(item)) {
+        this.setValue(item, value);
+        return;
+      }
+      item = this.getField(item);
+    }
+    currentValue = item.getValue();
+    
+    // no change go away
+    if (item.compareValues(value, currentValue)) {
+      return;
+    }
+    this.setValue(item, value);
+
+    // fire any new callouts
+    if (this.view) {
+      view = this.view;
+    } else if (this.grid && this.grid.view){
+      view = this.grid.view;
+    }
+
+    if (view && OB.OnChangeRegistry.hasOnChange(view.tabId, item)) {
+      OB.OnChangeRegistry.call(view.tabId, item, view, view.viewForm, 
view.viewGrid);
+    }
+  },
+  

------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2dcopy2
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to