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'
29 * This class is responsible for wiring the DropZone.js to our React actions.
37 function getCatalogPackageManagerServerOrigin() {
38 // return Utils.getSearchParams(window.location).upload_server + ':4567';
39 return window
.location
.origin
;
42 function initializeDropZone(element
= '#dropzone', button
= false, action
= ACTIONS
.onboard
) {
43 let Auth
= 'Basic ' + window
.sessionStorage
.getItem("auth");
44 let dev_download_server
= Utils
.getSearchParams(window
.location
).dev_download_server
;
45 DropZone
.autoDiscover
= false;
46 return new DropZone(element
, {
49 if (action
=== ACTIONS
.update
) {
50 return getCatalogPackageManagerServerOrigin() + '/composer/update?api_server=' + Utils
.getSearchParams(window
.location
).api_server
+ '&upload_server=' + Utils
.getSearchParams(window
.location
).upload_server
+ ( dev_download_server
? '&dev_download_server=' + dev_download_server
: '');
52 return getCatalogPackageManagerServerOrigin() + '/composer/upload?api_server=' + Utils
.getSearchParams(window
.location
).api_server
+ '&upload_server=' + Utils
.getSearchParams(window
.location
).upload_server
+ ( dev_download_server
? '&dev_download_server=' + dev_download_server
: '');
57 maxFilesize
: 10000000000,
59 acceptedFiles
: 'application/octet-stream,.gz,.tar.gz,.tar,.qcow,.qcow2,.iso,application/yaml,.yaml,application/json,.json,application/zip,.zip,application/x-rar-compressed,.rar,application/x-7z-compressed,.7z,application/x-bzip,.bz,application/x-bzip2,.bz2,application/x-gtar,.gtar',
60 autoProcessQueue
: true,
62 sending(file
, xhr
, formData
) {
63 // NOTE ie11 does not get this form data
64 formData
.append('id', file
.id
);
66 error(file
, errorMessage
) {
70 status
: 'upload-error',
74 CatalogPackageManagerActions
.uploadCatalogPackageError(response
);
77 const data
= JSON
.parse(file
.xhr
.responseText
);
78 data
.status
= 'upload-success';
83 CatalogPackageManagerActions
.uploadCatalogPackageStatusUpdated(response
);
86 file
.id
= file
.id
|| guid();
87 file
.riftAction
= action
;
88 CatalogPackageManagerActions
.uploadCatalogPackage(file
);
90 thumbnail(file
, dataUrl
) {
94 status
: 'upload-thumbnail',
98 CatalogPackageManagerActions
.uploadCatalogPackageStatusUpdated(response
);
100 uploadprogress(file
, progress
, bytesSent
) {
104 status
: 'upload-progress',
109 CatalogPackageManagerActions
.uploadCatalogPackageStatusUpdated(response
);
114 export default class CatalogPackageManagerUploadDropZone
{
116 constructor(element
, button
, action
) {
117 this.dropZone
= initializeDropZone(element
, button
, action
);
120 static get ACTIONS() {
124 on(eventName
, eventCallback
) {
125 this.dropZone
.on(eventName
, eventCallback
);