/*
 * JSMin
 * Javascript Compressor
 * http://www.crockford.com/
 * http://www.smallsharptools.com/Projects/Packer/
*/

// V:\1.1.007\js\lib\ext-namirial\Ext.ux.Namirial.data.GearsFiller.js

Ext.namespace('Ext.ux');Ext.namespace('Ext.ux.Namirial');Ext.namespace('Ext.ux.Namirial.data');Ext.ux.Namirial.data.GearsFiller=Ext.extend(Ext.util.Observable,{constructor:function(c){this.addEvents('load','loadexception','loadtable');this.gearsConn=c.gearsConn;this.cfisc=c.cfisc||false;this.selectFilter=c.selectFilter;this.db=c.db||session.userDb;this.url=c.url;this.i=0;this.tables=c.tables||[];this.mode=c.mode||'insert';this.sql=new Array();},load:function(){if(Ext.isEmpty(this.cfisc)){this.fireEvent('loadexception','load');return false;}
var clause=('CFISC = \''+this.cfisc+'\'')+(this.selectFilter||'');var sql='SELECT * FROM '+this.tables[this.i]+((clause!='')?(' WHERE '+clause):'');Ext.Ajax.request({url:this.url,params:{s:sql,db:this.db},scriptTag:true,success:function(response){this.readResponse(response)},failure:function(){log.error("Ext.ux.Namirial.data.GearsFiller.load Errore");},scope:this});},loadSingle:function(arguments){log.time(arguments.table);if(Ext.isEmpty(arguments.table)||Ext.isEmpty(arguments.fields)){this.fireEvent('loadexception','loadsingle');return false;}
this.table=arguments.table;var clause=(arguments.filter||'');var sql='SELECT * FROM '+arguments.table+((clause!='')?(' WHERE '+clause):'')
Ext.Ajax.request({url:this.url,params:{s:sql,db:this.db},scriptTag:true,success:function(response){this.readSingleResponse(response)},failure:function(){log.error("Ext.ux.Namirial.data.GearsFiller.loadSingle Errore");},scope:this});},readResponse:function(response){var responseObj=Ext.decode(response.responseText);var fields=unescape(responseObj.fields);var removeKey=false;if(fields.substr(0,5)=='keyId'){fields=fields.slice(6);removeKey=true;}
var records=responseObj.rows;if(this.mode=='replace'){this.sql.push("DELETE FROM "+this.tables[this.i]+" WHERE [CFISC] = '"+this.cfisc+"'")}
for(var j=0,len=responseObj.totalRows;j<len;j++){var values='';var rec=records[j]
for(var k=(removeKey)?1:0,m=rec.length;k<m;k++){var value=rec[k].toString();value=escapeApici(unescape(value));values+="'"+value+"',";}
values=values.slice(0,-1);var query="INSERT INTO "+this.tables[this.i]+" ("+fields+") VALUES ("+values+")";this.sql.push(query);}
this.fireEvent('loadtable',this,this.tables[this.i])
this.i++;if(this.i<this.tables.length){this.load();}
else{this.gearsConn.transaction(this.sql);this.sql=[];this.fireEvent('load',this,response)}},readSingleResponse:function(response){var responseObj=Ext.decode(response.responseText);var fields=unescape(responseObj.fields);var removeKey=false;if(fields.substr(0,5)=='keyId'){fields=fields.slice(6);removeKey=true;}
var records=responseObj.rows;for(var j=0,len=responseObj.totalRows;j<len;j++){var values='';var rec=records[j];for(var k=(removeKey)?1:0,m=rec.length;k<m;k++){var value=rec[k].toString();value=escapeApici(unescape(value));values+="'"+value+"',";}
values=values.slice(0,-1);var query="REPLACE INTO "+this.table+" ("+fields+") VALUES ("+values+")";this.sql.push(query);}
this.gearsConn.transaction(this.sql);this.sql=[];this.fireEvent('loadsingle',this,this.tables[this.i])}})

