mirror of
https://github.com/documize/community.git
synced 2025-07-21 06:09:42 +02:00
upgraded Ember and Bootstrap, merged changes
This commit is contained in:
parent
b4fd42da38
commit
5dd7d9c181
114 changed files with 9814 additions and 1361 deletions
|
@ -9,101 +9,119 @@
|
|||
//
|
||||
// https://documize.com
|
||||
|
||||
import $ from 'jquery';
|
||||
import { computed } from '@ember/object';
|
||||
import { schedule } from '@ember/runloop';
|
||||
import { inject as service } from '@ember/service';
|
||||
import Component from '@ember/component';
|
||||
import tocUtil from '../../utils/toc';
|
||||
import TooltipMixin from '../../mixins/tooltip';
|
||||
|
||||
export default Component.extend({
|
||||
export default Component.extend(TooltipMixin, {
|
||||
documentService: service('document'),
|
||||
document: {},
|
||||
folder: {},
|
||||
pages: [],
|
||||
currentPageId: '',
|
||||
state: {
|
||||
actionablePage: false,
|
||||
upDisabled: true,
|
||||
downDisabled: true,
|
||||
indentDisabled: true,
|
||||
outdentDisabled: true
|
||||
},
|
||||
isDesktop: false,
|
||||
emptyState: computed('pages', function () {
|
||||
return this.get('pages.length') === 0;
|
||||
}),
|
||||
isDesktop: false,
|
||||
canEdit: computed('permssions', 'document', function() {
|
||||
let constants = this.get('constants');
|
||||
let permissions = this.get('permissions');
|
||||
let authenticated = this.get('session.authenticated');
|
||||
let notEmpty = this.get('pages.length') > 0;
|
||||
|
||||
if (notEmpty && authenticated && permissions.get('documentEdit') && this.get('document.protection') === constants.ProtectionType.None) return true;
|
||||
if (notEmpty && authenticated && permissions.get('documentApprove') && this.get('document.protection') === constants.ProtectionType.Review) return true;
|
||||
|
||||
return false;
|
||||
}),
|
||||
|
||||
init() {
|
||||
this._super(...arguments);
|
||||
this.state = {
|
||||
actionablePage: false,
|
||||
upDisabled: true,
|
||||
downDisabled: true,
|
||||
indentDisabled: true,
|
||||
outdentDisabled: true,
|
||||
pageId: ''
|
||||
};
|
||||
},
|
||||
|
||||
didReceiveAttrs() {
|
||||
this._super(...arguments);
|
||||
this.setState(this.get('currentPageId'));
|
||||
let cp = this.get('currentPageId');
|
||||
this.setState(is.empty(cp) ? '' : cp);
|
||||
},
|
||||
|
||||
didInsertElement() {
|
||||
this._super(...arguments);
|
||||
|
||||
this.setSize();
|
||||
this.eventBus.subscribe('documentPageAdded', this, 'onDocumentPageAdded');
|
||||
this.eventBus.subscribe('resized', this, 'onResize');
|
||||
this.attachResizer();
|
||||
this.eventBus.subscribe('resized', this, 'setSize');
|
||||
|
||||
this.setSize();
|
||||
this.renderTooltips();
|
||||
},
|
||||
|
||||
willDestroyElement() {
|
||||
this._super(...arguments);
|
||||
|
||||
this.eventBus.unsubscribe('documentPageAdded');
|
||||
this.eventBus.unsubscribe('resized');
|
||||
|
||||
let t = '#doc-toc';
|
||||
if (interact.isSet(t)) {
|
||||
interact(t).unset();
|
||||
}
|
||||
if (interact.isSet(t)) interact(t).unset();
|
||||
this.removeTooltips();
|
||||
},
|
||||
|
||||
onDocumentPageAdded(pageId) {
|
||||
this.send('onEntryClick', pageId);
|
||||
this.setSize();
|
||||
},
|
||||
|
||||
onResize() {
|
||||
this.setSize();
|
||||
this.send('onGotoPage', pageId);
|
||||
},
|
||||
|
||||
setSize() {
|
||||
let isDesktop = $(window).width() >= 1800;
|
||||
this.set('isDesktop', isDesktop);
|
||||
schedule('afterRender', () => {
|
||||
let isDesktop = $(window).width() >= 1800;
|
||||
this.set('isDesktop', isDesktop);
|
||||
|
||||
if (isDesktop) {
|
||||
let h = $(window).height() - $("#nav-bar").height() - 140;
|
||||
$("#doc-toc").css('max-height', h);
|
||||
|
||||
let i = $("#doc-view").offset();
|
||||
|
||||
if (is.not.undefined(i)) {
|
||||
let l = i.left - 100;
|
||||
if (l > 350) l = 350;
|
||||
$("#doc-toc").width(l);
|
||||
if (isDesktop) {
|
||||
let h = $(window).height() - $("#nav-bar").height() - 140;
|
||||
$("#doc-toc").css('max-height', h);
|
||||
|
||||
let i = $("#doc-view").offset();
|
||||
|
||||
if (is.not.undefined(i)) {
|
||||
let l = i.left - 100;
|
||||
if (l > 350) l = 350;
|
||||
$("#doc-toc").width(l);
|
||||
|
||||
$("#doc-toc").css({
|
||||
'display': 'inline-block',
|
||||
'position': 'fixed',
|
||||
'width': l+'px',
|
||||
'height': 'auto',
|
||||
'transform': '',
|
||||
});
|
||||
|
||||
this.attachResizer();
|
||||
}
|
||||
} else {
|
||||
$("#doc-toc").css({
|
||||
'display': 'inline-block',
|
||||
'position': 'fixed',
|
||||
'width': l+'px',
|
||||
'height': 'auto',
|
||||
'transform': '',
|
||||
'display': 'block',
|
||||
'position': 'relative',
|
||||
'width': '100%',
|
||||
'height': '500px',
|
||||
'transform': 'none',
|
||||
});
|
||||
}
|
||||
} else {
|
||||
$("#doc-toc").css({
|
||||
'display': 'block',
|
||||
'position': 'relative',
|
||||
'width': '100%',
|
||||
'height': '500px',
|
||||
'transform': 'none',
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
attachResizer() {
|
||||
schedule('afterRender', () => {
|
||||
let t = '#doc-toc';
|
||||
if (interact.isSet(t)) {
|
||||
interact(t).unset();
|
||||
}
|
||||
|
||||
interact('#doc-toc')
|
||||
.draggable({
|
||||
autoScroll: true,
|
||||
|
@ -166,15 +184,12 @@ export default Component.extend({
|
|||
},
|
||||
|
||||
// Controls what user can do with the toc (left sidebar)
|
||||
// Identifies the target pages
|
||||
setState(pageId) {
|
||||
this.set('currentPageId', pageId);
|
||||
|
||||
let toc = this.get('pages');
|
||||
let page = _.findWhere(toc, { id: pageId });
|
||||
let state = tocUtil.getState(toc, page);
|
||||
let page = _.find(toc, function(i) { return i.get('page.id') === pageId; });
|
||||
let state = tocUtil.getState(toc, is.not.undefined(page) ? page.get('page') : page);
|
||||
|
||||
if (!this.get('permissions.documentEdit') || is.empty(pageId)) {
|
||||
if (!this.get('canEdit')) {
|
||||
state.actionablePage = false;
|
||||
state.upDisabled = state.downDisabled = state.indentDisabled = state.outdentDisabled = true;
|
||||
}
|
||||
|
@ -185,77 +200,77 @@ export default Component.extend({
|
|||
actions: {
|
||||
// Page up -- above pages shunt down
|
||||
pageUp() {
|
||||
if (this.get('state.upDisabled')) {
|
||||
let state = this.get('state');
|
||||
|
||||
if (state.upDisabled || this.get('document.protection') !== this.get('constants').ProtectionType.None) {
|
||||
return;
|
||||
}
|
||||
|
||||
let state = this.get('state');
|
||||
let pages = this.get('pages');
|
||||
let page = _.findWhere(pages, { id: this.get('currentPageId') });
|
||||
let pendingChanges = tocUtil.moveUp(state, pages, page);
|
||||
let page = _.find(pages, function(i) { return i.get('page.id') === state.pageId; });
|
||||
if (is.not.undefined(page)) page = page.get('page');
|
||||
|
||||
let pendingChanges = tocUtil.moveUp(state, pages, page);
|
||||
if (pendingChanges.length > 0) {
|
||||
this.attrs.onPageSequenceChange(pendingChanges);
|
||||
let cb = this.get('onPageSequenceChange');
|
||||
cb(state.pageId, pendingChanges);
|
||||
}
|
||||
},
|
||||
|
||||
// Move down -- pages below shift up
|
||||
pageDown() {
|
||||
if (this.get('state.downDisabled')) {
|
||||
return;
|
||||
}
|
||||
if (!this.get('canEdit')) return;
|
||||
|
||||
let state = this.get('state');
|
||||
var pages = this.get('pages');
|
||||
var page = _.findWhere(pages, { id: this.get('currentPageId') });
|
||||
let pendingChanges = tocUtil.moveDown(state, pages, page);
|
||||
let pages = this.get('pages');
|
||||
let page = _.find(pages, function(i) { return i.get('page.id') === state.pageId; });
|
||||
if (is.not.undefined(page)) page = page.get('page');
|
||||
|
||||
let pendingChanges = tocUtil.moveDown(state, pages, page);
|
||||
if (pendingChanges.length > 0) {
|
||||
this.attrs.onPageSequenceChange(pendingChanges);
|
||||
let cb = this.get('onPageSequenceChange');
|
||||
cb(state.pageId, pendingChanges);
|
||||
}
|
||||
},
|
||||
|
||||
// Indent -- changes a page from H2 to H3, etc.
|
||||
pageIndent() {
|
||||
if (this.get('state.indentDisabled')) {
|
||||
return;
|
||||
}
|
||||
if (!this.get('canEdit')) return;
|
||||
|
||||
let state = this.get('state');
|
||||
var pages = this.get('pages');
|
||||
var page = _.findWhere(pages, { id: this.get('currentPageId') });
|
||||
let pendingChanges = tocUtil.indent(state, pages, page);
|
||||
let pages = this.get('pages');
|
||||
let page = _.find(pages, function(i) { return i.get('page.id') === state.pageId; });
|
||||
if (is.not.undefined(page)) page = page.get('page');
|
||||
|
||||
let pendingChanges = tocUtil.indent(state, pages, page);
|
||||
if (pendingChanges.length > 0) {
|
||||
this.attrs.onPageLevelChange(pendingChanges);
|
||||
let cb = this.get('onPageLevelChange');
|
||||
cb(state.pageId, pendingChanges);
|
||||
}
|
||||
},
|
||||
|
||||
// Outdent -- changes a page from H3 to H2, etc.
|
||||
pageOutdent() {
|
||||
if (this.get('state.outdentDisabled')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.get('canEdit')) return;
|
||||
|
||||
let state = this.get('state');
|
||||
var pages = this.get('pages');
|
||||
var page = _.findWhere(pages, { id: this.get('currentPageId') });
|
||||
let pendingChanges = tocUtil.outdent(state, pages, page);
|
||||
let pages = this.get('pages');
|
||||
let page = _.find(pages, function(i) { return i.get('page.id') === state.pageId; });
|
||||
if (is.not.undefined(page)) page = page.get('page');
|
||||
|
||||
let pendingChanges = tocUtil.outdent(state, pages, page);
|
||||
if (pendingChanges.length > 0) {
|
||||
this.attrs.onPageLevelChange(pendingChanges);
|
||||
let cb = this.get('onPageLevelChange');
|
||||
cb(state.pageId, pendingChanges);
|
||||
}
|
||||
},
|
||||
|
||||
onEntryClick(id) {
|
||||
if (id !== '') {
|
||||
let jumpTo = "#page-" + id;
|
||||
this.set('tab', 'content');
|
||||
if (!$(jumpTo).inView()) {
|
||||
$(jumpTo).velocity("scroll", { duration: 250, offset: -100 });
|
||||
}
|
||||
this.setState(id);
|
||||
}
|
||||
onGotoPage(id) {
|
||||
if (id === '') return;
|
||||
this.setState(id);
|
||||
|
||||
let cb = this.get('onShowPage');
|
||||
cb(id);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue