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