2008-04-10 19:40:17 +00:00
|
|
|
import re
|
2008-04-12 00:51:32 +00:00
|
|
|
from Tags import Div, Span, H4, A, Table, Tr, Td
|
2008-04-09 23:31:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Note_tree_area( Div ):
|
2008-04-12 00:51:32 +00:00
|
|
|
LINK_PATTERN = re.compile( u'<a\s+(?:[^>]+\s)?href="[^"]+"[^>]*>', re.IGNORECASE )
|
2008-04-10 19:40:17 +00:00
|
|
|
|
2008-04-09 23:31:30 +00:00
|
|
|
def __init__( self, toolbar, notebook, root_notes, total_notes_count ):
|
|
|
|
Div.__init__(
|
|
|
|
self,
|
|
|
|
toolbar,
|
|
|
|
Div(
|
|
|
|
H4( u"notes",
|
|
|
|
Span(
|
|
|
|
Span( total_notes_count, id = u"total_notes_count" ), u"total",
|
|
|
|
class_ = u"small_text link_area_item",
|
|
|
|
),
|
|
|
|
id = u"note_tree_area_title",
|
|
|
|
),
|
2008-04-12 00:51:32 +00:00
|
|
|
self.make_tree(
|
|
|
|
[ self.make_item(
|
|
|
|
title = note.title,
|
2008-04-13 07:28:32 +00:00
|
|
|
link_attributes = u'href="/notebooks/%s?note_id=%s"' % ( notebook.object_id, note.object_id ),
|
2008-04-12 00:51:32 +00:00
|
|
|
link_class = u"note_tree_link",
|
|
|
|
has_children = self.LINK_PATTERN.search( note.contents ),
|
|
|
|
root_note_id = note.object_id,
|
|
|
|
) for note in root_notes ],
|
|
|
|
),
|
2008-04-13 07:28:32 +00:00
|
|
|
id = u"note_tree_area_holder",
|
2008-04-09 23:31:30 +00:00
|
|
|
),
|
2008-04-12 00:51:32 +00:00
|
|
|
Span( id = "tree_arrow_hover_preload" ),
|
|
|
|
Span( id = "tree_arrow_down_preload" ),
|
|
|
|
Span( id = "tree_arrow_down_hover_preload" ),
|
2008-04-09 23:31:30 +00:00
|
|
|
id = u"note_tree_area",
|
|
|
|
)
|
2008-04-12 00:51:32 +00:00
|
|
|
|
|
|
|
@staticmethod
|
2008-04-12 02:32:11 +00:00
|
|
|
def make_item( title, link_attributes, link_class, has_children = False, root_note_id = None, target = None ):
|
2008-04-12 00:51:32 +00:00
|
|
|
return Tr(
|
|
|
|
has_children and \
|
|
|
|
Td( id = root_note_id and u"note_tree_expander_" + root_note_id or None, class_ = u"tree_expander" ) or
|
|
|
|
Td( id = root_note_id and u"note_tree_expander_" + root_note_id or None, class_ = u"tree_expander_empty" ),
|
|
|
|
Td(
|
2008-04-12 02:32:11 +00:00
|
|
|
u"<a %s%s%s class=%s>%s</a>" % (
|
2008-04-12 00:51:32 +00:00
|
|
|
link_attributes,
|
2008-04-12 02:32:11 +00:00
|
|
|
root_note_id and u' id="note_tree_link_%s"' % root_note_id or "",
|
|
|
|
target and u' target="%s"' % target or "",
|
2008-04-12 00:51:32 +00:00
|
|
|
link_class,
|
|
|
|
title or u"untitled note",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
id = root_note_id and u"note_tree_item_" + root_note_id or None,
|
|
|
|
class_ = u"note_tree_item",
|
|
|
|
)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def make_tree( items, tree_id = None ):
|
|
|
|
return Table(
|
|
|
|
items,
|
2008-04-13 07:28:32 +00:00
|
|
|
class_ = u"note_tree_table",
|
2008-04-12 00:51:32 +00:00
|
|
|
)
|