forked from Immudzen/CompoundDoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
controlmodemanager.py
81 lines (68 loc) · 3.12 KB
/
controlmodemanager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# -*- coding: utf-8 -*-
###########################################################################
# Copyright (C) 2008 by kosh
# <kosh@kosh.aesaeion.com>
#
# Copyright: See COPYING file that comes with this distribution
#
###########################################################################
from basecontrolmanager import BaseControlManager
#For Security control and init
from AccessControl import ClassSecurityInfo
import Globals
import com.javascript
import utility
import nestedlisturl as NestedListUrl
class ControlModeManager(BaseControlManager):
"different mode views of objects"
meta_type = "ControlModeManager"
security = ClassSecurityInfo()
control_title = 'Mode'
drawMode = 'config'
drawBlankPath = 1
security.declareProtected('View management screens', 'edit')
def edit(self, *args, **kw):
"""This draws the inline forms for the objects present."""
origin = self.getOrigin()
path = self.getFixedUpPath()
if path or (not path and self.drawBlankPath) and origin is not None:
obj = origin.unrestrictedTraverse(path, None)
else:
obj = None
if obj is not None:
queryString = self.REQUEST.environ.get('QUERY_STRING', '')
draw_mode = self.getModeFromREQUEST(obj.drawDict)
modes = sorted(obj.drawDict.keys())
path = obj.absolute_url_path()
temp = ['<div class="%s">' % self.cssClass]
menu = []
otherAttributes = ''
cssClasses = ''
queryDict = utility.getQueryDict(queryString)
for mode in modes:
selected = draw_mode == mode
queryDict['renderType'] = mode
menu.append((self.REQUEST.URL,mode,selected,cssClasses,queryDict.copy(),otherAttributes))
temp.append(NestedListUrl.listRenderer('Themeroller Tabs',menu, None))
tab_format = '<div id="%s">%s<div>%s</div></div>'
config_object = obj.getConfigObject()
if config_object is not None and config_object is not self:
mode_url = obj.drawDict[draw_mode]
tabs = ((obj.absolute_url_path() + '/' + mode_url,'Local'),
(config_object.absolute_url_path() + '/' + mode_url,'Config'))
temp.append('<div>%s</div>' % self.submitChanges())
temp.append(com.javascript.tabs_html('control_tabs', tabs))
else:
temp.append(obj.draw(draw_mode))
temp.append('<div>%s</div>' % self.submitChanges())
return ''.join(temp)
return ""
security.declarePrivate('getModeFromREQUEST')
def getModeFromREQUEST(self, allowed):
"get the current mode from the REQUEST object"
mode = self.REQUEST.form.get('renderType', self.drawMode)
if mode in allowed:
return mode
else:
return 'edit'
Globals.InitializeClass(ControlModeManager)