| 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | ## |
|---|
| 3 | ## $id$ |
|---|
| 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.webinterface.pages.conferences import WPConferenceModifBase, WPConferenceDefaultDisplayBase |
|---|
| 23 | from MaKaC.webinterface import wcomponents |
|---|
| 24 | from MaKaC.webinterface.wcomponents import WTemplated |
|---|
| 25 | from MaKaC.common.utils import formatDateTime, parseDateTime |
|---|
| 26 | from MaKaC.common.fossilize import fossilize |
|---|
| 27 | from MaKaC.common.timezoneUtils import getAdjustedDate, nowutc, setAdjustedDate, DisplayTZ, minDatetime |
|---|
| 28 | from MaKaC.plugins import PluginsHolder, InstantMessaging |
|---|
| 29 | from MaKaC.plugins.helpers import DBHelpers |
|---|
| 30 | from MaKaC.plugins.util import PluginFieldsWrapper |
|---|
| 31 | from MaKaC.plugins.InstantMessaging import urlHandlers |
|---|
| 32 | from MaKaC.webinterface.rh.conferenceModif import RHMaterialsShow |
|---|
| 33 | from MaKaC.plugins.InstantMessaging.XMPP.helpers import generateCustomLinks, generateLogLink, XMPPLogsActivated, DesktopLinkGenerator, WebLinkGenerator |
|---|
| 34 | from MaKaC.i18n import _ |
|---|
| 35 | import zope.interface |
|---|
| 36 | from indico.core.extpoint import Component |
|---|
| 37 | from indico.core.extpoint.conference import IEventDisplayContributor |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | class WPConfModifChat(WPConferenceModifBase): |
|---|
| 41 | |
|---|
| 42 | def __init__(self, rh, conf): |
|---|
| 43 | WPConferenceModifBase.__init__(self, rh, conf) |
|---|
| 44 | self._conf = conf |
|---|
| 45 | self._tabs = {} # list of Indico's Tab objects |
|---|
| 46 | self._tabNames = rh._tabs |
|---|
| 47 | self._activeTabName = rh._activeTabName |
|---|
| 48 | self._aw = rh.getAW() |
|---|
| 49 | |
|---|
| 50 | self._tabCtrl = wcomponents.TabControl() |
|---|
| 51 | |
|---|
| 52 | #TODO: with wsgi we want to specify another path instead of the usual one for .js files, so we'll have to make some modifications |
|---|
| 53 | #to make possible specifying absoulte paths |
|---|
| 54 | def getJSFiles(self): |
|---|
| 55 | return WPConferenceModifBase.getJSFiles(self) + self._includeJSPackage('Plugins') |
|---|
| 56 | |
|---|
| 57 | def getJSFiles(self): |
|---|
| 58 | return WPConferenceModifBase.getJSFiles(self) + \ |
|---|
| 59 | self._includeJSFile('InstantMessaging/js', 'InstantMessaging') |
|---|
| 60 | |
|---|
| 61 | def getCSSFiles(self): |
|---|
| 62 | return WPConferenceModifBase.getCSSFiles(self) + \ |
|---|
| 63 | ['InstantMessaging/im.css'] |
|---|
| 64 | |
|---|
| 65 | def _createTabCtrl(self): |
|---|
| 66 | for tabName in self._tabNames: |
|---|
| 67 | url = urlHandlers.UHConfModifChat.getURL(self._conf, tab = tabName) |
|---|
| 68 | self._tabs[tabName] = self._tabCtrl.newTab(tabName, tabName, url) |
|---|
| 69 | |
|---|
| 70 | self._setActiveTab() |
|---|
| 71 | |
|---|
| 72 | def _setActiveSideMenuItem(self): |
|---|
| 73 | self._pluginsDictMenuItem['Instant Messaging'].setActive(True) |
|---|
| 74 | |
|---|
| 75 | def _setActiveTab(self): |
|---|
| 76 | self._tabs[self._activeTabName].setActive() |
|---|
| 77 | |
|---|
| 78 | def _getTitle(self): |
|---|
| 79 | return WPConferenceModifBase._getTitle(self) + " - " + _("Chat management") |
|---|
| 80 | |
|---|
| 81 | def _getPageContent(self, params): |
|---|
| 82 | if len(self._tabNames) > 0: |
|---|
| 83 | self._createTabCtrl() |
|---|
| 84 | wc = WConfModifChat.forModule(InstantMessaging, self._conf, |
|---|
| 85 | self._activeTabName, self._tabNames, self._aw) |
|---|
| 86 | return wcomponents.WTabControl(self._tabCtrl, self._getAW()).getHTML(wc.getHTML({})) |
|---|
| 87 | else: |
|---|
| 88 | return _("No available plugins, or no active plugins") |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | class WPConferenceInstantMessaging(WPConferenceDefaultDisplayBase): |
|---|
| 92 | |
|---|
| 93 | def __init__(self, rh, conf): |
|---|
| 94 | WPConferenceDefaultDisplayBase.__init__(self, rh, conf) |
|---|
| 95 | self._conf = conf |
|---|
| 96 | self._aw = rh.getAW() |
|---|
| 97 | |
|---|
| 98 | def _getBody(self, params): |
|---|
| 99 | wc = WConferenceInstantMessaging.forModule(InstantMessaging, |
|---|
| 100 | self._conf, self._aw) |
|---|
| 101 | return wc.getHTML({}) |
|---|
| 102 | |
|---|
| 103 | def _defineSectionMenu( self ): |
|---|
| 104 | WPConferenceDefaultDisplayBase._defineSectionMenu(self) |
|---|
| 105 | self._sectionMenu.setCurrentItem(self._sectionMenu.getLinkByName("instantMessaging")) |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | class IMEventDisplayComponent(Component): |
|---|
| 109 | |
|---|
| 110 | zope.interface.implements(IEventDisplayContributor) |
|---|
| 111 | |
|---|
| 112 | # EventDisplayContributor |
|---|
| 113 | def injectCSSFiles(self, obj): |
|---|
| 114 | return ['InstantMessaging/im.css'] |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | class WConfModifChat(wcomponents.WTemplated): |
|---|
| 118 | |
|---|
| 119 | def __init__(self, conference, activeTab, tabNames, aw): |
|---|
| 120 | self._conf = conference |
|---|
| 121 | self._activeTab = activeTab |
|---|
| 122 | self._tabNames = tabNames |
|---|
| 123 | self._aw = aw |
|---|
| 124 | self._user = aw.getUser() |
|---|
| 125 | |
|---|
| 126 | def getVars( self ): |
|---|
| 127 | vars = WTemplated.getVars( self ) |
|---|
| 128 | vars["Conference"] = self._conf |
|---|
| 129 | try: |
|---|
| 130 | chatrooms = list(DBHelpers.getChatroomList(self._conf)) |
|---|
| 131 | vars["Chatrooms"] = fossilize(chatrooms) |
|---|
| 132 | if len(vars['Chatrooms']) is 0: |
|---|
| 133 | vars['Chatrooms'] = None |
|---|
| 134 | except Exception, e: |
|---|
| 135 | vars["Chatrooms"] = None |
|---|
| 136 | chatrooms = {} |
|---|
| 137 | links = {} |
|---|
| 138 | |
|---|
| 139 | for cr in chatrooms: |
|---|
| 140 | crinfo = links[cr.getId() ] = {} |
|---|
| 141 | crinfo['custom'] = generateCustomLinks(cr) |
|---|
| 142 | crinfo['logs'] = generateLogLink(cr, self._conf) |
|---|
| 143 | |
|---|
| 144 | vars['links'] = links |
|---|
| 145 | |
|---|
| 146 | vars['DefaultServer'] = PluginFieldsWrapper('InstantMessaging', 'XMPP').getOption('chatServerHost') |
|---|
| 147 | vars["EventDate"] = formatDateTime(getAdjustedDate(nowutc(), self._conf)) |
|---|
| 148 | vars["User"] = self._user |
|---|
| 149 | vars["tz"] = DisplayTZ(self._aw,self._conf).getDisplayTZ() |
|---|
| 150 | vars["MaterialUrl"] = RHMaterialsShow._uh().getURL(self._conf).__str__() |
|---|
| 151 | vars["ShowLogsLink"] = XMPPLogsActivated() |
|---|
| 152 | |
|---|
| 153 | return vars |
|---|
| 154 | |
|---|
| 155 | class WConferenceInstantMessaging(wcomponents.WTemplated): |
|---|
| 156 | |
|---|
| 157 | def __init__(self, conference, aw): |
|---|
| 158 | self._conf = conference |
|---|
| 159 | self._aw = aw |
|---|
| 160 | self._user = aw.getUser() |
|---|
| 161 | |
|---|
| 162 | def getVars( self ): |
|---|
| 163 | vars = WTemplated.getVars( self ) |
|---|
| 164 | |
|---|
| 165 | vars["Conference"] = self._conf |
|---|
| 166 | |
|---|
| 167 | try: |
|---|
| 168 | vars["Chatrooms"] = DBHelpers.getShowableRooms(self._conf) |
|---|
| 169 | except Exception, e: |
|---|
| 170 | vars["Chatrooms"] = None |
|---|
| 171 | vars["Links"] = {} |
|---|
| 172 | for cr in vars["Chatrooms"]: |
|---|
| 173 | vars["Links"][cr.getId()] = {} |
|---|
| 174 | vars["Links"][cr.getId()]['custom'] = generateCustomLinks(cr) |
|---|
| 175 | |
|---|
| 176 | return vars |
|---|