diff --git a/app/src/frontend/app.js b/app/src/frontend/app.js index 857ef73f..f23ffc3f 100644 --- a/app/src/frontend/app.js +++ b/app/src/frontend/app.js @@ -118,16 +118,22 @@ class App extends React.Component { }); } + /** + * Colour building + * + * Used in multi-edit mode to colour buildings on map click + * + * Pulls data from URL to form update + * + * @param {object} building + */ colourBuilding(building) { const cat = parseCategoryURL(window.location.pathname); const q = parse(window.location.search); - let data; + const data = (cat === 'like')? {like: true}: JSON.parse(q.data); if (cat === 'like'){ - data = {like: true} this.likeBuilding(building.building_id) } else { - data = {} - data[q.k] = q.v; this.updateBuilding(building.building_id, data) } } diff --git a/app/src/frontend/building-edit.js b/app/src/frontend/building-edit.js index a7925cba..8f61a79e 100644 --- a/app/src/frontend/building-edit.js +++ b/app/src/frontend/building-edit.js @@ -50,18 +50,52 @@ BuildingEdit.propTypes = { class EditForm extends Component { constructor(props) { super(props); - this.state = {} + this.state = { + error: this.props.error || undefined, + like: this.props.like || undefined, + copying: false, + keys_to_copy: {} + } for (const field of props.fields) { this.state[field.slug] = props[field.slug] } - this.state.error = this.props.error || undefined; - this.state.like = this.props.like || undefined; this.handleChange = this.handleChange.bind(this); this.handleCheck = this.handleCheck.bind(this); this.handleLike = this.handleLike.bind(this); this.handleSubmit = this.handleSubmit.bind(this); this.handleUpdate = this.handleUpdate.bind(this); + + this.toggleCopying = this.toggleCopying.bind(this); + this.toggleCopyAttribute = this.toggleCopyAttribute.bind(this); + } + + /** + * Enter or exit "copying" state - allow user to select attributes to copy + */ + toggleCopying() { + this.setState({ + copying: !this.state.copying + }) + } + + /** + * Keep track of data to copy (accumulate while in "copying" state) + * + * Note that we track keys only - values are already held in state + * + * @param {string} key + */ + toggleCopyAttribute(key) { + const keys = this.state.keys_to_copy; + if(this.state.keys_to_copy[key]){ + delete keys[key]; + } else { + keys[key] = true; + } + this.setState({ + keys_to_copy: keys + }) } /** @@ -175,6 +209,12 @@ class EditForm extends Component { const cat = this.props.cat; const buildingLike = this.props.building_like; + const values_to_copy = {} + for (const key of Object.keys(this.state.keys_to_copy)) { + values_to_copy[key] = this.state[key] + } + const data_string = JSON.stringify(values_to_copy); + return (
@@ -187,14 +227,38 @@ class EditForm extends Component {