Ext.BLANK_IMAGE_URL="Content/images/default/s.gif";Ext.namespace("Aol");Ext.override(Ext.form.DisplayField,{getValue:function(){return this.value},setValue:function(a){this.value=a;this.setRawValue(this.formatValue(a));return this},formatValue:function(a){if(this.dateFormat&&Ext.isDate(a))return a.dateFormat(this.dateFormat);if(this.numberFormat&&typeof a=="number")return Ext.util.Format.number(a,this.numberFormat);return a}});
Aol.Grid=function(a){Aol.Grid.superclass.constructor.call(this,Ext.apply({title:"Elenco atti in pubblicazione",autoHeight:true,cm:new Aol.AffissioneColumnModel,disableSelection:true,stripeRows:true,viewConfig:{forceFit:true,enableRowBody:true,getRowClass:function(b,c,d){d.body="<p><b>Oggetto:</b> "+b.data.Oggetto+"</p>";return"x-grid3-row-expanded"}},autoload:true},a))};Ext.extend(Aol.Grid,Ext.grid.GridPanel,{});
Aol.GridSearch=function(a){Aol.Grid.superclass.constructor.call(this,Ext.apply({title:"Ricerca",collapsible:true,items:[{xtype:"form",border:false,bodyStyle:"padding:5px",labelAlign:"right",autoHeight:true,labelWidth:120,defaults:{width:300},buttons:[{text:"Trova",handler:this.trovaAffissioni,scope:this},{text:"Annulla",handler:this.annulla,scope:this}],items:[{xtype:"combo",fieldLabel:"Provenienza",hiddenName:"ProvenienzaSearch",mode:"local",triggerAction:"all",editable:false,store:new Ext.data.JsonStore({proxy:new Ext.data.HttpProxy({url:"Affissioni.aspx/UfficiRichiedenti",
method:"POST"}),totalProperty:"totalRecords",root:"uffici",remoteSort:false,autoLoad:true,id:"AFF_URCH",fields:["AFF_URCH","UFF_D_URCH"]}),valueField:"AFF_URCH",displayField:"UFF_D_URCH"},{xtype:"combo",fieldLabel:"Tipo atto",hiddenName:"TipoAttoSearch",mode:"local",triggerAction:"all",editable:false,store:new Ext.data.JsonStore({totalProperty:"totalRecords",root:"tipi",remoteSort:false,autoLoad:true,id:"AFF_CAT",fields:["AFF_CAT","ATT_DES"],proxy:new Ext.data.HttpProxy({url:"Affissioni.aspx/TipiAtto",
method:"POST"})}),valueField:"AFF_CAT",displayField:"ATT_DES"},{xtype:"textfield",fieldLabel:"Oggetto",name:"OggettoSearch"}]}]},a))};Ext.extend(Aol.GridSearch,Ext.Panel,{trovaAffissioni:function(){this.store.reload()},annulla:function(){this.getComponent(0).form.reset();this.store.reload()}});
Aol.AffissioneStore=function(a){Aol.AffissioneStore.superclass.constructor.call(this,Ext.apply({paramNames:{start:"Skip",limit:"Take",sort:"Sort",dir:"SortDir"},gridSearch:null,totalProperty:"totalRecords",root:"affissioni",remoteSort:true,autoLoad:false,idProperty:"Id",method:"POST",listeners:{beforeload:{scope:this,fn:this.prepareParams}}},a))};
Ext.extend(Aol.AffissioneStore,Ext.data.JsonStore,{prepareParams:function(){var a=this.gridSearch.getComponent(0).form.getValues();this.setBaseParam("UffCod",a.ProvenienzaSearch);this.setBaseParam("AttCod",a.TipoAttoSearch);this.setBaseParam("Oggetto",a.OggettoSearch)}});
Aol.AffissioneColumnModel=function(){Aol.AffissioneColumnModel.superclass.constructor.call(this,[{id:"affissione",header:"Provenienza",width:60,dataIndex:"UFF_D_URCH",sortable:true},{header:"Tipo atto",width:60,dataIndex:"ATT_DES",sortable:true},{header:"Data richiesta",width:20,dataIndex:"AFF_DRC",sortable:true,renderer:renderDate},{header:"Pubblicato il",width:20,dataIndex:"AFF_DIA",sortable:true,renderer:renderDate},{header:"Scadenza",width:20,dataIndex:"AFF_DSA",sortable:true,renderer:renderDate}])};
Ext.extend(Aol.AffissioneColumnModel,Ext.grid.ColumnModel,{});Aol.AffissioneBar=function(a){Aol.AffissioneBar.superclass.constructor.call(this,Ext.apply({pageSize:10,displayInfo:true,remoteSort:true,displayMsg:"Visualizzazione atti {0} - {1} di {2}",emptyMsg:"Nessun atto pubblicato",paramNames:{start:"Skip",limit:"Take"}},a))};Ext.extend(Aol.AffissioneBar,Ext.PagingToolbar,{});function renderDate(a){if(a&&!Ext.isEmpty(a))return a.format!==undefined?a.format("d/m/Y"):a}
Aol.AffissioneForm=function(a){Aol.AffissioneForm.superclass.constructor.call(this,Ext.apply({title:"Affissione",width:600,height:"auto",modal:true,resizable:false,layout:"fit",closeAction:"hide",formDocument:null,buttons:[{text:"Visualizza",handler:this.viewDocument,scope:this},{text:"Chiudi",handler:this.closeRecord,scope:this}],items:[{autoHeight:true,xtype:"form",border:false,bodyStyle:"padding:5px",labelAlign:"right",labelWidth:120,items:[{layout:"column",border:false,defaults:{border:false},
items:[{layout:"form",items:[{xtype:"displayfield",style:"padding:3px 3px 3px 0",fieldLabel:"N\u00b0 protocollo gen.",name:"AFF_NPG"}],columnWidth:0.5},{layout:"form",items:[{xtype:"displayfield",style:"padding:3px 3px 3px 0",fieldLabel:"Del",name:"AFF_DPG",dateFormat:"d/m/Y"}],columnWidth:0.5}]},{xtype:"displayfield",style:"padding:3px 3px 3px 0",fieldLabel:"Ricev. richiesta",name:"AFF_DRC",dateFormat:"d/m/Y"},{xtype:"displayfield",style:"padding:3px 3px 3px 0",fieldLabel:"Richiedente",name:"UFF_D_URCH"},
{xtype:"displayfield",style:"padding:3px 3px 3px 0",fieldLabel:"Emittente",name:"UFF_D_UEMI"},{xtype:"displayfield",style:"padding:3px 3px 3px 0",fieldLabel:"Tipo atto",name:"ATT_DES"},{layout:"column",border:false,defaults:{border:false},items:[{layout:"form",items:[{xtype:"displayfield",style:"padding:3px 3px 3px 0",fieldLabel:"N\u00b0 atto",name:"AFF_NUM"}],columnWidth:0.5},{layout:"form",items:[{xtype:"displayfield",style:"padding:3px 3px 3px 0",fieldLabel:"Del",name:"AFF_DTA",dateFormat:"d/m/Y"}],
columnWidth:0.5}]},{layout:"column",border:false,defaults:{border:false},items:[{layout:"form",items:[{xtype:"displayfield",style:"padding:3px 3px 3px 0",fieldLabel:"Inizio affissione",name:"AFF_DIA",dateFormat:"d/m/Y"}],columnWidth:0.5},{layout:"form",items:[{xtype:"displayfield",style:"padding:3px 3px 3px 0",fieldLabel:"Durata",name:"AFF_DUR"}],columnWidth:0.5}]},{layout:"column",border:false,defaults:{border:false},items:[{layout:"form",items:[{xtype:"displayfield",style:"padding:3px 3px 3px 0",
fieldLabel:"Giorni proroga",name:"AFF_DPR"}],columnWidth:0.5},{layout:"form",items:[{xtype:"displayfield",style:"padding:3px 3px 3px 0",fieldLabel:"Scadenza",name:"AFF_DSA",dateFormat:"d/m/Y"}],columnWidth:0.5}]},{xtype:"displayfield",style:"padding:3px 3px 3px 0",fieldLabel:"Oggetto",name:"Oggetto"},{xtype:"combo",id:"cmbAllegati",fieldLabel:"Allegati",mode:"local",triggerAction:"all",editable:false,width:382,lazyInit:false,store:new Ext.data.JsonStore({proxy:new Ext.data.HttpProxy({url:"Allegato.aspx/Index",
method:"POST"}),totalProperty:"totalRecords",root:"affissioni",remoteSort:false,autoLoad:false,id:"Id",fields:["Id","Descrizione","ResponseFile"]}),valueField:"Id",displayField:"Descrizione"}]}]},a))};
Ext.extend(Aol.AffissioneForm,Ext.Window,{viewDocument:function(){var a=this.getComponent(0).get("cmbAllegati");if(a){var b=a.getValue();if(!Ext.isEmpty(b)){var c=String.format("Allegato.aspx/ViewDocument?allegatoId={0}&affissioneId={1}",b,this.currentRec.data.Id),d=this.getMediaType(a,b);if(d=="PDFFRAME"){a={mediaType:d,url:c,unsupportedText:this.getUnsupportedText(a,b,c),autoSize:true};(new Ext.ux.MediaWindow({id:"PDFViewerWin",bodyStyle:"position:relative; padding:0px;",width:750,height:550,maximizable:true,
mediaCfg:a,title:"Affissione"})).show()}else{try{Ext.destroy(Ext.get("downloadIframe"))}catch(e){}Ext.DomHelper.append(document.body,{tag:"iframe",id:"downloadIframe",frameBorder:0,width:0,height:0,css:"display:none;visibility:hidden;height:0px;",src:c})}}}},closeRecord:function(){this.hide()},getMediaType:function(a,b){if(a=a.findRecord("Id",b))switch(a.data.ResponseFile){case "application/pdf":return"PDFFRAME";case "image/gif":return"GIF";case "image/tiff":return"TIFF";case "image/jpeg":return"JPEG";
case "image/jp2":return"JP2";case "image/png":return"PNG";case "text/plain":return"TXT";case "application/rtf":return"RTF";case "application/msword":return"WORD";case "application/vnd.ms-excel":return"EXCEL";case "application/vnd.ms-powerpoint":return"POWERPOINT";default:return"PDFFRAME"}else return""},getUnsupportedText:function(a,b,c){return a.findRecord("Id",b)?String.format("Impossibile visualizzare l'allegato direttamente nel browser. Provare a fare click <a href='{0}'>qui</a> per scaricare il file.",
c):"Impossibile trovare il visualizzatore per il tipo di file scelto"}});
Ext.onReady(function(){var a=new Aol.GridSearch({});a.render("gridSearch");var b=new Aol.AffissioneStore({fields:["Id","UFF_D_URCH","UFF_D_UEMI","ATT_DES","AFF_NPG",{name:"AFF_DPG",type:"date",dateFormat:"M$"},{name:"AFF_DRC",type:"date",dateFormat:"M$"},"Oggetto",{name:"AFF_DIA",type:"date",dateFormat:"M$"},"AFF_DUR","AFF_DPR",{name:"AFF_DSA",type:"date",dateFormat:"M$"},"AFF_NUM","AFF_PDF",{name:"AFF_DTA",type:"date",dateFormat:"M$"},{name:"HasPdf",type:"boolean"}],url:"Affissioni.aspx",gridSearch:a});
a.store=b;b.setDefaultSort("Id","asc");a=new Aol.AffissioneBar({store:b});a=new Aol.Grid({store:b,bbar:a});var c=new Aol.AffissioneForm({});a.on({rowclick:function(d,e){d=d.store.getAt(e);c.buttons[0].setDisabled(true);c.show();c.center();c.currentRec=d;c.getComponent(0).getForm().loadRecord(d);var f=c.getComponent(0).get("cmbAllegati");if(f){e=f.getStore();f.setValue("");e.on("load",function(h,g){if(g.length>0){f.setValue(g[0].data.Id);c.buttons[0].setDisabled(false)}else f.setValue("")},this,{single:true});
e.load({params:{affissioneId:d.data.Id}})}},scope:this});a.render("gridContainer");b.load({params:{Skip:0,Take:10}})});
