Produce a JavaScript array for the purpose of populating a navbar (navigation drop-down menu). The elements comprise the level (of the item in the menu), the page title and the page url. This format is assumed by the standard script _dsmScript_navbar which converts the array into a visible navbar. For the navbar to appear in a page, both array and script must appear within the output HMLL for the page, either within a <script> tag OR as a referred resources within tags of the form <script src="">. This function is used by the hdsApp::SetupScripts initialization function to prepare several scripts ahead of their use in pages. There are efficiency savings in doing this but it is imperative the navbar must not contain links to pages the visitor is not permitted to access. To this end, hdsApp::SetupScripts calls this function is called once for access level PUBLIC, once for access level of ADMIN and once for each of the user classes. This produces several variant navbar scripts and the page generation process selects the script to include in the page according to the user status.
| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | hdsApp::MakeNavbarJS | (hzChain&,hdsLang*,uint32_t,) |
Declared in file: hzDissemino.h
Defined in file : hdsScript.cpp
Function Logic:
Function body:
hzEcode hdsApp::MakeNavbarJS (hzChain& Z)hdsLang* pLang, uint32_t access,
{
// Category: HTML Generation
//
// Produce a JavaScript array for the purpose of populating a navbar (navigation drop-down menu). The elements comprise the level (of the item in the menu), the page title and
// the page url. This format is assumed by the standard script _dsmScript_navbar which converts the array into a visible navbar. For the navbar to appear in a page, both array
// and script must appear within the output HMLL for the page, either within a <script> tag OR as a referred resources within tags of the form <script src="">.
//
// This function is used by the hdsApp::SetupScripts initialization function to prepare several scripts ahead of their use in pages. There are efficiency savings in doing this
// but it is imperative the navbar must not contain links to pages the visitor is not permitted to access. To this end, hdsApp::SetupScripts calls this function is called once
// for access level PUBLIC, once for access level of ADMIN and once for each of the user classes. This produces several variant navbar scripts and the page generation process
// selects the script to include in the page according to the user status.
//
// Arguments: 1) Z The chain that will be populated with a script
// 2) pLang Currently applicable language
// 3) access The access level to which the script pertains
//
// Returns: E_OK If the navigation bar script is created
_hzfunc("hdsApp::MakeNavbarJS") ;
hzList<hzString>::Iter si ; // Subject iterator
hdsPage* pPage ; // Page within subject
uint32_t* counts ; // Counts of valid pages for each subject
hzString subject ; // Page subject
hzString S ; // Temp string
uint32_t x ; // Subject iterator
// uint32_t y ; // Page iterator (within subject)
uint32_t nLo ; // First Page of a given subject
uint32_t nHi ; // Last Page of a given subject
bool doComma ; // Comma control
if (!pLang)
pLang = m_pDfltLang ;
if (!pLang)
Fatal("No language supplied\n") ;
Z.Clear() ;
// counts = new uint32_t[m_vecPgSubjects.Count()] ;
counts = new uint32_t[m_lstPgSubjects.Count()] ;
// Go thru the subjects and the pages under the subjects and make a copy depending on access rights of pages.
// for (x = 0 ; x < m_vecPgSubjects.Count() ; x++)
for (si = m_lstPgSubjects, x = 0; si.Valid() ; x++, si++)
{
subject = si.Element() ;
counts[x] = 0;
nLo = m_mapSubj2Res.First(subject) ;
if (nLo < 0)
continue ;
nHi = m_mapSubj2Res.Last(subject) ;
for (; nLo <&eq; nHi ; nLo++)
{
pPage = m_mapSubj2Res.GetObj(nLo) ;
if (pPage->m_resAccess == ACCESS_PUBLIC || access == ACCESS_ADMIN
|| (pPage->m_resAccess == ACCESS_NOBODY && !access)
|| ((access & ACCESS_MASK) & pPage->m_resAccess))
{
m_pLog->Out("For access=%08x: Page %s (subj %s), acc=%08x\n", access, *pPage->m_Title, *pPage->m_Subj, pPage->m_resAccess) ;
counts[x] += 1;
}
}
}
/*
** for (x = 0 ; x < m_mapSubj2Res.Count() ; x++)
** {
** pSubj = m_vecPgSubjects[x] ;
**
** m_pLog->Log("NOTE: Subject [%s] has %d pages\n", *pSubj->subject, pSubj->pglist.Count()) ;
**
** counts[x] = 0 ;
** if (!pSubj->pglist.Count())
** continue ;
**
** for (y = 0 ; y < pSubj->pglist.Count() ; y++)
** {
** pPage = pSubj->pglist[y] ;
**
** // Only count if the page has correct access
** if (pPage->m_resAccess == ACCESS_PUBLIC || access == ACCESS_ADMIN
** || (pPage->m_resAccess == ACCESS_NOBODY && !access)
** || ((access & ACCESS_MASK) & pPage->m_resAccess))
** {
** m_pLog->Out("For access=%08x: Page %s (subj %s), acc=%08x\n", access, *pPage->m_Title, *pPage->m_Subj, pPage->m_resAccess) ;
** counts[x] += 1 ;
** }
** }
** }
** */
Z.Clear() ;
// Prepare headings
Z <<
"var pdmX = new Array();\npdmX = ["
;
doComma = false ;
// for (x = 0 ; x < m_vecPgSubjects.Count() ; x++)
for (si = m_lstPgSubjects, x = 0; si.Valid() ; x++, si++)
{
if (!counts[x])
continue ;
subject = si.Element() ;
// pSubj = m_vecPgSubjects[x] ;
// if (!pSubj->pglist.Count())
// continue ;
// Find value to print for subject
// if (pLang->m_MiscStrings.Exists(pSubj->m_USL)) langSubj = pLang->m_MiscStrings[pSubj->m_USL] ;
// else if (m_pDfltLang->m_MiscStrings.Exists(pSubj->m_USL)) langSubj = m_pDfltLang->m_MiscStrings[pSubj->m_USL] ;
// else
// langSubj = pSubj->subject ;
// Find value to print for subject's first page
// pPage = pSubj->pglist[0] ;
// if (pLang->m_MiscStrings.Exists(pPage->m_USL)) langTitl = pLang->m_MiscStrings[pPage->m_USL] ;
// else if (m_pDfltLang->m_MiscStrings.Exists(pPage->m_USL)) langTitl = m_pDfltLang->m_MiscStrings[pPage->m_USL] ;
// if (pLang->m_MiscStrings.Exists(pPage->m_RID)) langTitl = pLang->m_MiscStrings[pPage->m_RID] ;
// else if (m_pDfltLang->m_MiscStrings.Exists(pPage->m_RID)) langTitl = m_pDfltLang->m_MiscStrings[pPage->m_RID] ;
// else
// langTitl = pSubj->first ;
nLo = m_mapSubj2Res.First(subject) ;
if (nLo < 0)
continue ;
nHi = m_mapSubj2Res.Last(subject) ;
pPage = m_mapSubj2Res.GetObj(nLo) ;
// Write entry to script
if (doComma)
Z << ",\n" ;
if (nLo == nHi)
Z.Printf("[%d,\"%s\",\"%s\"]", x, *subject, *pPage->m_Url) ;
else
Z.Printf("[%d,\"%s\",\"\"]", x, *subject) ;
doComma = true ;
}
Z << "];\n" ;
// Prepare sub-menus
Z <<
"var subX = new Array();\nsubX = ["
;
doComma = false ;
for (si = m_lstPgSubjects, x = 0; si.Valid() ; x++, si++)
{
if (!counts[x])
continue ;
subject = si.Element() ;
nLo = m_mapSubj2Res.First(subject) ;
if (nLo < 0)
continue ;
nHi = m_mapSubj2Res.Last(subject) ;
for (; nLo <&eq; nHi ; nLo++)
{
pPage = m_mapSubj2Res.GetObj(nLo) ;
if (pPage->m_resAccess == ACCESS_PUBLIC || access == ACCESS_ADMIN
|| (pPage->m_resAccess == ACCESS_NOBODY && !access)
|| ((access & ACCESS_MASK) & pPage->m_resAccess))
{
if (doComma)
Z << ",\n" ;
// Z.AddByte(CHAR_COMMA) ;
Z.Printf("[%d,\"%s\",\"%s\"]", x, *pPage->m_Title, *pPage->m_Url) ;
doComma = true ;
}
}
}
/*
** for (x = 0 ; x < m_vecPgSubjects.Count() ; x++)
** {
** if (!counts[x])
** continue ;
**
** pSubj = m_vecPgSubjects[x] ;
**
** if (!pSubj->pglist.Count())
** continue ;
**
** for (y = 0 ; y < pSubj->pglist.Count() ; y++)
** {
** pPage = pSubj->pglist[y] ;
**
** if (pLang->m_MiscStrings.Exists(pPage->m_RID)) langTitl = pLang->m_MiscStrings[pPage->m_RID] ;
** else if (m_pDfltLang->m_MiscStrings.Exists(pPage->m_RID)) langTitl = m_pDfltLang->m_MiscStrings[pPage->m_RID] ;
** else
** langTitl = pPage->m_Title ;
**
** if (pPage->m_resAccess == ACCESS_PUBLIC || access == ACCESS_ADMIN
** || (pPage->m_resAccess == ACCESS_NOBODY && !access)
** || ((access & ACCESS_MASK) & pPage->m_resAccess))
** {
** if (doComma)
** Z << ",\n" ;
** //Z.AddByte(CHAR_COMMA) ;
** Z.Printf("[%d,\"%s\",\"%s\"]", x, *langTitl, *pPage->m_Url) ;
** doComma = true ;
** }
** }
** }
** */
Z << "];\n" ;
threadLog("Set script as\n") ;
threadLog(Z) ;
threadLog("End script\n") ;
delete [] counts ;
return E_OK ;
}