mirror of
https://github.com/documize/community.git
synced 2025-07-20 21:59:42 +02:00
fixed bug with unnecessary document import init
This commit is contained in:
parent
e4dac2ca7f
commit
10ecf0fbb0
2 changed files with 70 additions and 45 deletions
|
@ -47,6 +47,10 @@ export default Ember.Component.extend({
|
||||||
// TODO: refactor to eliminate self
|
// TODO: refactor to eliminate self
|
||||||
let self = this;
|
let self = this;
|
||||||
|
|
||||||
|
if (is.null(self.get('target'))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let drop = this.get('tether').createDrop({
|
let drop = this.get('tether').createDrop({
|
||||||
target: document.getElementById(self.get('target')),
|
target: document.getElementById(self.get('target')),
|
||||||
content: self.$(".dropdown-dialog")[0],
|
content: self.$(".dropdown-dialog")[0],
|
||||||
|
|
|
@ -44,7 +44,7 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, {
|
||||||
this.set('movedFolderOptions', targets);
|
this.set('movedFolderOptions', targets);
|
||||||
},
|
},
|
||||||
|
|
||||||
didRender() {
|
didRender() {
|
||||||
if (this.get('hasSelectedDocuments')) {
|
if (this.get('hasSelectedDocuments')) {
|
||||||
this.addTooltip(document.getElementById("move-documents-button"));
|
this.addTooltip(document.getElementById("move-documents-button"));
|
||||||
this.addTooltip(document.getElementById("delete-documents-button"));
|
this.addTooltip(document.getElementById("delete-documents-button"));
|
||||||
|
@ -57,52 +57,14 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, {
|
||||||
this.addTooltip(document.getElementById("import-document-button"));
|
this.addTooltip(document.getElementById("import-document-button"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
if (this.get('folderService').get('canEditCurrentFolder')) {
|
|
||||||
let self = this;
|
|
||||||
let folderId = this.get('folder.id');
|
|
||||||
let url = this.get('appMeta.endpoint');
|
|
||||||
let importUrl = `${url}/import/folder/${folderId}`;
|
|
||||||
|
|
||||||
let dzone = new Dropzone("#import-document-button > i", {
|
didUpdate() {
|
||||||
headers: {
|
this.setupImport();
|
||||||
'Authorization': 'Bearer ' + self.get('session.session.content.authenticated.token')
|
},
|
||||||
},
|
|
||||||
url: importUrl,
|
|
||||||
method: "post",
|
|
||||||
paramName: 'attachment',
|
|
||||||
acceptedFiles: ".doc,.docx,.txt,.md,.markdown",
|
|
||||||
clickable: true,
|
|
||||||
maxFilesize: 10,
|
|
||||||
parallelUploads: 3,
|
|
||||||
uploadMultiple: false,
|
|
||||||
addRemoveLinks: false,
|
|
||||||
autoProcessQueue: true,
|
|
||||||
|
|
||||||
init: function () {
|
didInsertElement() {
|
||||||
this.on("success", function (document) {
|
// this.setupImport();
|
||||||
self.send('onDocumentImported', document.name, document);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.on("error", function (x) {
|
|
||||||
console.log("Conversion failed for ", x.name, " obj ", x); // TODO proper error handling
|
|
||||||
});
|
|
||||||
|
|
||||||
this.on("queuecomplete", function () {});
|
|
||||||
|
|
||||||
this.on("addedfile", function (file) {
|
|
||||||
self.send('onDocumentImporting', file.name);
|
|
||||||
self.audit.record('converted-document');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
dzone.on("complete", function (file) {
|
|
||||||
dzone.removeFile(file);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.set('drop', dzone);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
willDestroyElement() {
|
willDestroyElement() {
|
||||||
|
@ -114,6 +76,65 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, {
|
||||||
this.destroyTooltips();
|
this.destroyTooltips();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
setupImport() {
|
||||||
|
// guard against unecessary file upload component init
|
||||||
|
if (this.get('hasSelectedDocuments') || !this.get('folderService').get('canEditCurrentFolder')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// already done init?
|
||||||
|
if (is.not.null(this.get('drop'))) {
|
||||||
|
if (is.not.null(this.get('drop'))) {
|
||||||
|
this.get('drop').destroy();
|
||||||
|
this.set('drop', null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let self = this;
|
||||||
|
let folderId = this.get('folder.id');
|
||||||
|
let url = this.get('appMeta.endpoint');
|
||||||
|
let importUrl = `${url}/import/folder/${folderId}`;
|
||||||
|
|
||||||
|
let dzone = new Dropzone("#import-document-button > i", {
|
||||||
|
headers: {
|
||||||
|
'Authorization': 'Bearer ' + self.get('session.session.content.authenticated.token')
|
||||||
|
},
|
||||||
|
url: importUrl,
|
||||||
|
method: "post",
|
||||||
|
paramName: 'attachment',
|
||||||
|
acceptedFiles: ".doc,.docx,.txt,.md,.markdown",
|
||||||
|
clickable: true,
|
||||||
|
maxFilesize: 10,
|
||||||
|
parallelUploads: 3,
|
||||||
|
uploadMultiple: false,
|
||||||
|
addRemoveLinks: false,
|
||||||
|
autoProcessQueue: true,
|
||||||
|
|
||||||
|
init: function () {
|
||||||
|
this.on("success", function (document) {
|
||||||
|
self.send('onDocumentImported', document.name, document);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.on("error", function (x) {
|
||||||
|
console.log("Conversion failed for ", x.name, " obj ", x); // TODO proper error handling
|
||||||
|
});
|
||||||
|
|
||||||
|
this.on("queuecomplete", function () {});
|
||||||
|
|
||||||
|
this.on("addedfile", function (file) {
|
||||||
|
self.send('onDocumentImporting', file.name);
|
||||||
|
self.audit.record('converted-document');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
dzone.on("complete", function (file) {
|
||||||
|
dzone.removeFile(file);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.set('drop', dzone);
|
||||||
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
onDocumentImporting(filename) {
|
onDocumentImporting(filename) {
|
||||||
this.send("showNotification", `Importing ${filename}`);
|
this.send("showNotification", `Importing ${filename}`);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue