Page MenuHomec4science

bibedit_templates.py
No OneTemporary

File Metadata

Created
Mon, Jun 24, 12:20

bibedit_templates.py

## This file is part of CDS Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN.
##
## CDS Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## CDS Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with CDS Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
# pylint: disable-msg=C0103
"""BibEdit Templates."""
__revision__ = "$Id$"
from invenio.config import CFG_SITE_URL, CFG_SITE_LANG
from invenio.messages import gettext_set_language
from urllib import quote
class Template:
"""BibEdit Templates Class."""
def __init__(self):
"""Initialize."""
pass
def menu(self):
"""Create the menu."""
imgCompressMenuSection = img('/img/bullet_toggle_minus.png',
'bibEditImgCompressMenuSection')
recordmenu = '<div class="bibEditMenuSectionHeader">\n' \
' %(imgCompressMenuSection)sRecord\n' \
' %(imgNewRecord)s\n' \
' %(imgCloneRecord)s\n' \
' </div>\n' \
' <table>\n' \
' <col width="28px">\n' \
' <col width="40px">\n' \
' <col width="40px">\n' \
' <col width="28px">\n' \
' <tr>\n' \
' <td colspan="2">\n' \
' <form onsubmit="return false;">\n' \
' %(txtSearchPattern)s\n' \
' </form>\n' \
' <td colspan="2">%(sctSearchType)s</td>\n' \
' </tr>\n' \
' <tr>\n' \
' <td colspan="4">%(btnSearch)s</td>\n' \
' </tr>\n' \
' <tr id="rowRecordBrowser" style="display: none">\n' \
' <td>%(btnPrev)s</td>\n' \
' <td colspan="2" id="cellRecordNo"\n' \
' style="text-align: center">1/1</td>\n' \
' <td>%(btnNext)s</td>\n' \
' </tr>\n' \
' <tr>\n' \
' <td colspan="2">%(btnSubmit)s</td>\n' \
' <td colspan="2">%(btnCancel)s</td>\n' \
' </tr>\n' \
' <tr>\n' \
' <td id="tickets" colspan="4"><!--filled by bibedit_menu.js--></td>\n' \
' </tr>\n' \
' <tr class="bibEditMenuMore">\n' \
' <td>%(imgDeleteRecord)s</td>\n' \
' <td colspan="3">%(btnDeleteRecord)s</td>\n' \
' </tr>\n' \
' <tr class="bibEditmenuMore">\n' \
' <td>Switch to:</td>\n' \
' <td colspan="3">%(btnSwitchReadOnly)s</td>\n' \
' </tr>' \
' </table>' % {
'imgCompressMenuSection': imgCompressMenuSection,
'imgNewRecord': img('/img/table.png', 'bibEditImgCtrlEnabled',
id='imgNewRecord', title='New record'), \
'imgCloneRecord': img('/img/table_multiple.png',
'bibEditImgCtrlDisabled', id='imgCloneRecord',
title='Clone record'), \
'txtSearchPattern': inp('text', id='txtSearchPattern'), \
'sctSearchType': '<select id="sctSearchType">\n' \
' <option value="recID">Rec ID</option>\n' \
' <option value="reportnumber">Rep No</option>\n' \
' <option value="anywhere">Anywhere</option>\n' \
' </select>',
'btnSearch': button('button', 'Search', 'bibEditBtnBold',
id='btnSearch'),
'btnPrev': button('button', '&lt;', id='btnPrev', disabled='disabled'),
'btnNext': button('button', '&gt;', id='btnNext', disabled='disabled'),
'btnSubmit': button('button', 'Submit', 'bibEditBtnBold',
id='btnSubmit', disabled='disabled'),
'btnCancel': button('button', 'Cancel', id='btnCancel',
disabled='disabled'),
'imgDeleteRecord': img('/img/table_delete.png'),
'btnDeleteRecord': button('button', 'Delete',
id='btnDeleteRecord', disabled='disabled'),
'btnSwitchReadOnly' : button('button', 'Read-only',
id='btnSwitchReadOnly')
}
fieldmenu = '<div class="bibEditMenuSectionHeader">\n' \
' %(imgCompressMenuSection)sFields\n' \
' </div>\n' \
' <table class="bibEditMenuMore">\n' \
' <col width="28px">\n' \
' <col>\n' \
' <tr>\n' \
' <td>%(imgAddField)s</td>\n' \
' <td>%(btnAddField)s</td>\n' \
' </tr>\n' \
' <tr>\n' \
' <td>%(imgDeleteSelected)s</td>\n' \
' <td>%(btnDeleteSelected)s</td>\n' \
' </tr>\n' \
' </table>' % {
'imgCompressMenuSection': imgCompressMenuSection,
'imgAddField': img('/img/table_row_insert.png'),
'btnAddField': button('button', 'Add', id='btnAddField',
disabled='disabled'),
'imgDeleteSelected': img('/img/table_row_delete.png'),
'btnDeleteSelected': button('button', 'Delete selected',
id='btnDeleteSelected', disabled='disabled')}
viewmenu = '<div class="bibEditMenuSectionHeader">\n' \
' %(imgCompressMenuSection)sView\n' \
' </div>\n' \
' <table>\n' \
' <col width="68px">\n' \
' <col width="68px">\n' \
' <tr class="bibEditMenuMore">\n' \
' <td>%(btnTagMARC)s</td>\n' \
' <td>%(btnTagNames)s</td>\n' \
' </tr>\n' \
' </table>' % {
'imgCompressMenuSection': imgCompressMenuSection,
'btnTagMARC': button('button', 'MARC', id='btnMARCTags',
disabled='disabled'),
'btnTagNames': button('button', 'Human', id='btnHumanTags',
disabled='disabled')
}
historymenu = '<div class="bibEditMenuSectionHeader">\n' \
' %(imgCompressMenuSection)sHistory\n' \
' </div>\n' \
' <div class="bibEditRevHistoryMenuSection">\n' \
' <table>\n' \
' <col width="136px">\n' \
' <tr class="bibEditMenuMore">\n' \
' <td id="bibEditRevisionsHistory"></td>'\
' </tr>\n' \
' </table>\n' \
' </div>\n'% {
'imgCompressMenuSection': imgCompressMenuSection,
}
undoredosection = '<div class="bibEditMenuSectionHeader">\n' \
' %(imgCompressMenuSection)sUndo/Redo\n' \
' </div>\n<table>' \
' <tr class="bibEditMenuMore"><td>' \
' <div class="bibEditURMenuSection">\n' \
' <div class="bibEditURDetailsSection" id="bibEditURUndoListLayer">\n' \
' <div class="bibEditURButtonLayer"><button id="btnUndo">&lt;</button></div>\n' \
' <div id="undoOperationVisualisationField" class="bibEditHiddenElement bibEditURPreviewBox">\n' \
' <div id="undoOperationVisualisationFieldContent"></div>\n' \
' </div>\n' \
' </div>' \
' <div class="bibEditURDetailsSection" id="bibEditURRedoListLayer">\n' \
' <div class="bibEditURButtonLayer"><button id="btnRedo">&gt;</button></div>' \
' <div id="redoOperationVisualisationField" class="bibEditHiddenElement bibEditURPreviewBox">\n' \
' <div id="redoOperationVisualisationFieldContent"></div>' \
' </div>\n' \
' </div>\n' \
' </div></td></tr></table>\n' % { \
'imgCompressMenuSection': imgCompressMenuSection }
statusarea = '<table>\n' \
' <tr>\n' \
' <td id="cellIndicator">%(imgIndicator)s</td>\n' \
' <td id="cellStatus">%(lblChecking)s</td>\n' \
' </table>' % {
'imgIndicator': img('/img/indicator.gif'),
'lblChecking': 'Checking status' + '...'
}
holdingpenpanel = '<div class="bibEditMenuSectionHeader">\n' \
' %(imgCompressMenuSection)sHolding Pen\n' \
'<table class="bibEditMenuMore">\n<tr><td>' \
' <div id="bibEditHoldingPenToolbar"> ' \
' <div id="bibeditHPChanges"></div>' \
' </div> </td></tr></table>' \
' </div>\n' %{ 'imgCompressMenuSection': imgCompressMenuSection,
}
# self.holdingPenPanel(CFG_SITE_LANG)
lnkhelp = img('/img/help.png', '', style='vertical-align: bottom') + \
link('Help', href='#', onclick='window.open(' \
'\'%s/help/admin/bibedit-admin-guide#2\', \'\', \'width=640,' \
'height=600,left=150,top=150,resizable=yes,scrollbars=yes\');' \
'return false;' % CFG_SITE_URL)
return ' <div id="bibEditMenu">\n' \
' <div class="bibEditMenuSection">\n' \
' %(recordmenu)s\n' \
' </div>\n' \
' <div class="bibEditMenuSection">\n' \
' %(fieldmenu)s\n' \
' </div>\n' \
' <div class="bibEditMenuSection">\n' \
' %(viewmenu)s\n' \
' </div>\n' \
' <div class="bibEditMenuSection">\n' \
' %(holdingpenpanel)s\n'\
' </div>'\
' <div class="bibEditMenuSection">\n' \
' %(undoredosection)s\n' \
' </div>\n' \
' <div class="bibEditMenuSection">\n' \
' %(historymenu)s\n' \
' </div>\n' \
' <div id="bibEditMenuSection">\n' \
' %(statusarea)s\n' \
' </div>\n' \
' <div class="bibEditMenuSection" align="right">\n' \
' %(lnkhelp)s\n' \
' </div>\n' \
' </div>\n' % {
'recordmenu': recordmenu,
'viewmenu': viewmenu,
'fieldmenu': fieldmenu,
'statusarea': statusarea,
'lnkhelp': lnkhelp,
'holdingpenpanel': holdingpenpanel,
'historymenu': historymenu,
'undoredosection': undoredosection
}
def history_comparebox(self, ln, revdate, revdate_cmp, comparison):
""" Display the bibedit history comparison box. """
_ = gettext_set_language(ln)
title = '<b>%(comp)s</b><br />%(rev)s %(revdate)s<br />%(rev)s %(revdate_cmp)s' % {
'comp': _('Comparison of:'),
'rev': _('Revision'),
'revdate': revdate,
'revdate_cmp': revdate_cmp}
return '''
<div class="bibEditHistCompare">
<p>%s</p>
<p>
%s
</p>
</div>''' % (title, comparison)
def clean_value(self, value, format):
""" This function clean value for HTML interface and inverse. """
if format != "html":
value = value.replace('"', '&quot;')
value = value.replace('<', '&lt;')
value = value.replace('>', '&gt;')
else:
value = value.replace('&quot;', '"')
value = value.replace('&lt;', '<')
value = value.replace('&gt;', '>')
return value
def img(src, _class='', **kargs):
"""Create an HTML <img> element."""
src = 'src="%s" ' % src
if _class:
_class = 'class="%s" ' % _class
args = ''
for karg in kargs:
args += '%s="%s" ' % (karg, kargs[karg])
return '<img %s%s%s/>' % (src, _class, args)
def inp(_type, _class='', **kargs):
"""Create an HTML <input> element."""
_type = 'type="%s" ' % _type
if _class:
_class = 'class="%s" ' % _class
args = ''
for karg in kargs:
args += '%s="%s" ' % (karg, kargs[karg])
return '<input %s%s%s/>' % (_type, _class, args)
def button(_type, value, _class='', **kargs):
"""Create an HTML <button> element."""
_type = 'type="%s" ' % _type
if _class:
_class = 'class="%s" ' % _class
args = ''
for karg in kargs:
args += '%s="%s" ' % (karg, kargs[karg])
return '<button %s%s%s>%s</button>' % (_type, _class, args, value)
def link(value, _class='', **kargs):
"""Create an HTML <a> (link) element."""
if _class:
_class = 'class="%s" ' % _class
args = ''
for karg in kargs:
args += '%s="%s" ' % (karg, kargs[karg])
return '<a %s%s>%s</a>' % (_class, args, value)

Event Timeline