Changed how we open a content doc at a specific target/page.

master
Pacman Ghost 3 years ago
parent a81bba9d67
commit 3e8386ad8e
  1. 41
      asl_rulebook2/webapp/static/ContentPane.js

@ -13,8 +13,8 @@ gMainApp.component( "content-pane", {
template: `
<div>
<tabbed-pages tabbedPagesId="content" ref="tabbedPages">
<tabbed-page v-for="cdoc in loadedContentDocs" :tabId=cdoc.cdoc_id :caption=cdoc.title :key=cdoc.cdoc_id >
<content-doc :cdoc=cdoc />
<tabbed-page v-for="lcdoc in loadedContentDocs" :tabId=lcdoc.cdoc.cdoc_id :caption=lcdoc.cdoc.title :key=lcdoc.cdoc.cdoc_id >
<content-doc :cdoc=lcdoc.cdoc :initRuleid=lcdoc.initRuleid :initPageNo=lcdoc.initPageNo />
</tabbed-page>
</tabbed-pages>
<asop />
@ -36,38 +36,25 @@ gMainApp.component( "content-pane", {
},
mounted() {
const showContentDoc = (cdocId) => {
const showContentDoc = (cdocId, initRuleid, initPageNo) => {
// check if the content doc has already been loaded
let cdoc = this.loadedContentDocs[ cdocId ] ;
if ( cdoc == undefined ) {
if ( this.loadedContentDocs[ cdocId ] == undefined ) {
// nope - load it
this.loadedContentDocs[ cdocId ] = this.contentDocs[ cdocId ] ;
this.loadedContentDocs[ cdocId ] = {
cdoc: this.contentDocs[ cdocId ],
initRuleid: initRuleid,
initPageNo: initPageNo,
} ;
}
this.$nextTick( () => {
this.$refs.tabbedPages.activateTab( cdocId ) ; // nb: tabId == cdocId
} ) ;
return (cdoc == undefined) ;
}
gEventBus.on( "show-target", (cdocId, ruleid) => { //eslint-disable-line no-unused-vars
let wasLoaded = showContentDoc( cdocId ) ;
if ( wasLoaded ) {
// FUDGE! If we just loaded a new content doc, it won't have been around to receive
// the "show-target" event, so we re-issue it here. This might cause some minor
// problems (e.g. footnotes showing twice), but we seem to be OK.
this.$nextTick( () => {
gEventBus.emit( "show-target", cdocId, ruleid ) ;
} ) ;
}
showContentDoc( cdocId, ruleid, null ) ;
} ) ;
gEventBus.on( "show-page", (cdocId, pageNo) => { //eslint-disable-line no-unused-vars
let wasLoaded = showContentDoc( cdocId ) ;
if ( wasLoaded ) {
// FUDGE! If we just loaded a new content doc, it won't have been around to receive
// the "show-page" event, so we re-issue it here.
this.$nextTick( () => {
gEventBus.emit( "show-page", cdocId, pageNo ) ;
} ) ;
}
showContentDoc( cdocId, null, pageNo ) ;
} ) ;
},
@ -75,7 +62,7 @@ gMainApp.component( "content-pane", {
// make sure the test empty document is loaded
let cdoc = this.contentDocs[ "empty" ] ;
if ( cdoc != undefined )
this.loadedContentDocs[ "empty" ] = cdoc ;
this.loadedContentDocs[ "empty" ] = { cdoc: cdoc } ;
},
methods: {
@ -171,9 +158,9 @@ gMainApp.component( "content-pane", {
gMainApp.component( "content-doc", {
props: [ "cdoc" ],
props: [ "cdoc", "initRuleid", "initPageNo" ],
data() { return {
ruleid: null, pageNo: null,
ruleid: this.initRuleid, pageNo: this.initPageNo,
noContent: gUrlParams.get( "no-content" ),
} ; },

Loading…
Cancel
Save