This repository has been archived by the owner on Jun 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Don't allow users to edit anything if there's no editable layer visible #65
Merged
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5973bdb
Don't allow users to edit anything if there's no editable layer visible
bb2576e
Don't allow users to edit anything if there's no editable layer visible
0fc45dc
Fixing menu item creation, thanks @elemoine
23ccd61
Fixing menu item creation, thanks @elemoine
8c0a01a
Actually Ext.each won't work on Array
983772a
Listening on checkchange doesn't work when nodes are added to the tree.
478fb4e
Abort requests when we get a new list of editable layers. This preven…
32b8c4a
Better management of the items a the new feature button when list of …
ef71619
Also close editing window if the currently edited feature is not in a…
71bd0f1
Better comparison for layer ids, don't use toString but parseInt
9e7e31a
Minor doc comment change
07e3219
the pendingRequests property needs to be initialized in the constructor
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,6 +91,12 @@ cgxp.plugins.Editing = Ext.extend(gxp.plugins.Tool, { | |
*/ | ||
win: null, | ||
|
||
/** private: property[newFeatureBtn] | ||
* ``Ext.form.SplitButton`` | ||
* The 'create an new feature' button. | ||
*/ | ||
newFeatureBtn: null, | ||
|
||
/** api: config[helpText] | ||
* ``String`` | ||
* The text to the top of the editing window (i18n). | ||
|
@@ -110,6 +116,12 @@ cgxp.plugins.Editing = Ext.extend(gxp.plugins.Tool, { | |
*/ | ||
createBtnText: 'Create a new feature', | ||
|
||
/** private: config[pendingRequests] | ||
* ``GeoExt.data.AttributeStore`` | ||
* The list of pendingRequests (actually the attribute stores) | ||
*/ | ||
pendingRequests: null, | ||
|
||
/** private: method[init] | ||
*/ | ||
init: function() { | ||
|
@@ -118,24 +130,80 @@ cgxp.plugins.Editing = Ext.extend(gxp.plugins.Tool, { | |
this.map = this.target.mapPanel.map; | ||
this.addEditingLayer(); | ||
this.createGetFeatureControl(); | ||
this.pendingRequests = []; | ||
|
||
this.newFeatureBtn = this.createNewFeatureBtn(); | ||
var win = this.win = new Ext.Window({ | ||
width: 300, | ||
border: false, | ||
closable: false, | ||
plain: true, | ||
resizable: false, | ||
disabled: true, | ||
items: [{ | ||
xtype: 'box', | ||
html: this.helpText + '<hr />' | ||
}, this.createNewFeatureBtn()] | ||
}, this.newFeatureBtn] | ||
}); | ||
this.target.mapPanel.on({ | ||
'render': function() { | ||
win.show(); | ||
win.anchorTo.defer(100, win, [this.body, 'tl-tl', [55, 10]]); | ||
} | ||
}); | ||
|
||
var portal = this.target; | ||
portal.on({ | ||
ready: function() { | ||
var tree = portal.tools[this.layerTreeId].tree; | ||
tree.on({ | ||
checkchange: this.manageLayers, | ||
addgroup: this.manageLayers, | ||
removegroup: this.manageLayers, | ||
scope: this | ||
}); | ||
}, | ||
scope: this | ||
}); | ||
}, | ||
|
||
/** private: manageLayers | ||
* Checks if there are editable layers, enables or disables the editing | ||
* window and updates the editable layers list in the create new feature | ||
* button. | ||
*/ | ||
manageLayers: function() { | ||
var layers = this.getEditableLayers(); | ||
var size = 0; | ||
var menu = this.newFeatureBtn.menu; | ||
this.abortPendingRequests(); | ||
var alreadyAvailableItems = []; | ||
menu.items.each(function(item) { | ||
if (!item.layerId) { | ||
return; | ||
} | ||
// remove items that are not in the layers list anymore | ||
if (!layers[item.layerId]) { | ||
menu.remove(item); | ||
} else { | ||
alreadyAvailableItems.push(item.layerId); | ||
} | ||
}); | ||
for (var i in layers) { | ||
size++; | ||
// only add an item for new editable layers | ||
if (alreadyAvailableItems.indexOf(i) == -1) { | ||
this.getAttributesStore(layers[i].attributes.layer_id, null, (function(store, geometryType, layer) { | ||
menu.add(this.createMenuItem(layer, geometryType)); | ||
}).createDelegate(this, [layers[i]], true)); | ||
} | ||
} | ||
this.win.setDisabled(size === 0); | ||
if (size === 0) { | ||
this.newFeatureBtn.toggle(false); | ||
this.newFeatureBtn.setText(this.createBtnText); | ||
this.closeEditing(); | ||
} | ||
}, | ||
|
||
/** private: method[addEditingLayer] | ||
|
@@ -165,30 +233,24 @@ cgxp.plugins.Editing = Ext.extend(gxp.plugins.Tool, { | |
/** private: method[createNewFeatureBtn] | ||
*/ | ||
createNewFeatureBtn: function() { | ||
function manageMenuItems() { | ||
menu.removeAll(); | ||
menu.add('<b class="menu-title">' + this.layerMenuText + '</b>'); | ||
var layers = this.getEditableLayers(); | ||
for (var i in layers) { | ||
this.getAttributesStore(layers[i].attributes.layer_id, null, function(store, geometryType) { | ||
menu.add(this.createMenuItem(layers[i], geometryType)); | ||
}); | ||
var menu = new Ext.menu.Menu({ | ||
items: ['<b class="menu-title">' + this.layerMenuText + '</b>'], | ||
listeners: { | ||
beforeremove: function(menu, item) { | ||
if (newFeatureBtn.activeItem == item) { | ||
newFeatureBtn.toggle(false); | ||
newFeatureBtn.activeItem = null; | ||
newFeatureBtn.setText(newFeatureBtn.initialConfig.text); | ||
} | ||
if (this.editorGrid && | ||
this.editorGrid.store.feature.attributes.__layer_id__.toString() == item.layerId) { | ||
this.closeEditing(); | ||
} | ||
}, | ||
scope: this | ||
} | ||
} | ||
|
||
var portal = this.target; | ||
portal.on({ | ||
ready: function() { | ||
var tree = portal.tools[this.layerTreeId].tree; | ||
tree.on({ | ||
addgroup: manageMenuItems.createDelegate(this), | ||
removegroup: manageMenuItems.createDelegate(this) | ||
}); | ||
}, | ||
scope: this | ||
}); | ||
|
||
var menu = new Ext.menu.Menu({}); | ||
window.menu = menu; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be removed. |
||
var newFeatureBtn = new Ext.SplitButton({ | ||
text: this.createBtnText, | ||
enableToggle: true, | ||
|
@@ -235,7 +297,7 @@ cgxp.plugins.Editing = Ext.extend(gxp.plugins.Tool, { | |
this.editingLayer, Handler, { | ||
featureAdded: OpenLayers.Function.bind(function(f) { | ||
control.deactivate(); | ||
newFeatureBtn.toggle(false); | ||
this.newFeatureBtn.toggle(false); | ||
f.attributes.__layer_id__ = | ||
layer.attributes.layer_id; | ||
var store = this.getAttributesStore( | ||
|
@@ -256,6 +318,7 @@ cgxp.plugins.Editing = Ext.extend(gxp.plugins.Tool, { | |
text: layer.attributes.text, | ||
group: 'create_layer', | ||
enableToggle: true, | ||
layerId: layer.attributes.layer_id.toString(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is |
||
control: control, | ||
listeners: { | ||
checkchange: function(item, checked) { | ||
|
@@ -318,6 +381,9 @@ cgxp.plugins.Editing = Ext.extend(gxp.plugins.Tool, { | |
for (var i in self.getEditableLayers()) { | ||
layerIds.push(i); | ||
} | ||
if (layerIds.length === 0) { | ||
return; | ||
} | ||
options.url = baseURL + layerIds.join(','); | ||
// ensure that there's no unsaved modification before sending | ||
// the request. | ||
|
@@ -387,12 +453,27 @@ cgxp.plugins.Editing = Ext.extend(gxp.plugins.Tool, { | |
}); | ||
callback.call(this, store, geometryType); | ||
}, | ||
beforeload: function(store) { | ||
this.pendingRequests.push(store); | ||
}, | ||
scope: this | ||
}); | ||
store.load(); | ||
return store; | ||
}, | ||
|
||
/** private: method[abortPendingRequests] | ||
* This method aborts xsd request if required. | ||
*/ | ||
abortPendingRequests: function() { | ||
Ext.each(this.pendingRequests, function(store) { | ||
// destroying the store will destroy the corresponding proxy, and | ||
// the corresponding active requests | ||
store.destroy(); | ||
}); | ||
this.pendingRequests = []; | ||
}, | ||
|
||
/** private: method[showAttributesEditingWindow] | ||
*/ | ||
showAttributesEditingWindow: function(store) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
toString
isn't necessary.