1 # -*- coding: utf-8 -*-
4 ## This file is part of CDS Indico.
5 ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 CERN.
7 ## CDS Indico is free software; you can redistribute it and/or
8 ## modify it under the terms of the GNU General Public License as
9 ## published by the Free Software Foundation; either version 2 of the
10 ## License, or (at your option) any later version.
12 ## CDS Indico is distributed in the hope that it will be useful, but
13 ## WITHOUT ANY WARRANTY; without even the implied warranty of
14 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ## General Public License for more details.
17 ## You should have received a copy of the GNU General Public License
18 ## along with CDS Indico; if not, write to the Free Software Foundation, Inc.,
19 ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
21 import MaKaC
.webinterface
.wcomponents
as wcomponents
22 import MaKaC
.webinterface
.urlHandlers
as urlHandlers
23 from MaKaC
.common
.Configuration
import Config
24 from MaKaC
.common
.info
import HelperMaKaCInfo
25 from MaKaC
.i18n
import _
26 from indico
.util
.i18n
import i18nformat
28 from MaKaC
.plugins
.base
import OldObservable
31 class WPBase(OldObservable
):
36 # required user-specific "data packages"
39 def __init__( self
, rh
):
43 #store page specific CSS and JS
47 def _includeJSPackage(self
, packageName
, module
= 'indico', path
=None):
48 info
= HelperMaKaCInfo().getMaKaCInfoInstance()
50 if info
.isDebugActive():
51 return ['js/%s/%s/Loader.js' % (module
, packageName
)]
53 return ['js/%s/pack/%s.js.pack' % (module
, packageName
)]
55 def _includeJQuery(self
):
56 info
= HelperMaKaCInfo().getMaKaCInfoInstance()
57 files
= ['underscore', 'jquery', 'jquery-ui', 'jquery.form', 'jquery.custom', 'jquery.daterange', 'jquery.qtip']
58 if info
.isDebugActive():
59 # We can't use Loader.js as jQuery is included before any indico js
60 return ['js/jquery/%s.js' % f
for f
in files
] + ['js/indico/jquery/defaults.js']
62 return ['js/jquery/pack/jquery.js.pack'] + ['js/indico/jquery/defaults.js']
64 def _includeJSFile(self
, path
, filename
):
65 info
= HelperMaKaCInfo().getMaKaCInfoInstance()
67 if info
.isDebugActive():
68 return ['%s/%s.js' % (path
, filename
)]
70 return ['%s/%s.js.pack' % (path
, filename
)]
72 def _includePresentationFiles(self
):
73 info
= HelperMaKaCInfo().getMaKaCInfoInstance()
75 if info
.isDebugActive():
76 return ['js/presentation/Loader.js']
78 return ['js/presentation/pack/Presentation.js.pack']
80 def _getBaseURL( self
):
81 if self
._rh
._req
.is_https() and Config
.getInstance().getBaseSecureURL():
82 baseurl
= Config
.getInstance().getBaseSecureURL()
84 baseurl
= Config
.getInstance().getBaseURL()
87 def _getTitle( self
):
90 def _setTitle( self
, newTitle
):
91 self
._title
= newTitle
.strip()
93 def getCSSFiles(self
):
97 return self
._includePresentationFiles
() + \
98 self
._includeJQuery
() + \
99 self
._includeJSPackage
('Core') + \
100 self
._includeJSPackage
('Legacy') + \
101 self
._includeJSPackage
('Common')
103 def _getJavaScriptInclude(self
, scriptPath
):
104 return '<script src="'+ scriptPath
+'" type="text/javascript"></script>\n'
106 def _getJavaScriptUserData(self
):
108 Returns structured data that should be passed on to the client side
109 but depends on user data (can't be in vars.js.tpl)
112 user
= self
._getAW
().getUser();
114 from MaKaC
.webinterface
.asyndico
import UserDataFactory
116 userData
= dict((packageName
,
117 UserDataFactory(user
).build(packageName
))
118 for packageName
in self
._userData
)
122 def _getHeadContent( self
):
124 Returns _additional_ content between <head></head> tags.
125 Please note that <title>, <meta> and standard CSS are always included.
127 Override this method to add your own, page-specific loading of
128 JavaScript, CSS and other legal content for HTML <head> tag.
132 def _getWarningMessage(self
):
135 def _getHTMLHeader( self
):
136 from MaKaC
.webinterface
.pages
.conferences
import WPConfSignIn
137 from MaKaC
.webinterface
.pages
.signIn
import WPSignIn
138 from MaKaC
.webinterface
.pages
.registrationForm
import WPRegistrationFormSignIn
139 from MaKaC
.webinterface
.rh
.base
import RHModificationBaseProtected
140 from MaKaC
.webinterface
.rh
.admins
import RHAdminBase
143 if isinstance(self
._rh
, RHModificationBaseProtected
):
144 area
=i18nformat(""" - _("Management area")""")
145 elif isinstance(self
._rh
, RHAdminBase
):
146 area
=i18nformat(""" - _("Administrator area")""")
148 info
= HelperMaKaCInfo().getMaKaCInfoInstance()
149 websession
= self
._getAW
().getSession()
151 language
= websession
.getLang()
153 language
= info
.getLang()
155 return wcomponents
.WHTMLHeader().getHTML({
157 "baseurl": self
._getBaseURL
(),
158 "conf": Config
.getInstance(),
160 "extraCSS": self
.getCSSFiles(),
161 "extraJSFiles": self
.getJSFiles(),
162 "extraJS": self
._extraJS
,
163 "language": language
,
164 "social": info
.getSocialAppConfig()
167 def _getHTMLFooter( self
):
173 def _display( self
, params
):
176 return _("no content")
179 return self
._rh
.getAW()
181 def display( self
, **params
):
184 return "%s%s%s"%( self
._getHTMLHeader
(), \
185 self
._display
( params
), \
186 self
._getHTMLFooter
() )
189 def addExtraJSFile(self
, filename
):
190 self
._extraJSFiles
.append(filename
)
192 def addExtraJS(self
, jsCode
):
193 self
._extraJS
.append(jsCode
)
196 def _escapeChars(self
, text
):
197 # Not doing anything right now - it used to convert % to %% for old-style templates
201 class WPDecorated( WPBase
):
203 def _getSiteArea(self
):
206 def getLoginURL( self
):
207 return urlHandlers
.UHSignIn
.getURL("%s"%self
._rh
.getCurrentURL())
209 def getLogoutURL( self
):
210 return urlHandlers
.UHSignOut
.getURL("%s"%self
._rh
.getCurrentURL())
212 def getLoginAsURL( self
):
213 return urlHandlers
.UHLogMeAs
.getURL("%s"%self
._rh
.getCurrentURL())
215 def _getHeader( self
):
218 wc
= wcomponents
.WHeader( self
._getAW
(), isFrontPage
=self
._isFrontPage
(), currentCategory
=self
._currentCategory
(), locTZ
=self
._locTZ
)
220 return wc
.getHTML( { "subArea": self
._getSiteArea
(), \
221 "loginURL": self
._escapeChars
(str(self
.getLoginURL())),\
222 "logoutURL": self
._escapeChars
(str(self
.getLogoutURL())),\
223 "loginAsURL": self
.getLoginAsURL() } )
225 def _getTabControl(self
):
228 def _getFooter( self
):
231 wc
= wcomponents
.WFooter(isFrontPage
=self
._isFrontPage
())
232 return wc
.getHTML({ "subArea": self
._getSiteArea
() })
234 def _applyDecoration( self
, body
):
237 return "<div class=\"wrapper\"><div class=\"main\">%s%s</div></div>%s"%( self
._getHeader
(), body
, self
._getFooter
() )
239 def _display( self
, params
):
241 return self
._applyDecoration
( self
._getBody
( params
) )
243 def _getBody( self
, params
):
248 def _getNavigationDrawer(self
):
251 def _isFrontPage(self
):
253 Welcome page class overloads this, so that additional info (news, policy)
258 def _isRoomBooking(self
):
261 def _currentCategory(self
):
263 Whenever in category display mode this is overloaded with the current category
267 def _getSideMenu(self
):
269 Overload and return side menu whenever there is one
273 class WPNotDecorated( WPBase
):
275 def getLoginURL( self
):
276 return urlHandlers
.UHSignIn
.getURL("%s"%self
._rh
.getCurrentURL())
278 def getLogoutURL( self
):
279 return urlHandlers
.UHSignOut
.getURL("%s"%self
._rh
.getCurrentURL())
281 def _display( self
, params
):
282 return self
._getBody
( params
)
284 def _getBody( self
, params
):
289 def _getNavigationDrawer(self
):