
if("undefined"===typeof brodos){brodos={}}
brodos.dsi={}
Ext.namespace("brodos.dsi");brodos.dsi.Config={xmlHeader:'<?xml version="1.0" encoding="UTF-8"?>',xmlNamespace:"http://brodos.net/schemas/dataStorage/2008/01"}
brodos.dsi.elements={}
Ext.namespace("brodos.dsi.elements");brodos.dsi.elements.Element=function(){this.addEvents('createexception');brodos.dsi.elements.Element.superclass.constructor.call(this);};Ext.extend(brodos.dsi.elements.Element,Ext.util.Observable,{createDom:function(){},createXml:function(setHeader){var dom=this.createDom();var root=document.createElement("root");root.appendChild(dom);var returnValue="";if(setHeader){returnValue=brodos.dsi.Config.xmlHeader;}
returnValue+=root.innerHTML.replace(/(\w+)=(\w+)/g,'$1="$2"');return returnValue;},parseDom:function(root){}});
Ext.namespace("brodos.dsi.elements");brodos.dsi.elements.Tab=function(config){Ext.apply(this,config);Ext.id(this);brodos.dsi.elements.Tab.superclass.constructor.call(this);};Ext.extend(brodos.dsi.elements.Tab,brodos.dsi.elements.Element,{key:"",refid:null,untabbed:false,name:"",createDom:function(){var root=document.createElement('tab');if(this.key){root.setAttribute('key',this.key);}
if(this.refid){root.setAttribute('refid',this.refid);}
if(this.untabbed){root.setAttribute('untabbed',true);}
if(this.name){root.setAttribute('name',this.name);}
return root;},parseDom:function(root){this.key=root.getAttribute('key');this.refid=root.getAttribute('refid');this.untabbed=root.getAttribute('untabbed');this.name=root.getAttribute('name');}});
Ext.namespace("brodos.dsi.elements");brodos.dsi.elements.Count=function(config){this.max=20;Ext.apply(this,config);Ext.id(this);brodos.dsi.elements.Count.superclass.constructor.call(this);};Ext.extend(brodos.dsi.elements.Count,brodos.dsi.elements.Element,{max:0,value:0,createDom:function(){var root=document.createElement('count');if(this.max>0){root.setAttribute('max',this.max);}
return root;},parseDom:function(root){this.value=root.getAttribute('value');this.max=root.getAttribute('max');}});
Ext.namespace("brodos.dsi.elements");brodos.dsi.elements.Column=function(config){Ext.apply(this,config);Ext.id(this);brodos.dsi.elements.Column.superclass.constructor.call(this);};Ext.extend(brodos.dsi.elements.Column,brodos.dsi.elements.Element,{subject:null,name:null,expression:null,type:null,precision:null,description:null,distinctive:false,direction:null,value:null,foreignfield:null,foreignkey:null,isCalculated:false,readonly:false,createDom:function(){var root=document.createElement('column');if(!this.name){this.fireEvent('createexception',' Column name not set!');return root;}
root.setAttribute('name',this.name);if(this.value){root.appendChild(document.createTextNode(this.value));}
if(this.distinctive){root.setAttribute('distinctive',this.distinctive);}
if(this.isCalculated){root.setAttribute('iscalculated',this.isCalculated);}
if(this.subject){root.setAttribute('subject',this.subject);}
if(this.expression){root.setAttribute('expression',this.expression);}
if(this.type){root.setAttribute('type',this.type);}
if(this.precision){root.setAttribute('precision',this.precision);}
if(this.description){root.setAttribute('description',this.description);}
if(this.direction){root.setAttribute('direction',this.direction);}
if(this.foreignfield){root.setAttribute('foreignfield',this.foreignfield);}
if(this.foreignkey){root.setAttribute('foreignkey',this.foreignkey);}
if(this.readonly){root.setAttribute('readonly',this.readonly);}
return root;},parseDom:function(root){var q=Ext.DomQuery;this.subject=root.getAttribute('subject');this.name=root.getAttribute('name');this.expression=root.getAttribute('expression');this.type=root.getAttribute('type');this.precision=root.getAttribute('precision');this.description=root.getAttribute('description');this.distinctive=root.getAttribute('distinctive');this.direction=root.getAttribute('direction');this.value=q.selectValue('column',root);this.foreignfield=root.getAttribute('foreignfield');this.foreignkey=root.getAttribute('foreignkey');this.isCalculated=root.getAttribute('iscalculated');this.readonly=root.getAttribute('readonly');}});
Ext.namespace("brodos.dsi.elements");brodos.dsi.elements.Filter=function(config){Ext.apply(this,config);Ext.id(this);brodos.dsi.elements.Filter.superclass.constructor.call(this);};Ext.extend(brodos.dsi.elements.Filter,brodos.dsi.elements.Element,{negated:false,operation:null,op1:"",op2:"",createDom:function(){var root=document.createElement('filter');if(this.negated){root.setAttribute('negated',this.negated);}
root.setAttribute('op1',this.op1);root.setAttribute('op2',this.op2);if(this.operation){root.setAttribute('operation',this.operation);}
return root;},parseDom:function(root){this.negated=root.getAttribute('negated');this.operation=root.getAttribute('operation');this.op1=root.getAttribute('op1');this.op2=root.getAttribute('op2');}});
Ext.namespace("brodos.dsi.elements");brodos.dsi.elements.OrderList=function(){Ext.id(this);this.columns=new Ext.util.MixedCollection();brodos.dsi.elements.OrderList.superclass.constructor.call(this);};Ext.extend(brodos.dsi.elements.OrderList,brodos.dsi.elements.Element,{completenessRanking:false,direction:null,columns:null,createDom:function(){var root=document.createElement('order-list');if(this.completenessRanking){root.setAttribute('completeness-ranking',true);if(this.direction){root.setAttribute('direction',this.direction);}}
this.columns.each(function(item){root.appendChild(item.createDom());},this);return root;},parseDom:function(root){this.completenessRanking=root.getAttribute('completeness-ranking');this.direction=root.getAttribute('direction');var columnElements=Ext.DomQuery.select('column');for(var i=0;i<columnElements.length;i++){var column=new brodos.dsi.elements.Column();column.parseDom(columnElements[i]);this.columns.add(column);}}});
Ext.namespace("brodos.dsi.elements");brodos.dsi.elements.Relation=function(config){this.relations=new Ext.util.MixedCollection();this.filters=new Ext.util.MixedCollection();Ext.apply(this,config);Ext.id(this);brodos.dsi.elements.Relation.superclass.constructor.call(this);};Ext.extend(brodos.dsi.elements.Relation,brodos.dsi.elements.Element,{type:"OR",negated:false,relations:null,filters:null,createDom:function(){var root=document.createElement('filter-relation');root.setAttribute('type',this.type);if(this.negated){root.setAttribute('negated',this.negated);}
this.relations.each(function(item){root.appendChild(item.createDom());},this);this.filters.each(function(item){root.appendChild(item.createDom());},this);return root;},parseDom:function(root){var q=Ext.DomQuery;this.type=root.getAttribute('type');this.negated=root.getAttribute('negated');var relationElements=q.select('filter-relation');for(var i=0;i<relationElements.length;i++){var relation=new brodos.dsi.elements.Relation();relation.parseDom(relationElements[i]);this.relations.add(relation);}
var filterElements=q.select('filter');for(var i=0;i<filterElements.length;i++){var filter=new brodos.dsi.elements.Filter();filter.parseDom(filterElements[i]);this.filters.add(filter);}}});
Ext.namespace("brodos.dsi.elements");brodos.dsi.elements.Paging=function(config){this.maxcount=20;Ext.apply(this,config);Ext.id(this);brodos.dsi.elements.Paging.superclass.constructor.call(this);};Ext.extend(brodos.dsi.elements.Paging,brodos.dsi.elements.Element,{maxcount:null,count:null,skip:0,limit:20,fromBehind:false,createDom:function(){var root=document.createElement('paging');if(this.maxcount>0){root.setAttribute('maxcount',this.maxcount);}
if(this.skip&&this.skip>=0){root.setAttribute('skip',this.skip);}
if(this.limit&&this.limit>0){root.setAttribute('limit',this.limit);}
if(this.fromBehind){root.setAttribute('from-behind',true);}
return root;},parseDom:function(root){this.value=root.getAttribute('count');this.maxcount=root.getAttribute('maxcount');this.skip=root.getAttribute('skip');this.limit=root.getAttribute('limit');this.fromBehind=root.getAttribute('from-behind');}});
Ext.namespace("brodos.dsi.elements");brodos.dsi.elements.QueryDefinition=function(config){this.columns=new Ext.util.MixedCollection();Ext.apply(this,config);this.orderList=new brodos.dsi.elements.OrderList();this.filterSettings=new Ext.util.MixedCollection();Ext.id(this);brodos.dsi.elements.QueryDefinition.superclass.constructor.call(this);};Ext.extend(brodos.dsi.elements.QueryDefinition,brodos.dsi.elements.Element,{key:null,refid:null,description:null,readonly:false,paging:null,tab:null,columns:null,filterSettings:null,orderList:null,createDom:function(){var root=document.createElement('query-definition');if(this.key){root.setAttribute('key',this.key);}
if(this.refid){root.setAttribute('refid',this.refid);}
if(this.description){root.setAttribute('description',this.description);}
if(this.readonly){root.setAttribute('readonly',this.readonly);}
if(this.paging){root.appendChild(this.paging.createDom());}
if(this.tab){root.appendChild(this.tab.createDom());}
if(this.columns){this.columns.each(function(item){root.appendChild(item.createDom());},this);}
if(this.filterSettings&&this.filterSettings.getCount()>0){var filtersElement=document.createElement('filter-relation');if(this.filterSettings.type){filtersElement.setAttribute('type',this.filterSettings.type);}
this.filterSettings.each(function(item){filtersElement.appendChild(item.createDom());},this);root.appendChild(filtersElement);}
if(this.orderList&&this.orderList.columns.getCount()>0){root.appendChild(this.orderList.createDom());}
return root;},parseDom:function(root){var q=Ext.DomQuery;this.key=root.getAttribute('key');this.refid=root.getAttribute('refid');this.description=root.getAttribute('description');this.readonly=root.getAttribute('readonly');this.paging=new brodos.dsi.elements.Paging();var pagingElement=q.selectNode('paging',root);if(pagingElement){this.paging.parseDom(pagingElement);}
var tabElement=q.selectNode('tab',root);if(tabElement){this.tab=new brodos.dsi.elements.Tab();this.tab.parseDom(tabElement);}
var orderListElement=q.selectNode('order-list',root);if(orderListElement){this.orderList=new brodos.dsi.elements.OrderList();this.orderList.parseDom(orderListElement);}
var columnElements=q.select('column',root);for(var i=0;i<columnElements.length;i++){var column=new brodos.dsi.elements.Column();column.parseDom(columnElements[i]);this.columns.add(column);}
var filterRelationElement=q.select('filter-relation',root);for(var i=0;i<filterRelationElement.length;i++){var relation=new brodos.dsi.elements.Relation();relation.parseDom(filterRelationElement[i]);this.filterSettings.add(relation);var filters=q.select('filter',filterRelationElement[i]);for(var o=0;o<filters.length;o++){var filter=new brodos.dsi.elements.Filter();filter.parseDom(filters[o]);this.filterSettings.add(filter);}}}});
Ext.namespace("brodos.dsi.elements");brodos.dsi.elements.Dataset=function(config){this.columns=new Ext.util.MixedCollection();Ext.apply(this,config);Ext.id(this);brodos.dsi.elements.Dataset.superclass.constructor.call(this);};Ext.extend(brodos.dsi.elements.Dataset,brodos.dsi.elements.Element,{key:null,toDelete:false,refid:null,tab:null,columns:null,createDom:function(){var root=document.createElement('dataset');if(this.toDelete){root.setAttribute('delete',this.toDelete);}
if(this.key){root.setAttribute('key',this.key);}
if(this.refid){root.setAttribute('refid',this.refid);}
if(this.tab){root.appendChild(this.tab.createDom());}
this.columns.each(function(item){root.appendChild(item.createDom());},this);return root;}});
Ext.namespace("brodos.dsi.elements");brodos.dsi.elements.Window=function(config){Ext.apply(this,config);Ext.id(this);brodos.dsi.elements.Window.superclass.constructor.call(this);};Ext.extend(brodos.dsi.elements.Window,brodos.dsi.elements.Element,{skip:0,limit:20,fromBehind:false,createDom:function(){var root=document.createElement('window');if(this.skip&&this.skip>=0){root.setAttribute('skip',this.skip);}
if(this.limit&&this.limit>0){root.setAttribute('limit',this.limit);}
if(this.fromBehind){root.setAttribute('from-behind',true);}
return root;},parseDom:function(root){this.skip=root.getAttribute('skip');this.limit=root.getAttribute('limit');this.fromBehind=root.getAttribute('from-behind');}});
Ext.namespace("brodos.dsi.elements");brodos.dsi.elements.DataInput=function(){Ext.id(this);this.elements=new Ext.util.MixedCollection();brodos.dsi.elements.DataInput.superclass.constructor.call(this);};Ext.extend(brodos.dsi.elements.DataInput,brodos.dsi.elements.Element,{elements:null,add:function(element){this.elements.add(element);},remove:function(element){this.elements.remove(element);},createDom:function(){var root=document.createElement('data-input');root.setAttribute('xmlns',brodos.dsi.Config.xmlNamespace);this.elements.each(function(item){root.appendChild(item.createDom());},this);return root;}});
Ext.namespace("brodos.dsi.elements");brodos.dsi.elements.DataQuery=function(){Ext.id(this);this.queryDefinitions=new Ext.util.MixedCollection();brodos.dsi.elements.DataQuery.superclass.constructor.call(this);};Ext.extend(brodos.dsi.elements.DataQuery,brodos.dsi.elements.Element,{queryDefinitions:null,createDom:function(){if(this.queryDefinitions.getCount()==0){this.fireEvent('createexception','No Querydefinition added yet!');return"";}
var root=document.createElement('data-query');root.setAttribute('xmlns',brodos.dsi.Config.xmlNamespace);this.queryDefinitions.each(function(item){root.appendChild(item.createDom());},this);return root;}});
Ext.namespace("brodos.dsi.elements");brodos.dsi.elements.Metadata=function(){Ext.id(this);this.columns=new Ext.util.MixedCollection();this.tabs=new Ext.util.MixedCollection();this.queryDefinitions=new Ext.util.MixedCollection();brodos.dsi.elements.Metadata.superclass.constructor.call(this);};Ext.extend(brodos.dsi.elements.Metadata,brodos.dsi.elements.Element,{columns:null,tabs:null,queryDefinitions:null,createDom:Ext.emptyFn,createXml:Ext.emptyFn,parseDom:function(root){var q=Ext.DomQuery;var columns=q.select("column",root);for(var i=0;i<columns.length;i++){var column=new brodos.dsi.elements.Column();column.parseDom(columns[i]);this.columns.add(column);}
var tabs=q.select("tab",root);for(var i=0;i<tabs.length;i++){var tab=new brodos.dsi.elements.Tab();tab.parseDom(tabs[i]);this.tabs.add(tab);}
var definitions=q.select("query-definition",root);for(var i=0;i<definitions.length;i++){var definition=new brodos.dsi.elements.QueryDefinition();definition.parseDom(definitions[i]);this.queryDefinitions.add(definition);}}});
brodos.dsi.reader={}
Ext.namespace("brodos.dsi.reader");brodos.dsi.reader.XmlResultReader=function(meta,recordType){var meta=meta||{};brodos.dsi.reader.XmlResultReader.superclass.constructor.call(this,meta,recordType||meta.fields);};Ext.extend(brodos.dsi.reader.XmlResultReader,Ext.data.DataReader,{read:function(response){var doc=response.responseXML;return this.readRecords(doc);},readRecords:function(doc){this.xmlData=doc;var root=doc.documentElement||doc;var q=Ext.DomQuery;var status=q.selectNode('status',root);var errorText=q.selectValue('status',root);var errorCode=status.getAttribute("code");if(errorCode!=0){throw{name:errorCode,message:errorText};return{success:false,records:[],totalRecords:0}}
if(q.selectNode('result-set',root)){var recordType=this.recordType,fields=recordType.prototype.fields;return this.processResultSet(q.selectNode('result-set',root),recordType,fields);}
else if(q.selectNode('metadata',root)){return this.processMetaData(q.selectNode('metadata',root));}
return{success:true,records:[],totalRecords:0};},processResultSet:function(root,recordType,fields){var q=Ext.DomQuery;var totalRecords=0,success=true;var paging=q.selectNode("paging",root);var countValue;if(paging){countValue=paging.getAttribute("count");}
var elements=q.select("row",root);var records=[];for(var i=0;i<elements.length;i++){var row=elements[i];var id=row.getAttribute("key");var childs=q.select("column",row);var values={};if(fields.items[0].name=="tB_checkboxField"){var newChild=document.createElement("column");newChild.name="tB_checkboxField";newChild.value="";var tmpChilds=childs;childs=[newChild];childs=childs.concat(tmpChilds);}
for(var o=0;o<childs.length;o++){var child=childs[o];var name=child.getAttribute("name");var text=[];for(var n=0;n<child.childNodes.length;n++){if(child.childNodes[n].nodeType==3||child.childNodes[n].nodeType==4){text.push(child.childNodes[n].nodeValue);}}
var value=text.join("");if(fields.items[o].type==Ext.data.Types.DATE){value=Date.parseDate(value,fields.items[o].dateFormat||"d.m.Y");}
if(fields.items[o].type==Ext.data.Types.BOOL){value=(value=='1'?true:false);}
if(typeof value=="undefined")value="";values[name]=value;}
var record=new recordType(values,id);record.node=row;records[records.length]=record;}
return{success:success,records:records,totalRecords:countValue};},processMetaData:function(root){var metadata=new brodos.dsi.elements.Metadata();metadata.parseDom(root);var record=new Ext.data.Record({metadata:metadata},metadata.id);return{success:true,records:[record],totalRecords:1};},createNewRecord:function(){var record=new this.recordType();record.data=[];record.isNew=true;for(var i=0;i<record.fields.items.length;i++){var recordItem=record.fields.items[i];if(recordItem.defaultValue){record.set(recordItem.name,recordItem.defaultValue);}
else{switch(recordItem.type){case"string":record.set(recordItem.name,"");break;case"bool":record.set(recordItem.name,false);break;case"date":record.set(recordItem.name,new Date());break;case"datetime":record.set(recordItem.name,new Date());break;case"float":record.set(recordItem.name,"");break;default:record.set(recordItem.name,"");break;}}}
return record;}});
