[Mpuls-commits] r278 - in wasko/trunk: . waskaweb/config waskaweb/controllers waskaweb/lib waskaweb/model waskaweb/public/images/icons waskaweb/templates/casemanagement

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sun Feb 22 16:55:03 CET 2009


Author: teichmann
Date: 2009-02-22 16:54:58 +0100 (Sun, 22 Feb 2009)
New Revision: 278

Added:
   wasko/trunk/waskaweb/public/images/icons/undo.png
Modified:
   wasko/trunk/ChangeLog.txt
   wasko/trunk/waskaweb/config/routing.py
   wasko/trunk/waskaweb/controllers/CaseBase.py
   wasko/trunk/waskaweb/controllers/case.py
   wasko/trunk/waskaweb/controllers/navigation.py
   wasko/trunk/waskaweb/controllers/rg_aid.py
   wasko/trunk/waskaweb/lib/helpers.py
   wasko/trunk/waskaweb/lib/renderer.py
   wasko/trunk/waskaweb/model/navigation.py
   wasko/trunk/waskaweb/templates/casemanagement/formular.mako
Log:
More changes backported from offline client.


Modified: wasko/trunk/ChangeLog.txt
===================================================================
--- wasko/trunk/ChangeLog.txt	2009-02-20 15:02:29 UTC (rev 277)
+++ wasko/trunk/ChangeLog.txt	2009-02-22 15:54:58 UTC (rev 278)
@@ -1,3 +1,41 @@
+2009-02-22	Sascha L. Teichmann <teichmann at intevation.de>
+
+	More changes backported from offline client.
+
+	* waskaweb/model/navigation.py: Behavior should now be nearly
+	  identical to offline client.
+
+	* waskaweb/config/routing.py: Added a few routes to find
+	  the controllers in navigation.
+
+	* waskaweb/controllers/navigation.py: New navigation from
+	  offline client. Old toggle stuff removed.
+
+	* waskaweb/controllers/CaseBase.py: Moved some common code
+	  of navigation and case controller into base class, mainly
+	  show(), edit() and select_item(). show() and edit() are
+	  considered deprecated because the current mode is fetched
+	  from session anyway. edit/show are left in by now because
+	  there many places from where they are called directly.
+
+	* waskaweb/controllers/case.py: Removed more old special code.
+	  Implemented the undo error function.
+
+	* waskaweb/controllers/rg_aid.py: fixed some naming issues.
+	  This controller should be removed anyway.
+
+	* waskaweb/lib/helpers.py: fixed naming issues. Generating
+	  of form headers is now done with the new navigation.
+
+	* waskaweb/lib/renderer.py: Replaced javascript from
+	  offline client to call undo with a valid call to case controller.
+
+	* waskaweb/public/images/icons/undo.png: New. Image for undo 
+	  function.
+
+	* waskaweb/templates/casemanagement/formular.mako: Fixed helpers
+	  call to render form headers.
+
 2009-02-20	Sascha L. Teichmann <teichmann at intevation.de>
 
 	Bring new error system to work.

Modified: wasko/trunk/waskaweb/config/routing.py
===================================================================
--- wasko/trunk/waskaweb/config/routing.py	2009-02-20 15:02:29 UTC (rev 277)
+++ wasko/trunk/waskaweb/config/routing.py	2009-02-22 15:54:58 UTC (rev 278)
@@ -52,6 +52,7 @@
     map.connect('case/open/:id/:confirmed', controller="case", action="open")
     map.connect('case/close/:id/:confirmed', controller="case", action="close")
     map.connect('case/select/:id/:confirmed', controller="case", action="select")
+    map.connect('case/select_item/:key_id', controller="case", action="select_item")
     map.connect('case/keepActive/:id/:confirmed', controller="case", action="keepActive")
     map.connect('case/phase/:id/:confirmed', controller="case", action="phase")
     map.connect('case/printAll/:id/:empty', controller="case", action="printAll", empty=0)
@@ -60,9 +61,16 @@
     map.connect('case/markForAnonymize/:id/:confirmed', controller="case", action="markForAnonymize")
     map.connect('case/markForAnonymizeFromOverview/:id/:confirmed', controller="case", action="markForAnonymizeFromOverview")
     map.connect('case/logbook/:id/:sort_field/:sort_order', controller="case", action="logbook") #sorting of logbookentries
+
+    map.connect('case/undo_error/:error_item', controller="case", action="undo_error")
     map.connect('case/:action/:ds_id/:page_id/:form', controller="case") 
     map.connect('case/:action/:ds_id/:page_id', controller="case")
