|
|
|
@ -15,6 +15,7 @@ import Upload from 'rc-upload';
|
|
|
|
|
import axios from 'axios'
|
|
|
|
|
|
|
|
|
|
import 'antd/lib/select/style/index.css'
|
|
|
|
|
import TPMMDEditor from '../tpm/challengesnew/TPMMDEditor'
|
|
|
|
|
|
|
|
|
|
import { getUrl } from 'educoder'
|
|
|
|
|
const Option = Select.Option;
|
|
|
|
@ -130,6 +131,7 @@ const languageSeparator = '/'
|
|
|
|
|
class MemoNew extends Component {
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props)
|
|
|
|
|
this.mdRef = React.createRef();
|
|
|
|
|
|
|
|
|
|
// https://testbdweb.trustie.net/uploads.js?attachment_id=1&filename=jqui.js
|
|
|
|
|
// https://ant.design/components/upload-cn/
|
|
|
|
@ -179,7 +181,7 @@ class MemoNew extends Component {
|
|
|
|
|
}
|
|
|
|
|
let mdVal;
|
|
|
|
|
try {
|
|
|
|
|
mdVal = this.taskpass_editormd.getValue()
|
|
|
|
|
mdVal = this.mdRef.current.getValue()
|
|
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
showSnackbar('编辑器还未加载完毕,请稍后')
|
|
|
|
@ -205,6 +207,7 @@ class MemoNew extends Component {
|
|
|
|
|
// collect attachments
|
|
|
|
|
const $ = window.$;
|
|
|
|
|
const attachmentsMap = {};
|
|
|
|
|
const attachmentIds = []
|
|
|
|
|
$('#attachments_fields .attachment').each(( index, item ) => {
|
|
|
|
|
const filename = $(item).find('.upload_filename').val();
|
|
|
|
|
// $($('#attachments_fields .attachment')[0]).find('input:nth-child(6)').val()
|
|
|
|
@ -215,13 +218,14 @@ class MemoNew extends Component {
|
|
|
|
|
token,
|
|
|
|
|
attachment_id
|
|
|
|
|
}
|
|
|
|
|
attachmentIds.push(attachment_id)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (currentMemoId) {
|
|
|
|
|
this.updateMemo(attachmentsMap)
|
|
|
|
|
this.updateMemo(attachmentIds)
|
|
|
|
|
} else {
|
|
|
|
|
this.newMemo(attachmentsMap)
|
|
|
|
|
this.newMemo(attachmentIds)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
onCancel() {
|
|
|
|
@ -235,20 +239,20 @@ class MemoNew extends Component {
|
|
|
|
|
}
|
|
|
|
|
updateMemo(attachmentsMap) {
|
|
|
|
|
const { memoSubject, memoRepertoire, memoLanguage, memoType, currentMemoId, content } = this.state;
|
|
|
|
|
const mdVal = this.taskpass_editormd.getValue()
|
|
|
|
|
const mdVal = this.mdRef.current.getValue()
|
|
|
|
|
console.log('isContentEdit: ', mdVal === content);
|
|
|
|
|
const newMemoUrl = `/api/v1/memos/${currentMemoId}/update`
|
|
|
|
|
axios.post(newMemoUrl, {
|
|
|
|
|
const newMemoUrl = `/memos/${currentMemoId}.json`
|
|
|
|
|
axios.put(newMemoUrl, {
|
|
|
|
|
content_changed: this.contentChanged,
|
|
|
|
|
tags: memoLanguage,
|
|
|
|
|
memo:{
|
|
|
|
|
// memo:{
|
|
|
|
|
subject: memoSubject ,
|
|
|
|
|
content: mdVal,
|
|
|
|
|
forum_id: memoType,
|
|
|
|
|
repertoire_name: memoRepertoire,
|
|
|
|
|
// language: memoLanguage.join(languageSeparator),
|
|
|
|
|
//
|
|
|
|
|
},
|
|
|
|
|
// },
|
|
|
|
|
attachments: attachmentsMap
|
|
|
|
|
}, {
|
|
|
|
|
// withCredentials: true,
|
|
|
|
@ -267,18 +271,18 @@ class MemoNew extends Component {
|
|
|
|
|
}
|
|
|
|
|
newMemo(attachmentsMap) {
|
|
|
|
|
const { memoSubject, memoRepertoire, memoLanguage, memoType } = this.state;
|
|
|
|
|
const mdVal = this.taskpass_editormd.getValue()
|
|
|
|
|
const mdVal = this.mdRef.current.getValue()
|
|
|
|
|
|
|
|
|
|
const newMemoUrl = `/api/v1/memos/create`
|
|
|
|
|
const newMemoUrl = `/memos.json`
|
|
|
|
|
axios.post(newMemoUrl, {
|
|
|
|
|
tags: memoLanguage,
|
|
|
|
|
memo:{
|
|
|
|
|
// memo:{
|
|
|
|
|
subject: memoSubject ,
|
|
|
|
|
content: mdVal,
|
|
|
|
|
forum_id: memoType,
|
|
|
|
|
repertoire_name: memoRepertoire,
|
|
|
|
|
// repertoire_name: memoRepertoire,
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
// },
|
|
|
|
|
attachments: attachmentsMap
|
|
|
|
|
}, {
|
|
|
|
|
// withCredentials: true,
|
|
|
|
@ -296,7 +300,7 @@ class MemoNew extends Component {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
componentDidMount() {
|
|
|
|
|
const newMemoUrl = `/api/v1/memos/new`
|
|
|
|
|
const newMemoUrl = `/memos/new.json`
|
|
|
|
|
axios.get(newMemoUrl,{
|
|
|
|
|
// withCredentials: true,
|
|
|
|
|
})
|
|
|
|
@ -336,7 +340,7 @@ class MemoNew extends Component {
|
|
|
|
|
const { match } = this.props
|
|
|
|
|
const memoId = match.params.memoId;
|
|
|
|
|
if (memoId) {
|
|
|
|
|
const memoUrl = `/api/v1/memos/${match.params.memoId}/edit`;
|
|
|
|
|
const memoUrl = `/memos/${match.params.memoId}/edit.json`;
|
|
|
|
|
axios.get(memoUrl,{
|
|
|
|
|
// withCredentials: true,
|
|
|
|
|
})
|
|
|
|
@ -344,10 +348,12 @@ class MemoNew extends Component {
|
|
|
|
|
const tag_list = response.data.tag_list
|
|
|
|
|
if (tag_list) {
|
|
|
|
|
// this.setState({...response.data})
|
|
|
|
|
const { content, forum_id, id, tag, repertoire_name, subject,
|
|
|
|
|
current_user, tag_list, attachments_url } = response.data;
|
|
|
|
|
const { content, forum_id, id, repertoire_name, subject,
|
|
|
|
|
current_user, tag_list, attachments_url, memo_tags } = response.data;
|
|
|
|
|
this.initMD(content);
|
|
|
|
|
// this.onRepertoiresChange(repertoire_name)
|
|
|
|
|
// tag -> memo_tags
|
|
|
|
|
const tag = memo_tags;
|
|
|
|
|
let memoLanguage = []
|
|
|
|
|
if (tag) {
|
|
|
|
|
memoLanguage = tag.map((item, index) => {
|
|
|
|
@ -355,7 +361,7 @@ class MemoNew extends Component {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
this.setState({
|
|
|
|
|
currentMemoId: id,
|
|
|
|
|
currentMemoId: memoId,
|
|
|
|
|
memoSubject: subject,
|
|
|
|
|
memoType: forum_id,
|
|
|
|
|
memoRepertoire: repertoire_name,
|
|
|
|
@ -377,7 +383,7 @@ class MemoNew extends Component {
|
|
|
|
|
window.$("html,body").animate({"scrollTop":0})
|
|
|
|
|
|
|
|
|
|
this.props.initForumState({
|
|
|
|
|
current_user,
|
|
|
|
|
// current_user,
|
|
|
|
|
tag_list
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
@ -394,6 +400,8 @@ class MemoNew extends Component {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
initMD(initValue) {
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
this.contentChanged = false;
|
|
|
|
|
const placeholder = "";
|
|
|
|
|
// amp;
|
|
|
|
@ -566,9 +574,12 @@ class MemoNew extends Component {
|
|
|
|
|
<div className="df">
|
|
|
|
|
<span className="mr30 color-orange pt10">*</span>
|
|
|
|
|
<div className="flex1 mr20">
|
|
|
|
|
<div className="flex1 break_word show_content_grey new_li" id="memoMD">
|
|
|
|
|
<TPMMDEditor ref={this.mdRef} placeholder={''} watch={false}
|
|
|
|
|
mdID={'memoMD'} initValue={this.state.content} className="memoMD">
|
|
|
|
|
</TPMMDEditor>
|
|
|
|
|
{/* <div className="flex1 break_word show_content_grey new_li" id="memoMD">
|
|
|
|
|
<textarea style={{'display':'none'}}></textarea>
|
|
|
|
|
</div>
|
|
|
|
|
</div> */}
|
|
|
|
|
<p id="e_tip_memoNew" className="edu-txt-right color-grey-cd font-12"></p>
|
|
|
|
|
<p id="e_tips_memoNew" className="edu-txt-right color-grey-cd font-12"></p>
|
|
|
|
|
</div>
|
|
|
|
|