Skip to content

Commit

Permalink
issue planetfederal#216 - disable unneeded buttons in rule fieldset
Browse files Browse the repository at this point in the history
  • Loading branch information
justb4 committed Feb 6, 2014
1 parent c9caa74 commit edb3f7b
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 46 deletions.
38 changes: 6 additions & 32 deletions src/script/plugins/VectorStyleWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,29 +120,6 @@ gxp.plugins.VectorStyleWriter = Ext.extend(gxp.plugins.StyleWriter, {
var layerRecord = this.target.layerRecord;
var layer = layerRecord.getLayer();
var layerStyles = layer.styleMap;
var controls = layer.map.getControlsByClass("OpenLayers.Control.SelectFeature");

/* if (controls && controls.length > 0 && layerSelectStyle) {
var layerDefaultStyle = layerStyles.styles['default'].clone();
var layerSelectStyle = layerStyles.styles['select'];
var selectStyleHash = OpenLayers.Util.extend(layerDefaultStyle.defaultStyle, layerSelectStyle.defaultStyle);
var selectStyle = selectStyleHash; // new OpenLayers.Style(selectStyleHash);
for (var index = 0; index < controls.length; index++) {
var control = controls[index];
if (control.layers && control.layers.length > 0) {
for (var l = 0; l < control.layers.length; l++) {
if (control.layers[l].id == layer.id) {
control.selectStyle = selectStyle;
break;
}
}
} else if (control.layer && control.layer.id == layer.id) {
control.selectStyle = selectStyle;
break;
}
}
} */
var styleRec = this.target.selectedStyle;
if (styleRec) {
// var oldStyleName = styleRec.get("userStyle").name;
Expand All @@ -152,8 +129,7 @@ gxp.plugins.VectorStyleWriter = Ext.extend(gxp.plugins.StyleWriter, {

// GXP Style Editing needs symbolizers array in Rule object
// while Vector/Style drawing needs symbolizer hash...
var textStyle = {};
var symbolizer;
var textStyle = {}, symbolizer;
if (newStyle.rules) {
for (var i = 0, len = newStyle.rules.length; i < len; i++) {
var rule = newStyle.rules[i];
Expand All @@ -180,14 +156,11 @@ gxp.plugins.VectorStyleWriter = Ext.extend(gxp.plugins.StyleWriter, {

newStyle.propertyStyles = newStyle.findPropertyStyles();
layerStyles.styles[styleName] = newStyle;
// newStyle.defaultStyle = undefined;
var feature;
// if (layer.customStyling === true && (!layer.selectedFeatures || layer.selectedFeatures.length == 0)) {
// return;
// }

// Assign Style to all or, if features selected, to individual Layer features
var features = (layer.selectedFeatures && layer.selectedFeatures.length > 0) ? layer.selectedFeatures : layer.features;
layer.eraseFeatures(features);
var feature;
for (var f = 0; f < features.length; f++) {
feature = features[f];

Expand All @@ -212,9 +185,10 @@ gxp.plugins.VectorStyleWriter = Ext.extend(gxp.plugins.StyleWriter, {
feature.style = newStyle.createSymbolizer(feature);
layer.drawFeature(feature);
} else {
layer.drawFeature(feature, newStyle.createSymbolizer(feature));
// Redraw feature with Layer Style
feature.style = null;
layer.drawFeature(feature);
}

}

// Emit this proprietary event, for example to have VectorLegend update itself
Expand Down
34 changes: 21 additions & 13 deletions src/script/widgets/StylesDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -1067,21 +1067,10 @@ gxp.StylesDialog = Ext.extend(Ext.Container, {
enableDD: options.enableDD,
listeners: {
"ruleselected": function(cmp, rule) {
this.selectedRule = rule;
// enable the Remove, Edit and Duplicate buttons
var tbItems = this.items.get(3).items;
this.updateRuleRemoveButton();
tbItems.get(2).enable();
tbItems.get(3).enable();
// cmp.items.get(0).focus();
this.onRuleSelected(cmp, rule);
},
"ruleunselected": function(cmp, rule) {
this.selectedRule = null;
// disable the Remove, Edit and Duplicate buttons
var tbItems = this.items.get(3).items;
tbItems.get(1).disable();
tbItems.get(2).disable();
tbItems.get(3).disable();
this.onRuleUnselected(cmp, rule);
},
"rulemoved": function() {
this.markModified();
Expand All @@ -1108,6 +1097,25 @@ gxp.StylesDialog = Ext.extend(Ext.Container, {
gxp.util.md5(layerName + new Date() + Math.random()).substr(0, 8);
},

onRuleSelected: function(cmp, rule) {
this.selectedRule = rule;
// enable the Remove, Edit and Duplicate buttons
var tbItems = this.items.get(3).items;
this.updateRuleRemoveButton();
tbItems.get(2).enable();
tbItems.get(3).enable();
// cmp.items.get(0).focus();
},

onRuleUnselected: function(cmp, rule) {
this.selectedRule = null;
// disable the Remove, Edit and Duplicate buttons
var tbItems = this.items.get(3).items;
tbItems.get(1).disable();
tbItems.get(2).disable();
tbItems.get(3).disable();
},

/** private: method[showDlg]
* :arg dlg:
*
Expand Down
44 changes: 43 additions & 1 deletion src/script/widgets/VectorStylesDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,40 @@ gxp.VectorStylesDialog = Ext.extend(gxp.StylesDialog, {
},


/** private: method[addRulesFieldSet]
* :return: ``Ext.form.FieldSet``
*
* Creates the rules fieldSet and adds it to this container.
*/
addRulesFieldSet: function() {
var rulesFieldSet = gxp.VectorStylesDialog.superclass.addRulesFieldSet.apply(this, arguments);
// Disable Add for now: it does not work well.
this.items.get(3).get(0).disable();
return rulesFieldSet;
},

/** private: method[disableConditional]
*
* Disable item, like in Rule toolbar when customStyling is enabled.
*/
disableConditional: function(item) {
var layer = this.layerRecord.getLayer();
if (item && layer.customStyling) {
item.disable();
}
},

onRuleSelected: function(cmp, rule) {
gxp.VectorStylesDialog.superclass.onRuleSelected.call(this, cmp, rule);
// enable the Remove, Edit and Duplicate buttons
var tbItems = this.items.get(3).items;
// Edit button
// tbItems.get(2).enable();
// Duplicate button
this.disableConditional(tbItems.get(3));
// cmp.items.get(0).focus();
},

/** private: method[editRule]
*/
editRule: function () {
Expand Down Expand Up @@ -465,14 +499,22 @@ gxp.VectorStylesDialog = Ext.extend(gxp.StylesDialog, {
});
},

/** private: method[updateRuleRemoveButton]
* Enable/disable the "Remove" button to make sure that we don't delete
* the last rule.
*/
updateRuleRemoveButton: function() {
gxp.VectorStylesDialog.superclass.updateRuleRemoveButton.apply(this, arguments);
this.disableConditional(this.items.get(3).items.get(1));
},

/** private: method[updateStyleRemoveButton]
* We cannot remove styles for Vector styles so always disable remove.
*/
updateStyleRemoveButton: function () {
this.items.get(1).items.get(1).setDisabled(true);
}


});

/** api: function[createGeoServerStylerConfig]
Expand Down

0 comments on commit edb3f7b

Please sign in to comment.