def __init__(self, parent, idevice):
        """
        Pre-create our field ids
        """
        Block.__init__(self, parent, idevice)
        
       
        # to compensate for the strange unpickling timing when objects are 
        # loaded from an elp, ensure that proper idevices are set:
        if idevice.instructionsForLearners.idevice is None: 
            idevice.instructionsForLearners.idevice = idevice
        if idevice.content.idevice is None: 
            idevice.content.idevice = idevice
        if idevice.feedback.idevice is None: 
            idevice.feedback.idevice = idevice
            
        dT = common.getExportDocType()
        sectionTag = "div"
        if dT == "HTML5":
            sectionTag = "section"
            
        idevice.instructionsForLearners.htmlTag = sectionTag
        idevice.instructionsForLearners.class_ = "block instructions"
        idevice.feedback.htmlTag = sectionTag            

        self.instructionElement = TextAreaElement(idevice.instructionsForLearners)
        self.instructionElement.field.content_w_resourcePaths = c_(self.instructionElement.field.content_w_resourcePaths)
        self.listaElement = ListaElement(idevice.content)
        self.feedbackElement = \
            TextAreaElement(idevice.feedback)
        self.previewing        = False # In view or preview render
        if not hasattr(self.idevice,'undo'): 
            self.idevice.undo = True
    def __init__(self, index, idevice, question):
        """
        Initialize
        """
        self.index      = index
        self.id         = unicode(index) + "b" + idevice.id        
        self.idevice    = idevice

        self.question   = question
        # also split out each part for a separate TextAreaElement:
        # but first...
        # to compensate for the strange unpickling timing when objects are 
        # loaded from an elp, ensure that proper idevices are set:
        if question.questionTextArea.idevice is None: 
            question.questionTextArea.idevice = idevice
        if question.feedbackTextArea.idevice is None: 
            question.feedbackTextArea.idevice = idevice
        if question.hintTextArea.idevice is None: 
            question.hintTextArea.idevice = idevice
        #
        self.question_question = TextAreaElement(question.questionTextArea)
        self.question_feedback = TextAreaElement(question.feedbackTextArea)
        self.question_hint = TextAreaElement(question.hintTextArea)

        # note, question.isCorrect is left as it was, and not split out.
        # because there are low-level mechanisms in place somewhere 
        # with the radio buttons or ??? expecting that as such.
        
        self.questionId = "question"+ unicode(index) + "b" + idevice.id
        self.question_question.id = self.questionId
        self.feedbackId = "feedback" + unicode(index) + "b" + idevice.id 
        self.question_feedback.id = self.feedbackId
        self.hintId     = "hint" + unicode(index) + "b" + idevice.id 
        self.question_hint.id = self.hintId
        self.keyId      = "Key" + unicode(index) + "b" + idevice.id       
Beispiel #3
0
    def __init__(self, index, idevice, question):
        """
        Initialize
        'index' is our number in the list of questions
        'idevice' is a case study idevice
        'question' is a exe.engine.casestudyidevice.Question instance
        """
        self.index        = index
        self.id           = "q" + unicode(index) + "b" + idevice.id        
        self.idevice      = idevice


        self.quesId       = "quesQuestion" + unicode(index) + "b" + idevice.id
        self.feedbackId   = "quesFeedback" + unicode(index) + "b" + idevice.id

        self.question     = question
        # also split out each part for a separate TextAreaElement:

        # but first....  
        # to compensate for the strange unpickling timing when objects are 
        # loaded from an elp, ensure that proper idevices are set: 
        if question.questionTextArea.idevice is None: 
            question.questionTextArea.idevice = idevice 
        if question.feedbackTextArea.idevice is None: 
            question.feedbackTextArea.idevice = idevice

        self.question_question = TextAreaElement(question.questionTextArea)
        self.question_question.id = self.quesId 
        self.question_feedback = TextAreaElement(question.feedbackTextArea)
        self.question_feedback.id = self.feedbackId 
Beispiel #4
0
 def __init__(self, parent, idevice):
     """
     Pre-create our field ids
     """
     Block.__init__(self, parent, idevice)
     self.instructionElement = TextAreaElement(idevice.instructionsForLearners)
     self.clozeElement = ClozeElement(idevice.content)
     self.feedbackElement = TextAreaElement(idevice.feedback)
Beispiel #5
0
 def __init__(self, parent, idevice):
     """
     Initialize a new Block object
     """
     Block.__init__(self, parent, idevice)
     self.activityInstruc = idevice.activityInstruc
     self.answerInstruc   = idevice.answerInstruc
     self.activityElement  = TextAreaElement(idevice.activityTextArea)
     self.answerElement    = TextAreaElement(idevice.answerTextArea)
     self.previewing        = False # In view or preview render
class ExampleBlock(Block):
    """
    ExampleBlock can render and process ExampleIdevices as XHTML
    GenericBlock will replace it..... one day
    """
    def __init__(self, parent, idevice):
        Block.__init__(self, parent, idevice)
        self.contentElement = TextAreaElement(idevice.content)
        self.contentElement.height = 250


    def process(self, request):
        """
        Process the request arguments from the web server to see if any
        apply to this block
        """
        Block.process(self, request)
        content = self.contentElement.process(request)
        if content:
            self.idevice.content = content


    def renderEdit(self, style):
        """
        Returns an XHTML string with the form element for editing this block
        """
        html  = u"<div>\n"
        html += self.contentElement.renderEdit()
        html += self.renderEditButtons()
        html += u"</div>\n"
        return html


    def renderPreview(self, style):
        """
        Returns an XHTML string for previewing this block
        """
        html  = u"<div class=\"iDevice "
        html += u"emphasis"+unicode(self.idevice.emphasis)+"\" "
        html += u"ondblclick=\"submitLink('edit',"+self.id+", 0);\">\n"
        html += self.contentElement.renderView()
        html += self.renderViewButtons()
        html += "</div>\n"
        return html


    def renderView(self, style):
        """
        Returns an XHTML string for viewing this block
        """
        html  = u"<div class=\"iDevice "
        html += u"emphasis"+unicode(self.idevice.emphasis)+"\">\n"
        html += self.contentElement.renderView()
        html += u"</div>\n"
        return html
class GenericHTMLBlock(Block):
    
    def __init__(self, parent, idevice):
        Block.__init__(self, parent, idevice)
        self.content_element = TextAreaElement(idevice.content_field)
        self.content_element.idevice = idevice
        
    def process(self, request):
        if self.id + "_htmlcontent" in request.args:
            request.args[self.content_element.id] = request.args[self.id+"_htmlcontent"]
        
        Block.process(self, request)
        self.content_element.process(request)
    
    
    def renderEdit(self, style):
        idevice_dir_name = self.idevice.get_idevice_dirname()
        html = u"<div>"
        html += common.ideviceShowEditMessage(self)
        
        html  = u"<div class='idevice_authoring_container' " \
            + "data-idevicetype='%s' " % idevice_dir_name \
            + "data-ideviceid='%s'>\n" % self.idevice.id
        
        
        # the content without wrapping div etc.
        content_html = self.content_element.field.content_w_resourcePaths
        
        html += content_html
        
        html += "</div>"
        html += "<input type='hidden' name='%s_htmlcontent'/>\n" % self.id
        html += "<input type='hidden' name='%s_resources'/>\n" % self.id
        html += self.renderEditButtons()
        html += u"</div>\n"
        
        return html

    def renderPreview(self, style):
        html = common.ideviceHeader(self, style, "preview")
        html += self.content_element.renderView()
        html += common.ideviceFooter(self, style, "preview")
        
        return html
    
    def renderView(self, style):
        html = common.ideviceHeader(self, style, "view")
        html += self.content_element.renderPreview()
        html += common.ideviceFooter(self, style, "view")
        
        return html
Beispiel #8
0
class PlacableObjectElement(Element):
    
    #here field should be placeableobjectfield
    def __init__(self, field):
        Element.__init__(self, field)
        # there is then field.maincontent, field.width, field.height, field.correctx, field.correcty , etc.
        self.mainContentElement = TextAreaElement(field.mainContentField)
        self.targetXElement = TextElement(field.targetX)
        self.targetYElement = TextElement(field.targetY)
        self.widthElement = TextElement(field.width)
        self.heightElement = TextElement(field.height)
        self.toleranceElement = TextElement(field.tolerance)

    def process(self, request):
        self.mainContentElement.process(request)
        self.targetXElement.process(request)
        self.targetYElement.process(request)
        self.widthElement.process(request)
        self.heightElement.process(request)
        self.toleranceElement.process(request)
        field_engine_check_delete(self, request, self.field.idevice.objectsToPlace)

    def renderEdit(self):
        html = ""
        html += self.mainContentElement.renderEdit()
        html += self.targetXElement.renderEdit()
        html += self.targetYElement.renderEdit()
        html += self.widthElement.renderEdit()
        html += self.heightElement.renderEdit()
        html += self.toleranceElement.renderEdit()
        html += field_engine_make_delete_button(self)
        return html
   
    def renderView(self):
        html = ""
        html += self.mainContentElement.renderView()
        html += self.mainContentElement.renderView()
        html += self.targetXElement.renderView()
        html += self.targetYElement.renderView()
        html += self.widthElement.renderView()
        html += self.heightElement.renderView()
        html += self.toleranceElement.renderView()

        return html

    def renderPreview(self):
        html = ""
        html += self.renderView()
        return html
Beispiel #9
0
 def __init__(self, parent, idevice):
     """
     Initialize
     """
     Block.__init__(self, parent, idevice)
     self.mediaElement = MultimediaElement(idevice.media)
     self.textElement  = TextAreaElement(idevice.text)
    def __init__(self, parent, idevice):
        """
        Initialize a new Block object
        """
        Block.__init__(self, parent, idevice)
        self.idevice           = idevice
        self.questionElements  = []

        # to compensate for the strange unpickling timing when objects are 
        # loaded from an elp, ensure that proper idevices are set:
        if idevice.storyTextArea.idevice is None: 
            idevice.storyTextArea.idevice = idevice

        self.storyElement      = TextAreaElement(idevice.storyTextArea)

        self.questionInstruc   = idevice.questionInstruc
        self.storyInstruc      = idevice.storyInstruc
        self.feedbackInstruc   = idevice.feedbackInstruc
        self.previewing        = False # In view or preview render 

        if not hasattr(self.idevice,'undo'): 
            self.idevice.undo = True

        i = 0
        
        for question in idevice.questions:
            self.questionElements.append(QuestionElement(i, idevice, question))
            i += 1
Beispiel #11
0
 def __init__(self, parent, idevice):
     """
     Initialize a new Block object
     """
     Block.__init__(self, parent, idevice)
     self.activityInstruc = idevice.activityInstruc
     self.answerInstruc   = idevice.answerInstruc
     if idevice.activityTextArea.idevice is None: 
         idevice.activityTextArea.idevice = idevice
     if idevice.answerTextArea.idevice is None: 
         idevice.answerTextArea.idevice = idevice
     self.activityElement  = TextAreaElement(idevice.activityTextArea)
     self.answerElement    = TextAreaElement(idevice.answerTextArea)
     self.previewing        = False # In view or preview render
     if not hasattr(self.idevice,'undo'): 
         self.idevice.undo = True
Beispiel #12
0
 def __init__(self, parent, idevice):
     """
     Initialize
     """
     Block.__init__(self, parent, idevice)
     self.flashMovieElement = FlashMovieElement(idevice.flash)
     self.textElement  = TextAreaElement(idevice.text)
    def __init__(self, parent, idevice):
        """
        Initialize a new Block object
        """
        Block.__init__(self, parent, idevice)
        self.idevice         = idevice
        self.questionElements  = []
        self.questionInstruc = idevice.questionInstruc
        self.keyInstruc      = idevice.keyInstruc
        self.feedbackInstruc = idevice.feedbackInstruc
        self.hintInstruc     = idevice.hintInstruc 

        # to compensate for the strange unpickling timing when objects are 
        # loaded from an elp, ensure that proper idevices are set:
        if idevice.instructionsForLearners.idevice is None: 
            idevice.instructionsForLearners.idevice = idevice
        self.instructionElement = \
            TextAreaElement(idevice.instructionsForLearners)

        if not hasattr(self.idevice,'undo'):
            self.idevice.undo = True
        
        i = 0
        for question in idevice.questions:
            self.questionElements.append(OpinionElement(i, idevice, 
                                                           question))
            i += 1
    def __init__(self, index, idevice, question):
        """
        Initialize
        """
        self.index      = index
        self.id         = unicode(index) + "b" + idevice.id        
        self.idevice    = idevice

        # to compensate for the strange unpickling timing when objects are 
        # loaded from an elp, ensure that proper idevices are set:
        if question.questionTextArea.idevice is None: 
            question.questionTextArea.idevice = idevice
        self.questionElement = TextAreaElement(question.questionTextArea)
        self.question   = question

        self.questionId = "question"+self.id
        self.questionElement.id = self.questionId

        self.options    = []
        self.keyId      = "key" + self.id
        i = 0
        for option in question.options:
            self.options.append(TestoptionElement(i,
                                                  question, 
                                                  self.id, 
                                                  option,
                                                  idevice))
            i += 1
Beispiel #15
0
 def __init__(self, parent, idevice):
     """
     Initialize
     """
     Block.__init__(self, parent, idevice)
     self.imageMagnifierElement = MagnifierElement(idevice.imageMagnifier)
     self.textElement  = TextAreaElement(idevice.text)
Beispiel #16
0
 def __init__(self, parent, idevice):
     """
     Initialize
     """
     Block.__init__(self, parent, idevice)
     self.articleElement = TextAreaElement(idevice.article)
     self.articleElement.height = 300
Beispiel #17
0
 def __init__(self, parent, idevice):
     Block.__init__(self, parent, idevice)
     if idevice.content.idevice is None: 
         idevice.content.idevice = idevice
     self.contentElement = TextAreaElement(idevice.content)
     self.contentElement.height = 250
     if not hasattr(self.idevice,'undo'): 
         self.idevice.undo = True
Beispiel #18
0
 def __init__(self, parent, idevice):
     """
     Pre-create our field ids
     """
     Block.__init__(self, parent, idevice)
     if idevice.instructionsForLearners.idevice is None: 
         idevice.instructionsForLearners.idevice = idevice
     if idevice.content.idevice is None: 
         idevice.content.idevice = idevice
     if idevice.feedback.idevice is None: 
         idevice.feedback.idevice = idevice
     self.instructionElement = \
         TextAreaElement(idevice.instructionsForLearners)
     self.clozeElement = ClozeElement(idevice.content)
     self.feedbackElement = \
         TextAreaElement(idevice.feedback)
     self.previewing        = False # In view or preview render
Beispiel #19
0
 def __init__(self, parent, idevice):
     """
     Initialize
     """
     Block.__init__(self, parent, idevice) 
     if idevice.descriptionTextArea.idevice is None: 
         idevice.descriptionTextArea.idevice = idevice
     self.descriptionElement = TextAreaElement(idevice.descriptionTextArea)
