diff --git a/public/react/src/modules/courses/graduation/topics/GraduateTopicNew.js b/public/react/src/modules/courses/graduation/topics/GraduateTopicNew.js index 8eeae8095..02fc5018e 100644 --- a/public/react/src/modules/courses/graduation/topics/GraduateTopicNew.js +++ b/public/react/src/modules/courses/graduation/topics/GraduateTopicNew.js @@ -66,27 +66,33 @@ class GraduateTopicNew extends Component{ //编辑,信息显示 getEditInfo=()=>{ const cid = this.props.match.params.coursesId - let topicId=this.props.match.params.topicId - let url=`/courses/${cid}/graduation_topics/${topicId}/edit.json`; - axios.get((url)).then((result)=>{ - if(result){ - this.setState({ - left_banner_id:result.data.left_banner_id, - course_name:result.data.course_name, - left_banner_name:result.data.left_banner_name - }) - this.GraduateTopicNewFromRef.initValue(result); - - } - }).catch((error)=>{ - console.log(error); - }) + let topicId=this.props.match.params.topicId; + if(topicId){ + let url=`/courses/${cid}/graduation_topics/${topicId}/edit.json`; + axios.get((url)).then((result)=>{ + if(result){ + this.setState({ + left_banner_id:result.data.left_banner_id, + course_name:result.data.course_name, + left_banner_name:result.data.left_banner_name + }) + this.GraduateTopicNewFromRef.initValue(result); + + } + }).catch((error)=>{ + console.log(error); + }) + } } // 编辑保存 - editSave = (params,topicId) =>{ + editSave = (param,attachments,topicId) =>{ const cid = this.props.match.params.coursesId const editUrl = `/courses/${cid}/graduation_topics/${topicId}.json` + let params = { + graduation_topic:param, + attachment_ids:attachments + } axios.put(editUrl, params).then((response) => { if (response.status == 200) { const { id } = response.data; @@ -101,9 +107,13 @@ class GraduateTopicNew extends Component{ } // 新建提交 - newSubmit = (params,topicId) =>{ + newSubmit = (param,attachments,topicId) =>{ const cid = this.props.match.params.coursesId const url = `/courses/${cid}/graduation_topics.json` + let params = { + graduation_topic:param, + attachment_ids:attachments + } axios.post(url, params).then((response) => { if (response.data) { const { id } = response.data; @@ -116,6 +126,16 @@ class GraduateTopicNew extends Component{ console.log(error); }); } + // 取消编辑或者新建 + editCancel = () =>{ + const cid = this.props.match.params.coursesId; + let topicId=this.props.match.params.topicId; + if(topicId){ + this.props.history.push(`/courses/${cid}/graduation_topics/${topicId}/detail`); + }else{ + this.props.history.push(`/courses/${cid}/graduation_topics/${this.state.left_banner_id}`); + } + } render() { @@ -127,9 +147,9 @@ class GraduateTopicNew extends Component{ const { current_user } = this.props let{ topicId,coursesId }=this.props.match.params const common={ - handleSubmit:this.handleSubmit, editSave:this.editSave, - newSubmit:this.newSubmit + newSubmit:this.newSubmit, + editCancel:this.editCancel } return(