1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-19 21:29:42 +02:00
documize/gui/app/components/document/view-attachment.js

117 lines
2.7 KiB
JavaScript
Raw Normal View History

// 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
import { computed } from '@ember/object';
import { notEmpty } from '@ember/object/computed';
import { inject as service } from '@ember/service';
import Component from '@ember/component';
import DropdownMixin from '../../mixins/dropdown';
2017-12-11 11:40:12 +00:00
export default Component.extend(DropdownMixin, {
documentService: service('document'),
appMeta: service(),
hasAttachments: notEmpty('files'),
deleteAttachment: {
id: "",
name: "",
},
canShow: computed('permissions', 'files', function() {
return this.get('files.length') > 0 || this.get('permissions.documentEdit');
}),
2017-12-11 11:40:12 +00:00
showDialog: false,
init() {
this._super(...arguments);
2017-08-08 14:24:24 +01:00
this.getAttachments();
},
didInsertElement() {
this._super(...arguments);
2017-09-14 12:54:57 +01:00
if (!this.get('permissions.documentEdit')) {
return;
}
let self = this;
let documentId = this.get('document.id');
let url = this.get('appMeta.endpoint');
let uploadUrl = `${url}/documents/${documentId}/attachments`;
let dzone = new Dropzone("#upload-document-files", {
headers: {
'Authorization': 'Bearer ' + self.get('session.session.content.authenticated.token')
},
url: uploadUrl,
method: "post",
paramName: 'attachment',
clickable: true,
maxFilesize: 10,
parallelUploads: 3,
uploadMultiple: false,
addRemoveLinks: false,
autoProcessQueue: true,
init: function () {
this.on("success", function (file /*, response*/ ) {
});
this.on("queuecomplete", function () {
self.getAttachments();
});
this.on("addedfile", function ( /*file*/ ) {
});
}
});
dzone.on("complete", function (file) {
dzone.removeFile(file);
});
this.set('drop', dzone);
},
willDestroyElement() {
this._super(...arguments);
},
getAttachments() {
this.get('documentService').getAttachments(this.get('document.id')).then((files) => {
this.set('files', files);
});
},
actions: {
2017-12-11 11:40:12 +00:00
onShowDialog(id, name) {
this.set('deleteAttachment', { id: id, name: name });
2017-12-11 11:40:12 +00:00
this.set('showDialog', true);
},
onDelete() {
2017-12-11 11:40:12 +00:00
this.set('showDialog', false);
let attachment = this.get('deleteAttachment');
2017-12-11 11:40:12 +00:00
this.get('documentService').deleteAttachment(this.get('document.id'), attachment.id).then(() => {
this.getAttachments();
this.set('deleteAttachment', {
id: "",
name: ""
});
});
return true;
}
}
});