Beispiel #20
0
 def __init__(self, field):
     Element.__init__(self, field)
     # there is then field.maincontent, field.width, field.height, field.correctx, field.correcty , etc.
     self.mainContentElement = TextAreaElement(field.mainContentField)
     self.targetXElement = TextElement(field.targetX)
     self.targetYElement = TextElement(field.targetY)
     self.widthElement = TextElement(field.width)
     self.heightElement = TextElement(field.height)
     self.toleranceElement = TextElement(field.tolerance)
Beispiel #21
0
 def __init__(self, parent, idevice):
     """
     Initialize
     """
     Block.__init__(self, parent, idevice)
     if idevice.rss.idevice is None: 
         idevice.rss.idevice = idevice
     self.rssElement = TextAreaElement(idevice.rss)
     self.rssElement.height = 300
Beispiel #22
0
 def __init__(self, parent, idevice):
     """
     Initialize
     """
     Block.__init__(self, parent, idevice)
     self.flashElement = FlashElement(idevice.flash)
     if idevice.text.idevice is None: 
         idevice.text.idevice = idevice
     self.textElement  = TextAreaElement(idevice.text)
Beispiel #23
0
 def __init__(self, index, idevice, question):
     """
     Initialize
     'index' is our number in the list of questions
     'idevice' is a case study idevice
     'question' is a exe.engine.casestudyidevice.Question instance
     """
     self.index        = index
     self.id           = "q" + unicode(index) + "b" + idevice.id        
     self.idevice      = idevice
     self.quesId       = "quesQuestion" + unicode(index) + "b" + idevice.id
     self.feedbackId   = "quesFeedback" + unicode(index) + "b" + idevice.id
     self.imageElement = ImageElement(question.image)
     self.question     = question
     self.question_question = TextAreaElement(question.questionTextArea)
     self.question_question.id = self.quesId 
     self.question_feedback = TextAreaElement(question.feedbackTextArea)
     self.question_feedback.id = self.feedbackId 
 def __init__(self, parent, idevice):
     Block.__init__(self, parent, idevice)
     self.fileAttachmentElements = []
     for fileField in self.idevice.fileAttachmentFields:
         fileElement = FileElement(fileField, False)
         self.fileAttachmentElements.append(fileElement)
     
     self.showDescBlock = ChoiceElement(idevice.showDesc)
     self.introHTMLElement = TextAreaElement(idevice.introHTML)
Beispiel #25
0
 def __init__(self, index, idevice, question):
     """
     Initialize
     """
     self.index      = index
     self.id         = unicode(index) + "b" + idevice.id        
     self.idevice    = idevice
     self.question   = question
     self.question_question = TextAreaElement(question.question)
     self.question_feedback = TextAreaElement(question.feedback)
     self.question_hint = TextAreaElement(question.hint)
     self.question_isCorrect = question.isCorrect
     self.questionId = "question"+ unicode(index) + "b" + idevice.id
     self.keyId      = "Key" + unicode(index) + "b" + idevice.id       
     self.feedbackId = "feedback" + unicode(index) + "b" + idevice.id 
     self.hintId     = "hint" + unicode(index) + "b" + idevice.id 
     self.question_question.id = self.questionId
     self.question_feedback.id = self.feedbackId
     self.question_hint.id = self.hintId
Beispiel #26
0
 def __init__(self, parent, idevice):
     """
     Initialize
     """
     Block.__init__(self, parent, idevice)
     self.imageMagnifierElement = MagnifierElement(idevice.imageMagnifier)
     if idevice.text.idevice is None: 
         idevice.text.idevice = idevice
     self.textElement  = TextAreaElement(idevice.text)
     if not hasattr(self.idevice,'undo'): 
         self.idevice.undo = True
Beispiel #27
0
    def __init__(self, parent, idevice):
        Block.__init__(self, parent, idevice)
        self.contentElement = TextAreaElement(idevice.content)
        self.contentElement.height = 250
        self.titleElement = TextElement(idevice.titleField)

        self.mainAreaElement = TextAreaElement(idevice.mainArea)
        self.mainAreaElement.height = 200
        
        self.placableObjectElements = []
        for placableObjectField in idevice.objectsToPlace:
            newPlacableElement = PlacableObjectElement(placableObjectField)
            self.placableObjectElements.append(newPlacableElement)

        self.positiveResponseElement = TextAreaElement(idevice.positiveResponseArea)
        self.negativeResponseElement = TextAreaElement(idevice.negativeResponseArea)
        self.clickToStartElement = TextAreaElement(idevice.clickToStartGameArea)
        self.gameTimeLimit = TextElement(idevice.gameTimeLimit)
        self.gameTimerShown = TextElement(idevice.gameTimerShown)
        self.partbinNumCols = TextElement(idevice.partbinNumCols)
Beispiel #28
0
 def __init__(self, parent, idevice):
     """
     Initialize
     """
     Block.__init__(self, parent, idevice)
     if idevice.rss.idevice is None: 
         idevice.rss.idevice = idevice
     self.rssElement = TextAreaElement(idevice.rss)
     self.rssElement.height = 300
     if not hasattr(self.idevice,'undo'): 
         self.idevice.undo = True
Beispiel #29
0
    def __init__(self, parent, idevice):
        Block.__init__(self, parent, idevice)
        if idevice.content.idevice is None: 
            # due to the loading process's timing, idevice wasn't yet set; 
            # set it here for the TextAreaElement's tinyMCE editor 
            idevice.content.idevice = idevice

        self.contentElement = TextAreaElement(idevice.content)
        self.contentElement.height = 250
        if not hasattr(self.idevice,'undo'): 
            self.idevice.undo = True
    def __init__(self, index, idevice, question):
        """
        Initialize
        """
        self.index      = index
        self.id         = unicode(index) + "b" + idevice.id        
        self.idevice    = idevice

        self.question   = question
        # also split out each part for a separate TextAreaElement:
        # but first...
        # to compensate for the strange unpickling timing when objects are 
        # loaded from an elp, ensure that proper idevices are set:
        if question.questionTextArea.idevice is None: 
            question.questionTextArea.idevice = idevice
        if question.feedbackTextArea.idevice is None: 
            question.feedbackTextArea.idevice = idevice
        if question.hintTextArea.idevice is None: 
            question.hintTextArea.idevice = idevice
        #
        self.question_question = TextAreaElement(question.questionTextArea)
        self.question_feedback = TextAreaElement(question.feedbackTextArea)
        self.question_hint = TextAreaElement(question.hintTextArea)

        # note, question.isCorrect is left as it was, and not split out.
        # because there are low-level mechanisms in place somewhere 
        # with the radio buttons or ??? expecting that as such.
        
        self.questionId = "question"+ unicode(index) + "b" + idevice.id
        self.question_question.id = self.questionId
        self.feedbackId = "feedback" + unicode(index) + "b" + idevice.id 
        self.question_feedback.id = self.feedbackId
        self.hintId     = "hint" + unicode(index) + "b" + idevice.id 
        self.question_hint.id = self.hintId
        self.keyId      = "Key" + unicode(index) + "b" + idevice.id       
Beispiel #31
0
    def __init__(self, parent, idevice):
        Block.__init__(self, parent, idevice)
        self.titleElement = TextElement(idevice.titleField)
        self.contentElement = TextAreaElement(idevice.content)
        self.contentElement.height = 250
        self.chanceImageElements = []

        #go through all image fields in the list and create an image element linked to that field
        for chanceImageField in idevice.chanceImageFields:
            newImgElement = ImageElement(chanceImageField)
            self.chanceImageElements.append(newImgElement)

        self.wordElements = []
        self.hintElements = []
        #go through all of the word fields and hint fields and create an 
        for wordIndex, word in enumerate(idevice.wordTextFields):
            newWordElement = TextElement(word)
            self.wordElements.append(newWordElement)
            newHintElement = TextElement(idevice.hintTextFields[wordIndex])
            self.hintElements.append(newHintElement)

        #make an element for the alphabet
        self.alphabetElement = TextElement(idevice.alphabet)

        #element for the messages that are shown to the player
        self.wrongGuessTextElement = TextAreaElement(self.idevice.wrongGuessMessageField)
        self.lostLevelTextElement = TextAreaElement(self.idevice.lostLevelMessageField)
        self.levelPassedTextElement = TextAreaElement(self.idevice.levelPasssedMessageField)
        self.gameWonTextElement = TextAreaElement(self.idevice.gameWonMessageField)
        
        self.letterButtonStyleElement = TextElement(self.idevice.letterButtonStyle)
        self.wrongLetterButtonStyleElement = TextElement(self.idevice.wrongLetterButtonStyle)
        self.rightLetterButtonStyleElement = TextElement(self.idevice.rightLetterButtonStyle)

        self.hintFieldStyleElement = TextElement(self.idevice.hintFieldStyle)
        self.wordAreaStyleElement = TextElement(self.idevice.wordAreaStyle)

        self.resetButtonTextElement = TextElement(self.idevice.resetButtonText)
        self.resetButtonStyleElement = TextElement(self.idevice.resetButtonStyle)
    def __init__(self, parent, idevice):
        """
        Initialize a new Block object
        """
        Block.__init__(self, parent, idevice)
        self.activityInstruc = idevice.activityInstruc
        self.answerInstruc   = idevice.answerInstruc

        # to compensate for the strange unpickling timing when objects are 
        # loaded from an elp, ensure that proper idevices are set:
        if idevice.activityTextArea.idevice is None: 
            idevice.activityTextArea.idevice = idevice
        if idevice.answerTextArea.idevice is None: 
            idevice.answerTextArea.idevice = idevice

        self.activityElement  = TextAreaElement(idevice.activityTextArea)
        self.answerElement    = TextAreaElement(idevice.answerTextArea)

        self.previewing        = False # In view or preview render

        if not hasattr(self.idevice,'undo'): 
            self.idevice.undo = True
    def __init__(self, index, idevice, question):
        """
        Initialize
        'index' is our number in the list of questions
        'idevice' is a case study idevice
        'question' is a exe.engine.casestudyidevice.Question instance
        """
        self.index = index
        self.id = "q" + unicode(index) + "b" + idevice.id
        self.idevice = idevice

        self.quesId = "quesQuestion" + unicode(index) + "b" + idevice.id
        self.feedbackId = "quesFeedback" + unicode(index) + "b" + idevice.id

        self.question = question
        # also split out each part for a separate TextAreaElement:

        # but first....
        # to compensate for the strange unpickling timing when objects are
        # loaded from an elp, ensure that proper idevices are set:
        if question.questionTextArea.idevice is None:
            question.questionTextArea.idevice = idevice
        if question.feedbackTextArea.idevice is None:
            question.feedbackTextArea.idevice = idevice

        dT = common.getExportDocType()
        sectionTag = "div"
        if dT == "HTML5":
            sectionTag = "section"
        question.questionTextArea.htmlTag = sectionTag

        self.question_question = TextAreaElement(question.questionTextArea)
        self.question_question.id = self.quesId

        question.feedbackTextArea.htmlTag = "div"

        self.question_feedback = Feedback2Element(question.feedbackTextArea)
        self.question_feedback.id = self.feedbackId
Beispiel #34
0
    def __init__(self, parent, idevice):
        """
        Pre-create our field ids
        """
        Block.__init__(self, parent, idevice)

        # to compensate for the strange unpickling timing when objects are
        # loaded from an elp, ensure that proper idevices are set:
        if idevice.instructionsForLearners.idevice is None:
            idevice.instructionsForLearners.idevice = idevice
        if idevice.content.idevice is None:
            idevice.content.idevice = idevice
        if idevice.feedback.idevice is None:
            idevice.feedback.idevice = idevice

        self.instructionElement = \
            TextAreaElement(idevice.instructionsForLearners)
        self.clozeElement = ClozeElement(idevice.content)
        self.feedbackElement = \
            TextAreaElement(idevice.feedback)
        self.previewing = False  # In view or preview render
        if not hasattr(self.idevice, 'undo'):
            self.idevice.undo = True
    def __init__(self, parent, idevice):
        """
        Initialize a new Block object
        """
        Block.__init__(self, parent, idevice)
        self.idevice           = idevice
        self.questionElements  = []

        # to compensate for the strange unpickling timing when objects are 
        # loaded from an elp, ensure that proper idevices are set:
        if idevice.storyTextArea.idevice is None: 
            idevice.storyTextArea.idevice = idevice
            
        dT = common.getExportDocType()
        sectionTag = "div"
        if dT == "HTML5":
            sectionTag = "section"
            
        idevice.storyTextArea.htmlTag = sectionTag
        idevice.storyTextArea.class_ = "block story"

        self.storyElement      = TextAreaElement(idevice.storyTextArea)

        self.questionInstruc   = idevice.questionInstruc
        self.storyInstruc      = idevice.storyInstruc
        self.feedbackInstruc   = idevice.feedbackInstruc
        self.previewing        = False # In view or preview render 

        if not hasattr(self.idevice,'undo'): 
            self.idevice.undo = True

        i = 0
        
        for question in idevice.questions:
            self.questionElements.append(QuestionElement(i, idevice, question))
            i += 1
Beispiel #36
0
    def __init__(self, index, question, questionId, option, idevice):
        """
        Initialize
        """
        self.index = index
        self.id = unicode(index) + "q" + questionId
        self.question = question
        self.questionId = questionId
        self.option = option
        self.answerId = "optionAnswer" + unicode(index) + "q" + questionId
        self.keyId = "key" + questionId
        self.idevice = idevice
        self.checked = False

        # to compensate for the strange unpickling timing when objects are
        # loaded from an elp, ensure that proper idevices are set:
        # (only applies to the image-embeddable ones, not FlashElement)
        if option.answerTextArea.idevice is None:
            option.answerTextArea.idevice = idevice
        self.answerElement = TextAreaElement(option.answerTextArea)
        self.answerElement.id = self.answerId

        if not hasattr(self.idevice, 'undo'):
            self.idevice.undo = True
Beispiel #37
0
    def __init__(self, field):
        Element.__init__(self, field)

        self.textElements = {}
        self.textAreaElements = {}

        for textFieldName, textFieldDetails in field.textFieldNames.iteritems(
        ):
            self.textElements[textFieldName] = TextElement(
                field.textFields[textFieldName])

        for textAreaFieldName, textAreaFieldDetails in field.textAreaFieldNames.iteritems(
        ):
            self.textAreaElements[textAreaFieldName] = TextAreaElement(
                field.textAreaFields[textAreaFieldName])
