据说是段非常经典的遍历代码. 但对我而言, 实在是对牛弹琴, 有高手能帮我注释一下吗, 多谢了
var ProductHelper = new _ProductHelper();function _ProductHelper() {
}
_ProductHelper.prototype.selectProduct = function(productOid) {
var theForm = document.getElementById("theQueryForm");
var theOpenerItemOid = theForm["itemOid"].value;
var items = Utilities.parseInt(document.getElementById("products._rowCount").value, 0);
for (var i = 0; i < items; i++) {
if (theForm["products{" + i + "}.oid"].value == productOid) {
var theProductCode = theForm["products{" + i + "}.code"].value;
var theProductName = theForm["products{" + i + "}.name"].value;
var theProductPrice = theForm["products{" + i + "}.price"].value;
this.setOpenerValue(theOpenerItemOid, productOid, theProductCode, theProductName, theProductPrice);
return;
}
}
}_ProductHelper.prototype.setOpenerValue = function(itemOid, productOid, productCode, productName, productPrice) {
var theForm = opener.document.getElementById("theEditBoutForm");
if (theForm == null) {
alert("System Exception, cant get the parent window!");
return;
}
// alert(theForm["bout.startDate"].value);
var items = 100;
// Assumption
var itemFieldPrefix = "bout.quotation.items";
for (var i = 0; i < items; i++) {
var theFieldName = itemFieldPrefix + "{" + i + "}.oid";
var theField = theForm[theFieldName];
if (theField == null) {
break;
}
if (itemOid == theField.value) {
// alert(productOid);
theForm[itemFieldPrefix + "{" + i + "}.productOid"].value = productOid;
theForm[itemFieldPrefix + "{" + i + "}.productCode"].value = productCode;
theForm[itemFieldPrefix + "{" + i + "}.productName"].value = productName;
theForm[itemFieldPrefix + "{" + i + "}.unitPrice"].value = productPrice;
window.close();
return;
}
}
}/**
Calculate Amount
*/
_ProductHelper.prototype.doCalculate = function() {
var theForm = document.getElementById("theEditBoutForm");
var designFee = Utilities.parseFloat(theForm["bout.quotation.designFee"].value);
var designRate = Utilities.parseFloat(theForm["bout.quotation.designFeeRate"].value, 0);
var transFee = Utilities.parseFloat(theForm["bout.quotation.transFee"].value);
var transRate = Utilities.parseFloat(theForm["bout.quotation.transFeeRate"].value, 0);
var otherfee = Utilities.parseFloat(theForm["bout.quotation.otherFee"].value); var items = 100;
// Assumption
var itemFieldPrefix = "bout.quotation.items";
var itemTotal = 0.00;
for (var i = 0; i < items; i++) {
var theFieldName = itemFieldPrefix + "{" + i + "}.quantity";
var theField = theForm[theFieldName];
if (theField == null) {
break;
}
var itemAmount = this.calcItem(theForm, i);
itemTotal += itemAmount;
}
designFee = Utilities.round(designFee * (1.00 - designRate / 100.00), 2);
//Design real fee
transFee = Utilities.round(transFee * (1.00 - transRate / 100.00), 2);
//trans real fee
theTotalAmount = Utilities.round(designFee + transFee + otherfee + itemTotal, 2);
theForm["bout.quotation.amount"].value = Utilities.format(theTotalAmount,"###0.00");
}_ProductHelper.prototype.calcItem = function(theForm, row) {
var itemFieldPrefix = "bout.quotation.items";
var theQuantity = Utilities.parseFloat(theForm[itemFieldPrefix + "{" + row + "}.quantity"].value, 0);
var thePrice = Utilities.parseFloat(theForm[itemFieldPrefix + "{" + row + "}.unitPrice"].value, 0);
var theDiscount = Utilities.parseFloat(theForm[itemFieldPrefix + "{" + row + "}.discount"].value, 0);
var theAmount = Utilities.round(theQuantity * thePrice * (1.00 - theDiscount / 100), 2);
theForm[itemFieldPrefix + "{" + row + "}.amount"].value = Utilities.format(theAmount,"##0.00");
return theAmount;
}