2017-11-21 14:47:49 +00: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
|
|
|
|
|
2018-01-22 10:31:03 +00:00
|
|
|
import $ from 'jquery';
|
2017-11-22 11:02:35 +00:00
|
|
|
import { computed } from '@ember/object';
|
2017-12-15 13:41:20 +00:00
|
|
|
import { schedule } from '@ember/runloop';
|
2017-11-22 11:02:35 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
2017-11-27 15:38:39 +00:00
|
|
|
import TooltipMixin from '../../mixins/tooltip';
|
2017-12-05 19:03:38 +00:00
|
|
|
import ModalMixin from '../../mixins/modal';
|
2017-11-21 14:47:49 +00:00
|
|
|
import AuthMixin from '../../mixins/auth';
|
2018-07-29 10:59:24 -04:00
|
|
|
import Notifier from '../../mixins/notifier';
|
2018-03-03 17:46:29 +00:00
|
|
|
import Component from '@ember/component';
|
2017-11-21 14:47:49 +00:00
|
|
|
|
2018-07-29 10:59:24 -04:00
|
|
|
export default Component.extend(ModalMixin, TooltipMixin, AuthMixin, Notifier, {
|
2017-11-23 20:40:46 +00:00
|
|
|
spaceService: service('folder'),
|
2017-12-15 13:41:20 +00:00
|
|
|
localStorage: service(),
|
|
|
|
templateService: service('template'),
|
2018-07-28 11:43:45 -04:00
|
|
|
browserSvc: service('browser'),
|
|
|
|
documentSvc: service('document'),
|
2017-11-22 11:02:35 +00:00
|
|
|
session: service(),
|
|
|
|
appMeta: service(),
|
|
|
|
pinned: service(),
|
2017-11-21 14:47:49 +00:00
|
|
|
spaceName: '',
|
|
|
|
copyTemplate: true,
|
|
|
|
copyPermission: true,
|
|
|
|
copyDocument: false,
|
2017-11-22 11:02:35 +00:00
|
|
|
spaceSettings: computed('permissions', function() {
|
|
|
|
return this.get('permissions.spaceOwner') || this.get('permissions.spaceManage');
|
|
|
|
}),
|
|
|
|
deleteSpaceName: '',
|
2017-12-15 13:41:20 +00:00
|
|
|
hasTemplates: computed('templates', function() {
|
|
|
|
return this.get('templates.length') > 0;
|
|
|
|
}),
|
2018-07-28 11:43:45 -04:00
|
|
|
hasCategories: computed('categories', function() {
|
|
|
|
return this.get('categories.length') > 0;
|
|
|
|
}),
|
|
|
|
hasDocuments: computed('documents', function() {
|
|
|
|
return this.get('documents.length') > 0;
|
|
|
|
}),
|
2017-12-15 13:41:20 +00:00
|
|
|
emptyDocName: '',
|
|
|
|
emptyDocNameError: false,
|
|
|
|
templateDocName: '',
|
|
|
|
templateDocNameError: false,
|
|
|
|
selectedTemplate: '',
|
|
|
|
dropzone: null,
|
2017-11-22 11:02:35 +00:00
|
|
|
|
2018-01-22 10:31:03 +00:00
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this.importedDocuments = [];
|
|
|
|
this.importStatus = [];
|
|
|
|
this.clonedSpace = { id: '' };
|
|
|
|
this.pinState = {
|
|
|
|
isPinned: false,
|
|
|
|
pinId: '',
|
|
|
|
newName: ''
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2017-11-22 11:02:35 +00:00
|
|
|
didReceiveAttrs() {
|
|
|
|
this._super(...arguments);
|
|
|
|
|
|
|
|
let folder = this.get('space');
|
|
|
|
let targets = _.reject(this.get('spaces'), {id: folder.get('id')});
|
2017-12-15 13:41:20 +00:00
|
|
|
this.set('movedFolderOptions', targets);
|
2017-11-22 11:02:35 +00:00
|
|
|
|
|
|
|
this.get('pinned').isSpacePinned(folder.get('id')).then((pinId) => {
|
|
|
|
this.set('pinState.pinId', pinId);
|
|
|
|
this.set('pinState.isPinned', pinId !== '');
|
|
|
|
this.set('pinState.newName', folder.get('name'));
|
|
|
|
this.renderTooltips();
|
|
|
|
});
|
2018-07-28 11:43:45 -04:00
|
|
|
|
|
|
|
let cats = this.get('categories');
|
|
|
|
cats.forEach((cat) => {
|
|
|
|
cat.set('exportSelected', false);
|
|
|
|
})
|
2017-11-22 11:02:35 +00:00
|
|
|
},
|
2017-11-21 14:47:49 +00:00
|
|
|
|
|
|
|
didInsertElement() {
|
|
|
|
this._super(...arguments);
|
2017-12-05 19:03:38 +00:00
|
|
|
this.modalInputFocus('#space-delete-modal', '#delete-space-name');
|
|
|
|
this.modalInputFocus('#space-invite-modal', '#space-invite-email');
|
2017-11-23 20:40:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
willDestroyElement() {
|
|
|
|
this._super(...arguments);
|
2017-11-27 15:38:39 +00:00
|
|
|
this.removeTooltips();
|
2017-12-15 13:41:20 +00:00
|
|
|
|
|
|
|
if (is.not.null(this.get('dropzone'))) {
|
|
|
|
this.get('dropzone').destroy();
|
|
|
|
this.set('dropzone', null);
|
2018-03-27 11:33:43 +01:00
|
|
|
}
|
2017-11-22 11:02:35 +00:00
|
|
|
},
|
|
|
|
|
2017-12-15 13:41:20 +00:00
|
|
|
setupImport() {
|
|
|
|
// already done init?
|
|
|
|
if (is.not.null(this.get('dropzone'))) {
|
|
|
|
this.get('dropzone').destroy();
|
|
|
|
this.set('dropzone', null);
|
|
|
|
}
|
|
|
|
|
|
|
|
let self = this;
|
|
|
|
let folderId = this.get('space.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,.md,.markdown,.htm,.html",
|
|
|
|
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, x); // eslint-disable-line no-console
|
|
|
|
});
|
|
|
|
|
|
|
|
// this.on("queuecomplete", function () {});
|
|
|
|
|
|
|
|
this.on("addedfile", function (file) {
|
|
|
|
self.send('onDocumentImporting', file.name);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
dzone.on("complete", function (file) {
|
|
|
|
dzone.removeFile(file);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.set('dropzone', dzone);
|
|
|
|
},
|
|
|
|
|
2017-11-21 14:47:49 +00:00
|
|
|
actions: {
|
2017-11-22 11:02:35 +00:00
|
|
|
onUnpin() {
|
|
|
|
this.get('pinned').unpinItem(this.get('pinState.pinId')).then(() => {
|
2017-11-23 20:40:46 +00:00
|
|
|
$('#space-pin-button').tooltip('dispose');
|
2017-11-22 11:02:35 +00:00
|
|
|
this.set('pinState.isPinned', false);
|
|
|
|
this.set('pinState.pinId', '');
|
|
|
|
this.eventBus.publish('pinChange');
|
|
|
|
this.renderTooltips();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
onPin() {
|
|
|
|
let pin = {
|
|
|
|
pin: this.get('pinState.newName'),
|
|
|
|
documentId: '',
|
2018-10-12 17:54:15 +01:00
|
|
|
spaceId: this.get('space.id')
|
2017-11-22 11:02:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
this.get('pinned').pinItem(pin).then((pin) => {
|
2017-11-23 20:40:46 +00:00
|
|
|
$('#space-pin-button').tooltip('dispose');
|
2017-11-22 11:02:35 +00:00
|
|
|
this.set('pinState.isPinned', true);
|
|
|
|
this.set('pinState.pinId', pin.get('id'));
|
|
|
|
this.eventBus.publish('pinChange');
|
|
|
|
this.renderTooltips();
|
|
|
|
});
|
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2017-11-23 20:40:46 +00:00
|
|
|
onSpaceDelete(e) {
|
2017-11-22 11:02:35 +00:00
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
let spaceName = this.get('space').get('name');
|
|
|
|
let spaceNameTyped = this.get('deleteSpaceName');
|
|
|
|
|
|
|
|
if (spaceNameTyped !== spaceName || spaceNameTyped === '' || spaceName === '') {
|
|
|
|
$("#delete-space-name").addClass("is-invalid").focus();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.set('deleteSpaceName', '');
|
|
|
|
$("#delete-space-name").removeClass("is-invalid");
|
|
|
|
|
2018-01-22 10:31:03 +00:00
|
|
|
let cb = this.get('onDeleteSpace');
|
|
|
|
cb(this.get('space.id'));
|
2017-12-05 19:03:38 +00:00
|
|
|
|
|
|
|
this.modalClose('#space-delete-modal');
|
2017-11-21 14:47:49 +00:00
|
|
|
},
|
|
|
|
|
2017-12-15 13:41:20 +00:00
|
|
|
onShowEmptyDocModal() {
|
|
|
|
this.modalOpen("#empty-doc-modal", {"show": true}, '#empty-doc-name');
|
|
|
|
},
|
|
|
|
|
|
|
|
onAddEmptyDoc(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
let docName = this.get('emptyDocName');
|
|
|
|
|
|
|
|
if (is.empty(docName)) {
|
|
|
|
this.set('emptyDocNameError', true);
|
|
|
|
$('#empty-doc-name').focus();
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
this.set('emptyDocNameError', false);
|
|
|
|
this.set('emptyDocName', '');
|
|
|
|
}
|
|
|
|
|
|
|
|
this.modalClose("#empty-doc-modal");
|
|
|
|
|
|
|
|
this.get('templateService').importSavedTemplate(this.get('space.id'), '0', docName).then((document) => {
|
|
|
|
this.get('router').transitionTo('document', this.get('space.id'), this.get('space.slug'), document.get('id'), document.get('slug'));
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
onShowTemplateDocModal() {
|
|
|
|
let t = this.get('templates');
|
2018-01-24 13:23:11 +00:00
|
|
|
t.forEach((t) => {
|
|
|
|
t.set('selected', false);
|
|
|
|
});
|
|
|
|
this.modalOpen("#template-doc-modal", {"show": true}, '#template-doc-name');
|
2017-12-15 13:41:20 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onSelectTemplate(i) {
|
|
|
|
let t = this.get('templates');
|
|
|
|
t.forEach((t) => {
|
|
|
|
t.set('selected', false);
|
2018-01-24 13:23:11 +00:00
|
|
|
});
|
2017-12-15 13:41:20 +00:00
|
|
|
i.set('selected', true);
|
|
|
|
this.set('selectedTemplate', i.id);
|
|
|
|
},
|
|
|
|
|
|
|
|
onAddTemplateDoc(e) {
|
2017-11-21 14:47:49 +00:00
|
|
|
e.preventDefault();
|
2017-12-15 13:41:20 +00:00
|
|
|
let docName = this.get('templateDocName');
|
|
|
|
|
|
|
|
if (is.empty(docName)) {
|
|
|
|
this.set('templateDocNameError', true);
|
|
|
|
$('#template-doc-name').focus();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let id = this.get('selectedTemplate');
|
|
|
|
if (is.empty(id)) {
|
2018-01-24 13:23:11 +00:00
|
|
|
$('#widget-list-picker').addClass('is-invalid');
|
2017-12-15 13:41:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-24 13:23:11 +00:00
|
|
|
this.set('templateDocNameError', false);
|
|
|
|
this.set('templateDocName', '');
|
|
|
|
|
2017-12-15 13:41:20 +00:00
|
|
|
this.modalClose("#template-doc-modal");
|
|
|
|
|
|
|
|
this.get('templateService').importSavedTemplate(this.get('space.id'), id, docName).then((document) => {
|
|
|
|
this.get('router').transitionTo('document', this.get('space.id'), this.get('space.slug'), document.get('id'), document.get('slug'));
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
onShowImportDocModal() {
|
|
|
|
this.modalOpen("#import-doc-modal", {"show": true});
|
|
|
|
|
|
|
|
this.setupImport();
|
|
|
|
this.modalOnShown('#import-doc-modal', function() {
|
|
|
|
schedule('afterRender', ()=> {
|
|
|
|
});
|
|
|
|
});
|
2017-11-22 17:27:09 +00:00
|
|
|
},
|
|
|
|
|
2017-12-15 13:41:20 +00:00
|
|
|
onDocumentImporting(filename) {
|
|
|
|
let status = this.get('importStatus');
|
|
|
|
let documents = this.get('importedDocuments');
|
|
|
|
|
|
|
|
status.pushObject(`Converting ${filename}...`);
|
|
|
|
documents.push(filename);
|
|
|
|
|
|
|
|
this.set('importStatus', status);
|
|
|
|
this.set('importedDocuments', documents);
|
2017-11-22 17:27:09 +00:00
|
|
|
},
|
|
|
|
|
2017-12-15 13:41:20 +00:00
|
|
|
onDocumentImported(filename /*, document*/ ) {
|
|
|
|
let status = this.get('importStatus');
|
|
|
|
let documents = this.get('importedDocuments');
|
|
|
|
|
|
|
|
status.pushObject(`Successfully converted ${filename}`);
|
|
|
|
documents.pop(filename);
|
|
|
|
|
|
|
|
this.set('importStatus', status);
|
|
|
|
this.set('importedDocuments', documents);
|
|
|
|
|
|
|
|
if (documents.length === 0) {
|
2018-01-22 10:31:03 +00:00
|
|
|
this.modalClose("#import-doc-modal");
|
|
|
|
let cb = this.get('onRefresh');
|
|
|
|
cb();
|
2017-12-15 13:41:20 +00:00
|
|
|
}
|
2018-07-28 11:43:45 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
onShowExport() {
|
|
|
|
this.modalOpen("#space-export-modal", {"show": true});
|
|
|
|
},
|
|
|
|
|
|
|
|
onExport() {
|
2018-07-29 10:59:24 -04:00
|
|
|
this.showWait();
|
|
|
|
|
2018-07-28 11:43:45 -04:00
|
|
|
let spec = {
|
|
|
|
spaceId: this.get('space.id'),
|
|
|
|
data: [],
|
|
|
|
filterType: '',
|
2018-07-29 10:59:24 -04:00
|
|
|
};
|
2018-07-28 11:43:45 -04:00
|
|
|
|
|
|
|
let cats = this.get('categories');
|
|
|
|
cats.forEach((cat) => {
|
|
|
|
if (cat.get('exportSelected')) spec.data.push(cat.get('id'));
|
|
|
|
});
|
|
|
|
|
|
|
|
if (spec.data.length > 0) {
|
|
|
|
spec.filterType = 'category';
|
|
|
|
} else {
|
|
|
|
spec.filterType = 'space';
|
|
|
|
spec.data.push(this.get('space.id'));
|
|
|
|
}
|
|
|
|
|
|
|
|
this.get('documentSvc').export(spec).then((htmlExport) => {
|
|
|
|
this.get('browserSvc').downloadFile(htmlExport, this.get('space.slug') + '.html');
|
2018-07-29 10:59:24 -04:00
|
|
|
this.showDone();
|
2018-07-28 11:43:45 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
this.modalClose("#space-export-modal");
|
2017-11-21 14:47:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|