PageRenderTime 33ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/modules/bibformat/lib/bibformat_templates.py

https://github.com/lbjay/cds-invenio
Python | 1933 lines | 1871 code | 32 blank | 30 comment | 20 complexity | 893d69c6836b620345f0957a5d13be30 MD5 | raw file
Possible License(s): GPL-2.0
  1. # -*- coding: utf-8 -*-
  2. ##
  3. ## This file is part of CDS Invenio.
  4. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN.
  5. ##
  6. ## CDS Invenio is free software; you can redistribute it and/or
  7. ## modify it under the terms of the GNU General Public License as
  8. ## published by the Free Software Foundation; either version 2 of the
  9. ## License, or (at your option) any later version.
  10. ##
  11. ## CDS Invenio is distributed in the hope that it will be useful, but
  12. ## WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. ## General Public License for more details.
  15. ##
  16. ## You should have received a copy of the GNU General Public License
  17. ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc.,
  18. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  19. """HTML Templates for BibFormat administration"""
  20. __revision__ = "$Id$"
  21. # non Invenio imports
  22. import cgi
  23. # Invenio imports
  24. from invenio.messages import gettext_set_language
  25. from invenio.config import CFG_SITE_URL, CFG_SITE_SECURE_URL
  26. from invenio.messages import language_list_long
  27. from invenio.config import CFG_PATH_PHP
  28. MAX_MAPPINGS = 100 #show max this number of mappings on one page
  29. class Template:
  30. """Templating class, refer to bibformat.py for examples of call"""
  31. def tmpl_admin_index(self, ln, warnings, is_admin):
  32. """
  33. Returns the main BibFormat admin page.
  34. @param ln: language
  35. @param warnings: a list of warnings to display at top of page. None if no warning
  36. @param is_admin: indicate if user is authorized to use BibFormat
  37. @return: main BibFormat admin page
  38. """
  39. _ = gettext_set_language(ln) # load the right message language
  40. out = ''
  41. if warnings:
  42. out += '''
  43. <table width="66%%" class="errorbox" style="margin-left: auto; margin-right: auto;">
  44. <tr>
  45. <th class="errorboxheader">
  46. %(warnings)s
  47. </th>
  48. </tr>
  49. </table>
  50. ''' % {'warnings': '<br/>'.join(warnings)}
  51. out += '''
  52. <p>
  53. This is where you can edit the formatting styles available for the records. '''
  54. if not is_admin:
  55. out += '''You need to
  56. <a href="%(siteurl)s/youraccount/login?referer=%(siteurl)s/admin/bibformat/bibformatadmin.py">login</a> to enter.
  57. ''' % {'siteurl':CFG_SITE_URL}
  58. out += '''
  59. </p>
  60. <dl>
  61. <dt><a href="%(siteurl)s/admin/bibformat/bibformatadmin.py/format_templates_manage?ln=%(ln)s">Manage Format Templates</a></dt>
  62. <dd>Define how to format a record.</dd>
  63. </dl>
  64. <dl>
  65. <dt><a href="%(siteurl)s/admin/bibformat/bibformatadmin.py/output_formats_manage?ln=%(ln)s">Manage Output Formats</a></dt>
  66. <dd>Define which template is applied to which record for a given output.</dd>
  67. </dl>
  68. <br/>
  69. <dl>
  70. <dt><a href="%(siteurl)s/admin/bibformat/bibformatadmin.py/format_elements_doc?ln=%(ln)s">Format Elements Documentation</a></dt>
  71. <dd>Documentation of the format elements to be used inside format templates.</dd>
  72. </dl>
  73. <dl>
  74. <dt><a href="%(siteurl)s/help/admin/bibformat-admin-guide">BibFormat Admin Guide</a></dt>
  75. <dd>Documentation about BibFormat administration</dd>
  76. </dl>
  77. '''% {'siteurl':CFG_SITE_URL, 'ln':ln}
  78. if CFG_PATH_PHP:
  79. #Show PHP admin only if PHP is enabled
  80. out += '''
  81. <br/><br/><br/><br/>
  82. <div style="background-color:rgb(204, 204, 204);">
  83. <h2><span style="color:rgb(204, 0, 0);">Old</span>
  84. BibFormat admin interface (in gray box)</h2>
  85. <em>
  86. <p>The BibFormat admin interface enables you to specify how the
  87. bibliographic data is presented to the end user in the search
  88. interface and search results pages. For example, you may specify that
  89. titles should be printed in bold font, the abstract in small italic,
  90. etc. Moreover, the BibFormat is not only a simple bibliographic data
  91. <em>output formatter</em>, but also an automated <em>link
  92. constructor</em>. For example, from the information on journal name
  93. and pages, it may automatically create links to publisher's site based
  94. on some configuration rules.
  95. <h2>Configuring BibFormat</h2>
  96. <p>By default, a simple HTML format based on the most common fields
  97. (title, author, abstract, keywords, fulltext link, etc) is defined.
  98. You certainly want to define your own ouput formats in case you have a
  99. specific metadata structure.
  100. <p>Here is a short guide of what you can configure:
  101. <blockquote>
  102. <dl>
  103. <dt><a href="BEH_display.php">Behaviours</a>
  104. <dd>Define one or more output BibFormat behaviours. These are then
  105. passed as parameters to the BibFormat modules while executing
  106. formatting.
  107. <br /><em>Example:</em> You can tell BibFormat that is has to enrich the
  108. incoming metadata file by the created format, or that it only has to
  109. print the format out.
  110. <dt><a href="OAIER_display.php">Extraction Rules</a>
  111. <dd>Define how the metadata tags from input are mapped into internal
  112. BibFormat variable names. The variable names can afterwards be used
  113. in formatting and linking rules.
  114. <br /><em>Example:</em> You can tell that <code>100 $a</code> field
  115. should be mapped into <code>$100.a</code> internal variable that you
  116. could use later.
  117. <dt><a href="LINK_display.php">Link Rules</a>
  118. <dd>Define rules for automated creation of URI links from mapped
  119. internal variables.
  120. <br /><em>Example:</em> You can tell a rule how to create a link to
  121. People database out of the <code>$100.a</code> internal variable
  122. repesenting author's name. (The <code>$100.a</code> variable was mapped
  123. in the previous step, see the Extraction Rules.)
  124. <dt><a href="LINK_FORMAT_display.php">File Formats</a>
  125. <dd>Define file format types based on file extensions. This will be
  126. used when proposing various fulltext services.
  127. <br /><em>Example:</em> You can tell that <code>*.pdf</code> files will
  128. be treated as PDF files.
  129. <dt><a href="UDF_display.php">User Defined Functions (UDFs)</a>
  130. <dd>Define your own functions that you can reuse when creating your
  131. own output formats. This enables you to do complex formatting without
  132. ever touching the BibFormat core code.
  133. <br /><em>Example:</em> You can define a function how to match and
  134. extract email addresses out of a text file.
  135. <dt><a href="FORMAT_display.php">Formats</a>
  136. <dd>Define the output formats, i.e. how to create the output out of
  137. internal BibFormat variables that were extracted in a previous step.
  138. This is the functionality you would want to configure most of the
  139. time. It may reuse formats, user defined functions, knowledge bases,
  140. etc.
  141. <br /><em>Example:</em> You can tell that authors should be printed in
  142. italic, that if there are more than 10 authors only the first three
  143. should be printed, etc.
  144. <dt><a href="KB_display.php">Knowledge Bases (KBs)</a>
  145. <dd>Define one or more knowledge bases that enables you to transform
  146. various forms of input data values into the unique standard form on
  147. the output.
  148. <br /><em>Example:</em> You can tell that <em>Phys Rev D</em> and
  149. <em>Physical Review D</em> are both the same journal and that these
  150. names should be standardized to <em>Phys Rev : D</em>.
  151. <dt><a href="test.php">Execution Test</a>
  152. <dd>Enables you to test your formats on your sample data file. Useful
  153. when debugging newly created formats.
  154. </dl>
  155. </blockquote>
  156. <p>To learn more on BibFormat configuration, you can consult the <a
  157. href="guide.html">BibFormat Admin Guide</a>.</small>
  158. <h2>Running BibFormat</h2>
  159. <h3>From the Web interface</h3>
  160. <p>
  161. Run <a href="BIBREFORMAT_display.php">Reformat Records</a> tool.
  162. This tool permits you to update stored formats for bibliographic records.
  163. <br />
  164. It should normally be used after configuring BibFormat's
  165. <a href="BEH_display.php">Behaviours</a> and
  166. <a href="FORMAT_display.php">Formats</a>.
  167. When these are ready, you can choose to rebuild formats for selected
  168. collections or you can manually enter a search query and the web interface
  169. will accomplish all necessary formatting steps.
  170. <br />
  171. <i>Example:</i> You can request Photo collections to have their HTML
  172. brief formats rebuilt, or you can reformat all the records written by Ellis.
  173. <h3>From the command-line interface</h3>
  174. <p>Consider having an XML MARC data file that is to be uploaded into
  175. the CDS Invenio. (For example, it might have been harvested from other
  176. sources and processed via <a href="../bibconvert/">BibConvert</a>.)
  177. Having configured BibFormat and its default output type behaviour, you
  178. would then run this file throught BibFormat as follows:
  179. <blockquote>
  180. <pre>
  181. $ bibformat < /tmp/sample.xml > /tmp/sample_with_fmt.xml
  182. <pre>
  183. </blockquote>
  184. that would create default HTML formats and would "enrich" the input
  185. XML data file by this format. (You would then continue the upload
  186. procedure by calling successively <a
  187. href="../bibupload/">BibUpload</a> and <a
  188. href="../bibindex/">BibIndex</a>.)
  189. <p>Now consider a different situation. You would like to add a new
  190. possible format, say "HTML portfolio" and "HTML captions" in order to
  191. nicely format multiple photographs in one page. Let us suppose that
  192. these two formats are called <code>hp</code> and <code>hc</code> and
  193. are already loaded in the <code>collection_format</code> table.
  194. (TODO: describe how this is done via WebAdmin.) You would then
  195. proceed as follows: firstly, you would prepare the corresponding <a
  196. href="BEH_display.php">output behaviours</a> called <code>HP</code>
  197. and <code>HC</code> (TODO: note the uppercase!) that would not enrich
  198. the input file but that would produce an XML file with only
  199. <code>001</code> and <code>FMT</code> tags. (This is in order not to
  200. update the bibliographic information but the formats only.) You would
  201. also prepare corresponding <a href="FORMAT_display.php">formats</a>
  202. at the same time. Secondly, you would launch the formatting as
  203. follows:
  204. <blockquote>
  205. <pre>
  206. $ bibformat otype=HP,HC < /tmp/sample.xml > /tmp/sample_fmts_only.xml
  207. <pre>
  208. </blockquote>
  209. that should give you an XML file containing only 001 and FMT tags.
  210. Finally, you would upload the formats:
  211. <blockquote>
  212. <pre>
  213. $ bibupload < /tmp/sample_fmts_only.xml
  214. <pre>
  215. </blockquote>
  216. and that's it. The new formats should now appear in <a
  217. href="%(siteurl)s">WebSearch</a>.
  218. </em>
  219. </div>
  220. ''' % {'siteurl':CFG_SITE_URL, 'ln':ln}
  221. return out
  222. def tmpl_admin_format_template_show_attributes(self, ln, name, description, filename, editable,
  223. all_templates=[], new=False):
  224. """
  225. Returns a page to change format template name and description
  226. If template is new, offer a way to create a duplicate from an
  227. existing template
  228. @param ln: language
  229. @param name: the name of the format
  230. @param description: the description of the format
  231. @param filename: the filename of the template
  232. @param editable: True if we let user edit, else False
  233. @param all_templates: a list of tuples (filename, name) of all other templates
  234. @param new: if True, the format template has just been added (is new)
  235. @return: editor for 'format'
  236. """
  237. _ = gettext_set_language(ln) # load the right message language
  238. out = ""
  239. out += '''
  240. <table class="admin_wvar" cellspacing="0">
  241. <tr><th colspan="4" class="adminheaderleft">%(menu)s</th></tr>
  242. <tr>
  243. <td>0.&nbsp;<small><a href="format_templates_manage?ln=%(ln)s">%(close_editor)s</a></small>&nbsp;</td>
  244. <td>1.&nbsp;<small><a href="format_template_show?ln=%(ln)s&amp;bft=%(filename)s">%(template_editor)s</a></small>&nbsp;</td>
  245. <td>2.&nbsp;<small>%(modify_template_attributes)s</small>&nbsp;</td>
  246. <td>3.&nbsp;<small><a href="format_template_show_dependencies?ln=%(ln)s&amp;bft=%(filename)s">%(check_dependencies)s</a></small>&nbsp;</td>
  247. </tr>
  248. </table><br/>
  249. ''' % {'ln':ln,
  250. 'menu':_("Menu"),
  251. 'filename':filename,
  252. 'close_editor': _("Close Editor"),
  253. 'modify_template_attributes': _("Modify Template Attributes"),
  254. 'template_editor': _("Template Editor"),
  255. 'check_dependencies': _("Check Dependencies")
  256. }
  257. disabled = ""
  258. readonly = ""
  259. if not editable:
  260. disabled = 'disabled="disabled"'
  261. readonly = 'readonly="readonly"'
  262. out += '''
  263. <form action="format_template_update_attributes?ln=%(ln)s&amp;bft=%(filename)s" method="POST">
  264. ''' % {'ln':ln,
  265. 'filename':filename}
  266. if new:
  267. #Offer the possibility to make a duplicate of existing format template code
  268. out += '''
  269. <table><tr>
  270. <th class="adminheaderleft">Make a copy of format template:&nbsp;[<a href="%(siteurl)s/help/admin/bibformat-admin-guide#addFormatTemplate">?</a>]</th>
  271. </tr>
  272. <tr>
  273. <td><select tabindex="1" name="duplicate" id="duplicate" %(readonly)s>
  274. <option value="">None (Blank Page)</option>
  275. <option value="" disabled="disabled">-------------</option>
  276. ''' % {'siteurl': CFG_SITE_URL,
  277. 'readonly':readonly}
  278. for (o_filename, o_name) in all_templates:
  279. out += '''<option value="%(template_filename)s">%(template_name)s</option>''' % {'template_name':o_name,
  280. 'template_filename': o_filename}
  281. out += ''' </select>
  282. </td></tr></table>'''
  283. out += '''
  284. <table><tr>
  285. <th colspan="2" class="adminheaderleft">%(name)s attributes&nbsp;[<a href="%(siteurl)s/help/admin/bibformat-admin-guide#attrsFormatTemplate">?</a>]</th>
  286. </tr>
  287. <tr>
  288. <td class="admintdright">
  289. <input type="hidden" name="key" value="%(name)s"/>
  290. <label for="name">%(name_label)s</label>:&nbsp;</td>
  291. <td><input tabindex="2" name="name" type="text" id="name" size="25" value="%(name)s" %(readonly)s/>
  292. <input type="hidden" value="%(filename)s"/>
  293. </td>
  294. </tr>
  295. ''' % {"name": name,
  296. 'ln':ln,
  297. 'filename':filename,
  298. 'disabled':disabled,
  299. 'readonly':readonly,
  300. 'name_label': _("Name"),
  301. 'siteurl':CFG_SITE_URL
  302. }
  303. out += '''
  304. <tr>
  305. <td class="admintdright" valign="top"><label for="description">%(description_label)s</label>:&nbsp;</td>
  306. <td><textarea tabindex="3" name="description" id="description" rows="4" cols="25" %(readonly)s>%(description)s</textarea> </td>
  307. </tr>
  308. <tr>
  309. <td>&nbsp;</td>
  310. <td align="right"><input tabindex="6" class="adminbutton" type="submit" value="%(update_format_attributes)s" %(disabled)s/></td>
  311. </tr>
  312. </table></form>
  313. ''' % {"description": description,
  314. 'ln':ln,
  315. 'filename':filename,
  316. 'disabled':disabled,
  317. 'readonly':readonly,
  318. 'description_label': _("Description"),
  319. 'update_format_attributes': _("Update Format Attributes"),
  320. 'siteurl':CFG_SITE_URL
  321. }
  322. return out
  323. def tmpl_admin_format_template_show_dependencies(self, ln, name, filename, output_formats, format_elements, tags):
  324. """
  325. Shows the dependencies (on elements) of the given format.
  326. @param name: the name of the template
  327. @param filename: the filename of the template
  328. @param format_elements: the elements (and list of tags in each element) this template depends on
  329. @param output_formats: the output format that depend on this template
  330. @param tags: the tags that are called by format elements this template depends on.
  331. """
  332. _ = gettext_set_language(ln) # load the right message language
  333. out = '''
  334. <table class="admin_wvar" cellspacing="0">
  335. <tr><th colspan="4" class="adminheaderleft">%(menu)s</th></tr>
  336. <tr>
  337. <td>0.&nbsp;<small><a href="format_templates_manage?ln=%(ln)s">%(close_editor)s</a>&nbsp;</small></td>
  338. <td>1.&nbsp;<small><a href="format_template_show?ln=%(ln)s&amp;bft=%(filename)s">%(template_editor)s</a></small>&nbsp;</td>
  339. <td>2.&nbsp;<small><a href="format_template_show_attributes?ln=%(ln)s&amp;bft=%(filename)s">%(modify_template_attributes)s</a></small>&nbsp;</td>
  340. <td>3.&nbsp;<small>%(check_dependencies)s</small>&nbsp;</td>
  341. </tr>
  342. </table>
  343. <table width="90%%" class="admin_wvar" cellspacing="0"><tr>
  344. <th class="adminheaderleft">Output Formats that use %(name)s</th>
  345. <th class="adminheaderleft">Format Elements used by %(name)s*</th>
  346. <th class="adminheaderleft">All Tags Called*</th>
  347. </tr>
  348. <tr>
  349. <td valign="top">&nbsp;<br/>
  350. ''' % {'ln':ln,
  351. 'filename':filename,
  352. 'menu': _("Menu"),
  353. 'close_editor': _("Close Editor"),
  354. 'modify_template_attributes': _("Modify Template Attributes"),
  355. 'template_editor': _("Template Editor"),
  356. 'check_dependencies': _("Check Dependencies"),
  357. 'name': name }
  358. #Print output formats
  359. if len(output_formats) == 0:
  360. out += '<p align="center"><i>No output format uses this format template.</i></p>'
  361. for output_format in output_formats:
  362. name = output_format['names']['generic']
  363. filename = output_format['filename']
  364. out += ''' <a href="output_format_show?ln=%(ln)s&amp;bfo=%(filename)s">%(name)s</a>''' % {'filename':filename,
  365. 'name':name,
  366. 'ln':ln}
  367. if len(output_format['tags']) > 0:
  368. out += "("+", ".join(output_format['tags'])+")"
  369. out += "<br/>"
  370. #Print format elements (and tags)
  371. out += '</td><td valign="top">&nbsp;<br/>'
  372. if len(format_elements) == 0:
  373. out += '<p align="center"><i>This format template uses no format element.</i></p>'
  374. for format_element in format_elements:
  375. name = format_element['name']
  376. out += ''' <a href="format_elements_doc?ln=%(ln)s#%(anchor)s">%(name)s</a>''' % {'name':"bfe_"+name.lower(),
  377. 'anchor':name.upper(),
  378. 'ln':ln}
  379. if len(format_element['tags']) > 0:
  380. out += "("+", ".join(format_element['tags'])+")"
  381. out += "<br/>"
  382. #Print tags
  383. out += '</td><td valign="top">&nbsp;<br/>'
  384. if len(tags) == 0:
  385. out += '<p align="center"><i>This format template uses no tag.</i></p>'
  386. for tag in tags:
  387. out += '''%(tag)s<br/>''' % { 'tag':tag}
  388. out += '''
  389. </td>
  390. </tr>
  391. </table>
  392. <b>*Note</b>: Some tags linked with this format template might not be shown. Check manually.
  393. '''
  394. return out
  395. def tmpl_admin_format_template_show(self, ln, name, description, code, filename, ln_for_preview, pattern_for_preview, editable, content_type_for_preview, content_types):
  396. """
  397. Returns the editor for format templates. Edit 'format'
  398. @param ln: language
  399. @param format: the format to edit
  400. @param filename: the filename of the template
  401. @param ln_for_preview: the language for the preview (for bfo)
  402. @param pattern_for_preview: the search pattern to be used for the preview (for bfo)
  403. @param editable: True if we let user edit, else False
  404. @param code: the code of the template of the editor
  405. @return: editor for 'format'
  406. """
  407. _ = gettext_set_language(ln) # load the right message language
  408. out = ""
  409. # If xsl, hide some options in the menu
  410. nb_menu_options = 4
  411. if filename.endswith('.xsl'):
  412. nb_menu_options = 2
  413. out += '''
  414. <style type="text/css">
  415. <!--
  416. .ed_button {
  417. font-size: x-small;
  418. }
  419. -->
  420. </style>
  421. <script src="%(siteurl)s/admin/bibformat/js_quicktags.js" type="text/javascript"></script>
  422. <script type="text/javascript">
  423. /* Ask user confirmation before leaving page */
  424. var user_must_confirm_before_leaving_page = false;
  425. window.onbeforeunload = confirmExit;
  426. function confirmExit() {
  427. if (user_must_confirm_before_leaving_page)
  428. return "%(leave_editor_message)s";
  429. }
  430. function getByID( id ) {
  431. if (document.getElementById)
  432. var returnVar = document.getElementById(id);
  433. else if (document.all)
  434. var returnVar = document.all[id];
  435. else if (document.layers)
  436. var returnVar = document.layers[id];
  437. return returnVar;
  438. }
  439. window.onresize= resizeViews;
  440. window.onload= prepareLayout;
  441. function prepareLayout(){
  442. resizeViews();
  443. }
  444. function resizeViews(){
  445. var myWidth = 0, myHeight = 0;
  446. if( typeof( window.innerWidth ) == 'number' ) {
  447. //Non-IE
  448. myWidth = window.innerWidth;
  449. myHeight = window.innerHeight;
  450. } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
  451. //IE 6+ in 'standards compliant mode'
  452. myWidth = document.documentElement.clientWidth;
  453. myHeight = document.documentElement.clientHeight;
  454. } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
  455. //IE 4 compatible
  456. myWidth = document.body.clientWidth;
  457. myHeight = document.body.clientHeight;
  458. }
  459. if (myHeight <= 400) {
  460. getByID("code").style.height=10;
  461. getByID("previewiframe").style.height=10;
  462. } else{
  463. getByID("code").style.height=((myHeight-400)/2);
  464. getByID("previewiframe").style.height=((myHeight-400)/2);
  465. }
  466. getByID("previewiframe").style.height=200;
  467. // Resize documentation
  468. var height = document.documentElement.clientHeight;
  469. height -= getByID('shortDocFrame').offsetTop
  470. //height -= 20;
  471. getByID('shortDocFrame').style.height = height +"px";
  472. }
  473. </script>
  474. <table class="admin_wvar" cellspacing="0">
  475. <tr><th colspan="%(nb_menu_options)s" class="adminheaderleft">%(menu)s</th></tr>
  476. <tr>
  477. <td>0.&nbsp;<small><a href="format_templates_manage?ln=%(ln)s">%(close_editor)s</a></small>&nbsp;</td>
  478. <td>1.&nbsp;<small>%(template_editor)s</small>&nbsp;</td>
  479. ''' % {'ln': ln, 'filename': filename,
  480. 'menu': _("Menu"),
  481. 'label_show_doc': _("Show Documentation"),
  482. 'label_hide_doc': _("Hide Documentation"),
  483. 'close_editor': _("Close Editor"),
  484. 'modify_template_attributes': _("Modify Template Attributes"),
  485. 'template_editor': _("Template Editor"),
  486. 'check_dependencies': _("Check Dependencies"),
  487. 'nb_menu_options': nb_menu_options,
  488. 'siteurl': CFG_SITE_SECURE_URL or CFG_SITE_URL,
  489. 'leave_editor_message': _('Your modifications will not be saved.').replace('"', '\\"')
  490. }
  491. if not filename.endswith('.xsl'):
  492. out +='''<td>2.&nbsp;<small><a href="format_template_show_attributes?ln=%(ln)s&amp;bft=%(filename)s">%(modify_template_attributes)s</a></small>&nbsp;</td>
  493. <td>3.&nbsp;<small><a href="format_template_show_dependencies?ln=%(ln)s&amp;bft=%(filename)s">%(check_dependencies)s</a></small>&nbsp;</td>
  494. ''' % {'ln': ln, 'filename': filename,
  495. 'menu': _("Menu"),
  496. 'label_show_doc': _("Show Documentation"),
  497. 'label_hide_doc': _("Hide Documentation"),
  498. 'close_editor': _("Close Editor"),
  499. 'modify_template_attributes': _("Modify Template Attributes"),
  500. 'template_editor': _("Template Editor"),
  501. 'check_dependencies': _("Check Dependencies"),
  502. 'siteurl': CFG_SITE_SECURE_URL or CFG_SITE_URL
  503. }
  504. out +='''
  505. </tr>
  506. </table>
  507. <script type="text/javascript">
  508. function toggle_doc_visibility(){
  509. var doc = document.getElementById('docTable');
  510. var link = document.getElementById('docLink');
  511. if (doc.style.display=='none'){
  512. doc.style.display = '';
  513. link.innerHTML = "%(label_hide_doc)s"
  514. } else {
  515. doc.style.display = 'none';
  516. link.innerHTML = "%(label_show_doc)s"
  517. }
  518. }
  519. </script>
  520. ''' % {'ln': ln, 'filename': filename,
  521. 'menu': _("Menu"),
  522. 'label_show_doc': _("Show Documentation"),
  523. 'label_hide_doc': _("Hide Documentation"),
  524. 'close_editor': _("Close Editor"),
  525. 'modify_template_attributes': _("Modify Template Attributes"),
  526. 'template_editor': _("Template Editor"),
  527. 'check_dependencies': _("Check Dependencies"),
  528. 'siteurl': CFG_SITE_SECURE_URL or CFG_SITE_URL
  529. }
  530. disabled = ""
  531. readonly = ""
  532. toolbar = """<script type="text/javascript">edToolbar('%s/admin/bibformat/bibformatadmin.py/format_elements_doc?ln=%s');</script>""" % (CFG_SITE_URL, ln)
  533. if not editable:
  534. disabled = 'disabled="disabled"'
  535. readonly = 'readonly="readonly"'
  536. toolbar = ''
  537. #First column: template code and preview
  538. out += '''
  539. <table width="90%%" cellspacing="5">
  540. <tr>
  541. <td valign="top">
  542. <form action="format_template_show_preview_or_save?ln=%(ln)s&amp;bft=%(filename)s" method="POST" target="previewiframe">
  543. <table width="100%%" id="mainTable"><tr>
  544. <th class="adminheaderleft"><div style="float:left;">Format template code</div>
  545. <div style="float:right;">
  546. <a id="docLink" href="#" onclick="toggle_doc_visibility()">%(label_hide_doc)s</a>
  547. </div>
  548. </th>
  549. </tr>
  550. <tr><td colspan="2" id="codetd">
  551. %(toolbar)s
  552. <textarea name="code" id="code" rows="25" %(readonly)s
  553. style="width:100%%" onchange="user_must_confirm_before_leaving_page=true;">%(code)s</textarea>
  554. <script type="text/javascript">var edCanvas = document.getElementById('code');</script>
  555. </td></tr>
  556. <tr><td align="right" valign="top">
  557. <input type="submit" class="adminbutton" name="save_action" value="Save Changes" onclick="user_must_confirm_before_leaving_page=false;" %(disabled)s/>
  558. </td>
  559. </tr>
  560. </table>
  561. <table width="100%%">
  562. <tr><th class="adminheaderleft">
  563. Preview
  564. </th>
  565. </tr>
  566. <tr><td align="right" valign="top" style="font-size: small;">
  567. <nobr>
  568. <label for="content_type_for_preview">Content-type (MIME):</label> <select id="content_type_for_preview" name="content_type_for_preview" style="font-size: x-small;">
  569. ''' % {'ln':ln,
  570. 'siteurl':CFG_SITE_URL,
  571. 'filename':filename,
  572. 'label_hide_doc':_("Hide Documentation"),
  573. 'code':code,
  574. 'readonly':readonly,
  575. 'disabled':disabled,
  576. 'toolbar':toolbar}
  577. for content_type in content_types:
  578. if content_type == content_type_for_preview:
  579. out += '''<option value="%(content_type)s" selected="selected">%(content_type)s</option>''' % {'content_type':content_type}
  580. else:
  581. out += '''<option value="%(content_type)s">%(content_type)s</option>''' % {'content_type':content_type}
  582. out += '''
  583. </select></nobr>
  584. <nobr><label for="ln_for_preview">Language:</label> <select id="ln_for_preview" name="ln_for_preview" style="font-size: x-small;">
  585. '''
  586. for lang in language_list_long():
  587. if lang[0] == ln_for_preview:
  588. out += '''<option value="%(ln)s" selected="selected">%(language)s</option>''' % {'ln':lang[0],
  589. 'language':lang[1]}
  590. else:
  591. out += '''<option value="%(ln)s">%(language)s</option>''' % {'ln':lang[0], 'language':lang[1]}
  592. out += '''
  593. </select></nobr>
  594. &nbsp;
  595. <nobr><label for="pattern_for_preview">Search Pattern: </label><input type="text" value="%(pattern_for_preview)s" size="8" name="pattern_for_preview" id="pattern_for_preview" style="font-size: x-small;"/></nobr>&nbsp;
  596. <input type="submit" class="adminbutton" name="preview_action" value="Reload Preview"/>
  597. </td>
  598. </tr>
  599. <tr><td>
  600. <iframe src ="%(siteurl)s/admin/bibformat/bibformatadmin.py/format_template_show_preview_or_save?ln=%(ln)s&amp;ln_for_preview=%(ln_for_preview)s&amp;pattern_for_preview=%(pattern_for_preview)s&amp;bft=%(filename)s" name="previewiframe" id="previewiframe" width="100%%" height="400"></iframe>
  601. </td></tr>
  602. </table>
  603. </form>
  604. </td>
  605. ''' % {'code':code, 'ln':ln,
  606. 'siteurl':CFG_SITE_URL, 'filename':filename,
  607. 'ln_for_preview':ln_for_preview,
  608. 'pattern_for_preview':pattern_for_preview
  609. }
  610. #Second column Print documentation
  611. out += '''
  612. <td valign="top" id="docTable">
  613. <table width="100%%"><tr>
  614. <th class="adminheaderleft">Elements Documentation</th>
  615. </tr>
  616. </table>
  617. <table width="100%%"><tr>
  618. <td class="admintdright">
  619. <form action="format_template_show_short_doc?ln=%(ln)s" method="POST" target="shortDocFrame">
  620. <nobr><label for="search_doc_pattern">Search for:&nbsp;</label><input type="text" size="15" name="search_doc_pattern" id="search_doc_pattern" value=""/> <input type="submit" class="adminbutton" name="search_in_doc" value="Search" /></nobr>
  621. </form>
  622. </td>
  623. </tr>
  624. </table>
  625. <iframe name="shortDocFrame" id="shortDocFrame" src ="%(siteurl)s/admin/bibformat/bibformatadmin.py/format_template_show_short_doc?ln=%(ln)s" height="90%%" width="98%%"></iframe>
  626. </td>
  627. </tr>
  628. </table>
  629. ''' % {'siteurl':CFG_SITE_URL, 'ln':ln}
  630. return out
  631. def tmpl_admin_format_template_show_short_doc(self, ln, format_elements):
  632. """
  633. Prints the format element documentation in a condensed way to display
  634. inside format template editor.
  635. This page is different from others: it is displayed inside a <iframe>
  636. tag in template tmpl_admin_format_template_show.
  637. @param ln: language
  638. @param format_elements: a list of format elements structures as returned by get_format_elements
  639. """
  640. out = '''
  641. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  642. <html>
  643. <head>
  644. <title>BibFormat Short Documentation of Format Elements</title>
  645. <link rel="stylesheet" href="%(siteurl)s/img/invenio.css">
  646. <script src="%(siteurl)s/admin/bibformat/js_quicktags.js" type="text/javascript"></script>
  647. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  648. </head>
  649. <body>
  650. <script type="text/javascript">
  651. function toggle_visibility(element, show, r,g,b){
  652. var children = element.childNodes
  653. var child
  654. for(x=0; x<children.length; x++){
  655. if (children[x].id == 'params'){
  656. child = children[x]
  657. }
  658. }
  659. if (show=='show'){
  660. element.style.background='rgb(201, 218, 255)'
  661. element.style.cursor='pointer'
  662. child.style.display=''
  663. } else {
  664. element.style.background="rgb("+r+","+g+","+b+")"
  665. child.style.display='none'
  666. }
  667. }
  668. ///// FROM JS QuickTags ///////
  669. // Copyright (c) 2002-2005 Alex King
  670. // http://www.alexking.org/
  671. //
  672. // Licensed under the LGPL license
  673. // http://www.gnu.org/copyleft/lesser.html
  674. function insertAtCursor(myField, myValue) {
  675. //IE support
  676. if (document.selection) {
  677. myField.focus();
  678. sel = document.selection.createRange();
  679. sel.text = myValue;
  680. }
  681. //MOZILLA/NETSCAPE support
  682. else if (myField.selectionStart || myField.selectionStart == '0') {
  683. var startPos = myField.selectionStart;
  684. var endPos = myField.selectionEnd;
  685. myField.value = myField.value.substring(0, startPos)
  686. + myValue
  687. + myField.value.substring(endPos, myField.value.length);
  688. } else {
  689. myField.value += myValue;
  690. }
  691. }
  692. ///// END FROM JS QuickTags /////
  693. function insert_my_code_into_container(code){
  694. var codeArea = parent.document.getElementById("code");
  695. if (codeArea.readOnly == false){
  696. //var clean_code = code.replace(=#,'="');
  697. //clean_code = clean_code.replace(# ,'" ');
  698. insertAtCursor(codeArea, code);
  699. }
  700. }
  701. </script>
  702. ''' % {'siteurl': CFG_SITE_SECURE_URL or CFG_SITE_URL}
  703. if len(format_elements) == 0:
  704. out += '''
  705. <em>No format elements found</em>
  706. '''
  707. else:
  708. line = 0
  709. #Print elements doc
  710. for format_element in format_elements:
  711. format_attributes = format_element['attrs']
  712. row_content = ""
  713. name = format_attributes['name']
  714. description = format_attributes['description']
  715. params = [x['name'] + '=\u0022'+str(x['default'])+'\u0022' for x in format_attributes['params']]
  716. builtin_params = [x['name'] + '=\u0022'+str(x['default'])+'\u0022' for x in format_attributes['builtin_params']]
  717. code = "<BFE_" + name + ' ' + ' '.join(builtin_params)+ ' ' + ' '.join(params) +"/>"
  718. if line % 2:
  719. row_content += '''<div onmouseover="toggle_visibility(this, 'show', 235, 247, 255);"
  720. onmouseout="toggle_visibility(this, 'hide', 235, 247, 255);"
  721. style="background-color: rgb(235, 247, 255);"
  722. onclick="insert_my_code_into_container('%s')"
  723. ><hr/>''' % code
  724. else:
  725. row_content += '''<div onmouseover="toggle_visibility(this, 'show', 255, 255, 255);"
  726. onmouseout="toggle_visibility(this, 'hide', 255, 255, 255);"
  727. onclick="insert_my_code_into_container('%s')"
  728. >''' % code
  729. params_names = ""
  730. for param in format_attributes['params']:
  731. params_names += "<b>"+param['name'] +'</b> '
  732. row_content += '''
  733. <code> <b>&lt;BFE_%(name)s/&gt;</b><br/></code>
  734. <small>%(description)s.</small>
  735. <div id="params" style="display:none;">
  736. <ul>
  737. ''' % {'params_names':params_names, 'name':name, 'description':description}
  738. for param in format_attributes['params']:
  739. row_content += '''
  740. <li><small><b>%(name)s</b>:&nbsp;%(description)s</small></li>
  741. ''' % {'name':param['name'],
  742. 'description':param['description']}
  743. for param in format_attributes['builtin_params']:
  744. row_content += '''
  745. <li><small><b>%(name)s</b>:&nbsp;%(description)s</small></li>
  746. ''' % {'name':param['name'],
  747. 'description':param['description']}
  748. row_content += '</ul></div>'
  749. if line % 2:
  750. row_content += '''<hr/></div>'''
  751. else:
  752. row_content += '</div>'
  753. line += 1
  754. out += row_content
  755. out += '''</body></html>'''
  756. return out
  757. def tmpl_admin_format_templates_management(self, ln, formats):
  758. """
  759. Returns the management console for formats. Includes list of formats and
  760. associated administration tools.
  761. @param ln: language
  762. @param formats: a list of dictionaries with formats attributes
  763. @return: format management console as html
  764. """
  765. _ = gettext_set_language(ln) # load the right message language
  766. #top of the page and table header
  767. out = '''
  768. <table class="admin_wvar" cellspacing="0">
  769. <tr><th colspan="4" class="adminheaderleft">%(menu)s</th></tr>
  770. <tr>
  771. <td>0.&nbsp;<small>%(manage_format_templates)s</small>&nbsp;</td>
  772. <td>1.&nbsp;<small><a href="output_formats_manage?ln=%(ln)s">%(manage_output_formats)s</a>&nbsp;</td>
  773. <td>2.&nbsp;<small><a href="format_elements_doc?ln=%(ln)s">%(format_elements_documentation)s</a></small>&nbsp;</td>
  774. </tr>
  775. </table>
  776. <p>From here you can create, edit or delete formats templates.
  777. Have a look at the <a href="format_elements_doc?ln=%(ln)s">format elements documentation</a> to
  778. learn which elements you can use in your templates.</p>
  779. <table class="admin_wvar" width="95%%" cellspacing="0">
  780. <tr>
  781. <th class="adminheaderleft" >&nbsp;</th>
  782. <th class="adminheaderleft" >%(name)s</th>
  783. <th class="adminheaderleft" >%(description)s</th>
  784. <th class="adminheaderleft" >%(status)s</th>
  785. <th class="adminheaderleft" >%(last_modification_date)s</th>
  786. <th class="adminheadercenter" >%(action)s&nbsp;&nbsp;&nbsp;[<a href="%(siteurl)s/help/admin/bibformat-admin-guide#formatTemplates">?</a>]</th>
  787. </tr>
  788. ''' % {'name':_("Name"),
  789. 'description':_("Description"),
  790. 'menu': _("Menu"),
  791. 'status':_("Status"),
  792. 'last_modification_date':_("Last Modification Date"),
  793. 'action':_("Action"),
  794. 'ln':ln,
  795. 'manage_output_formats':_("Manage Output Formats"),
  796. 'manage_format_templates':_("Manage Format Templates"),
  797. 'format_elements_documentation':_("Format Elements Documentation"),
  798. 'siteurl':CFG_SITE_URL}
  799. #table content: formats names, description and buttons
  800. if len(formats) == 0:
  801. out += '''<tr>
  802. <td colspan="6" class="admintd" align="center"><em>No format</em></td>
  803. </tr>'''
  804. else:
  805. line = 0
  806. for attrs in formats:
  807. filename = attrs['filename']
  808. if filename == "":
  809. filename = "&nbsp;"
  810. name = attrs['name']
  811. if name == "":
  812. name = "&nbsp;"
  813. description = attrs['description']
  814. if description == "":
  815. description = "&nbsp;"
  816. last_mod_date = attrs['last_mod_date']
  817. status = attrs['status']
  818. disabled = ""
  819. if not attrs['editable']:
  820. disabled = 'disabled="disabled"'
  821. style = 'style="vertical-align: middle;'
  822. if line % 2:
  823. style = 'style="vertical-align: middle;background-color: rgb(235, 247, 255);'
  824. line += 1
  825. row_content = '''<tr>
  826. <td class="admintdright" %(style)s">&nbsp;</td>
  827. <td class="admintdleft" %(style)s white-space: nowrap;"><a href="format_template_show?bft=%(filename)s&amp;ln=%(ln)s">%(name)s</a></td>
  828. <td class="admintdleft" %(style)s" >%(description)s</td>
  829. <td class="admintdleft" %(style)s white-space: nowrap;" >%(status)s</td>
  830. <td class="admintdleft" %(style)s white-space: nowrap;" >%(last_mod_date)s</td>
  831. <td class="admintd" %(style)s white-space: nowrap;">
  832. <form method="post" action="format_template_delete?ln=%(ln)s&amp;bft=%(filename)s">
  833. <input class="adminbutton" type="submit" value="%(delete)s" %(disabled)s/>
  834. </form>
  835. </td>
  836. </tr>
  837. ''' % {'filename':filename,
  838. 'name':name,
  839. 'description':description,
  840. 'ln':ln,
  841. 'style':style,
  842. 'disabled':disabled,
  843. 'last_mod_date':last_mod_date,
  844. 'status':status,
  845. 'delete':_("Delete")
  846. }
  847. out += row_content
  848. #table footer, buttons and bottom of the page
  849. out += '''
  850. <tr>
  851. <td align="left" colspan="3">
  852. <form action="format_templates_manage?ln=%(ln)s">
  853. <input type="hidden" name="checking" value="1"></input>
  854. <input class="adminbutton" type="submit" value="%(extensive_checking)s"/>
  855. </form>
  856. </td>
  857. <td align="right" colspan="3">
  858. <form action="format_template_add?ln=%(ln)s">
  859. <input class="adminbutton" type="submit" value="%(add_format_template)s"/>
  860. </form>
  861. </td>
  862. </tr>
  863. </table>
  864. ''' % {'ln':ln,
  865. 'add_format_template':_("Add New Format Template"),
  866. 'extensive_checking':_("Check Format Templates Extensively")}
  867. return out
  868. def tmpl_admin_output_formats_management(self, ln, output_formats):
  869. """
  870. Returns the main management console for formats. Includes list of formats and
  871. associated administration tools.
  872. @param ln: language
  873. @param output_formats: a list of output formats
  874. @return: main management console as html
  875. """
  876. _ = gettext_set_language(ln) # load the right message language
  877. #top of the page and table header
  878. out = '''
  879. <table class="admin_wvar" cellspacing="0">
  880. <tr><th colspan="4" class="adminheaderleft">%(menu)s</th></tr>
  881. <tr>
  882. <td>0.&nbsp;<small><a href="format_templates_manage?ln=%(ln)s">%(manage_format_templates)s</a></small>&nbsp;</td>
  883. <td>1.&nbsp;<small>%(manage_output_formats)s</small>&nbsp;</td>
  884. <td>2.&nbsp;<small><a href="format_elements_doc?ln=%(ln)s">%(format_elements_documentation)s</a></small>&nbsp;</td>
  885. </tr>
  886. </table>
  887. <p>From here you can add, edit or delete output formats available for collections. Output formats define which template to use. <br/>To edit templates go to the <a href="format_templates_manage?ln=%(ln)s">template administration page</a>.</p>
  888. <table class="admin_wvar" width="95%%" cellspacing="0">
  889. <tr>
  890. <th class="adminheaderleft" >&nbsp;</th>
  891. <th class="adminheaderleft" ><a href="output_formats_manage?ln=%(ln)s&amp;sortby=code">%(code)s</a></th>
  892. <th class="adminheaderleft" ><a href="output_formats_manage?ln=%(ln)s&amp;sortby=name">%(name)s</a></th>
  893. <th class="adminheaderleft" >%(description)s</th>
  894. <th class="adminheaderleft" >%(status)s</th>
  895. <th class="adminheaderleft" >%(last_modification_date)s</th>
  896. <th class="adminheadercenter" >%(action)s&nbsp;&nbsp;&nbsp;[<a href="%(siteurl)s/help/admin/bibformat-admin-guide#outputFormats">?</a>]</th>
  897. </tr>
  898. ''' % {'code':_("Code"),
  899. 'name':_("Name"),
  900. 'description':_("Description"),
  901. 'status':_("Status"),
  902. 'last_modification_date':_("Last Modification Date"),
  903. 'action':_("Action"),
  904. 'ln':ln,
  905. 'manage_output_formats':_("Manage Output Formats"),
  906. 'manage_format_templates':_("Manage Format Templates"),
  907. 'format_elements_documentation':_("Format Elements Documentation"),
  908. 'menu': _("Menu"),
  909. 'siteurl':CFG_SITE_URL}
  910. #table content: formats names, description and buttons
  911. if len(output_formats) == 0:
  912. out += '''<tr>
  913. <td colspan="5" class="admintd" align="center"><em>No format</em></td>
  914. </tr>'''
  915. else:
  916. line = 0
  917. for output_format in output_formats:
  918. format_attributes = output_format['attrs']
  919. name = format_attributes['names']['generic']
  920. if name == "":
  921. name = "&nbsp;"
  922. description = format_attributes['description']
  923. if description == "":
  924. description = "&nbsp;"
  925. code = format_attributes['code']
  926. if code == "":
  927. code = "&nbsp;"
  928. last_mod_date = output_format['last_mod_date']
  929. status = output_format['status']
  930. disabled = ""
  931. if not output_format['editable']:
  932. disabled = 'disabled="disabled"'
  933. style = "vertical-align: middle;"
  934. if line % 2:
  935. style = 'vertical-align: middle; background-color: rgb(235, 247, 255);'
  936. line += 1
  937. row_content = '''<tr>
  938. <td class="admintdright" style="%(style)s">&nbsp;</td>
  939. <td class="admintdleft" style="white-space: nowrap; %(style)s">
  940. <a href="output_format_show?bfo=%(code)s">%(code)s</a>
  941. </td>
  942. <td class="admintdleft" style="white-space: nowrap; %(style)s">
  943. <a href="output_format_show?bfo=%(code)s">%(name)s</a>
  944. </td>
  945. <td class="admintdleft"style="%(style)s" >
  946. %(description)s
  947. </td>
  948. <td class="admintd" style="white-space: nowrap; %(style)s" >%(status)s</td>
  949. <td class="admintdleft" style="white-space: nowrap;%(style)s" >%(last_mod_date)s</td>
  950. <td class="admintd" style="white-space: nowrap; %(style)s">
  951. <form method="POST" action="output_format_delete?ln=%(ln)s&amp;bfo=%(code)s">
  952. <input class="adminbutton" type="submit" value="Delete" %(disabled)s />
  953. </form>
  954. </td>
  955. </tr>
  956. ''' % {'style':style,
  957. 'code':code,
  958. 'description':description,
  959. 'name':name,
  960. 'ln':ln,
  961. 'disabled':disabled,
  962. 'last_mod_date':last_mod_date,
  963. 'status':status}
  964. out += row_content
  965. #table footer, buttons and bottom of the page
  966. out += '''
  967. <tr>
  968. <td align="right" colspan="7">
  969. <form method="GET" action="output_format_add?ln=%(ln)s">
  970. <input class="adminbutton" type="submit" value="%(add_output_format)s"/>
  971. </form>
  972. </td>
  973. </tr>
  974. </table>
  975. ''' % {'ln':ln,
  976. 'add_output_format':_("Add New Output Format")}
  977. return out
  978. def tmpl_admin_output_format_show(self, ln, code, name, rules, default, format_templates, editable):
  979. """
  980. Returns the content of an output format
  981. rules is an ordered list of dict (sorted by evaluation order),
  982. with keys 'field', 'value' and 'template'
  983. IMPORTANT: we display rules evaluation index starting at 1 in
  984. interface, but we start internally at 0
  985. @param ln: language
  986. @param code: the code of the output to show
  987. @param name: the name of this output format
  988. @param rules: the list of rules for this output format
  989. @param default: the default format template of the output format
  990. @param format_templates: the list of format_templates
  991. @param editable: True if we let user edit, else False
  992. @return: the management console for this output format
  993. """
  994. _ = gettext_set_language(ln)
  995. out = '''
  996. <table class="admin_wvar" cellspacing="0">
  997. <tr><th colspan="4" class="adminheaderleft">%(menu)s</th></tr>
  998. <tr>
  999. <td>0.&nbsp;<small><a href="output_formats_manage?ln=%(ln)s">%(close_output_format)s</a></small>&nbsp;</td>
  1000. <td>1.&nbsp;<small>%(rules)s</small>&nbsp;</td>
  1001. <td>2.&nbsp;<small><a href="output_format_show_attributes?ln=%(ln)s&amp;bfo=%(code)s">%(modify_output_format_attributes)s</a></small>&nbsp;</td>
  1002. <td>3.&nbsp;<small><a href="output_format_show_dependencies?ln=%(ln)s&amp;bfo=%(code)s">%(check_dependencies)s</a></small>&nbsp;</td>
  1003. </tr>
  1004. </table>
  1005. <p>Define here the rules the specifies which template to use for a given record.</p>
  1006. ''' % {'code':code,
  1007. 'ln':ln,
  1008. 'menu':_("menu"),
  1009. 'close_output_format':_("Close Output Format"),
  1010. 'rules':_("Rules"),
  1011. 'modify_output_format_attributes':_("Modify Output Format Attributes"),
  1012. 'check_dependencies':_("Check Dependencies")
  1013. }
  1014. out += '''
  1015. <form name="rules" action="output_format_show?ln=%(ln)s&amp;bfo=%(code)s" method="post">
  1016. <table>
  1017. <tr>
  1018. <td>
  1019. ''' % {'ln': ln, 'code':code}
  1020. disabled = ""
  1021. readonly = ""
  1022. if not editable:
  1023. disabled = 'disabled="disabled"'
  1024. readonly = 'readonly="readonly"'
  1025. if len(rules) == 0:
  1026. out += '''<p align="center"><em>No special rule</em></p>'''
  1027. line = 1
  1028. for rule in rules:
  1029. out += '''
  1030. <table align="center" class="admin_wvar" cellspacing="0">
  1031. <tr>
  1032. '''
  1033. out += '''
  1034. <td rowspan="2" class="adminheader" style="vertical-align: middle;">'''
  1035. if line > 1:
  1036. out += '''
  1037. <input type="image" src="%(siteurl)s/img/smallup.gif" alt="Increase priority of rule %(row)s" name="+ %(row)s" value="+ %(row)s" %(disabled)s/></div>
  1038. ''' % {'siteurl':CFG_SITE_URL, 'row':line, 'disabled':disabled}
  1039. out += '''<div>%(row)s</div>''' % { 'row':line}
  1040. if line < len(rules):
  1041. out += '''
  1042. <input type="image" src="%(siteurl)s/img/smalldown.gif" alt="Decrease priority of rule %(row)s" name="- %(row)s" value="- %(row)s" %(disabled)s/>
  1043. ''' % {'siteurl':CFG_SITE_URL,
  1044. 'row':line,
  1045. 'disabled':disabled}
  1046. out += '''</td>
  1047. <td class="adminheaderleft">&nbsp;</td>
  1048. '''
  1049. out += '''
  1050. <td class="adminheaderleft" style="white-space: nowrap;">
  1051. Use template&nbsp;<select name="r_tpl" %(disabled)s>''' % {'disabled':disabled}
  1052. for template in format_templates:
  1053. attrs = format_templates[template]['attrs']
  1054. attrs['template'] = template
  1055. if template.endswith('.xsl') and not \
  1056. attrs['name'].endswith(' (XSL)'):
  1057. attrs['name'] += ' (XSL)'
  1058. if template != rule['template']:
  1059. out += '''<option value="%(template)s">%(name)s</option>''' % attrs
  1060. else:
  1061. out += '''<option value="%(template)s" selected="selected">%(name)s</option>''' % attrs
  1062. if not format_templates.has_key(rule['template']) and rule['template'] != "":
  1063. #case where a non existing format template is use in output format
  1064. #we need to add it as option
  1065. out += '''<option value="%s" selected="selected">%s</option>''' % (rule['template'],
  1066. rule['template'])
  1067. ################ FIXME remove when migration is done ####################
  1068. #Let the user choose a non existing template, that is a placeholder
  1069. #meaning that the template has not been migrated
  1070. selected = ''
  1071. if rule['template'] == 'migration_in_progress':
  1072. selected = 'selected="selected"'
  1073. if CFG_PATH_PHP or selected != '':
  1074. out += '''<option disabled="disabled">For Migration:</option>'''
  1075. out += '''<option value="migration_in_progress" %s>defined in old BibFormat</option>''' % selected
  1076. ################ END FIXME ####################
  1077. out += '''</select>&nbsp;if field
  1078. &nbsp;<input type="text" name="r_fld" value="%(field)s" size="10" %(readonly)s/>&nbsp;is equal to&nbsp;<input type="text" value="%(value)s" name="r_val" %(readonly)s/>
  1079. </td>
  1080. <td class="adminheaderright" style="vertical-align: middle;">
  1081. &nbsp;[<a href="%(siteurl)s/help/admin/bibformat-admin-guide#rulesOutputFormat">?</a>]
  1082. </td>
  1083. </tr>
  1084. ''' % {'siteurl':CFG_SITE_URL,
  1085. 'field': rule['field'],
  1086. 'value':rule['value'],
  1087. 'readonly':readonly}
  1088. out += '''
  1089. <tr>
  1090. <td colspan ="3" class="adminheaderright" style="vertical-align: middle; white-space: nowrap;">
  1091. <input type="submit" class="adminbutton" name="r_upd" value="%(remove_rule_label)s %(row)s" %(disabled)s/>&nbsp;
  1092. </td>
  1093. </tr>
  1094. </table>
  1095. ''' % {'remove_rule_label': _("Remove Rule"),
  1096. 'row':line,
  1097. 'disabled':disabled}
  1098. line += 1
  1099. out += '''
  1100. <table width="100%" align="center" class="admin_wvar" cellspacing="0">
  1101. <tr>
  1102. '''
  1103. out += '''
  1104. <td width="30" class="adminheaderleft">&nbsp;</td>
  1105. <td class="adminheaderleft">By default use <select id="default" name="default" %(disabled)s>''' % {'disabled':disabled}
  1106. for template in format_templates:
  1107. attrs = format_templates[template]['attrs']
  1108. attrs['template'] = template
  1109. if template.endswith('.xsl') and not \
  1110. attrs['name'].endswith(' (XSL)'):
  1111. attrs['name'] += ' (XSL)'
  1112. if template != default:
  1113. out += '''<option value="%(template)s">%(name)s</option>''' % attrs
  1114. else:
  1115. out += '''<option value="%(template)s" selected="selected">%(name)s</option>''' % attrs
  1116. if not format_templates.has_key(default) and default!= "":
  1117. #case where a non existing format tempate is use in output format
  1118. #we need to add it as option (only if it is not empty string)
  1119. out += '''<option value="%s" selected="selected">%s</option>''' % (default,default)
  1120. ################ FIXME remove when migration is done ####################
  1121. #Let the user choose a non existing template, that is a placeholder
  1122. #meaning that the template has not been migrated
  1123. selected = ''
  1124. if default == 'migration_in_progress':
  1125. selected = 'selected="selected"'
  1126. if CFG_PATH_PHP or selected != '':
  1127. out += '''<option disabled="disabled">For Migration:</option>'''
  1128. out += '''<option value="migration_in_progress" %s>defined in old BibFormat</option>''' % selected
  1129. ################ END FIXME ####################
  1130. out += '''</select></td>
  1131. </tr>
  1132. </table>
  1133. <div align="right">
  1134. <input tabindex="6" class="adminbutton" type="submit" name="r_upd" value="%(add_new_rule_label)s" %(disabled)s/>
  1135. <input tabindex="7" class="adminbutton" type="submit" name="r_upd" value="%(save_changes_label)s" %(disabled)s/>
  1136. </div>
  1137. </td>
  1138. </tr>
  1139. </table>
  1140. </form>
  1141. ''' % {'add_new_rule_label':_("Add New Rule"),
  1142. 'save_changes_label':_("Save Changes"),
  1143. 'disabled':disabled
  1144. }
  1145. return out
  1146. def tmpl_admin_output_format_show_attributes(self, ln,
  1147. name,
  1148. description,
  1149. content_type,
  1150. code,
  1151. names_trans,
  1152. editable,
  1153. visible):
  1154. """
  1155. Returns a page to change output format name and description
  1156. names_trans is an ordered list of dicts with keys 'lang' and 'trans'
  1157. @param ln: language
  1158. @param name: the name of the format
  1159. @param description: the description of the format
  1160. @param code: the code of the format
  1161. @param content_type: the (MIME) content type of the ouput format
  1162. @param names_trans: the translations in the same order as the languages from get_languages()
  1163. @param editable: True if we let user edit, else False
  1164. @param visible: True if output format should be shown in list of available output formats
  1165. @return: editor for output format attributes
  1166. """
  1167. _ = gettext_set_language(ln) # load the right message language
  1168. out = ""
  1169. out += '''
  1170. <table class="admin_wvar" cellspacing="0">
  1171. <tr><th colspan="4" class="adminheaderleft">%(menu)s</th></tr>
  1172. <tr>
  1173. <td>0.&nbsp;<small><a href="output_formats_manage?ln=%(ln)s">%(close_output_format)s</a></small>&nbsp;</td>
  1174. <td>1.&nbsp;<small><a href="output_format_show?ln=%(ln)s&amp;bfo=%(code)s">%(rules)s</a></small>&nbsp;</td>
  1175. <td>2.&nbsp;<small>%(modify_output_format_attributes)s</small>&nbsp;</td>
  1176. <td>3.&nbsp;<small><a href="output_format_show_dependencies?ln=%(ln)s&amp;bfo=%(code)s">%(check_dependencies)s</a></small>&nbsp;</td>
  1177. </tr>
  1178. </table><br/>
  1179. ''' % {'ln':ln,
  1180. 'code':code,
  1181. 'close_output_format':_("Close Output Format"),
  1182. 'rules':_("Rules"),
  1183. 'modify_output_format_attributes':_("Modify Output Format Attributes"),
  1184. 'check_dependencies':_("Check Dependencies"),
  1185. 'menu':_("Menu")
  1186. }
  1187. disabled = ""
  1188. readonly = ""
  1189. if not editable:
  1190. disabled = 'disabled="disabled"'
  1191. readonly = 'readonly="readonly"'
  1192. out += '''
  1193. <form action="output_format_update_attributes?ln=%(ln)s&amp;bfo=%(code)s" method="POST">
  1194. <table class="admin_wvar" cellspacing="0">
  1195. <tr>
  1196. <th colspan="2" class="adminheaderleft">
  1197. Output Format Attributes&nbsp;[<a href="%(siteurl)s/help/admin/bibformat-admin-guide#attrsOutputFormat">?</a>]</th>
  1198. </tr>
  1199. <tr>
  1200. <td class="admintdright"><label for="outputFormatCode">Code</label>:&nbsp;</td>
  1201. <td><input tabindex="0" name="code" type="text" id="outputFormatCode" maxlength="6" size="6" value="%(code)s" %(readonly)s/></td>
  1202. </tr>
  1203. <tr>
  1204. <td class="admintdright">Visibility:&nbsp;</td>
  1205. <td><input tabindex="1" name="visibility" type="checkbox" id="outputFormatVisibility" %(visibility)s %(disabled)s value="1" /><small><label for="outputFormatVisibility">Show in list of available output formats (on public pages)</label></small></td>
  1206. </tr>
  1207. <td class="admintdright"><label for="outputFormatContentType">Content type</label>:&nbsp;</td>
  1208. <td><input tabindex="2" name="content_type" type="text" id="outputFormatContentType" size="25" value="%(content_type)s" %(readonly)s/> <small>Mime content-type. Specifies how the browser should handle this output.</small></td>
  1209. <tr>
  1210. <td class="admintdright"><label for="outputFormatName">Name</label>:&nbsp;</td>
  1211. <td><input tabindex="3" name="name" type="text" id="outputFormatName" size="25" value="%(name)s" %(readonly)s/></td>
  1212. </tr>
  1213. ''' % {'name': name,
  1214. 'ln':ln,
  1215. 'code':code,
  1216. 'content_type':content_type,
  1217. 'readonly':readonly,
  1218. 'siteurl':CFG_SITE_URL,
  1219. 'visibility': visible==1 and 'checked="checked"' or '',
  1220. 'disabled':disabled}
  1221. #Add translated names
  1222. i = 3
  1223. for name_trans in names_trans:
  1224. i += 1
  1225. out += '''
  1226. <tr>
  1227. <td class="admintdright"><label for="outputFormatName%(i)s">%(lang)s Name</label>:&nbsp;</td>
  1228. <td><input tabindex="%(i)s" name="names_trans" type="text" id="outputFormatName%(i)s" size="25" value="%(name)s" %(readonly)s/></td>
  1229. </tr>''' % {'name':name_trans['trans'],
  1230. 'lang':name_trans['lang'],
  1231. 'i':i,
  1232. 'readonly':readonly}
  1233. #Description and end of page
  1234. out += '''
  1235. <tr>
  1236. <td class="admintdright" valign="top"><label for="outputFormatDescription">Description</label>:&nbsp;</td>
  1237. <td><textarea tabindex="%(tabindexdesc)s" name="description" id="outputFormatDescription" rows="4" cols="25" %(readonly)s>%(description)s</textarea> </td>
  1238. </tr>
  1239. <tr>
  1240. <td colspan="2" align="right"><input tabindex="%(tabindexbutton)s" class="adminbutton" type="submit" value="Update Output Format Attributes" %(disabled)s/></td>
  1241. </tr>
  1242. </table>
  1243. </form>
  1244. ''' % {'description': description,
  1245. 'tabindexdesc': i + 1,
  1246. 'tabindexbutton': i + 2,
  1247. 'readonly':readonly,
  1248. 'disabled':disabled}
  1249. return out
  1250. def tmpl_admin_output_format_show_dependencies(self, ln, name, code, format_templates):
  1251. """
  1252. Shows the dependencies of the given format.
  1253. @param name: the name of the output format
  1254. @param code: the code of the output format
  1255. @param format_templates: format templates that depend on this format (and also elements and tags)
  1256. """
  1257. _ = gettext_set_language(ln) # load the right message language
  1258. out = '''
  1259. <table class="admin_wvar">
  1260. <tr><th colspan="4" class="adminheaderleft" cellspacing="0">%(menu)s</th></tr>
  1261. <tr>
  1262. <td>0.&nbsp;<small><a href="output_formats_manage?ln=%(ln)s">%(close_output_format)s</a></small>&nbsp;</td>
  1263. <td>1.&nbsp;<small><a href="output_format_show?ln=%(ln)s&amp;bfo=%(code)s">%(rules)s</a></small>&nbsp;</td>
  1264. <td>2.&nbsp;<small><a href="output_format_show_attributes?ln=%(ln)s&amp;bfo=%(code)s">%(modify_output_format_attributes)s</a></small>&nbsp;</td>
  1265. <td>3.&nbsp;<small>%(check_dependencies)s</small>&nbsp;</td>
  1266. </tr>
  1267. </table><br/>
  1268. <table width="90%%" class="admin_wvar" cellspacing="0"><tr>
  1269. <th class="adminheaderleft">Format Templates that use %(name)s</th>
  1270. <th class="adminheaderleft">Format Elements used by %(name)s</th>
  1271. <th class="adminheaderleft">Tags Called*</th>
  1272. </tr>
  1273. ''' % {'name': name,
  1274. 'code': code,
  1275. 'ln':ln,
  1276. 'close_output_format':_("Close Output Format"),
  1277. 'rules':_("Rules"),
  1278. 'modify_output_format_attributes':_("Modify Output Format Attributes"),
  1279. 'check_dependencies':_("Check Dependencies"),
  1280. 'menu': _("Menu")
  1281. }
  1282. if len(format_templates) == 0:
  1283. out += '''<tr><td colspan="3"><p align="center">
  1284. <i>This output format uses no format template.</i></p></td></tr>'''
  1285. for format_template in format_templates:
  1286. name = format_template['name']
  1287. filename = format_template['filename']
  1288. out += '''<tr><td><a href="format_template_show?bft=%(filename)s&amp;ln=%(ln)s">%(name)s</a></td>
  1289. <td>&nbsp;</td><td>&nbsp;</td></tr>''' % {'filename':filename,
  1290. 'name':name,
  1291. 'ln':ln}
  1292. for format_element in format_template['elements']:
  1293. name = format_element['name']
  1294. filename = format_element['filename']
  1295. out += '''<tr><td>&nbsp;</td>
  1296. <td><a href="format_elements_doc?ln=%(ln)s#%(anchor)s">%(name)s</a></td>
  1297. <td>&nbsp;</td></tr>''' % {'anchor':name.upper(),
  1298. 'name':name,
  1299. 'ln':ln}
  1300. for tag in format_element['tags']:
  1301. out += '''<tr><td>&nbsp;</td><td>&nbsp;</td>
  1302. <td>%(tag)s</td></tr>''' % {'tag':tag}
  1303. out += '''
  1304. </table>
  1305. <b>*Note</b>: Some tags linked with this format template might not be shown. Check manually.
  1306. '''
  1307. return out
  1308. def tmpl_admin_format_elements_documentation(self, ln, format_elements):
  1309. """
  1310. Returns the main management console for format elements. Includes list of formats elements and
  1311. associated administration tools.
  1312. @param ln: language
  1313. @param formats: a list of dictionaries with formats elements attributes
  1314. @return: main management console as html
  1315. """
  1316. _ = gettext_set_language(ln) # load the right message language
  1317. #top of the page and table header
  1318. out = '''
  1319. <table class="admin_wvar" cellspacing="0">
  1320. <tr><th colspan="4" class="adminheaderleft">%(menu)s</th></tr>
  1321. <tr>
  1322. <td>0.&nbsp;<small><a href="format_templates_manage?ln=%(ln)s">%(manage_format_templates)s</a></small>&nbsp;</td>
  1323. <td>1.&nbsp;<small><a href="output_formats_manage?ln=%(ln)s">%(manage_output_formats)s</a></small>&nbsp;</td>
  1324. <td>2.&nbsp;<small>%(format_elements_documentation)s</small>&nbsp;</td>
  1325. </tr>
  1326. </table>
  1327. <p>Here you can read the APIs of the formats elements, the elementary bricks for formats.</p>
  1328. ''' % {'ln':ln,
  1329. 'menu': _("Menu"),
  1330. 'manage_output_formats':_("Manage Output Formats"),
  1331. 'manage_format_templates':_("Manage Format Templates"),
  1332. 'format_elements_documentation':_("Format Elements Documentation"),
  1333. }
  1334. #table content: formats names, description and actions
  1335. if len(format_elements) == 0:
  1336. out += '''
  1337. <em>No format elements found</em>
  1338. '''
  1339. else:
  1340. #Print summary of elements (name + decription)
  1341. out += '''<h2>Summary table of elements</h2>'''
  1342. out += '''<table width="90%">'''
  1343. for format_element in format_elements:
  1344. format_attributes = format_element['attrs']
  1345. out += '''
  1346. <tr>
  1347. <td>
  1348. <code><a href="#%(name)s">&lt;BFE_%(name)s/&gt;</a></code>
  1349. </td>
  1350. <td>
  1351. %(description)s
  1352. </td>
  1353. </tr>
  1354. ''' % format_attributes
  1355. out += "</table>"
  1356. #Print details of elements
  1357. out += '''<h2>Details of elements</h2>'''
  1358. for format_element in format_elements:
  1359. format_attributes = format_element['attrs']
  1360. element_name = format_attributes['name']
  1361. out += self.tmpl_admin_print_format_element_documentation(ln, element_name, format_attributes)
  1362. #table footer, buttons and bottom of the page
  1363. out += '''
  1364. <table align="center" width="95%">
  1365. </table>'''
  1366. return out
  1367. def tmpl_admin_print_format_element_documentation(self, ln, name, attributes, print_see_also=True):
  1368. """
  1369. Prints the formatted documentation of a single element. Used in main documentation of element and
  1370. in creation of floater for Dreamweaver.
  1371. @param ln: language
  1372. @param name: the name of the element
  1373. @param attributes: the attributes of the element, as returned by get_format_element_attrs_from_*
  1374. @param print_see_also: if True, prints links to other sections related to element
  1375. """
  1376. params_names = ""
  1377. for param in attributes['params']:
  1378. params_names += "<b>"+param['name'] +'</b>="..." '
  1379. out = '''
  1380. <a name="%(name)s"></a><h3>%(name)s</h3>
  1381. <b>&lt;BFE_%(name)s</b> %(params_names)s<b>/&gt;</b><br/><br/>
  1382. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<em>%(description)s.</em><br/><br/>
  1383. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Parameters:</b><br/>
  1384. ''' % {'params_names': params_names,
  1385. 'name':name,
  1386. 'description': attributes['description']}
  1387. for param in attributes['params']:
  1388. out += '''
  1389. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  1390. <code>%(name)s</code> - %(description)s. ''' % param
  1391. if param['default'] != "":
  1392. default = cgi.escape(str(param['default']))
  1393. if default.strip() == "":
  1394. default = "&nbsp;"
  1395. out += '''
  1396. Default value is &laquo;<code>%s</code>&raquo;
  1397. ''' % default
  1398. out += '<br/>'
  1399. for param in attributes['builtin_params']:
  1400. out += '''
  1401. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  1402. <code>%(name)s</code> - %(description)s. ''' % param
  1403. if param['default'] != "":
  1404. default = cgi.escape(str(param['default']))
  1405. if default.strip() == "":
  1406. default = "&nbsp;"
  1407. out += '''
  1408. Default value is &laquo;<code>%s</code>&raquo;
  1409. ''' % default
  1410. out += '<br/>'
  1411. if print_see_also:
  1412. out += '''<br/>
  1413. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  1414. <b>See also:</b><br/>'''
  1415. for element in attributes['seealso']:
  1416. element_name = element.split('.')[0].upper()
  1417. out += '''
  1418. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  1419. <a href="#%(name)s">Element <em>%(name)s</em></a><br/>''' % {'name':element_name}
  1420. out += '''
  1421. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  1422. <a href ="format_element_show_dependencies?ln=%(ln)s&amp;bfe=%(bfe)s">Dependencies of this element</a><br/>
  1423. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  1424. <a href ="validate_format?ln=%(ln)s&amp;bfe=%(bfe)s">The correctness of this element</a><br/>
  1425. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  1426. <a href ="format_element_test?ln=%(ln)s&amp;bfe=%(bfe)s">Test this element</a><br/>
  1427. ''' % {'ln':ln, 'bfe':name}
  1428. return out
  1429. def tmpl_admin_format_element_show_dependencies(self, ln, name, format_templates, tags):
  1430. """
  1431. Shows the dependencies of the given format element
  1432. @param name: the name of the element
  1433. @param format_templates: format templates that depend on this element
  1434. @param tags: the tags that are called by this format element
  1435. """
  1436. out = '''
  1437. <p>Go back to <a href="format_elements_doc?ln=%(ln)s#%(name)s">documentation</a></p>
  1438. ''' % {'ln':ln, 'name':name.upper()}
  1439. out += ''' <table width="90%" class="admin_wvar" cellspacing="0"><tr>'''
  1440. out += '''
  1441. <th class="adminheaderleft">Format Templates that use %(name)s</th>
  1442. <th class="adminheaderleft">Tags Called*</th>
  1443. </tr>
  1444. <tr>
  1445. <td>&nbsp;<br/>''' % {"name": name}
  1446. #Print format elements (and tags)
  1447. if len(format_templates) == 0:
  1448. out += '''<p align="center">
  1449. <i>This format element is not used in any format template.</i></p>'''
  1450. for format_template in format_templates:
  1451. name = format_template['name']
  1452. filename = format_template['filename']
  1453. out += '''<a href="format_template_show?ln=%(ln)s&amp;bft=%(filename)s">%(name)s</a><br/>''' % {'filename':filename,
  1454. 'name':name,
  1455. 'ln':ln}
  1456. #Print tags
  1457. out += "</td><td>&nbsp;<br/>"
  1458. if len(tags) == 0:
  1459. out += '''<p align="center">
  1460. <i>This format element uses no tag.</i></p>'''
  1461. for tag in tags:
  1462. out += '''%(tag)s<br/>''' % {'tag':tag}
  1463. out += '''
  1464. </td>
  1465. </tr>
  1466. </table>
  1467. <b>*Note</b>: Some tags linked with this format template might not be shown. Check manually.
  1468. '''
  1469. return out
  1470. def tmpl_admin_format_element_test(self, ln, bfe, description, param_names, param_values, param_descriptions, result):
  1471. """
  1472. Prints a page where the user can test the given format element with his own parameters.
  1473. @param ln: language
  1474. @param bfe: the format element name
  1475. @param description: a description of the element
  1476. @param param_names: a list of parameters names/labels
  1477. @param param_values: a list of values for parameters
  1478. @param param_descriptions: a list of description for parameters
  1479. @param result: the result of the evaluation
  1480. """
  1481. out = '''
  1482. <p>Go back to <a href="format_elements_doc?ln=%(ln)s#%(name)s">documentation</a></p>
  1483. ''' % {'ln':ln, 'name':bfe.upper()}
  1484. out += '''
  1485. <h3>&lt;BFE_%(bfe)s /&gt;</h3>
  1486. <p>%(description)s</p>
  1487. <table width="100%%"><tr><td>
  1488. <form method="post" action="format_element_test?ln=%(ln)s&amp;bfe=%(bfe)s">
  1489. <table>
  1490. ''' % {'bfe':bfe, 'ln':ln, 'description':description }
  1491. for i in range(len(param_names)):
  1492. out += '''
  1493. <tr>
  1494. <td class="admintdright">%(name)s</td>
  1495. <td class="admintdright"><input type="text" name="param_values" value="%(value)s"/></td>
  1496. <td class="admintdleft">%(description)s&nbsp;</td>
  1497. </tr>
  1498. ''' % {'name':param_names[i],
  1499. 'value':param_values[i],
  1500. 'description':param_descriptions[i]}
  1501. out += '''
  1502. <tr><td colspan="2" class="admintdright"><input type="submit" class="adminbutton" value="Test!"/></td>
  1503. <td>&nbsp;</td>
  1504. </tr>
  1505. </table>
  1506. </form>
  1507. <fieldset style="display:inline;margin-left:auto;margin-right:auto;">
  1508. <legend>Result:</legend>%(result)s</fieldset>
  1509. ''' % {'result':result}
  1510. out += '''
  1511. </td></tr><tr><td>
  1512. '''
  1513. #out += self.tmpl_admin_print_format_element_documentation(ln, bfe, attributes, False)
  1514. out += '''</td></tr></table>'''
  1515. return out
  1516. def tmpl_admin_add_format_element(self, ln):
  1517. """
  1518. Shows how to add a format element (mainly doc)
  1519. @param ln: language
  1520. """
  1521. _ = gettext_set_language(ln) # load the right message language
  1522. out = '''
  1523. <p>To add a new basic element (only fetch the value of a field, without special post-processing), go to the <a href="%(siteurl)sadmin/bibindex/bibindexadmin.py/field">BibEdit "Manage Logical Fields"</a> page and add a name for a field. Make sure that the name is unique and corresponds well to the field. For example, to add an element that fetch the value of field 245__%%, add a new logical field with name "title" and field "245__%%". Then in your template, call BFE_TITLE to print the title.</p>
  1524. <p>To add a new complex element (for eg. special formatting of the field, condition on the value, etc.) you must go to the lib/python/invenio/bibformat_elements directory of your Invenio installation, and add a new format element file. Read documentation for more information.</p>
  1525. ''' % {'siteurl':CFG_SITE_URL}
  1526. return out
  1527. def tmpl_dreamweaver_floater(self, ln, format_elements):
  1528. """
  1529. Returns the content of the BibFormat palette for Dreamweaver. This
  1530. 'floater' will let users of Dreamweaver to insert Format elements
  1531. into their code right from the floater.
  1532. @param format_elements: an ordered list of format elements structures as returned by get_format_elements
  1533. """
  1534. names_list = [] # list of element names such as ['Authors', 'Title']
  1535. codes_list = [] # list of element code such as ['<BFE_AUTHORS limit="" separator="," />', '<BFE_TITLE />']
  1536. docs_list = [] # list of HTML doc for each element
  1537. for format_element in format_elements:
  1538. format_attributes = format_element['attrs']
  1539. name = format_attributes['name']
  1540. #description = format_attributes['description']
  1541. params = [x['name'] + '="'+str(x['default'])+'"' for x in format_attributes['params']]
  1542. builtin_params = [x['name'] + '="'+str(x['default'])+'"' for x in format_attributes['builtin_params']]
  1543. code = ("<BFE_" + name + ' ' + ' '.join(builtin_params)+ ' ' + ' '.join(params) +"/>").replace("'", r"\'")
  1544. doc = self.tmpl_admin_print_format_element_documentation(ln, name, format_attributes, print_see_also=False).replace("'", r"\'")
  1545. names_list.append(name)
  1546. codes_list.append(code)
  1547. docs_list.append(doc)
  1548. out = '''
  1549. <!DOCTYPE HTML SYSTEM "-//Macromedia//DWExtension layout-engine5.0//floater">
  1550. <html>
  1551. <head>
  1552. <!-- This file is to be used as floating panel for Dreamweaver.
  1553. To install, drag and drop inside /Configuration/Floaters of your Dreamweaver
  1554. application directory. You also have to enable a menu to open the floater:
  1555. Edit file Menu.xml located inside /Configuration/Menus of your Dreamweaver
  1556. application directory and copy-paste the following line in the menu you want
  1557. (typically inside tag 'menu' with attribute id = 'DWMenu_Window_Others'):
  1558. <menuitem name="BibFormat Elements" enabled="true" command="dw.toggleFloater('BibFormat_floater.html')" checked="dw.getFloaterVisibility('BibFormat_floater.html')" />
  1559. -->
  1560. <title>BibFormat Elements</title>
  1561. <script language="JavaScript">
  1562. var docs = new Array(%(docs)s);
  1563. var codes = new Array(%(codes)s);
  1564. function selectionChanged(){
  1565. // get the selected node
  1566. var theDOM = dw.getDocumentDOM();
  1567. var theNode = theDOM.getSelectedNode();
  1568. // check if node is a BibFormat Element
  1569. if (theNode.nodeType == Node.COMMENT_NODE && theNode.data.length >= 5 && theNode.data.toLowerCase().substring(0,5) == "<bfe_"){
  1570. var names = document.elementsList.options;
  1571. for (i=0;i<names.length; i++){
  1572. if (names[i].text.toLowerCase() == theNode.data.split(' ')[0].toLowerCase() ||
  1573. names[i].text.toLowerCase() == theNode.data.split(' ')[0].toLowerCase().substring(5,theNode.data.length)){
  1574. document.elementsList.selectedIndex = i;
  1575. selectElement(document.elementsList);
  1576. return;
  1577. }
  1578. }
  1579. }
  1580. }
  1581. function isAvailableInCodeView(){
  1582. return true;
  1583. }
  1584. function selectElement(elementsList){
  1585. document.infoBFE.innerHTML = docs[elementsList.selectedIndex];
  1586. }
  1587. function insertElement(){
  1588. // insert selection into code
  1589. var element_code = codes[document.elementsList.selectedIndex];
  1590. // get the DOM
  1591. var theDOM = dw.getDocumentDOM();
  1592. var theDocEl = theDOM.documentElement;
  1593. var theWholeDoc = theDocEl.outerHTML;
  1594. // Get the offsets of the selection
  1595. var theSel = theDOM.getSelection();
  1596. theDocEl.outerHTML = theWholeDoc.substring(0,theSel[0]) + element_code + theWholeDoc.substring(theSel[1]);
  1597. }
  1598. </script>
  1599. </head>
  1600. <body>
  1601. <table width="100%%" border="0" cellspacing="0" cellpadding="3">
  1602. <tr>
  1603. <td valign="top">
  1604. <select name="elementsList" id="elementsList" size="15" onChange="selectElement(this)">
  1605. %(names)s
  1606. </select><br/>
  1607. <input type="submit" name="Submit" value="Insert" onClick="insertElement()">
  1608. </td>
  1609. <td valign="top" width="100%%">
  1610. <div id="infoBFE">
  1611. <center>No Format Element selected. Select one from the list on the right.</center>
  1612. </div>
  1613. </td>
  1614. </tr>
  1615. </table>
  1616. </body>
  1617. </html>
  1618. ''' % {'docs': ', '.join(["'"+x+"'" for x in docs_list]).replace('\n','\\n'),
  1619. 'codes': ', '.join(["'"+x+"'" for x in codes_list]).replace('\n','\\n'),
  1620. 'names': '\n'.join(['<option>'+x+'</option>' for x in names_list])}
  1621. return out
  1622. def tmpl_admin_validate_format(self, ln, errors):
  1623. """
  1624. Prints the errors of the validation of a format (might be any
  1625. kind of format)
  1626. @param ln: language
  1627. @param errors: a list of tuples (error code, string error message)
  1628. """
  1629. _ = gettext_set_language(ln) # load the right message language
  1630. out = ""
  1631. if len(errors) == 0:
  1632. out += '''<span style="color: rgb(0, 255, 0);" >%s.</span>''' % _('No problem found with format')
  1633. elif len(errors) == 1:
  1634. out += '''<span style="color: rgb(255, 0, 0);" >%s:</span><br/>''' % _('An error has been found')
  1635. else:
  1636. out += '''<span style="color: rgb(255, 0, 0);" >%s:</span><br/>''' % _('The following errors have been found')
  1637. for error in errors:
  1638. out += error + "<br/>"
  1639. return out
  1640. def tmpl_admin_dialog_box(self, url, ln, title, message, options):
  1641. """
  1642. Prints a dialog box with given title, message and options
  1643. @param url: the url of the page that must process the result of the dialog box
  1644. @param ln: language
  1645. @param title: the title of the dialog box
  1646. @param message: a formatted message to display inside dialog box
  1647. @param options: a list of string options to display as button to the user
  1648. """
  1649. out = ""
  1650. out += '''
  1651. <div style="text-align:center;">
  1652. <fieldset style="display:inline;margin-left:auto;margin-right:auto;">
  1653. <legend>%(title)s:</legend>
  1654. <p>%(message)s</p>
  1655. <form method="post" action="%(url)s">
  1656. ''' % {'title':title,
  1657. 'message':message,
  1658. 'url':url}
  1659. for option in options:
  1660. out += '''<input type="submit" class="adminbutton" name="chosen_option" value="%(value)s" />&nbsp;''' % {'value':option}
  1661. out += '''</form></fieldset></div>'''
  1662. return out