Beispiel #38
0
def field_engine_build_elements_on_block(fieldInfoDict, fieldDict, idevice):
    fieldCounter = 0
    elementDict = {}
    for fieldInfoKey, fieldInfoArr in fieldInfoDict.items():
        elementTypeName = fieldInfoArr[EXEFIELDINFO_TYPE]

        #check the field - if this is a new one or src code edit etc. then add this field...
        field_engine_check_field(fieldInfoKey, fieldInfoDict, fieldDict,
                                 idevice)
        newElement = ""
        if elementTypeName == 'image':
            newElement = ImageElement(fieldDict[fieldInfoKey])
        elif elementTypeName == 'text':
            newElement = TextElement(fieldDict[fieldInfoKey])
        elif elementTypeName == 'textarea':
            newElement = TextAreaElement(fieldDict[fieldInfoKey])
        elif elementTypeName == 'choice':
            newElement = ChoiceElement(fieldDict[fieldInfoKey])

        if newElement != "":
            elementDict[fieldInfoKey] = newElement

    return elementDict
Beispiel #39
0
    def __init__(self, parent, idevice):
        Block.__init__(self, parent, idevice)
        self.mainTextAreaElements = {}
        self.mainTextElements = {}
        self.clickableAreaElements = []
        self.questionOrderChoiceElement = ChoiceElement(
            idevice.questionOrderChoiceField)
        self.timerChoiceElement = ChoiceElement(idevice.timerChoiceField)
        self.titleElement = TextElement(idevice.titleField)

        for textAreaFieldName, textAreaFieldVals in idevice.textAreaFieldNames.iteritems(
        ):
            self.mainTextAreaElements[textAreaFieldName] = TextAreaElement(
                idevice.textAreaFields[textAreaFieldName])

        for textFieldName, textFieldVals in idevice.textFieldNames.iteritems():
            self.mainTextElements[textFieldName] = TextElement(
                idevice.textFields[textFieldName])

        for clickableAreaField in idevice.clickableAreaFields:
            newClickableElement = ClickInOrderClickableAreaElement(
                clickableAreaField)
            self.clickableAreaElements.append(newClickableElement)
Beispiel #40
0
class TrueFalseBlock(Block):
    """
    TrueFalseBlock can render and process TrueFalseIdevices as XHTML
    """
    def __init__(self, parent, idevice):
        """
        Initialize a new Block object
        """
        Block.__init__(self, parent, idevice)
        self.idevice = idevice
        self.questionElements = []
        self.questionInstruc = idevice.questionInstruc
        self.keyInstruc = idevice.keyInstruc
        self.feedbackInstruc = idevice.feedbackInstruc
        self.hintInstruc = idevice.hintInstruc

        # to compensate for the strange unpickling timing when objects are
        # loaded from an elp, ensure that proper idevices are set:
        if idevice.instructionsForLearners.idevice is None:
            idevice.instructionsForLearners.idevice = idevice
        self.instructionElement = \
            TextAreaElement(idevice.instructionsForLearners)

        if not hasattr(self.idevice, 'undo'):
            self.idevice.undo = True

        i = 0
        for question in idevice.questions:
            self.questionElements.append(TrueFalseElement(
                i, idevice, question))
            i += 1

    def process(self, request):
        """
        Process the request arguments from the web server
        """
        Block.process(self, request)

        is_cancel = common.requestHasCancel(request)

        self.instructionElement.process(request)

        if ("addQuestion" + unicode(self.id)) in request.args:
            self.idevice.addQuestion()
            self.idevice.edit = True
            # disable Undo once a question has been added:
            self.idevice.undo = False

        if "title"+self.id in request.args \
        and not is_cancel:
            self.idevice.title = request.args["title" + self.id][0]

        for element in self.questionElements:
            element.process(request)

        if ("action" in request.args and request.args["action"][0] == "done"
                or not self.idevice.edit):
            # remove the undo flag in order to reenable it next time:
            if hasattr(self.idevice, 'undo'):
                del self.idevice.undo

    def renderEdit(self, style):
        """
        Returns an XHTML string with the form element for editing this block
        """

        html = u"<div class=\"iDevice\"><br/>\n"
        html += common.textInput("title" + self.id, self.idevice.title)
        html += u"<br/><br/>\n"
        html += self.instructionElement.renderEdit()

        for element in self.questionElements:
            html += element.renderEdit()

        value = _(u"Add another question")
        html += common.submitButton("addQuestion" + unicode(self.id), value)
        html += u"<br /><br />" + self.renderEditButtons(
            undo=self.idevice.undo)
        html += u"</div>\n"

        return html

    def renderPreview(self, style):
        """
        Returns an XHTML string for previewing this block
        """
        html = u"<div class=\"iDevice "
        html += u"emphasis" + unicode(self.idevice.emphasis) + "\" "
        html += u"ondblclick=\"submitLink('edit'," + self.id + ", 0);\">\n"
        html += u'<img alt="" class="iDevice_icon" '
        html += u"src=\"/style/" + style + "/icon_" + self.idevice.icon + ".gif\" />\n"
        html += u"<span class=\"iDeviceTitle\"><strong>"
        html += self.idevice.title + "</strong></span>\n"
        html += u"<div class=\"iDevice_inner\">\n"
        html += self.instructionElement.renderPreview()

        for element in self.questionElements:
            html += element.renderQuestionPreview()
            html += element.renderFeedbackPreview()

        html += "</div>\n"
        html += self.renderViewButtons()
        html += "</div>\n"

        return html

    def renderView(self, style):
        """
        Returns an XHTML string for viewing this block
        """
        html = u'<script type="text/javascript" src="common.js"></script>\n'
        html += u'<script type="text/javascript" src="libot_drag.js"></script>'
        html += u"\n<div class=\"iDevice "
        html += u"emphasis" + unicode(self.idevice.emphasis) + "\">\n"
        html += u'<img alt="" class="iDevice_icon" '
        html += u"src=\"icon_" + self.idevice.icon + ".gif\" />\n"
        html += u"<span class=\"iDeviceTitle\"><strong>"
        html += self.idevice.title + "</strong></span>\n"
        html += u"<div class=\"iDevice_inner\">\n"
        html += self.instructionElement.renderView()

        for element in self.questionElements:
            html += "<div class=\"question\">\n"
            html += element.renderQuestionView()
            html += element.renderFeedbackView()
            html += "</div>\n"

        html += u"</div>\n"
        html += u"</div>\n"

        return html
Beispiel #41
0
class NotaBlock(Block):
    def __init__(self, parent, idevice):
        """
        Initialize a new Block object
        """
        Block.__init__(self, parent, idevice)
        self.commentInstruc = idevice.commentInstruc

        if idevice.commentTextArea.idevice is None:
            idevice.commentTextArea.idevice = idevice

        self.commentElement = TextAreaElement(idevice.commentTextArea)

        self.previewing = False  # In view or preview render

        if not hasattr(self.idevice, 'undo'):
            self.idevice.undo = True

    def process(self, request):
        """
        Process the request arguments from the web server
        """
        Block.process(self, request)

        is_cancel = common.requestHasCancel(request)

        if not is_cancel:
            self.commentElement.process(request)
            if "title" + self.id in request.args:
                self.idevice.title = request.args["title" + self.id][0]

    def renderEdit(self, style):
        """
        Returns an XHTML string with the form element for editing this block
        """
        html = "<div class=\"iDevice\"><br/>\n"
        html += common.textInput("title" + self.id, self.idevice.title)
        html += self.commentElement.renderEdit()
        html += "<br/>" + self.renderEditButtons()
        html += "</div>\n"
        return html

    def renderPreview(self, style):
        """ 
        Remembers if we're previewing or not, 
        then implicitly calls self.renderViewContent (via Block.renderPreview) 
        """

        self.previewing = True
        return self.renderNote()

    def renderView(self, style):
        """ 
        Remembers if we're previewing or not, 
        then implicitly calls self.renderViewContent (via Block.renderPreview) 
        """
        self.previewing = False
        return self.renderNote()

    def renderNote(self):
        """
        Returns an XHTML string for this block
        """
        html = u'<div class="classnote">\n'
        if self.commentElement.field.content:
            html += '<div class="notetitleex" onclick="jQuery(\'#fb%s\').toggle()" title="%s">' % (
                self.id, _(u"Show/Hide"))
        else:
            html += '<div class="notetitle">'
        html += '%s</div>' % self.idevice.title
        if self.commentElement.field.content:
            html += '<div id="fb%s" class="notearea">' % self.id

            if self.previewing:
                html += self.commentElement.renderPreview()
            else:
                html += self.commentElement.renderView()

            html += "</div>\n"
        if self.previewing:
            html += Block.renderViewButtons(self)
            html += "<a title=\"" + _(
                u"Delete all notes"
            ) + "\" href=\"#\" onclick=\"confirmThenSubmitLink('" + _(
                u"Would you delete all notes?"
            ) + "', '" + u'deleteallnotes' + "', '" + self.id + "', 1);\" style=\"float:right;margin-top:-20px;\"><img alt=\"" + _(
                u"Delete all notes"
            ) + "\" width=\"16\" height=\"16\" class=\"submit\" src=\"/images/stock-delete.png\"></a>"
        html += "</div>\n"

        return html
class MultimediaBlock(Block):
    """
    ImageWithTextBlock can render and process ImageWithTextIdevices as XHTML
    """

    name = 'MultimediaWithText'

    def __init__(self, parent, idevice):
        """
        Initialize
        """
        Block.__init__(self, parent, idevice)
        self.mediaElement = MultimediaElement(idevice.media)

        # to compensate for the strange unpickling timing when objects are
        # loaded from an elp, ensure that proper idevices are set:
        # (only applies to the image-embeddable ones, not MultimediaElement)
        if idevice.text.idevice is None:
            idevice.text.idevice = idevice
        self.textElement = TextAreaElement(idevice.text)

    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)

        if (u"action" not in request.args
                or request.args[u"action"][0] != u"delete"):
            self.mediaElement.process(request)
            self.textElement.process(request)

        if 'emphasis' + self.id in request.args:
            self.idevice.emphasis = int(request.args['emphasis' + self.id][0])

        if "float" + self.id in request.args:
            self.idevice.float = request.args["float" + self.id][0]

        if "title" + self.id in request.args:
            self.idevice.title = request.args["title" + self.id][0]

    def renderEdit(self, style):
        """
        Returns an XHTML string with the form elements for editing this block
        """
        log.debug("renderEdit")
        html = u"<div class=\"iDevice\">\n"
        html += common.textInput("title" + self.id,
                                 self.idevice.title) + '<br/><br/>'
        html += self.mediaElement.renderEdit()
        floatArr = [[_(u'Left'), 'left'], [_(u'Right'), 'right'],
                    [_(u'None'), 'none']]

        this_package = None
        if self.idevice is not None and self.idevice.parentNode is not None:
            this_package = self.idevice.parentNode.package
        html += common.formField('select', this_package, _("Align:"),
                                 "float" + self.id, '',
                                 self.idevice.alignInstruc, floatArr,
                                 self.idevice.float)
        #html += u'<div class="block">' #<b>%s</b></div>' % _(u"Caption:")
        #html += common.textInput("caption" + self.id, self.idevice.media.caption)
        #html += common.elementInstruc(self.idevice.media.captionInstruc)
        html += "<br/>" + self.textElement.renderEdit()
        emphasisValues = [(_(u"No emphasis"), Idevice.NoEmphasis),
                          (_(u"Some emphasis"), Idevice.SomeEmphasis)]

        html += common.formField(
            'select',
            this_package,
            _('Emphasis'),
            'emphasis',
            self.id,
            '',  # TODO: Instructions
            emphasisValues,
            self.idevice.emphasis)
        html += self.renderEditButtons()
        html += u"</div>\n"
        return html

    def renderPreview(self, style):
        """
        Returns an XHTML string for previewing this block
        """
        log.debug("renderPreview")
        html = u"\n<!-- MP3 iDevice -->\n"
        html += u"<div class=\"iDevice "
        html += u"emphasis" + unicode(self.idevice.emphasis) + "\" "
        html += "ondblclick=\"submitLink('edit'," + self.id + ", 0);\">\n"
        if self.idevice.emphasis != Idevice.NoEmphasis:
            if self.idevice.icon:
                html += u'<img alt="idevice icon" class="iDevice_icon" '
                html += u" src=\"/style/" + style
                html += "/icon_" + self.idevice.icon + ".gif\"/>\n"
            html += u"<span class=\"iDeviceTitle\">"
            html += self.idevice.title
            html += u"</span>\n"
        html += u"<div class=\"iDevice_inner\"> "
        html += u"<div class=\"media\">\n"
        html += self.mediaElement.renderPreview() + "</div>\n"
        # html += u"<br />" + self.idevice.media.caption + "</div>\n"
        html += self.textElement.renderPreview()
        html += u"<br/>\n"
        html += u"<div style=\"clear:both;\">"
        html += u"</div></div>\n"
        html += self.renderViewButtons()
        html += u"</div>\n"
        return html

    def renderView(self, style):
        """
        Returns an XHTML string for viewing this block
        """
        log.debug("renderView")
        html = u"\n<!-- MP3 iDevice -->\n"
        html += u"<div class=\"iDevice "
        html += u"emphasis" + unicode(self.idevice.emphasis) + "\">\n"
        if self.idevice.emphasis != Idevice.NoEmphasis:
            if self.idevice.icon:
                html += u'<img alt="idevice icon" class="iDevice_icon" '
                html += u' src="icon_' + self.idevice.icon + '.gif"/>\n'
            html += u"<span class=\"iDeviceTitle\">"
            html += self.idevice.title
            html += u"</span>\n"
        html += u"<div class=\"iDevice_inner\"> "
        html += u"<div class=\"media\">\n" + "</div>"
        html += self.mediaElement.renderView()
        # html += u"<br/>" + self.idevice.media.caption + "</div>"
        html += self.textElement.renderView()
        html += u"<div style=\"clear:both;\">"
        html += u"</div></div>\n"
        html += u"</div>\n"
        return html
