diff --git a/js/components/whitelabel/prize/constants/prize_api_urls.js b/js/components/whitelabel/prize/constants/prize_api_urls.js
index e493cffd..cb4e2e44 100644
--- a/js/components/whitelabel/prize/constants/prize_api_urls.js
+++ b/js/components/whitelabel/prize/constants/prize_api_urls.js
@@ -2,6 +2,7 @@
import AppPrizeConstants from './prize_application_constants';
+
function getPrizeApiUrls(subdomain) {
return {
'users_login': AppPrizeConstants.prizeApiEndpoint + subdomain + '/users/login/',
@@ -21,7 +22,6 @@ function getPrizeApiUrls(subdomain) {
'select_piece': AppPrizeConstants.prizeApiEndpoint + subdomain + '/ratings/${piece_id}/select/',
'notes': AppPrizeConstants.prizeApiEndpoint + subdomain + '/notes/',
'note': AppPrizeConstants.prizeApiEndpoint + subdomain + '/notes/${piece_id}/'
-
};
}
diff --git a/js/components/whitelabel/prize/portfolioreview/components/pr_forms/pr_register_piece_form.js b/js/components/whitelabel/prize/portfolioreview/components/pr_forms/pr_register_piece_form.js
index 0150d67e..e8063f8b 100644
--- a/js/components/whitelabel/prize/portfolioreview/components/pr_forms/pr_register_piece_form.js
+++ b/js/components/whitelabel/prize/portfolioreview/components/pr_forms/pr_register_piece_form.js
@@ -5,30 +5,107 @@ import React from 'react';
import Form from '../../../../../ascribe_forms/form';
import Property from '../../../../../ascribe_forms/property';
import InputTextAreaToggable from '../../../../../ascribe_forms/input_textarea_toggable';
-import InputCheckbox from '../../../../../ascribe_forms/input_checkbox';
import UploadFileButton from '../../../../../ascribe_buttons/upload_file_button';
+import GlobalNotificationModel from '../../../../../../models/global_notification_model';
+import GlobalNotificationActions from '../../../../../../actions/global_notification_actions';
+
import AppConstants from '../../../../../../constants/application_constants';
+import ApiUrls from '../../../../../../constants/api_urls';
+
+import requests from '../../../../../../utils/requests';
import { getLangText } from '../../../../../../utils/lang_utils';
+import { setCookie } from '../../../../../../utils/fetch_api_utils';
const { object } = React.PropTypes;
const PRRegisterPieceForm = React.createClass({
propTypes: {
- location: object
+ location: object,
+ history: object,
+ currentUser: object
},
getInitialState(){
return {
- isUploadReady: false
+ isUploadReady: false,
+ piece: null
};
},
- handleSuccess() {
+ /**
+ * In this method, we're composing all fields on the page
+ * in two steps, first submitting the registration of the piece and
+ * second adding all the additional details
+ */
+ submit() {
+ const { currentUser } = this.props;
+ const { registerPieceForm,
+ digitalWorkForm,
+ proofOfPaymentForm,
+ supportingMaterialsForm,
+ additionalDataForm } = this.refs;
+ const additionalDataFormData = additionalDataForm.getFormData();
+ // composing data for piece registration
+ let registerPieceFormData = registerPieceForm.getFormData();
+ registerPieceFormData.digital_work_key = digitalWorkForm.state.file ? digitalWorkForm.state.file.key : '';
+ registerPieceFormData.terms = true;
+
+ // submitting the piece
+ requests
+ .post(ApiUrls.pieces_list, { body: registerPieceFormData })
+ .then(({ success, piece, notification }) => {
+ if(success) {
+ this.setState({
+ piece
+ }, () => {
+ supportingMaterialsForm.createBlobRoutine();
+ proofOfPaymentForm.createBlobRoutine();
+ //thumbnailForm.createBlobRoutine();
+ });
+
+ setCookie(currentUser.email, piece.id);
+
+ return requests.post(ApiUrls.piece_extradata, {
+ body: {
+ extradata: additionalDataFormData,
+ piece_id: piece.id
+ },
+ piece_id: piece.id
+ });
+ } else {
+ const notificationMessage = new GlobalNotificationModel(notification, 'danger', 5000);
+ GlobalNotificationActions.appendGlobalNotification(notificationMessage);
+ }
+ })
+ .catch((err) => {
+ console.log(err);
+ });
+
+ },
+
+ getCreateBlobRoutine(fileClass) {
+ const { piece } = this.state;
+
+ if(piece && piece.id) {
+ if(fileClass === 'other_data') {
+ return {
+ url: ApiUrls.blob_otherdatas,
+ pieceId: piece.id
+ };
+ } else if(fileClass === 'thumbnail') {
+ return {
+ url: ApiUrls.blob_thumbnail,
+ pieceId: piece.id
+ };
+ }
+ } else {
+ return null;
+ }
},
render() {
@@ -37,8 +114,9 @@ const PRRegisterPieceForm = React.createClass({
return (
-
+
{getLangText('Select the PDF with your work')}
{getLangText('Featured Cover photo')}
{getLangText('Supporting Materials (Optional)')}
{getLangText('Proof of payment')}
+ onClick={this.submit}>
{getLangText('Submit to Portfolio Review')}
diff --git a/js/components/whitelabel/prize/portfolioreview/components/pr_register_piece.js b/js/components/whitelabel/prize/portfolioreview/components/pr_register_piece.js
index 5d1fd728..2d141866 100644
--- a/js/components/whitelabel/prize/portfolioreview/components/pr_register_piece.js
+++ b/js/components/whitelabel/prize/portfolioreview/components/pr_register_piece.js
@@ -1,14 +1,19 @@
'use strict';
import React from 'react';
+import { Link, History } from 'react-router';
import Col from 'react-bootstrap/lib/Col';
import Row from 'react-bootstrap/lib/Row';
+import UserStore from '../../../../../stores/user_store';
+import UserActions from '../../../../../actions/user_actions';
+
import PRRegisterPieceForm from './pr_forms/pr_register_piece_form';
import { getLangText } from '../../../../../utils/lang_utils';
import { setDocumentTitle } from '../../../../../utils/dom_utils';
+import { getCookie } from '../../../../../utils/fetch_api_utils';
const { object } = React.PropTypes;
@@ -18,7 +23,37 @@ const PRRegisterPiece = React.createClass({
location: object
},
+ mixins: [History],
+
+ getInitialState() {
+ return UserStore.getState();
+ },
+
+ componentDidMount() {
+ UserStore.listen(this.onChange);
+ UserActions.fetchCurrentUser();
+ },
+
+ componentDidUpdate() {
+ const { currentUser } = this.state;
+ if(currentUser && currentUser.email) {
+ const submittedPieceId = getCookie(currentUser.email);
+ if(submittedPieceId) {
+ this.history.pushState(null, `/pieces/${submittedPieceId}`);
+ }
+ }
+ },
+
+ componentWillUnmount() {
+ UserStore.unlisten(this.onChange);
+ },
+
+ onChange(state) {
+ this.setState(state);
+ },
+
render() {
+ const { currentUser } = this.state;
const { location } = this.props;
setDocumentTitle(getLangText('Submission form'));
@@ -28,14 +63,25 @@ const PRRegisterPiece = React.createClass({
Portfolio Review
{getLangText('Submission closing on %s', ' 21 Dec 2015')}
-
{getLangText('Submissions are open to everyone, we accept only PDFs.')}
-
{getLangText('We accept only one PDF with up to 20 images from every participant.')}
-
{getLangText('You need to pay 50€ in order to apply. We only accept PayPal.')}
+
+ {getLangText('Submissions are open to everyone, we accept only PDFs.')}
+
+
+ {getLangText('We accept only one PDF with up to 20 images from every participant.')}
+
+
+ {getLangText('You need to pay 50€ in order to apply. We only accept PayPal.')}
+
+
+ {getLangText("You're submitting as %s. ", currentUser.email)}
+ {getLangText('Change account?')}
+
+ location={location}
+ currentUser={currentUser}/>
);
diff --git a/js/components/whitelabel/prize/portfolioreview/pr_app.js b/js/components/whitelabel/prize/portfolioreview/pr_app.js
index 072542f9..22a837be 100644
--- a/js/components/whitelabel/prize/portfolioreview/pr_app.js
+++ b/js/components/whitelabel/prize/portfolioreview/pr_app.js
@@ -1,7 +1,6 @@
'use strict';
import React from 'react';
-import Footer from '../../../footer';
import GlobalNotification from '../../../global_notification';
import { getSubdomain } from '../../../../utils/general_utils';
@@ -26,7 +25,6 @@ let PrizeApp = React.createClass({
{children}
-
);
}
diff --git a/js/components/whitelabel/prize/prize_routes.js b/js/components/whitelabel/prize/prize_routes.js
index 7c4b40a3..1f2c6374 100644
--- a/js/components/whitelabel/prize/prize_routes.js
+++ b/js/components/whitelabel/prize/prize_routes.js
@@ -78,6 +78,7 @@ const ROUTES = {
+
)
diff --git a/js/constants/api_urls.js b/js/constants/api_urls.js
index 2ff689fe..a07f29b1 100644
--- a/js/constants/api_urls.js
+++ b/js/constants/api_urls.js
@@ -14,6 +14,7 @@ let ApiUrls = {
'blob_digitalworks': AppConstants.apiEndpoint + 'blob/digitalworks/',
'blob_otherdatas': AppConstants.apiEndpoint + 'blob/otherdatas/',
'blob_contracts': AppConstants.apiEndpoint + 'blob/contracts/',
+ 'blob_thumbnails': AppConstants.apiEndpoint + 'blob/thumbnails/',
'coa': AppConstants.apiEndpoint + 'coa/${id}/',
'coa_create': AppConstants.apiEndpoint + 'coa/',
'coa_verify': AppConstants.apiEndpoint + 'coa/verify_coa/',
diff --git a/js/utils/fetch_api_utils.js b/js/utils/fetch_api_utils.js
index 3ed964ba..a9e4bf56 100644
--- a/js/utils/fetch_api_utils.js
+++ b/js/utils/fetch_api_utils.js
@@ -1,6 +1,7 @@
'use strict';
import Q from 'q';
+import moment from 'moment';
import { sanitize } from './general_utils';
import AppConstants from '../constants/application_constants';
@@ -70,12 +71,20 @@ export function getCookie(name) {
let parts = document.cookie.split(';');
for(let i = 0; i < parts.length; i++) {
- if(parts[i].indexOf(AppConstants.csrftoken + '=') > -1) {
+ if(parts[i].indexOf(name + '=') > -1) {
return parts[i].split('=').pop();
}
}
}
+export function setCookie(key, value, days) {
+ const exdate = moment();
+ exdate.add(days, 'days');
+ console.log(exdate.utc());
+ value = window.escape(value) + ((days === null) ? '' : `; expires= ${exdate.utc()}`);
+ document.cookie = `${key}=${value}`;
+}
+
/*
Given a url for an image, this method fetches it and returns a promise that resolves to
diff --git a/sass/ascribe_property.scss b/sass/ascribe_property.scss
index cb7662e8..61df454a 100644
--- a/sass/ascribe_property.scss
+++ b/sass/ascribe_property.scss
@@ -222,7 +222,7 @@ $ascribe-red-error: rgb(169, 68, 66);
.input-upload-file-button-property {
background-color: white;
- padding: 1.5em 0 1.5em 0;
+ padding: 1em 0 1em 0;
text-align: right;
button {
diff --git a/sass/whitelabel/prize/portfolioreview/portfolioreview_custom_style.scss b/sass/whitelabel/prize/portfolioreview/portfolioreview_custom_style.scss
index 6c0d5d66..8ecb65ca 100644
--- a/sass/whitelabel/prize/portfolioreview/portfolioreview_custom_style.scss
+++ b/sass/whitelabel/prize/portfolioreview/portfolioreview_custom_style.scss
@@ -31,7 +31,8 @@
}
.register-piece--form {
-
+ margin-bottom: 3em;
+
form {
border-top: none;
}