mirror of
https://github.com/ascribe/onion.git
synced 2025-01-03 18:35:09 +01:00
fineuploader session with cors
This commit is contained in:
commit
85347a8916
@ -9,6 +9,9 @@ import Router from 'react-router';
|
|||||||
import LicenseActions from '../actions/license_actions';
|
import LicenseActions from '../actions/license_actions';
|
||||||
import LicenseStore from '../stores/license_store';
|
import LicenseStore from '../stores/license_store';
|
||||||
|
|
||||||
|
import PieceListStore from '../stores/piece_list_store';
|
||||||
|
import PieceListActions from '../actions/piece_list_actions';
|
||||||
|
|
||||||
import GlobalNotificationModel from '../models/global_notification_model';
|
import GlobalNotificationModel from '../models/global_notification_model';
|
||||||
import GlobalNotificationActions from '../actions/global_notification_actions';
|
import GlobalNotificationActions from '../actions/global_notification_actions';
|
||||||
|
|
||||||
@ -29,6 +32,7 @@ let RegisterPiece = React.createClass( {
|
|||||||
getInitialState(){
|
getInitialState(){
|
||||||
return mergeOptions(
|
return mergeOptions(
|
||||||
LicenseStore.getState(),
|
LicenseStore.getState(),
|
||||||
|
PieceListStore.getState(),
|
||||||
{
|
{
|
||||||
digitalWorkKey: null,
|
digitalWorkKey: null,
|
||||||
uploadStatus: false,
|
uploadStatus: false,
|
||||||
@ -39,10 +43,12 @@ let RegisterPiece = React.createClass( {
|
|||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
LicenseActions.fetchLicense();
|
LicenseActions.fetchLicense();
|
||||||
LicenseStore.listen(this.onChange);
|
LicenseStore.listen(this.onChange);
|
||||||
|
PieceListStore.listen(this.onChange);
|
||||||
},
|
},
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
LicenseStore.unlisten(this.onChange);
|
LicenseStore.unlisten(this.onChange);
|
||||||
|
PieceListStore.unlisten(this.onChange);
|
||||||
},
|
},
|
||||||
|
|
||||||
onChange(state) {
|
onChange(state) {
|
||||||
@ -52,6 +58,11 @@ let RegisterPiece = React.createClass( {
|
|||||||
handleSuccess(response){
|
handleSuccess(response){
|
||||||
let notification = new GlobalNotificationModel(response.notification, 'success', 10000);
|
let notification = new GlobalNotificationModel(response.notification, 'success', 10000);
|
||||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||||
|
|
||||||
|
// once the user was able to register a piece successfully, we need to make sure to keep
|
||||||
|
// the piece list up to date
|
||||||
|
PieceListActions.fetchPieceList(this.state.page, this.state.pageSize, this.state.searchTerm, this.state.orderBy, this.state.orderAsc);
|
||||||
|
|
||||||
this.transitionTo('edition', {editionId: response.edition.bitcoin_id});
|
this.transitionTo('edition', {editionId: response.edition.bitcoin_id});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -64,6 +64,26 @@ export function formatText() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Checks a list of objects for key duplicates and returns a boolean
|
||||||
|
*/
|
||||||
|
function _doesObjectListHaveDuplicates(l) {
|
||||||
|
let mergedList = [];
|
||||||
|
|
||||||
|
l = l.map((obj) => Object.keys(obj));
|
||||||
|
|
||||||
|
// Taken from: http://stackoverflow.com/a/10865042
|
||||||
|
// How to flatten an array of arrays in javascript.
|
||||||
|
// If two objects contain the same key, then these two keys
|
||||||
|
// will actually be represented in the merged array
|
||||||
|
mergedList = mergedList.concat.apply(mergedList, l);
|
||||||
|
|
||||||
|
// Taken from: http://stackoverflow.com/a/7376645/1263876
|
||||||
|
// By casting the array to a set, and then checking if the size of the array
|
||||||
|
// shrunk in the process of casting, we can check if there were any duplicates
|
||||||
|
return (new Set(mergedList)).size !== mergedList.length;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes a list of object and merges their keys to one object.
|
* Takes a list of object and merges their keys to one object.
|
||||||
* Uses mergeOptions for two objects.
|
* Uses mergeOptions for two objects.
|
||||||
@ -71,6 +91,12 @@ export function formatText() {
|
|||||||
* @return {[type]} [description]
|
* @return {[type]} [description]
|
||||||
*/
|
*/
|
||||||
export function mergeOptions(...l) {
|
export function mergeOptions(...l) {
|
||||||
|
// If the objects submitted in the list have duplicates,in their key names,
|
||||||
|
// abort the merge and tell the function's user to check his objects.
|
||||||
|
if(_doesObjectListHaveDuplicates(l)) {
|
||||||
|
throw new Error('The objects you submitted for merging have duplicates. Merge aborted.');
|
||||||
|
}
|
||||||
|
|
||||||
let newObj = {};
|
let newObj = {};
|
||||||
|
|
||||||
for(let i = 1; i < l.length; i++) {
|
for(let i = 1; i < l.length; i++) {
|
||||||
@ -86,18 +112,14 @@ export function mergeOptions(...l) {
|
|||||||
* @returns obj3 a new object based on obj1 and obj2
|
* @returns obj3 a new object based on obj1 and obj2
|
||||||
* Taken from: http://stackoverflow.com/a/171256/1263876
|
* Taken from: http://stackoverflow.com/a/171256/1263876
|
||||||
*/
|
*/
|
||||||
function _mergeOptions(obj1, obj2){
|
function _mergeOptions(obj1, obj2) {
|
||||||
let obj3 = {};
|
let obj3 = {};
|
||||||
|
|
||||||
for (let attrname in obj1) {
|
for (let attrname in obj1) {
|
||||||
obj3[attrname] = obj1[attrname];
|
obj3[attrname] = obj1[attrname];
|
||||||
}
|
}
|
||||||
for (let attrname in obj2) {
|
for (let attrname in obj2) {
|
||||||
if(attrname in obj3) {
|
obj3[attrname] = obj2[attrname];
|
||||||
throw Error('Overwrite Conflict: You\'re merging two objects with the same keys: ' + attrname);
|
|
||||||
} else {
|
|
||||||
obj3[attrname] = obj2[attrname];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return obj3;
|
return obj3;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user