4 * Copyright 2016 RIFT.IO Inc
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 * Created by onvelocity on 10/27/15.
23 import guid
from '../libraries/guid'
24 import DropZone
from 'dropzone'
25 import Utils
from '../libraries/utils'
26 import CatalogPackageManagerActions
from '../actions/CatalogPackageManagerActions';
27 import FileManagerActions
from '../components/filemanager/FileManagerActions.js';
30 * This class is responsible for wiring the DropZone.js to our React actions.
38 function getCatalogPackageManagerServerOrigin() {
39 // return Utils.getSearchParams(window.location).upload_server + ':4567';
40 return window
.location
.origin
;
43 function initializeDropZone(element
= '#dropzone', button
= false, action
= ACTIONS
.onboard
, getUploadProps
) {
44 let Auth
= 'Basic ' + window
.sessionStorage
.getItem("auth");
45 let dev_download_server
= Utils
.getSearchParams(window
.location
).dev_download_server
;
46 DropZone
.autoDiscover
= false;
47 return new DropZone(element
, {
50 let {packageType
, packageId
, assetGroup
, path
} = getUploadProps();
51 if (action
=== ACTIONS
.update
) {
52 return getCatalogPackageManagerServerOrigin() + '/api/update';
54 let url
= getCatalogPackageManagerServerOrigin()
55 + '/composer/api/file-manager?api_server='
56 + Utils
.getSearchParams(window
.location
).api_server
57 + '&package_type=' + packageType
58 + '&package_id=' + packageId
59 + '&package_path=' + path
60 + '&asset_type=' + assetGroup
.id
61 + ( dev_download_server
? '&dev_download_server=' + dev_download_server
: '');
67 maxFilesize
: 10000000000,
69 autoProcessQueue
: true,
71 sending(file
, xhr
, formData
) {
72 // NOTE ie11 does not get this form data
73 let {packageType
, packageId
, assetGroup
, path
} = getUploadProps();
74 formData
.append('id', file
.id
);
75 FileManagerActions
.addFileSuccess({
76 path
: assetGroup
.folder
+ (path
? '/' + path
: ''),
80 error(file
, errorMessage
) {
84 status
: 'upload-error',
88 CatalogPackageManagerActions
.uploadCatalogPackageError(response
);
91 const data
= JSON
.parse(file
.xhr
.responseText
);
92 data
.status
= 'upload-success';
97 //CatalogPackageManagerActions.uploadCatalogPackageStatusUpdated(response);
100 file
.id
= file
.id
|| guid();
101 file
.riftAction
= action
;
102 //CatalogPackageManagerActions.uploadCatalogPackage(file);
104 thumbnail(file
, dataUrl
) {
108 status
: 'upload-thumbnail',
112 //CatalogPackageManagerActions.uploadCatalogPackageStatusUpdated(response);
114 uploadprogress(file
, progress
, bytesSent
) {
115 // FileManagerActions.addFileSuccess({
117 // fileName: file.name
122 status
: 'upload-progress',
127 //CatalogPackageManagerActions.uploadCatalogPackageStatusUpdated(response);
132 export default class FileManagerUploadDropZone
{
134 constructor(element
, button
, action
, getUploadProps
) {
135 this.dropZone
= initializeDropZone(element
, button
, action
, getUploadProps
);
138 static get ACTIONS() {
142 on(eventName
, eventCallback
) {
143 this.dropZone
.on(eventName
, eventCallback
);