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
, type
, id
, path
) {
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 if (action
=== ACTIONS
.update
) {
51 return getCatalogPackageManagerServerOrigin() + '/api/update';
53 return getCatalogPackageManagerServerOrigin() + '/composer/api/file-manager?api_server=' + Utils
.getSearchParams(window
.location
).api_server
+ '&package_type=' + type
+ '&package_id=' + id
+ '&package_path=' + path
+ ( dev_download_server
? '&dev_download_server=' + dev_download_server
: '');
58 maxFilesize
: 10000000000,
60 autoProcessQueue
: true,
62 sending(file
, xhr
, formData
) {
63 // NOTE ie11 does not get this form data
64 formData
.append('id', file
.id
);
65 FileManagerActions
.addFileSuccess({
70 error(file
, errorMessage
) {
74 status
: 'upload-error',
78 CatalogPackageManagerActions
.uploadCatalogPackageError(response
);
81 const data
= JSON
.parse(file
.xhr
.responseText
);
82 data
.status
= 'upload-success';
87 //CatalogPackageManagerActions.uploadCatalogPackageStatusUpdated(response);
90 file
.id
= file
.id
|| guid();
91 file
.riftAction
= action
;
92 //CatalogPackageManagerActions.uploadCatalogPackage(file);
94 thumbnail(file
, dataUrl
) {
98 status
: 'upload-thumbnail',
102 //CatalogPackageManagerActions.uploadCatalogPackageStatusUpdated(response);
104 uploadprogress(file
, progress
, bytesSent
) {
105 // FileManagerActions.addFileSuccess({
107 // fileName: file.name
112 status
: 'upload-progress',
117 //CatalogPackageManagerActions.uploadCatalogPackageStatusUpdated(response);
122 export default class CatalogPackageManagerUploadDropZone
{
124 constructor(element
, button
, action
, type
, id
, path
) {
125 this.dropZone
= initializeDropZone(element
, button
, action
, type
, id
, path
);
128 static get ACTIONS() {
132 on(eventName
, eventCallback
) {
133 this.dropZone
.on(eventName
, eventCallback
);