diff --git a/js/components/ascribe_forms/form_piece_extradata.js b/js/components/ascribe_forms/form_piece_extradata.js index ef58b58a..8cb23813 100644 --- a/js/components/ascribe_forms/form_piece_extradata.js +++ b/js/components/ascribe_forms/form_piece_extradata.js @@ -27,16 +27,19 @@ let PieceExtraDataForm = React.createClass({ }, renderForm() { - + let defaultValue = this.props.editions[0].extra_data[this.props.name] || ''; + if (defaultValue.length === 0 && ~this.props.editable){ + return null; + } return (
{this.props.title}
diff --git a/js/components/edition.js b/js/components/edition.js index 7d6a66f8..d54a9964 100644 --- a/js/components/edition.js +++ b/js/components/edition.js @@ -2,6 +2,9 @@ import React from 'react'; +import UserActions from '../actions/user_actions'; +import UserStore from '../stores/user_store'; + import MediaPlayer from './ascribe_media/media_player'; import CollapsibleMixin from 'react-bootstrap/lib/CollapsibleMixin'; @@ -31,6 +34,23 @@ let Edition = React.createClass({ loadEdition: React.PropTypes.func }, + getInitialState() { + return UserStore.getState(); + }, + + componentDidMount() { + UserStore.listen(this.onChange); + UserActions.fetchCurrentUser(); + }, + + componentWillUnmount() { + UserStore.unlisten(this.onChange); + }, + + onChange(state) { + this.setState(state); + }, + render() { let thumbnail = this.props.edition.thumbnail; let mimetype = this.props.edition.digital_work.mime; @@ -71,8 +91,10 @@ let Edition = React.createClass({ edition={this.props.edition} /> @@ -160,7 +182,7 @@ let EditionSummary = React.createClass({ status = ; } let actions = null; - if (this.props.edition.request_action){ + if (this.props.edition.request_action && this.props.edition.request_action.length > 0){ actions = ( -1; return ( @@ -379,16 +402,19 @@ let EditionFurtherDetails = React.createClass({ name='artist_contact_info' title='Artist Contact Info' handleSuccess={this.showNotification} + editable={editable} editions={[this.props.edition]} /> diff --git a/js/components/header.js b/js/components/header.js index aed6b846..77dd113a 100644 --- a/js/components/header.js +++ b/js/components/header.js @@ -24,6 +24,7 @@ import { getLangText } from '../utils/lang_utils'; let Link = Router.Link; let Header = React.createClass({ + mixins: [Router.Navigation], getInitialState() { return UserStore.getState(); @@ -43,8 +44,7 @@ let Header = React.createClass({ }, refreshData(){ - UserActions.fetchCurrentUser(); - PieceListActions.fetchPieceList(1, 10); + location.reload(); }, render() { let account = null; diff --git a/js/utils/fetch_api_utils.js b/js/utils/fetch_api_utils.js index 272e29f3..68f8fe6d 100644 --- a/js/utils/fetch_api_utils.js +++ b/js/utils/fetch_api_utils.js @@ -62,3 +62,11 @@ export function status(response) { } throw new Error(response.json()); } + +export function getCookie(name) { + let value = '; ' + document.cookie; + let parts = value.split('; ' + name + '='); + if (parts.length === 2) { + return parts.pop().split(';').shift(); + } +} \ No newline at end of file diff --git a/js/utils/requests.js b/js/utils/requests.js index 46f97fa9..1eee67ab 100644 --- a/js/utils/requests.js +++ b/js/utils/requests.js @@ -1,6 +1,6 @@ 'use strict'; -import { argsToQueryParams } from '../utils/fetch_api_utils'; +import { argsToQueryParams, getCookie } from '../utils/fetch_api_utils'; class UrlMapError extends Error {} @@ -76,6 +76,7 @@ class Requests { request(verb, url, options) { options = options || {}; let merged = this._merge(this.httpOptions, options); + this.httpOptions.headers['X-CSRFToken'] = getCookie('csrftoken'); merged.method = verb; return fetch(url, merged) .then(this.unpackResponse)