2016-10-23 18:33:07 -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';
|
2016-10-24 19:20:29 -07:00
|
|
|
import TooltipMixin from '../../mixins/tooltip';
|
2016-10-23 18:33:07 -07:00
|
|
|
|
|
|
|
const {
|
|
|
|
inject: { service }
|
|
|
|
} = Ember;
|
|
|
|
|
2016-10-24 19:20:29 -07:00
|
|
|
export default Ember.Component.extend(TooltipMixin, {
|
2016-10-23 18:33:07 -07:00
|
|
|
link: service(),
|
|
|
|
hasSections: false,
|
|
|
|
hasAttachments: false,
|
|
|
|
linkName: '',
|
2016-10-24 19:20:29 -07:00
|
|
|
keywords: '',
|
2016-10-23 18:33:07 -07:00
|
|
|
selection: null,
|
|
|
|
|
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
|
|
|
let self = this;
|
|
|
|
|
|
|
|
let documentId = this.get('document.id');
|
|
|
|
let pageId = this.get('page.id');
|
|
|
|
|
|
|
|
this.get('link').getCandidates(documentId, pageId).then(function (candidates) {
|
|
|
|
self.set('candidates', candidates);
|
|
|
|
self.set('hasSections', is.not.null(candidates.pages) && candidates.pages.length);
|
|
|
|
self.set('hasAttachments', is.not.null(candidates.attachments) && candidates.attachments.length);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-10-24 19:20:29 -07:00
|
|
|
didRender() {
|
|
|
|
this.addTooltip(document.getElementById("content-linker-button"));
|
|
|
|
},
|
2016-10-23 18:33:07 -07:00
|
|
|
|
2016-10-24 19:20:29 -07:00
|
|
|
willDestroyElement() {
|
|
|
|
this.destroyTooltips();
|
|
|
|
},
|
2016-10-23 18:33:07 -07:00
|
|
|
|
|
|
|
actions: {
|
2016-10-24 19:20:29 -07:00
|
|
|
setSelection(i) {
|
|
|
|
this.set('selection', i);
|
|
|
|
|
|
|
|
let candidates = this.get('candidates');
|
|
|
|
|
|
|
|
candidates.pages.forEach(c => {
|
|
|
|
Ember.set(c, 'selected', c.id === i.id);
|
|
|
|
});
|
|
|
|
|
|
|
|
candidates.attachments.forEach(c => {
|
|
|
|
Ember.set(c, 'selected', c.id === i.id);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-10-23 18:33:07 -07:00
|
|
|
onInsertLink() {
|
|
|
|
let selection = this.get('selection');
|
|
|
|
|
2016-10-24 19:20:29 -07:00
|
|
|
if (is.null(selection)) {
|
|
|
|
return;
|
2016-10-23 18:33:07 -07:00
|
|
|
}
|
|
|
|
|
2016-10-24 19:20:29 -07:00
|
|
|
return this.get('onInsertLink')(selection);
|
2016-10-23 18:33:07 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|