modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/templates/datasource.ftl
author Harpreet Singh <harpreet@openbravo.com>
Fri, 10 Dec 2010 19:47:45 +0100
changeset 9076 c4f1a5c7d7c2
child 10224 0b0dae5828d5
permissions -rw-r--r--
Added 3.0 modules to modules dir and changed the VERSION number
harpreet@9076
     1
<#--
harpreet@9076
     2
 *************************************************************************
harpreet@9076
     3
 * The contents of this file are subject to the Openbravo  Public  License
harpreet@9076
     4
 * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
harpreet@9076
     5
 * Version 1.1  with a permitted attribution clause; you may not  use this
harpreet@9076
     6
 * file except in compliance with the License. You  may  obtain  a copy of
harpreet@9076
     7
 * the License at http://www.openbravo.com/legal/license.html 
harpreet@9076
     8
 * Software distributed under the License  is  distributed  on  an "AS IS"
harpreet@9076
     9
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
harpreet@9076
    10
 * License for the specific  language  governing  rights  and  limitations
harpreet@9076
    11
 * under the License. 
harpreet@9076
    12
 * The Original Code is Openbravo ERP. 
harpreet@9076
    13
 * The Initial Developer of the Original Code is Openbravo SLU 
harpreet@9076
    14
 * All portions are Copyright (C) 2009-2010 Openbravo SLU 
harpreet@9076
    15
 * All Rights Reserved. 
harpreet@9076
    16
 * Contributor(s):  ______________________________________.
harpreet@9076
    17
 ************************************************************************
harpreet@9076
    18
-->
harpreet@9076
    19
/* jslint */
harpreet@9076
    20
<#-- 
harpreet@9076
    21
if the createStatement parameter is passed then only create the 
harpreet@9076
    22
javascript with the isc.RestDataSource.create statement.
harpreet@9076
    23
harpreet@9076
    24
use these directives to compress during template generation
harpreet@9076
    25
although the same is done by the compressor
harpreet@9076
    26
<@compress single_line=true>
harpreet@9076
    27
</@compress>
harpreet@9076
    28
-->
harpreet@9076
    29
<#if data.getParameter("_onlyGenerateCreateStatement") != "">
harpreet@9076
    30
    <@generateDataSource data=data/>
harpreet@9076
    31
</#if>
harpreet@9076
    32
<#if data.getParameter("create") != "">
harpreet@9076
    33
    <@generateDataSource data=data/>;
harpreet@9076
    34
</#if>
harpreet@9076
    35
harpreet@9076
    36
<#macro generateDataSource data>
harpreet@9076
    37
    OB.Datasource.create({
harpreet@9076
    38
<#if data.getParameter("_onlyGenerateCreateStatement") == "" || data.getParameter("create") != "">
harpreet@9076
    39
        ID:'${data.id}',
harpreet@9076
    40
</#if>
harpreet@9076
    41
        dataURL:'${data.dataUrl?js_string}${data.name?js_string}'
harpreet@9076
    42
        , recordXPath: '/response/data', dataFormat: 'json'
harpreet@9076
    43
        , operationBindings:  [{operationType: 'fetch', dataProtocol: 'postParams', requestProperties:{httpMethod: 'POST'}} 
harpreet@9076
    44
        , {operationType: 'add', dataProtocol: 'postMessage'}
harpreet@9076
    45
        , {operationType: 'remove', dataProtocol: 'postParams', requestProperties:{httpMethod: 'DELETE'}}
harpreet@9076
    46
        , {operationType: 'update', dataProtocol: 'postMessage', requestProperties:{httpMethod: 'PUT'}}
harpreet@9076
    47
        ], requestProperties : { params : {
harpreet@9076
    48
                <#list data.getParameterNames() as key>
harpreet@9076
    49
                    ${key} : '${data.getParameter(key)?js_string}'<#if key_has_next>,</#if>     
harpreet@9076
    50
                </#list>
harpreet@9076
    51
                }
harpreet@9076
    52
        }, fields:[
harpreet@9076
    53
<#list data.dataSourceProperties as property>
harpreet@9076
    54
    <@generateField property=property /><#if property_has_next>,</#if>
harpreet@9076
    55
</#list>
harpreet@9076
    56
    ]})
harpreet@9076
    57
</#macro>
harpreet@9076
    58
harpreet@9076
    59
