import { gMainApp, gAppConfig, gContentDocs, gEventBus } from "./MainApp.js" ; import { getASOPChapterIdFromSectionId, showWarningMsg } from "./utils.js" ; // -------------------------------------------------------------------- gMainApp.component( "nav-pane", { props: [ "asop" ], data() { return { ruleInfo: [], } ; }, template: `
`, created() { gEventBus.on( "show-target", (cdocId, ruleid) => { if ( gAppConfig.DISABLE_AUTO_SHOW_RULE_INFO ) return ; // get the Q+A and annotations for the target being opened // NOTE: Targets are associated with a content set, but the Q+A is global, which is not quite // the right thing to do - what if there is a ruleid that exists in multiple content set, // but is referenced in the Q+A? Hopefully, this will never happen... :-/ let url = gGetRuleInfoUrl.replace( "RULEID", ruleid ) ; //eslint-disable-line no-undef $.getJSON( url, (resp) => { if ( resp.length > 0 ) { // install the rule info entries this.ruleInfo = resp ; } } ).fail( (xhr, status, errorMsg) => { showWarningMsg( "Couldn't get the Q+A for " + ruleid + ".
" + errorMsg + "
" ) ; } ) ; } ) ; // close the rule info popup if Escape is pressed gEventBus.on( "escape-pressed", () => { if ( $( ".growl-footnote" ).length > 0 ) return ; // nb: unless a footnote on-screen (let the Escape close that instead) this.closeRuleInfo() ; } ) ; }, methods: { closeRuleInfo() { // close the rule info popup let isOpen = this.ruleInfo.length > 0 ; this.ruleInfo = [] ; return isOpen ; }, }, } ) ; // -------------------------------------------------------------------- gMainApp.component( "nav-pane-search", { data() { return { seqNo: 0, // nb: for the test suite } ; }, template: ` `, created() { // notify the test suite that the search results are now available gEventBus.on( "search-done", () => { this.seqNo += 1 ; } ) ; }, methods: { onSearch( queryString ) { // run the search (handled elsewhere) if ( $("#rule-info").css( "display" ) != "none" ) return ; // nb: dont respond to key-presses if the rule info popup is open gEventBus.emit( "search", queryString ) ; }, }, } ) ; // -------------------------------------------------------------------- gMainApp.component( "nav-pane-chapters", { data() { return { chapters: [], } ; }, template: `
No chapters.
`, created() { // initialize the chapters gEventBus.on( "app-loaded", () => { Object.values( gContentDocs ).forEach( (cdoc) => { if ( ! cdoc.chapters ) return ; cdoc.chapters.forEach( (chapter) => { this.chapters.push( [ cdoc.cdoc_id, chapter ] ) ; } ) ; } ) ; } ) ; }, methods: { onChapterPaneExpanded( chapter, isClick ) { //eslint-disable-line no-unused-vars // show the first page of the specified chapter gEventBus.emit( "show-page", chapter[0], chapter[1].page_no ) ; }, onChapterEntryClicked( paneKey, entry ) { // show the chapter entry's target gEventBus.emit( "show-target", paneKey[0], entry.ruleid ) ; }, getEntryKey( entry ) { return entry.ruleid ; }, }, } ) ; // -------------------------------------------------------------------- gMainApp.component( "nav-pane-asop", { props: [ "asop" ], data() { return { footer: null, } ; }, template: `