/*
Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
Available via Academic Free License >= 2.1 OR the modified BSD license.
see: http://dojotoolkit.org/license for details
*/
if(!dojo._hasResource["kfc.kwo.MeterReadingGrid"]){dojo._hasResource["kfc.kwo.MeterReadingGrid"]=true;dojo.provide("kfc.kwo.MeterReadingGrid");dojo.require("kfc.kwo._MeterReading");dojo.require("kfc.kwo._GridBase");dojo.require("kfc.form.NumberTextBox");dojo.require("kfc.form.OracleDateTextBox");dojo.require("kfc.grid.Formatters");dojo.declare("kfc.kwo.MeterReadingGrid",[kfc.kwo._MeterReading,kfc.kwo._GridBase],{templateString:dojo.cache("kfc.kwo","templates/MeterReadingGrid.html","
\n
\n"),widgetsInTemplate:true,lastReadingFile:"server/getLastMeterReading.php",lastReading:{},rowWarned:-1,_getGridStructure:function(){return [{name:" ",field:"",formatter:function(){return " ";},editable:false,width:"0px"},{name:"Reading Date",field:"P_READING_DATE",widgetClass:kfc.form.OracleDateTextBox,type:dojox.grid.cells._Widget,width:"10em",editable:true},{name:"Reading",field:"P_VALUE",widgetClass:kfc.form.NumberTextBox,get:dojo.hitch(this,"_validateReading"),editable:true},{name:"Notes",field:"P_TEXT",width:"auto",editable:true}];},refreshGrid:function(){setTimeout(dojo.hitch(this.f_grid,"_refresh"),100);},setStatus:function(_1){},getData:function(_2,_3,_4){this.inherited(arguments);this.getLastReading();},getLastReading:function(){var v=this._getSearchObj();v.P_SOURCE_ID=[v.P_SOURCE_ID];dojo.xhrPost({sync:true,url:this.lastReadingFile,handleAs:"json",content:{P_REQ_NAME:this.P_REQ_NAME,P_REQ_TYPE:"LOAD",P_SCHEMA:this.db_schema,P_TABLE_NAME:this.db_table_name,P_VALUES:dojo.toJson(v)},load:dojo.hitch(this,"setLastReading"),error:dojo.hitch(this,"throwError")});},setLastReading:function(_5){var r=_5.items;if(r&&typeof (r.length)!="undefined"){switch(r.length){case 1:this.lastReading=r[0];break;default:this.lastReading={};break;}}},_validateReading:function(r,i){if(!i){return;}var lr=this.lastReading;var cv=i.P_VALUE[0];var lv=(lr.P_LAST_VALUE)?lr.P_LAST_VALUE:(cv-1);var _6=(i.NEW_ROW_FLAG)?i.NEW_ROW_FLAG[0]:"N";if(_6=="Y"){if(cv&&parseFloat(lv)>parseFloat(cv)){var w=this.rowWarned;if(!w||w!=cv){this.throwError("WARNING: Current reading ("+cv+") is less than last reading ("+lv+").");i.IN_ERROR="Y";}}else{i.IN_ERROR="N";this.setStatus("New reading ok.");}this.rowWarned=cv;}return i.P_VALUE;},reset:function(){this.rowWarned=-1;this.inherited(arguments);},postCreate:function(){this.inherited(arguments);}});}