2016-07-07 18:54:16 -07:00
|
|
|
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
|
|
|
//
|
2016-11-01 14:00:23 -07:00
|
|
|
// This software (Documize Community Edition) is licensed under
|
2016-07-07 18:54:16 -07:00
|
|
|
// 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
|
2016-11-01 14:00:23 -07:00
|
|
|
// by contacting <sales@documize.com>.
|
2016-07-07 18:54:16 -07:00
|
|
|
//
|
|
|
|
// https://documize.com
|
|
|
|
|
|
|
|
import Ember from 'ember';
|
2016-11-06 20:11:21 -08:00
|
|
|
import NotifierMixin from '../../mixins/notifier';
|
2016-07-07 18:54:16 -07:00
|
|
|
|
|
|
|
export default Ember.Controller.extend(NotifierMixin, {
|
|
|
|
documentService: Ember.inject.service('document'),
|
|
|
|
folderService: Ember.inject.service('folder'),
|
2017-07-20 11:37:38 +01:00
|
|
|
localStorage: Ember.inject.service('localStorage'),
|
2016-07-07 18:54:16 -07:00
|
|
|
selectedDocuments: [],
|
2017-08-17 18:31:19 +01:00
|
|
|
hasSelectedDocuments: Ember.computed.gt('selectedDocuments.length', 0),
|
2017-03-24 13:10:32 +00:00
|
|
|
queryParams: ['tab'],
|
|
|
|
tab: 'index',
|
2016-07-07 18:54:16 -07:00
|
|
|
|
|
|
|
actions: {
|
|
|
|
onMoveDocument(folder) {
|
|
|
|
let self = this;
|
|
|
|
let documents = this.get('selectedDocuments');
|
|
|
|
|
|
|
|
documents.forEach(function (documentId) {
|
|
|
|
self.get('documentService').getDocument(documentId).then(function (doc) {
|
|
|
|
doc.set('folderId', folder);
|
2017-04-12 18:00:52 +01:00
|
|
|
doc.set('selected', !doc.get('selected'));
|
2016-07-07 18:54:16 -07:00
|
|
|
self.get('documentService').save(doc).then(function () {
|
2017-08-08 11:24:21 +01:00
|
|
|
self.get('target._routerMicrolib').refresh();
|
2016-07-07 18:54:16 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
this.set('selectedDocuments', []);
|
|
|
|
this.send("showNotification", "Moved");
|
|
|
|
},
|
|
|
|
|
|
|
|
onDeleteDocument() {
|
|
|
|
let documents = this.get('selectedDocuments');
|
|
|
|
let self = this;
|
2017-08-17 18:31:19 +01:00
|
|
|
let promises = [];
|
2016-07-07 18:54:16 -07:00
|
|
|
|
2017-08-17 18:31:19 +01:00
|
|
|
documents.forEach(function (document, index) {
|
|
|
|
promises[index] = self.get('documentService').deleteDocument(document);
|
2016-07-07 18:54:16 -07:00
|
|
|
});
|
|
|
|
|
2017-08-17 18:31:19 +01:00
|
|
|
Ember.RSVP.all(promises).then(() => {
|
|
|
|
let documents = this.get('model.documents');
|
|
|
|
documents.forEach(function (document) {
|
|
|
|
document.set('selected', false);
|
|
|
|
});
|
|
|
|
this.set('model.documents', documents);
|
|
|
|
|
|
|
|
this.set('selectedDocuments', []);
|
|
|
|
this.send("showNotification", "Deleted");
|
|
|
|
this.get('target._routerMicrolib').refresh();
|
|
|
|
});
|
2016-07-07 18:54:16 -07:00
|
|
|
},
|
|
|
|
|
2017-08-21 17:51:06 +01:00
|
|
|
onAddSpace(payload) {
|
2016-07-07 18:54:16 -07:00
|
|
|
let self = this;
|
|
|
|
this.showNotification("Added");
|
|
|
|
|
2017-08-21 17:51:06 +01:00
|
|
|
this.get('folderService').add(payload).then(function (newFolder) {
|
2016-07-07 18:54:16 -07:00
|
|
|
self.get('folderService').setCurrentFolder(newFolder);
|
2016-11-06 20:11:21 -08:00
|
|
|
self.transitionToRoute('folder', newFolder.get('id'), newFolder.get('slug'));
|
2016-07-07 18:54:16 -07:00
|
|
|
});
|
2017-03-24 13:10:32 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onDeleteSpace() {
|
|
|
|
this.get('folderService').delete(this.get('model.folder.id')).then(() => { /* jshint ignore:line */
|
|
|
|
this.showNotification("Deleted");
|
|
|
|
this.get('localStorage').clearSessionItem('folder');
|
|
|
|
this.transitionToRoute('application');
|
|
|
|
});
|
2017-03-24 17:43:41 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onImport() {
|
2017-08-08 11:24:21 +01:00
|
|
|
this.get('target._routerMicrolib').refresh();
|
2016-07-07 18:54:16 -07:00
|
|
|
}
|
|
|
|
}
|
2016-11-01 14:00:23 -07:00
|
|
|
});
|