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';
41 function initializeDropZone(element
= '#dropzone', button
= false, action
= ACTIONS
.onboard
) {
42 DropZone
.autoDiscover
= false;
43 return new DropZone(element
, {
44 paramName
: 'descriptor',
46 if (action
=== ACTIONS
.update
) {
47 return getCatalogPackageManagerServerOrigin() + '/api/update';
49 return getCatalogPackageManagerServerOrigin() + '/api/upload';
51 maxFilesize
: 10000000000,
53 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',
54 autoProcessQueue
: true,
56 sending(file
, xhr
, formData
) {
57 // NOTE ie11 does not get this form data
58 formData
.append('id', file
.id
);
60 error(file
, errorMessage
) {
64 status
: 'upload-error',
68 CatalogPackageManagerActions
.uploadCatalogPackageError(response
);
71 const data
= JSON
.parse(file
.xhr
.responseText
);
72 data
.status
= 'upload-success';
77 CatalogPackageManagerActions
.uploadCatalogPackageStatusUpdated(response
);
80 file
.id
= file
.id
|| guid();
81 file
.riftAction
= action
;
82 CatalogPackageManagerActions
.uploadCatalogPackage(file
);
84 thumbnail(file
, dataUrl
) {
88 status
: 'upload-thumbnail',
92 CatalogPackageManagerActions
.uploadCatalogPackageStatusUpdated(response
);
94 uploadprogress(file
, progress
, bytesSent
) {
98 status
: 'upload-progress',
103 CatalogPackageManagerActions
.uploadCatalogPackageStatusUpdated(response
);
108 export default class CatalogPackageManagerUploadDropZone
{
110 constructor(element
, button
, action
) {
111 this.dropZone
= initializeDropZone(element
, button
, action
);
114 static get ACTIONS() {
118 on(eventName
, eventCallback
) {
119 this.dropZone
.on(eventName
, eventCallback
);