1
|
/*
|
2
|
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
|
3
|
$Id: Save.js 3052 2007-08-01 21:25:21Z ahocevar $
|
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 the targetModel is posted to the serializeUrl.
|
11
|
* Also defines a listener function for the "modelSaved" event which opens
|
12
|
* the serialized document in a new browser window but only
|
13
|
* if the a popupWindowName property is defined for the button in config.
|
14
|
*
|
15
|
* @constructor
|
16
|
* @base ButtonBase
|
17
|
* @param widgetNode The widget node from the Config XML file.
|
18
|
* @param model The model for this widget
|
19
|
*/
|
20
|
function Save(widgetNode, model) {
|
21
|
ButtonBase.apply(this, new Array(widgetNode, model));
|
22
|
|
23
|
/**
|
24
|
* Add event listener to the modelSaved event
|
25
|
* @param objRef Pointer to this widget
|
26
|
*/
|
27
|
this.init = function(objRef) {
|
28
|
objRef.targetModel.addListener("modelSaved", objRef.popupContext, objRef);
|
29
|
}
|
30
|
this.model.addListener("loadModel", this.init, this );
|
31
|
|
32
|
/**
|
33
|
* Save model control.
|
34
|
* @param objRef reference to this object.
|
35
|
* @return {OpenLayers.Control} instance of the OL control.
|
36
|
*/
|
37
|
this.createControl = function(objRef) {
|
38
|
var Control = OpenLayers.Class( OpenLayers.Control, {
|
39
|
|
40
|
type: OpenLayers.Control.TYPE_BUTTON,
|
41
|
|
42
|
trigger: function () {
|
43
|
objRef.targetModel.saveModel(objRef.targetModel);
|
44
|
},
|
45
|
CLASS_NAME: 'mbControl.Save'
|
46
|
});
|
47
|
return Control;
|
48
|
}
|
49
|
|
50
|
/**
|
51
|
* Open popup window with context
|
52
|
* @param objRef reference to this object.
|
53
|
* @return none
|
54
|
*/
|
55
|
this.popupContext = function(objRef) {
|
56
|
url = objRef.targetModel.getParam("modelSaved");
|
57
|
if (url) {
|
58
|
var popup=window.open(url);
|
59
|
if (!popup) {
|
60
|
alert('Please allow popups in order to save the context');
|
61
|
}
|
62
|
} else {
|
63
|
alert('Model could not be saved. Our apologies.');
|
64
|
}
|
65
|
}
|
66
|
|
67
|
|
68
|
}
|
69
|
|
70
|
|