1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-19 13:19:43 +02:00
documize/app/app/components/folder/start-document.js

124 lines
3 KiB
JavaScript
Raw Normal View History

2016-07-07 18:54:16 -07: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';
export default Ember.Component.extend(NotifierMixin, {
2016-07-08 16:08:23 -07:00
localStorage: Ember.inject.service(),
2016-11-01 14:00:23 -07:00
appMeta: Ember.inject.service(),
2016-07-08 16:08:23 -07:00
canEditTemplate: "",
2016-11-01 14:00:23 -07:00
importedDocuments: [],
drop: null,
didInsertElement() {
this.setupImport();
},
willDestroyElement() {
if (is.not.null(this.get('drop'))) {
this.get('drop').destroy();
this.set('drop', null);
}
},
2016-11-01 14:00:23 -07:00
setupImport() {
// already done init?
if (is.not.null(this.get('drop'))) {
this.get('drop').destroy();
this.set('drop', null);
2016-11-01 14:00:23 -07:00
}
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", {
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);
},
2016-07-07 18:54:16 -07:00
2016-07-08 16:08:23 -07:00
actions: {
2016-11-01 14:00:23 -07:00
onDocumentImporting(filename) {
this.send("showNotification", `Importing ${filename}`);
let documents = this.get('importedDocuments');
documents.push(filename);
this.set('importedDocuments', documents);
},
onDocumentImported(filename /*, document*/ ) {
this.send("showNotification", `${filename} ready`);
let documents = this.get('importedDocuments');
documents.pop(filename);
this.set('importedDocuments', documents);
this.attrs.onImport();
if (documents.length === 0) {
// this.get('showDocument')(this.get('folder'), document);
}
},
2016-10-07 10:19:46 -07:00
editTemplate(template) {
2016-07-08 16:08:23 -07:00
this.audit.record('edited-saved-template');
this.attrs.onEditTemplate(template);
2016-07-07 18:54:16 -07:00
2016-07-08 16:08:23 -07:00
return true;
},
2016-07-07 18:54:16 -07:00
2016-10-07 10:19:46 -07:00
startDocument(template) {
2016-07-08 16:08:23 -07:00
this.audit.record('used-saved-template');
this.attrs.onDocumentTemplate(template.id, template.title, "private");
2016-07-07 18:54:16 -07:00
2016-10-06 19:28:57 -07:00
return true;
2016-07-08 16:08:23 -07:00
}
}
2016-10-06 19:28:57 -07:00
});