class ReflectionBlock(Block):
    """
    ReflectionBlock can render and process ReflectionIdevices as XHTML
    """
    def __init__(self, parent, idevice):
        """
        Initialize a new Block object
        """
        Block.__init__(self, parent, idevice)
        self.activityInstruc = idevice.activityInstruc
        self.answerInstruc   = idevice.answerInstruc

        # to compensate for the strange unpickling timing when objects are 
        # loaded from an elp, ensure that proper idevices are set:
        if idevice.activityTextArea.idevice is None: 
            idevice.activityTextArea.idevice = idevice
        if idevice.answerTextArea.idevice is None: 
            idevice.answerTextArea.idevice = idevice

        self.activityElement  = TextAreaElement(idevice.activityTextArea)
        self.answerElement    = TextAreaElement(idevice.answerTextArea)

        self.previewing        = False # In view or preview render

        if not hasattr(self.idevice,'undo'): 
            self.idevice.undo = True


    def process(self, request):
        """
        Process the request arguments from the web server
        """
        Block.process(self, request)

        is_cancel = common.requestHasCancel(request)

        if not is_cancel:
            self.activityElement.process(request)
            self.answerElement.process(request)
            if "title"+self.id in request.args:
                self.idevice.title = request.args["title"+self.id][0]
        

    def renderEdit(self, style):
        """
        Returns an XHTML string with the form element for editing this block
        """
        html  = "<div class=\"iDevice\"><br/>\n"
        html += common.textInput("title"+self.id, self.idevice.title)
        html += self.activityElement.renderEdit()
        html += self.answerElement.renderEdit()
        html += "<br/>" + self.renderEditButtons()
        html += "</div>\n"
        return html

    def renderPreview(self, style):
        """ 
        Remembers if we're previewing or not, 
        then implicitly calls self.renderViewContent (via Block.renderPreview) 
        """ 
        self.previewing = True 
        return Block.renderPreview(self, style)

    def renderView(self, style): 
        """ 
        Remembers if we're previewing or not, 
        then implicitly calls self.renderViewContent (via Block.renderPreview) 
        """ 
        self.previewing = False 
        return Block.renderView(self, style)


    def renderViewContent(self):
        """
        Returns an XHTML string for this block
        """
        html  = u'<script type="text/javascript" src="common.js"></script>\n'
        html += u'<div class="iDevice_inner">\n'
    
        if self.previewing: 
            html += self.activityElement.renderPreview()
        else:
            html += self.activityElement.renderView()

        html += '<div id="view%s" style="display:block;">' % self.id
        html += common.feedbackButton("btnshow"+self.id, _(u"Click here"),
                    onclick="showAnswer('%s',1)" % self.id)
        html += '</div>\n' 
        html += '<div id="hide%s" style="display:none;">' % self.id
        html += common.feedbackButton("btnshow"+self.id, _(u"Hide"),
                    onclick="showAnswer('%s',0)" % self.id)
        html += '</div>\n'
        html += '<div id="s%s" class="feedback" style=" ' % self.id
        html += 'display: none;">'

        if self.previewing: 
            html += self.answerElement.renderPreview()
        else:
            html += self.answerElement.renderView()

        html += "</div>\n"
        html += "</div>\n"
        return html
