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';
|
|
|
|
import TooltipMixin from '../../mixins/tooltip';
|
|
|
|
|
|
|
|
export default Ember.Component.extend(NotifierMixin, TooltipMixin, {
|
2016-07-08 16:08:23 -07:00
|
|
|
appMeta: Ember.inject.service(),
|
|
|
|
userService: Ember.inject.service('user'),
|
|
|
|
localStorage: Ember.inject.service(),
|
|
|
|
drop: null,
|
|
|
|
users: [],
|
2016-11-08 16:10:19 -08:00
|
|
|
menuOpen: false,
|
2016-07-08 16:08:23 -07:00
|
|
|
saveTemplate: {
|
|
|
|
name: "",
|
|
|
|
description: ""
|
|
|
|
},
|
2016-11-21 19:27:18 -08:00
|
|
|
pinned: Ember.inject.service(),
|
|
|
|
pinState : {
|
|
|
|
isPinned: false,
|
|
|
|
pinId: '',
|
|
|
|
newName: '',
|
|
|
|
},
|
2016-07-07 18:54:16 -07:00
|
|
|
|
|
|
|
didReceiveAttrs() {
|
|
|
|
this.set('saveTemplate.name', this.get('document.name'));
|
|
|
|
this.set('saveTemplate.description', this.get('document.excerpt'));
|
2016-11-20 19:55:52 -08:00
|
|
|
|
|
|
|
let doc = this.get('document');
|
|
|
|
|
|
|
|
this.set('layoutLabel', doc.get('layout') === 'doc' ? 'Wiki style' : 'Document style');
|
2016-11-21 19:27:18 -08:00
|
|
|
|
|
|
|
this.set('pinState.pinId', this.get('pinned').isDocumentPinned(doc.get('id')));
|
|
|
|
this.set('pinState.isPinned', this.get('pinState.pinId') !== '');
|
|
|
|
this.set('pinState.newName', doc.get('name').substring(0,3).toUpperCase());
|
2016-07-07 18:54:16 -07:00
|
|
|
},
|
|
|
|
|
2016-11-09 15:16:44 -08:00
|
|
|
didRender() {
|
|
|
|
if (this.session.isEditor) {
|
|
|
|
this.addTooltip(document.getElementById("add-document-tab"));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-07-08 16:08:23 -07:00
|
|
|
willDestroyElement() {
|
|
|
|
this.destroyTooltips();
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
2016-11-08 16:10:19 -08:00
|
|
|
onMenuOpen() {
|
|
|
|
this.set('menuOpen', !this.get('menuOpen'));
|
|
|
|
},
|
|
|
|
|
2016-07-07 18:54:16 -07:00
|
|
|
deleteDocument() {
|
|
|
|
this.attrs.onDocumentDelete();
|
2016-07-08 16:08:23 -07:00
|
|
|
},
|
2016-07-07 18:54:16 -07:00
|
|
|
|
|
|
|
printDocument() {
|
|
|
|
window.print();
|
2016-07-08 16:08:23 -07:00
|
|
|
},
|
2016-07-07 18:54:16 -07:00
|
|
|
|
2016-11-20 19:55:52 -08:00
|
|
|
changeLayout() {
|
|
|
|
let doc = this.get('document');
|
|
|
|
let layout = doc.get('layout') === 'doc' ? 'wiki' : 'doc';
|
|
|
|
|
|
|
|
doc.set('layout', layout);
|
|
|
|
|
|
|
|
this.attrs.onSaveMeta(doc);
|
|
|
|
|
|
|
|
this.set('layoutLabel', doc.get('layout') === 'doc' ? 'Wiki style' : 'Document style');
|
|
|
|
},
|
|
|
|
|
2016-07-08 16:08:23 -07:00
|
|
|
saveTemplate() {
|
|
|
|
var name = this.get('saveTemplate.name');
|
|
|
|
var excerpt = this.get('saveTemplate.description');
|
2016-07-07 18:54:16 -07:00
|
|
|
|
2016-07-08 16:08:23 -07:00
|
|
|
if (is.empty(name)) {
|
|
|
|
$("#new-template-name").addClass("error").focus();
|
|
|
|
return false;
|
|
|
|
}
|
2016-07-07 18:54:16 -07:00
|
|
|
|
2016-07-08 16:08:23 -07:00
|
|
|
if (is.empty(excerpt)) {
|
|
|
|
$("#new-template-desc").addClass("error").focus();
|
|
|
|
return false;
|
|
|
|
}
|
2016-07-07 18:54:16 -07:00
|
|
|
|
2016-07-08 16:08:23 -07:00
|
|
|
this.showNotification('Template saved');
|
|
|
|
this.attrs.onSaveTemplate(name, excerpt);
|
2016-07-07 18:54:16 -07:00
|
|
|
|
2016-07-08 16:08:23 -07:00
|
|
|
return true;
|
2016-11-20 13:41:43 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
saveMeta() {
|
|
|
|
let doc = this.get('document');
|
|
|
|
|
|
|
|
if (is.empty(doc.get('name'))) {
|
|
|
|
$("#meta-name").addClass("error").focus();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is.empty(doc.get('excerpt'))) {
|
|
|
|
$("#meta-excerpt").addClass("error").focus();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
doc.set('excerpt', doc.get('excerpt').substring(0, 250));
|
|
|
|
|
|
|
|
this.attrs.onSaveMeta(doc);
|
|
|
|
return true;
|
|
|
|
},
|
2016-11-21 19:27:18 -08:00
|
|
|
|
|
|
|
unpin() {
|
2016-11-22 10:05:32 -08:00
|
|
|
this.audit.record('unpinned-document');
|
|
|
|
|
2016-11-21 19:27:18 -08:00
|
|
|
this.get('pinned').unpinItem(this.get('pinState.pinId')).then(() => {
|
|
|
|
this.set('pinState.isPinned', false);
|
|
|
|
this.set('pinState.pinId', '');
|
|
|
|
this.eventBus.publish('pinChange');
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
pin() {
|
|
|
|
let pin = {
|
|
|
|
pin: this.get('pinState.newName'),
|
|
|
|
documentId: this.get('document.id'),
|
|
|
|
folderId: this.get('folder.id')
|
|
|
|
};
|
|
|
|
|
|
|
|
if (is.empty(pin.pin)) {
|
|
|
|
$("#pin-document-name").addClass("error").focus();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-22 10:05:32 -08:00
|
|
|
this.audit.record('pinned-document');
|
|
|
|
|
2016-11-21 19:27:18 -08:00
|
|
|
this.get('pinned').pinItem(pin).then((pin) => {
|
|
|
|
this.set('pinState.isPinned', true);
|
|
|
|
this.set('pinState.pinId', pin.get('id'));
|
|
|
|
this.eventBus.publish('pinChange');
|
|
|
|
});
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-07-08 16:08:23 -07:00
|
|
|
}
|
2016-11-20 13:41:43 -08:00
|
|
|
});
|