# ===========================================================================
# eXe
# Copyright 2004-2006, University of Auckland
#
# 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
# ===========================================================================
"""
The EditorPane is responsible for creating new idevice
"""
import logging
from exe.webui import common
from exe.engine.field import TextField, TextAreaField, ImageField, FlashField
from exe.engine.field import FeedbackField, MultimediaField, AttachmentField
from exe.webui.editorelement import TextEditorElement
from exe.webui.editorelement import TextAreaEditorElement
from exe.webui.editorelement import ImageEditorElement
from exe.webui.editorelement import FeedbackEditorElement
from exe.webui.editorelement import FlashEditorElement
from exe.webui.editorelement import MultimediaEditorElement
from exe.webui.editorelement import AttachmentEditorElement
from exe.engine.idevice import Idevice
from exe.engine.genericidevice import GenericIdevice
from exe.engine.path import Path
from exe.engine.translate import lateTranslate
log = logging.getLogger(__name__)
# ===========================================================================
class EditorPane(object):
"""
The EditorPane is responsible for creating new idevice
"""
def __init__(self, webServer):
"""
Initialize
"""
self.ideviceStore = webServer.application.ideviceStore
self.webDir = webServer.application.config.webDir
self.styles = webServer.application.config.styles
self.elements = []
self.idevice = GenericIdevice("", "", "", "", "")
self.idevice.id = self.ideviceStore.getNewIdeviceId()
self.originalIdevice = GenericIdevice("", "", "", "", "")
self.purpose = ""
self.tip = ""
self.message = ""
self._nameInstruc = \
x_(u"Your new iDevice will appear in the iDevice "
u"pane with this title. This is a compulsory field "
u"and you will be prompted to enter a label if you try "
u"to submit your iDevice without one.")
self._authorInstruc = x_(u"This is an optional field.")
self._purposeInstruc = x_(u"The purpose dialogue allows you to describe"
u" your intended purpose of the iDevice to other"
u" potential users.")
self._emphasisInstruc = x_(u"Use this pulldown to select whether or not "
u" the iDevice should have any formatting "
u" applied to it to distinguish "
u"it; ie. a border and an icon.")
self._tipInstruc = x_(u"Use this field to describe "
u"your intended use and the pedagogy behind "
u"the device's development. This can be useful "
u"if your iDevice is to be exported for others "
u"to use.")
self._lineInstruc = x_(u"Add a single text line to an iDevice. "
u"Useful if you want the ability to place a "
u"label within the iDevice.")
self._textBoxInstruc = x_(u"Add a text entry box to an iDevice. "
u"Used for entering larger amounts of textual "
u"content.")
self._feedbackInstruc = x_(u"Add an interactive feedback field to your iDevice.")
self._flashInstruc = x_(u"Add a flash video to your iDevice.")
self._mp3Instruc = x_(u"Add an mp3 file to your iDevice.")
self._attachInstruc = x_(u"Add an attachment file to your iDevice.")
self.style = "default"
# Properties
nameInstruc = lateTranslate('nameInstruc')
authorInstruc = lateTranslate('authorInstruc')
purposeInstruc = lateTranslate('purposeInstruc')
emphasisInstruc = lateTranslate('emphasisInstruc')
tipInstruc = lateTranslate('tipInstruc')
lineInstruc = lateTranslate('lineInstruc')
textBoxInstruc = lateTranslate('textBoxInstruc')
feedbackInstruc = lateTranslate('feedbackInstruc')
flashInstruc = lateTranslate('flashInstruc')
mp3Instruc = lateTranslate('mp3Instruc')
attachInstruc = lateTranslate('attachInstruc')
def setIdevice(self, idevice):
"""
Sets the iDevice to edit
"""
self.idevice = idevice.clone()
self.idevice.id = idevice.id
self.originalIdevice = idevice
def process(self, request, status):
"""
Process
"""
log.debug("process " + repr(request.args))
self.message = ""
if status == "old":
for element in self.elements:
element.process(request)
if "title" in request.args:
self.idevice.title = unicode(request.args["title"][0], 'utf8')
if "tip" in request.args:
self.idevice.tip = unicode(request.args["tip"][0], 'utf8')
if "emphasis" in request.args:
self.idevice.emphasis = int(request.args["emphasis"][0])
if self.idevice.emphasis == 0:
self.idevice.icon = ""
if "addText" in request.args:
field = TextField(_(u"Enter the label here"),
_(u"Enter instructions for completion here"))
field.setIDevice(self.idevice)
self.idevice.addField(field)
self.idevice.edit = True
if "addTextArea" in request.args:
field = TextAreaField(_(u"Enter the label here"),
_(u"Enter the instructions for completion here"))
field.setIDevice(self.idevice)
self.idevice.addField(field)
self.idevice.edit = True
if "addFeedback" in request.args:
field = FeedbackField(_(u"Enter the label here"),
_(u"""Feedback button will not appear if no
data is entered into this field."""))
field.setIDevice(self.idevice)
self.idevice.addField(field)
self.idevice.edit = True
#if "addFlash" in request.args:
#print "add a flash"
#field = FlashField(_(u"Enter the label here"),
#_(u"Enter the instructions for completion here"))
#field.setIDevice(self.idevice)
#self.idevice.addField(field)
if "addMP3" in request.args:
field = MultimediaField(_(u"Enter the label here"),
_(u"Enter the instructions for completion here"))
field.setIDevice(self.idevice)
self.idevice.addField(field)
if not 'xspf_player.swf' in self.idevice.systemResources:
self.idevice.systemResources += ['xspf_player.swf']
self.idevice.edit = True
if "addAttachment" in request.args:
field = AttachmentField(_(u"Enter the label here"),
_(u"Enter the instructions for completion here"))
field.setIDevice(self.idevice)
self.idevice.addField(field)
self.idevice.edit = True
if ("action" in request.args and
request.args["action"][0] == "selectIcon"):
self.idevice.icon = request.args["object"][0]
if "preview" in request.args:
if self.idevice.title == "":
self.message = _("Please enter
an idevice name.")
else:
self.idevice.edit = False
if "edit" in request.args:
self.idevice.edit = True
if "cancel" in request.args:
ideviceId = self.idevice.id
self.idevice = self.originalIdevice.clone()
self.idevice.id = ideviceId
if ("action" in request.args and
request.args["action"][0] == "changeStyle"):
self.style = request.args["object"][0]
self.__buildElements()
def __buildElements(self):
"""
Building up element array
"""
self.elements = []
elementTypeMap = {TextField: TextEditorElement,
TextAreaField: TextAreaEditorElement,
ImageField: ImageEditorElement,
FeedbackField: FeedbackEditorElement,
MultimediaField: MultimediaEditorElement,
FlashField: FlashEditorElement,
AttachmentField: AttachmentEditorElement}
for field in self.idevice.fields:
elementType = elementTypeMap.get(field.__class__)
if elementType:
# Create an instance of the appropriate element class
log.debug(u"createElement "+elementType.__class__.__name__+
u" for "+field.__class__.__name__)
self.elements.append(elementType(field))
else:
log.error(u"No element type registered for " +
field.__class__.__name__)
def renderButtons(self, request):
"""
Render the idevice being edited
"""
html = ""+self.message+""
html += "