2016-11-08 16:10:19 -08:00
|
|
|
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
|
|
|
//
|
|
|
|
// This software (Documize Community Edition) is licensed under
|
|
|
|
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
|
|
|
//
|
|
|
|
// You can operate outside the AGPL restrictions by purchasing
|
|
|
|
// Documize Enterprise Edition and obtaining a commercial license
|
|
|
|
// by contacting <sales@documize.com>.
|
|
|
|
//
|
|
|
|
// https://documize.com
|
|
|
|
|
2017-11-16 13:28:05 +00:00
|
|
|
import { computed } from '@ember/object';
|
|
|
|
import { notEmpty } from '@ember/object/computed';
|
|
|
|
import { inject as service } from '@ember/service';
|
2018-10-01 13:31:47 +01:00
|
|
|
import Modals from '../../mixins/modal';
|
|
|
|
import Notifier from '../../mixins/notifier';
|
2017-11-16 13:28:05 +00:00
|
|
|
import Component from '@ember/component';
|
2016-11-08 16:10:19 -08:00
|
|
|
|
2018-10-01 13:31:47 +01:00
|
|
|
export default Component.extend(Modals, Notifier, {
|
2019-01-04 16:33:30 +00:00
|
|
|
classNames: ["section"],
|
2017-11-16 13:28:05 +00:00
|
|
|
documentService: service('document'),
|
2018-12-18 19:03:34 +00:00
|
|
|
browserSvc: service('browser'),
|
2017-11-16 13:28:05 +00:00
|
|
|
appMeta: service(),
|
2018-12-19 12:41:36 +00:00
|
|
|
session: service(),
|
2017-11-16 13:28:05 +00:00
|
|
|
hasAttachments: notEmpty('files'),
|
2018-02-04 15:51:14 +00:00
|
|
|
canEdit: computed('permissions.documentEdit', 'document.protection', function() {
|
2018-01-22 10:31:03 +00:00
|
|
|
return this.get('document.protection') !== this.get('constants').ProtectionType.Lock && this.get('permissions.documentEdit');
|
|
|
|
}),
|
2017-12-11 11:40:12 +00:00
|
|
|
showDialog: false,
|
2018-12-19 12:41:36 +00:00
|
|
|
downloadQuery: '',
|
2018-05-29 18:26:04 +01:00
|
|
|
|
2018-06-15 14:25:05 +01:00
|
|
|
didReceiveAttrs() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this.getAttachments();
|
2017-03-07 14:39:06 +00:00
|
|
|
},
|
2016-11-08 16:10:19 -08:00
|
|
|
|
|
|
|
didInsertElement() {
|
2017-03-07 14:39:06 +00:00
|
|
|
this._super(...arguments);
|
|
|
|
|
2018-01-22 10:31:03 +00:00
|
|
|
if (!this.get('permissions.documentEdit') || this.get('document.protection') === this.get('constants').ProtectionType.Lock) {
|
2016-11-08 16:10:19 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let self = this;
|
|
|
|
let documentId = this.get('document.id');
|
|
|
|
let url = this.get('appMeta.endpoint');
|
|
|
|
let uploadUrl = `${url}/documents/${documentId}/attachments`;
|
|
|
|
|
2019-01-04 16:33:30 +00:00
|
|
|
let dzone = new Dropzone("#upload-document-files > div", {
|
2016-11-08 16:10:19 -08:00
|
|
|
headers: {
|
2018-12-19 12:41:36 +00:00
|
|
|
'Authorization': 'Bearer ' + self.get('session.authToken')
|
2016-11-08 16:10:19 -08:00
|
|
|
},
|
|
|
|
url: uploadUrl,
|
|
|
|
method: "post",
|
|
|
|
paramName: 'attachment',
|
|
|
|
clickable: true,
|
2018-10-01 13:31:47 +01:00
|
|
|
maxFilesize: 50,
|
|
|
|
parallelUploads: 5,
|
2016-11-08 16:10:19 -08:00
|
|
|
uploadMultiple: false,
|
|
|
|
addRemoveLinks: false,
|
|
|
|
autoProcessQueue: true,
|
|
|
|
|
|
|
|
init: function () {
|
2017-12-11 14:50:11 +00:00
|
|
|
this.on("success", function (/*file, response*/ ) {
|
2016-11-08 16:10:19 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
this.on("queuecomplete", function () {
|
2018-12-19 12:41:36 +00:00
|
|
|
self.notifySuccess('Uploaded file');
|
2017-03-07 14:39:06 +00:00
|
|
|
self.getAttachments();
|
2016-11-08 16:10:19 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
this.on("addedfile", function ( /*file*/ ) {
|
2018-10-01 13:31:47 +01:00
|
|
|
});
|
|
|
|
|
2018-12-19 12:41:36 +00:00
|
|
|
this.on("error", function (error, msg) {
|
2018-12-05 13:44:10 +00:00
|
|
|
self.notifyError(msg);
|
2018-12-19 12:41:36 +00:00
|
|
|
self.notifyError(error);
|
2016-11-08 16:10:19 -08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
dzone.on("complete", function (file) {
|
|
|
|
dzone.removeFile(file);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.set('drop', dzone);
|
2018-12-19 12:41:36 +00:00
|
|
|
|
|
|
|
// For authenticated users we send server auth token.
|
|
|
|
let qry = '';
|
|
|
|
if (this.get('session.authenticated')) {
|
|
|
|
qry = '?token=' + this.get('session.authToken');
|
2019-01-15 20:14:32 +00:00
|
|
|
} else {
|
|
|
|
qry = '?secure=' + this.get('session.secureToken');
|
2018-12-19 12:41:36 +00:00
|
|
|
}
|
|
|
|
this.set('downloadQuery', qry);
|
2016-11-08 16:10:19 -08:00
|
|
|
},
|
|
|
|
|
2017-03-07 14:39:06 +00:00
|
|
|
getAttachments() {
|
|
|
|
this.get('documentService').getAttachments(this.get('document.id')).then((files) => {
|
|
|
|
this.set('files', files);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-11-08 16:10:19 -08:00
|
|
|
actions: {
|
2019-01-15 20:14:32 +00:00
|
|
|
onDelete(attachment) {
|
2017-03-07 14:39:06 +00:00
|
|
|
this.get('documentService').deleteAttachment(this.get('document.id'), attachment.id).then(() => {
|
2019-01-15 20:14:32 +00:00
|
|
|
this.notifySuccess('File deleted');
|
2017-03-07 14:39:06 +00:00
|
|
|
this.getAttachments();
|
2016-11-08 16:10:19 -08:00
|
|
|
});
|
2018-12-18 19:03:34 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onExport() {
|
|
|
|
this.get('documentSvc').export({}).then((htmlExport) => {
|
|
|
|
this.get('browserSvc').downloadFile(htmlExport, this.get('space.slug') + '.html');
|
|
|
|
this.notifySuccess('Exported');
|
|
|
|
});
|
|
|
|
|
|
|
|
this.modalClose("#space-export-modal");
|
2016-11-08 16:10:19 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|