aimitems.js
Summary
Collection of application level classes.
This collection implements the rich-internet-application tier of
the Inventory Module for AIM (Auction Inventory Management),
which is a demonstration of the Gravey framework.
Version: 2.0
Requires:
Author: Bruce Wallace (PolyGlotInc.com)
|
Class Summary
|
| Item |
This class encapsulates an Auction Item record. |
| ItemModel |
This class encapsulates the data model of a particular Item. |
| ItemModelView |
This class produces the view of the entire data panel. |
| ItemSelectionModel |
This class encapsulates the data model for
"which Item is currently selected". |
| ItemSummary |
This class encapsulates the identifying attributes of an auction Item. |
| ItemView |
This class produces a view of a Item. |
| Loan |
This class encapsulates any optional financing available
for an Item (i.e. |
| LoanView |
This class produces a view of a Loan. |
| LotDecode |
This class encapsulates a Lot picklist item. |
| PLEDO |
This is the abstract base class for PlainItems/LoanItems EDOs. |
| PLIndex |
This class encapsulates an EDO index for Plain/Loan. |
Class(LotDecode,["Lot Key","Lot Name","Lot Number"])
.Extends(MVCDecode);
function LotDecode()
{
this.konstructor = function( lotkey, lotname, lotnum ) {
this.souper( "Lot", lotkey, lotname, lotnum );
}
this.getDescription = function() {
return "Lot# "+this.aux+" "+this.desc;
}
}
Class(ItemSummary,["unique Key","Item Name","Item Type Code",
"Lot Number","Pulled Flag","Item Number"])
.Extends(EDOHolderSelectionItem);
function ItemSummary()
{
this.konstructor = function( theKey, iName, iType, lNum, pulled, iNum )
{
this.key = theKey;
this.iName = iName;
this.iType = iType;
this.lotNo = lNum;
this.pulled = pulled;
this.iNum = iNum;
}
this.getDescription = function()
{
var s = new Array();
s.push( grvDiamond(!this.pulled)+this.lotNo );
s.push( this.iNum );
s.push( this.iName );
return s.join( "-" );
}
this.toString = function()
{
var s = new Array();
s.push( this.key );
s.push( this.iName );
s.push( this.lotNo );
s.push( this.iNum );
return s.join( "-" );
}
this.updateProperties = function( it ){
this.key = it.key;
this.iName = it.iName;
this.iType = it.iType;
this.lotNo = it.lotNo;
this.pulled = it.pulled;
this.iNum = it.iNum;
}
}
Class(PLIndex).Extends(EDOIndex);
function PLIndex()
{
if (!PLIndex.Plain){
PLIndex.Plain = function(){ return new PLIndex(0,null); }
PLIndex.Loan = function(){ return new PLIndex(0,0); }
PLIndex.Item = function(){ return PLIndex.Plain(); }
}
this.konstructor = function( optP,optL )
{
this.p = optP===undefined ? null : optP;
this.l = optL===undefined ? null : optL;
}
this.asEventArgs = function() {
return " new PLIndex("+this.p+","+this.l+") ";
}
this.asString = function() {
return this.invoke( this, this._noString, this._lonString )
+ this._itString( this.p );
}
this._noString = function(){ return ""; }
this._itString = function( pindex ){
var a = gItemData._getItem( pindex );
if (a && a[ kStrIdName ]) return a[ kStrIdName ];
return (a && !a.isNew()) ? "Unnamed Item" : "New Item";
}
this._lonString = function( cindex ){
cindex -= 0;
return "Loan Attributes of ";
}
this.hasSelection = function(){ return this.p!=null
|| this.l!=null; }
this.equals = function(x){
return x ? (this.p==x.p && this.l==x.l) : false;
}
this.invoke = function(self,pMethod,lMethod,optArg){
var aMethod;
var i;
if (this.l!=null) { aMethod = lMethod; i = this.l; } else
{ aMethod = pMethod; i = this.p; }
return aMethod.call( self, i, optArg );
}
}
var kIntIdLotNum = 'Lot#';
var kIntIdLotKey = 'Lot';
var kBoolIdPulled = 'Pulled?';
var kBoolIdEligVIP = 'VIP Eligible?';
var kStrIdItemType = 'Item Category';
var kDateIdLast = 'Last Updated';
var kDateIdFirst = 'First Added';
var kStrIdName = 'Item Name';
var kAddrIdStreet = 'Street';
var kAddrIdState = 'State';
var kAddrIdCity = 'City';
var kAddrIdZip = 'Zip';
var kAmtIdBook = 'Retail Value';
var kPctIdTarget = 'Target%';
var kPctIdReserve = 'Reserve%';
var kIntIdItemNum = 'Item#';
var kStrIdComments2 = 'Description';
var kStrIdOwnName = 'Owner Name';
var kStrIdBank = 'Bank #';
var kPctIdIntRate = 'Interest Rate';
Class(PLEDO,["parent holder model", "edo Class", "property values array",
"edit Date","edit User","unique Key" ])
.Extends(EDO);
function PLEDO()
{
this.konstructor = function
(
holder,
CLAZZ,
propValues,
editDate,
editUser,
theKey,
optEditStatus,
optName
){
this.souper( CLAZZ, holder, propValues, editDate, editUser,
theKey, optEditStatus, optName );
}
this.pushUpdateFields = function( uFields )
{
uFields.push( this.holder.isLoan()?'Y':'N' );
this.pushEncodedValues( uFields );
}
}
Class(Item,["property values array","edit Date","edit User",
"unique Key","parent holder"])
.Extends(PLEDO);
function Item()
{
if (!Item.Properties) {
Item.Factory = function(index,holder)
{
var x = new Item( null, grvGetTodayAsMMDDYYYY(),kUserID,null,holder );
x[ kAmtIdBook ] = 0;
x[ kPctIdTarget ] = 0;
x[ kPctIdReserve ] = 0;
x[ kIntIdLotNum ] = kLotKey ? kLotNumber : 0;
x[ kIntIdLotKey ] = kLotKey ? kLotKey : kLotZeroKey;
x[ kDateIdFirst ] = x.date;
x[ kDateIdLast ] = x.date;
x[ kBoolIdPulled ] = false;
x[ kBoolIdEligVIP ] = false;
x[ kStrIdItemType ] = "AI";
return x;
}
Item.UpdateID = "Item";
Item.Properties = [ kIntIdLotKey,
kIntIdLotNum, kBoolIdPulled, kBoolIdEligVIP, kStrIdItemType,
kDateIdLast, kDateIdFirst, kStrIdName, kAddrIdStreet,
kAddrIdCity, kAddrIdState, kAddrIdZip, kAmtIdBook,
kPctIdTarget, kPctIdReserve, kIntIdItemNum,
kStrIdComments2, kStrIdOwnName
];
Item.EditRules = [ MVCEditRule.kPOS,
MVCEditRule.kRO, MVCEditRule.kBOOL, MVCEditRule.kBOOL, MVCEditRule.kALFA,
MVCEditRule.kDATE, MVCEditRule.kDATE, MVCEditRule.kEdit, MVCEditRule.kEdit,
MVCEditRule.kAlfa, MVCEditRule.kAlfa, MVCEditRule.kZip, MVCEditRule.kDec,
MVCEditRule.kDec, MVCEditRule.kDec, MVCEditRule.kInt,
MVCEditRule.kEdit, MVCEditRule.kEdit
];
}
this.konstructor = function
( propArray, editDate, editUser, theKey, holder, optEditStatus, optName )
{
this.souper( holder, Item,
propArray, editDate, editUser, theKey, optEditStatus, optName );
this[ kIntIdItemNum+MVCAttributeModel.kValidateSuffix ] = this.validateItemNum;
}
this.validateItemNum = function()
{
if ( grvIsEmpty(this[kIntIdItemNum]) ) return null;
if ( this[kIntIdItemNum]==0 ) return "Item number zero is not allowed.";
if ( this.hasDuplicateItemNum()) return "Duplicate Item numbers are not allowed.";
return null;
}
this.hasDuplicateItemNum = function() {
return this.holder.itemCount( this[kIntIdItemNum], this.key ) > 1;
}
this.clone = function() {
return new Item( this.propValues(), this.date, this.whom,
this.key, this.holder, this.editStatus );
}
this.toString = function() {
var s = grvIsEmpty(this[kIntIdItemNum]) ? "" : ("#"+this[kIntIdItemNum]);
var t = grvIsEmpty(this[kStrIdName ]) ? "" : (" "+this[kStrIdName ]);
return s+t;
}
this.canCreate = function(appendFlag) {
return this.holder.isTrue()
? "Can't add a new Item until pending changes have been saved"
: null;
}
this.canDelete = function(){
if ( this.isActive() && !kLaunched ) return null;
return 'Items can not be deleted after Auction Launch. Mark as "pulled" instead.';
}
this.canUncreate = function(appendFlag){ return false; }
}
Class(Loan,["property values array","edit Date","edit User",
"unique Key","parent holder"])
.Extends(PLEDO);
function Loan()
{
if (!Loan.Properties) {
Loan.Factory = function(index,holder)
{
var x = new Loan( null,grvGetTodayAsMMDDYYYY(),kUserID,null,holder );
x[ kStrIdBank ] = "000";
x[ kPctIdIntRate ] = 0;
return x;
}
Loan.Title = "Financing Available";
Loan.UpdateID = "Loan";
Loan.Properties = [ kStrIdBank, kPctIdIntRate ];
Loan.EditRules = [ MVCEditRule.kALNO, MVCEditRule.kDec ];
}
this.konstructor = function
( propArray, editDate, editUser, theKey, holder, optEditStatus, optName )
{
this.souper( holder, Loan,
propArray, editDate, editUser, theKey, optEditStatus, optName );
}
this.clone = function() {
return new Loan( this.propValues(), this.date, this.whom,
this.key, this.holder, this.editStatus );
}
this.toString = function()
{
return this[ kStrIdBank ];
}
this.canCreate = function(appendFlag) {
return "There can only be one set of Loan Attributes.";
}
this.canDelete = function(){
if ( this.isNew() && this.isActive() ) return null;
return "This section can't be deleted. The entire Item must be deleted.";
}
}
Class(ItemModel,["Item Selection Model"]).Extends(EDOHolderModel);
function ItemModel()
{
this.konstructor = function( itemSelectionModel, optName )
{
if (!ItemModel.LoadXslDOM) ItemModel.LoadXslDOM = grvGetXslDOM( kXSLPath+"AIMitToJS.xsl" );
var holderName = optName ? optName : "Item";
this.souper( itemSelectionModel, ItemModel.LoadXslDOM, holderName );
this._resetEDOs();
}
this.getName = function(){
return this.item ? this.item[kStrIdName] : null;
}
this.getLotNo = function(){
return this.item ? kLotMap.getItem( this.item[kIntIdLotKey] ).aux : null;
}
this.isDirty = function()
{
if (this.item && this.item.inEdit()) return true;
if (this.loan && this.loan.inEdit()) return true;
return false;
}
this.isValid = function()
{
if (!this.item || !this.item.isValid()) return false;
if (this.item.isDeleted()) return true;
if (this.isLoan() && !this.loan.isValid()) return false;
return true;
}
this._resetEDOs = function( optItem, optLoan )
{
this.item = optItem ? optItem : null;
this.loan = optLoan ? optLoan : null;
}
this.isLoan = function(){ return this.loan!=null; }
this._setItem = function(o){ this.item = o; }
this._setLoan = function(o){ this.loan = o; }
this.dump = function()
{
var dStr = new Array();
dStr.push( "ItemModel>>>[" );
dStr.push( "item="+(this.item?this.item.dump():"null") );
dStr.push( "loan="+(this.loan?this.loan.dump():"null") );
dStr.push( "]" );
return dStr.join("\n");
}
this.createSelectionItem = function()
{
return new ItemSummary(
this.item.key,
this.getName(),
this.item[kStrIdItemType],
this.getLotNo(),
this.item[kBoolIdPulled],
this.item[kIntIdItemNum]
);
}
this.getUpdatedProperty = function(){ return this.createSelectionItem(); }
this.hasEDO = function(){ return this.item!=null; }
this.keysMatch = function(item){ return this.item.key==item.key; }
this.propMatch = function(item){
return item.iName ==this.getName()
&& item.pulled==this.item[kBoolIdPulled]
&& item.lotNo ==this.getLotNo()
&& item.aNum ==this.item[kIntIdItemNum];
}
this.pushPosts = function( posts )
{
this.item.pushPosts( posts );
if (this.isLoan())
this.loan.pushPosts( posts );
}
this._newEDO = function(xi) {
return xi.invoke( this, Item.Factory, Loan.Factory, this );
}
this._getItem = function( i ) {
return (i==0 && this.item) ? this.item : null;
}
this._getLoan = function( i ) {
return (i==0 && this.loan) ? this.loan : null;
}
this.getEDO = function(xi){
return xi.invoke( this, this._getItem, this._getLoan );
}
this.createEDO = function(xi){
xi.invoke( this, this._newItem, this._newLoan, this.newEDO(xi) );
return xi;
}
this._newItem = function( i, itemEDO )
{
var loanEDO = this.newEDO( PLIndex.Loan() );
this._resetEDOs( itemEDO, loanEDO );
this.updateStamp();
return PLIndex.Plain();
}
this._newLoan = function( i, edo ) {
this.updateStamp();
return PLIndex.Loan();
}
this.appendEDO = function(xi){
return xi.invoke( this, this._newItem, this._newLoan, this.newEDO(xi) );
}
this.toggleExpand = function( doAllFlag, xi )
{
var edo = this.getEDO(xi);
if (doAllFlag)
{
var newVal = !edo.isExpanded();
this.item.toggleExpand( newVal );
this.loan.toggleExpand( newVal );
}
else edo.toggleExpand();
this.updateStamp();
}
this.itemCount = function( itemnum, key )
{
var lotnum = this.getLotNo();
if (lotnum==null || itemnum==null) return 0;
var count = 1;
this.model.model.iterate( function(i,it){
if (it.key!=key && it.lotNo==lotnum && it.iNum==itemnum && !it.pulled) ++count;
} );
return count;
}
}
Class(ItemSelectionModel,["ItemSummary List Model"]).Extends(EDOHolderSelectionModel);
function ItemSelectionModel()
{
this.konstructor = function( listModel ){
this.souper( listModel, "Item " );
}
this.findItem = function( itemKey )
{
var list = this.model;
var N = list.getCount();
if (N<1) return -2;
for (var i=0; i<N; ++i)
if (list.getItem(i).key == itemKey) return i;
return -1;
}
this.selectInitial = function( selectFirst )
{
var i = this.findItem( kItemKey );
if (i==-2){ this.selectNothing(); return; }
if (i>= 0){ this.select(i); return; }
if (selectFirst) this.select(0);
}
}
Class(ItemView,["Item object"])
.Extends(EDOView);
function ItemView()
{
this.konstructor = function( item ) {
this.souper( item, PLIndex.Plain() );
}
this.preSelect = function() {
this.sharedMenuSelect( gLotSelected, kIntIdLotKey );
this.sharedMenuSelect( gITypeSelected, kStrIdItemType );
}
this.buildFields = function( HTML )
{
HTML.push( this.buildStrField( kStrIdName , 50, 50, false, 3 ) );
HTML.push( this.buildPopField( kIntIdLotKey , false, gLotSelected, 2 ) );
HTML.push( this.buildStrField( kIntIdItemNum , 3, 3, false ) );
HTML.push( this.buildBoxField( kBoolIdPulled , true ) );
HTML.push( this.buildStrField( kStrIdOwnName , 50, 50, false, 3 ) );
HTML.push( this.buildDayField( kDateIdFirst , false ) );
HTML.push( this.buildDayField( kDateIdLast , false ) );
HTML.push( this.buildPopField( kStrIdItemType , false, gITypeSelected ) );
HTML.push( this.buildBoxField( kBoolIdEligVIP , true ) );
HTML.push( this.buildTxtField( kAddrIdStreet,2, 50,250, false, 3 ) );
HTML.push( this.buildPctField( kPctIdTarget , false ) );
HTML.push( this.buildPctField( kPctIdReserve , false ) );
HTML.push( this.buildAmtField( kAmtIdBook , true ) );
HTML.push( this.buildStrField( kAddrIdCity , 20, 50, false ) );
HTML.push( this.buildUprField( kAddrIdState , 2, 2, false ) );
HTML.push( this.buildStrField( kAddrIdZip , 10, 10, true ) );
HTML.push( this.buildTxtField( kStrIdComments2,4,120,2000,true, 7 ) );
}
}
Class(LoanView,["Loan object"])
.Extends(EDOView);
function LoanView()
{
this.konstructor = function( loan ) {
this.souper( loan, PLIndex.Loan() );
}
this.buildFields = function( HTML )
{
HTML.push( this.buildStrField( kStrIdBank , 3, 3, false ) );
HTML.push( this.buildPctField( kPctIdIntRate, false ) );
}
}
Class(ItemModelView,["Item data model"])
.Extends(EDOHolderView);
function ItemModelView()
{
this.konstructor = function( itModel ) {
this.souper( itModel );
}
this.buildFields = function( HTML )
{
var vwID = this.getWidgetID();
var selected = this.model;
if ( !selected.item || selected.item.inLimbo() )
{
if (!grvWAITING())
HTML.push( EDOView.ShellHTML( PLIndex.Item(), Item ) );
}
else if ( selected.item.isActive() )
{
HTML.push( this.embedHTML( vwID+".itWdgt",
new ItemView( selected.item ) ) );
if ( selected.isLoan() || selected.item.isNew() )
if ( !selected.loan || selected.loan.inLimbo() )
{
if (!grvWAITING())
HTML.push( EDOView.ShellHTML( PLIndex.Loan(), Loan ) );
}
else if ( selected.loan.isViewable() )
HTML.push( this.embedHTML( vwID+".loWdgt",
new LoanView( selected.loan ) ) );
}
else HTML.push( '<thead>This Item is deleted. You must Cancel, Save, or Undo.</thead>' );
}
}
Documentation generated by
JSDoc on Sun Feb 11 13:31:42 2007