From 8d73e4a77bab7a20958adc9b3b7f55a109db6da7 Mon Sep 17 00:00:00 2001 From: ddejongh Date: Tue, 16 Jun 2015 14:01:53 +0200 Subject: [PATCH] edit acl editionnote --- .../ascribe_forms/form_piece_extradata.js | 9 ++++-- js/components/edition.js | 28 ++++++++++++++++++- js/components/header.js | 4 +-- js/utils/fetch.js | 4 ++- js/utils/fetch_api_utils.js | 8 ++++++ 5 files changed, 46 insertions(+), 7 deletions(-) diff --git a/js/components/ascribe_forms/form_piece_extradata.js b/js/components/ascribe_forms/form_piece_extradata.js index 41828120..fc0dcc7d 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 9130b675..65373202 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.js b/js/utils/fetch.js index 74477281..3cb09f5b 100644 --- a/js/utils/fetch.js +++ b/js/utils/fetch.js @@ -2,7 +2,7 @@ import { default as _fetch } from 'isomorphic-fetch'; -import { argsToQueryParams } from '../utils/fetch_api_utils'; +import { argsToQueryParams, getCookie } from '../utils/fetch_api_utils'; class UrlMapError extends Error {} @@ -78,6 +78,7 @@ class Fetch { 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) @@ -106,6 +107,7 @@ class Fetch { if (paramsCopy && paramsCopy.body) { body = JSON.stringify(paramsCopy.body); } + return this.request('post', newUrl, { body }); } 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