class FreeTextfpdBlock(Block):
    """
    FreeTextBlock can render and process FreeTextIdevices as XHTML
    GenericBlock will replace it..... one day
    """
    def __init__(self, parent, idevice):
        Block.__init__(self, parent, idevice)
        if idevice.content.idevice is None:
            # due to the loading process's timing, idevice wasn't yet set;
            # set it here for the TextAreaElement's tinyMCE editor
            idevice.content.idevice = idevice

        self.contentElement = TextAreaElement(idevice.content)
        self.contentElement.height = 250
        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
        """
        is_cancel = common.requestHasCancel(request)

        if is_cancel:
            self.idevice.edit = False
            # but double-check for first-edits, and ensure proper attributes:
            if not hasattr(self.idevice.content, 'content_w_resourcePaths'):
                self.idevice.content.content_w_resourcePaths = ""
            if not hasattr(self.idevice.content, 'content_wo_resourcePaths'):
                self.idevice.content.content_wo_resourcePaths = ""
            return

        Block.process(self, request)

        if (u"action" not in request.args
                or request.args[u"action"][0] != u"delete"):
            content = self.contentElement.process(request)
            if content:
                self.idevice.content = content

    def renderEdit(self, style):
        """
        Returns an XHTML string with the form element for editing this block
        """
        html = u"<div>\n"
        html += self.contentElement.renderEdit()
        html += self.renderEditButtons()
        html += u"</div>\n"
        return html

    def renderPreview(self, style):
        """
        Returns an XHTML string for previewing this block
        """
        html = u"<div class=\"iDevice "
        html += u"emphasis" + unicode(self.idevice.emphasis) + "\" "
        html += u"ondblclick=\"submitLink('edit'," + self.id + ", 0);\">\n"
        html += self.contentElement.renderPreview()
        html += self.renderViewButtons()
        html += "</div>\n"
        return html

    def renderView(self, style):
        """
        Returns an XHTML string for viewing this block
        """
        html = u"<div class=\"iDevice "
        html += u"emphasis" + unicode(self.idevice.emphasis) + "\">\n"
        html += self.contentElement.renderView()
        html += u"</div>\n"
        return html
Beispiel #45
0
class ImageMagnifierBlock(Block):
    """
    ImageMagnifierBlock can render and process ImageMagnifierIdevices as XHTML
    """

    name = 'imageManifier'

    def __init__(self, parent, idevice):
        """
        Initialize
        """
        Block.__init__(self, parent, idevice)
        self.imageMagnifierElement = MagnifierElement(idevice.imageMagnifier)

        # to compensate for the strange unpickling timing when objects are
        # loaded from an elp, ensure that proper idevices are set:
        # (only applies to the image-embeddable ones, not MagnifierElement)
        if idevice.text.idevice is None:
            idevice.text.idevice = idevice
        self.textElement = TextAreaElement(idevice.text)

        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 (u"action" not in request.args or
            (request.args[u"action"][0] != u"delete" and not is_cancel)):
            self.imageMagnifierElement.process(request)
            self.textElement.process(request)

        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 "float"+self.id in request.args \
        and not is_cancel:
            self.idevice.float = request.args["float" + self.id][0]

        if "caption"+self.id in request.args \
        and not is_cancel:
            self.idevice.caption = request.args["caption" + self.id][0]

        if "glass"+self.id in request.args \
        and not is_cancel:
            self.idevice.imageMagnifier.glassSize = \
                request.args["glass"+self.id][0]

        if "initial"+self.id in request.args \
        and not is_cancel:
            self.idevice.imageMagnifier.initialZSize = \
                request.args["initial"+self.id][0]

        if "maxZoom"+self.id in request.args \
        and not is_cancel:
            self.idevice.imageMagnifier.maxZSize = \
                request.args["maxZoom"+self.id][0]

    def renderEdit(self, style):
        """
        Returns an XHTML string with the form elements for editing this block
        """
        log.debug("renderEdit")
        floatArr = [[_(u'Left'), 'left'], [_(u'Right'), 'right'],
                    [_(u'None'), 'none']]
        html = u"<div class=\"iDevice\">\n"

        # Caption
        html += '<div class="block">'
        html += u"<strong>%s</strong>" % _(u"Caption:")
        html += common.elementInstruc(self.idevice.captionInstruc)
        html += '</div>'
        html += '<div class="block">'
        html += common.textInput("caption" + self.id, self.idevice.caption)
        html += '</div>'

        # Text
        html += '<div class="block">'
        html += self.textElement.renderEdit()
        html += '</div>'

        # Image
        html += self.imageMagnifierElement.renderEdit()

        this_package = None
        if self.idevice is not None and self.idevice.parentNode is not None:
            this_package = self.idevice.parentNode.package

        # Align
        html += common.formField('select', this_package, _("Align:"),
                                 "float" + self.id, '',
                                 self.idevice.alignInstruc, floatArr,
                                 self.idevice.float)

        # Initial and Max Zoom opts
        zoomOpts = []
        for i in range(100, 201, 10):
            zoomOpts.append(('%d%%' % (i), str(i)))

        # Initial Zoom Size
        selection = self.idevice.imageMagnifier.initialZSize
        html += common.formField('select', this_package, _(u"Initial Zoom"),
                                 "initial" + self.id, '',
                                 self.idevice.initialZoomInstruc, zoomOpts,
                                 selection)

        # Maximum Zoom
        selection = self.idevice.imageMagnifier.maxZSize
        html += common.formField('select', this_package, _(u"Maximum zoom"),
                                 "maxZoom" + self.id, '',
                                 self.idevice.maxZoomInstruc, zoomOpts,
                                 selection)

        # Size of Magnifying Glass
        glassSizeArr = [
            [_(u'Small'), '1'],
            [_(u'Medium'), '2'],
            [_(u'Large'), '3'],
            [_(u'Extra large'), '4'],
        ]
        html += common.formField('select', this_package,
                                 _(u"Size of magnifying glass: "),
                                 "glass" + self.id, '',
                                 self.idevice.glassSizeInstruc, glassSizeArr,
                                 self.idevice.imageMagnifier.glassSize)

        html += self.renderEditButtons(undo=self.idevice.undo)
        html += u"</div>\n"
        return html

    def renderPreview(self, style):
        """
        Returns an XHTML string for previewing this block
        """
        log.debug("renderPreview")
        html = u"\n<!-- image with text iDevice -->\n"
        html += u"<div class=\"iDevice "
        html += u"emphasis" + unicode(self.idevice.emphasis) + "\" "
        html += "ondblclick=\"submitLink('edit'," + self.id + ", 0);\">\n"
        html += u"  <div class=\"image_text\" style=\""
        html += u"width:" + str(self.idevice.imageMagnifier.width) + "px; "
        html += u"float:%s;\">\n" % self.idevice.float
        html += u"    <div class=\"image\">\n"
        html += self.imageMagnifierElement.renderPreview()
        html += u"" + self.idevice.caption
        html += u"    </div> <!-- class=\"image\" -->\n"
        html += u"  </div> <!-- class=\"image_text\" -->\n"
        text = self.textElement.renderPreview()
        if text:
            html += text
        else:
            html += '&nbsp;'
        html += u'\n<div style="clear:both;height:1px;overflow:hidden;"></div>\n'
        html += self.renderViewButtons()
        html += u"</div> <!-- class=\"iDevice emphasisX\" -->\n"
        return html

    def renderView(self, style):
        """
        Returns an XHTML string for viewing this block
        """
        log.debug("renderView")
        html = u"\n<!-- image with text iDevice -->\n"
        html += u"<div class=\"iDevice "
        html += u"emphasis" + unicode(self.idevice.emphasis) + "\">\n"
        html += u"  <div class=\"image_text\" style=\""
        html += u"width:" + str(self.idevice.imageMagnifier.width) + "px; "
        html += u"float:%s;\">\n" % self.idevice.float
        html += u"    <div class=\"image\">\n"
        html += self.imageMagnifierElement.renderView()
        html += u"    <br/>" + self.idevice.caption
        html += u"    </div> <!-- class=\"image\" -->\n"
        html += u"  </div> <!-- class=\"image_text\" -->\n"
        text = self.textElement.renderView()
        if text:
            html += text
        else:
            html += '&nbsp;'
        html += u'\n<div style="clear:both;height:1px;overflow:hidden;"></div>\n'
        html += u"</div> <!-- class=\"iDevice emphasisX\" -->\n"
        return html
Beispiel #46
0
class TestquestionElement(object):
    """
    TestQuestionElement is responsible for a block of question.  
    Used by QuizTestBlock
    == SCORM Quiz Testquestion, 
    pretty much the same as MultiSelect's SelectquestionElement
    """
    def __init__(self, index, idevice, question):
        """
        Initialize
        """
        self.index      = index
        self.id         = unicode(index) + "b" + idevice.id        
        self.idevice    = idevice

        # to compensate for the strange unpickling timing when objects are 
        # loaded from an elp, ensure that proper idevices are set:
        if question.questionTextArea.idevice is None: 
            question.questionTextArea.idevice = idevice
        self.questionElement = TextAreaElement(question.questionTextArea)
        self.question   = question

        self.questionId = "question"+self.id
        self.questionElement.id = self.questionId

        self.options    = []
        self.keyId      = "key" + self.id
        i = 0
        for option in question.options:
            self.options.append(TestoptionElement(i,
                                                  question, 
                                                  self.id, 
                                                  option,
                                                  idevice))
            i += 1

    def process(self, request):
        """
        Process the request arguments from the web server
        """
        log.info("process " + repr(request.args))
        if self.questionId in request.args: 
            self.questionElement.process(request)
            
        if ("addOption"+unicode(self.id)) in request.args: 
            self.question.addOption()
            self.idevice.edit = True
            # disable Undo once an option has been added: 
            self.idevice.undo = False
            
        if "action" in request.args and request.args["action"][0] == self.id:
            # before deleting the question object, remove any internal anchors:
            for q_field in self.question.getRichTextFields():
                 q_field.ReplaceAllInternalAnchorsLinks()  
                 q_field.RemoveAllInternalLinks()  
            self.idevice.questions.remove(self.question)
            # disable Undo once a question has been deleted: 
            self.idevice.undo = False

        for element in self.options:
            element.process(request)


    def renderEdit(self):
        """
        Returns an XHTML string with the form element for editing this element
        """
        html  = u"<div class=\"iDevice\">\n"
        html += common.submitImage(self.id, self.idevice.id,  
                "/images/stock-cancel.png", 
                _("Delete question")) 
        html += self.questionElement.renderEdit()

        html += u"<table width =\"100%%\">"
        html += u"<thead>"
        html += u"<tr>"
        html += u"<th>%s " % _("Options")
        html += common.elementInstruc(self.question.optionInstruc)
        html += u"</th>"
        html += u"</tr>"
        html += u"</thead>"
        html += u"<tbody>"

        for element in self.options:
            html += element.renderEdit() 
            
        html += u"</tbody>"
        html += u"</table>\n"
        value = _(u"Add another Option")    
        html += common.submitButton("addOption"+unicode(self.id), value)
        html += u"<br />"
        html += u"</div>\n"

        return html

    
    def renderPreview(self):
        """
        Returns an XHTML string for previewing this element
        """
        return self.renderView(preview=True)

    def renderView(self, preview=False):
        """
        Returns an XHTML string for viewing this element
        """
        html  = u""

        html += "<div class=\"question\">\n"
        if preview: 
            html += self.questionElement.renderPreview()
        else:
            html += self.questionElement.renderView()
        html += "<br/>\n"

        html += "<table>"
        for element in self.options:
            if preview: 
                html += element.renderPreview()      
            else:
                html += element.renderView()      
        html += "</table>"   
        html += "</div>\n"
        
        return html
    
    
    def getCorrectAns(self):
        """
        return the correct answer for the question
        """
        return self.question.correctAns

    
    def getNumOption(self):
        """
        return the number of options
        """
        return len(self.question.options)
Beispiel #47
0
class FlashWithTextBlock(Block):
    """
    FlashWithTextBlock can render and process FlashWithTextIdevices as XHTML
    """

    name = 'flashWithText'

    def __init__(self, parent, idevice):
        """
        Initialize
        """
        Block.__init__(self, parent, idevice)
        self.flashElement = FlashElement(idevice.flash)

        # to compensate for the strange unpickling timing when objects are
        # loaded from an elp, ensure that proper idevices are set:
        # (only applies to the image-embeddable ones, not FlashElement)
        if idevice.text.idevice is None:
            idevice.text.idevice = idevice
        self.textElement = TextAreaElement(idevice.text)

    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)

        if (u"action" not in request.args
                or request.args[u"action"][0] != u"delete"):
            self.flashElement.process(request)
            self.textElement.process(request)

        if "float" + self.id in request.args:
            self.idevice.float = request.args["float" + self.id][0]

        if "caption" + self.id in request.args:
            self.idevice.caption = request.args["caption" + self.id][0]

    def renderEdit(self, style):
        """
        Returns an XHTML string with the form elements for editing this block
        """
        log.debug("renderEdit")
        html = u"<div class=\"iDevice\">\n"
        html += self.flashElement.renderEdit()
        floatArr = [[_(u'Left'), 'left'], [_(u'Right'), 'right'],
                    [_(u'None'), 'none']]

        this_package = None
        if self.idevice is not None and self.idevice.parentNode is not None:
            this_package = self.idevice.parentNode.package
        html += common.formField('select',
                                 this_package,
                                 _("Align:"),
                                 "float" + self.id,
                                 options=floatArr,
                                 selection=self.idevice.float)
        html += u"\n"
        html += u"<b>%s </b>" % _(u"Caption:")
        html += common.textInput("caption" + self.id, self.idevice.caption)
        html += common.elementInstruc(self.idevice.captionInstruc)
        html += "<br/>" + self.textElement.renderEdit()
        html += self.renderEditButtons()
        html += u"</div>\n"
        return html

    def renderPreview(self, style):
        """
        Returns an XHTML string for previewing this block
        """
        log.debug("renderPreview")
        html = u"\n<!-- flash with text iDevice -->\n"
        html = u"<div class=\"iDevice "
        html += u"emphasis" + unicode(self.idevice.emphasis) + "\" "
        html += "ondblclick=\"submitLink('edit'," + self.id + ", 0);\">\n"
        html += u"<div class=\"flash_text\" style=\""
        html += u"width:" + str(self.idevice.flash.width) + "px; "
        html += u"float:%s;\">\n" % self.idevice.float
        html += u"<div class=\"flash\">\n"
        html += self.flashElement.renderPreview()
        html += u"" + self.idevice.caption + "</div>"
        html += u"</div>\n"
        html += self.textElement.renderPreview()
        html += u"<br/>\n"
        html += u"<div style=\"clear:both;\">"
        html += u"</div>\n"
        html += self.renderViewButtons()
        html += u"</div>\n"
        return html

    def renderView(self, style):
        """
        Returns an XHTML string for viewing this block
        """
        log.debug("renderView")
        html = u"\n<!-- Flash with text iDevice -->\n"
        html += u"<div class=\"iDevice "
        html += u"emphasis" + unicode(self.idevice.emphasis) + "\">\n"
        html += u"<div class=\"flash_text\" style=\""
        html += u"width:" + str(self.idevice.flash.width) + "px; "
        html += u"float:%s;\">\n" % self.idevice.float
        html += u"<div class=\"flash\">\n"
        html += self.flashElement.renderView()
        html += u"<br/>" + self.idevice.caption + "</div>"
        html += u"</div>\n"
        html += self.textElement.renderView()
        html += u"<div style=\"clear:both;\">"
        html += u"</div>\n"
        html += u"</div><br/>\n"
        return html
Beispiel #48
0
class WikipediaBlock(Block):
    """
    WikipediaBlock can render and process WikipediaIdevices as XHTML
    """
    def __init__(self, parent, idevice):
        """
        Initialize
        """
        Block.__init__(self, parent, idevice)

        # to compensate for the strange unpickling timing when objects are
        # loaded from an elp, ensure that proper idevices are set:
        if idevice.article.idevice is None:
            idevice.article.idevice = idevice
        self.articleElement = TextAreaElement(idevice.article)
        self.articleElement.height = 300
        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))

        is_cancel = common.requestHasCancel(request)

        if 'emphasis'+self.id in request.args \
        and not is_cancel:
            self.idevice.emphasis = int(request.args['emphasis' + self.id][0])
            # disable Undo once an emphasis has changed:
            self.idevice.undo = False

        if 'ssite'+self.id in request.args \
        and not is_cancel:
            self.idevice.site = request.args['ssite' + self.id][0]

        if 'ownUrl'+self.id in request.args \
        and not is_cancel:
            self.idevice.ownUrl = request.args['ownUrl' + self.id][0]

        if 'title'+self.id in request.args \
        and not is_cancel:
            self.idevice.title = request.args['title' + self.id][0]

        if ("object" in request.args
                and request.args["object"][0] == "site" + self.id):
            pass
        elif 'loadWikipedia' + self.id in request.args:
            # If they've hit "load" instead of "the tick"
            self.idevice.loadArticle(request.args['article'][0])
            # disable Undo once an article has been loaded:
            self.idevice.undo = False
        else:
            # If they hit "the tick" instead of "load"
            Block.process(self, request)
            if (u"action" not in request.args \
            or request.args[u"action"][0] != u"delete"):
                # If the text has been changed
                self.articleElement.process(request)
            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

    def renderEdit(self, style):
        """
        Returns an XHTML string with the form elements for editing this block
        """
        log.debug("renderEdit")

        html = u"<div class=\"iDevice\"><br/>\n"
        html += common.textInput("title" + self.id,
                                 self.idevice.title) + "<br/><br/>"

        sites = [
            (_(u"English Wikipedia Article"), "http://en.wikipedia.org/wiki/"),
            (_(u"Basque Wikipedia Article"), "http://eu.wikipedia.org/wiki/"),
            (_(u"Catalan Wikipedia Article"), "http://ca.wikipedia.org/wiki/"),
            (_(u"Chinese Wikipedia Article"), "http://zh.wikipedia.org/wiki/"),
            (_(u"Dutch Wikipedia Article"), "http://nl.wikipedia.org/wiki/"),
            (_(u"French Wikipedia Article"), "http://fr.wikipedia.org/wiki/"),
            (_(u"German Wikipedia Article"), "http://de.wikipedia.org/wiki/"),
            (_(u"Galician Wikipedia Article"),
             "http://gl.wikipedia.org/wiki/"),
            (_(u"Greek Wikipedia Article"), "http://el.wikipedia.org/wiki/"),
            (_(u"Italian Wikipedia Article"), "http://it.wikipedia.org/wiki/"),
            (_(u"Japanese Wikipedia Article"),
             "http://ja.wikipedia.org/wiki/"),
            (_(u"Magyar Wikipedia Article"), "http://hu.wikipedia.org/wiki/"),
            (_(u"Polish Wikipedia Article"), "http://pl.wikipedia.org/wiki/"),
            (_(u"Portugese Wikipedia Article"),
             "http://pt.wikipedia.org/wiki/"),
            (_(u"Slovenian Wikipedia Article"),
             "http://sl.wikipedia.org/wiki/"),
            (_(u"Spanish Wikipedia Article"), "http://es.wikipedia.org/wiki/"),
            (_(u"Swedish Wikipedia Article"), "http://sv.wikipedia.org/wiki/"),
            (_(u"Wikibooks Article"), "http://en.wikibooks.org/wiki/"),
            (_(u"Wikiversity"), "http://en.wikiversity.org/wiki/"),
            (_(u"Wiktionary"), "http://en.wiktionary.org/wiki/"),
            (_(u"Wikieducator Content"), "http://wikieducator.org/"),
            (_(u"Other"), "")
        ]

        this_package = None
        if self.idevice is not None and self.idevice.parentNode is not None:
            this_package = self.idevice.parentNode.package
        html += common.formField('select', this_package, _('Site'), 's',
                                 'site' + self.id, self.idevice.langInstruc,
                                 sites, self.idevice.site)

        url = "none"
        if self.idevice.site == "":
            url = "block"
        html += '<div style="display:%s"> %s: <br/>' % (url, _("Own site"))
        html += common.textInput("ownUrl" + self.id,
                                 self.idevice.ownUrl) + '<br/></div>'
        html += "<br/>"
        html += common.textInput("article", self.idevice.articleName)
        html += common.elementInstruc(self.idevice.searchInstruc)
        html += common.submitButton(u"loadWikipedia" + self.id, _(u"Load"))

        html += u"<br/>\n"
        html += self.articleElement.renderEdit()
        emphasisValues = [(_(u"No emphasis"), Idevice.NoEmphasis),
                          (_(u"Some emphasis"), Idevice.SomeEmphasis)]

        html += common.formField(
            'select',
            this_package,
            _('Emphasis'),
            'emphasis',
            self.id,
            '',  # TODO: Instructions
            emphasisValues,
            self.idevice.emphasis)

        html += self.renderEditButtons(undo=self.idevice.undo)
        html += u"</div>\n"
        return html

    def renderPreview(self, style):
        """
        Returns an XHTML string for previewing this block
        """
        log.debug("renderPreview")
        html = common.ideviceHeader(self, style, "preview")
        html += self.articleElement.renderPreview()
        html += common.ideviceFooter(self, style, "preview")
        return html

    def renderView(self, style):
        """
        Returns an XHTML string for viewing this block
        """
        log.debug("renderView")
        content = self.articleElement.renderView()
        # content = re.sub(r'src="resources/', 'src="', content)
        content = re.sub(r'src="http://127.0.0.1:\d+/newPackage.*/resources/',
                         'src="', content)
        content = re.sub(r'src="/newPackage.*/resources/', 'src="', content)
        content = re.sub(r'src=\'/newPackage.*/resources/', 'src="', content)
        content = re.sub(r'src=\"/newPackage.*/resources/', 'src="', content)
        html = common.ideviceHeader(self, style, "view")
        html += content
        html += common.ideviceFooter(self, style, "view")
        return html
Beispiel #49
0
class ListaBlock(Block):
    """

    """
    def __init__(self, parent, idevice):
        """
        Pre-create our field ids
        """
        Block.__init__(self, parent, idevice)
        
       
        # to compensate for the strange unpickling timing when objects are 
        # loaded from an elp, ensure that proper idevices are set:
        if idevice.instructionsForLearners.idevice is None: 
            idevice.instructionsForLearners.idevice = idevice
        if idevice.content.idevice is None: 
            idevice.content.idevice = idevice
        if idevice.feedback.idevice is None: 
            idevice.feedback.idevice = idevice
            
        dT = common.getExportDocType()
        sectionTag = "div"
        if dT == "HTML5":
            sectionTag = "section"
            
        idevice.instructionsForLearners.htmlTag = sectionTag
        idevice.instructionsForLearners.class_ = "block instructions"
        idevice.feedback.htmlTag = sectionTag            

        self.instructionElement = TextAreaElement(idevice.instructionsForLearners)
        self.instructionElement.field.content_w_resourcePaths = c_(self.instructionElement.field.content_w_resourcePaths)
        self.listaElement = ListaElement(idevice.content)
        self.feedbackElement = \
            TextAreaElement(idevice.feedback)
        self.previewing        = False # In view or preview render
        if not hasattr(self.idevice,'undo'): 
            self.idevice.undo = True

    def process(self, request):
        """
        Handles changes in the paragraph text from editing
        """
        is_cancel = common.requestHasCancel(request)

        if "title"+self.id in request.args \
        and not is_cancel:
            self.idevice.title = request.args["title"+self.id][0]
        object = request.args.get('object', [''])[0]
        action = request.args.get('action', [''])[0]
        self.instructionElement.process(request)
        self.listaElement.process(request)
        self.feedbackElement.process(request)
        Block.process(self, request)

    def renderEdit(self, style):
        """
        Renders a screen that allows the user to enter paragraph text and choose
        which words are hidden.
        """
        html = [
            u'<div class="iDevice">',
            u'<div class="block">',
            common.textInput("title"+self.id, self.idevice.title),
            u'</div>',
            self.instructionElement.renderEdit(),
            self.listaElement.renderEdit(),
            self.feedbackElement.renderEdit(),
            self.renderEditButtons(),
            u'</div>'
            ]
        return u'\n    '.join(html)
    
    def renderPreview(self, style):
        """ 
        Remembers if we're previewing or not, 
        then implicitly calls self.renderViewContent (via Block.renderPreview) 
        """ 
        self.previewing = True 
        return Block.renderPreview(self, style)

    def renderView(self, style):
        """ 
        Remembers if we're previewing or not, 
        then implicitly calls self.renderViewContent (via Block.renderPreview) 
        """ 
        self.previewing = False 
        return Block.renderView(self, style)

    def renderViewContent(self):
        """
        Returns an XHTML string for this block
        """
        # Only show feedback button if feedback is present
        if self.feedbackElement.field.content.strip():
            # Lista Idevice needs id of div for feedback content
            feedbackID = self.feedbackElement.id
            if self.previewing: 
                clozeContent = self.listaElement.renderPreview(feedbackID)
            else: 
                clozeContent = self.listaElement.renderView(feedbackID)
        else:
            if self.previewing: 
                clozeContent = self.listaElement.renderPreview()
            else:
                clozeContent = self.listaElement.renderView()
        instruction_html = ""
        if self.previewing: 
            instruction_html = self.instructionElement.renderPreview()
        else:
            instruction_html = self.instructionElement.renderView()
        html = [       
            instruction_html,
            clozeContent]
        if self.feedbackElement.field.content: 
            if self.previewing: 
                html.append(self.feedbackElement.renderPreview(False, 
                                                     class_="feedback"))
            else:
                html.append(self.feedbackElement.renderView(False, 
                                                     class_="feedback"))
        return u'\n'.join(html)

    def renderText(self): 
        
        """
        Returns an XHTML string for text file export.
        """
        
        if self.previewing: 
            html = '<p>' +  self.instructionElement.renderPreview() +'</p>'
        else:
            html = '<p>' +  self.instructionElement.renderView() +'</p>'
        html += '<p>' + self.listaElement.renderText() + '</p>'
        if self.feedbackElement.field.content:
            html += '<p>%s:</P>' % c_(u"Feedback") 
            if self.previewing: 
                html += '<p>' +self.feedbackElement.renderPreview(False, 
                                                        class_="feedback") 
                html += '</p>'
            else:
                html += '<p>' +self.feedbackElement.renderView(False, 
                                                        class_="feedback") 
                html += '</p>'
        html += self.listaElement.renderAnswers()
        return html
class FreeTextBlock(Block):
    """
    FreeTextBlock can render and process FreeTextIdevices as XHTML
    GenericBlock will replace it..... one day
    """
    def __init__(self, parent, idevice):
        Block.__init__(self, parent, idevice)
        if idevice.content.idevice is None:
            # due to the loading process's timing, idevice wasn't yet set;
            # set it here for the TextAreaElement's tinyMCE editor
            idevice.content.idevice = idevice

        self.contentElement = TextAreaElement(idevice.content)
        self.contentElement.height = 250
        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
        """
        is_cancel = common.requestHasCancel(request)

        if is_cancel:
            self.idevice.edit = False
            # but double-check for first-edits, and ensure proper attributes:
            if not hasattr(self.idevice.content, 'content_w_resourcePaths'):
                self.idevice.content.content_w_resourcePaths = ""
            if not hasattr(self.idevice.content, 'content_wo_resourcePaths'):
                self.idevice.content.content_wo_resourcePaths = ""
            return

        Block.process(self, request)

        if (u"action" not in request.args
                or request.args[u"action"][0] != u"delete"):
            content = self.contentElement.process(request)
            if content:
                self.idevice.content = content

    def renderEdit(self, style):
        """
        Returns an XHTML string with the form element for editing this block
        """
        html = u"<div style=\"position: relative\">\n"
        html += self.contentElement.renderEdit()
        html += self.renderEditButtons()
        html += u"</div>\n"
        return html

    def renderPreview(self, style):
        """
        Returns an XHTML string for previewing this block
        """
        if hasattr(self.idevice, 'parent'
                   ) and self.idevice.parent and not self.idevice.parent.edit:
            return u""
        html = common.ideviceHeader(self, style, "preview")
        html += self.contentElement.renderPreview()
        html += common.ideviceFooter(self, style, "preview")
        return html

    def renderView(self, style):
        """
        Returns an XHTML string for viewing this block
        """
        html = u"<div class=\"iDevice "
        html += u"emphasis" + unicode(self.idevice.emphasis) + "\">\n"
        html += self.contentElement.renderView()
        html += u"</div>\n"
        return html

    def renderXML(self, style):
        xml = u""
        """
        If we are effectively just one large image then make just an img tag and sound
        tag if appropriate.  If not output all the html 
        """

        xmlStr = self.contentElement.renderXML(None, "idevice",
                                               self.idevice.id)
        return xmlStr