-    map.connect('navigation/:action/:ds_id/:page_id', controller="navigation")
+
+    map.connect('navigation/open_branch/:tree_id', controller="navigation", action="open_branch")
+    map.connect('navigation/close_branch/:tree_id', controller="navigation", action="close_branch")
+    map.connect('navigation/select_branch/:tree_id', controller="navigation", action="select_branch")
+
+#    map.connect('navigation/:action/:ds_id/:page_id', controller="navigation")
     map.connect('rg_aid/:action/:rg_id/:page_id/:form', controller="rg_aid") 
     map.connect('rg_aid/:action/:rg_id/:page_id', controller="rg_aid")
     map.connect('formhelp', 'case/showhelp/:help_id', controller="case", action="showHelp")

Modified: wasko/trunk/waskaweb/controllers/CaseBase.py
===================================================================
--- wasko/trunk/waskaweb/controllers/CaseBase.py	2009-02-20 15:02:29 UTC (rev 277)
+++ wasko/trunk/waskaweb/controllers/CaseBase.py	2009-02-22 15:54:58 UTC (rev 278)
@@ -31,12 +31,13 @@
 import paste
 import logging
 
-from paste.httpexceptions           import HTTPNotFound
-from waskaweb.lib.base              import *
-from waskaweb.lib.renderer          import FormDataImpl, ViewRenderer
-from waskaweb.lib.filecache         import FileCache 
-from waskaweb.model.case            import CaseFactory, LoadCaseNotExistsError 
-from waskaweb.model.repeatgroup     import AidList 
+from paste.httpexceptions       import HTTPNotFound
+from waskaweb.lib.base          import *
+from waskaweb.lib.renderer      import FormDataImpl, ViewRenderer
+from waskaweb.lib.filecache     import FileCache 
+from waskaweb.model.case        import CaseFactory, LoadCaseNotExistsError 
+from waskaweb.model.repeatgroup import AidList 
+from waskaweb.lib.security      import checkRole
 
 log = logging.getLogger(__name__)
 
@@ -63,7 +64,7 @@
 
     def _getRenderdFormElements(self, ti, ds_id, page_id=None, ro_mode=False, no_data=False):
         navigation        = self._getFormNavigation(selected_key=ti.key)
