source: TI05-delivery/ows_framework/trunk/ows_server/ows_server/controllers/viewItems.py @ 3607

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/ows_framework/trunk/ows_server/ows_server/controllers/viewItems.py@3607
Revision 3607, 2.7 KB checked in by cbyrom, 14 years ago (diff)

Complete drag and drop functionality for the View tab: add fixes to
allow overlaid maps to be properly displayed with transparancy + allow
removal of layers (NB, have to hide list items rather than remove them
otherwise the coupling with the drag and drop js control is lost and things
stop working) + allow removal of WMCs (NB, have to refresh delete event
listeners each time the tree view is redrawn, otherwise the event listeners
stop working).

Line 
1#
2# Controller for the 'View' tab - allowing the display of WMC map layers
3#
4# $Id$
5#
6from ows_server.lib.base import *
7from paste.request import parse_querystring
8from ows_server.models import Utilities
9from ows_server.lib.wmc_util import *
10from ows_server.models import stubB
11import copy
12
13class ViewitemsController(BaseController):
14   
15    def index(self):
16        self.inputs=dict(parse_querystring(request.environ))
17        c.wmcURL = ""
18        # check if all we're doing is removing a view item
19        if 'removeItem' in self.inputs:
20            return self.removeViewItem(self.inputs['removeItem'])
21       
22        # check if we're doing an AJAX callback to get some WMC data
23        if 'REQUEST' in self.inputs and self.inputs['REQUEST'] == 'GetWebMapContext':
24            return GetWebMapContext(self)
25       
26        # otherwise, we can get here by two routes:
27        # i) either by clicking on the WMC icon in the details view - if so, get passed endpoint and add to
28        #    selected items;
29        # ii) or from the selections tab - which will already have set up the correct selected items
30       
31        # firstly check if page has been visited before; if not display tab
32        if (Utilities.isTabRequired(c.pageTabs, 'View')):
33            c.pageTabs.append(('View', h.url_for(controller='viewItems',action='index')))
34           
35        # if ENDPOINT specified, we've reached the page via the WMC icon
36        if ('ENDPOINT' in self.inputs):
37            self.addViewItem(self.inputs['ENDPOINT'])
38                                   
39        session.save()
40        return render('viewItems')
41
42
43    # add a selected item to the session
44    # - if this is the first item, then display the selections tab
45    def addViewItem(self,endpoint):
46       
47        item = stubB.SelectedItem(None, None, None, endpoint)
48       
49        selections = [item,]
50        # avoid duplicates
51        if 'viewItems' in session:
52            for selection in session['viewItems']:
53                if selection.wmcURL != endpoint:
54                    selections.append(selection)
55                   
56        session['viewItems'] = selections
57        session.save()
58       
59   
60    # Remove view item from session data
61    # - NB, do this by rebuilding the session data
62    # without the input data included
63    def removeViewItem(self,endpoint):
64        selections = []
65        for selection in session['viewItems']:
66            if selection.wmcURL != endpoint:
67                selections.append(selection)
68               
69        # if the new list is empty, remove the session variable
70        if len(selections) == 0:
71            del session['viewItems']
72            c.UpdatePageTabs=1
73        else:
74            session['viewItems'] = selections
75
76        session.save()
77       
Note: See TracBrowser for help on using the repository browser.