class EjercicioresueltofpdBlock(Block):
    """
    FPD - CasestudyBlock can render and process CasestudyIdevices as XHTML
    """
    def __init__(self, parent, idevice):
        """
        Initialize a new Block object
        """
        Block.__init__(self, parent, idevice)
        self.idevice           = idevice
        self.questionElements  = []

        # to compensate for the strange unpickling timing when objects are 
        # loaded from an elp, ensure that proper idevices are set:
        if idevice.storyTextArea.idevice is None: 
            idevice.storyTextArea.idevice = idevice
            
        dT = common.getExportDocType()
        sectionTag = "div"
        if dT == "HTML5":
            sectionTag = "section"
            
        idevice.storyTextArea.htmlTag = sectionTag
        idevice.storyTextArea.class_ = "block story"

        self.storyElement      = TextAreaElement(idevice.storyTextArea)

        self.questionInstruc   = idevice.questionInstruc
        self.storyInstruc      = idevice.storyInstruc
        self.feedbackInstruc   = idevice.feedbackInstruc
        self.previewing        = False # In view or preview render 

        if not hasattr(self.idevice,'undo'): 
            self.idevice.undo = True

        i = 0
        
        for question in idevice.questions:
            self.questionElements.append(QuestionElement(i, idevice, question))
            i += 1


    def process(self, request):
        """
        Process the request arguments from the web server
        """
        Block.process(self, request)

        is_cancel = common.requestHasCancel(request)

        self.storyElement.process(request)
            
        if (u"addQuestion"+unicode(self.id)) in request.args: 
            self.idevice.addQuestion()
            self.idevice.edit = True
            # disable Undo once another activity has been added:
            self.idevice.undo = False

            
        if "title"+self.id in request.args \
        and not is_cancel:
            self.idevice.title = request.args["title"+self.id][0]
            
        if "action" in request.args and request.args[u"action"][0] != u"delete":
            for element in self.questionElements:
                element.process(request)
            if request.args[u"action"][0] == u'done':
                # remove the undo flag in order to reenable it next time:
                if hasattr(self.idevice,'undo'): 
                    del self.idevice.undo


    def renderEdit(self, style):
        """
        Returns an XHTML string with the form element for editing this block
        """
        self.previewing = True

        html  = u'<div class="iDevice"><br/>\n'

   # JRJ
	# Quitamos el prefijo "FPD -"
	# (let's remove the "FPD -" prefix)
	if self.idevice.title.find("FPD - ") == 0:
		self.idevice.title = x_(u"Translation")
        html += common.textInput("title"+self.id, self.idevice.title)
        html += self.storyElement.renderEdit()

        for element in self.questionElements:
            html += element.renderEdit() 
         
        html += u"</table>\n"
        value = _(u"Add another activity")    
        html += common.submitButton(u"addQuestion"+unicode(self.id), value)
        html += u"<br /><br />" + self.renderEditButtons(undo=self.idevice.undo)
        html += u"</div>\n"
        return html

    def renderView(self, style):
        """
        Remembers if we're previewing or not,
        then implicitly calls self.renderViewContent (via Block.renderView)
        """
        self.previewing = False
        return Block.renderView(self, style)
    
    def renderPreview(self, style):
        """
        Remembers if we're previewing or not,
        then implicitly calls self.renderViewContent (via Block.renderPreview)
        """
        self.previewing = True
        return Block.renderPreview(self, style)
    
    def renderViewContent(self):
        """
        Returns an XHTML string for this block
        """
        log.debug("renderViewContent called with previewing mode = " + str(self.previewing))

        html  = u""

        if self.previewing:
            html += self.storyElement.renderPreview()
            html + u"<br />\n"
            for element in self.questionElements:
                html += element.renderPreview()
        else:
            html += self.storyElement.renderView()
            html + u"<br />\n"
            for element in self.questionElements:
                html += element.renderView()

        return html
Beispiel #52
0
class OpinionElement(object):
    """
    TrueFalseElement is responsible for a block of question. 
    Used by TrueFalseBlock.
    """
    def __init__(self, index, idevice, question):
        """
        Initialize
        """
        self.index = index
        self.id = unicode(index) + "b" + idevice.id
        self.idevice = idevice

        self.question = question
        # also split out each part for a separate TextAreaElement:
        # but first...
        # to compensate for the strange unpickling timing when objects are
        # loaded from an elp, ensure that proper idevices are set:
        if question.questionTextArea.idevice is None:
            question.questionTextArea.idevice = idevice
        if question.feedbackTextArea.idevice is None:
            question.feedbackTextArea.idevice = idevice
        if question.hintTextArea.idevice is None:
            question.hintTextArea.idevice = idevice
        #
        self.question_question = TextAreaElement(question.questionTextArea)
        self.question_feedback = TextAreaElement(question.feedbackTextArea)
        self.question_hint = TextAreaElement(question.hintTextArea)

        # note, question.isCorrect is left as it was, and not split out.
        # because there are low-level mechanisms in place somewhere
        # with the radio buttons or ??? expecting that as such.

        self.questionId = "question" + unicode(index) + "b" + idevice.id
        self.question_question.id = self.questionId
        self.feedbackId = "feedback" + unicode(index) + "b" + idevice.id
        self.question_feedback.id = self.feedbackId
        self.hintId = "hint" + unicode(index) + "b" + idevice.id
        self.question_hint.id = self.hintId
        self.keyId = "Key" + unicode(index) + "b" + idevice.id

    def process(self, request):
        """
        Process arguments from the web server.  Return any which apply to this 
        element.
        """
        log.debug("process " + repr(request.args))

        is_cancel = common.requestHasCancel(request)

        if self.questionId in request.args \
        and not is_cancel:
            self.question_question.process(request)

        if self.hintId in request.args \
        and not is_cancel:
            self.question_hint.process(request)

        if self.keyId in request.args \
        and not is_cancel:
            if request.args[self.keyId][0] == "true":
                self.question.isCorrect = True
                log.debug("question " + repr(self.question.isCorrect))
            else:
                self.question.isCorrect = False

        if self.feedbackId in request.args \
        and not is_cancel:
            self.question_feedback.process(request)

        if "action" in request.args and request.args["action"][0] == self.id:
            # before deleting the question object, remove any internal anchors:
            for q_field in self.question.getRichTextFields():
                q_field.ReplaceAllInternalAnchorsLinks()
                q_field.RemoveAllInternalLinks()
            self.idevice.questions.remove(self.question)
            # disable Undo once a question has been deleted:
            self.idevice.undo = False

    def renderEdit(self):
        """
        Returns an XHTML string for editing this option element
        """

        html = self.question_question.renderEdit()

        #removed unnecessary elements kthamm 111028
        #html += _("True") + " "
        #html += common.option(self.keyId, self.question.isCorrect, "true")
        #html += _("False") + " "
        #html += common.option(self.keyId, not self.question.isCorrect, "false")

        #html += "<br/><br/>\n"

        #html += common.elementInstruc(self.idevice.keyInstruc)

        #html += self.question_hint.renderEdit()
        #end removed

        html += self.question_feedback.renderEdit()
        html += common.submitImage(self.id, self.idevice.id,
                                   "/images/stock-cancel.png",
                                   _("Delete question"))
        html += "<br/><br/>\n"
        return html

    def renderQuestionView(self):
        """
        Returns an XHTML string for viewing this question element
        """
        is_preview = 0
        html = self.renderQuestion(is_preview)

        #removed kthamm 111028
        #if self.question.hintTextArea.content.strip() != "":
        #html += u'<span '
        #html += u'style="background-image:url(\'panel-amusements.png\');">'
        #html += u'\n<a onmousedown="Javascript:updateCoords(event);'
        #html += u'showMe(\'%s\', 350, 100);" ' % self.hintId
        #html += u'style="cursor:help;align:center;vertical-align:middle;" '
        #html += u'title="%s" \n' % _(u"Hint")
        #html += u'href="javascript:void(0);">&nbsp;&nbsp;&nbsp;&nbsp;</a>'
        #html += u'</span>'
        ##html += u'<div id="'+self.hintId+'" ' //removed kthamm 111028
        ##html += u'style="display:none; z-index:99;">' //removed kthamm 111028
        #html += u'<div style="float:right;" >'
        #html += u'<img alt="%s" ' % _('Close')
        #html += u'src="stock-stop.png" title="%s"' % _('Close')
        #html += u" onmousedown=\"Javascript:hideMe();\"/></div>"
        #html += u'<div class="popupDivLabel">'
        #html += _(u"Hint")
        #html += u'</div>\n'
        #html += self.question_hint.renderView()
        #html += u"</div>\n"
        #end removed
        return html

    def renderQuestionPreview(self):
        #TODO merge renderQuestionView and renderQuestionPreview
        """
        Returns an XHTML string for previewing this question element
        """
        is_preview = 1
        html = self.renderQuestion(is_preview)
        html += " &nbsp;&nbsp;\n"

        #html += common.elementInstruc(self.question_hint.field.content,"panel-amusements.png", "Hint") //removed kthamm 111028
        return html

    def renderQuestion(self, is_preview):
        """
        Returns an XHTML string for viewing and previewing this question element
        """
        log.debug("renderPreview called in the form of renderQuestion")

        html = u"<br/><br/>"

        if is_preview:
            html += self.question_question.renderPreview() + "<br/>"
        else:
            html += self.question_question.renderView() + "<br/>"

        html += _("I agree") + " "
        html += self.__option(0, 2, "true") + " \n"
        html += _("I disagree") + " "
        html += self.__option(1, 2, "false") + "\n"

        return html

    def __option(self, index, length, true):
        """Add a option input"""
        html = u'<input type="radio" name="option%s" ' % self.id
        html += u'id="%s%s" ' % (true, self.id)
        html += u'onclick="getOptionFeedback(%d,%d,\'%s\',\'truefalse\')"/>' % (
            index, length, self.id)
        return html

    def renderFeedbackPreview(self):
        """
        Merely a front-end to renderFeedbackView(), setting preview mode.
        Note: this won't really matter all that much, since these won't yet
        show up in exported printouts, BUT the image paths will be correct.
        """
        return self.renderFeedbackView(is_preview=True)

    def renderFeedbackView(self, is_preview=False):
        """
        return xhtml string for display this option's feedback
        """
        feedbackStr1 = _(u"Correct!") + " "
        feedbackStr2 = _(u"Incorrect!") + " "

        # embed a score_representation as well, even==true,
        # so that Correct/Incorrect doesn't need to be un-translated
        # upon bursting from a CC export.
        # start off with a sorta random looking number:
        to_even1 = int(self.idevice.id) + 5
        if to_even1 % 2:
            # ensure that to_even1 is indeed even, correct:
            to_even1 += 1
        # and ensure that to_even2 is odd, incorrect:
        to_even2 = to_even1 + 1

        if not self.question.isCorrect:
            feedbackStr1, feedbackStr2 = feedbackStr2, feedbackStr1
            to_even1, to_even2 = to_even2, to_even1

        feedbackId1 = "0" + "b" + self.id
        feedbackId2 = "1" + "b" + self.id
        html = u''
        #html  = u'<div id="s%s" style="color: rgb(0, 51, 204);' % feedbackId1
        #html += u'display: none;" even_steven="%s">' % (str(to_even1))
        #html += feedbackStr1 + '</div>\n'
        #html += u'<div id="s%s" style="color: rgb(0, 51, 204);' % feedbackId2
        #html += u'display: none;" even_steven="%s">' % (str(to_even2))
        #html += feedbackStr2 + '</div>\n'
        html += u'<div id="sfbk%s" style="color: rgb(0, 51, 204);' % self.id
        html += u'display: none;">'
        if is_preview:
            html += self.question_feedback.renderPreview()
        else:
            html += self.question_feedback.renderView()
        html += u'</div>\n'

        return html
