source: indico/indico/MaKaC/webinterface/pages/base.py @ cc169e

hello-world-walkthroughipv6v0.98-seriesv0.98.2v0.98.3v0.98b2v0.99v1.0v1.1
Last change on this file since cc169e was cc169e, checked in by Pedro Ferreira <jose.pedro.ferreira@…>, 2 years ago

[MIN] Add jQuery plugin to serialize form -> obj

  • jQuery only serializes to arrays by default
  • .serializeObject() creates an object mapping field names to their values as expected by indicoSource etc
  • Property mode set to 100644
File size: 9.2 KB
Line 
1# -*- coding: utf-8 -*-
2##
3##
4## This file is part of CDS Indico.
5## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 CERN.
6##
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.
11##
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.
16##
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.
20
21import MaKaC.webinterface.wcomponents as wcomponents
22import MaKaC.webinterface.urlHandlers as urlHandlers
23from MaKaC.common.Configuration import Config
24from MaKaC.common.info import HelperMaKaCInfo
25from MaKaC.i18n import _
26
27from MaKaC.plugins.base import OldObservable
28
29
30class WPBase(OldObservable):
31    """
32    """
33    _title = "Indico"
34
35    # required user-specific "data packages"
36    _userData = []
37
38    def __init__( self, rh ):
39        self._rh = rh
40        self._locTZ = ""
41
42        #store page specific CSS and JS
43        self._extraCSS = []
44        self._extraJS = []
45
46    def _includeJSPackage(self, packageName, module = 'indico', path=None):
47        info = HelperMaKaCInfo().getMaKaCInfoInstance()
48
49        if info.isDebugActive():
50            return ['js/%s/%s/Loader.js' % (module, packageName)]
51        else:
52            return ['js/%s/pack/%s.pack.js' % (module, packageName)]
53
54    def _includeJQuery(self):
55        info = HelperMaKaCInfo().getMaKaCInfoInstance()
56        files = ['jquery', 'jquery-compat', 'jquery-ui', 'jquery.custom', 'jquery.daterange']
57        if info.isDebugActive():
58            # We can't use Loader.js as jQuery is included before any indico js
59            return ['js/jquery/%s.js' % f for f in files] + ['js/indico/jquery/defaults.js']
60        else:
61            return ['js/jquery/jquery.pack.js'] + ['js/indico/jquery/defaults.js']
62
63    def _includeJSFile(self, path, filename):
64        info = HelperMaKaCInfo().getMaKaCInfoInstance()
65
66        if info.isDebugActive():
67            return ['%s/%s.js' % (path, filename)]
68        else:
69            return ['%s/%s.pack.js' % (path, filename)]
70
71    def _includePresentationFiles(self):
72        info = HelperMaKaCInfo().getMaKaCInfoInstance()
73
74        if info.isDebugActive():
75            return ['js/presentation/Loader.js']
76        else:
77            return ['js/presentation/pack/Presentation.pack.js']
78
79    def _getBaseURL( self ):
80        return Config.getInstance().getBaseURL()
81
82    def _getTitle( self ):
83        return self._title
84
85    def _setTitle( self, newTitle ):
86        self._title = newTitle.strip()
87
88    def getCSSFiles(self):
89        return []
90
91    def getJSFiles(self):
92        return self._includePresentationFiles() + \
93               self._includeJQuery() + \
94               self._includeJSPackage('Core') + \
95               self._includeJSPackage('Legacy') + \
96               self._includeJSPackage('Common')
97
98    def _getJavaScriptInclude(self, scriptPath):
99        return '<script src="'+ scriptPath +'" type="text/javascript"></script>\n'
100
101    def _getJavaScriptUserData(self):
102        """
103        Returns structured data that should be passed on to the client side
104        but depends on user data (can't be in vars.js.tpl)
105        """
106
107        user = self._getAW().getUser();
108
109        from MaKaC.webinterface.asyndico import UserDataFactory
110
111        userData = dict((packageName,
112                         UserDataFactory(user).build(packageName))
113                        for packageName in self._userData)
114
115        return userData
116
117    def _getHeadContent( self ):
118        """
119        Returns _additional_ content between <head></head> tags.
120        Please note that <title>, <meta> and standard CSS are always included.
121
122        Override this method to add your own, page-specific loading of
123        JavaScript, CSS and other legal content for HTML <head> tag.
124        """
125        return ""
126
127    def _getWarningMessage(self):
128        return ""
129
130    def _getHTMLHeader( self ):
131        from MaKaC.webinterface.pages.conferences import WPConfSignIn
132        from MaKaC.webinterface.pages.signIn import WPSignIn
133        from MaKaC.webinterface.pages.registrationForm import WPRegistrationFormSignIn
134        from MaKaC.webinterface.rh.base import RHModificationBaseProtected
135        from MaKaC.webinterface.rh.admins import RHAdminBase
136
137        baseurl = self._getBaseURL()
138        if ((isinstance(self, WPSignIn) or isinstance(self, WPConfSignIn) or isinstance(self, WPRegistrationFormSignIn)) and \
139                Config.getInstance().getLoginURL().startswith("https")) or \
140                self._rh._req.is_https() and self._rh._tohttps:
141            baseurl = baseurl.replace("http://","https://")
142            baseurl = urlHandlers.setSSLPort( baseurl )
143
144        area=""
145        if isinstance(self._rh, RHModificationBaseProtected):
146            area=_(""" - _("Management area")""")
147        elif isinstance(self._rh, RHAdminBase):
148            area=_(""" - _("Administrator area")""")
149
150        websession = self._getAW().getSession()
151        if websession:
152            language = websession.getLang()
153        else:
154            info = HelperMaKaCInfo().getMaKaCInfoInstance()
155            language = info.getLang()
156
157        return wcomponents.WHTMLHeader().getHTML({
158                            "area": area,
159                            "baseurl": baseurl,
160                            "conf": Config.getInstance(),
161                            "page": self,
162                            "extraCSS": self.getCSSFiles(),
163                            "extraJSFiles": self.getJSFiles(),
164                            "extraJS": self._extraJS,
165                            "language": language
166                            })
167
168    def _getHTMLFooter( self ):
169        return """
170    </body>
171</html>
172               """
173
174    def _display( self, params ):
175        """
176        """
177        return _("no content")
178
179    def _getAW( self ):
180        return self._rh.getAW()
181
182    def display( self, **params ):
183        """
184        """
185        return "%s%s%s"%( self._getHTMLHeader(), \
186                            self._display( params ), \
187                            self._getHTMLFooter() )
188
189
190    def addExtraJSFile(self, filename):
191        self._extraJSFiles.append(filename)
192
193    def addExtraJS(self, jsCode):
194        self._extraJS.append(jsCode)
195
196    # auxiliar functions
197    def _escapeChars(self, text):
198        # Not doing anything right now - it used to convert % to %% for old-style templates
199        return text
200
201
202class WPDecorated( WPBase ):
203
204    def _getSiteArea(self):
205        return "DisplayArea"
206
207    def getLoginURL( self ):
208        return urlHandlers.UHSignIn.getURL("%s"%self._rh.getCurrentURL())
209
210    def getLogoutURL( self ):
211        return urlHandlers.UHSignOut.getURL("%s"%self._rh.getCurrentURL())
212
213    def getLoginAsURL( self ):
214        return urlHandlers.UHLogMeAs.getURL("%s"%self._rh.getCurrentURL())
215
216
217    def _getHeader( self ):
218        """
219        """
220        wc = wcomponents.WHeader( self._getAW(), isFrontPage=self._isFrontPage(), currentCategory=self._currentCategory(), locTZ=self._locTZ )
221        return wc.getHTML( { "subArea": self._getSiteArea(), \
222                             "loginURL": self._escapeChars(str(self.getLoginURL())),\
223                             "logoutURL": self._escapeChars(str(self.getLogoutURL())),\
224                             "loginAsURL": self.getLoginAsURL() } )
225
226    def _getTabControl(self):
227        return None
228
229    def _getFooter( self):
230        """
231        """
232        wc = wcomponents.WFooter(isFrontPage=self._isFrontPage())
233        return wc.getHTML({ "subArea": self._getSiteArea() })
234
235    def _applyDecoration( self, body ):
236        """
237        """
238        return "<div class=\"wrapper\">%s%s<div class=\"emptyFooter\"></div></div>%s"%( self._getHeader(), body, self._getFooter() )
239
240    def _display( self, params ):
241
242        return self._applyDecoration( self._getBody( params ) )
243
244    def _getBody( self, params ):
245        """
246        """
247        pass
248
249    def _getNavigationDrawer(self):
250        return None
251
252    def _isFrontPage(self):
253        """
254            Welcome page class overloads this, so that additional info (news, policy)
255            is shown.
256        """
257        return False
258
259    def _isRoomBooking(self):
260        return False
261
262    def _currentCategory(self):
263        """
264            Whenever in category display mode this is overloaded with the current category
265        """
266        return None
267
268    def _getSideMenu(self):
269        """
270            Overload and return side menu whenever there is one
271        """
272        return None
273
274class WPNotDecorated( WPBase ):
275
276    def getLoginURL( self ):
277        return urlHandlers.UHSignIn.getURL("%s"%self._rh.getCurrentURL())
278
279    def getLogoutURL( self ):
280        return urlHandlers.UHSignOut.getURL("%s"%self._rh.getCurrentURL())
281
282    def _display( self, params ):
283        return self._getBody( params )
284
285    def _getBody( self, params ):
286        """
287        """
288        pass
289
290    def _getNavigationDrawer(self):
291        return None
292
293
294
Note: See TracBrowser for help on using the repository browser.