1 /**
  2  * @require framework/widgets/form/MultipleInputField.js
  3  */
  4 
  5 /**
  6  * @namespace framework.widgets
  7  */
  8 Ext.namespace("framework.widgets"),
  9         /** 
 10          *  Panel search engine container.
 11          *  This implementation manage different search engine. 
 12          *  By default, place a comboBox to switch different search engine components located inside the panel. 
 13          *  @name_ PanelSearch 
 14          *  @class Panel search engine container.
 15          *  @constructor
 16          *  @extends <a target="_blank" href="http://docs.sencha.com/extjs/4.1.3/#!/api/Ext.panel.Panel">Ext.Panel</a>
 17          */
 18         framework.widgets.TopAttributiDizioniDataPanel = Ext.extend(Ext.Window, {
 19             /**
 20              * The Servlet name used to get Poi Term-Category information
 21              * @type String
 22              */
 23             topCatTipServeltName: 'toponimirequest',
 24             id: 'IDTopAttributiDizioniDataPanel',
 25             layout: 'fit',
 26             width: 490,
 27             height: 230,
 28             title: 'Attributo Dizione',
 29             closable: false,
 30             resizable: true,
 31             plain: true,
 32             border: false,
 33             x: 140,
 34             y: 140,
 35             initTipo: null,
 36             /** api: config[urlService]
 37              *  
 38              *  url to proxy for authenticate http calls
 39              *  @public
 40              *  @type String
 41              */
 42             urlProxy: '',
 43             /** api: config[geometryFields]
 44              *  
 45              *  fields from service answer to be transformed on OpenLayers.Bounds
 46              *  @public
 47              *  @type Array of String
 48              */
 49             geometryFields: null,
 50             srs: 'EPSG:300',
 51             topFeature: null,
 52             topFeatureNew: null,
 53             /**
 54              * paht for images marker,
 55              * default value is "theme/app/img/".
 56              * @public
 57              * @type String
 58              */
 59             markersImgPath: 'theme/app/img/',
 60             click: null,
 61             checkControlClick: false,
 62             userAuthDS: null,
 63             geometryAttrDiz: null,
 64             testID: false,
 65             
 66             destroy: function() {
 67                 framework.widgets.TopAttributiDizioniDataPanel.superclass.destroy.apply(this, arguments);
 68             },
 69             initComponent: function() {
 70                 
 71                 var _self = this;
 72                 
 73                 this._attributodizioneform = new Ext.FormPanel({
 74                     labelWidth: 100,
 75                     frame: true,
 76                     defaultType: 'textfield',
 77                     id: 'attributidizioneFormID',
 78 //          monitorValid: true,
 79                     standardSubmit: false,
 80                     layout: 'form',
 81                     items: [
 82                         {
 83                             id: 'idAttributo',
 84                             fieldLabel: 'ID',
 85                             name: 'idTesto',
 86                             width: 300,
 87                             blankText : this.blankText,
 88                             allowBlank: false
 89                         },{
 90                             id: 'testoAttributo',
 91                             fieldLabel: 'Testo',
 92                             name: 'testo',
 93                             width: 300,
 94                             blankText : this.blankText,
 95                             allowBlank: false
 96                         },
 97                         {id: 'geometryDiz', xtype: 'hidden', name: 'geometryDiz'}
 98                         ,{
 99                             width: 460,
100                             height: 70,
101                             xtype: 'fieldset',
102                             title: 'Linea base',
103                             collapsible: false,
104                           //  defaults: {width: 140},
105                             //style: 'margin-left: 10px;',
106                             defaultType: 'textfield',
107                           //  labelAlign:'top',
108                             items: [
109                                 {
110                                     xtype: 'container',
111                                     id: 'editorattdiz_panel',
112                                     cls: 'olEditorControlEditorPanel olControl',
113                                     layout: 'fit',
114                                     height: 50
115                                 }
116                             ]
117 
118                            }
119                         ],
120                     buttons: [{
121                             text: 'Annulla',
122                             handler: function() {
123                                 _self.hide();
124                             }
125                         }, {
126                             text: 'Elimina',
127                             id: 'btnDeleteAttrDizTOP',
128                             handler: function() {
129                                  Ext.MessageBox.show({
130                                     title : 'Attenzione!',
131                                     msg : 'Sei sicuro di voler eliminare questo attributo?',
132                                     width : 300,
133                                     buttons: Ext.MessageBox.YESNO,
134                                     buttonText:{ 
135                                         yes: "Si", 
136                                         no: "No" 
137                                     },
138                                     fn : myCallback
139                                    // icon : Ext.MessageBox.QUESTION
140                                 });
141                                 
142                                 function myCallback(btn) {
143                                     if (btn == "yes") {
144                                         var idTesto = _self._attributodizioneform.getForm().findField('idTesto').getValue();
145                                         _self.fireEvent('deleteAttrDiz', idTesto);
146                                         _self.hide();
147                                     }
148                                 }
149                                 
150                             }
151                         }, {
152                             text: 'Salva',
153                             id: 'btnSaveAttrDizTOP',
154                             handler: function() {
155                                 
156                                 var idTesto = _self._attributodizioneform.getForm().findField('idTesto').getValue();
157                                 var testo = _self._attributodizioneform.getForm().findField('testo').getValue();
158                                 
159                                 function isInt(n) {
160                                     return n % 1 === 0;
161                                 }
162                                 
163                                 _self.fireEvent('testID',idTesto);
164                                 _self.fireEvent('getGeometryAttrDiz');
165                                 
166                                 var idTestoCurr = null;
167                                 if (_self.attributoDiz)
168                                     idTestoCurr = _self.attributoDiz.idTesto;
169                                 
170                                 
171                                 if (!isInt(idTesto) || parseInt(idTesto) == 0) {
172                                     Ext.Msg.alert('Attenzione', "L'ID deve essere un numero intero");
173                                 }
174                                 else if ((_self.testID != -1) && (idTesto != idTestoCurr)) {
175                                     Ext.Msg.alert('Attenzione', "L'ID è già utilizzato");
176                                 }
177                                 else if (_self.geometryAttrDiz == "multiline") {
178                                     Ext.Msg.alert('Attenzione', "L'attributo della dizione deve avere solo una linea base");
179                                 }
180                                 else if (idTesto && testo && _self.geometryAttrDiz) {
181                                     
182                                     var obj = JSON.parse(_self.geometryAttrDiz);
183                                     
184                                     if (!_self.attributoDiz) {
185                                        _self.attributoDiz = {};
186                                     }
187                                 
188                                     _self.attributoDiz.idTesto = parseInt(idTesto);
189                                     _self.attributoDiz.testo = testo;
190                                     _self.attributoDiz.geometria = obj.features[0].geometry;
191                                     
192                                     _self.fireEvent('saveAttrDiz', _self.attributoDiz);
193 
194                                     _self.hide();
195                                 
196                                 }
197                                 else 
198                                     Ext.Msg.alert('Attenzione', "Compilare tutti i campi e/o aggiungere una linea base");
199                                 
200                             }
201                         }]
202                 });
203 
204                 this.items = [this._attributodizioneform];
205 
206                 this.openEditAttrDizTopForm = function(attributo) {
207                     
208                     this.attributoDiz = attributo;
209                     
210                     var _self = this;
211                  //   _self.topFeature = topFeature;
212                  //   _self.topFeatureNew = null;
213                      
214                     if (attributo) {
215                         this.title = 'Modifica attributo';
216                         this._attributodizioneform.getForm().findField('idTesto').setValue(attributo.idTesto);
217                         this._attributodizioneform.getForm().findField('testo').setValue(attributo.testo);
218                         
219                         var geojsonData = 
220                         {
221                                 "type":"Feature",
222                                 "geometry": attributo.geometria
223                         };
224                         var geojson_format = new OpenLayers.Format.GeoJSON({
225                             'internalProjection': new OpenLayers.Projection("EPSG:3003"),
226                             'externalProjection': new OpenLayers.Projection("EPSG:3003")
227                         });
228                         var geom = geojson_format.read(geojsonData);
229                         var features = [];
230 
231                         var features = new OpenLayers.Feature.Vector(
232                                 new OpenLayers.Geometry.LineString(geom[0].geometry.components)
233                         );
234 
235                         this.fireEvent('loadGeometryAttDiz', features);
236                         Ext.getCmp('btnDeleteAttrDizTOP').enable();
237 
238                     }
239                     else {
240                        this.title = 'Nuovo attributo';
241                        this._attributodizioneform.getForm().reset();
242                        Ext.getCmp('btnDeleteAttrDizTOP').disable();
243                            
244                    }
245                    
246                 };
247                
248                 framework.widgets.TopAttributiDizioniDataPanel.superclass.initComponent.call(this);
249             }
250 
251 
252         });
253 
254 /** api: xtype = framework_panelpoidata */
255 Ext.reg("framework_topattributidizionidatapanel", framework.widgets.TopAttributiDizioniDataPanel);