# =========================================================================== # eXe # Copyright 2004-2005, University of Auckland # Copyright 2004-2007 eXe Project http://eXeLearning.org/ # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # =========================================================================== """ AppletBlock can render and process AppletIdevices as XHTML """ import os.path from exe.webui.block import Block from exe.webui import common #from string import Template import logging log = logging.getLogger(__name__) # =========================================================================== class AppletBlock(Block): """ AttachmentBlock can render and process AttachmentIdevices as XHTML """ def __init__(self, parent, idevice): """ Initialize """ Block.__init__(self, parent, idevice) if not hasattr(self.idevice,'undo'): self.idevice.undo = True def process(self, request): """ Process the request arguments from the web server to see if any apply to this block """ log.debug("process " + repr(request.args)) Block.process(self, request) is_cancel = common.requestHasCancel(request) if "code" + self.id in request.args \ and not is_cancel: self.idevice.appletCode = request.args["code" + self.id][0] if "action" in request.args and request.args["action"][0] == self.id: self.idevice.deleteFile(request.args["object"][0]) self.idevice.edit = True self.idevice.undo = False if "action" in request.args and request.args["action"][0] == "changeType" + self.id: self.idevice.type = request.args["object"][0] self.idevice.copyFiles() self.idevice.edit = True self.idevice.undo = False if "action" in request.args and request.args["action"][0] == "done": # remove the undo flag in order to reenable it next time: if hasattr(self.idevice,'undo'): del self.idevice.undo if "upload" + self.id in request.args: if "path" + self.id in request.args: filePath = request.args["path"+self.id][0] if filePath: if self.idevice.type == "geogebra" and not filePath.endswith(".ggb"): self.idevice.message = _("Please upload a .ggb file.") else: self.idevice.uploadFile(filePath) self.idevice.message = "" self.idevice.edit = True self.idevice.undo = False def renderEdit(self, style): """ Returns an XHTML string with the form elements for editing this block """ log.debug("renderEdit") html = "

\n" html += common.textInput("title"+self.id, self.idevice.title) html += u"

\n" types = [(_(u"Geogebra"), "geogebra"), (_(u"Other"), "other")] html += u"%s" % _("Applet Type") html += ' \n" html += common.elementInstruc(self.idevice.typeInstruc) + "

" if self.idevice.message <> "": html += '

' + self.idevice.message + '

' html += common.textInput("path"+self.id, "", 50) html += u'\n' % _(u"Add files") html += u'\n' html += u'%s\n' % _(u'Applet Code:') html += common.elementInstruc(self.idevice.codeInstruc) html += u'
\n' html += common.textArea('code'+self.id, self.idevice.appletCode,rows="12") if self.idevice.userResources: html += '' for resource in self.idevice.userResources: html += '\n' html += '
%s' % resource.storageName html += common.submitImage(self.id, resource.storageName, "/images/stock-cancel.png", _("Delete File")) html += '
' html += u'
\n' html += self.renderEditButtons(undo=self.idevice.undo) html += u'\n
\n' return html def renderPreview(self, style): """ Returns an XHTML string for previewing this block """ log.debug("renderPreview") appletcode = self.idevice.appletCode appletcode = appletcode.replace('>', '>') appletcode = appletcode.replace('<', '<') appletcode = appletcode.replace('"', '"') appletcode = appletcode.replace(' ', '') appletcode = appletcode.replace('\n" html += appletcode html += u"
" html += self.renderViewButtons() html += u"\n" return html def renderView(self, style): """ Returns an XHTML string for viewing this block """ log.debug("renderView") html = u"\n" html += u"
\n" appletcode = self.idevice.appletCode appletcode = appletcode.replace('>', '>') appletcode = appletcode.replace('<', '<') appletcode = appletcode.replace('"', '"') appletcode = appletcode.replace(' ', '') html += appletcode html += u"
" html += u"
\n" return html # =========================================================================== """Register this block with the BlockFactory""" from exe.engine.appletidevice import AppletIdevice from exe.webui.blockfactory import g_blockFactory g_blockFactory.registerBlockType(AppletBlock, AppletIdevice) # ===========================================================================