1
0
mirror of https://github.com/ascribe/onion.git synced 2024-07-01 06:02:12 +02:00

Merged in AD-44-in-piece-detail-support-public-not (pull request #2)

CSRF and acl edit tweaks
This commit is contained in:
diminator 2015-06-16 14:18:15 +02:00
commit 8846a11e00
5 changed files with 45 additions and 7 deletions

View File

@ -27,16 +27,19 @@ let PieceExtraDataForm = React.createClass({
}, },
renderForm() { renderForm() {
let defaultValue = this.props.editions[0].extra_data[this.props.name] || '';
if (defaultValue.length === 0 && ~this.props.editable){
return null;
}
return ( return (
<form role="form" key={this.props.name}> <form role="form" key={this.props.name}>
<h5>{this.props.title}</h5> <h5>{this.props.title}</h5>
<InputTextAreaToggable <InputTextAreaToggable
ref={this.props.name} ref={this.props.name}
className="form-control" className="form-control"
defaultValue={this.props.editions[0].extra_data[this.props.name]} defaultValue={defaultValue}
rows={3} rows={3}
editable={true} editable={this.props.editable}
required="" required=""
onSubmit={this.submit} onSubmit={this.submit}
/> />

View File

@ -2,6 +2,9 @@
import React from 'react'; import React from 'react';
import UserActions from '../actions/user_actions';
import UserStore from '../stores/user_store';
import MediaPlayer from './ascribe_media/media_player'; import MediaPlayer from './ascribe_media/media_player';
import CollapsibleMixin from 'react-bootstrap/lib/CollapsibleMixin'; import CollapsibleMixin from 'react-bootstrap/lib/CollapsibleMixin';
@ -31,6 +34,23 @@ let Edition = React.createClass({
loadEdition: React.PropTypes.func 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() { render() {
let thumbnail = this.props.edition.thumbnail; let thumbnail = this.props.edition.thumbnail;
let mimetype = this.props.edition.digital_work.mime; let mimetype = this.props.edition.digital_work.mime;
@ -71,8 +91,10 @@ let Edition = React.createClass({
edition={this.props.edition} /> edition={this.props.edition} />
<CollapsibleEditionDetails <CollapsibleEditionDetails
title="Personal Note" title="Personal Note"
show={this.state.currentUser && true || false}
iconName="pencil"> iconName="pencil">
<EditionPersonalNote <EditionPersonalNote
currentUser={this.state.currentUser}
handleSuccess={this.props.loadEdition} handleSuccess={this.props.loadEdition}
edition={this.props.edition}/> edition={this.props.edition}/>
</CollapsibleEditionDetails> </CollapsibleEditionDetails>
@ -160,7 +182,7 @@ let EditionSummary = React.createClass({
status = <EditionDetailProperty label="STATUS" value={ this.props.edition.status.join().replace(/_/, ' ') } />; status = <EditionDetailProperty label="STATUS" value={ this.props.edition.status.join().replace(/_/, ' ') } />;
} }
let actions = null; let actions = null;
if (this.props.edition.request_action){ if (this.props.edition.request_action && this.props.edition.request_action.length > 0){
actions = ( actions = (
<RequestActionForm <RequestActionForm
editions={ [this.props.edition] } editions={ [this.props.edition] }
@ -372,6 +394,7 @@ let EditionFurtherDetails = React.createClass({
}, },
render() { render() {
let editable = this.props.edition.acl.indexOf('edit') > -1;
return ( return (
<Row> <Row>
<Col md={12} className="ascribe-edition-personal-note"> <Col md={12} className="ascribe-edition-personal-note">
@ -379,16 +402,19 @@ let EditionFurtherDetails = React.createClass({
name='artist_contact_info' name='artist_contact_info'
title='Artist Contact Info' title='Artist Contact Info'
handleSuccess={this.showNotification} handleSuccess={this.showNotification}
editable={editable}
editions={[this.props.edition]} /> editions={[this.props.edition]} />
<PieceExtraDataForm <PieceExtraDataForm
name='display_instructions' name='display_instructions'
title='Display Instructions' title='Display Instructions'
handleSuccess={this.showNotification} handleSuccess={this.showNotification}
editable={editable}
editions={[this.props.edition]} /> editions={[this.props.edition]} />
<PieceExtraDataForm <PieceExtraDataForm
name='technology_details' name='technology_details'
title='Technology Details' title='Technology Details'
handleSuccess={this.showNotification} handleSuccess={this.showNotification}
editable={editable}
editions={[this.props.edition]} /> editions={[this.props.edition]} />
</Col> </Col>
</Row> </Row>

View File

@ -24,6 +24,7 @@ import { getLangText } from '../utils/lang_utils';
let Link = Router.Link; let Link = Router.Link;
let Header = React.createClass({ let Header = React.createClass({
mixins: [Router.Navigation],
getInitialState() { getInitialState() {
return UserStore.getState(); return UserStore.getState();
@ -43,8 +44,7 @@ let Header = React.createClass({
}, },
refreshData(){ refreshData(){
UserActions.fetchCurrentUser(); location.reload();
PieceListActions.fetchPieceList(1, 10);
}, },
render() { render() {
let account = null; let account = null;

View File

@ -62,3 +62,11 @@ export function status(response) {
} }
throw new Error(response.json()); 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();
}
}

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
import { argsToQueryParams } from '../utils/fetch_api_utils'; import { argsToQueryParams, getCookie } from '../utils/fetch_api_utils';
class UrlMapError extends Error {} class UrlMapError extends Error {}
@ -76,6 +76,7 @@ class Requests {
request(verb, url, options) { request(verb, url, options) {
options = options || {}; options = options || {};
let merged = this._merge(this.httpOptions, options); let merged = this._merge(this.httpOptions, options);
this.httpOptions.headers['X-CSRFToken'] = getCookie('csrftoken');
merged.method = verb; merged.method = verb;
return fetch(url, merged) return fetch(url, merged)
.then(this.unpackResponse) .then(this.unpackResponse)