1WebGis.FeatureCRUD = OpenLayers.Class({ 2 3 /*********************************************************************************************/ 4 /********************************* Variables ************************************************/ 5 /********************************************************************************************/ 6 7 layer: null, 8 feature: null, 9 saveStrategy: null, 10 state: null, 11 insertedFeature_geometryWKT: null, 12 refreshTimeout: null, 13 14 onSuccess: null, 15 onError: null, 16 17 EM_CREATE: properties.map.CRUD_EM_Create, 18 EM_UPDATE: properties.map.CRUD_EM_Update, 19 EM_DELETE: properties.map.CRUD_EM_Delete, 20 EM_REFRESH: properties.map.CRUD_EM_Refresh, 21 22 /*********************************************************************************************/ 23 24 25 /*********************************************************************************************/ 26 /********************************* Constructor ***********************************************/ 27 /*********************************************************************************************/ 28 29 initialize: function () { 30 31 }, 32 33 /*********************************************************************************************/ 34 35 /*********************************************************************************************/ 36 /********************************* Public methods ********************************************/ 37 /*********************************************************************************************/ 38 39 //Insert feature 40 create: function (_feature, _layer, _onSucces, _onError) { 41 42 this.feature = _feature; 43 this.layer = _layer; 44 this.onSuccess = _onSucces; 45 this.onError = _onError; 46 this.state = OpenLayers.State.INSERT; 47 48 this.feature.state = OpenLayers.State.INSERT; 49 this.insertedFeature_geometryWKT = (new OpenLayers.Format.WKT()).write(this.feature); 50 this.save(); 51 52 }, 53 54 //Update feature 55 update: function (_feature, _layer, _onSucces, _onError) { 56 57 this.feature = _feature; 58 this.layer = _layer; 59 this.onSuccess = _onSucces; 60 this.onError = _onError; 61 this.state = OpenLayers.State.UPDATE; 62 63 this.insertedFeature_geometryWKT = null; 64 this.feature.state = OpenLayers.State.UPDATE; 65 this.save(); 66 }, 67 68 //Delete feature 69 delete: function (_feature, _layer, _onSucces, _onError) { 70 71 this.feature = _feature; 72 this.layer = _layer; 73 this.onSuccess = _onSucces; 74 this.onError = _onError; 75 this.state = OpenLayers.State.DELETE; 76 this.insertedFeature_geometryWKT = null; 77 this.feature.state = OpenLayers.State.DELETE; 78 this.save(); 79 }, 80 81 //Retrieve feature 82 retrieve: function () { 83 84 }, 85 86 /*********************************************************************************************/ 87 88 /*********************************************************************************************/ 89 /********************************* Private methods ********************************************/ 90 /*********************************************************************************************/ 91 92 //Create/Insert/Delete the current feature 93 save: function () { 94 95 this.createSaveStrategy(); 96 this.saveStrategy.activate(); 97 this.saveStrategy.save(this.features); 98 }, 99 100 //Create the save strategy and set its success and error events 101 createSaveStrategy: function () { 102 103 this.saveStrategy = new OpenLayers.Strategy.Save({ auto: false }); 104 //It can be a difference between the feature layer and the layer because it can be used another layer for the form 105 this.saveStrategy.layer = this.feature.layer; 106 107 //On succes event 108 this.saveStrategy.events.register("success", this, function (e) { 109 110 //Deactivate save strategy 111 this.saveStrategy.deactivate(); 112 113 //Search result 114 if (this.layer.isTemporary) { 115
116 //Trigger the delegate event for successfull CRUD operation 117 this.onSuccess(); 118 return; 119 } 120 121 //If the layer is not visible, then the layer should not be refresh 122 var zoomMin = _mapControl.GetLayerZoomMin(this.layer); 123 var zoomMax = _mapControl.GetLayerZoomMax(this.layer); 124 var zoom = _mapControl.map.getZoom(); 125 if (zoom < zoomMin || zoom > zoomMax || !this.layer.visibility) { 126 127 if (this.state == OpenLayers.State.INSERT) { 128 129 this.layer.forceRefresh = true; 130 _mapControl.featureSelection.ClearSelection(); 131 } 132 else if (this.state == OpenLayers.State.UPDATE) { 133 _mapControl.featureSelection.UpdateFeatureDetails(this.layer.GUID, this.feature.attributes[this.layer.idFieldName], this.feature) 134 } 135 //Trigger the delegate event for successfull CRUD operation 136 this.onSuccess(); 137 return; 138 } 139 140 //Refresh layer after successfull CRUD operation 141 this.layer.events.register("loadend", this, this.Layer_LoadEnd_onSuccessfullSave); 142 this.layer.refresh({ force: true }); 143 144 if (this.refresh != null) { 145 clearTimeout(this.refreshTimeout); 146 } 147 this.refreshTimeout = setTimeout(function () { 148 this.Layer_LoadEnd_onSuccessfullSave(null); 149 }.bind(this), 60000); 150 151 }); 152 153 //On error event 154 this.saveStrategy.events.register("fail", this, function (e) { 155 156 //Deactivate save strategy 157 this.saveStrategy.deactivate(); 158 159 160 if (this.layer.isTemporary) { 161 162 163 var msg = ""; 164 switch (this.state) { 165 case OpenLayers.State.INSERT: 166 msg = this.EM_CREATE; 167 break; 168 case OpenLayers.State.UPDATE: 169 msg = this.EM_UPDATE; 170 break; 171 case OpenLayers.State.DELETE: 172 msg = this.EM_DELETE; 173 break; 174 175 } 176 if (msg != "") { 177 Ext.Msg.alert('', msg, Ext.emptyFn); 178 } 179 180 //Trigger the delegate event for successfull CRUD operation 181 this.onError(); 182 return; 183 } 184 185 //If the layer is not visible, then the layer should not be refresh 186 var zoomMin = _mapControl.GetLayerZoomMin(this.layer); 187 var zoomMax = _mapControl.GetLayerZoomMax(this.layer); 188 var zoom = _mapControl.map.getZoom(); 189 if (zoom < zoomMin || zoom > zoomMax || !this.layer.visibility) { 190 191 //Inform the user about the error 192 var msg = ""; 193 switch (this.state) { 194 case OpenLayers.State.INSERT: 195 msg = this.EM_CREATE; 196 break; 197 case OpenLayers.State.UPDATE: 198 msg = this.EM_UPDATE; 199 break; 200 case OpenLayers.State.DELETE: 201 msg = this.EM_DELETE; 202 break; 203 204 } 205 if (msg != "") { 206 Ext.Msg.alert('', msg, Ext.emptyFn); 207 } 208 209 //Trigger the delegate event for successfull CRUD operation 210 this.onError(); 211 return; 212 } 213 214 //Refresh layer after unsuccessfull CRUD operation 215 this.layer.events.register("loadend", this, this.Layer_LoadEnd_onUnsuccessfullSave); 216 this.layer.refresh({ force: true }); 217 218 if (this.refresh != null) { 219 clearTimeout(this.refreshTimeout); 220 } 221 this.refreshTimeout = setTimeout(function () { 222 this.Layer_LoadEnd_onUnsuccessfullSave(null); 223 }.bind(this), 60000); 224 }); 225 }, 226 227 //Layer load end delegate event for successfull save operation 228 Layer_LoadEnd_onSuccessfullSave: function (evt) { 229 230 try { 231 //Clear timeout 232 clearTimeout(this.refreshTimeout); 233 234 //Unregister event 235 this.layer.events.unregister("loadend", this, this.Layer_LoadEnd_onSuccessfullSave); 236 237 //In case of insert , try select the new feature 238 if (this.state == OpenLayers.State.INSERT) { 239 240 var insertedFeatureID = null; 241 var insertedFeature = null; 242 243 244 for (var i = 0; i < this.layer.features.length; i++) { 245 if ((new OpenLayers.Format.WKT()).write(this.layer.features[i]) == this.insertedFeature_geometryWKT) { 246 insertedFeatureID = insertedFeatureID == null ? this.layer.features[i].attributes[this.layer.idFieldName] : 247 Math.max(insertedFeatureID, this.layer.features[i].attributes[this.layer.idFieldName]); 248 insertedFeature = insertedFeatureID == this.layer.features[i].attributes[this.layer.idFieldName] ? this.layer.features[i] : 249 insertedFeature; 250 } 251 } 252 253 if (insertedFeature != null) {
254 _mapControl.featureSelection.SelectFeature(insertedFeature); 255 } 256 } 257 258 //In case an error has occured during the refresh layer process 259 if (evt == null || (evt.response != null && evt.response.priv.statusText != "OK")) { 260 var msg = this.EM_REFRESH; 261 switch (this.state) { 262 case OpenLayers.State.INSERT: 263 msg = msg.replace(properties.map.Salvat, "salvat"); 264 break; 265 case OpenLayers.State.UPDATE: 266 msg = msg.replace(properties.map.Actualizat, "actualizat"); 267 break; 268 case OpenLayers.State.DELETE: 269 msg = msg.replace(properties.map.Sters, "sters"); 270 break; 271 } 272 if (msg != "") { 273 Ext.Msg.alert('', msg, Ext.emptyFn); 274 } 275 } 276 277 //Trigger the delegate event for successfull CRUD operation 278 this.onSuccess(); 279 280 } 281 catch (e) { 282 283 //Trigger the delegate event for successfull CRUD operation 284 this.onSuccess(); 285 } 286 287 }, 288 289 //Layer load end delegate event for unsuccessfull save operation 290 Layer_LoadEnd_onUnsuccessfullSave: function (evt) { 291 292 try { 293 294 //Clear timeout 295 clearTimeout(this.refreshTimeout); 296 297 //Unregister event 298 this.layer.events.unregister("loadend", this, this.Layer_LoadEnd_onUnsuccessfullSave); 299 300 //Inform the user about the error 301 var msg = ""; 302 switch (this.state) { 303 case OpenLayers.State.INSERT: 304 msg = this.EM_CREATE; 305 break; 306 case OpenLayers.State.UPDATE: 307 msg = this.EM_UPDATE; 308 break; 309 case OpenLayers.State.DELETE: 310 msg = this.EM_DELETE; 311 break; 312 313 } 314 if (msg != "") { 315 Ext.Msg.alert('', msg, Ext.emptyFn); 316 } 317 318 //Trigger the delegate event for successfull CRUD operation 319 this.onError(); 320 321 } 322 catch (e) { 323 324 //Trigger the delegate event for successfull CRUD operation 325 this.onError(); 326 } 327 328 }, 329 330 /*********************************************************************************************/ 331 332 333});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.