modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-form.js.ftl
author Inigo Sanchez <inigo.sanchez@openbravo.com>
Sun, 13 Dec 2015 18:52:55 +0100
changeset 28121 d9584faf499b
parent 28028 16d5a95d9323
child 28252 e91d7a38fa6b
permissions -rw-r--r--
Fixed issue 31627:Fields with display logic equals to false cause js error

The problem was when a display logic was false (not a condition evaluated
to false) an error is thrown in the console. This error warned about trivial
comparisons (false === false).

To resolved this problem it has been added some condition to check this special
case. When a display logic is false, it is avoid this unecessary comparasion.

Now when a display logic is false is avoid to make this trivial comparison.
martin@13359
     1
<#--
staff@10778
     2
/*
staff@10778
     3
 *************************************************************************
staff@10778
     4
 * The contents of this file are subject to the Openbravo  Public  License
harpreet@9091
     5
 * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
staff@10778
     6
 * Version 1.1  with a permitted attribution clause; you may not  use this
staff@10778
     7
 * file except in compliance with the License. You  may  obtain  a copy of
staff@10778
     8
 * the License at http://www.openbravo.com/legal/license.html 
staff@10778
     9
 * Software distributed under the License  is  distributed  on  an "AS IS"
staff@10778
    10
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
staff@10778
    11
 * License for the specific  language  governing  rights  and  limitations
staff@10778
    12
 * under the License.
staff@10778
    13
 * The Original Code is Openbravo ERP.
staff@10778
    14
 * The Initial Developer of the Original Code is Openbravo SLU
inigo@28023
    15
 * All portions are Copyright (C) 2010-2015 Openbravo SLU
staff@10778
    16
 * All Rights Reserved.
staff@10778
    17
 * Contributor(s):  ______________________________________.
staff@10778
    18
 ************************************************************************
staff@10778
    19
*/
martin@13359
    20
-->
martin@13359
    21
{
martin@13779
    22
    <#if data.fieldHandler.hasStatusBarFields>
martin@13779
    23
    <#--
martin@13779
    24
    // this this is the view    
martin@13779
    25
    -->
inigo@28023
    26
    statusBarFields: this.statusBarFields<#if data.fieldHandler.hasFieldsWithReadOnlyIf || data.fieldHandler.hasFieldsWithShowIf>,</#if>
martin@13779
    27
    </#if>
martin@13740
    28
    
martin@13740
    29
<#--
martin@10659
    30
    // except for the fields all other form properties should be added to the formProperties
martin@10659
    31
    // the formProperties are re-used for inline grid editing
martin@13740
    32
-->
inigo@28023
    33
   <#if data.fieldHandler.hasFieldsWithReadOnlyIf || data.fieldHandler.hasFieldsWithShowIf>
martin@10659
    34
    obFormProperties: {
martin@10659
    35
      onFieldChanged: function(form, item, value) {
martin@10659
    36
        var f = form || this,
martin@10659
    37
            context = this.view.getContextInfo(false, true),
augusto@19790
    38
            currentValues = isc.shallowClone(f.view.getCurrentValues()), otherItem,
asier@15346
    39
            disabledFields, i;
augusto@19790
    40
            OB.Utilities.fixNull250(currentValues);
martin@13740
    41
        <#list data.fieldHandler.fields as field>
inigo@28025
    42
        <#if field.readOnlyIf != "" && field.showIf == "">
inigo@28121
    43
        // Applying read only.
inigo@28023
    44
           f.disableItem('${field.name}', ${field.readOnlyIf});
inigo@28121
    45
        <#else>
inigo@28121
    46
        <#if field.readOnlyIf == "" && field.showIf != "">
inigo@28023
    47
        // Applying display logic in grid.
inigo@28023
    48
        if (!this.view.isShowingForm) {
inigo@28121
    49
        <#if field.showIf == "false">
inigo@28121
    50
           f.disableItem('${field.name}', true);
inigo@28121
    51
        <#else>
inigo@28025
    52
           f.disableItem('${field.name}', (${field.showIf}) === false);
inigo@28121
    53
        </#if>
inigo@28023
    54
        }
inigo@28121
    55
        <#else>
inigo@28121
    56
        <#if field.readOnlyIf != "" && field.showIf != "">
inigo@28121
    57
        // Applying display logic and read only in grid/form.
inigo@28024
    58
        if (!this.view.isShowingForm) {
inigo@28121
    59
        <#if field.showIf == "false">
inigo@28121
    60
           // If display logic has a false value, it is only necessary take into account the read only logic.
inigo@28121
    61
           f.disableItem('${field.name}', (${field.readOnlyIf}));
inigo@28121
    62
        <#else>
inigo@28025
    63
           f.disableItem('${field.name}', (${field.readOnlyIf}) || (${field.showIf}) === false);
inigo@28121
    64
        </#if>
inigo@28028
    65
        } else {
inigo@28027
    66
           f.disableItem('${field.name}', ${field.readOnlyIf});
inigo@28023
    67
        }
martin@10659
    68
        </#if>
inigo@28121
    69
        </#if>
inigo@28121
    70
        </#if>
martin@10659
    71
        </#list>
asier@15346
    72
        // disable forced in case the fields are set as read only per role
asier@15346
    73
        disabledFields = form.view.disabledFields;
asier@15346
    74
        if (disabledFields) {
asier@15346
    75
          for (i=0; i<disabledFields.length; i++){
asier@15346
    76
            f.disableItem(disabledFields[i], true);
asier@15346
    77
          }
asier@15346
    78
        }
martin@10659
    79
      }
ivan@9947
    80
    }
martin@13779
    81
    </#if>
martin@13740
    82
}