1 /**
  2  * @fileOverview  
  3  * Copyright (c) 2013 Regione Autonoma della Sardegna
  4  * Published under the GPL license.<br>
  5  * See <a href="https://sardegnageoportale.it/webgis/license.txt">https://sardegnageoportale.it/webgis/license.txt</a>
  6  * for the full text of the license.
  7  * @version 0.1
  8  */
  9  
 10  /**
 11  * @require OpenLayers/Control/SelectFeature.js
 12  */
 13 
 14 /**
 15  * @namespace framework.plugins
 16  */
 17 Ext.namespace("framework.form");
 18 
 19 /**
 20 * Creates a combo box that handles results from a directory service OpenLS. By
 21  *  default it uses Directory OpenLS service by Regione Autonoma della Sardegna (http://www.sardegnageoportale.it/index.php?xsl=1598&s=203310&v=2&c=9869&t=1), but it can be configured with a custom store
 22  *  to use other services standard OpenLS. If the user enters a valid address in the search
 23  *  box, the combo's store will be populated with records that match the
 24  *  address.
 25  *  @name_ DirectoryOpenLSComboBox
 26  * @class Creates a combo box that handles results from a directory service OpenLS.
 27  * @constructor
 28  @extends <a target="_blank" href="http://docs.sencha.com/extjs/3.4.0/#!/api/Ext.form.ComboBox">Ext.form.ComboBox</a>
 29  */
 30 
 31 framework.form.DirectoryOpenLSComboBox = Ext.extend(Ext.form.ComboBox,
 32 /** 
 33  * @lends framework.form.DirectoryOpenLSComboBox.prototype 
 34  */
 35 {
 36     /**
 37     * Text to display for an empty field
 38     * @public
 39     * @type String
 40     */
 41     emptyText: "Search with OpenLS",
 42  
 43     /**
 44     * The srs used by the geocoder service.
 45     * Default is "EPSG:3003".
 46     * @public
 47     * @type String
 48     */
 49     srs: "EPSG:3003",
 50    
 51      /** 
 52      * The minimum zoom level to use when zooming to a location.
 53      * Not used when zooming to a bounding box. Default is 12.
 54      * @public
 55      * @type number
 56      */
 57     zoom: 12,  
 58    
 59     /** 
 60     * If provided, a marker will be drawn on this
 61     * layer with the location returned by the geocoder. The location will be
 62     * cleared when the map panned. 
 63     * @public
 64     * @type OpenLayers.Layer.Vector
 65     */
 66     layer: null,
 67     
 68     /** 
 69     * define the mapping from xml to the store
 70     * @public
 71     * @type Ext.data.XmlReader
 72     */
 73     reader: new framework.data.DirectoryOpenLS_XLSReader(),
 74   
 75     /** 
 76     * Delay before the search occurs.
 77     * Default is 200ms.
 78     * @public
 79     * @type number
 80     */
 81     queryDelay: 200,
 82     
 83     /**
 84      * Field from selected record to use when the combo's
 85      * :meth:`getValue` method is called.  Default is "bounds". This field is
 86      * supposed to contain an array of [left, bottom, right, top] coordinates
 87      * for a bounding box or [x, y] for a location. 
 88      * @public
 89      * @type String
 90      */
 91     valueField: "bounds",
 92     
 93     /** 
 94      * The field to display in the combo box. Default is
 95      *  "name" for instant use with the default store for this component.
 96      * @public
 97      * @type String
 98      */
 99     displayField: "text",
100     
101     /**
102      * The field to get the location from. This field is supposed
103      * to contain an array of [x, y] for a location. Default is "lonlat" for
104      * instant use with the default store for this component.
105      * @public
106      * @type String
107      */
108     locationField: "lonlat",
109     
110     /**
111      * URL template for querying the geocoding service. If a
112      * :obj:`store` is configured, this will be ignored. Note that the
113      * :obj:`queryParam` will be used to append the user's combo box
114      * input to the url. Default is
115      * "http://nominatim.openstreetmap.org/search?format=json", for instant
116      * use with the OSM Nominatim geolocator. However, if you intend to use
117      * that, note the
118      * `Nominatim Usage Policy <http://wiki.openstreetmap.org/wiki/Nominatim_usage_policy>`_.
119      * @public
120      * @type String
121      */
122     url: 'http://webgis.regione.sardegna.it/ricercatoponimi/RicercaToponimiService.ejb?serviceName=RTOpenGISResp',
123     
124     /** api: config[queryParam]
125      *  ``String`` The query parameter for the user entered search text.
126      *  Default is "q" for instant use with OSM Nominatim.
127      */
128     //  queryParam: "xmlRequest",
129     
130     /** 
131      * Minimum number of entered characters to trigger a search.
132      * Default is 4.
133      * @public
134      * @type Number
135      */
136     minChars: 4,
137 
138     /**
139      * See http://www.dev.sencha.com/deploy/dev/docs/source/BoxComponent.html#cfg-Ext.BoxComponent-width,
140      * default value is 240.
141      * @public
142      * @type Number
143      */
144     width: 240,
145     
146     /**
147      * See http://www.dev.sencha.com/deploy/dev/docs/source/Combo.html#cfg-Ext.form.ComboBox-listWidth,
148      * default value is 350.
149      * @public
150      * @type Number
151      */
152     listWidth: 400,
153     
154     /**
155      * See http://www.dev.sencha.com/deploy/dev/docs/source/Combo.html#cfg-Ext.form.ComboBox-loadingText,
156      * default value is "Search in Geozet...".
157      * @public
158      * @type String
159      */
160     loadingText: 'Searching...',
161     
162     /**
163      * paht for images marker,
164      * default value is "theme/app/img/".
165      * @public
166      * @type String
167      */
168     markersImgPath: 'theme/app/img/',
169     
170     /**
171      * Hide trigger of the combo.
172      * @private
173      * @type boolean
174      */
175     hideTrigger: true,
176     
177     /**
178      * Force selection.
179      * @private
180      * @type boolean
181      */
182     forceSelection: false,
183     
184     /** private: property[countryCode]
185      * countryCode, default is IT.
186      * @private
187      * @type String
188      */
189     countryCode: 'IT',
190     
191     /**
192      * geometry, default is true.
193      * @private
194      * @type boolean
195      */
196     geometry: true,
197     
198     /**
199      * number current page
200      * default is 1.
201      * @private
202      * @type boolean
203      */
204     numpage: 1,
205     
206     /**
207      * number page size
208      * default is 10.
209      * @private
210      * @type boolean
211      */
212     pageSize: 10,
213     
214     /** private: property[typerequest]
215      *  number page of results, default is freeFormDescription.
216      *  type request:
217      *  - testo (si basa su una richiesta in un formato strutturato in cui viene specificato il toponimo (o 
218      una sua parte) e opzionalmente il Comune e/o il tipo del toponimo)
219      *  - freeFormDescription (prevede la possibilità di ricercare un toponimo specificando una stringa di ricerca 
220      non strutturata, composta da un insieme di parole.)
221      *  - testoEuristico (ricerca euristica che si basa su una richiesta in un formato strutturato in cui viene specificato il toponimo (o 
222      una sua parte) e opzionalmente il Comune e/o il tipo del toponimo)
223      *  - testoFullLike (ricerca il testo all'interno delle parole)
224      * @private
225      * @type String
226      */
227     typerequest: 'testoFullLike',
228     
229     /** private: property[tpl]
230      * template result search.
231      * @private
232      * @type Ext.XTemplate
233      */
234     tpl: new Ext.XTemplate('<tpl for="."><div class="search-item-directory">' +
235             
236            '<table border="0">' +
237                '<tr>' +
238                     '<td><img src="{img}"></td>' +
239                         '<td>' +
240                             '<p class="title">{text}</p>' +
241                             '<p class="type">{type}</p>' +
242                         '</td>' +
243                 '</tr>' +
244           '</table>' +
245            
246             '</div></div></tpl>'),
247     
248     /** private: property[itemSelector]
249      * @private
250      * @type String
251      */
252     itemSelector: 'div.search-item-directory',
253    
254     /**
255      * proxy, default is null.
256      * @private
257      * @type String
258      */
259     proxy: null,
260     
261     textSearch: '',
262     
263      /** api: config[urlCatasto]
264     *  
265     *  url for wfs catasto service
266     *  @public
267     *  @type String
268     */
269    urlWFS: '/geoserver/ows?',
270    /** api: config[serviceType]
271     *  
272     *  Service type for catasto service (query string parameter)
273     *  Default WFS
274     *  @public
275     *  @type String
276     */
277    serviceType: 'WFS',
278    /** api: config[version]
279     *  
280     *  Version for WFS service (query string parameter)
281     *  Default 1.0.0
282     *  @public
283     *  @type String
284     */
285    version: '1.0.0',
286    /** api: config[GetFeature]
287     *  
288     *  Request type for WFS service (query string parameter)
289     *  Default GetFeature
290     *  @public
291     *  @type String
292     */
293    requestType: 'GetFeature',
294    /** api: config[typeName]
295     * 
296     *  typeName for WFS service (query string parameter)
297     *  @public
298     *  @type String
299     */
300     typeName: 'dbu:limitiamministrcomunali', // dbu:LIMITIAMMINISTRCOMUNALI
301     /** 
302      * ricerca comune WFS: nome del campo geometrico del layer
303      * @private
304      * @type String
305      */
306     nameGeometry: 'geom', // POLIGONO
307     /** 
308      * ricerca comune WFS: nome del campo con il nome del comune
309      * @private
310      * @type String
311      */
312     properties_nome: 'nome', // NOME
313     /** 
314      * ricerca comune WFS: nome del campo con l'ISTAT del comune
315      * @private
316      * @type String
317      */
318     properties_istat: 'codiceist1', //CODICEISTATCOMUNALE
319    /** api: config[infoFormat]
320     *  
321     *  maxFeatures for WFS service (query string parameter)
322     *  Default 50
323     *  @public
324     *  @type Number
325     */
326    maxFeatures: 5,
327     
328     /** 
329      * the authenticate user
330      * @public
331      * @type Ext.data.Store
332      */
333     userAuthDS: null,
334     
335     /** 
336      * Editor geometry
337      * @public
338      * @type OpenLayers.Editor
339      */
340     editor: null, 
341     
342     /** Init the component creating a store and object'events.
343     * @public
344     */  
345     initComponent: function() {
346 
347         //var epsgOutput = this.srs.replace("EPSG:","");
348         
349         if(!this.map){
350             var mapPanel = this.findParentBy(function(cmp) {
351                 return cmp instanceof GeoExt.MapPanel;
352                 });
353             this.map = mapPanel.map;
354         }
355 
356         if (Ext.isString(this.srs)) {
357             this.srs = new OpenLayers.Projection(this.srs);
358         }
359         if (this.proxy)
360          	var sUrl = this.proxy + escape(this.url);
361         else
362             var sUrl = this.url;
363 
364         if (!this.store) {
365             this.store = new Ext.data.Store({
366                 proxy: new Ext.data.HttpProxy({
367                     url: sUrl,
368                     method: 'POST'
369                 }),
370                 fields: [
371                     "topID",
372                     {name: "lon", type: "number"},
373                     {name: "lat", type: "number"},
374                     {name: "numresult", type: "number"},
375                     "text",
376                     "type",
377                     "link",
378                     "istat",
379                     "enabled",
380                     "img"
381                             //Alias, NomeComune, NomeTipo, Punteggio, POINumPage, POINumResults
382                 ],
383                 reader: this.reader,
384                 
385                 listeners: {
386                     exception : function(proxy, response, operation) {
387 /*                        
388                         console.log(q);
389         console.log(q.length);
390         console.log(checkAdvSearch);
391         
392         if (!checkAdvSearch && (Ext.isEmpty(q) || q.length < 3)) {
393             Ext.Msg.alert('Attenzione', 'E\' necessario inserire una parola di almeno 3 lettere o un filtro di ricerca');
394             return false;
395         }
396         
397   */      
398                         if (this.combo.layer)
399                             this.combo.layer.destroyFeatures();
400                         this.combo.store.removeAll();
401                         if (operation) {
402                             Ext.Msg.alert('Avviso', 'La ricerca non ha prodotto risultati');
403                            // alert(operation.error);
404                         } else {
405                             Ext.Msg.alert('Errore', 'La ricerca è andata in errore, ritenta, sarai più fortunato :)');
406                             // May be a proxy error...
407                         }
408                     },
409                     load: function (){
410                         if (this.data.items.length === 0) {                                    
411                           Ext.Msg.alert('Avviso', 'La ricerca non ha prodotto risultati. Controllare i filtri di ricerca e riprovare.');
412                         }
413                         this.combo.fireEvent('viewReady');
414                     },
415                     datachanged: function(store){
416                         
417                         //alert(store);
418                        
419                         if (this.combo.map.getLayersByName(this.combo.layer.name).length == 0) {
420                             this.combo.map.addLayer(this.combo.layer);
421                         }
422                         
423                         //this.combo.map.zoom = 12;
424                         
425                         //remove marker and popup
426                         this.combo.layer.destroyFeatures();
427                         removePopup();
428                         
429                          function removePopup() {
430                                  if (this.popupAddr) {
431                                          this.popupAddr.close();
432                                          this.popupAddr.destroy();	
433                                  }
434 
435                              };
436 
437                         function createPopup(combo, feature) {
438 
439                                 removePopup();
440 
441                                 this.popupAddr = new framework.plugins.PopUp({
442                                     //title: 'Ricerca indirizzo',
443                                     //map: this.map,
444                                     location: feature,
445                                     obj: feature,
446                                     width:200,
447                                     border: false,
448                                     userAuth: combo.userAuthDS,
449                                     html: '<div class="popupAddr">'+feature.text+'</div>',
450                                     maximizable: false,
451                                     collapsible: false,
452                                     listeners: {
453                                         modTOP: function(e) {
454                                             this.modFeatureTOP(e);
455                                         },
456                                         insTOP: function(e) {
457                                             this.insFeatureTOP(e);
458                                         },
459                                         scope: combo
460                                     }
461                                 });
462                                 this.popupAddr.show();	
463                         };
464                         
465                         var bounds = new OpenLayers.Bounds();
466                      
467                         //insert marker	
468                         for(i=0;i<store.data.items.length;i++){
469                             var position = new OpenLayers.LonLat(store.data.items[i].data.lon, store.data.items[i].data.lat);
470 
471                             // Reproject (if required)
472                             position.transform(
473                                 new OpenLayers.Projection("EPSG:3003"),
474                                 this.combo.map.getProjectionObject()
475                             );
476                     
477                             if (store.data.items[i].data.enabled == "1") {
478                                 var externalGraphic = this.combo.markersImgPath + "carattere_red_shadow_" + i + ".png";
479                                 var imgCombo = this.combo.markersImgPath + "carattere_red_" + i + ".gif";
480                             }
481                             else {
482                                 var externalGraphic = this.combo.markersImgPath + "disable/carattere_red_shadow_" + i + ".png";
483                                 var imgCombo = this.combo.markersImgPath + "disable/carattere_red_" + i + ".gif";
484                             }
485                             
486                             var feature = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(position.lon, position.lat)
487                                 ,null, {externalGraphic: externalGraphic,
488                                     graphicWidth: 68,
489                                     graphicHeight: 48,
490                                     graphicYOffset: -48,
491                                     fillOpacity: 1
492                                 });
493                             feature.topID = store.data.items[i].data.topID;
494                                     
495                             feature.text = this.combo.msgPopup(store.data.items[i].data);  
496                             this.combo.layer.addFeatures(feature);
497                             
498                             this.combo.selectCtrl = new OpenLayers.Control.SelectFeature([this.combo.layer],{
499 								toggle: true,
500 								clickout: true
501 							});
502 
503                             this.combo.map.addControl(this.combo.selectCtrl);
504                             this.combo.selectCtrl.activate();
505                             
506                             bounds.extend(new OpenLayers.LonLat(position.lon, position.lat));
507                             store.data.items[i].data.img = imgCombo;
508                             
509                         }
510                         
511                         this.combo.map.searchName = this.combo.id;
512                                              
513                          //set map extent
514                          this.combo.map.zoomToExtent(bounds);
515                          
516                           // create popup on "featureselected"
517                           if (!this.combo.isActiveFeatureselected) {
518                                 this.combo.layer.events.on({
519                                         featureselected: function(e) {
520                                                 createPopup(this.combo, e.feature);
521                                         },
522                                        scope: this
523                                 });
524                                 this.combo.isActiveFeatureselected = true;
525                           }
526   
527                     },
528                     
529                     beforeload: function(store, operation) {
530                         /**
531                          * Inserimento numero di pagina nell'XML di richiesta del servizio
532                          * <xls:DirectoryRequest xmlns:xls="http://www.opengis.net/xls">
533                          * <xls:POIProperties><xls:POIProperty name="other" value="freeFormDescription|Sedilo"/>
534                          * <xls:POIProperty name="other" value="geometry|true"/>
535                          * <xls:POIProperty name="other" value="numPagina|1"/>
536                          * <xls:POIProperty name="other" value="numRisultatiPerPagina|10"/>
537                          * </xls:POIProperties>
538                          * </xls:DirectoryRequest>
539                          */
540                        
541                        
542                         var queryParam = this.combo.queryParam;
543                        
544                         // calcolo numero di pagina
545                         var numpage = (operation.params.start / operation.params.limit) + 1;
546                         // recupero stringa prima del numero di pagina
547                         var index_01 = store.baseParams[queryParam].indexOf("numPagina");
548                         var str_01 = store.baseParams[queryParam].substr(0, index_01 + 10);
549                         // recupero stringa dopo il numero di pagina
550                         var index_02 = store.baseParams[queryParam].indexOf("numRisultatiPerPagina");
551                         var str_02 = store.baseParams[queryParam].substr(index_02 - 40);
552                         // concatenazione stringa con il nuovo numero di pagina
553                         var xmlRequest = str_01.concat(numpage).concat(str_02);
554 
555                         // aggiornamento XML di richiesta
556                         store.baseParams[queryParam] = xmlRequest;
557 
558                     }
559                 },
560                 baseParams: {
561                     'xmlRequest': ''
562                 }
563             });
564             this.store.combo = this;
565         }
566        
567        this.on({
568             added: this.handleAdded,
569             select: this.handleSelect,
570             focus: function() {
571                 this.clearResult();
572                 if (this.store.data.items.length > 0)
573                     this.expand();
574                 this.setValue(this.textSearch);
575                 //  this.removeLocationFeature();
576             },
577             blur: function(textfield) {
578               //  textfield.setValue("");
579                 textfield.setValue(this.textSearch);
580             },
581             keyup: function(textfield, eventObject) {
582                 //  this.textSearch = textfield.getValue();
583                 if(this.el.dom.value.indexOf('<b>') > -1)
584                     this.el.dom.value = this.textSearch;
585                 else
586                     this.textSearch = this.el.dom.value;
587                 if (eventObject.getCharCode() === Ext.EventObject.ENTER) {
588                     this.focus();
589                       this.setValue(this.textSearch);
590                       this.doQuery(this.el.dom.value,true);
591                 } else {
592                     if (this.isExpanded()) {
593                         this.list.hide();
594                     }
595                 }
596             },
597             //Gestione onMouseOver 
598             //TODO  non funzionante
599             viewReady: function() {
600                 this.view.trackOver = true;
601                 this.view.on({
602                     mouseenter: function(obj, index, node, e) {
603                         var x = 1;
604                      //   alert(index);
605                     }
606                 });
607                 var x = 1;
608             },
609             scope: this
610         });
611 
612         return framework.form.DirectoryOpenLSComboBox.superclass.initComponent.apply(this, arguments);
613     },
614     
615     updateuserAuth: function(userAuthDS) {
616 
617         this.userAuthDS = userAuthDS;
618 
619         if (userAuthDS) {
620             this.store.baseParams.codfisc = this.userAuthDS.codfiscale;
621    //         this.authenticatedUser = this.userAuthDS.codfiscale;
622         }
623         else
624             this.store.baseParams.codfisc = '';
625 
626 
627     },
628     modFeatureTOP: function(evt) {
629         
630         var position = evt.location;
631         // Reproject (if required)
632         position.transform(
633                 new OpenLayers.Projection("EPSG:3003"),
634                 this.map.getProjectionObject()
635                 );
636 
637         if (Ext.getCmp('IDTopDataPanel') && !this.winEditTOP)
638             this.winEditTOP = Ext.getCmp('IDTopDataPanel');
639 
640         if (!this.winEditTOP) {
641             this.winEditTOP = new framework.widgets.TopDataPanel({
642                 userAuthDS: this.userAuthDS,
643                 typeName: this.typeName, 
644                 id: 'IDTopDataPanel',
645                 nameGeometry: this.nameGeometry,
646                 properties_nome: this.properties_nome,
647                 properties_istat: this.properties_istat,
648                 listeners: {
649                     loadGeometry: function(geom) {
650                         var _editor = this.editor;
651                         if (Ext.getCmp(this.idnewTopManage)) {
652                                 if (Ext.getCmp(this.idnewTopManage).editor) {
653                                     _editor = Ext.getCmp(this.idnewTopManage).editor;
654                                 }
655                         }
656                         if (Ext.getCmp(this.idPoiVerifyManagement)) {
657                                 if (Ext.getCmp(this.idPoiVerifyManagement).editor) {
658                                     _editor = Ext.getCmp(this.idPoiVerifyManagement).editor;
659                                 }
660                         }
661                         _editor.loadFeatures(geom);
662                     },
663                     loadGeometryDiz: function(geom) {
664                         
665                         if (!this.dizLayer) {
666                             this.dizLayer = new OpenLayers.Layer.Vector('Dizioni', {
667                                 displayInLayerSwitcher: false,
668                                 visibility: true
669                             });
670                             this.dizLayer.styleMap = new OpenLayers.StyleMap({
671                                 'default': new OpenLayers.Style({
672                                     strokeColor: '#f29f1e',
673                                     strokeOpacity: 0.4,
674                                     strokeWidth: 2,
675                                     strokeDashstyle: 'dash',
676                                     graphicZIndex: 1
677                                 })
678                             });
679                             this.map.addLayer(this.dizLayer);
680                         }
681                         
682                         var _dizLayer = this.dizLayer;
683                         if (Ext.getCmp(this.idnewTopManage)) {
684                                 if (Ext.getCmp(this.idnewTopManage).dizLayer) {
685                                     _dizLayer = Ext.getCmp(this.idnewTopManage).dizLayer;
686                                 }
687                         }
688                         if (Ext.getCmp(this.idPoiVerifyManagement)) {
689                                 if (Ext.getCmp(this.idPoiVerifyManagement).dizLayer) {
690                                     _dizLayer = Ext.getCmp(this.idPoiVerifyManagement).dizLayer;
691                                 }
692                         }
693                                         
694                         _dizLayer.destroyFeatures();
695                         if (geom) {
696                             _dizLayer.addFeatures(geom);
697                         }        
698                     
699                     },       
700                     openWinEditDizTOP: function(flag) {
701                         var _editor = this.editor;
702                         if (Ext.getCmp(this.idnewTopManage)) {
703                                 if (Ext.getCmp(this.idnewTopManage).editor) {
704                                     _editor = Ext.getCmp(this.idnewTopManage).editor;
705                                 }
706                         }
707                         if (Ext.getCmp(this.idPoiVerifyManagement)) {
708                                 if (Ext.getCmp(this.idPoiVerifyManagement).editor) {
709                                     _editor = Ext.getCmp(this.idPoiVerifyManagement).editor;
710                                 }
711                         }
712                         if (flag)
713                             _editor.stopEditMode();
714                         else {
715                             _editor.startEditMode();
716                             if (_editor.editLayer.features.length > 0)
717                                 _editor.map.zoomToExtent(_editor.editLayer.getDataExtent());
718                         }
719                     },
720                     loadGeometryAttDiz: function(geom) {
721                         var _editorAttDiz = this.editorAttDiz;
722                         if (Ext.getCmp(this.idnewTopManage)) {
723                                 if (Ext.getCmp(this.idnewTopManage).editorAttDiz) {
724                                     _editorAttDiz = Ext.getCmp(this.idnewTopManage).editorAttDiz;
725                                 }
726                         }
727                         if (Ext.getCmp(this.idPoiVerifyManagement)) {
728                                 if (Ext.getCmp(this.idPoiVerifyManagement).editorAttDiz) {
729                                     _editorAttDiz = Ext.getCmp(this.idPoiVerifyManagement).editorAttDiz;
730                                 }
731                         }
732                         
733                         _editorAttDiz.loadFeatures(geom);
734                     },
735                     openWinEditAttDizTOP: function(flag) {
736                         
737                         if (!this.editorAttDiz) {
738                             /**
739                              * 
740                              * @type OpenLayers.Editor
741                              */
742                             this.editorAttDiz = new OpenLayers.Editor(this.map, {
743                                 div: document.getElementById('editorattdiz_panel'),
744                                 id: "editorAttributoDizione",
745                                 activeControls: ['DeleteAllFeatures','DeleteFeature','DragFeature','SelectFeature','Navigation'],
746                                 featureTypes: ['path'],
747                                 language: 'it'
748                             });
749                         }
750                         
751                         var _editorAttDiz = this.editorAttDiz;
752                         if (Ext.getCmp(this.idnewTopManage)) {
753                                 if (Ext.getCmp(this.idnewTopManage).editorAttDiz) {
754                                     _editorAttDiz = Ext.getCmp(this.idnewTopManage).editorAttDiz;
755                                 }
756                         }
757                         if (Ext.getCmp(this.idPoiVerifyManagement)) {
758                                 if (Ext.getCmp(this.idPoiVerifyManagement).editorAttDiz) {
759                                     _editorAttDiz = Ext.getCmp(this.idPoiVerifyManagement).editorAttDiz;
760                                 }
761                         }
762             
763                         if (flag)
764                             _editorAttDiz.startEditMode();
765                         else {
766                             _editorAttDiz.stopEditMode();
767                             _editorAttDiz.editLayer.removeAllFeatures();
768                            // this.editorAttDiz.controls.DeleteAllFeatures.deleteAllFeatures();
769                         }
770                     },
771                     getGeometry: function() {
772                         var _editor = this.editor;
773                         if (Ext.getCmp(this.idnewTopManage)) {
774                                 if (Ext.getCmp(this.idnewTopManage).editor) {
775                                     _editor = Ext.getCmp(this.idnewTopManage).editor;
776                                 }
777                         }
778                         if (Ext.getCmp(this.idPoiVerifyManagement)) {
779                                 if (Ext.getCmp(this.idPoiVerifyManagement).editor) {
780                                     _editor = Ext.getCmp(this.idPoiVerifyManagement).editor;
781                                 }
782                         }
783                         Ext.getCmp('IDTopDataPanel').geometryTop = _editor.geoJSON.write(_editor.editLayer.features);
784                     },
785                     getExtent: function() {
786                         var _editor = this.editor;
787                         if (Ext.getCmp(this.idnewTopManage)) {
788                                 if (Ext.getCmp(this.idnewTopManage).editor) {
789                                     _editor = Ext.getCmp(this.idnewTopManage).editor;
790                                 }
791                         }
792                         if (Ext.getCmp(this.idPoiVerifyManagement)) {
793                                 if (Ext.getCmp(this.idPoiVerifyManagement).editor) {
794                                     _editor = Ext.getCmp(this.idPoiVerifyManagement).editor;
795                                 }
796                         }
797                         if (_editor)
798                             Ext.getCmp('IDTopDataPanel').extentAreaSemantica = _editor.editLayer.getExtent();
799                     },
800                     getGeometryAttrDiz: function() {
801                         
802                         var _editorAttDiz = this.editorAttDiz;
803                         if (Ext.getCmp(this.idnewTopManage)) {
804                                 if (Ext.getCmp(this.idnewTopManage).editorAttDiz) {
805                                     _editorAttDiz = Ext.getCmp(this.idnewTopManage).editorAttDiz;
806                                 }
807                         }
808                         if (Ext.getCmp(this.idPoiVerifyManagement)) {
809                                 if (Ext.getCmp(this.idPoiVerifyManagement).editorAttDiz) {
810                                     _editorAttDiz = Ext.getCmp(this.idPoiVerifyManagement).editorAttDiz;
811                                 }
812                         }
813                         
814                         if (_editorAttDiz.editLayer.features.length == 1)
815                             Ext.getCmp('IDTopAttributiDizioniDataPanel').geometryAttrDiz = _editorAttDiz.geoJSON.write(this.editorAttDiz.editLayer.features);
816                         else if (_editorAttDiz.editLayer.features.length > 1)
817                             Ext.getCmp('IDTopAttributiDizioniDataPanel').geometryAttrDiz = "multiline";
818                         else
819                             Ext.getCmp('IDTopAttributiDizioniDataPanel').geometryAttrDiz = false;
820                     },
821                     show: function() {
822                        this.layer.setVisibility(false);  
823                     },
824                     hide: function(win) {
825                         if (Ext.getCmp(this.idnewTopManage)) {
826                             if (Ext.getCmp(this.idnewTopManage).editor) {
827                                 Ext.getCmp(this.idnewTopManage).closeWinEdit();
828                             }
829                         }
830                         if (Ext.getCmp(this.idPoiVerifyManagement)) {
831                             if (Ext.getCmp(this.idPoiVerifyManagement).editor) {
832                                 Ext.getCmp(this.idPoiVerifyManagement).closeWinEdit();
833                             }
834                             Ext.getCmp(this.idPoiVerifyManagement).topDS.load();
835                         }
836                         this.closeWinEdit();
837                         this.layer.setVisibility(true);
838                         if (this.dizLayer)
839                             this.dizLayer.destroyFeatures();
840                     },
841                     close: function(win) {
842                         if (Ext.getCmp(this.idnewTopManage)) {
843                             if (Ext.getCmp(this.idnewTopManage).editor) {
844                                 Ext.getCmp(this.idnewTopManage).closeWinEdit();
845                             }
846                         }
847                         if (Ext.getCmp(this.idPoiVerifyManagement)) {
848                             if (Ext.getCmp(this.idPoiVerifyManagement).editor) {
849                                 Ext.getCmp(this.idPoiVerifyManagement).closeWinEdit();
850                             }
851                             Ext.getCmp(this.idPoiVerifyManagement).topDS.load();
852                         }
853                         this.closeWinEdit();
854                         this.layer.setVisibility(true);
855                         if (this.dizLayer)
856                             this.dizLayer.destroyFeatures();
857                     },
858                     scope: this
859                 }
860             });
861         }
862         this.winEditTOP.updateUserAuth(this.userAuthDS);
863         this.winEditTOP.openEditTopForm(evt.obj.topID);
864         this.winEditTOP.show();
865         
866         if (Ext.getCmp(this.idnewTopManage)) {
867             if (Ext.getCmp(this.idnewTopManage).editor) {
868                 this.editor = Ext.getCmp(this.idnewTopManage).editor;
869             }
870         }
871         if (Ext.getCmp(this.idTopVerifyManagement)) {
872             if (Ext.getCmp(this.idTopVerifyManagement).editor) {
873                 this.editor = Ext.getCmp(this.idTopVerifyManagement).editor;
874             }
875         }
876 
877         if (!this.editor) {
878             /**
879              * 
880              * @type OpenLayers.Editor
881              */
882             this.editor = new OpenLayers.Editor(this.map, {
883                 div: document.getElementById('editor_panel'),
884                 id: "editorAreaSematica",
885                 activeControls: ['DeleteAllFeatures','DeleteFeature','DragFeature','SelectFeature','Navigation'],
886                 featureTypes: ['point'],
887                 language: 'it'
888             });
889         }
890             
891         this.editor.startEditMode();
892         
893         if (Ext.getCmp('idBtnInsTOP'))
894             Ext.getCmp('idBtnInsTOP').disable();
895         if (Ext.getCmp('idGridPanelVerifyTop'))
896             Ext.getCmp('idGridPanelVerifyTop').disable();
897 
898         evt.hide();
899 
900 //        this.map.moveTo(evt.location, 12);
901 
902 
903     },
904     closeWinEdit: function() {
905         this.editor.stopEditMode();
906         this.editor.editLayer.removeAllFeatures();       
907      //   this.editor.controls.DeleteAllFeatures.deleteAllFeatures();
908 
909         if (Ext.getCmp('idBtnInsTOP'))
910             Ext.getCmp('idBtnInsTOP').enable();
911         if (Ext.getCmp('idGridPanelVerifyTop'))
912             Ext.getCmp('idGridPanelVerifyTop').enable();
913         //hack per visualizzare il marker
914       //  this.map.zoomOut();
915       //  this.map.zoomIn();
916     },
917     
918     /** Create comboBox object, the main object of the class.
919     * @private
920     * @param {data} is a record store
921     * @returns {String} html text to load on marker'popUp
922     */  
923     msgPopup: function(data){
924         var text = data.text + '<br>' + data.type;
925         var link = data.link;
926         if(link){
927             text = text + '<br><a target="_blank" href=' + link + '>vai al sito</a>';
928         }
929         return text;
930     },
931     
932     
933     /** 
934      *  When this component is added to a container, see if it has a parent
935      *  MapPanel somewhere and set the map
936      *  @private
937      */
938     handleAdded: function() {
939         var mapPanel = this.findParentBy(function(cmp) {
940             return cmp instanceof GeoExt.MapPanel;
941         });
942         if (mapPanel) {
943             this.setMap(mapPanel);
944         }
945 
946     },
947     
948     /**
949      *  Hides the dropdown list if it is currently expanded. Fires the {@link #collapse} event on completion.
950      *  @private
951      */
952     collapse : function(){
953         if(!this.isExpanded()){
954             return;
955         }
956         this.list.hide();
957         this.el.blur();
958         Ext.getDoc().un('mousewheel', this.collapseIf, this);
959         Ext.getDoc().un('mousedown', this.collapseIf, this);
960         this.fireEvent('collapse', this);
961     },
962    
963     /** 
964      * Zoom to the selected location, and also set a location marker if this
965      * component was configured with an :obj:`layer`.
966      * @private
967      * @param {Object} combo comnoBox object.
968      * @param {Object} record selected record.
969      * @param {Object} idx index of selected record.
970      */
971     handleSelect: function(combo, record, index) {
972         var position = new OpenLayers.LonLat(record.data.lon, record.data.lat);
973 
974         // Reproject (if required)
975         position.transform(
976                 new OpenLayers.Projection("EPSG:3003"),
977                 this.map.getProjectionObject()
978                 );
979 
980         // zoom in on the location
981         var zoomResult = this.zoom;
982 
983         this.map.setCenter(position, zoomResult);
984         
985         //strip HTML tags from string 
986         var div = document.createElement("div");
987         div.innerHTML = record.data.text;
988         var text = div.textContent || div.innerText || "";
989        // this.textSearch = text;
990       //  this.setValue(text); // put the selected name in the box
991 
992         // blur the combo box
993         //TODO Investigate if there is a more elegant way to do this.
994         (function() {
995             this.triggerBlur();
996             this.el.blur();
997         }).defer(100, this);
998     },
999             
1000     /** 
1001      *  Handler for the map's moveend event. Clears the selected location
1002      *  when the map center has changed.
1003      *  @private
1004      */
1005     clearResult: function() {
1006         this.clearValue();
1007     },
1008             
1009     /** 
1010      *  Set the :obj:`map` for this instance.
1011      *  @private
1012      *  @param {GeoExt.MapPanel||OpenLayers.Map} map object
1013      */
1014     setMap: function(map) {
1015         if (map instanceof GeoExt.MapPanel) {
1016             map = map.map;
1017         }
1018         this.map = map;
1019         map.events.on({
1020             // "moveend": this.clearResult,
1021             //  "click": this.removeFocus,
1022             scope: this
1023         });
1024     },
1025             
1026     /** 
1027      *  Called by a MapPanel if this component is one of the items in the panel.
1028      *  @private
1029      */
1030     addToMapPanel: Ext.emptyFn,
1031             
1032     /**
1033      * Execute a query to filter the dropdown list.  Fires the {@link #beforequery} event prior to performing the
1034      * query allowing the query action to be canceled if needed.
1035      * @private
1036      * @param {String} query The SQL query to execute
1037      * @param {Boolean} forceAll <tt>true</tt> to force the query to execute even if there are currently fewer
1038      * characters in the field than the minimum specified by the <tt>{@link #minChars}</tt> config option.  It
1039      * also clears any filter previously saved in the current store (defaults to <tt>false</tt>)
1040      */
1041     doQuery: function(q, forceAll) {
1042         qc = Ext.isEmpty(q) ? '' : q;
1043         
1044         var filter = '<xls:DirectoryRequest xmlns:xls="http://www.opengis.net/xls">' +
1045                 '<xls:POIProperties>';
1046         
1047         var advSearch = false;
1048         
1049         if (!Ext.isEmpty(q)) {
1050             if (this.store.baseParams.istat || this.store.baseParams.bbox 
1051                     || this.store.baseParams.euristic || this.store.baseParams.category) {
1052                 if (this.store.baseParams.euristic)
1053                     filter += '<xls:POIProperty name="other" value="testoEuristico|' + q + '"/>';
1054                 else
1055                     filter += '<xls:POIProperty name="other" value="testoFullLike|' + q + '"/>';                
1056             }
1057             else {
1058                 filter += '<xls:POIProperty name="other" value="' + this.typerequest + '|' + q + '"/>';    
1059             }
1060         }
1061         if (this.store.baseParams.istat) {
1062             filter += '<xls:POIProperty name="other" value="codIstatComune|'+this.store.baseParams.istat+'"/>';
1063             advSearch = true;
1064         }
1065         if (this.store.baseParams.bbox) {
1066             filter +=  '<xls:POIProperty name="other" value="extent|'+this.store.baseParams.bbox+'"/>';
1067         }
1068         if (this.store.baseParams.category) {
1069             filter += '<xls:POIProperty name="other" value="tipi|'+this.store.baseParams.category+'"/>'; 
1070             advSearch = true;
1071         }
1072         
1073         filter += '<xls:POIProperty name="other" value="geometry|' + this.geometry + '"/>' +
1074                 '<xls:POIProperty name="other" value="numPagina|' + this.numpage + '"/>' +
1075                 '<xls:POIProperty name="other" value="numRisultatiPerPagina|' + this.pageSize + '"/>' +
1076                 '</xls:POIProperties>' +
1077                 '</xls:DirectoryRequest>';
1078         
1079        // var q = Ext.isEmpty(q) ? '' : filter;
1080         var q = filter;
1081          
1082         var qe = {
1083             query: q,
1084             forceAll: forceAll,
1085             combo: this,
1086             cancel: false
1087         };
1088         if (this.fireEvent('beforequery', qe) === false || qe.cancel) {
1089             return false;
1090         }
1091         q = qe.query;
1092         forceAll = qe.forceAll;
1093         if (forceAll === true || (qc.length >= this.minChars)) {
1094             
1095             if (!advSearch && qc.length < 3) {
1096                 Ext.Msg.alert('Avviso', 'È necessario inserire una parola di almeno tre lettere o impostare un filtro di ricerca avanzato');
1097             }
1098             else if (this.lastQuery !== q) {
1099                 this.lastQuery = q;
1100                 if (this.mode === 'local') {
1101                     this.selectedIndex = -1;
1102                     if (forceAll) {
1103                         this.store.clearFilter();
1104                     } else {
1105                         this.store.filter(this.displayField, q);
1106                     }
1107                     this.onLoad();
1108                 } else {
1109                     this.store.baseParams[this.queryParam] = q;
1110                     this.store.load({
1111                         params: this.getParams(q)
1112                     });
1113                     this.expand();
1114                 }
1115             } /*else {
1116                 this.selectedIndex = -1;
1117                 this.onLoad();
1118             }*/
1119         }
1120         //this.insertPOIMap(this.store);  
1121     }
1122 });
1123 
1124 /** api: xtype = gx_DirectoryOpenLSComboBox */
1125 Ext.reg("framework_directoryopenlscombobox", framework.form.DirectoryOpenLSComboBox);
1126