1
|
/*
|
2
|
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
|
3
|
$Id: InsertFeature.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 InsertFeature 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 InsertFeature(widgetNode, model) {
|
18
|
|
19
|
// override default cursor by user
|
20
|
// cursor can be changed by spefying a new cursor in config file
|
21
|
this.cursor = "default";
|
22
|
|
23
|
// Extend ButtonBase
|
24
|
ButtonBase.apply(this, new Array(widgetNode, model));
|
25
|
|
26
|
this.trm=this.getProperty("mb:transactionResponseModel");
|
27
|
this.tm=this.getProperty("mb:targetModel");
|
28
|
this.tc=this.getProperty("mb:targetContext");
|
29
|
|
30
|
this.httpPayload=new Object();
|
31
|
this.httpPayload.url=this.getProperty("mb:webServiceUrl");
|
32
|
this.httpPayload.method="post";
|
33
|
|
34
|
/** Xsl to convert Feature into a WFS Transaction Insert. */
|
35
|
this.insertXsl=new XslProcessor(baseDir+"/tool/xsl/wfs_Insert.xsl");
|
36
|
|
37
|
/** Xsl to convert Feature into a WFS Transaction Update. */
|
38
|
this.updateXsl=new XslProcessor(baseDir+"/tool/xsl/wfs_Update.xsl");
|
39
|
|
40
|
/** creates the OL control for this button */
|
41
|
this.createControl = function(objRef) {
|
42
|
var Control = OpenLayers.Class(OpenLayers.Control, {
|
43
|
CLASS_NAME: 'mbInsertFeature',
|
44
|
type: OpenLayers.Control.TYPE_BUTTON
|
45
|
});
|
46
|
return Control;
|
47
|
}
|
48
|
|
49
|
/**
|
50
|
* Start a WFS-T InsertFeature transaction.
|
51
|
* @param objRef Pointer to this object.
|
52
|
*/
|
53
|
this.doSelect = function(objRef, selected) {
|
54
|
if (selected){
|
55
|
// Model that will be populated with the WFS response.
|
56
|
if (!objRef.transactionResponseModel){
|
57
|
objRef.transactionResponseModel=window.config.objects[objRef.trm];
|
58
|
objRef.transactionResponseModel.addListener("loadModel",objRef.handleResponse, objRef);
|
59
|
}
|
60
|
if (!objRef.targetModel){
|
61
|
objRef.targetModel=window.config.objects[objRef.tm];
|
62
|
}
|
63
|
if (!objRef.targetContext){
|
64
|
objRef.targetContext=window.config.objects[objRef.tc];
|
65
|
}
|
66
|
fid=objRef.targetModel.getXpathValue(objRef.targetModel,"//@fid");
|
67
|
if (objRef.targetModel.doc){
|
68
|
//if fid exists, then we are modifying an existing feature,
|
69
|
// otherwise we are adding a new feature
|
70
|
if(fid){
|
71
|
s=objRef.updateXsl.transformNodeToObject(objRef.targetModel.doc);
|
72
|
}else{
|
73
|
s=objRef.insertXsl.transformNodeToObject(objRef.targetModel.doc);
|
74
|
}
|
75
|
objRef.httpPayload.postData=s;
|
76
|
objRef.transactionResponseModel.transactionType="insert";
|
77
|
objRef.transactionResponseModel.newRequest(objRef.transactionResponseModel,objRef.httpPayload);
|
78
|
}else alert(mbGetMessage("noFeatureToInsert"));
|
79
|
}
|
80
|
}
|
81
|
|
82
|
/**
|
83
|
* If transaction was sucessful, refresh the map and remove contents of
|
84
|
* FeatureList. This function is called after the TransactionResponseModel
|
85
|
* has been updated.
|
86
|
* @param objRef Pointer to this object.
|
87
|
*/
|
88
|
this.handleResponse=function(objRef){
|
89
|
if (objRef.transactionResponseModel.transactionType=="insert") {
|
90
|
success=objRef.transactionResponseModel.doc.selectSingleNode("//wfs:TransactionResult/wfs:Status/wfs:SUCCESS");
|
91
|
if (success){
|
92
|
// Remove FeatureList
|
93
|
config.loadModel(objRef.targetModel.id, objRef.targetModel.url);
|
94
|
|
95
|
// Repaint the WMS layers
|
96
|
objRef.targetContext.callListeners("refreshWmsLayers");
|
97
|
}
|
98
|
}
|
99
|
}
|
100
|
}
|