-        real_id           = ti.realId(ds_id)
+        real_id           = ds_id
         formdata          = self._getFormdata(ti, real_id, no_data)
         vr                = ViewRenderer(formdata, ro_mode)
         content           = vr.renderView(
@@ -82,12 +83,9 @@
         if not case or not self.navigation:
             redirect_to(h.url_for(controller='/case_overview'))
         errors = case.getFormErrors()
-        id     = case.id
-        #mode   = case.getMode()
-        self.navigation.setErrors([err.page for err in errors.itervalues()])
-        select_url = lambda t: '/case/select_item/%s/%s' % (id, t.key)
-        toggle_url = lambda r: '/navigation/toggle/%s/%s' % (id, r.key)
-        return self.navigation.render(select_url, toggle_url, selected_key) 
+        error_pages = set([err.page for err in errors.itervalues()])
+        file_cache  = FileCache()
+        return self.navigation.render(selected_key, file_cache, error_pages)
 
     def _getFormdata(self, treeItem, ds_id, no_data=False):
         case = session.get('case')
@@ -95,7 +93,7 @@
             redirect_to(controller="/case_overview")
         doc  = g.formedTree
         help = g.helpData
-        page = doc.getPageStore(treeItem.page, ds_id, no_data=no_data)
+        page = doc.getPageStore(treeItem.name, ds_id, no_data=no_data)
 
         form_errors = case.getFormErrors()
         formdata = FormDataImpl(
@@ -121,4 +119,62 @@
         except:
             return False
 
+    @checkRole('cm_ka')
+    def edit(self, ds_id, page_id):
+        case_session = session.get('case')
+        ds_id        = self._checkInt(ds_id)
+        page_id      = self._checkInt(page_id)
+        ti           = self.getNavigation().getTreeItem(page_id)
+        c.ds_id      = ds_id
+        real_id      = ds_id
+        # TODO: Move repieatgroup handling in an own controller
+        #factory     = CaseFactory()
+        #c.case      = factory.loadById(ds_id)
+        case_session = session.get('case')
+        case_session.setPageId(page_id)
+        case_session.setMode("edit")
+        case_session.setPageId(page_id)
+        session.save()
+
+        c.page_id = page_id
+        c.print_form = "show" # Which page to open in popup on printing?
+        content, navigation = self._getRenderdFormElements(
+            ti, ds_id, page_id, ro_mode=False)
+        c.formular = content
+        c.form_navigation = navigation 
+        return render('/casemanagement/formular.mako')
+
+    @checkRole(('admin_ka', 'cm_ka', 'pt_dlr'))
+    def select_item(self, key_id):
+        try:
+            case = session.get('case')
+        except KeyError:
+            raise HTTPNotFound()
+
+        ds_id = case.id
+
+        if case.getMode() == "show":
+            return self.show(ds_id, key_id)
+
+        return self.edit(ds_id, key_id)
+
+
+    @checkRole(('admin_ka', 'cm_ka', 'pt_dlr'))
+    def show(self, ds_id, page_id):
+        ds_id        = self._checkInt(ds_id)
+        page_id      = self._checkInt(page_id)
+        ti           = self.getNavigation().getTreeItem(page_id)
+        c.ds_id      = ds_id
+        real_id      = ds_id
+        c.page_id    = page_id
+        c.print_form = "show" # Which page to open in popup on printing?
+        case_session = session.get('case')
+        case_session.setPageId(page_id)
+        case_session.setMode("show")
+        session.save()
+        content, navigation = self._getRenderdFormElements(ti, ds_id, page_id, ro_mode=True)
+        c.formular = content
+        c.form_navigation = navigation 
+        return render('/casemanagement/formular.mako')
+
 # vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

Modified: wasko/trunk/waskaweb/controllers/case.py
===================================================================
--- wasko/trunk/waskaweb/controllers/case.py	2009-02-20 15:02:29 UTC (rev 277)
+++ wasko/trunk/waskaweb/controllers/case.py	2009-02-22 15:54:58 UTC (rev 278)
@@ -349,62 +349,6 @@
 
         return self.select(str(case.id))
 
-    @checkRole('cm_ka')
-    def edit(self, ds_id, page_id):
-        case_session = session.get('case')
-        ds_id        = self._checkInt(ds_id)
-        page_id      = self._checkInt(page_id)
-        ti           = self.getNavigation().getTreeItem(page_id)
-        c.ds_id      = ds_id
-        real_id      = ti.realId(ds_id)
-        # TODO: Move repieatgroup handling in an own controller
-        #factory     = CaseFactory()
-        #c.case      = factory.loadById(ds_id)
-        case_session = session.get('case')
-        case_session.setPageId(page_id)
-        case_session.setMode("edit")
-        case_session.setPageId(page_id)
-        session.save()
-
-        c.page_id = page_id
-        c.print_form = "show" # Which page to open in popup on printing?
-        content, navigation = self._getRenderdFormElements(
-            ti, ds_id, page_id, ro_mode=False)
-        c.formular = content
-        c.form_navigation = navigation 
-        return render('/casemanagement/formular.mako')
-
-    @checkRole(('admin_ka', 'cm_ka', 'pt_dlr'))
-    def select_item(self, ds_id, page_id):
-        try:
-            case_session = session.get('case')
-        except KeyError:
-            raise HTTPNotFound()
-
-        if case_session.getMode() == "show":
-            return self.show(ds_id, page_id)
-
-        return self.edit(ds_id, page_id)
-
-
-    @checkRole(('admin_ka', 'cm_ka', 'pt_dlr'))
-    def show(self, ds_id, page_id):
-        ds_id        = self._checkInt(ds_id)
-        page_id      = self._checkInt(page_id)
-        ti           = self.getNavigation().getTreeItem(page_id)
-        c.ds_id      = ds_id
-        real_id      = ti.realId(ds_id)
-        c.page_id    = page_id
-        c.print_form = "show" # Which page to open in popup on printing?
-        case_session = session.get('case')
-        case_session.setPageId(page_id)
-        case_session.setMode("show")
-        session.save()
-        content, navigation = self._getRenderdFormElements(ti, ds_id, page_id, ro_mode=True)
-        c.formular = content
-        c.form_navigation = navigation 
-        return render('/casemanagement/formular.mako')
-
     @checkRole(('admin_ka', 'cm_ka', 'pb_ka'))
     def showHelp(self, help_id):
         help = g.helpData.getHelp(help_id)
@@ -427,8 +371,19 @@
         return render('/casemanagement/required.mako')
 
     @checkRole('cm_ka')
+    def undo_error(self, error_item):
+        case = session.get('case')
+        if not case: raise HTTPNotFound()
+        errors = case.getFormErrors()
+        if not errors: raise HTTPNotFound()
+        errors.pop(error_item)
+        session.save()
+        page_id = case.page_id
+        if page_id is None: raise HTTPNotFound()
+        return self.select_item(page_id)
+
+    @checkRole('cm_ka')
     def save(self):
-        print request.params
         case_session = session.get('case')
         try:
             ti = self.getNavigation().getTreeItem(request.params["page"])
@@ -440,7 +395,7 @@
 
         # If we edit page_1 we better update the infofield because the names
         # may have been edited 
-        if ti.page == "page_1":
+        if ti.name == "page-1":
             try:
                 case_session.last_name = request.params.getone("name_1")
                 case_session.first_name = request.params.getone("vorname_1")
@@ -452,17 +407,17 @@
         old_errors = case_session.getFormErrors()
         ds_id = request.params["ds"]
         new_errors, page = self.__save(
-            ti.page, 
+            ti.name, 
             request.params.dict_of_lists(), 
             old_errors, 
-            ti.realId(ds_id))
+            ds_id)
 
         if new_errors:
             c.status_msg = h.status_message("Eingabedaten fehlerhaft! Daten wurden nicht gespeichert.")
         else:
             c.status_msg = h.status_message(u'Daten erfolgreich gespeichert. Bitte beachten Sie die <a href="/case/showhelp/datenschutz_veraenderte_daten" target="_blank">Hinweise zur Datenschutz.</a>')
 
-        if ti.page == "page_0":
+        if ti.name == "page-0":
             try:
                 case_session.first_meeting = page.getData("erstgespraech")
                 case_session.knr           = page.getData("kundennummer")
@@ -641,7 +596,7 @@
         session_case = session.get('case')
 
         mode = session_case and session_case.getMode() or "show" 
-        link = lambda ti: '"/case/%s/%d/%s"' % (mode, ti.realId(id), ti.key)
+        link = lambda ti: '"/case/%s/%d/%s"' % (mode, id, ti.key)
 
         c.phase_pairs   = phases_pairs(fields, phase, self.getNavigation(), link)
         c.current_phase = Phase(phase, True)

Modified: wasko/trunk/waskaweb/controllers/navigation.py
===================================================================
--- wasko/trunk/waskaweb/controllers/navigation.py	2009-02-20 15:02:29 UTC (rev 277)
+++ wasko/trunk/waskaweb/controllers/navigation.py	2009-02-22 15:54:58 UTC (rev 278)
@@ -41,6 +41,8 @@
 
 log = logging.getLogger(__name__)
 
+import sys
+
 class NavigationController(CasebaseController):
 
     def __before__(self):
@@ -48,44 +50,50 @@
 
     @checkRole(('admin_ka', 'cm_ka', 'pt_dlr'))
     def index(self):
-        # Return a rendered template
-        #   return render('/some/template.mako')
-        # or, Return a response
-        return 'Hello World'
+        raise HTTPNotFound()
 
+    def __ensure_selected_page(self, case, tree_item):
+        page_id = case.page_id
+        if page_id is None:
+            page_id = tree_item.deepest_item().key
+            case.setPageId(page_id)
+            session.save()
+        return page_id
+
     @checkRole(('admin_ka', 'cm_ka', 'pt_dlr'))
-    def toggle(self, ds_id, page_id):
-        '''This function toggles the selected item in thenavigation tree and
-        than returns the last selected page. If no page was selected (e.g fresh
-        opened case) it will return the rendered page of the item which will be
-        toggeled'''
+    def open_branch(self, tree_id):
+        case = session.get('case')
+        if not case: raise HTTPNotFound()
+        tree_id   = self._checkInt(tree_id)
+        tree_item = self.navigation.getTreeItem(tree_id)
+        if not tree_item: raise HTTPNotFound()
+        tree_item.unfold()
+        page_id = self.__ensure_selected_page(case, tree_item)
+        return self.select_item(page_id)
 
-        # Check values and toggle navigation tree
-        ds_id        = self._checkInt(ds_id)
-        page_id      = self._checkInt(page_id)
-        try:
-            ti = self.navigation.getTreeItem(page_id)
-        except:
-            return render('/casemanagement/formular.mako')
-        ti.toggle()
+    @checkRole(('admin_ka', 'cm_ka', 'pt_dlr'))
+    def close_branch(self, tree_id):
+        case = session.get('case')
+        if not case: raise HTTPNotFound()
+        tree_id   = self._checkInt(tree_id)
+        tree_item = self.navigation.getTreeItem(tree_id)
+        if not tree_item: raise HTTPNotFound()
+        tree_item.set_open(False)
+        page_id = self.__ensure_selected_page(case, tree_item)
+        return self.select_item(page_id)
 
-        # Load last selected page
-        sti = ti 
-        session_case = session.get('case')
-        if session_case.id != ds_id: #Case seems to have changed. 
-            redirect_to(controller="/case", action="select", id=ds_id, confirmed=0)
-            sti = self.navigation.getTreeItem(session_case.getPageId())
-        c.ds_id      = ds_id
-        real_id      = sti.realId(ds_id)
-        c.case       = self._loadCase(ds_id)
-        c.page_id    = session_case.getPageId() or page_id
+    @checkRole(('admin_ka', 'cm_ka', 'pt_dlr'))
+    def select_branch(self, tree_id):
+        case = session.get('case')
+        if not case: raise HTTPNotFound()
+        tree_id   = self._checkInt(tree_id)
+        tree_item = self.navigation.getTreeItem(tree_id)
+        if not tree_item: raise HTTPNotFound()
+        tree_item = tree_item.deepest_item()
+        tree_item.unfold()
+        page_id = tree_item.key
+        case.setPageId(page_id)
         session.save()
+        return self.select_item(page_id)
 
-        c.print_form = "show" # Which page to open in popup on printing?
-        read_only = (session_case.getMode() == "show")
-        content, navigation = self._getRenderdFormElements(sti, ds_id, sti.key, ro_mode=read_only)
-        c.formular = content
-        c.form_navigation = navigation 
-        return render('/casemanagement/formular.mako')
-
 # vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

Modified: wasko/trunk/waskaweb/controllers/rg_aid.py
===================================================================
--- wasko/trunk/waskaweb/controllers/rg_aid.py	2009-02-20 15:02:29 UTC (rev 277)
+++ wasko/trunk/waskaweb/controllers/rg_aid.py	2009-02-22 15:54:58 UTC (rev 278)
@@ -58,7 +58,7 @@
         rg_id     = self._checkInt(rg_id)
         page_id   = self._checkInt(page_id)
         ti        = self.getNavigation().getTreeItem(page_id)
-        c.ds_id   = ti.realId(rg_id)
+        c.ds_id   = rg_id
         c.page_id = page_id
 
         case_session = session.get('case')
@@ -79,7 +79,7 @@
         rg_id     = self._checkInt(rg_id)
         page_id   = self._checkInt(page_id)
         ti        = self.getNavigation().getTreeItem(page_id)
-        c.ds_id   = ti.realId(rg_id)
+        c.ds_id   = rg_id
         c.page_id = page_id
 
         case_session = session.get('case')

Modified: wasko/trunk/waskaweb/lib/helpers.py
===================================================================
--- wasko/trunk/waskaweb/lib/helpers.py	2009-02-20 15:02:29 UTC (rev 277)
+++ wasko/trunk/waskaweb/lib/helpers.py	2009-02-22 15:54:58 UTC (rev 278)
@@ -180,12 +180,12 @@
 
 def getFormularHeaders(page_id):
     navigation = session.get('navigation.tree')
-    try:
-        headers = navigation.getHeaders(page_id)
-    except StandardError, err:
-        print err
-        return "" 
-    return headers
+    if not navigation: return u""
+    tree_item = navigation.getTreeItem(page_id)
+    if not tree_item: return u""
+    from waskaweb.lib.renderer import FormData
+    form_data = FormData(g.helpData)
+    return tree_item.renderHeader(form_data)
 
 def getHelp(help_id):
     from waskaweb.lib.renderer import FormData
@@ -207,7 +207,7 @@
     if not navigation: return ""
     tree_item = navigation.getTreeItem(page_id)
     if not tree_item: return ""
-    page_name = tree_item.page
+    page_name = tree_item.name
     if not page_name: return ""
     case_id  = case.id
     errors   = case.getFormErrors()

Modified: wasko/trunk/waskaweb/lib/renderer.py
===================================================================
--- wasko/trunk/waskaweb/lib/renderer.py	2009-02-20 15:02:29 UTC (rev 277)
+++ wasko/trunk/waskaweb/lib/renderer.py	2009-02-22 15:54:58 UTC (rev 278)
@@ -285,7 +285,7 @@
        
         out = []
         if not self.ro_mode:
-            out.append('<form id="waska_form" action="/case/save" accept-charset="UTF-8">\n')
+            out.append('<form id="waska_form" action="/case/save" accept-charset="UTF-8" method="POST">\n')
             # Add submitbutton at the top of the page too
             out.append('<div class="waska_form_element w100">')
             out.append('<input type="hidden" name="ds" value="%s"' % ds_id)
@@ -949,8 +949,8 @@
             errors_list.sort(lambda a, b: cmp(order[a[0]], order[b[0]]))
 
             for k, v in errors_list:
-                out.append(u'<li><a href="javascript:undo_error(\'%s\',\'%s\');">' % (k, page_name))
-                out.append(get_image("images/icons/undo.png",
+                out.append(u'<li><a href="/case/undo_error/%s">' % k)
+                out.append(get_image("/images/icons/undo.png",
                     u'border="0" alt="undo" title="Letzten gültigen Wert wieder herstellen."'))
                 out.append(
                     u'</a> '

Modified: wasko/trunk/waskaweb/model/navigation.py
===================================================================
--- wasko/trunk/waskaweb/model/navigation.py	2009-02-20 15:02:29 UTC (rev 277)
+++ wasko/trunk/waskaweb/model/navigation.py	2009-02-22 15:54:58 UTC (rev 278)
@@ -28,7 +28,7 @@
 # Sascha L. Teichmann <teichmann at intevation.de>
 #
 
-import sys
+from cgi import escape
 
 from paste.httpexceptions  import HTTPNotFound
 from waskaweb.lib.helpers  import getHelp
@@ -36,85 +36,136 @@
 from waskaweb.model.nodecomponents import Node
 from waskaweb.model.data           import PageNode
 
+
+SELECT_ITEM   = u"/case/select_item/%s"
+SELECT_BRANCH = u"/navigation/select_branch/%s"
+CLOSE_BRANCH  = u"/navigation/close_branch/%s"
+OPEN_BRANCH   = u"/navigation/open_branch/%s"
+
 class TreeItem:
 
-    def __init__(self, key, page = "", description = "", children=None, enabled=True, fname=None):
-        self.displayChildren = False
-        self.key             = key
-        self.formed_name     = fname
-        self.page            = page
-        self.parent          = None 
-        self.description     = description
-        self.children        = children
-        self.enabled         = enabled 
+    def __init__(self, name, description, children = None, parent = None):
+        self.is_open     = False
+        self.name        = name
+        self.description = description
+        self.parent      = parent
+        self.children    = children
+        self.key         = None
 
-    def __str__(self):
-        return "Desc: %s, Key: %s, Fname: %s, Page: %s" % (self.description, self.key, self.formed_name, self.page)
+    def is_child(self):
+        return self.children is None
 
-    def toggle(self):
-        self.displayChildren = not self.displayChildren
+    def deepest_item(self):
+        cur = self
+        while cur.children:
+            cur = cur.children[0]
+        return cur
 
-    def setParent(self, treeItem):
-        self.parent = treeItem
+    def unfold(self):
+        cur = self
+        while cur:
+            cur.is_open = True
+            cur = cur.parent
 
-    def hasEnabledChildren(self):
-        """Return true/false depending if the item has enabled children."""
-        if self.children and len(self.children) > 0:
-            for child in self.children:
-                if child.enabled: return True
-        return False
+    def render(self, page, out, get_image, error_lookup):
+        out.append(u'<li class="formpage">')
+        out.append(page == self.key \
+            and u'<span class="formpage_highlight">' or u'<span>')
 
-    def hasDisplayedChildren(self):
-        """Return true/false depending if item has children to be displayed."""
-        if self.children and len(self.children) > 0:
-            return self.displayChildren
-        return False
+        has_error = self.name in error_lookup
+        if self.is_child():
 
-    def render(self, select_action, toggle_action, out, 
-                error=False, selected_key=None):
-        err_str = ""
-        if self.enabled:
+            select_link = SELECT_ITEM % self.key
 
-            hl = self.key == selected_key and 'class="formpage_highlight"' or ""
-            out.append('<li class="formpage"><span %s>' % hl)
+            out.append(u'<a href="%s" class="navigation">' % select_link)
 
-            if self.hasEnabledChildren():
-                if error:
-                    symbol = '<img src="/images/icons/folder_closed_blue_2_error.gif" alt="Geschlossener Ordner Fehler" title="Ordner &ouml;ffnen - Fehler in Fallakte" border="0">'
-                else: 
-                    symbol = '<img src="/images/icons/folder_closed_blue_2.gif" alt="Geschlossener Ordner" title="Ordner &ouml;ffnen" border="0">'
+            if has_error:
+                out.append(get_image("/images/icons/formular_page_blue_error.gif",
+                    u' border="0"'
+                    u' alt="Fehler auf dieser Seite"'
+                    u' title="Seite öffnen - Diese Seite enthält Fehler."'))
             else:
-                if error:
-                    symbol = '<img src="/images/icons/formular_page_blue_error.gif" alt="Formular" title="Formular - Fehler enthalten" border="0">'
-                else:
-                    symbol = '<img src="/images/icons/formular_page_blue.gif" alt="Formular" title="Formular &ouml;ffnen" border="0">'
+                out.append(get_image("/images/icons/formular_page_blue.gif",
+                    u' border="0"'
+                    u' alt="Formularseite" title="Seite öffnen"'))
 
-            out.append('<a href="%s" onclick="return checkModification();">%s</a>' % (
-                toggle_action(self),
-                symbol))
+            out.append(u'</a> <a href="%s" class="navigation">%s</a>\n' % (
+                select_link, escape(self.description)))
+        else:
+            # when clicking on link select the first page in branch
+            deepest = self.deepest_item()
 
-            out.append('<a href="%s" onclick="return checkModification();">%s%s</a>' % (
-                select_action(self),
-                err_str, 
-                self.description))
+            select_link = SELECT_BRANCH %  deepest.key
 
-            out.append('</span>')
+            if self.is_open or has_error:
+                if not has_error:
+                    action = CLOSE_BRANCH % self.key
+                    out.append(u'<a href="%s" class="navigation">' % action)
 
-            if self.hasDisplayedChildren():
-                out.append('<ul>')
+                out.append(get_image("/images/icons/folder_closed_blue_2.gif",
+                    u' border="0"'
+                    u' title="Ordner%s"'
+                    u' alt="%s"' % (
+                        not has_error and "schliessen" or "",
+                        has_error and u"offener" or u"geschlossener")))
+
+                out.append(has_error and u' ' or u'</a>')
+
+                out.append(u'<a href="%s" class="navigation">%s</a>' % (
+                    select_link, escape(self.description)))
+
+                out.append(u'<ul>\n')
                 for child in self.children:
-                    child.render(
-                        select_action, 
-                        toggle_action, 
-                        out, 
-                        selected_key=selected_key
-                    )
-                out.append('</ul>')
-            out.append("</li>")
+                    child.render(page, out, get_image, error_lookup)
+                out.append(u'</ul>\n')
+            else:
+                action = OPEN_BRANCH % self.key
+                out.append(u'<a href="%s" class="navigation">' % action)
 
-    def realId(self, id):
-        return id
+                out.append(get_image("/images/icons/folder_closed_blue_2.gif",
+                    u' border="0"'
+                    u' alt="geschlossener Ordner" title="Ordner öffnen"'))
+                    
+                out.append(u'</a> ')
 
+                out.append(u'<a href="%s" class="navigation">%s</a>' % (
+                    select_link, escape(self.description)))
+
+        out.append(u"</span></li>\n")
+
+    def set_open(self, flag):
+        self.is_open = flag
+
+    def build_error_lookup(self, lookup, error_pages):
+        mark = self.name in error_pages
+        if self.children:
+            for child in self.children:
+                if child.build_error_lookup(lookup, error_pages):
+                    mark = True
+        if mark:
+            lookup.add(self.name)
+        return mark
+
+    def get_description_chain(self, form_data):
+        cur = self
+        descriptions = []
+        while cur:
+            if cur.description:
+                descriptions.insert(0, u"%s%s" % (
+                    escape(cur.description), form_data.getHelp(cur.name)))
+            cur = cur.parent
+        return descriptions
+
+    def renderHeader(self, form_data):
+        descriptions = self.get_description_chain(form_data)
+        if not descriptions: return u""
+        out = [u'<div class="content_ueberschrift"><ul>']
+        for depth, desc in enumerate(descriptions):
+            depth = min(depth + 1, 4)
+            out.append(u'<li><h%d>%s</h%d></li>' % (depth, desc, depth))
+        out.append(u'</ul></div>')
+        return u"".join(out)
+
     def nextKey(self):
         n_key = self.key + 1
         root = self
@@ -135,9 +186,6 @@
             current.displayChildren = True
             current = current.parent
 
-    def getPageName(self):
-        return get_page(self)
-
 def get_page(nc):
     while nc:
         if isinstance(nc, PageNode):
@@ -148,47 +196,39 @@
 class NavigationTreeBuilder(object):
 
     def __init__(self, formed):
-        #self.pages = []
-        self.key   = 0
-        self.root  = self.build(formed, None)
+        self.key  = 0
+        self.root = self.build(formed, None)
 
     def build(self, nc, parent):
 
         if isinstance(nc, PageNode):
-            ti = TreeItem(
-                self.key, get_page(nc), nc.getDescription())
-
-            ti.parent = parent
+            ti = TreeItem(nc.getName(), nc.getDescription(), parent = parent)
+            ti.key = self.key
             self.key += 1
             return ti
 
         if isinstance(nc, Node):
             children = []
             n = TreeItem(
-                self.key, 
-                get_page(nc), 
-                nc.getDescription(), 
-                children)
-
-            n.parent = parent
-            self.key += 1
+                get_page(nc),
+                nc.getDescription(),
+                children,
+                parent)
             for child in nc.children:
                 children.append(self.build(child, n))
+            n.key = self.key
+            self.key += 1
             return n
 
-        ti = TreeItem(self.key, "xxx", "Unknown Item")
-        ti.parent = parent
+        ti = TreeItem("xxx", "Unknown Item", parent = parent)
+        ti.key = self.key
         self.key += 1
         return ti
 
 class NavigationTree:
 
-    #def __init__(self, factories=None):
     def __init__(self, formed, case=None):
-        self.errors = [] #List page name with faulty pages
-
         builder = NavigationTreeBuilder(formed.root.children[0])
-
         self.root = builder.root
 
     def getAllItems(self, node=None):
@@ -213,27 +253,13 @@
                     stack.append(c.children)
         return None
 
-    def getHeaders(self, key):
-        headers = []
-        ti = self.getTreeItem(key)
-        if not ti: return headers
-        # we need to look forward in the children to get page which will be
-        # actually rendered
-        ti = self.getTreeItemByPageName(ti.page)
-        while True:
-            headers.append((ti.description, getHelp(ti.formed_name)))
-            if not ti.parent: break
-            ti = ti.parent
-        headers.reverse()
-        return headers
-
     def findTreeItemByPageName(self, name):
         stack = [self.root.children]
         item = None
         while stack:
             children = stack.pop()
             for c in children:
-                if c.page == name:
+                if c.name == name:
                     return c
                 if c.children:
                     stack.append(c.children)
@@ -247,16 +273,14 @@
         if not item: raise HTTPNotFound()
         return item
 
-    def render(self, select_action, toggle_action, selected_key=None):
-        out = ['<ul>']
+    def render(self, page, file_cache, error_pages = set()):
+        error_lookup = set()
+        self.root.build_error_lookup(error_lookup, error_pages)
+        out = [u'<ul>']
+        get_image = file_cache.get_image
         for child in self.root.children:
-            child.render(select_action, toggle_action, out, (child.page in self.errors), selected_key)
-        out.append('</ul>')
-        return "\n".join(out)
+            child.render(page, out, get_image, error_lookup)
+        out.append(u"</ul>")
+        return u"".join(out)
 
-    def setErrors(self, errors):
-        self.errors = errors
-
-
-
-# vim:set ts=4 sw=4 si et sta sts=4:
+# vim:set ts=4 sw=4 si et sta sts=4 :

Added: wasko/trunk/waskaweb/public/images/icons/undo.png
===================================================================
(Binary files differ)


Property changes on: wasko/trunk/waskaweb/public/images/icons/undo.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: wasko/trunk/waskaweb/templates/casemanagement/formular.mako
===================================================================
--- wasko/trunk/waskaweb/templates/casemanagement/formular.mako	2009-02-20 15:02:29 UTC (rev 277)
+++ wasko/trunk/waskaweb/templates/casemanagement/formular.mako	2009-02-22 15:54:58 UTC (rev 278)
@@ -47,15 +47,7 @@
 </%def>
 
 <%def name="buildUeberschrift()">
-% if len(h.getFormularHeaders(c.page_id)) > 0:
-  <div id="content_ueberschrift">
-    <ul>
-    % for header, help in h.getFormularHeaders(c.page_id):
-      <li><h1>${header} ${help}</h1></li>
-    % endfor
-    </ul>
-  </div>
-% endif
+${h.getFormularHeaders(c.page_id)}
 </%def>
 
 <%def name="buildModusfield()">



More information about the Mpuls-commits mailing list