Commit 1800ba88 by hfpp2012 yinsigan

router hash history push

1 parent 93d82e96
import React from 'react'
import Move from '../libs/move'
import EventEmitter from '../libs/eventEmitter'
import { hashHistory } from 'react-router'
export default class Element extends React.Component {
static get getDefaultProps() {
......@@ -241,7 +240,7 @@ export default class Element extends React.Component {
const childrenObjectType = this.props.childrenObjectType
const url = `/regional_design/${this.props.id}?object=${childrenObjectType}`
if (childrenObjectType != 'drug_brandreth_grid') {
hashHistory.push(url)
this.props.hashHistory.push(url)
}
}
......
......@@ -10,9 +10,11 @@ export default class ModalRepoForm extends React.Component {
this.state = {
showModal: false, name: ''
};
this.init_state = this.state;
this.close = this.close.bind(this);
this.open = this.open.bind(this);
this.handleChange = this.handleChange.bind(this);
this.save = this.save.bind(this);
}
close() {
......@@ -36,7 +38,7 @@ export default class ModalRepoForm extends React.Component {
e.preventDefault()
$.post('/regional_design/repos.json', { repo: this.state }, function(data) {
this.props.handleNewRepo(data)
this.setState(this.getInitialState())
this.setState(this.init_state)
EventEmitter.dispatch('alert', '操作成功')
}.bind(this), 'JSON')
}
......
......@@ -11,6 +11,7 @@ export default class RegionalDesign extends React.Component {
this.state = {
data: null, loading: true, error: null, object_name: '', object_type: '', children_object_type: ''
};
this.init_state = this.state;
this.addElement = this.addElement.bind(this);
this.updateElement = this.updateElement.bind(this);
this.addElement = this.addElement.bind(this);
......@@ -34,11 +35,12 @@ export default class RegionalDesign extends React.Component {
children_param_name: 'drug_brandreth_grid'
}
}
return config[props.location.query.object][key]
const search_str = props.location.search
return config[search_str.substring(search_str.indexOf("=") + 1)][key]
}
componentDidMount() {
const url = this.getConfig(this.props, 'object_url') + '/' + this.props.params.id + '.json'
const url = this.getConfig(this.props, 'object_url') + '/' + this.props.match.params.id + '.json'
this.getJSON(url)
EventEmitter.subscribe('moveDropZone', function(element){
......@@ -59,7 +61,7 @@ export default class RegionalDesign extends React.Component {
name: element.name,
pos_x: element.initialPos.x,
pos_y: element.initialPos.y,
parent_id: this.props.params.id
parent_id: this.props.match.params.id
}
const url = this.getConfig(this.props, 'children_object_url') + '.json'
......@@ -95,8 +97,8 @@ export default class RegionalDesign extends React.Component {
}
componentWillReceiveProps(nextProps) {
this.setState(this.getInitialState)
const url = this.getConfig(nextProps, 'object_url') + '/' + nextProps.params.id + '.json'
this.setState(this.init_state)
const url = this.getConfig(nextProps, 'object_url') + '/' + nextProps.match.params.id + '.json'
this.getJSON(url)
}
......@@ -118,7 +120,7 @@ export default class RegionalDesign extends React.Component {
else {
const data = this.state.data.map(function(element) {
return (
<Element childrenObjectType={ this.state.children_object_type } isDropZoneChild={ true } key={ element.id } id={ element.id } name={ element.name } initialPos={ element.initialPos } />
<Element hashHistory={ this.props.history } childrenObjectType={ this.state.children_object_type } isDropZoneChild={ true } key={ element.id } id={ element.id } name={ element.name } initialPos={ element.initialPos } />
)
}.bind(this))
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!