1
|
/*
|
2
|
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
|
3
|
$Id: DeleteFeature.js 3879 2008-02-27 14:20:29Z gjvoosten $
|
4
|
*/
|
5
|
|
6
|
// Ensure this object's dependancies are loaded.
|
7
|
mapbuilder.loadScript(baseDir+"/widget/ButtonBase.js");
|
8
|
|
9
|
/**
|
10
|
* When this button is pressed a WFS-T DeleteFeature transaction will be started.
|
11
|
* @constructor
|
12
|
* @base ButtonBase
|
13
|
* @author Cameron Shorter
|
14
|
* @param widgetNode The widget node from the Config XML file.
|
15
|
* @param model The model for this widget
|
16
|
*/
|
17
|
function DeleteFeature(widgetNode, model) {
|
18
|
// Extend ButtonBase
|
19
|
ButtonBase.apply(this, new Array(widgetNode, model));
|
20
|
|
21
|
// override default cursor by user
|
22
|
// cursor can be changed by spefying a new cursor in config file
|
23
|
this.cursor = "default";
|
24
|
|
25
|
this.trm=this.getProperty("mb:transactionResponseModel");
|
26
|
this.tm=this.getProperty("mb:targetModel");
|
27
|
this.tc=this.getProperty("mb:targetContext");
|
28
|
|
29
|
this.httpPayload=new Object();
|
30
|
this.httpPayload.url=this.getProperty("mb:webServiceUrl");
|
31
|
this.httpPayload.method="post";
|
32
|
|
33
|
/** Xsl to convert Feature into a WFS Transaction Delete. */
|
34
|
this.deleteXsl=new XslProcessor(baseDir+"/tool/xsl/wfs_Delete.xsl");
|
35
|
|
36
|
/** creates the OL control for this button */
|
37
|
this.createControl = function(objRef) {
|
38
|
var Control = OpenLayers.Class(OpenLayers.Control, {
|
39
|
CLASS_NAME: 'mbDeleteFeature',
|
40
|
type: OpenLayers.Control.TYPE_BUTTON
|
41
|
});
|
42
|
return Control;
|
43
|
}
|
44
|
|
45
|
/**
|
46
|
* Start a WFS-T DeleteFeature transaction.
|
47
|
* @param objRef Pointer to this object.
|
48
|
*/
|
49
|
this.doSelect = function(objRef, selected) {
|
50
|
if (selected){
|
51
|
// Model that will be populated with the WFS response.
|
52
|
if (!objRef.transactionResponseModel){
|
53
|
objRef.transactionResponseModel=window.config.objects[objRef.trm];
|
54
|
objRef.transactionResponseModel.addListener("loadModel",objRef.handleResponse, objRef);
|
55
|
}
|
56
|
if (!objRef.targetModel){
|
57
|
objRef.targetModel=window.config.objects[objRef.tm];
|
58
|
}
|
59
|
if (!objRef.targetContext){
|
60
|
objRef.targetContext=window.config.objects[objRef.tc];
|
61
|
}
|
62
|
fid=objRef.targetModel.getXpathValue(objRef.targetModel,"//@fid");
|
63
|
//if fid exists, then we are deleting an existing feature.
|
64
|
if (objRef.targetModel.doc && fid){
|
65
|
s=objRef.deleteXsl.transformNodeToObject(objRef.targetModel.doc);
|
66
|
objRef.httpPayload.postData=s;
|
67
|
objRef.transactionResponseModel.transactionType="delete";
|
68
|
objRef.transactionResponseModel.newRequest(objRef.transactionResponseModel,objRef.httpPayload);
|
69
|
}else alert(mbGetMessage("noFeatureToDelete"));
|
70
|
}
|
71
|
}
|
72
|
|
73
|
/**
|
74
|
* If transaction was sucessful, refresh the map and remove contents of
|
75
|
* FeatureList. This function is called after the TransactionResponseModel
|
76
|
* has been updated.
|
77
|
* @param objRef Pointer to this object.
|
78
|
*/
|
79
|
this.handleResponse=function(objRef){
|
80
|
if (objRef.transactionResponseModel.transactionType=="delete") {
|
81
|
success=objRef.transactionResponseModel.doc.selectSingleNode("//wfs:TransactionResult/wfs:Status/wfs:SUCCESS");
|
82
|
if (success){
|
83
|
// Remove FeatureList if feature entry was successful.
|
84
|
objRef.targetModel.setModel(objRef.targetModel,null);
|
85
|
|
86
|
// Repaint GmlRenderers
|
87
|
objRef.targetModel.callListeners("refreshGmlRenderers");
|
88
|
|
89
|
// Repaint the WMS layers
|
90
|
objRef.targetContext.callListeners("refreshWmsLayers");
|
91
|
}
|
92
|
}
|
93
|
}
|
94
|
}
|