<#macro generateField property>
harpreet@9076
    60
  {name: '${property.name?js_string}',
harpreet@9076
    61
    type: '${property.type}'
harpreet@9076
    62
<#if property.id>
harpreet@9076
    63
    , hidden: true, primaryKey: true
harpreet@9076
    64
</#if>
harpreet@9076
    65
<#if property.mandatory && property.updatable && !property.auditInfo && !property.boolean>
harpreet@9076
    66
    , required: true
harpreet@9076
    67
</#if>
harpreet@9076
    68
<#if !property.updatable || property.auditInfo>
harpreet@9076
    69
    , canSave: false
harpreet@9076
    70
</#if>
harpreet@9076
    71
<#if 0 < property.fieldLength && property.primitive && !property.id && property.primitiveObjectType.name="java.lang.String">
harpreet@9076
    72
      , length: ${property.fieldLength?c}
harpreet@9076
    73
</#if>
harpreet@9076
    74
    <#--TODO: translate this-->
harpreet@9076
    75
    , title: '${property.name?js_string}'
harpreet@9076
    76
<#if (property.allowedValues)?? && 0 < property.allowedValues?size>
harpreet@9076
    77
    , valueMap: {
harpreet@9076
    78
    <#list property.valueMapContent as entry>
harpreet@9076
    79
    <#-- 
harpreet@9076
    80
        Note the replace is needed because freemarker js_string will replace > with \> resulting in jslint escape errors
harpreet@9076
    81
        Note uses the _;_;_;_ as a trick assuming that it will never occur.
harpreet@9076
    82
        see this issue: https://issues.openbravo.com/view.php?id=14487
harpreet@9076
    83
    -->
harpreet@9076
    84
    '${entry.value?js_string}': '${entry.label?replace(">", "_;_;_;_")?js_string?replace("_;_;_;_", ">")}'<#if entry_has_next>,</#if>
harpreet@9076
    85
    </#list>
harpreet@9076
    86
    }
harpreet@9076
    87
</#if>
harpreet@9076
    88
<#if !property.primitive>
harpreet@9076
    89
   <#if !property.id>
harpreet@9076
    90
    , hidden: true
harpreet@9076
    91
   </#if>
harpreet@9076
    92
   <#-- , foreignKey: '${property.targetEntity.name}.id' -->
harpreet@9076
    93
</#if>
harpreet@9076
    94
    }
harpreet@9076
    95
<#if !property.primitive>
harpreet@9076
    96
    <#-- Note the subPropName are constants from the JsonConstants class -->
harpreet@9076
    97
    <#-- , <@generateReferenceField property=property subPropName='id'/> -->
harpreet@9076
    98
    , <@generateReferenceField property=property subPropName='_identifier'/>
harpreet@9076
    99
</#if>
harpreet@9076
   100
    
harpreet@9076
   101
</#macro>
harpreet@9076
   102
harpreet@9076
   103
<#macro generateReferenceField property subPropName>
harpreet@9076
   104
    {name: '${property.name?js_string}.${subPropName}'
harpreet@9076
   105
    , type: 'text', hidden: true
harpreet@9076
   106
    <#if property.mandatory>
harpreet@9076
   107
      <#--, required: true-->
harpreet@9076
   108
    </#if>
harpreet@9076
   109
harpreet@9076
   110
    <#if !property.updatable || property.auditInfo>
harpreet@9076
   111
      , canSave: false
harpreet@9076
   112
    </#if>
harpreet@9076
   113
    <#--, valueXPath: '${property.name?js_string}/${subPropName}'-->
harpreet@9076
   114
    <#--TODO Translate this-->
harpreet@9076
   115
    , title: '${property.name?js_string}'
harpreet@9076
   116
    }
harpreet@9076
   117
    
harpreet@9076
   118
<#--
harpreet@9076
   119
    if (subPropName.equals(JsonConstants.IDENTIFIER)) {
harpreet@9076
   120
      // sb.append(", editorType: 'comboBox'");
harpreet@9076
   121
      // sb.append(", editorProperties: {displayField: '" + JsonConstants.IDENTIFIER
harpreet@9076
   122
      // + "', valueField: '" + JsonConstants.ID + "'");
harpreet@9076
   123
      // sb.append(", optionDataSource: '" + property.getTargetEntity().getName()
harpreet@9076
   124
      // + "', fetchDelay: 300, autoFetchData: false, selectOnFocus: true, dataPageSize : 15}");
harpreet@9076
   125
      // sb.append(", filterEditorProperties: {displayField: '" + JsonConstants.IDENTIFIER
harpreet@9076
   126
      // + "', valueField: '" + JsonConstants.IDENTIFIER + "', editorType: 'comboBox'");
harpreet@9076
   127
      // sb.append(", required: false, optionDataSource: '" + property.getTargetEntity().getName()
harpreet@9076
   128
      // + "', fetchDelay: 300, autoFetchData: false, selectOnFocus: true, dataPageSize : 15}");
harpreet@9076
   129
    } else if (subPropName.equals(JsonConstants.ID)) {
harpreet@9076
   130
      // sb.append(", editorType: 'comboBox'");
harpreet@9076
   131
      // sb.append(", editorProperties: {displayField: '" + JsonConstants.IDENTIFIER
harpreet@9076
   132
      // + "', valueField: '" + JsonConstants.ID + "'");
harpreet@9076
   133
      // sb.append(", optionDataSource: '" + property.getTargetEntity().getName()
harpreet@9076
   134
      // + "', fetchDelay: 300, autoFetchData: false, selectOnFocus: true, dataPageSize : 15}");
harpreet@9076
   135
      // sb.append(", filterEditorProperties: {displayField: '" + JsonConstants.IDENTIFIER
harpreet@9076
   136
      // + "', valueField: '" + JsonConstants.ID + "', editorType: 'comboBox'");
harpreet@9076
   137
      // sb.append(", required: false, optionDataSource: '" + property.getTargetEntity().getName()
harpreet@9076
   138
      // + "', fetchDelay: 300, autoFetchData: false, selectOnFocus: true, dataPageSize : 15}");
harpreet@9076
   139
    } else {
harpreet@9076
   140
      // sb.append(", filterEditorProperties: {required: false}");
harpreet@9076
   141
    }
harpreet@9076
   142
-->
harpreet@9076
   143
</#macro>