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: ` template: `
<div> <div>
<tabbed-pages tabbedPagesId="content" ref="tabbedPages"> <tabbed-pages tabbedPagesId="content" ref="tabbedPages">
<tabbed-page v-for="cdoc in loadedContentDocs" :tabId=cdoc.cdoc_id :caption=cdoc.title :key=cdoc.cdoc_id > <tabbed-page v-for="lcdoc in loadedContentDocs" :tabId=lcdoc.cdoc.cdoc_id :caption=lcdoc.cdoc.title :key=lcdoc.cdoc.cdoc_id >
<content-doc :cdoc=cdoc /> <content-doc :cdoc=lcdoc.cdoc :initRuleid=lcdoc.initRuleid :initPageNo=lcdoc.initPageNo />
</tabbed-page> </tabbed-page>
</tabbed-pages> </tabbed-pages>
<asop /> <asop />
@ -36,38 +36,25 @@ gMainApp.component( "content-pane", {
}, },
mounted() { mounted() {
const showContentDoc = (cdocId) => { const showContentDoc = (cdocId, initRuleid, initPageNo) => {
// check if the content doc has already been loaded // check if the content doc has already been loaded
let cdoc = this.loadedContentDocs[ cdocId ] ; if ( this.loadedContentDocs[ cdocId ] == undefined ) {
if ( cdoc == undefined ) {
// nope - load it // nope - load it
this.loadedContentDocs[ cdocId ] = this.contentDocs[ cdocId ] ; this.loadedContentDocs[ cdocId ] = {
cdoc: this.contentDocs[ cdocId ],
initRuleid: initRuleid,
initPageNo: initPageNo,
} ;
} }
this.$nextTick( () => { this.$nextTick( () => {
this.$refs.tabbedPages.activateTab( cdocId ) ; // nb: tabId == cdocId this.$refs.tabbedPages.activateTab( cdocId ) ; // nb: tabId == cdocId
} ) ; } ) ;
return (cdoc == undefined) ;
} }
gEventBus.on( "show-target", (cdocId, ruleid) => { //eslint-disable-line no-unused-vars gEventBus.on( "show-target", (cdocId, ruleid) => { //eslint-disable-line no-unused-vars
let wasLoaded = showContentDoc( cdocId ) ; showContentDoc( cdocId, ruleid, null ) ;
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 ) ;
} ) ;
}
} ) ; } ) ;
gEventBus.on( "show-page", (cdocId, pageNo) => { //eslint-disable-line no-unused-vars gEventBus.on( "show-page", (cdocId, pageNo) => { //eslint-disable-line no-unused-vars
let wasLoaded = showContentDoc( cdocId ) ; showContentDoc( cdocId, null, pageNo ) ;
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 ) ;
} ) ;
}
} ) ; } ) ;
}, },
@ -75,7 +62,7 @@ gMainApp.component( "content-pane", {
// make sure the test empty document is loaded // make sure the test empty document is loaded
let cdoc = this.contentDocs[ "empty" ] ; let cdoc = this.contentDocs[ "empty" ] ;
if ( cdoc != undefined ) if ( cdoc != undefined )
this.loadedContentDocs[ "empty" ] = cdoc ; this.loadedContentDocs[ "empty" ] = { cdoc: cdoc } ;
}, },
methods: { methods: {
@ -171,9 +158,9 @@ gMainApp.component( "content-pane", {
gMainApp.component( "content-doc", { gMainApp.component( "content-doc", {
props: [ "cdoc" ], props: [ "cdoc", "initRuleid", "initPageNo" ],
data() { return { data() { return {
ruleid: null, pageNo: null, ruleid: this.initRuleid, pageNo: this.initPageNo,
noContent: gUrlParams.get( "no-content" ), noContent: gUrlParams.get( "no-content" ),
} ; }, } ; },

Loading…
Cancel
Save