/* jshint ignore:start */ import React from 'react'; import Breadcrumbs from './breadcrumbs'; import { isModerationVisible, ModerationControls } from '../moderation/thread'; import Stats from './stats'; import Form from 'misago/components/form'; import { getTitleValidators } from 'misago/components/posting/utils/validators'; import ajax from 'misago/services/ajax'; import snackbar from 'misago/services/snackbar'; import store from 'misago/services/store'; import * as thread from 'misago/reducers/thread'; export default class extends Form { constructor(props) { super(props); this.state = { isEditing: false, isLoading: false, title: props.thread.title, validators: { title: getTitleValidators() }, errors: {} }; } onChange = (event) => { this.changeValue('title', event.target.value); }; onEdit = () => { this.setState({ isEditing: true }); }; onCancel = () => { this.setState({ title: this.props.thread.title, isEditing: false }); }; clean() { if (!this.state.title.trim().length) { snackbar.error(gettext("You have to enter thread title.")); return false; } const errors = this.validate(); if (errors.title) { snackbar.error(errors.title[0]); return false; } return true; } send() { return ajax.patch(this.props.thread.api.index, [ {op: 'replace', path: 'title', value: this.state.title} ]); } handleSuccess(data) { store.dispatch(thread.update(data)); this.setState({ 'isEditing': false }); } handleError(rejection) { if (rejection.status === 400) { snackbar.error(rejection.detail[0]); } else { snackbar.apiError(rejection); } } render() { const {thread, user} = this.props; const showModeration = !!user.id && isModerationVisible(thread); if (this.state.isEditing) { return (
); } else if (user.id && thread.acl.can_edit) { return (

{thread.title}

{showModeration && ( )}
); } else if (showModeration) { return (

{thread.title}

); } return (

{thread.title}

); } } export function Moderation(props) { return (
); }