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
|
|
|
|
|
|
|
|
import Ember from 'ember';
|
|
|
|
import NotifierMixin from '../../mixins/notifier';
|
|
|
|
import TooltipMixin from '../../mixins/tooltip';
|
|
|
|
|
|
|
|
export default Ember.Component.extend(NotifierMixin, TooltipMixin, {
|
2017-03-07 14:39:06 +00:00
|
|
|
documentService: Ember.inject.service('document'),
|
2016-11-08 16:10:19 -08:00
|
|
|
appMeta: Ember.inject.service(),
|
|
|
|
drop: null,
|
2017-09-21 15:48:00 +01:00
|
|
|
hasAttachments: Ember.computed.notEmpty('files'),
|
2016-11-08 16:10:19 -08:00
|
|
|
deleteAttachment: {
|
|
|
|
id: "",
|
|
|
|
name: "",
|
|
|
|
},
|
2017-03-07 14:39:06 +00:00
|
|
|
|
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
2017-08-08 14:24:24 +01:00
|
|
|
|
2017-03-07 14:39:06 +00:00
|
|
|
this.getAttachments();
|
|
|
|
},
|
2016-11-08 16:10:19 -08:00
|
|
|
|
|
|
|
didInsertElement() {
|
2017-03-07 14:39:06 +00:00
|
|
|
this._super(...arguments);
|
|
|
|
|
2017-09-14 12:54:57 +01:00
|
|
|
if (!this.get('permissions.documentEdit')) {
|
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`;
|
|
|
|
|
|
|
|
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*/ ) {
|
|
|
|
self.showNotification(`Attached ${file.name}`);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.on("queuecomplete", function () {
|
2017-03-07 14:39:06 +00:00
|
|
|
self.getAttachments();
|
2016-11-08 16:10:19 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
this.on("addedfile", function ( /*file*/ ) {
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
dzone.on("complete", function (file) {
|
|
|
|
dzone.removeFile(file);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.set('drop', dzone);
|
|
|
|
},
|
|
|
|
|
|
|
|
willDestroyElement() {
|
2017-03-07 14:39:06 +00:00
|
|
|
this._super(...arguments);
|
2016-11-08 16:10:19 -08:00
|
|
|
|
2017-03-07 14:39:06 +00:00
|
|
|
let drop = this.get('drop');
|
2016-11-08 16:10:19 -08:00
|
|
|
if (is.not.null(drop)) {
|
|
|
|
drop.destroy();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
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: {
|
2017-03-07 14:39:06 +00:00
|
|
|
onConfirmDelete(id, name) {
|
2016-11-08 16:10:19 -08:00
|
|
|
this.set('deleteAttachment', {
|
|
|
|
id: id,
|
|
|
|
name: name
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".delete-attachment-dialog").css("display", "block");
|
|
|
|
|
|
|
|
let drop = new Drop({
|
|
|
|
target: $(".delete-attachment-" + id)[0],
|
|
|
|
content: $(".delete-attachment-dialog")[0],
|
|
|
|
classes: 'drop-theme-basic',
|
2017-09-21 15:48:00 +01:00
|
|
|
position: "bottom right",
|
2016-11-08 16:10:19 -08:00
|
|
|
openOn: "always",
|
|
|
|
tetherOptions: {
|
|
|
|
offset: "5px 0",
|
|
|
|
targetOffset: "10px 0"
|
|
|
|
},
|
|
|
|
remove: false
|
|
|
|
});
|
|
|
|
|
|
|
|
this.set('drop', drop);
|
|
|
|
},
|
|
|
|
|
2017-03-07 14:39:06 +00:00
|
|
|
onCancel() {
|
2016-11-08 16:10:19 -08:00
|
|
|
let drop = this.get('drop');
|
|
|
|
drop.close();
|
|
|
|
|
|
|
|
this.set('deleteAttachment', {
|
|
|
|
id: "",
|
|
|
|
name: ""
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-03-07 14:39:06 +00:00
|
|
|
onDelete() {
|
2016-11-08 16:10:19 -08:00
|
|
|
let attachment = this.get('deleteAttachment');
|
|
|
|
let drop = this.get('drop');
|
|
|
|
drop.close();
|
|
|
|
|
2017-03-07 14:39:06 +00:00
|
|
|
this.showNotification(`Deleted ${name}`);
|
2016-11-08 16:10:19 -08:00
|
|
|
|
2017-03-07 14:39:06 +00:00
|
|
|
this.get('documentService').deleteAttachment(this.get('document.id'), attachment.id).then(() => {
|
|
|
|
this.getAttachments();
|
|
|
|
this.set('deleteAttachment', {
|
|
|
|
id: "",
|
|
|
|
name: ""
|
|
|
|
});
|
2016-11-08 16:10:19 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|