import React from 'react'; import {observer, inject} from 'mobx-react'; import { Card, FlatButton, Divider, RaisedButton, Toolbar, MenuItem, ToolbarGroup, IconButton, ToolbarTitle, Dialog, Toggle } from 'material-ui'; import DeleteIcon from 'material-ui/svg-icons/action/delete'; import {Icon, Input, Select, message, Button as ButtonAntd, Affix,TreeSelect} from 'antd' import {LINKS} from "../../../routes"; const Option = Select.Option; const TreeNode = TreeSelect.TreeNode; import {lowerCase,debounce} from 'lodash'; // Require Editor JS files. // import 'froala-editor/js/froala_editor.pkgd.min.js'; // Require Editor CSS files. // import 'froala-editor/css/froala_style.min.css'; // import 'froala-editor/css/froala_editor.pkgd.min.css'; const $ = require("jquery"); // require("froala-editor/js/froala_editor.pkgd.min.js")($); window.$ = window.jQuery = $; // require("froala-editor/js/froala_editor.pkgd.min.js")($); // require("froala-editor/js/plugins/code_view.min.js")($); // window.$ = window.jQuery = $; import 'froala-editor/css/froala_style.min.css'; import 'froala-editor/css/froala_editor.pkgd.min.css'; // import 'froala-editor/css/plugins/code_view.min.css'; // Require Font Awesome. import 'font-awesome/css/font-awesome.css'; import FroalaEditor from 'react-froala-wysiwyg'; @inject('appstate') @observer export default class Form extends React.Component { constructor(props) { super(props); this.props = props; this.rewardStore = props.appstate.reward; this.state = { openedDialogEmpty:false, featured_media_exist: false, text: '', openedDialog: false, openDeleteDialog : false, saveButton: true, value: 1, isFree : false, searchText: '', slideIndex: 0, openedDialogBack: false, reward_type: "Choose Reward Type", expanded: false, previewVisible: false, previewImage: '', fileList: [], fileLength: 0, fileMainExist: false, visible:false, formData: { //tags: ['a571f41f-c9d2-4fe1-9638-320c589cffe3'], tags: [], additional_data : { items: [] } }, disabled_price : false, mode: 'create', html : "", config: { placeholderText: 'Edit Your Content Here!', charCounterCount: true, toolbarStickyOffset: 73, toolbarButtons: ['insertLink', 'bold', 'italic', 'underline', 'fontFamily', 'fontSize', 'color', 'align', 'formatOL', 'formatUL', 'embedly', '|', 'insertImage', 'insertVideo', 'insertFile', '|', 'help'], quickInsertButtons: ['embedly','hr', 'image', 'video'], codeBeautifierOptions: { end_with_newline: true, indent_inner_html: true, extra_liners: "['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'blockquote', 'pre', 'ul', 'ol', 'table', 'dl']", brace_style: 'expand', indent_char: ' ', indent_size: 4, wrap_line_length: 0 }, heightMin: '50vh' } }; this.defaultState = Object.assign({}, this.state); this.http = props.appstate.http; this.authStore = props.appstate.auth; this.globalUI = props.appstate.globalUI; this.categoryStore = props.appstate.category; this.itemStore = props.appstate.item; this.myStoreItem = props.appstate.myStoreItem; this.contentManagerStore = props.appstate.contentManager; this.editor = null; this.userData = props.appstate.userData; } async componentDidMount() { console.log(this.props.match.params.id,'ini id params') window.scrollTo(0, 0); this.contentManagerStore.getTags(); // this.contentManagerStore.getTypes(); this.contentManagerStore.clearItems(); if(this.props.match.params.id){ this.contentManagerStore.getDetail(this.props.match.params.id).then(res => { console.log(this.contentManagerStore.selected.title,this.contentManagerStore.selected.content,'res detail') let newArray = this.contentManagerStore.selected.additional_data.items.map(it => it); let newTagsArray =this.contentManagerStore.selected.tags.map(it => it); console.log(newTagsArray[0].tag_id,'newTagsArray'); if(newArray.length>0){ this.contentManagerStore.loadItems(newArray); } let data; data = { title:this.contentManagerStore.selected.title, type:this.contentManagerStore.selected.type, content:this.contentManagerStore.selected.content, tags:[newTagsArray[0].tag_id], additional_data:{ items: newArray } } this.setState({ formData : data, text : this.contentManagerStore.selected.content, }); if(newTagsArray[0].tag_id == 'b0819754-fb35-4e52-be67-eb76ca80c5a4'){ this.setState({ visible:true }) } // console.log("new formmm",this.state.formData,this.state.text) }); // console.log("new formmm items",this.state.formData.additional_data.items) } // $('.fr-wrapper').children[0].style.display = 'none'; // setTimeout(() => { // $('.fr-wrapper').children[0].style.display = 'none'; // }, 1000); } handleModelChange = (model) => { this.setState({ text: model }); }; handleCancel = () => this.setState({ previewVisible: false }); handleOpen = () => { console.log(this.state.html,'heree'); this.setState({openedDialog: true}); }; handleClose = () => { this.setState({openedDialog: false}); }; goToClassDetail(){ this.props.history.push(`${LINKS.CLASSES}/${this.props.match.params.id}`); } postData = () => { console.log("post!!!", this.state.formData); if(!this.state.formData.title || this.state.formData.title=="" || !this.state.text || this.state.text==""){ message.success('Title and content cannot be empty!'); console.log('inikosongdatanya') this.setState({openedDialog: false}); this.setState({openedDialogEmpty:true}); } else{ this.setState({openedDialog: false}); this.globalUI.openLoading(); const data=Object.assign({},this.state.formData); data.content=this.state.text; // if(typeof data.price === "string"){ // data.price = new DC(data.price.replace(/\,/g,"")).toFixed(); // } console.log("data",data); this.contentManagerStore.post(data) .then(res => { this.globalUI.hideDialogLoading(); this.globalUI.openSnackbar("Success Added New Content"); this.props.history.push(LINKS.CONTENT); }) .catch(err => { this.globalUI.openSnackbar(err.message); console.error(err, 'ini errornya'); }); } }; deleteData = () => { }; searchItem = ()=>{ console.log('do search'); }; editData = () => { console.log("Edit!!!", this.state.formData); if(!this.state.formData.title || this.state.formData.title=="" || !this.state.text || this.state.text==""){ console.log('inikosongdatanya') this.setState({openedDialog: false}); this.setState({openedDialogEmpty:true}); } else{ this.globalUI.openLoading(); this.setState({openedDialog: false}); const data=Object.assign({},this.state.formData); data.content=this.state.text; console.log("data",data); this.contentManagerStore.put(this.props.match.params.id,data) .then(res => { this.globalUI.hideDialogLoading(); this.globalUI.openSnackbar("Success Edit Content"); this.props.history.push(LINKS.CONTENT_MANAGER); }) .catch(err => { this.globalUI.openSnackbar(err.message); console.error(err, 'ini errornya'); }); } }; handleBackClose = () => { this.setState({openedDialogBack: false}) }; handleEmptyClose = () => { this.setState({openedDialogEmpty: false}) }; handleEmptyOpen = () => { this.setState({openedDialogEmpty: true}) }; handleBackOpen = () => { this.setState({openedDialogBack: true}); }; inputContent = (evt)=>{ // console.log(evt.target.value); this.setState({ html : evt.target.value }) } handleChange = ({ fileList }) => {this.setState({ fileList }); console.log(fileList, 'remove')}; uploaderHandler({file, onProgress}) { console.log(file, 'upload'); console.log("fileLength", this.state.fileLength); console.log("fileMainExist", this.state.fileMainExist); this.http.upload(file) .then(res => { const {fileList} = this.state; let newFileList = fileList.filter((obj)=>{ if(!obj.lastModified){ return true; } }) if(!this.state.fileMainExist){ newFileList.push({ uid: newFileList.length, name: file.name, status: 'done', url: this.http.appendImagePath(res.path), path: res.path, type: 'main' }); } else{ newFileList.push({ uid: newFileList.length, name: file.name, status: 'done', url: this.http.appendImagePath(res.path), path: res.path, type: 'gallery' }); } console.log("update fileList",fileList); console.log("new fileList",newFileList); this.setState({fileList : newFileList}); }) } handleWarningDialog = (bool)=>{ this.setState({ openDeleteDialog : bool }) } setFree = (bool) =>{ this.setState({ formData : { ...this.state.formData, is_free: bool, price : 0 }, disabled_price : bool }) } render() { //add mock data for tag option, change this if api for tag is complete const children = []; for (let i = 10; i < 36; i++) { children.push(); } const { previewVisible, previewImage, fileList } = this.state; const uploadButton = (
Title Content
{wrapperText("title")( )}Tag
{wrapperSelect("tags")( )}Types
*/} {/*{wrapperSelectType("type")(*/} {/**/} {/*)}*/} {/*Items
{/*{wrapperSelectANT("items")()}*/} {wrapperTree("items")(