| 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | ## |
|---|
| 3 | ## $Id: roomBooking.py,v 1.19 2009/06/19 16:20:42 cangelov Exp $ |
|---|
| 4 | ## |
|---|
| 5 | ## This file is part of CDS Indico. |
|---|
| 6 | ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 CERN. |
|---|
| 7 | ## |
|---|
| 8 | ## CDS Indico is free software; you can redistribute it and/or |
|---|
| 9 | ## modify it under the terms of the GNU General Public License as |
|---|
| 10 | ## published by the Free Software Foundation; either version 2 of the |
|---|
| 11 | ## License, or (at your option) any later version. |
|---|
| 12 | ## |
|---|
| 13 | ## CDS Indico is distributed in the hope that it will be useful, but |
|---|
| 14 | ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 16 | ## General Public License for more details. |
|---|
| 17 | ## |
|---|
| 18 | ## You should have received a copy of the GNU General Public License |
|---|
| 19 | ## along with CDS Indico; if not, write to the Free Software Foundation, Inc., |
|---|
| 20 | ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 21 | |
|---|
| 22 | from MaKaC.common.general import * |
|---|
| 23 | import MaKaC.webinterface.urlHandlers as urlHandlers |
|---|
| 24 | import MaKaC.webinterface.wcomponents as wcomponents |
|---|
| 25 | from MaKaC.webinterface.pages.main import WPMainBase |
|---|
| 26 | from MaKaC.rb_location import CrossLocationDB |
|---|
| 27 | import MaKaC.common.info as info |
|---|
| 28 | |
|---|
| 29 | #import MaKaC.common.info as info |
|---|
| 30 | #import MaKaC.archives as archives |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | # 0. Base classes... |
|---|
| 34 | #class WPRoomBookingBase0( WPMainBase ): |
|---|
| 35 | # def _getHeadContent( self ): |
|---|
| 36 | # """ |
|---|
| 37 | # !!!! WARNING |
|---|
| 38 | # If you update the following, you will need to do |
|---|
| 39 | # the same update in: |
|---|
| 40 | # roomBooking.py / WPRoomBookingBase0 AND |
|---|
| 41 | # conferences.py / WPConfModifRoomBookingBase |
|---|
| 42 | # |
|---|
| 43 | # For complex reasons, these two inheritance chains |
|---|
| 44 | # should not have common root, so this duplication is |
|---|
| 45 | # necessary evil. (In general, one chain is for standalone |
|---|
| 46 | # room booking and second is for conference-context room |
|---|
| 47 | # booking.) |
|---|
| 48 | # """ |
|---|
| 49 | # baseurl = self._getBaseURL() |
|---|
| 50 | # conf = Config.getInstance() |
|---|
| 51 | # return """ |
|---|
| 52 | # <!-- Lightbox --> |
|---|
| 53 | # <link rel="stylesheet" href="%s/js/lightbox/lightbox.css"> <!--lightbox.css--> |
|---|
| 54 | # <script type="text/javascript" src="%s/js/lightbox/lightbox.js"></script> |
|---|
| 55 | # |
|---|
| 56 | # <!-- Our libs --> |
|---|
| 57 | # <script type="text/javascript" src="%s/js/indico/validation.js"></script> |
|---|
| 58 | # |
|---|
| 59 | # <!-- Calendar --> |
|---|
| 60 | # <link rel="stylesheet" type="text/css" href="%s/css/calendar-blue.css" /> |
|---|
| 61 | # <script type="text/javascript" src="%s"></script> |
|---|
| 62 | # <script type="text/javascript" src="%s"></script> |
|---|
| 63 | # """ % ( baseurl, baseurl, baseurl, baseurl, urlHandlers.UHJavascriptCalendar.getURL(), |
|---|
| 64 | # urlHandlers.UHJavascriptCalendarSetup.getURL() ) |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | class WPRoomBookingBase( WPMainBase ): |
|---|
| 68 | |
|---|
| 69 | def _getTitle(self): |
|---|
| 70 | return WPMainBase._getTitle(self) + " - " + _("Room Booking") |
|---|
| 71 | |
|---|
| 72 | def getJSFiles(self): |
|---|
| 73 | return [ 'js/prototype/prototype.js', |
|---|
| 74 | 'js/scriptaculous/scriptaculous.js' ] + \ |
|---|
| 75 | WPMainBase.getJSFiles(self) |
|---|
| 76 | |
|---|
| 77 | def _getHeadContent( self ): |
|---|
| 78 | """ |
|---|
| 79 | !!!! WARNING |
|---|
| 80 | If you update the following, you will need to do |
|---|
| 81 | the same update in: |
|---|
| 82 | roomBooking.py / WPRoomBookingBase0 AND |
|---|
| 83 | conferences.py / WPConfModifRoomBookingBase |
|---|
| 84 | |
|---|
| 85 | For complex reasons, these two inheritance chains |
|---|
| 86 | should not have common root, so this duplication is |
|---|
| 87 | necessary evil. (In general, one chain is for standalone |
|---|
| 88 | room booking and second is for conference-context room |
|---|
| 89 | booking.) |
|---|
| 90 | """ |
|---|
| 91 | baseurl = self._getBaseURL() |
|---|
| 92 | return """ |
|---|
| 93 | <!-- Lightbox --> |
|---|
| 94 | <link rel="stylesheet" href="%s/js/lightbox/lightbox.css"> <!--lightbox.css--> |
|---|
| 95 | <script type="text/javascript" src="%s/js/lightbox/lightbox.js"></script> |
|---|
| 96 | |
|---|
| 97 | <!-- Our libs --> |
|---|
| 98 | <script type="text/javascript" src="%s/js/indico/Legacy/validation.js"></script> |
|---|
| 99 | """ % ( baseurl, baseurl, baseurl) |
|---|
| 100 | |
|---|
| 101 | def _getSideMenu(self): |
|---|
| 102 | minfo = info.HelperMaKaCInfo.getMaKaCInfoInstance() |
|---|
| 103 | |
|---|
| 104 | self._leftMenu = wcomponents.BasicSideMenu(self._getAW().getUser() != None) |
|---|
| 105 | |
|---|
| 106 | self._showResponsible = False |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | if minfo.getRoomBookingModuleActive() and CrossLocationDB.isConnected(): |
|---|
| 110 | self._showResponsible = ( self._getAW().getUser() != None ) and self._getAW().getUser().isResponsibleForRooms() |
|---|
| 111 | |
|---|
| 112 | self._roomsOpt = wcomponents.SideMenuSection(_("View Rooms"), \ |
|---|
| 113 | urlHandlers.UHRoomBookingSearch4Rooms.getURL() ) |
|---|
| 114 | self._roomSearchOpt = wcomponents.SideMenuItem(_("Search rooms"), |
|---|
| 115 | urlHandlers.UHRoomBookingSearch4Rooms.getURL(), |
|---|
| 116 | enabled=True) |
|---|
| 117 | self._myRoomListOpt = wcomponents.SideMenuItem(_("My rooms"), |
|---|
| 118 | urlHandlers.UHRoomBookingRoomList.getURL( onlyMy = True ), |
|---|
| 119 | enabled=self._showResponsible) |
|---|
| 120 | self._bookingsOpt = wcomponents.SideMenuSection(_("View Bookings"), \ |
|---|
| 121 | urlHandlers.UHRoomBookingSearch4Bookings.getURL()) |
|---|
| 122 | self._bookARoomOpt = wcomponents.SideMenuItem(_("Book a Room"), \ |
|---|
| 123 | urlHandlers.UHRoomBookingSearch4Rooms.getURL( forNewBooking = True ), |
|---|
| 124 | enabled=True) |
|---|
| 125 | self._bookingListSearchOpt = wcomponents.SideMenuItem(_("Search bookings"), |
|---|
| 126 | urlHandlers.UHRoomBookingSearch4Bookings.getURL(), |
|---|
| 127 | enabled=True) |
|---|
| 128 | self._bookingListCalendarOpt = wcomponents.SideMenuItem(_("Calendar"), |
|---|
| 129 | urlHandlers.UHRoomBookingBookingList.getURL( today = True, allRooms = True ), |
|---|
| 130 | enabled=True) |
|---|
| 131 | self._myBookingListOpt = wcomponents.SideMenuItem(_("My bookings"), |
|---|
| 132 | urlHandlers.UHRoomBookingBookingList.getURL( onlyMy = True, autoCriteria = True ), |
|---|
| 133 | enabled=True) |
|---|
| 134 | self._myPreBookingListOpt = wcomponents.SideMenuItem(_("My PRE-bookings"), |
|---|
| 135 | urlHandlers.UHRoomBookingBookingList.getURL( onlyMy = True, onlyPrebookings = True, autoCriteria = True ), |
|---|
| 136 | enabled=True) |
|---|
| 137 | self._usersBookings = wcomponents.SideMenuItem(_("Bookings in my rooms"), |
|---|
| 138 | urlHandlers.UHRoomBookingBookingList.getURL( ofMyRooms = True, autoCriteria = True ), |
|---|
| 139 | enabled=self._showResponsible) |
|---|
| 140 | self._usersPrebookings = wcomponents.SideMenuItem(_("PRE-bookings in my rooms"), |
|---|
| 141 | urlHandlers.UHRoomBookingBookingList.getURL( ofMyRooms = True, onlyPrebookings = True, autoCriteria = True ), |
|---|
| 142 | enabled=self._showResponsible) |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | self._leftMenu.addSection( self._roomsOpt ) |
|---|
| 146 | self._roomsOpt.addItem( self._roomSearchOpt ) |
|---|
| 147 | self._roomsOpt.addItem( self._myRoomListOpt ) |
|---|
| 148 | self._leftMenu.addSection( self._bookingsOpt ) |
|---|
| 149 | self._bookingsOpt.addItem( self._bookARoomOpt ) |
|---|
| 150 | self._bookingsOpt.addItem( self._bookingListSearchOpt ) |
|---|
| 151 | self._bookingsOpt.addItem( self._bookingListCalendarOpt ) |
|---|
| 152 | self._bookingsOpt.addItem( self._myBookingListOpt ) |
|---|
| 153 | self._bookingsOpt.addItem( self._myPreBookingListOpt ) |
|---|
| 154 | self._bookingsOpt.addItem( self._usersBookings ) |
|---|
| 155 | self._bookingsOpt.addItem( self._usersPrebookings ) |
|---|
| 156 | return self._leftMenu |
|---|
| 157 | |
|---|
| 158 | |
|---|
| 159 | class WPRoomBookingWelcome( WPRoomBookingBase ): |
|---|
| 160 | |
|---|
| 161 | def _getBody( self, params ): |
|---|
| 162 | wc = wcomponents.WRoomBookingWelcome() |
|---|
| 163 | return wc.getHTML( params ) |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 166 | # 1. Searching ... |
|---|
| 167 | |
|---|
| 168 | class WPRoomBookingSearch4Rooms( WPRoomBookingBase ): |
|---|
| 169 | |
|---|
| 170 | def __init__( self, rh, forNewBooking = False ): |
|---|
| 171 | self._rh = rh |
|---|
| 172 | self._forNewBooking = forNewBooking |
|---|
| 173 | WPRoomBookingBase.__init__( self, rh ) |
|---|
| 174 | |
|---|
| 175 | def _getTitle(self): |
|---|
| 176 | return WPRoomBookingBase._getTitle(self) + " - " + _("Search for rooms") |
|---|
| 177 | |
|---|
| 178 | def _setCurrentMenuItem( self ): |
|---|
| 179 | if self._forNewBooking: |
|---|
| 180 | self._bookARoomOpt.setActive(True) |
|---|
| 181 | else: |
|---|
| 182 | self._roomSearchOpt.setActive(True) |
|---|
| 183 | |
|---|
| 184 | def _getBody( self, params ): |
|---|
| 185 | wc = wcomponents.WRoomBookingSearch4Rooms( self._rh, standalone = True ) |
|---|
| 186 | return wc.getHTML( params ) |
|---|
| 187 | |
|---|
| 188 | class WPRoomBookingSearch4Bookings( WPRoomBookingBase ): |
|---|
| 189 | |
|---|
| 190 | def __init__( self, rh ): |
|---|
| 191 | self._rh = rh |
|---|
| 192 | WPRoomBookingBase.__init__( self, rh ) |
|---|
| 193 | |
|---|
| 194 | def _getTitle(self): |
|---|
| 195 | return WPRoomBookingBase._getTitle(self) + " - " + _("Search for bookings") |
|---|
| 196 | |
|---|
| 197 | def _setCurrentMenuItem( self ): |
|---|
| 198 | self._bookingListSearchOpt.setActive(True) |
|---|
| 199 | |
|---|
| 200 | def _getBody( self, params ): |
|---|
| 201 | wc = wcomponents.WRoomBookingSearch4Bookings( self._rh ) |
|---|
| 202 | return wc.getHTML( params ) |
|---|
| 203 | |
|---|
| 204 | class WPRoomBookingSearch4Users( WPRoomBookingBase ): |
|---|
| 205 | def __init__( self, rh ): |
|---|
| 206 | self._rh = rh |
|---|
| 207 | WPRoomBookingBase.__init__( self, rh ) |
|---|
| 208 | |
|---|
| 209 | def _getBody( self, params ): |
|---|
| 210 | wc = wcomponents.WUserSelection( \ |
|---|
| 211 | urlHandlers.UHRoomBookingSearch4Users.getURL(), |
|---|
| 212 | forceWithoutExtAuth = self._rh._forceWithoutExtAuth, |
|---|
| 213 | multi = False ) |
|---|
| 214 | params["addURL"] = urlHandlers.UHRoomBookingRoomForm.getURL() |
|---|
| 215 | return wc.getHTML( params ) |
|---|
| 216 | |
|---|
| 217 | # 2. List of ... |
|---|
| 218 | |
|---|
| 219 | class WPRoomBookingRoomList( WPRoomBookingBase ): |
|---|
| 220 | |
|---|
| 221 | def __init__( self, rh, onlyMy = False ): |
|---|
| 222 | self._rh = rh |
|---|
| 223 | self._onlyMy = onlyMy |
|---|
| 224 | WPRoomBookingBase.__init__( self, rh ) |
|---|
| 225 | |
|---|
| 226 | def _getTitle(self): |
|---|
| 227 | if self._onlyMy: |
|---|
| 228 | return WPRoomBookingBase._getTitle(self) + " - " + _("My Rooms") |
|---|
| 229 | else: |
|---|
| 230 | return WPRoomBookingBase._getTitle(self) + " - " + _("Found rooms") |
|---|
| 231 | |
|---|
| 232 | def _setCurrentMenuItem( self ): |
|---|
| 233 | if self._onlyMy: |
|---|
| 234 | self._myRoomListOpt.setActive(True) |
|---|
| 235 | else: |
|---|
| 236 | self._bookingListSearchOpt.setActive(True) |
|---|
| 237 | |
|---|
| 238 | |
|---|
| 239 | def _getBody( self, params ): |
|---|
| 240 | wc = wcomponents.WRoomBookingRoomList( self._rh, standalone = True ) |
|---|
| 241 | return wc.getHTML( params ) |
|---|
| 242 | |
|---|
| 243 | class WPRoomBookingBookingList( WPRoomBookingBase ): |
|---|
| 244 | |
|---|
| 245 | def __init__( self, rh, today=False, onlyMy=False, onlyPrebookings=False, onlyMyRooms=False ): |
|---|
| 246 | self._rh = rh |
|---|
| 247 | WPRoomBookingBase.__init__( self, rh ) |
|---|
| 248 | |
|---|
| 249 | def _getTitle(self): |
|---|
| 250 | if self._rh._today: |
|---|
| 251 | return WPRoomBookingBase._getTitle(self) + " - " + _("Calendar") |
|---|
| 252 | elif self._rh._onlyMy and self._rh._onlyPrebookings: |
|---|
| 253 | return WPRoomBookingBase._getTitle(self) + " - " + _("My PRE-bookings") |
|---|
| 254 | elif self._rh._onlyMy: |
|---|
| 255 | return WPRoomBookingBase._getTitle(self) + " - " + _("My bookings") |
|---|
| 256 | elif self._rh._ofMyRooms and self._rh._onlyPrebookings: |
|---|
| 257 | return WPRoomBookingBase._getTitle(self) + " - " + _("PRE-bookings in my rooms") |
|---|
| 258 | elif self._rh._ofMyRooms: |
|---|
| 259 | return WPRoomBookingBase._getTitle(self) + " - " + _("Bookings in my rooms") |
|---|
| 260 | else: |
|---|
| 261 | return WPRoomBookingBase._getTitle(self) + " - " + _("Found bookings") |
|---|
| 262 | |
|---|
| 263 | def _setCurrentMenuItem( self ): |
|---|
| 264 | if self._rh._today: |
|---|
| 265 | self._bookingListCalendarOpt.setActive(True) |
|---|
| 266 | elif self._rh._onlyMy and self._rh._onlyPrebookings: |
|---|
| 267 | self._myPreBookingListOpt.setActive(True) |
|---|
| 268 | elif self._rh._onlyMy: |
|---|
| 269 | self._myBookingListOpt.setActive(True) |
|---|
| 270 | elif self._rh._ofMyRooms and self._rh._onlyPrebookings: |
|---|
| 271 | self._usersPrebookings.setActive(True) |
|---|
| 272 | elif self._rh._ofMyRooms: |
|---|
| 273 | self._usersBookings.setActive(True) |
|---|
| 274 | else: |
|---|
| 275 | self._bookingListSearchOpt.setActive(True) |
|---|
| 276 | |
|---|
| 277 | def _getBody( self, pars ): |
|---|
| 278 | wc = wcomponents.WRoomBookingBookingList( self._rh ) |
|---|
| 279 | return wc.getHTML( pars ) |
|---|
| 280 | |
|---|
| 281 | |
|---|
| 282 | # 3. Details of... |
|---|
| 283 | |
|---|
| 284 | class WPRoomBookingRoomDetails( WPRoomBookingBase ): |
|---|
| 285 | |
|---|
| 286 | def __init__( self, rh ): |
|---|
| 287 | self._rh = rh |
|---|
| 288 | WPRoomBookingBase.__init__( self, rh ) |
|---|
| 289 | |
|---|
| 290 | def _getTitle(self): |
|---|
| 291 | return WPRoomBookingBase._getTitle(self) + " - " + _("Room Details") |
|---|
| 292 | |
|---|
| 293 | def _setCurrentMenuItem( self ): |
|---|
| 294 | self._roomSearchOpt.setActive(True) |
|---|
| 295 | |
|---|
| 296 | def _getBody( self, params ): |
|---|
| 297 | wc = wcomponents.WRoomBookingRoomDetails( self._rh, standalone = True ) |
|---|
| 298 | return wc.getHTML( params ) |
|---|
| 299 | |
|---|
| 300 | class WPRoomBookingRoomStats( WPRoomBookingBase ): |
|---|
| 301 | |
|---|
| 302 | def __init__( self, rh ): |
|---|
| 303 | self._rh = rh |
|---|
| 304 | WPRoomBookingBase.__init__( self, rh ) |
|---|
| 305 | |
|---|
| 306 | def _setCurrentMenuItem( self ): |
|---|
| 307 | self._roomSearchOpt.setActive(True) |
|---|
| 308 | |
|---|
| 309 | def _getBody( self, params ): |
|---|
| 310 | wc = wcomponents.WRoomBookingRoomStats( self._rh, standalone = True ) |
|---|
| 311 | return wc.getHTML( params ) |
|---|
| 312 | |
|---|
| 313 | class WPRoomBookingBookingDetails( WPRoomBookingBase ): |
|---|
| 314 | |
|---|
| 315 | def __init__( self, rh ): |
|---|
| 316 | self._rh = rh |
|---|
| 317 | WPRoomBookingBase.__init__( self, rh ) |
|---|
| 318 | |
|---|
| 319 | def _setCurrentMenuItem( self ): |
|---|
| 320 | self._bookingListSearchOpt.setActive(True) |
|---|
| 321 | |
|---|
| 322 | def _getBody( self, params ): |
|---|
| 323 | wc = wcomponents.WRoomBookingDetails( self._rh, standalone = True ) |
|---|
| 324 | return wc.getHTML( params ) |
|---|
| 325 | |
|---|
| 326 | # 4. New booking |
|---|
| 327 | |
|---|
| 328 | class WPRoomBookingBookingForm( WPRoomBookingBase ): |
|---|
| 329 | |
|---|
| 330 | def __init__( self, rh ): |
|---|
| 331 | self._rh = rh |
|---|
| 332 | WPRoomBookingBase.__init__( self, rh ) |
|---|
| 333 | |
|---|
| 334 | def _setCurrentMenuItem( self ): |
|---|
| 335 | self._bookARoomOpt.setActive(True) |
|---|
| 336 | |
|---|
| 337 | def _getBody( self, params ): |
|---|
| 338 | wc = wcomponents.WRoomBookingBookingForm( self._rh, standalone = True ) |
|---|
| 339 | return wc.getHTML( params ) |
|---|
| 340 | |
|---|
| 341 | class WPRoomBookingStatement( WPRoomBookingBase ): |
|---|
| 342 | |
|---|
| 343 | def __init__( self, rh ): |
|---|
| 344 | self._rh = rh |
|---|
| 345 | WPRoomBookingBase.__init__( self, rh ) |
|---|
| 346 | |
|---|
| 347 | def _getBody( self, params ): |
|---|
| 348 | wc = wcomponents.WRoomBookingStatement( self._rh ) |
|---|
| 349 | return wc.getHTML( params ) |
|---|
| 350 | |
|---|
| 351 | class WPRoomBookingConfirmBooking( WPRoomBookingBase ): |
|---|
| 352 | |
|---|
| 353 | def __init__( self, rh ): |
|---|
| 354 | self._rh = rh |
|---|
| 355 | WPRoomBookingBase.__init__( self, rh ) |
|---|
| 356 | |
|---|
| 357 | def _getBody( self, params ): |
|---|
| 358 | wc = wcomponents.WRoomBookingConfirmBooking( self._rh, standalone = True ) |
|---|
| 359 | return wc.getHTML( params ) |
|---|