2015年2月14日 星期六

javascript-enum

http://stackoverflow.com/questions/287903/enums-in-javascript





var Colors = function(){
return {
    'WHITE':0,
    'BLACK':1,
    'RED':2,
    'GREEN':3
    }
}();

console.log(Colors.WHITE)  //this prints out "0"
if(currentColor == my.namespace.ColorEnum.RED) {
   // alert name of currentColor (RED: 0)
   var col = my.namespace.ColorEnum;
   for (var name in col) {
     if (col[name] == col.RED)
       alert(name);
   } 

}
Alternatively, you could make the values objects, so you can have the cake and eat it to:
var SIZE = {
  SMALL : {value: 0, name: "Small", code: "S"}, 
  MEDIUM: {value: 1, name: "Medium", code: "M"}, 
  LARGE : {value: 2, name: "Large", code: "L"}
};

var currentSize = SIZE.MEDIUM;
if (currentSize == SIZE.MEDIUM) {
  // this alerts: "1: Medium"
  alert(currentSize.value + ": " + currentSize.name);
}
In Javascript, as it is a dynamic language, it is even possible to add enum values to the set later:
// Add EXTRALARGE size
SIZE.EXTRALARGE = {value: 3, name: "Extra Large", code: "XL"};
Remember, the fields of the enum (value, name and code in this example) are not needed for the identity check and are only there for convenience. Also the name of the size property itself does not need to be hardcoded, but can also be set dynamically. So supposing you only know the name for your new enum value, you can still add it without problems:
// Add 'Extra Large' size, only knowing it's name
var name = "Extra Large";
SIZE[name] = {value: -1, name: name, code: "?"};
Ofcourse this means that some assumptions can no longer be made (that value represents the correct order for the size for example).
Remember, in Javascript an object is just like a map or hashtable. A set of name-value pairs. You can loop through them or otherwise manipulate them without knowing much about them in advance.
E.G:
for (var sz in SIZE) {
  // sz will be the names of the objects in SIZE, so
  // 'SMALL', 'MEDIUM', 'LARGE', 'EXTRALARGE'
  var size = SIZE[sz]; // Get the object mapped to the name in sz
  for (var prop in size) {
    // Get all the properties of the size object, iterates over
    // 'value', 'name' and 'code'. You can inspect everything this way.        
  }
} 
And btw, if you are interested in namespaces, you may want to have a look at my solution for simple but powerful namespace and dependency management for javascript: Packages JS










2015年2月11日 星期三

generator-excel



PropertyButton1Caption=Excel
PropertyButton1Action=retrieval('','csv');
csvFileName=OS GRN

2015年2月10日 星期二

generator-scan table-scan

var table=document.getElementById('tableName3_222');
for (i=0;i<table.rows.length;i++)
{
var s050209=_lookup('SALES_ORDER_INV_DESC.recordID'+i);
var s2=_lookup('SALES_ORDER_INV_DESC.DESCRIPTION'+i);
comboSelfData0=comboSelfData0+delimiter2+s050209+'<,>'+s2.replace(/,/g,'%2C');
delimiter2='<,>';
}

2015年2月9日 星期一

generator-appendDataActionAfter




append from self table

for (i=0;i<table.rows.length;i++)
{
var s1=_lookup('SALES_ORDER_INV_DESC.PRODUCT_RECORDID'+i);
var s2=_lookup('SALES_ORDER_INV_DESC.DESCRIPTION'+i);
var s3=_lookup('SALES_ORDER_INV_DESC.recordID'+i);
tableName1_111Append();
_refreshv2('SALES_ORDER_PO_DESC.PRODUCT_RECORDID'+currentRow,s1);
_refreshv2('SALES_ORDER_PO_DESC.DESCRIPTION'+currentRow,s2);
_refreshv2('SALES_ORDER_PO_DESC.SOI_RECORDID'+currentRow,s3);
_comboSelfData('SALES_ORDER_PO_DESC.SOI_RECORDID'+currentRow,comboSelfData0,s3,'noSpace');
}




{appendData0ActionAfter}
var s1103x:_lookup('DNOTE_HEADER.SALES_ORDER'); _refreshv2('DNOTE_HEADER.CONTACT_TEL',lookupTable('CUSTOMER_CONTACT1_TELEPHONE','SALES_ORDER_HEAD.SALES_ORDER',s1103x)); 
_refreshv2('DNOTE_HEADER.CONTACT_NAME',lookupTable('CUSTOMER_CONTACT1_NAME','SALES_ORDER_HEAD.SALES_ORDER',s1103x)); 
{/appendData0ActionAfter}

2015年2月3日 星期二

generator-grid-invisible-when-approve-enable -scroll-table








Config.txt
Page1TableWidth=100%
Page3TableWidth=100%
gridWidth=,1401px;,1402px;,1013px;



{layoutInvisibleWhenPROCESSING_MODE}D{/layoutInvisibleWhenPROCESSING_MODE}
{enableWhenApprove}


{object}
1.361,SUPPLIER_INVOICE_LINE.AC_CODE,text:GRID,10%,10,AC CODE,,
{dblclickSetData}FORM=codeListOnly{/dblclickSetData}  
{dblclickGetData}
SOURCE_TABLE=CODE, 
SOURCE_FIELD=CODE&ACCOUNT&RECORDID&RECORDID,
SOURCE_FORMAT=S&S&S,
TARGET_FIELD=this..AC_CODE&this..ACCOUNT&this..CODE_RECORDID
{/dblclickGetData}
{layoutInvisibleWhenPROCESSING_MODE}D{/layoutInvisibleWhenPROCESSING_MODE}
{enableWhenApprove}
{/object}


{object}
1.361,SUPPLIER_INVOICE_LINE.DESCRIPTION,textarea:GRID,20%,150,Description,,
{subformHeight}300{/subformHeight}{subformWidth}640{/subformWidth}
{whenDraftModeWidth}50{/whenDraftModeWidth}
{readonly}
{/object}