1 /**
  2  * @require framework/widgets/form/MultipleInputField.js
  3  * @require framework/widgets/toponimi/TOPDizioniManagement.js
  4  * @require framework/widgets/toponimi/TOPDizioniDataPanel.js
  5  * @require framework/widgets/toponimi/TOPAttributiDizioniManagement.js
  6  * @require framework/widgets/toponimi/TOPAttributiDizioniDataPanel.js
  7  */
  8 
  9 /**
 10  * @namespace framework.widgets
 11  */
 12 Ext.namespace("framework.widgets"),
 13         /** 
 14          *  Panel search engine container.
 15          *  This implementation manage different search engine. 
 16          *  By default, place a comboBox to switch different search engine components located inside the panel. 
 17          *  @name_ PanelSearch 
 18          *  @class Panel search engine container.
 19          *  @constructor
 20          *  @extends <a target="_blank" href="http://docs.sencha.com/extjs/4.1.3/#!/api/Ext.panel.Panel">Ext.Panel</a>
 21          */
 22         framework.widgets.TopDataPanel = Ext.extend(Ext.Window, {
 23             /**
 24              * The Servlet name used to get Poi Term-Category information
 25              * @type String
 26              */
 27             topCatTipServeltName: 'toponimirequest',
 28             id: 'IDTopDataPanel',
 29             layout: 'fit',
 30             width: 500,
 31             height: 550,
 32             title: 'Toponimo',
 33             closable: false,
 34             resizable: true,
 35             plain: true,
 36             border: false,
 37             x: 20,
 38             y: 40,
 39             initTipo: null,
 40             /** api: config[urlService]
 41              *  
 42              *  url to proxy for authenticate http calls
 43              *  @public
 44              *  @type String
 45              */
 46             urlProxy: '',
 47             /** api: config[urlCatasto]
 48              *  
 49              *  url for wfs catasto service
 50              *  @public
 51              *  @type String
 52              */
 53             urlWFS: '/geoserver/ows?',
 54             /** api: config[serviceType]
 55              *  
 56              *  Service type for catasto service (query string parameter)
 57              *  Default WFS
 58              *  @public
 59              *  @type String
 60              */
 61             serviceType: 'WFS',
 62             /** api: config[version]
 63              *  
 64              *  Version for WFS service (query string parameter)
 65              *  Default 1.0.0
 66              *  @public
 67              *  @type String
 68              */
 69             version: '1.0.0',
 70             /** api: config[GetFeature]
 71              *  
 72              *  Request type for WFS service (query string parameter)
 73              *  Default GetFeature
 74              *  @public
 75              *  @type String
 76              */
 77             requestType: 'GetFeature',
 78             /** api: config[typeName]
 79              * 
 80              *  typeName for WFS service (query string parameter)
 81              *  @public
 82              *  @type String
 83              */
 84            
 85              typeName: 'dbu:limitiamministrcomunali', // dbu:LIMITIAMMINISTRCOMUNALI
 86              nameGeometry: 'geom', // POLIGONO
 87              properties_nome: 'nome', // NOME
 88              properties_istat: 'codiceist1', //CODICEISTATCOMUNALE
 89             /** api: config[infoFormat]
 90              *  
 91              *  maxFeatures for WFS service (query string parameter)
 92              *  Default 50
 93              *  @public
 94              *  @type String
 95              */
 96             maxFeatures: 5,
 97             /** api: config[geometryFields]
 98              *  
 99              *  fields from service answer to be transformed on OpenLayers.Bounds
100              *  @public
101              *  @type Array of String
102              */
103             geometryFields: null,
104             srs: 'EPSG:300',
105             geometryTop: null,
106             /**
107              * paht for images marker,
108              * default value is "theme/app/img/".
109              * @public
110              * @type String
111              */
112             markersImgPath: 'theme/app/img/',
113             click: null,
114             checkControlClick: false,
115             userAuthDS: null,
116             
117             catDefaultValue: null,
118             tipoDefaultValue: null,
119             
120             dizioni: null,
121             extentAreaSemantica: null,
122             
123             destroy: function() {
124                 framework.widgets.TopDataPanel.superclass.destroy.apply(this, arguments);
125             },
126             initComponent: function() {
127                 this.catFaccDS = new Ext.data.Store({
128                     url: this.topCatTipServeltName,
129                     baseParams: {method: 'getAllCategoriesFacc',start:0,limit:100},
130                     reader: new Ext.data.JsonReader({
131                         root: 'categoriesfacc',
132                         totalProperty: 'totalCount',
133                         id: 'categoria'
134                     }, [
135                         {name: 'categoria', mapping: 'categoria'}
136                      ]),
137                     listeners: {
138                         load: function() {
139                         },
140                         scope: this
141                     }
142                 });
143                 this.catFaccDS.on(
144                         'load', function(store) {   // store is equivalent to this.catFaccDS
145                             var i = 0;
146                             var itemFound = false;
147                             while ((i < store.data.items.length) && (!itemFound)) {
148                                 if (store.data.items[i++].data.categoria === this.catDefaultValue) {
149                                     this._toponimoform.items.items[4].setValue(this.catDefaultValue);
150                                     itemFound = true;
151                                 }
152                             }
153                             if (itemFound) {
154                                 this.tipiByCategoriaFacc.baseParams['categoriaFacc'] = store.data.items[i-1].data.categoria;
155                                 this.tipiByCategoriaFacc.reload();
156                                 this.initTipo = this.tipoDefaultValue;
157                             }
158                 }, this);
159 
160                 this.tipiByCategoriaFacc = new Ext.data.Store({
161                     url: this.topCatTipServeltName,
162                     baseParams: {method: 'getTipiByCategoriaFacc'},
163                     reader: new Ext.data.JsonReader({
164                         root: 'tipiToponimi',
165                         totalProperty: 'totalCount',
166                         id: 'codTipo'
167                     }, [
168                         {name: 'codTipo', mapping: 'codTipo'},
169                         {name: 'codFacc', mapping: 'categoriaFaccObject.codice'},
170                         {name: 'tipo', mapping: 'tipo'},
171                         {name: 'categoriaFacc', mapping: 'categoriaFaccObject.categoria'},
172                         {name: 'descrizioneFacc', mapping: 'categoriaFaccObject.descrizione'},
173                         {name: 'valid', mapping: 'valid'}
174                     ]),
175                     listeners: {
176                         load: function() {
177                             if (this.initTipo) {
178                                 this._toponimoform.getForm().findField('tipo').setValue(this.initTipo);                            
179                                 this.initTipo = null;
180                             }
181                              this.checkPermission();
182                         },
183                         scope: this
184                     }
185                 });
186                 
187                 /**
188                 * Store TipiLocalità
189                 */
190 
191                this.tipilocalitaDS = new Ext.data.Store({
192                    url: this.topCatTipServeltName,
193                    baseParams: {method: 'getAllTipiLocalita'},
194                    reader: new Ext.data.JsonReader(
195                            {
196                                id: 'codice',
197                                root: 'tipiLocalita',
198                                totalProperty: 'totalCount'
199                            }, [
200                        {name: 'codice', mapping: 'codice'},
201                        {name: 'descrizione', mapping: 'descrizione'}
202                    ]),
203                    listeners: {
204                         load: function() {                  
205                             this._toponimoform.getForm().findField('tipo_loc').setValue(this._toponimoform.form.getValues().tipo_loc);
206                         },
207                         scope: this
208                     }
209                }); 
210                
211                 /**
212                 * Store Categoria
213                 */
214 
215                this.categoriesDS = new Ext.data.Store({
216                    url: this.topCatTipServeltName,
217                    baseParams: {method: 'getAllCategories'},
218                    reader: new Ext.data.JsonReader(
219                            {
220                                id: 'codice',
221                                root: 'categories',
222                                totalProperty: 'totalCount'
223                            }, [
224                        {name: 'codice', mapping: 'codice'},
225                        {name: 'descrizione', mapping: 'descrizione'}
226                    ]),
227                    listeners: {
228                         load: function() {
229                             this._toponimoform.getForm().findField('categories').setValue(this._toponimoform.form.getValues().categories);
230                         },
231                         scope: this
232                     }
233                }); 
234                
235                 this.typesByUserDs = new Ext.data.Store({
236                     url: this.topCatTipServeltName,
237                     baseParams: {method: 'getTypes4User'},
238                     reader: new Ext.data.JsonReader({
239                         root: 'types',
240                         totalProperty: 'totalCount',
241                         id: 'codTipo'
242                     }, [
243                         {name: 'codTipo', mapping: 'codTipo'},
244                         {name: 'codFacc', mapping: 'codFacc'},
245                         {name: 'tipo', mapping: 'tipo'},
246                         {name: 'valid', mapping: 'valid'}
247                     ]),
248                     listeners: {
249                         load: function() {
250       //                       this.checkPermission();
251                         },
252                         scope: this
253                     }
254                 });
255 
256 
257                 var _self = this;
258                 
259                 this._toponimoform = new Ext.FormPanel({
260                     labelWidth: 100,
261                     frame: true,
262                     defaultType: 'textfield',
263                     id: 'toponimoFormID',
264 //          monitorValid: true,
265                     standardSubmit: false,
266                     layout: 'form',
267                   /*  listeners: {
268                         modPositionTOP: function(e) {
269 
270                             this.fireEvent('modPositionTOP', e);
271 
272                             var lonlat = e.object.getLonLatFromPixel(e.xy);
273                             this.updateCoord(lonlat);
274                             this.updateISTAT(lonlat);
275                         },
276                         scope: this
277                     },*/
278                     items: [{
279                             id: 'topTipiLocalita',
280                             xtype: 'combo',
281                             name: 'tipo_loc_name',
282                             mode: 'local',
283                             editable: false,
284                             store: this.tipilocalitaDS,
285                             valueField: 'codice',
286                             displayField: 'descrizione',
287                             width: 350,
288                             blankText : this.blankText,
289                             emptyText: 'Seleziona un tipo localita\'...',
290                             fieldLabel: 'Tipo localita\'',
291                             hiddenName: 'tipo_loc',
292                             triggerAction: 'all',
293                             allowBlank: false,
294                             lastQuery: ''
295 
296                         },{
297                             id: 'topCategories',
298                             xtype: 'combo',
299                             name: 'categories_name',
300                             mode: 'local',
301                             editable: false,
302                             store: this.categoriesDS,
303                             valueField: 'codice',
304                             displayField: 'descrizione',
305                             width: 350,
306                             blankText : this.blankText,
307                             emptyText: 'Seleziona una categoria...',
308                             fieldLabel: 'Categoria',
309                             hiddenName: 'categories',
310                             triggerAction: 'all',
311                             allowBlank: false,
312                             lastQuery: ''
313 
314                         },{
315                             id: 'topUpdate',
316                             xtype: 'displayfield',
317                             //  fieldLabel: 'update',
318                             name: 'update',
319                             width: 350
320                         }, {
321                             xtype: 'radiogroup',
322                             // fieldLabel: 'Auto Layout',
323                             name: 'publicTop',
324                             id: 'publicTop',
325                             width: 350,
326                           //  height: 18,
327                           //  columns: [170, 170],
328                             items: [
329                                 {boxLabel: 'Online', name: 'rb-auto', inputValue: 1},
330                                 {boxLabel: 'Offline', name: 'rb-auto', inputValue: 2, checked: true}
331                             ]
332                         },{
333                             width: 460,
334                             height: 90,
335                             xtype: 'fieldset',
336                             title: 'standard FACC',
337                             collapsible: false,
338                           //  defaults: {width: 140},
339                             //style: 'margin-left: 10px;',
340                             defaultType: 'textfield',
341                           //  labelAlign:'top',
342                             items: [
343                                 {
344                                     id: 'topCategoriaFacc',
345                                     xtype: 'combo',
346                                     name: 'categoria_name',
347                                     mode: 'local',
348                                     editable: false,
349                                     store: this.catFaccDS,
350                                     valueField: 'categoria',
351                                     displayField: 'categoria',
352                                     width: 320,
353                                     blankText : this.blankText,
354                                     emptyText: 'Seleziona una categoria...',
355                                     fieldLabel: 'Categoria',
356                                     hiddenName: 'categoria',
357                                     triggerAction: 'all',
358                                     allowBlank: false,
359                                     listeners: {
360                                         select: function(combo, record, index) {
361                                             var categoria = record.data.categoria;
362                                             Ext.getCmp('topTipologiaFacc').setValue(undefined);//sbianco la combo delle tipologie
363                                             _self.tipiByCategoriaFacc.baseParams = _self.tipiByCategoriaFacc.baseParams || {};
364                                             _self.tipiByCategoriaFacc.baseParams['categoriaFacc'] = categoria;
365                                             _self.tipiByCategoriaFacc.reload();
366                                         }
367                                     }
368                                 }, {
369                                     id: 'topTipologiaFacc',
370                                     xtype: 'combo',
371                                     name: 'tipo_name',
372                                     mode: 'local',
373                                     editable: false,
374                                     store: this.tipiByCategoriaFacc,
375                                     valueField: 'codTipo',
376                                     displayField: 'tipo',
377                                     width: 320,
378                                     blankText : this.blankText,
379                                     emptyText: 'Seleziona una tipologia...',
380                                     fieldLabel: 'Tipologia',
381                                     hiddenName: 'tipo',
382                                     triggerAction: 'all',
383                                     allowBlank: false,
384                                     lastQuery: '',
385                                     listeners: {
386                                         select: function(combo, record, index) {
387                                             _self.checkPermission();
388                                         }
389                                     }
390 
391                                  }]
392                         }, {
393                             id: 'topComune',
394                             xtype: 'displayfield',
395                             fieldLabel: 'Comune',
396                             name: 'comune',
397                             width: 350,
398                             allowBlank: false
399                         }, {
400                             id: 'topISTAT',
401                             hidden: true,
402                             fieldLabel: 'ISTAT',
403                             name: 'istat',
404                             width: 350,
405                             allowBlank: false
406                         },
407                         {id: 'geometry', xtype: 'hidden', name: 'geometry'}
408                         ,{
409                             width: 460,
410                             height: 70,
411                             xtype: 'fieldset',
412                             title: 'Area semantica',
413                             collapsible: false,
414                           //  defaults: {width: 140},
415                             //style: 'margin-left: 10px;',
416                             defaultType: 'textfield',
417                           //  labelAlign:'top',
418                             items: [
419                                 {
420                                     xtype: 'container',
421                                     id: 'editor_panel',
422                                     cls: 'olEditorControlEditorPanel olControl',
423                                     layout: 'fit',
424                                     height: 50
425                                 }
426                             ]
427 
428                            },
429                            {
430                             xtype: "framework_topdizionimanagement",
431                             id: "topDizioniManagement",
432                             topdatapanel: this,
433                             collapsed: false,
434                             title: 'Gestione dizioni',
435                             layout: 'fit',
436                             width: 460,
437                             height: 160,
438                             autoScroll:true,
439                             listeners: {
440                                 loadGeometryDiz: function(geom) {
441                                     this.fireEvent('loadGeometryDiz', geom);
442                                 },
443                                 openWinEditDizTOP: function(flag) {
444                                     this.fireEvent('openWinEditDizTOP', flag);
445                                 },
446                                 loadGeometryAttDiz: function(geom) {
447                                     this.fireEvent('loadGeometryAttDiz', geom);
448                                 },
449                                 openWinEditAttDizTOP: function(flag) {
450                                     this.fireEvent('openWinEditAttDizTOP', flag);                                       
451                                 },
452                                 getGeometryAttrDiz: function() {
453                                     this.fireEvent('getGeometryAttrDiz');
454                                  },
455                                 saveDiz: function(diz) {                                  
456                                 //    console.log(diz);
457                                 },
458                                 scope:this
459                             }
460                            }
461                         ],
462                     buttons: [{
463                             text: 'Annulla',
464                             handler: function() {
465                                 
466                                 _self.hide();
467                               //  _self.click.deactivate();
468                                 //  _self.destroy();
469                             }
470                         }, {
471                             text: 'Salva',
472                             id: 'btnSaveTOP',
473                             disabled: true,
474                             handler: function() {
475                                 
476                                 
477                                 _self.updateISTAT(true);
478                               
479                             }
480                         }, {
481                             text: 'Elimina',
482                             id: 'btnDeleteTOP',
483                             cls: 'btnDeleteTOP',
484                             disabled: true,
485                             handler: function() {
486                                  Ext.MessageBox.show({
487                                     title : 'Attenzione!',
488                                     msg : 'Sei sicuro di voler eliminare questo toponimo? Questa operazione è irreversibile.',
489                                     width : 300,
490                                     buttons: Ext.MessageBox.YESNO,
491                                     buttonText:{ 
492                                         yes: "Si", 
493                                         no: "No" 
494                                     },
495                                     fn : myCallback
496                                    // icon : Ext.MessageBox.QUESTION
497                                 });
498                                 
499                                 function myCallback(btn) {
500                                     if (btn == "yes") {
501                                         _self.delTop();
502                                         _self.hide();
503                                     }
504                                 }
505                                 
506                             }
507                         }]
508                 });
509 
510                 this.items = [this._toponimoform];
511 
512                 this.openEditTopForm = function(topID) {
513                     
514                     this.title = 'Modifica toponimo';
515                     
516                     var _self = this;
517                     
518                     if (!_self.busyMask) {
519                         try{
520                             _self.busyMask = new Ext.LoadMask(
521                                     Ext.getBody(), {
522                                         msg: 'Operazione in corso ...'
523                                     }
524                             );
525                          }catch(error){}
526                     };
527 
528                     if(_self.busyMask) {
529                         _self.busyMask.show();
530                         _self.disable();
531                     }
532                     
533                     _self.topID = topID;
534                     this.catFaccDS.load({params: {method: 'getAllCategoriesFacc',start:0,limit:100}});
535                     this.tipilocalitaDS.load({params: {method: 'getAllTipiLocalita',start:0,limit:100}});
536                     this.categoriesDS.load({params: {method: 'getAllCategories',start:0,limit:100}});
537                     
538                     
539                     _self.topID = (topID) ? topID : null;
540 
541                     Ext.Ajax.request({
542                         url: this.topCatTipServeltName,
543                         method: 'POST',
544                         params: {
545                             method: 'getToponimoById',
546                             id: _self.topID
547                         },
548                         success: function(data) {
549                             
550                             _self.enable();
551                             if(_self.busyMask)
552                                 _self.busyMask.hide();
553 
554                             var resp = Ext.util.JSON.decode(data.responseText);
555                             
556                             if (resp.status == -1) {
557                                 Ext.MessageBox.alert('Attenzione', 'Il toponimo non esiste o è stato eliminato');
558                                 this.hide();
559                             }
560                             else {
561                                 
562                                 // AREA SEMANTICA
563                                 var geojsonData = 
564                                 {
565                                         "type":"Feature",
566                                         "geometry": resp.geometria
567                                 };
568                                 var geojson_format = new OpenLayers.Format.GeoJSON({
569                                     'internalProjection': new OpenLayers.Projection("EPSG:3003"),
570                                     'externalProjection': new OpenLayers.Projection("EPSG:3003")
571                                 });
572                                 var geom = geojson_format.read(geojsonData);
573                                 var features = [];
574                                 geom[0].geometry.components.forEach(function(point) {
575                                     features.push(new OpenLayers.Feature.Vector(point));
576                                 }); 
577                                 
578                                 this.fireEvent('loadGeometry', features);
579                                 
580                                 var features_diz = [];
581                                 //DIZIONI
582                                 resp.dizioni.forEach(function(diz) {
583                                     
584                                     var geojsonDataDiz = 
585                                     {
586                                             "type":"Feature",
587                                             "geometry": diz.geometria
588                                     };
589                                     var geojson_format_diz = new OpenLayers.Format.GeoJSON({
590                                         'internalProjection': new OpenLayers.Projection("EPSG:3003"),
591                                         'externalProjection': new OpenLayers.Projection("EPSG:3003")
592                                      });
593                                     var geom_diz = geojson_format_diz.read(geojsonDataDiz);
594                                     features_diz.push(geom_diz[0]);
595                                 
596                                 });
597                                 
598                                 this.fireEvent('loadGeometryDiz', features_diz);
599                             
600                                 if (resp.status)
601                                     _self._toponimoform.getForm().findField('publicTop').items.items[0].setValue(true);
602                                 else
603                                     _self._toponimoform.getForm().findField('publicTop').items.items[1].setValue(true);
604 
605 
606                                 this._toponimoform.getForm().findField('tipo_loc').setValue(resp.tipoLocalita.codice);
607                                 this._toponimoform.getForm().findField('categories').setValue(resp.gruppoToponimi.codice);
608 
609                                 //in alcuni casi lo store non è valorizzato e il setting avviene in modo sbagliato
610                                 if(Ext.getCmp('topTipiLocalita').lastSelectionText == resp.tipoLocalita.codice){
611                                     window.setTimeout(function (obj) {
612                                         obj._toponimoform.getForm().findField('tipo_loc').setValue(resp.tipoLocalita.codice);
613                                         obj._toponimoform.getForm().findField('categories').setValue(resp.gruppoToponimi.codice);
614                                     },100,this);
615                                 }
616 
617 
618                                 this._toponimoform.getForm().findField('categoria').setValue(resp.tipo.categoriaFaccObject.categoria);
619                                 this.tipiByCategoriaFacc.baseParams['categoriaFacc'] = resp.tipo.categoriaFaccObject.categoria;
620                                 this.tipiByCategoriaFacc.reload();
621 
622                                 this.initTipo = resp.tipo.codTipo;
623                                 
624                                 var nome_comune = "MARE";
625                                 var istat_comune = "20";
626                                 if (resp.comune)  {
627                                     nome_comune = resp.comune.nome;
628                                     istat_comune = resp.comune.istat;
629                                 }
630                                         
631                                 this._toponimoform.getForm().findField('comune').setValue(nome_comune);
632                                 this._toponimoform.getForm().findField('istat').setValue(istat_comune);
633                                 this.istat = istat_comune;
634 
635                                 Ext.getCmp('topDizioniManagement').upDateDizTop(resp.dizioni);
636 
637                                 this.dizioni = resp.dizioni;
638 
639                                 this.updateISTAT();
640 
641                                 if (this.userAuthDS.usertype.description == "Amministratore"
642                                         || this.userAuthDS.usertype.description == "Gestore")
643                                     Ext.getCmp('btnDeleteTOP').enable();
644                             
645                             }
646                             
647                         },
648                         failure: function(form, action) {
649                             Ext.Msg.alert("Load failed", action.result.errorMessage);
650                         },
651                         scope: this
652                     });
653 
654 
655                 };
656 
657 
658                 this.openEditNewTopForm = function(position) {
659                     
660                     this.title = 'Nuovo toponimo';
661                     var _self = this;
662               
663                     this.catFaccDS.load({params: {method: 'getAllCategoriesFacc',start:0,limit:100}});
664                     this.tipilocalitaDS.load({params: {method: 'getAllTipiLocalita',start:0,limit:100}});
665                     this.categoriesDS.load({params: {method: 'getAllCategories',start:0,limit:100}});
666                    
667                     this._toponimoform.getForm().reset();
668                     Ext.getCmp('topDizioniManagement').clearDataDizTop();
669 
670            //         this.updateCoord(position);
671                     this.updateISTAT();
672                     
673                     Ext.getCmp('btnDeleteTOP').disable();
674 
675                 };
676 
677                 framework.widgets.TopDataPanel.superclass.initComponent.call(this);
678                 
679                 this.on("show", function() {
680                      var tabPanel = Ext.getCmp('tabPanelID');
681                      if(tabPanel){
682                          tabPanel.disable();
683                      }
684                 });
685                 this.on("hide", function() {
686                     var tabPanel = Ext.getCmp('tabPanelID');
687                      if(tabPanel){
688                          tabPanel.enable();
689                      }
690                 });
691             },
692             /** 
693              * Create query string for wfs catasto service
694              * @private
695              */
696             getParameters: function(coord) {
697                 var parameters = {service: this.serviceType, version: this.version, request: this.requestType,
698                     typeName: this.typeName, maxFeatures: this.maxFeatures, outputFormat: 'application/json',
699                     FILTER: '<Filter xmlns="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml">' +
700                             '<Intersects><PropertyName>'+this.nameGeometry+'</PropertyName>' +
701                             '<gml:Point srsName="' + this.srs + '">' +
702                             '<gml:coordinates>' + coord.lon + ',' + coord.lat + '</gml:coordinates>' +
703                             '</gml:Point></Intersects></Filter>'};
704                     /*FILTER: '<Filter xmlns="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml">' +
705                             '<BBOX><PropertyName>'+this.nameGeometry+'</PropertyName>' +
706                             '<gml:Box srsName="urn:x-ogc:def:crs:' + this.srs + '">' +
707                             '<gml:coord><gml:X>'+coord.left+'</gml:X><gml:Y>'+coord.bottom+'</gml:Y></gml:coord>'+
708                             '<gml:coord><gml:X>'+coord.right+'</gml:X><gml:Y>'+coord.top+'</gml:Y></gml:coord>'+
709                             '</gml:Box>'+
710                             '</BBOX></Filter>'};*/
711                 
712                 return parameters;
713             },
714             /** 
715              * Create query string for wfs catasto service
716              * @private
717              */
718             updateCoord: function(coord) {
719               //  this._toponimoform.getForm().findField('longitude').setValue(coord.lon);
720               //  this._toponimoform.getForm().findField('latitude').setValue(coord.lat);
721               //  this._toponimoform.getForm().findField('coordinates').setValue(coord.lon + ',' + coord.lat);
722 
723             },
724             updateISTAT: function(save) {
725                 
726                 var _self = this;
727                 
728                 this.fireEvent('getExtent');
729                 
730                 if (this.extentAreaSemantica) {
731                     var coord = this.extentAreaSemantica.getCenterLonLat();
732                    
733                 
734                     Ext.Ajax.request({
735                         method: 'POST',
736                         url: this.urlProxy + this.urlWFS,
737                         params: this.getParameters(coord),
738                         success: function(result, request) {
739                             try {
740                                 var obj = Ext.decode(result.responseText);
741                                 if (obj && obj.features) {
742                                     if (obj.features.length == 0) {
743                                         if (save) {
744                                             Ext.MessageBox.show({
745                                                 title : 'Attenzione!',
746                                                 msg : 'Stai salvando un toponimo su territorio non comunale (probabilmente sei sul mare), vuoi proseguire?',
747                                                 width : 300,
748                                                 buttons: Ext.MessageBox.YESNO,
749                                                 buttonText:{ 
750                                                     yes: "Si", 
751                                                     no: "No" 
752                                                 },
753                                                 fn : function(btn){                    
754                                                    if (btn == "no"){
755                                                        // NO              
756                                                    }
757                                                    if (btn == "yes"){
758                                                         _self.istat = '20';
759                                                         _self._toponimoform.getForm().findField('comune').setValue("MARE");
760                                                         _self._toponimoform.getForm().findField('istat').setValue(_self.istat);
761                                                         _self.checkPermission(save);
762                                                    }
763                                                }
764 
765                                                // icon : Ext.MessageBox.QUESTION
766                                             });
767                                         }
768                                       //  else 
769                                       //      Ext.MessageBox.alert('Attenzione', 'Non sei su territorio comunale (probabilmente sei sul mare)');
770 
771                                         
772                                     }
773                                     else if (obj.features.length >= 1) {
774 
775                                         var nome_comune = obj.features[0].properties[this.properties_nome];
776                                         this.istat = obj.features[0].properties[this.properties_istat];
777 
778                                         this._toponimoform.getForm().findField('comune').setValue(nome_comune);
779                                         this._toponimoform.getForm().findField('istat').setValue(this.istat);
780                                         this.checkPermission(save);
781                                     }
782                                     else if (obj.features.length > 1) {
783                                         alert('Trovati più risultati!\n Affinare la ricerca per stabilire un extent.');
784                                         obj.features.forEach(function(feature) {
785                                              console.log(feature.properties[this.properties_nome]);
786                                              console.log(feature.properties[this.properties_istat]);
787                                         }); 
788                                     }
789 
790                                 } else
791                                     alert('Il servizio non risponde');
792                             } catch (ex) {
793                                 Ext.MessageBox.alert('Error', 'Il servizio è andato in errore!');
794                             }
795 
796                         },
797                         failure: function(result, request) {
798                             if (self.busyMask)
799                                 self.busyMask.hide();
800                             //Ext.MessageBox.alert('Error', result.responseText);
801                         },
802                         scope: this
803                     });
804                 }
805             },
806             updateUserAuth: function(userAuthDS) {
807                 this.userAuthDS = userAuthDS;
808                 if (this.userAuthDS.usertype.description === "Amministratore" || this.userAuthDS.usertype.description === "Gestore")
809                     this._toponimoform.getForm().findField('publicTop').enable();
810                 else
811                     this._toponimoform.getForm().findField('publicTop').disable();
812 
813                 this.typesByUserDs.load({
814                     params: {
815                         method: 'getTypes4User',
816                         userId: this.userAuthDS.myid
817                     }});
818             },
819             checkPermission: function(save) {
820 
821                 var enableISTAT = false;
822                 var enableType = false;
823                 
824                 var provinciaInteresse = this.userAuthDS.provinciaInteresse;
825                 var comuneInteresse = this.userAuthDS.comuneInteresse;
826 
827                 if (provinciaInteresse === "Tutte" || provinciaInteresse === "") {
828                     enableISTAT = true;
829                 }
830                 else if (this.istat.search(provinciaInteresse) === 0) {
831                     if (comuneInteresse === "Tutti" || comuneInteresse === "")
832                         enableISTAT = true;
833                     else if (comuneInteresse === this.istat)
834                         enableISTAT = true;
835                 }
836 
837                 var tip = this._toponimoform.getForm().findField('tipo').getValue();
838 
839                 if (this.typesByUserDs.find('codTipo', tip) !== -1)
840                     enableType = true;
841               //  else
842               //      alert('Utente non abilitato alla categoria selezionata');
843 
844                 if (enableType) 
845                 //if (enableISTAT && enableType) 
846                     Ext.getCmp('btnSaveTOP').enable();
847                 else
848                     Ext.getCmp('btnSaveTOP').disable();
849                 
850                 if (save) {
851                   if (enableISTAT)
852                         this.saveTop();
853                   else
854                         Ext.MessageBox.alert('Attenzione', 'Non hai i permessi per questo comune');
855                 }
856                 
857            //     Ext.getCmp('btnSaveTOP').enable();
858             },
859             saveTop: function() {
860                 
861                 var _self = this;
862                 
863                 var tipo_loc = _self._toponimoform.getForm().findField('tipo_loc').getValue();
864                                 
865                 var categories = _self._toponimoform.getForm().findField('categories').getValue();
866 
867                 var categoria = _self._toponimoform.getForm().findField('categoria').getValue();
868 
869                 var codTipo = _self._toponimoform.getForm().findField('tipo').getValue();
870                 var tipo_Idx = _self.tipiByCategoriaFacc.find('codTipo', codTipo);
871                 var codFacc = _self.tipiByCategoriaFacc.getAt(tipo_Idx).data.codFacc;
872 
873 
874                 var comune = _self._toponimoform.getForm().findField('comune').getValue();
875                 var istat = _self._toponimoform.getForm().findField('istat').getValue();
876 
877                 var publicTopObj = _self._toponimoform.getForm().findField('publicTop').getValue();
878                 var publicTop = this.publicTop = (publicTopObj.inputValue === 1) ? 1 : 0;
879                 var author = _self.userAuthDS.myid;
880                 
881                 var dizioni = Ext.getCmp('topDizioniManagement').getDizTop();
882                 
883                 _self.fireEvent('getGeometry');
884 
885                 if (_self.topID)
886                     var myid = _self.topID;
887                 else
888                     var myid = null;
889                 
890                 var areasemantica = Ext.util.JSON.decode(_self.geometryTop);
891               
892                 if (tipo_loc && categories && categoria && codTipo && areasemantica.features.length > 0) {
893 
894                     if (!_self.busyMask) {
895                         try{
896                             _self.busyMask = new Ext.LoadMask(
897                                     Ext.getBody(), {
898                                         msg: 'Operazione in corso ...'
899                                     }
900                             );
901                          }catch(error){}
902                     };
903 
904                     if(_self.busyMask) {
905                         _self.busyMask.show();
906                         _self.disable();
907                     }
908                    
909                     if (istat == '20')
910                         istat = '';
911                     
912                     Ext.Ajax.request({
913                         url: _self.topCatTipServeltName,
914                         headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' },
915                         method: 'POST',
916                         params: {
917                             method: 'saveToponimo',
918                             id: myid,
919                             tipo_loc: tipo_loc,
920                             categories: categories,
921                             categoria: categoria,
922                             codTipo: codTipo,
923                             codFacc: codFacc,
924                             comune: comune,
925                             istat: istat,
926                             author: author,
927                             publicTop: publicTop,
928                             areasemantica: _self.geometryTop,
929                            // dizioni: Ext.util.JSON.encode(_self.dizioni)
930                             dizioni: Ext.util.JSON.encode(dizioni)
931                         },
932                         success: function(data) {
933                             _self.enable();
934                             if(_self.busyMask)
935                                 _self.busyMask.hide();
936                             var resp = Ext.util.JSON.decode(data.responseText);
937                             if (resp.success) {
938                                 Ext.Msg.alert('Info', resp.msg);
939                                 
940                                 //SVUOTARE TUTTO
941                                 Ext.getCmp('topDizioniManagement').clearDataDizTop();
942                                 _self.topID = null;
943                                 
944                                 _self.hide();
945 
946                                 //Aggiorna lista toponimi offLine
947                                 if(!_self.topVerifyBox){
948                                     _self.topVerifyBox = Ext.getCmp('idTopVerifyManagement');
949                                 }   
950                                 _self.topVerifyBox.pagingBar.doRefresh();
951                                 
952                                 //   _self.destroy();
953                             } else {
954                                 Ext.Msg.alert('Attenzione', resp.msg);
955                             }
956 
957                         },
958                         failure: function(form, action) {
959                             if(_self.busyMask)
960                                 _self.busyMask.hide();
961                             Ext.Msg.alert("Load failed", action.result.errorMessage);
962                         },
963                         scope: this
964                     });
965 
966                 }
967                 else
968                     Ext.Msg.alert('Attenzione', "Compilare tutti i campi obbligatori");
969 
970             },
971             delTop: function() {
972                 
973                 var _self = this;
974                 
975                 if (_self.topID) {
976                     var myid = _self.topID;
977                 
978                     Ext.Ajax.request({
979                            url: _self.topCatTipServeltName,
980                            headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' },
981                            method: 'POST',
982                            params: {
983                                method: 'deleteToponimo',
984                                id: myid,
985                                publicTop: -1
986                            },
987                            success: function(data) {
988                                if(_self.busyMask)
989                                    _self.busyMask.hide();
990                                var resp = Ext.util.JSON.decode(data.responseText);
991                                if (resp.success) {
992                                    Ext.Msg.alert('Info', resp.msg);
993 
994                                    _self.hide();
995                                    
996                                     //Aggiorna lista toponimi offLine
997                                     if(!_self.topVerifyBox){
998                                         _self.topVerifyBox = Ext.getCmp('idTopVerifyManagement');
999                                     }   
1000                                 _self.topVerifyBox.pagingBar.doRefresh();
1001                                    //   _self.destroy();
1002                                } else {
1003                                    Ext.Msg.alert('Attenzione', resp.msg);
1004                                }
1005 
1006                            },
1007                            failure: function(form, action) {
1008                                if(_self.busyMask)
1009                                    _self.busyMask.hide();
1010                                Ext.Msg.alert("Load failed", action.result.errorMessage);
1011                            },
1012                            scope: this
1013                        });
1014                    }
1015                    else {
1016                        Ext.Msg.alert('Attenzione', "Toponimo non inserito in banca dati");
1017                    }
1018                 
1019             }
1020 
1021 
1022         });
1023 
1024 /** api: xtype = framework_panelpoidata */
1025 Ext.reg("framework_topdatapanel", framework.widgets.TopDataPanel);