Beispiel #53
0
class TrueFalseElement(object):
    """
    TrueFalseElement is responsible for a block of question. 
    Used by TrueFalseBlock.
    """
    def __init__(self, index, idevice, question):
        """
        Initialize
        """
        self.index = index
        self.id = unicode(index) + "b" + idevice.id
        self.idevice = idevice

        self.question = question
        # also split out each part for a separate TextAreaElement:
        # but first...
        # to compensate for the strange unpickling timing when objects are
        # loaded from an elp, ensure that proper idevices are set:
        if question.questionTextArea.idevice is None:
            question.questionTextArea.idevice = idevice
        if question.feedbackTextArea.idevice is None:
            question.feedbackTextArea.idevice = idevice
        if question.hintTextArea.idevice is None:
            question.hintTextArea.idevice = idevice
        #
        self.question_question = TextAreaElement(question.questionTextArea)
        self.question_feedback = TextAreaElement(question.feedbackTextArea)
        self.question_hint = TextAreaElement(question.hintTextArea)

        # note, question.isCorrect is left as it was, and not split out.
        # because there are low-level mechanisms in place somewhere
        # with the radio buttons or ??? expecting that as such.

        self.questionId = "question" + unicode(index) + "b" + idevice.id
        self.question_question.id = self.questionId
        self.feedbackId = "feedback" + unicode(index) + "b" + idevice.id
        self.question_feedback.id = self.feedbackId
        self.hintId = "hint" + unicode(index) + "b" + idevice.id
        self.question_hint.id = self.hintId
        self.keyId = "Key" + unicode(index) + "b" + idevice.id

    def process(self, request):
        """
        Process arguments from the web server.  Return any which apply to this 
        element.
        """
        log.debug("process " + repr(request.args))

        is_cancel = common.requestHasCancel(request)

        if self.questionId in request.args \
        and not is_cancel:
            self.question_question.process(request)

        if self.hintId in request.args \
        and not is_cancel:
            self.question_hint.process(request)

        if self.keyId in request.args \
        and not is_cancel:
            if request.args[self.keyId][0] == "true":
                self.question.isCorrect = True
                log.debug("question " + repr(self.question.isCorrect))
            else:
                self.question.isCorrect = False

        if self.feedbackId in request.args \
        and not is_cancel:
            self.question_feedback.process(request)

        if "action" in request.args and request.args["action"][0] == self.id:
            # before deleting the question object, remove any internal anchors:
            for q_field in self.question.getRichTextFields():
                q_field.ReplaceAllInternalAnchorsLinks()
                q_field.RemoveAllInternalLinks()
            self.idevice.questions.remove(self.question)
            # disable Undo once a question has been deleted:
            self.idevice.undo = False

    def renderEdit(self):
        """
        Returns an XHTML string for editing this option element
        """

        html = self.question_question.renderEdit()

        html += _("True") + " "
        html += common.option(self.keyId, self.question.isCorrect, "true")
        html += _("False") + " "
        html += common.option(self.keyId, not self.question.isCorrect, "false")

        html += "<br/><br/>\n"

        html += common.elementInstruc(self.idevice.keyInstruc)

        html += self.question_feedback.renderEdit()
        html += self.question_hint.renderEdit()

        html += common.submitImage(self.id, self.idevice.id,
                                   "/images/stock-cancel.png",
                                   _("Delete question"))
        html += "<br/><br/>\n"
        return html

    def renderQuestionView(self):
        """
        Returns an XHTML string for viewing this question element
        """
        is_preview = 0
        html = self.renderQuestion(is_preview)
        return html

    """
    Will render this for XML - is actually designed to change this into
    an MCQ (because I'm lazy at the moment to make more J2ME)
    """

    def renderQuestionXML(self):
        questionFormatted = self.question_question.renderView()
        questionFormatted = questionFormatted.replace("align=\"right\"", "")
        xml = u"<question><![CDATA["
        xml += questionFormatted
        xml += "]]>"

        options = [True, False]

        for currentOption in options:
            answerCorrectStr = "false"
            if currentOption == self.question.isCorrect:
                answerCorrectStr = "true"

            xml += "<answer iscorrect='%s'><![CDATA[\n" % answerCorrectStr
            xml += "<span class='exe_tfmob'>" + str(currentOption) + "</span>"
            xml += "]]><feedback>\n<![CDATA["
            if currentOption == self.question.isCorrect:
                #this is a correct answer
                xml += "<img src='icon_mobile_stockcorrect.png'/>"
            else:
                xml += "<img src='icon_mobile_stockwrong.png'/>"

            xml += "]]></feedback>\n"
            xml += "</answer>\n"

        xml += "</question>\n"

        return xml

    def renderQuestionPreview(self):
        #TODO merge renderQuestionView and renderQuestionPreview
        """
        Returns an XHTML string for previewing this question element
        """
        is_preview = 1
        html = self.renderQuestion(is_preview)
        return html

    def renderQuestion(self, is_preview):
        """
        Returns an XHTML string for viewing and previewing this question element
        """
        log.debug("renderPreview called in the form of renderQuestion")

        lb = "\n"  #Line breaks
        dT = common.getExportDocType()
        titleTag = "h3"
        if dT == "HTML5":
            titleTag = "h1"

        if is_preview:
            html = '<' + titleTag + ' class="js-sr-av">' + c_(
                "Question") + ' ' + str(self.index +
                                        1) + '</' + titleTag + '>' + lb
            html += self.question_question.renderPreview()
            if self.question_hint.field.content:
                html += common.ideviceHint(self.question_hint.field.content,
                                           "preview", "h4")
        else:
            html = '<form name="true-false-form-' + self.id + '" action="#" class="activity-form">' + lb
            html += '<' + titleTag + ' class="js-sr-av">' + c_(
                "Question") + ' ' + str(self.index +
                                        1) + '</' + titleTag + '>' + lb
            html += self.question_question.renderView()
            if self.question_hint.field.content:
                html += common.ideviceHint(self.question_hint.field.content,
                                           "view", "h4")

        html += '<p class="iDevice_answer js-required">' + lb
        html += '<label for="true' + self.id + '">'
        html += self.__option(0, 2, "true") + ' '
        html += c_("True")
        html += '</label> ' + lb
        html += '<label for="false' + self.id + '">'
        html += self.__option(1, 2, "false") + ' '
        html += c_("False")
        html += '</label>' + lb
        html += '</p>' + lb

        if not is_preview:
            html += '</form>' + lb

        return html

    def __option(self, index, length, true):
        """Add a option input"""
        html = '<input type="radio" name="option%s" ' % self.id
        html += 'id="%s%s" ' % (true, self.id)
        html += 'class="exe-radio-option exe-radio-option-%d-%d-%s-truefalse" />' % (
            index, length, self.id)
        return html

    def renderFeedbackPreview(self):
        """
        Merely a front-end to renderFeedbackView(), setting preview mode.
        Note: this won't really matter all that much, since these won't yet
        show up in exported printouts, BUT the image paths will be correct.
        """
        return self.renderFeedbackView(is_preview=True)

    def renderFeedbackView(self, is_preview=False):
        """
        return xhtml string for display this option's feedback
        """
        lb = "\n"  #Line breaks
        dT = common.getExportDocType()
        sectionTag = "div"
        titleTag = "h4"
        if dT == "HTML5":
            sectionTag = "section"
            titleTag = "h1"

        if is_preview:
            content = self.question_feedback.field.content_w_resourcePaths
        else:
            content = self.question_feedback.field.content_wo_resourcePaths

        html = '<' + sectionTag + ' id="s' + self.id + '" class="feedback js-feedback js-hidden">' + lb
        html += '<' + titleTag + ' class="js-sr-av">' + c_(
            "Feedback") + '</' + titleTag + '>' + lb
        if self.question.isCorrect:
            html += '<p><strong id="s' + self.id + '-result" class="right">' + c_(
                "True") + '</strong></p>' + lb
        else:
            html += '<p><strong id="s' + self.id + '-result" class="wrong">' + c_(
                "False") + '</strong></p>' + lb
        html += content + lb
        html += '</' + sectionTag + '>' + lb

        return html
class DestacadofpdBlock(Block):
    def __init__(self, parent, idevice):
        """
        Initialize a new Block object
        """
        Block.__init__(self, parent, idevice)
        self.activityInstruc = idevice.activityInstruc

        # to compensate for the strange unpickling timing when objects are
        # loaded from an elp, ensure that proper idevices are set:
        if idevice.activityTextArea.idevice is None:
            idevice.activityTextArea.idevice = idevice

        self.activityElement = TextAreaElement(idevice.activityTextArea)

        self.previewing = False  # In view or preview render

        if not hasattr(self.idevice, 'undo'):
            self.idevice.undo = True

    def process(self, request):
        """
        Process the request arguments from the web server
        """
        Block.process(self, request)

        is_cancel = common.requestHasCancel(request)

        if not is_cancel:
            self.activityElement.process(request)
            if "title" + self.id in request.args:
                self.idevice.title = request.args["title" + self.id][0]

    def renderEdit(self, style):
        """
        Returns an XHTML string with the form element for editing this block
        """
        html = "<div class=\"iDevice\"><br/>\n"
        #        html += common.textInput("title"+self.id, "Destacado")
        html += self.activityElement.renderEdit()
        html += "<br/>" + self.renderEditButtons()
        html += "</div>\n"
        return html

    def renderPreview(self, style):
        """ 
        Remembers if we're previewing or not, 
        then implicitly calls self.renderViewContent (via Block.renderPreview) 
        """
        self.previewing = True
        return Block.renderPreview(self, style)

    def renderView(self, style):
        """ 
        Remembers if we're previewing or not, 
        then implicitly calls self.renderViewContent (via Block.renderPreview) 
        """
        self.previewing = False
        return Block.renderView(self, style)

    def renderViewContent(self):
        """
        Returns an XHTML string for this block
        """
        #        html  = u'<script type="text/javascript" src="common.js"></script>\n'
        #        html += u'<div class="iDevice_destacadofpd">\n'
        html = u'<div class="iDevice_destacadofpd">\n'

        if self.previewing:
            html += self.activityElement.renderPreview()
        else:
            html += self.activityElement.renderView()

        html += "</div>\n"
        return html
Beispiel #55
0
class TestoptionElement(object):
    """
    TestOptionElement is responsible for a block of option.  Used by
    TestquestionElement.  
    == SCORM Quiz Testoption, 
    pretty much the same as MultiSelect's SelectoptionElement,
    but with enough subtle variations that you'd better pay attention :-)
    """
    def __init__(self, index, question, questionId, option, idevice):
        """
        Initialize
        """
        self.index = index
        self.id = unicode(index) + "q" + questionId
        self.question = question
        self.questionId = questionId
        self.option = option
        self.answerId = "optionAnswer" + unicode(index) + "q" + questionId
        self.keyId = "key" + questionId
        self.idevice = idevice
        self.checked = False

        # to compensate for the strange unpickling timing when objects are
        # loaded from an elp, ensure that proper idevices are set:
        # (only applies to the image-embeddable ones, not FlashElement)
        if option.answerTextArea.idevice is None:
            option.answerTextArea.idevice = idevice
        self.answerElement = TextAreaElement(option.answerTextArea)
        self.answerElement.id = self.answerId

        if not hasattr(self.idevice, 'undo'):
            self.idevice.undo = True

    def process(self, request):
        """
        Process arguments from the web server.  Return any which apply to this 
        element.
        """
        log.debug("process " + repr(request.args))

        is_cancel = common.requestHasCancel(request)

        if self.answerId in request.args \
        and not is_cancel:
            self.answerElement.process(request)

        if "c"+self.keyId in request.args \
        and not is_cancel:
            if request.args["c" + self.keyId][0] == self.id:
                self.option.isCorrect = True
                self.question.correctAns = self.index
                log.debug("option " + repr(self.option.isCorrect))
            else:
                self.option.isCorrect = False

        if self.keyId in request.args \
        and not is_cancel:
            if request.args[self.keyId][0] == unicode(self.index):
                self.question.userAns = self.index

        if "action" in request.args and request.args["action"][0] == self.id:
            # before deleting the option object, remove any internal anchors:
            for o_field in self.option.getRichTextFields():
                o_field.ReplaceAllInternalAnchorsLinks()
                o_field.RemoveAllInternalLinks()
            self.question.options.remove(self.option)
            # disable Undo once an option has been deleted:
            self.idevice.undo = False

    def renderEdit(self):
        """
        Returns an XHTML string for editing this option element
        """
        html = u"<tr><td align=\"left\"><b>%s</b>" % _("Option")
        html += common.elementInstruc(self.question.optionInstruc)

        header = ""
        if self.index == 0:
            header = _("Correct Option")

        html += u"</td><td align=\"right\"><b>%s</b>\n" % header
        html += u"</td><td>\n"
        if self.index == 0:
            html += common.elementInstruc(self.question.correctAnswerInstruc)
        html += "</td></tr><tr><td colspan=2>\n"

        # rather than using answerElement.renderEdit(),
        # access the appropriate content_w_resourcePaths attribute directly,
        # since this is in a customised output format
        # (in a table, with an extra delete-option X to the right)

        this_package = None
        if self.answerElement.field_idevice is not None \
        and self.answerElement.field_idevice.parentNode is not None:
            this_package = self.answerElement.field_idevice.parentNode.package

        html += common.richTextArea(
            self.answerId,
            self.answerElement.field.content_w_resourcePaths,
            package=this_package)

        html += "</td><td align=\"center\">\n"
        html += common.option("c" + self.keyId, self.option.isCorrect, self.id)
        html += "<br><br><br><br>\n"
        html += common.submitImage(self.id, self.idevice.id,
                                   "/images/stock-cancel.png",
                                   _(u"Delete option"))
        html += "</td></tr>\n"

        return html

    def renderPreview(self):
        """
        Returns an XHTML string for previewing this option element
        """
        return self.renderView(preview=True)

    def renderView(self, preview=False):
        """
        Returns an XHTML string for viewing this option element
        """
        log.debug("renderView called")

        lb = "\n"  #Line breaks
        dT = common.getExportDocType()
        sectionTag = "div"
        if dT == "HTML5":
            sectionTag = "section"

        html = '<' + sectionTag + ' class="iDevice_answer">' + lb

        # Checkbox
        fieldId = self.keyId + unicode((self.index + 1))
        html += '<p class="iDevice_answer-field js-required">' + lb
        html += '<label for="' + fieldId + '" class="sr-av"><a href="#answer-' + fieldId + '">' + c_(
            "Option") + ' ' + unicode((self.index + 1)) + '</a></label>'
        html += '<input type="radio" name="' + self.keyId + '" id="' + fieldId + '" value="' + unicode(
            self.index) + '" />'
        html += lb
        html += '</p>' + lb

        # Answer content
        html += '<div class="iDevice_answer-content" id="answer-' + fieldId + '">'
        if dT != "HTML5":
            html += '<a name="answer-' + fieldId + '"></a>'
        html += lb
        if preview:
            html += self.answerElement.renderPreview()
        else:
            html += self.answerElement.renderView()
        html += '</div>' + lb

        html += "</" + sectionTag + ">" + lb

        return html
class QuestionElement(object):
    """
    QuestionElement is responsible for a block of question. 
    Used by MultichoiceBlock CasestudyBlock.
    """

    def __init__(self, index, idevice, question):
        """
        Initialize
        'index' is our number in the list of questions
        'idevice' is a case study idevice
        'question' is a exe.engine.casestudyidevice.Question instance
        """
        self.index        = index
        self.id           = "q" + unicode(index) + "b" + idevice.id        
        self.idevice      = idevice


        self.quesId       = "quesQuestion" + unicode(index) + "b" + idevice.id
        self.feedbackId   = "quesFeedback" + unicode(index) + "b" + idevice.id

        self.question     = question
        # also split out each part for a separate TextAreaElement:

        # but first....  
        # to compensate for the strange unpickling timing when objects are 
        # loaded from an elp, ensure that proper idevices are set: 
        if question.questionTextArea.idevice is None: 
            question.questionTextArea.idevice = idevice 
        if question.feedbackTextArea.idevice is None: 
            question.feedbackTextArea.idevice = idevice

        self.question_question = TextAreaElement(question.questionTextArea)
        self.question_question.id = self.quesId 
        self.question_feedback = TextAreaElement(question.feedbackTextArea)
        self.question_feedback.id = self.feedbackId 

    def process(self, request):
        """
        Process arguments from the web server.  Return any which apply to this
        element.
        """
        log.debug("process " + repr(request.args))
        
        if self.quesId in request.args:
            self.question_question.process(request)
                        
        if self.feedbackId in request.args:
            self.question_feedback.process(request)

        if "action" in request.args and request.args["action"][0] == self.id:
            # before deleting the question object, remove any internal anchors:
            for q_field in self.question.getRichTextFields():
                 q_field.ReplaceAllInternalAnchorsLinks()  
                 q_field.RemoveAllInternalLinks()  
            self.idevice.questions.remove(self.question)
            # disable Undo once an activity has been deleted:
            self.idevice.undo = False


    def renderEdit(self):
        """
        Returns an XHTML string for editing this question element
        """

        html  = "<tr><td><b>%s</b>\n" % _("Activity")
        html += common.elementInstruc(self.idevice.questionInstruc)
        html += self.question_question.renderEdit()

        html += "<b>%s</b>\n" % _("Feedback")
        html += common.elementInstruc(self.idevice.feedbackInstruc)
        html += self.question_feedback.renderEdit()

        html += "</td><td>\n"
        html += common.submitImage(self.id, self.idevice.id, 
                                   "/images/stock-cancel.png",
                                   _("Delete question"))
        html += "</td></tr>\n"
        return html

    def doRender(self, preview=False):
        """
        Returns an XHTML string for viewing and previewing this question element
        depending on the value of 'preview'.
        """
        log.debug("renderView called")
              
        if preview: 
            html  = self.question_question.renderPreview()
        else:
            html  = self.question_question.renderView()

        if  self.question_feedback.field.content.strip() != "" :            
            html += '<div id="view%s" style="display:block;">' % self.id
            html += common.feedbackButton('btnshow' + self.id,
                        _(u"Show Feedback"),
                        onclick = "showAnswer('%s',1)" % self.id)
            html += '</div>'
            html += '<div id="hide%s" style="display:none;">' % self.id
            html += common.feedbackButton('btnhide' + self.id,
                        _(u"Hide Feedback"),
                        onclick = "showAnswer('%s',0)" % self.id)
            html += '<p>'

            html += '</p>'
            html += '</div>'
            html += '<div id="s%s" class="feedback" style=" ' % self.id
            html += 'display: none;">'

            if preview: 
                html  += self.question_feedback.renderPreview() 
            else: 
                html  += self.question_feedback.renderView()

            html += "</div>\n"
# JR: Generamos el contenido que ira dentro de la etiqueta noscript
	    html += '<noscript><div class="feedback">\n'
	    html += "<p><strong>" + _("Solucion") + ": </strong></p>\n"
            if preview: 
            	html  += self.question_feedback.field.content_w_resourcePaths
            else: 
            	html  += self.question_feedback.field.content_wo_resourcePaths
	    html += "</div></noscript>\n"
        else:
            html += "\n"
        
        return html

    def renderView(self):
        """
        Returns an XHTML string for viewing this question element
        """
        html = "<div class=\"question\">\n"
        html += self.doRender(preview=False)
        html += "</div>\n"
        return html
    
    def renderPreview(self):
        """
        Returns an XHTML string for previewing this question element
        """
        return self.doRender(preview=True)
Beispiel #57
0
class AttachmentBlock(Block):
    """
    AttachmentBlock can render and process AttachmentIdevices as XHTML
    """
    def __init__(self, parent, idevice):
        """
        Initialize
        """

        Block.__init__(self, parent, idevice)

        # to compensate for the strange unpickling timing when objects are
        # loaded from an elp, ensure that proper idevices are set:
        if idevice.descriptionTextArea.idevice is None:
            idevice.descriptionTextArea.idevice = idevice

        self.descriptionElement = TextAreaElement(idevice.descriptionTextArea)

    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)

        if (u"action" not in request.args
                or request.args[u"action"][0] != u"delete"):
            if u"label" + self.id in request.args:
                self.idevice.label = request.args[u"label" + self.id][0]

            self.descriptionElement.process(request)

            if "path" + self.id in request.args:
                attachmentPath = request.args["path" + self.id][0]

                if attachmentPath:
                    self.idevice.setAttachment(attachmentPath)

                if self.idevice.label == "":
                    self.idevice.label = os.path.basename(attachmentPath)

    def renderEdit(self, style):
        """
        Returns an XHTML string with the form elements for editing this block
        """
        log.debug("renderEdit")
        html = u'<div class="iDevice">\n'
        html += u'<div class="block">\n'

        label = _(u'Filename:')
        if self.idevice.userResources:
            label += u': '
            label += u'<span style="text-decoration:underline">'
            label += self.idevice.userResources[0].storageName
            label += u'</span>\n'
        html += u'<div>'
        this_package = None
        if self.idevice is not None and self.idevice.parentNode is not None:
            this_package = self.idevice.parentNode.package
        html += common.formField('textInput',
                                 this_package,
                                 label,
                                 'path' + self.id,
                                 '',
                                 self.idevice.filenameInstruc,
                                 size=40)
        html += u'<input type="button" onclick="addFile(\'%s\')"' % self.id
        html += u' value="%s" />\n' % _(u"Select a file")
        html += u'</div><br style="clear:both;" />'
        html += u'</div>\n'
        html += u'<div class="block">\n'
        html += u'\n<b>%s</b>\n' % _(u'Label:')
        html += common.elementInstruc(self.idevice.labelInstruc)
        html += u'</div>\n'
        html += common.textInput(u'label' + self.id, self.idevice.label)
        html += self.descriptionElement.renderEdit()
        html += u'<div class="block">\n'
        html += self.renderEditButtons()
        html += u'</div>\n'
        html += u'\n</div>\n'

        return html

    def renderPreview(self, style):
        """
        Returns an XHTML string for previewing this block
        """
        log.debug("renderPreview")
        html = u"<div class=\"iDevice "
        html += u"emphasis" + unicode(self.idevice.emphasis) + "\" "
        html += u"ondblclick=\"submitLink('edit'," + self.id + ", 0);\">\n"

        if self.idevice.userResources:
            html += u"<img src='/images/stock-attach.png'> <a style=\"cursor: pointer;\" "
            html += u" onclick=\"browseURL('"
            html += u"%s/" % (G.application.exeAppUri)
            html += self.package.name
            html += u"/resources/"
            html += self.idevice.userResources[0].storageName
            html += u"');\" >"
            html += self.idevice.label
            html += u"</a>\n"

        html += u'<div class="block">\n'
        html += self.descriptionElement.renderPreview()
        html += u"</div>\n"
        html += self.renderViewButtons()
        html += u"</div>\n"

        return html

    def renderView(self, style):
        """
        Returns an XHTML string for viewing this block
        """
        log.debug("renderView")
        html = u"<!-- attachment iDevice -->\n"
        html += u"<div class=\"iDevice "
        html += u"emphasis" + unicode(self.idevice.emphasis) + "\">\n"

        if self.idevice.userResources:
            html += u"<img src='stock-attach.png'> "
            html += u"<a href=\"#\" onclick=\"window.open('"
            html += self.idevice.userResources[0].storageName
            html += u"', '_blank');\" >"
            html += self.idevice.label
            html += u"</a> \n"

        html += u'<div class="block">\n'
        html += self.descriptionElement.renderView()
        html += u"</div>"
        html += u"</div>\n"

        return html
Beispiel #58
0
class DebesconocerfpdBlock(Block):
    def __init__(self, parent, idevice):
        """
        Initialize a new Block object
        """
        Block.__init__(self, parent, idevice)
        self.activityInstruc = idevice.activityInstruc

        # to compensate for the strange unpickling timing when objects are
        # loaded from an elp, ensure that proper idevices are set:
        if idevice.activityTextArea.idevice is None:
            idevice.activityTextArea.idevice = idevice

        self.activityElement = TextAreaElement(idevice.activityTextArea)

        self.previewing = False  # In view or preview render

        if not hasattr(self.idevice, 'undo'):
            self.idevice.undo = True

    def process(self, request):
        """
        Process the request arguments from the web server
        """
        Block.process(self, request)

        is_cancel = common.requestHasCancel(request)

        if not is_cancel:
            self.activityElement.process(request)
            if "title" + self.id in request.args:
                self.idevice.title = request.args["title" + self.id][0]

    def renderEdit(self, style):
        """
        Returns an XHTML string with the form element for editing this block
        """
        html = "<div class=\"iDevice\"><br/>\n"

        # JRJ
        # Quitamos el prefijo "FPD -"
        # (let's remove the "FPD -" prefix)
        if self.idevice.title.find("FPD - ") == 0:
            self.idevice.title = x_(u"You Should Know")

        html += common.textInput("title" + self.id, self.idevice.title)
        html += self.activityElement.renderEdit()
        html += "<br/>" + self.renderEditButtons()
        html += "</div>\n"
        return html

    def renderPreview(self, style):
        """ 
        Remembers if we're previewing or not, 
        then implicitly calls self.renderViewContent (via Block.renderPreview) 
        """
        self.previewing = True
        return Block.renderPreview(self, style)

    def renderView(self, style):
        """ 
        Remembers if we're previewing or not, 
        then implicitly calls self.renderViewContent (via Block.renderPreview) 
        """
        self.previewing = False
        return Block.renderView(self, style)

    def renderViewContent(self):
        """
        Returns an XHTML string for this block
        """

        if self.previewing:
            html = self.activityElement.renderPreview()
        else:
            html = self.activityElement.renderView()

        return html
Beispiel #59
0
class ClozefpdBlock(Block):
    """
    Renders a paragraph where the content creator can choose which words the
    student must fill in.
    """
    def __init__(self, parent, idevice):
        """
        Pre-create our field ids
        """
        Block.__init__(self, parent, idevice)

        # to compensate for the strange unpickling timing when objects are
        # loaded from an elp, ensure that proper idevices are set:
        if idevice.instructionsForLearners.idevice is None:
            idevice.instructionsForLearners.idevice = idevice
        if idevice.content.idevice is None:
            idevice.content.idevice = idevice
        if idevice.feedback.idevice is None:
            idevice.feedback.idevice = idevice

        self.instructionElement = \
            TextAreaElement(idevice.instructionsForLearners)
        self.clozeElement = ClozeElement(idevice.content)
        self.feedbackElement = \
            TextAreaElement(idevice.feedback)
        self.previewing = False  # In view or preview render
        if not hasattr(self.idevice, 'undo'):
            self.idevice.undo = True

    def process(self, request):
        """
        Handles changes in the paragraph text from editing
        """
        is_cancel = common.requestHasCancel(request)

        if "title"+self.id in request.args \
        and not is_cancel:
            self.idevice.title = request.args["title" + self.id][0]
        object = request.args.get('object', [''])[0]
        action = request.args.get('action', [''])[0]
        self.instructionElement.process(request)
        self.clozeElement.process(request)
        self.feedbackElement.process(request)
        Block.process(self, request)

    def renderEdit(self, style):
        """
        Renders a screen that allows the user to enter paragraph text and choose
        which words are hidden.
        """
        """        
	html = [
            u'<div class="iDevice">',
            u'<div class="block">',
#            common.textInput("title"+self.id, self.idevice.title),
            common.textInput("title"+self.id, "Autoevaluaci&oacute;n"),
            u'</div>',
            self.instructionElement.renderEdit(),
            self.clozeElement.renderEdit(),
            self.feedbackElement.renderEdit(),
            self.renderEditButtons(),
            u'</div>'
            ]
        return u'\n    '.join(html)"""
        html = "<div class=\"iDevice\"><br/>\n"
        html = "<div class=\"block\">"

        # JR
        # Quitamos el prefijo "FPD -"
        if self.idevice.title.find("FPD - ") == 0:
            self.idevice.title = x_(u"Autoevaluacion")

        html += common.textInput("title" + self.id, self.idevice.title)
        html += "</div>"
        html += self.instructionElement.renderEdit()
        html += self.clozeElement.renderEdit()
        html += self.feedbackElement.renderEdit()
        html += self.renderEditButtons()
        html += "</div>"
        return html

    def renderPreview(self, style):
        """ 
        Remembers if we're previewing or not, 
        then implicitly calls self.renderViewContent (via Block.renderPreview) 
        """
        self.previewing = True
        return Block.renderPreview(self, style)

    def renderView(self, style):
        """ 
        Remembers if we're previewing or not, 
        then implicitly calls self.renderViewContent (via Block.renderPreview) 
        """
        self.previewing = False
        return Block.renderView(self, style)

    def renderViewContent(self):
        """
        Returns an XHTML string for this block
        """
        # Only show feedback button if feedback is present
        if self.feedbackElement.field.content.strip():
            # Cloze Idevice needs id of div for feedback content
            feedbackID = self.feedbackElement.id
            if self.previewing:
                clozeContent = self.clozeElement.renderPreview(feedbackID)
            else:
                clozeContent = self.clozeElement.renderView(feedbackID)
        else:
            if self.previewing:
                clozeContent = self.clozeElement.renderPreview()
            else:
                clozeContent = self.clozeElement.renderView()
        instruction_html = ""
        if self.previewing:
            instruction_html = self.instructionElement.renderPreview()
        else:
            instruction_html = self.instructionElement.renderView()
        html = u'<script type="text/javascript" src="common.js"></script>\n'
        html += u'<div class="iDevice_inner">\n'
        html += instruction_html
        html += clozeContent
        if self.feedbackElement.field.content:
            if self.previewing:
                html += self.feedbackElement.renderPreview(False,
                                                           class_="feedback")
            else:
                html += self.feedbackElement.renderView(False,
                                                        class_="feedback")
        html += u'</div>\n'

        #JR: Anadimos la etiqueta noscript
        if self.previewing:
            cloze = self.clozeElement.field.content_w_resourcePaths
            feedback = self.feedbackElement.field.content_w_resourcePaths
        else:
            cloze = self.clozeElement.field.content_w_resourcePaths
            feedback = self.feedbackElement.field.content_wo_resourcePaths
        html += u'<noscript><div class="feedback">\n'
        html += u"<strong>" + _("Solucion") + u": </strong><br/>\n"
        html += cloze
        if self.feedbackElement.field.content:
            html += u"<br/><br/><strong>" + _(
                "Retroalimentacion") + ": </strong><br/>\n"
            html += feedback
        html += u"</div></noscript>"

        return html

    def renderText(self):
        """
        Returns an XHTML string for text file export.
        """

        if self.previewing:
            html = '<p>' + self.instructionElement.renderPreview() + '</p>'
        else:
            html = '<p>' + self.instructionElement.renderView() + '</p>'
        html += '<p>' + self.clozeElement.renderText() + '</p>'
        if self.feedbackElement.field.content:
            html += '<p>%s:</P>' % _(u"Feedback")
            if self.previewing:
                html += '<p>' + self.feedbackElement.renderPreview(
                    False, class_="feedback")
                html += '</p>'
            else:
                html += '<p>' + self.feedbackElement.renderView(
                    False, class_="feedback")
                html += '</p>'
        html += self.clozeElement.renderAnswers()
        return html