Esempio n. 1
0
 def render_GET(self, request):
     """Called for all requests to this object"""
     log.debug("render_GET")
     self.process(request)
     html = common.docType()
     html += '<html xmlns="http://www.w3.org/1999/xhtml">\n'
     html += "<head>\n"
     html += '<style type="text/css">\n'
     html += "@import url(/css/exe.css);\n"
     html += "@import url(/style/base.css);\n"
     html += "@import url(/style/standardwhite/content.css);</style>\n"
     html += '<script type="text/javascript" src="/scripts/libot_drag.js">'
     html += "</script>\n"
     html += '<script type="text/javascript" src="/scripts/common.js">'
     html += "</script>\n"
     html += '<script type="text/javascript" src="/scripts/editor.js">'
     html += "</script>\n"
     html += "<title>" + _("eXe : elearning XHTML editor") + "</title>\n"
     html += '<meta http-equiv="content-type" content="text/html; '
     html += ' charset=UTF-8"></meta>\n'
     html += "</head>\n"
     html += "<body>\n"
     html += '<div id="main"> \n'
     html += '<form method="post" action="' + self.url + '" '
     html += 'id="contentForm" >'
     html += common.hiddenField("action")
     html += common.hiddenField("object")
     html += common.hiddenField("isChanged", "1")
     html += '<font color="red"><b>' + self.message + "</b></font>"
     html += '<div id="editorButtons"> \n'
     html += self.renderList()
     html += self.editorPane.renderButtons(request)
     if self.isNewIdevice:
         html += "<br/>" + common.submitButton("delete", _("Delete"), False)
     else:
         html += "<br/>" + common.submitButton("delete", _("Delete"))
     html += '<br/><input class="button" type="button" name="save" '
     title = "none"
     if self.editorPane.idevice.edit == False:
         title = self.editorPane.idevice.title
         title = title.replace(" ", "+")
     html += 'onclick=saveIdevice("%s") value="%s"/>' % (escape(title), _("Save"))
     html += u'<br/><input class="button" type="button" name="import" onclick="importPackage(\'package\')"'
     html += u' value="%s" />' % _("Import iDevice")
     html += u'<br/><input class="button" type="button" name="export" '
     html += u"onclick=\"exportPackage('package','%d')\"" % self.isNewIdevice
     html += u' value="%s" />' % _("Export iDevice")
     html += u'<br/><input class="button" type="button" name="quit" '
     html += u"onclick=JavaScript:window.close()"
     html += u' value="%s" />\n' % _("Quit")
     html += common.hiddenField("pathpackage")
     html += "</fieldset>"
     html += "</div>\n"
     html += self.editorPane.renderIdevice(request)
     html += "</div>\n"
     html += "<br/></form>\n"
     html += "</body>\n"
     html += "</html>\n"
     return html.encode("utf8")
Esempio n. 2
0
 def render_GET(self, request):
     """Called for all requests to this object"""
     log.debug("render_GET")
     self.process(request)
     html  = common.docType()
     html += "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
     html += "<head>\n"
     html += "<style type=\"text/css\">\n"
     html += "@import url(/css/exe.css);\n"
     html += '@import url(/style/base.css);\n'
     html += "@import url(/style/standardwhite/content.css);</style>\n"
     html += '<script type="text/javascript" src="/scripts/libot_drag.js">'
     html += '</script>\n'
     html += '<script type="text/javascript" src="/scripts/common.js">'
     html += '</script>\n'
     html += '<script type="text/javascript" src="/scripts/editor.js">'
     html += '</script>\n'
     html += "<title>"+_("eXe : elearning XHTML editor")+"</title>\n"
     html += "<meta http-equiv=\"content-type\" content=\"text/html; "
     html += " charset=UTF-8\"></meta>\n";
     html += "</head>\n"
     html += "<body>\n"
     html += "<div id=\"main\"> \n"     
     html += "<form method=\"post\" action=\""+self.url+"\" "
     html += "id=\"contentForm\" >"  
     html += common.hiddenField("action")
     html += common.hiddenField("object")
     html += common.hiddenField("isChanged", "1") 
     html += "<font color=\"red\"<b>"+self.message+"</b></font>"
     html += "<div id=\"editorButtons\"> \n"     
     html += self.renderList()
     html += self.editorPane.renderButtons(request)
     if self.isNewIdevice:
         html += "<br/>" + common.submitButton("delete", _("Delete"), 
                                                     False)
     else:
         html += "<br/>" + common.submitButton("delete", _("Delete"))
     html += '<br/><input class="button" type="button" name="save" '
     title = "none"
     if self.editorPane.idevice.edit == False:
         title = self.editorPane.idevice.title
     html += 'onclick=saveIdevice("%s") value="%s"/>' % (title, _("Save"))
     html += u'<br/><input class="button" type="button" name="import" onclick="importPackage(\'package\')"' 
     html += u' value="%s" />'  % _("Import iDevice")
     html += u'<br/><input class="button" type="button" name="export" '
     html += u'onclick="exportPackage(\'package\',\'%d\')"' % self.isNewIdevice
     html += u' value="%s" />'  % _("Export iDevice")
     html += common.hiddenField("pathpackage")
     html += "</fieldset>"
     html += "</div>\n"
     html += self.editorPane.renderIdevice(request)
     html += "</div>\n"
     html += "<br/></form>\n"
     html += "</body>\n"
     html += "</html>\n"
     return html.encode('utf8')
Esempio n. 3
0
    def render_GET(self, request=None):
        """
        Returns an XHTML string for viewing this page
        if 'request' is not passed, will generate psedo/debug html
        """
        log.debug(u"render_GET "+repr(request))

        if request is not None:
            # Process args
            for key, value in request.args.items():
                request.args[key] = [unicode(value[0], 'utf8')]
            self._process(request)

        topNode     = self.package.currentNode
        self.blocks = []
        self.__addBlocks(topNode)
        html  = self.__renderHeader()
        html += u'<body onload="onLoadHandler();">\n'
        html += u"<form method=\"post\" "

        if request is None:
            html += u'action="NO_ACTION"'
        else:
            html += u"action=\""+request.path+"#currentBlock\""
        html += u" id=\"contentForm\">"
        html += u'<div id="main">\n'
        html += common.hiddenField(u"action")
        html += common.hiddenField(u"object")
        html += common.hiddenField(u"isChanged", u"0")
        html += u'<!-- start authoring page -->\n'
        html += u'<div id="nodeDecoration">\n'
        html += u'<h1 id="nodeTitle">\n'
        html += escape(topNode.titleLong)
        html += u'</h1>\n'
        html += u'</div>\n'

        for block in self.blocks:
            html += block.render(self.package.style)

        html += u'</div>\n'
        html += u'<script type="text/javascript">$exeAuthoring.ready()</script>'
#modifications by lernmodule.net
        html += u'</form>\n'
        html += u'<div id=\"lmsubmit\"></div><script type=\"text/javascript\" language=\"javascript\">doStart();</script>\n'
#end modification
        html += common.footer()

        html = html.encode('utf8')
        return html
Esempio n. 4
0
    def renderEdit(self, style):
        """
        Returns an XHTML string with the form element for editing this block
        """
        html = u'<div><div class="block">'
        html += common.textInput("title" + self.id, self.idevice.title)
        html += common.hiddenField("iconiDevice" + self.id, self.idevice.icon)
        html += u'<a class="js-show-icon-panel-button" href="javascript:showMessageBox(\'iconpanel\');">%s</a>' % _(
            'Select an icon')

        # Get icon source (if it exists)
        icon = self.idevice.icon
        icon_exists = False
        if icon != '':
            idevice_icon = Path(G.application.config.stylesDir / style /
                                'icon_' + self.idevice.icon + '.gif')
            if idevice_icon.exists():
                icon_exists = True
            else:
                idevice_icon = Path(G.application.config.stylesDir / style /
                                    "icon_" + self.idevice.icon + ".png")
                if idevice_icon.exists():
                    icon_exists = True

        # Icon HTML element
        html += u'<img class="js-idevide-icon-preview" name="iconiDevice%s" id="iconiDevice"' % (
            self.id)
        if icon_exists:
            html += u' src="/style/%s/icon_%s%s"' % (style, icon,
                                                     idevice_icon.ext)
        else:
            html += u' src="/images/empty.gif"'
        html += u'/>'

        # Delete button
        html += u'<a href="javascript:deleteIcon(%s);" id="deleteIcon%s" class="deleteIcon" title="%s"' % (
            self.id, self.id, _('Delete'))
        # If the icon doesn't exists
        if not icon_exists:
            html += u' style="display: none;"'
        html += u'>'
        html += u'<img class="js-delete-icon" alt="%s" src="%s"/>' % (
            _('Delete'), '/images/stock-delete.png')
        html += u'</a>'

        html += u'<div class="js-icon-panel-container">'
        html += u'<div id="iconpaneltitle">%s</div>' % _("Icons")
        html += u'<div id="iconpanelcontent">'
        html += self.__renderIcons(style)
        html += u'</div>'
        html += u'</div>'
        html += u"</div>"

        for element in self.elements:
            html += element.renderEdit() + u'<br />'

        html += self.renderEditButtons()
        html += u"</div>"

        return html
Esempio n. 5
0
    def renderEdit(self, style):
        """
        Returns an XHTML string with the form element for editing this block
        """
        html = u'<div>'
        html += '<span class="js-idevice-title-label">'
        html += '<label for="title'+self.id+'">'+_('Title')+':</label> '
        html += common.elementInstruc(_('The title and the icon are not required. If you leave them empty the iDevice will have no emphasis.'))
        html += '</span>'
        html += common.hiddenField("iconiDevice" + self.id, self.idevice.icon)
        html += u'<a class="js-show-icon-panel-button" href="javascript:showMessageBox(\'iconpanel\');" title="%s"><img src="/images/stock-insert-image.png" alt="%s" width="16" height="16" /></a>' % (_('Select an icon'),_('Choose an Image'))        
        
        # Get icon source (if it exists)
        icon = self.idevice.icon
        icon_exists = False
        if icon != '':
            idevice_icon = Path(G.application.config.stylesDir / style / 'icon_' + self.idevice.icon + '.gif')
            if idevice_icon.exists():
                icon_exists = True
            else:
                idevice_icon = Path(G.application.config.stylesDir/style/"icon_" + self.idevice.icon + ".png")
                if idevice_icon.exists():
                    icon_exists = True

        # Icon HTML element
        html += u'<img class="js-idevide-icon-preview" name="iconiDevice%s" id="iconiDevice"' % (self.id)
        if icon_exists:
            html += u' src="/style/%s/icon_%s%s"' % (style, icon, idevice_icon.ext)
        else:
            html += u' src="/images/empty.gif"'
        html += u'/>'

        # Delete button
        html += u'<a href="javascript:deleteIcon(%s);" id="deleteIcon%s" class="deleteIcon" title="%s"' % (self.id, self.id, _('Delete'))
        # If the icon doesn't exists
        if not icon_exists:
            html += u' style="display: none;"'
        html += u'>'
        html += u'<img class="js-delete-icon" alt="%s" src="%s"/>' % (_('Delete'), '/images/stock-delete.png')
        html += u'</a>'
        
        html += common.textInput("title" + self.id, self.idevice.title)

        html += u'<div class="js-icon-panel-container">'
        html += u'<div id="iconpaneltitle">%s</div>' % _("Icons")
        html += u'<div id="iconpanelcontent">'
        html += self.__renderIcons(style)
        html += u'</div>'
        
        html += u"</div>"

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

        html += self.renderEditButtons()
        html += u"</div>"

        return html
Esempio n. 6
0
 def render_GET(self, request):
     """Called for all requests to this object"""
     log.debug("render_GET")
     self.process(request)
     html = common.docType()
     html += '<html xmlns="http://www.w3.org/1999/xhtml">\n'
     html += "<head>\n"
     html += '<style type="text/css">\n'
     html += "@import url(/css/exe.css);\n"
     html += "@import url(/style/base.css);\n"
     html += "@import url(/style/standardwhite/content.css);</style>\n"
     html += '<script type="text/javascript" src="/scripts/libot_drag.js">'
     html += "</script>\n"
     html += '<script type="text/javascript" src="/scripts/common.js">'
     html += "</script>\n"
     html += "<title>" + _("eXe : elearning XHTML editor") + "</title>\n"
     html += '<meta http-equiv="content-type" content="text/html; '
     html += ' charset=UTF-8"></meta>\n'
     html += "</head>\n"
     html += "<body>\n"
     html += '<div id="main"> \n'
     html += '<form method="post" action="' + self.url + '" '
     html += 'id="contentForm" >'
     html += common.hiddenField("action")
     html += common.hiddenField("object")
     html += common.hiddenField("isChanged", "1")
     html += '<font color="red"<b>' + self.message + "</b></font>"
     html += '<div id="editorButtons"> \n'
     html += self.renderList()
     html += self.editorPane.renderButtons(request)
     if self.isNewIdevice:
         html += "<br/>" + common.submitButton("delete", _("Delete"), False)
         html += "<br/>" + common.submitButton("save", _("Save"), False)
     else:
         html += "<br/>" + common.submitButton("delete", _("Delete"))
         html += "<br/>" + common.submitButton("save", _("Save"))
     html += "<br/>" + common.submitButton("add", _("Save as"))
     html += "</fieldset>"
     html += "</div>\n"
     html += self.editorPane.renderIdevice(request)
     html += "</div>\n"
     html += "<br/></form>\n"
     html += "</body>\n"
     html += "</html>\n"
     return html.encode("utf8")
Esempio n. 7
0
 def render(self):
     """Returns an XHTML string for viewing this pane"""
     log.debug("render")
     html  = u''
     html += u'<a name="currentBlock"/>'
     html += u"<form method=\"post\" action=\"%s\" " % self.url
     html += u"id=\"contentForm\" " 
     html += u'onSubmit="return handleSubmit()">\n' 
     html += common.hiddenField("action")
     html += common.hiddenField("isChanged", self.package.isChanged)
     html += common.hiddenField("posting", self.package.isChanged)
     html += u"<table border=\"0\" cellspacing=\"6\">\n"
     html += u"<tr><td><b>%s</b></td><td>\n" % _(u"Project title:")
     html += common.textInput("title", self.package.root.title, 53) 
     html += u"</td>"
     html += u"</tr><tr><td><b>"
     html += _(u"Author")
     html += u":</b></td><td>\n"
     html += common.textInput("author", self.package.author, 53) 
     html += u"</td></tr>\n"
     html += u"<tr><td valign=\"top\"><b>"
     html += _(u"Description")
     html += u":</b></td><td>\n"
     html += common.textArea("description", self.package.description)
     html += u"</td></tr>\n"
     html += u"<tr><td valign=\"top\"><b>"
     html += _(u"Taxonomy")
     html += u":</b></td>\n"
     html += u"<td valign=\"top\">"
     html += _(u"Level 1: ")
     html += common.textInput("level1", self.package.levelName(0), 20)
     html += u'<div class="block">'
     html += _(u"Level 2: ")
     html += common.textInput("level2", self.package.levelName(1), 20)
     html += u"</div>\n"
     html += u'<div class="block">'
     html += _(u"Level 3: ")
     html += common.textInput("level3", self.package.levelName(2), 20)
     html += u"</div></td></tr><tr><td align=\"right\">\n"       
     html += common.submitButton('done', _(u'Done'))
     html += u"</td><td>&nbsp;</td></tr></table></form>\n"
     return html
    def render_GET(self, request=None):
        """
        Returns an XHTML string for viewing this page
        if 'request' is not passed, will generate psedo/debug html
        """
        log.debug(u"render_GET "+repr(request))

        topNode = self.package.root
        is_ajax = "mode" in request.args and request.args['mode'][0] == "ajax"
        
        if request is not None and is_ajax is not True:
            # Process args
            for key, value in request.args.items():
                request.args[key] = [unicode(value[0], 'utf8')]
            topNode = self._process(request)

        #Update other authoring pages that observes the current package
        if "action" in request.args:
            if request.args['clientHandleId'][0] == "":
                raise(Exception("Not clientHandleId defined"))
            activeClient = None
            for client in self.parent.clientHandleFactory.clientHandles.values():
                if request.args['clientHandleId'][0] != client.handleId:
                    if client.handleId in self.parent.authoringPages:
                        destNode = None
                        if request.args["action"][0] == "move":
                            destNode = request.args["move" + request.args["object"][0]][0]
                        client.call('eXe.app.getController("MainTab").updateAuthoring', request.args["action"][0], \
                            request.args["object"][0], request.args["isChanged"][0], request.args["currentNode"][0], destNode)
                else:
                    activeClient = client

            if request.args["action"][0] == "done":
                if activeClient:
                    return "<body onload='location.replace(\"" + request.path + "?clientHandleId=" + activeClient.handleId + "\")'/>"
                else:
                    log.error("No active client")

        self.blocks = []
        self.__addBlocks(topNode)
        html  = self.__renderHeader()
        html += u'<body onload="onLoadHandler();" class="exe-authoring-page js">\n'
        html += u"""<div id='externalToolbarHolder' 
        style='z-index: 1000; position: fixed; top: 0px; width: 100%; left:0px; border-bottom: 2px solid gray; height: 0px'>"""
        
        #html += u"<div id='externalToolbarWrapper' class='defaultSkin'>&nbsp;</div>\n"
        html += u"</div>"
        
        html += u"<form method=\"post\" "

        if request is None:
            html += u'action="NO_ACTION"'
        else:
            html += u"action=\""+request.path+"#currentBlock\""
        html += u" id=\"contentForm\">"
        html += u'<div id="main">\n'
        html += common.hiddenField(u"action")
        html += common.hiddenField(u"object")
        html += common.hiddenField(u"isChanged", u"0")
        html += common.hiddenField(u"currentNode", unicode(topNode.id))
        html += common.hiddenField(u'clientHandleId', request.args['clientHandleId'][0])
        html += u'<!-- start authoring page -->\n'
        html += u'<div id="nodeDecoration">\n'
        html += u'<h1 id="nodeTitle">\n'
        html += escape(topNode.titleLong)
        html += u'</h1>\n'
        html += u'</div>\n'
        
        html += "<div class='authoring_button_row'>"
        #html += "<input value='%s' class='insert_button' type='button' onclick=\"submitLink('%s', '%s', %d);\"/>" % \
        #        (_("Insert Here"), "addidevice", "authoring", 1)
        
        html += "<input value='%s' class='insert_button' type='button' onclick=\"authoringInsertIdevice();\"/>" % \
                _("Add Content")
        html += "</div>"
        
        for block in self.blocks:
            html += block.render(self.package.style)
            
        
        
        

        html += u'</div>'
        html += '<script type="text/javascript">$exeAuthoring.ready()</script>\n'
        html += common.footer()

        html = html.encode('utf8')
        return html
    def renderView(self, feedbackId=None, preview=False):
        
        # Shows the text with inputs for the missing parts
       
        dT = common.getExportDocType()
        sectionTag = "div"
        if dT == "HTML5":
            sectionTag = "section"

        html = ['<%s class="activity" id="activity-%s">' % (sectionTag,self.id)]
        
        if preview: 
            # to render, use the content with the preview-able resource paths:
            self.field.encodedContent = self.field.content_w_resourcePaths
            html += ['<div class="activity-form">']
        else:
            # to render, use the flattened content, withOUT resource paths: 
            self.field.encodedContent = self.field.content_wo_resourcePaths
            html += ['<form name="cloze-form-'+self.id+'" action="#" onsubmit="showClozeScore(\''+self.id+'\',1);return false" class="activity-form">']

        html += ['<div id="cloze%s">' % self.id]
        html += ['<script type="text/javascript">var YOUR_SCORE_IS="%s"</script>' % c_('Your score is ')]
        # Store our args in some hidden fields
        def storeValue(name):
            value = str(bool(getattr(self.field, name))).lower()
            return common.hiddenField('clozeFlag%s.%s' % (self.id, name), value)
        #html.append(storeValue('showScore'))
      
        if feedbackId:
            html.append(common.hiddenField('clozeVar%s.feedbackId' % self.id,'ta'+feedbackId))
        # Mix the parts together
        words = ""
        wordslista='<option selected="selected"> </option>'
        wordsarray=[]
        listaotras=[]
        listaotras2=[]
        wordsarraylimpo=[] 
        
        for i, (text, missingWord) in enumerate(self.field.parts):
            if missingWord:
                wordsarray.append([missingWord])
        
        listaotras=re.compile(",|\|").split(self.field.otras)
        
        for i, (missingWord) in enumerate(listaotras):
            if missingWord:
                listaotras2.append([missingWord])
        wordsarray=wordsarray + listaotras2 
        wordsarraylimpo= [wordsarray[i] for i in range(len(wordsarray)) if wordsarray[i] not in wordsarray[:i]]
        random.shuffle(wordsarraylimpo)
        for wdlista in wordsarraylimpo:
           wordslista +='<option value="%s">%s</option>' % (escape(wdlista[0], True), wdlista[0])
          
        for i, (text, missingWord) in enumerate(self.field.parts):
            if text:
                html.append(text)
            if missingWord:
                words += "'" + missingWord + "',"
                # The edit box for the user to type into
                inputHtml = ['<label for="clozeBlank%s.%s" class="sr-av">%s (%s):</label>' % (self.id, i, c_("Cloze"), (i+1))]
                inputHtml += ['<select id="clozeBlank%s.%s">' % (self.id, i),wordslista,'</select>']
                html += inputHtml
                            
                # Hidden span with correct answer
                html += ['<span style="display:none" id="clozeAnswer%s.%s">%s</span>' % (self.id, i, self.ecrypt(missingWord))]

        # Score string
        html += ['<div class="block iDevice_buttons">']
        html += ['<p>']
        
        if preview:
            html += [common.button('getScore%s' % self.id, c_(u"Check"), id='getScore%s' % self.id, onclick="showClozeScore('%s',1)" % self.id)]
        else:
            html += [common.submitButton('getScore%s' % self.id, c_(u"Check"), id='getScore%s' % self.id)]
        if feedbackId:
            html += [common.feedbackButton('feedback%s' % self.id, c_(u"Show Feedback"), onclick = "toggleClozeFeedback('%s',this)" % self.id)]
         
        codotras=self.ecrypt(self.field.otras)
        html += [common.hiddenField('clozeOtras%s' % self.id,codotras)]   
        html += ['<input type="hidden" name="clozeFlag%s.strictMarking" id="clozeFlag%s.strictMarking" value="false" />' % (self.id,self.id)]
        html += ['<input type="hidden" name="clozeFlag%s.checkCaps" id="clozeFlag%s.checkCaps" value="false" />' % (self.id,self.id)]
        html += ['<input type="hidden" name="clozeFlag%s.instantMarking" id="clozeFlag%s.instantMarking" value="false" />' % (self.id,self.id)]
        html += [common.javaScriptIsRequired()]
        html += ['</p>']
        html += ['</div>']
        html += ['<div class="score js-feedback" id="clozeScore%s"></div>' % self.id]        
        html += ['</div>']
        if preview: 
            html += ['</div>']
        else:
            html += ['</form>']
        html += ['</%s>' % sectionTag]
        return '\n'.join(html)
Esempio n. 10
0
 def storeValue(name):
     value = str(bool(getattr(self.field, name))).lower()
     return common.hiddenField('clozeFlag%s.%s' % (self.id, name), value)
Esempio n. 11
0
    def renderView(self, feedbackId=None, preview=False):
        
        # Shows the text with inputs for the missing parts
       
        dT = common.getExportDocType()
        sectionTag = "div"
        if dT == "HTML5":
            sectionTag = "section"

        html = ['<%s class="activity" id="activity-%s">' % (sectionTag,self.id)]
        
        if preview: 
            # to render, use the content with the preview-able resource paths:
            self.field.encodedContent = self.field.content_w_resourcePaths
            html += ['<div class="activity-form">']
        else:
            # to render, use the flattened content, withOUT resource paths: 
            self.field.encodedContent = self.field.content_wo_resourcePaths
            html += ['<form name="cloze-form-'+self.id+'" action="#" class="activity-form cloze-form">']

        html += ['<div id="cloze%s">' % self.id]
        # Store our args in some hidden fields
        def storeValue(name):
            value = str(bool(getattr(self.field, name))).lower()
            return common.hiddenField('clozeFlag%s.%s' % (self.id, name), value)
        #html.append(storeValue('showScore'))
      
        if feedbackId:
            html.append(common.hiddenField('clozeVar%s.feedbackId' % self.id,'ta'+feedbackId))
        # Mix the parts together
        words = ""
        wordslista='<option selected="selected"> </option>'
        wordsarray=[]
        listaotras=[]
        listaotras2=[]
        wordsarraylimpo=[] 
        
        for i, (text, missingWord) in enumerate(self.field.parts):
            if missingWord:
                wordsarray.append([missingWord])
        listaotras=self.field.otras.split('|')
        for i, (missingWord) in enumerate(listaotras):
            if missingWord:
                listaotras2.append([missingWord])
        wordsarray=wordsarray + listaotras2 
        wordsarraylimpo= [wordsarray[i] for i in range(len(wordsarray)) if wordsarray[i] not in wordsarray[:i]]
        random.shuffle(wordsarraylimpo)
        for wdlista in wordsarraylimpo:
           wordslista +='<option value="%s">%s</option>' % (escape(wdlista[0], True), wdlista[0])
          
        for i, (text, missingWord) in enumerate(self.field.parts):
            if text:
                html.append(text)
            if missingWord:
                words += "'" + missingWord + "',"
                # The edit box for the user to type into
                inputHtml = ['<label for="clozeBlank%s.%s" class="sr-av">%s (%s):</label>' % (self.id, i, c_("Cloze"), (i+1))]
                inputHtml += ['<select id="clozeBlank%s.%s">' % (self.id, i),wordslista,'</select>']
                html += inputHtml
                            
                # Hidden span with correct answer
                html += ['<span style="display:none" id="clozeAnswer%s.%s">%s</span>' % (self.id, i, self.ecrypt(missingWord))]

        # Score string
        html += ['<div class="block iDevice_buttons">']
        html += ['<p>']
        
        if preview:
            html += [common.button('getScore%s' % self.id, c_(u"Check"), id='getScore%s' % self.id, class_ = "cloze-score-toggler")]
        else:
            html += [common.submitButton('getScore%s' % self.id, c_(u"Check"), id='getScore%s' % self.id)]
        if feedbackId:
            html += [common.button('feedback%s' % self.id, c_(u"Show Feedback"), class_ = "feedbackbutton cloze-feedback-toggler")]
         
        codotras=self.ecrypt(self.field.otras)
        html += [common.hiddenField('clozeOtras%s' % self.id,codotras)]   
        html += ['<input type="hidden" name="clozeFlag%s.strictMarking" id="clozeFlag%s.strictMarking" value="false" />' % (self.id,self.id)]
        html += ['<input type="hidden" name="clozeFlag%s.checkCaps" id="clozeFlag%s.checkCaps" value="false" />' % (self.id,self.id)]
        html += ['<input type="hidden" name="clozeFlag%s.instantMarking" id="clozeFlag%s.instantMarking" value="false" />' % (self.id,self.id)]
        html += [common.javaScriptIsRequired()]
        html += ['</p>']
        html += ['</div>']
        html += ['<div class="score js-feedback" id="clozeScore%s"></div>' % self.id]        
        html += ['</div>']
        if preview: 
            html += ['</div>']
        else:
            html += ['</form>']
        html += ['</%s>' % sectionTag]
        return '\n'.join(html)
Esempio n. 12
0
    def render_GET(self, request=None):
        """
        Returns an XHTML string for viewing this page
        if 'request' is not passed, will generate psedo/debug html
        """
        log.debug(u"render_GET "+repr(request))

        topNode = self.package.root
        if request is not None:
            # Process args
            for key, value in request.args.items():
                request.args[key] = [unicode(value[0], 'utf8')]
            topNode = self._process(request)

        #Update other authoring pages that observes the current package
        if "action" in request.args:
            if request.args['clientHandleId'][0] == "":
                raise(Exception("Not clientHandleId defined"))
            activeClient = None
            for client in self.parent.clientHandleFactory.clientHandles.values():
                if request.args['clientHandleId'][0] != client.handleId:
                    if client.handleId in self.parent.authoringPages:
                        destNode = None
                        if request.args["action"][0] == "move":
                            destNode = request.args["move" + request.args["object"][0]][0]
                        client.call('eXe.app.getController("MainTab").updateAuthoring', request.args["action"][0], \
                            request.args["object"][0], request.args["isChanged"][0], request.args["currentNode"][0], destNode)
                else:
                    activeClient = client

            if request.args["action"][0] == "done":
                if activeClient:
                    return "<body onload='location.replace(\"" + request.path + "?clientHandleId=" + activeClient.handleId + "\")'/>"
                else:
                    log.error("No active client")

        self.blocks = []
        self.__addBlocks(topNode)
        html  = self.__renderHeader()
        html += u'<body onload="onLoadHandler();" class="exe-authoring-page js">\n'
        html += u"<form method=\"post\" "

        if request is None:
            html += u'action="NO_ACTION"'
        else:
            html += u"action=\""+request.path+"#currentBlock\""
        html += u" id=\"contentForm\">"
        html += u'<div id="main">\n'
        html += common.hiddenField(u"action")
        html += common.hiddenField(u"object")
        html += common.hiddenField(u"isChanged", u"0")
        html += common.hiddenField(u"currentNode", unicode(topNode.id))
        html += common.hiddenField(u'clientHandleId', request.args['clientHandleId'][0])
        html += u'<!-- start authoring page -->\n'
        html += u'<div id="nodeDecoration">\n'
        html += u'<div id="headerContent">\n'
        html += u'<h1 id="nodeTitle">\n'
        html += escape(topNode.titleLong)
        html += u'</h1>\n'
        html += u'</div>\n'
        html += u'</div>\n'

        for block in self.blocks:
            html += block.render(self.package.style)

        html += u'</div>'
        style = G.application.config.styleStore.getStyle(self.package.style)
        
        html += common.renderLicense(self.package.license,"authoring")
        html += common.renderFooter(self.package.footer)
        
        if style.hasValidConfig:
            html += style.get_edition_extra_body()
        html += '<script type="text/javascript">$exeAuthoring.ready()</script>\n'
        html += common.footer()

        html = html.encode('utf8')
        return html
Esempio n. 13
0
 def storeValue(name):
     value = str(bool(getattr(self.field, name))).lower()
     return common.hiddenField('clozeFlag%s.%s' % (self.id, name), value)
Esempio n. 14
0
 def render_GET(self, request):
     """Called for all requests to this object"""
     
     # Processing 
     log.debug("render_GET")
     self.process(request)
     
     # Rendering
     html  = common.docType()
     html += "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
     html += "<head>\n"
     html += "<style type=\"text/css\">\n"
     html += "@import url(/css/exe.css);\n"
     html += '@import url(/style/base.css);\n'
     html += "@import url(/style/standardwhite/content.css);</style>\n"
     html += '<script type="text/javascript" src="/scripts/authoring.js">'
     html += '</script>\n'
     html += '<script type="text/javascript" src="/scripts/common.js">'
     html += '</script>\n'
     html += '<script type="text/javascript" src="/scripts/editor.js">'
     html += '</script>\n'
     html += "<title>"+_("eXe : elearning XHTML editor")+"</title>\n"
     html += "<meta http-equiv=\"content-type\" content=\"text/html; "
     html += " charset=UTF-8\"></meta>\n";
     html += "</head>\n"
     html += "<body>\n"
     html += "<div id=\"main\"> \n"     
     html += "<form method=\"post\" action=\""+self.url+"\" "
     html += "id=\"contentForm\" >"  
     html += common.hiddenField("action")
     html += common.hiddenField("object")
     html += common.hiddenField("isChanged", "1") 
     if self.message != '':
         html += "<script>Ext.Msg.alert('"+_('Info')+"', '"+self.message+"');</script>"
     html += "<div id=\"editorButtons\"> \n"     
     html += self.renderList()
     html += self.editorPane.renderButtons(request)
     if self.isNewIdevice:
         html += "<br/>" + common.submitButton("delete", _("Delete"), 
                                                     False)
     else:
         html += '<br /><input type="button" class="button" onclick="deleteIdevice()" value="'+_("Delete")+'" />'
     html += '<br/><input class="button" type="button" name="save" '
     title = "none"
     if self.editorPane.idevice.edit == False:
         title = self.editorPane.idevice.title
         title = title.replace(" ", "+")
     html += 'onclick=saveIdevice("%s") value="%s"/>' % (escape(title), _("Save"))
     html += u'<br/><input class="button" type="button" name="import" ' 
     html += u' onclick="importPackage(\'package\')" value="%s" />'  % _("Import iDevice")
     html += u'<br/><input class="button" type="button" name="export" '
     html += u'onclick="exportPackage(\'package\',\'%d\')"' % self.isNewIdevice
     html += u' value="%s" />'  % _("Export iDevice")
     html += u'<br/><input class="button" type="button" name="quit" '
     #html += u'onclick="parent.Ext.getCmp(\'ideviceeditorwin\').close()"'        
     html += u'onclick="quitDialog()"'  
     html += u' value="%s" />\n'  % _("Quit")
     html += common.hiddenField("pathpackage")
     html += "</fieldset>"
     html += "</div>\n"
     html += self.editorPane.renderIdevice(request)
     html += "</div>\n"
     html += "<br/></form>\n"
     html += "</body>\n"
     html += "</html>\n"
     return html.encode('utf8')
    def render_GET(self, request=None):
        """
        Returns an XHTML string for viewing this page
        if 'request' is not passed, will generate psedo/debug html
        """
        log.debug(u"render_GET " + repr(request))

        topNode = self.package.root
        if request is not None:
            # Process args
            for key, value in request.args.items():
                request.args[key] = [unicode(value[0], 'utf8')]
            topNode = self._process(request)

        #Update other authoring pages that observes the current package
        if "action" in request.args:
            if request.args['clientHandleId'][0] == "":
                raise (Exception("Not clientHandleId defined"))
            activeClient = None
            for client in self.parent.clientHandleFactory.clientHandles.values(
            ):
                if request.args['clientHandleId'][0] != client.handleId:
                    if client.handleId in self.parent.authoringPages:
                        destNode = None
                        if request.args["action"][0] == "move":
                            destNode = request.args[
                                "move" + request.args["object"][0]][0]
                        client.call('eXe.app.getController("MainTab").updateAuthoring', request.args["action"][0], \
                            request.args["object"][0], request.args["isChanged"][0], request.args["currentNode"][0], destNode)
                else:
                    activeClient = client

            if request.args["action"][0] == "done":
                if activeClient:
                    return "<body onload='location.replace(\"" + request.path + "?clientHandleId=" + activeClient.handleId + "\")'/>"
                else:
                    log.error("No active client")

        self.blocks = []
        self.__addBlocks(topNode)
        html = self.__renderHeader()
        html += u'<body onload="onLoadHandler();" class="exe-authoring-page js">\n'
        html += u"<form method=\"post\" "

        if request is None:
            html += u'action="NO_ACTION"'
        else:
            html += u"action=\"" + request.path + "#currentBlock\""
        html += u" id=\"contentForm\">"
        html += u'<div id="main">\n'
        html += common.hiddenField(u"action")
        html += common.hiddenField(u"object")
        html += common.hiddenField(u"isChanged", u"0")
        html += common.hiddenField(u"currentNode", unicode(topNode.id))
        html += common.hiddenField(u'clientHandleId',
                                   request.args['clientHandleId'][0])
        html += u'<!-- start authoring page -->\n'
        html += u'<div id="nodeDecoration">\n'
        html += u'<h1 id="nodeTitle">\n'
        html += escape(topNode.titleLong)
        html += u'</h1>\n'
        html += u'</div>\n'

        for block in self.blocks:
            html += block.render(self.package.style)

        html += u'</div>'
        html += '<script type="text/javascript">$exeAuthoring.ready()</script>\n'
        html += u'</form>\n'
        html += u'<div id=\"lmsubmit\"></div><script type=\"text/javascript\" language=\"javascript\">doStart();</script>\n'
        html += common.footer()

        html = html.encode('utf8')
        return html
Esempio n. 16
0
 def render_GET(self, request):
     """Called for all requests to this object"""
     
     # Processing 
     log.debug("render_GET")
     self.process(request)
     
     # Rendering
     html  = common.docType()
     html += "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
     html += "<head>\n"
     html += "<style type=\"text/css\">\n"
     html += "@import url(/css/exe.css);\n"
     html += '@import url(/style/base.css);\n'
     html += "@import url(/style/standardwhite/content.css);</style>\n"
     html += '<script type="text/javascript" src="/scripts/libot_drag.js">'
     html += '</script>\n'
     html += '<script type="text/javascript" src="/scripts/common.js">'
     html += '</script>\n'
     html += '<script type="text/javascript" src="/scripts/editor.js">'
     html += '</script>\n'
     html += "<title>"+_("eXe : elearning XHTML editor")+"</title>\n"
     html += "<meta http-equiv=\"content-type\" content=\"text/html; "
     html += " charset=UTF-8\"></meta>\n";
     html += "</head>\n"
     html += "<body>\n"
     html += "<div id=\"main\"> \n"     
     html += "<form method=\"post\" action=\""+self.url+"\" "
     html += "id=\"contentForm\" >"  
     html += common.hiddenField("action")
     html += common.hiddenField("object")
     html += common.hiddenField("isChanged", "1") 
     html += "<font color=\"red\"><b>"+self.message+"</b></font>"
     html += "<div id=\"editorButtons\"> \n"     
     html += self.renderList()
     html += self.editorPane.renderButtons(request, self.showHide)
     if self.isNewIdevice:
         html += "<br/>" + common.submitButton("delete", _("Delete"), 
                                                     False)
     else:
         html += "<br/>" + common.submitButton("delete", _("Delete"))
     html += '<br/><input class="button" type="button" name="save" '
     title = "none"
     if self.editorPane.idevice.edit == False:
         title = self.editorPane.idevice.title
         title = title.replace(" ", "+")
     html += 'onclick=saveIdevice("%s") value="%s"/>' % (escape(title), _("Save"))
     html += u'<br/><input class="button" type="button" name="import" ' 
     if self.showHide:
         html += ' disabled="disabled" '
     html += u' onclick="importPackage(\'package\')" value="%s" />'  % _("Import iDevice")
     html += u'<br/><input class="button" type="button" name="export" '
     if self.showHide:
         html += ' disabled="disabled" '
     html += u'onclick="exportPackage(\'package\',\'%d\')"' % self.isNewIdevice
     html += u' value="%s" />'  % _("Export iDevice")
     #JR: anado un boton que permite mostrar u ocultar iDevices
     if self.showHide:
         html += "<br/>" + common.submitButton("showHide", _("Show/Hide"), False)
     else:
         html += "<br/>" + common.submitButton("showHide", _("Show/Hide"))
     html += u'<br/><input class="button" type="button" name="quit" '
     #html += u'onclick="parent.Ext.getCmp(\'ideviceeditorwin\').close()"'        
     html += u'onclick="quitDialog()"'  
     html += u' value="%s" />\n'  % _("Quit")
     html += common.hiddenField("pathpackage")
     html += "</fieldset>"
     html += "</div>\n"
     #if ("showHide" in request.args):
     if self.showHide:  
         html += self.editorPane.renderShowHideiDevices(self.ideviceStore.getFactoryIdevices())
     else:
         html += self.editorPane.renderIdevice(request)
     html += "</div>\n"
     html += "<br/></form>\n"
     html += "</body>\n"
     html += "</html>\n"
     return html.encode('utf8')
Esempio n. 17
0
 def renderView(self, feedbackId=None):
     """
     Shows the text with inputs for the missing parts
     """
     html = ['<div id="cloze%s">' % self.id]
     def storeValue(name):
         value = str(bool(getattr(self.field, name))).lower()
         return common.hiddenField('clozeFlag%s.%s' % (self.id, name), value)
     html.append(storeValue('strictMarking'))
     html.append(storeValue('checkCaps'))
     html.append(storeValue('instantMarking'))
     if feedbackId:
         html.append(common.hiddenField('clozeVar%s.feedbackId' % self.id,
                                        'ta'+feedbackId))
     words = ""
     def encrypt(word):
         """
         Simple XOR encryptions
         """
         result = ''
         key = 'X'
         for letter in word:
             result += unichr(ord(key) ^ ord(letter))
             key = letter
         output = ''
         for char in result:
             output += '%%u%04x' % ord(char[0])
         return output.encode('base64')
     for i, (text, missingWord) in enumerate(self.field.parts):
         if text:
             html.append(text)
         if missingWord:
             words += "'" + missingWord + "',"
             inputHtml = [
                 ' <input type="text" value="" ',
                 '        id="clozeBlank%s.%s"' % (self.id, i),
                 '    autocomplete="off"',
                 '    style="width:%sem"/>\n' % len(missingWord)]
             if self.field.instantMarking:
                 inputHtml.insert(2, '  onKeyUp="onClozeChange(this)"')
             html += inputHtml
             html += [
                 '<span style="display: none;" ',
                 'id="clozeAnswer%s.%s">%s</span>' % (
                     self.id, i, encrypt(missingWord))]
     html += ['<p id="clozeScore%s"></p>' % self.id]
     html += ['<div class="block">\n']
     if self.field.instantMarking:
         html += ['<input type="button" ',
                  'value="%s"' % _(u"Get score"),
                  'id="getScore%s"' % self.id,
                  'onclick="showClozeScore(\'%s\')"/>\n' % (self.id)]
         if feedbackId is not None:
             html += [common.feedbackButton('feedback'+self.id, 
                          _(u"Show/Hide Feedback"),
                          style="margin: 0;",
                          onclick="toggleClozeFeedback('%s')" % self.id)]
         style = 'display: inline;'
         value = _(u"Show/Clear Answers")
         onclick = "toggleClozeAnswers('%s')" % self.id
     else:
         html += [common.button('submit%s' % self.id,
                     _(u"Submit"),
                     id='submit%s' % self.id,
                     onclick="clozeSubmit('%s')" % self.id),
                  common.button(
                     'restart%s' % self.id,
                     _(u"Restart"),
                     id='restart%s' % self.id,
         style="display: none;",
                     onclick="clozeRestart('%s')" % self.id),
                  ]
         style = 'display: none;'
         value = _(u"Show Answers")
         onclick = "fillClozeInputs('%s')" % self.id
     html += ['&nbsp;&nbsp;',
              common.button(
                 '%sshowAnswersButton' % self.id,
                 value,
                 id='showAnswersButton%s' % self.id,
                 style=style,
                 onclick=onclick),
     ]
     html += ['</div>\n']
     return '\n'.join(html) + '</div>'
Esempio n. 18
0
 def render_GET(self, request):
     """Called for all requests to this object"""
     
     # Processing 
     log.debug("render_GET")
     self.process(request)
     
     # Rendering
     html  = common.docType()
     html += "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
     html += "<head>\n"
     html += "<style type=\"text/css\">\n"
     html += "@import url(/css/exe.css);\n"
     html += '@import url(/style/base.css);\n'
     html += "@import url(/style/standardwhite/content.css);</style>\n"
     html += '<script type="text/javascript" src="/scripts/libot_drag.js">'
     html += '</script>\n'
     html += '<script type="text/javascript" src="/scripts/common.js">'
     html += '</script>\n'
     html += '<script type="text/javascript" src="/scripts/editor.js">'
     html += '</script>\n'
     html += "<title>"+_("eXe : elearning XHTML editor")+"</title>\n"
     html += "<meta http-equiv=\"content-type\" content=\"text/html; "
     html += " charset=UTF-8\"></meta>\n";
     html += "</head>\n"
     html += "<body>\n"
     html += "<div id=\"main\"> \n"     
     html += "<form method=\"post\" action=\""+self.url+"\" "
     html += "id=\"contentForm\" >"  
     html += common.hiddenField("action")
     html += common.hiddenField("object")
     html += common.hiddenField("isChanged", "1") 
     html += "<font color=\"red\"><b>"+self.message+"</b></font>"
     html += "<div id=\"editorButtons\"> \n"     
     html += self.renderList()
     html += self.editorPane.renderButtons(request, self.showHide)
     if self.isNewIdevice:
         html += "<br/>" + common.submitButton("delete", _("Delete"), 
                                                     False)
     else:
         html += "<br/>" + common.submitButton("delete", _("Delete"))
     html += '<br/><input class="button" type="button" name="save" '
     title = "none"
     if self.editorPane.idevice.edit == False:
         title = self.editorPane.idevice.title
         title = title.replace(" ", "+")
     html += 'onclick=saveIdevice("%s") value="%s"/>' % (escape(title), _("Save"))
     html += u'<br/><input class="button" type="button" name="import" ' 
     if self.showHide:
         html += ' disabled="disabled" '
     html += u' onclick="importPackage(\'package\')" value="%s" />'  % _("Import iDevice")
     html += u'<br/><input class="button" type="button" name="export" '
     if self.showHide:
         html += ' disabled="disabled" '
     html += u'onclick="exportPackage(\'package\',\'%d\')"' % self.isNewIdevice
     html += u' value="%s" />'  % _("Export iDevice")
     #JR: anado un boton que permite mostrar u ocultar iDevices
     if self.showHide:
         html += "<br/>" + common.submitButton("showHide", _("Show/Hide"), False)
     else:
         html += "<br/>" + common.submitButton("showHide", _("Show/Hide"))
     html += u'<br/><input class="button" type="button" name="quit" '
     html += u'onclick=JavaScript:window.close()'         
     html += u' value="%s" />\n'  % _("Quit")
     html += common.hiddenField("pathpackage")
     html += "</fieldset>"
     html += "</div>\n"
     #if ("showHide" in request.args):
     if self.showHide:  
         html += self.editorPane.renderShowHideiDevices(self.ideviceStore.getFactoryIdevices())
     else:
         html += self.editorPane.renderIdevice(request)
     html += "</div>\n"
     html += "<br/></form>\n"
     html += "</body>\n"
     html += "</html>\n"
     return html.encode('utf8')
Esempio n. 19
0
    def render_GET(self, request=None):
        """
        Returns an XHTML string for viewing this page
        if 'request' is not passed, will generate psedo/debug html
        """
        log.debug(u"render_GET " + repr(request))

        topNode = self.package.root
        if request is not None:
            # Process args
            for key, value in request.args.items():
                request.args[key] = [unicode(value[0], 'utf8')]
            topNode = self._process(request)

        #Update other authoring pages that observes the current package
        activeClient = None
        if "action" in request.args:
            if request.args['clientHandleId'][0] == "":
                raise (Exception("Not clientHandleId defined"))
            for client in self.parent.clientHandleFactory.clientHandles.values(
            ):
                if request.args['clientHandleId'][0] != client.handleId:
                    if client.handleId in self.parent.authoringPages:
                        destNode = None
                        if request.args["action"][0] == "move":
                            destNode = request.args[
                                "move" + request.args["object"][0]][0]
                        client.call('eXe.app.getController("MainTab").updateAuthoring', request.args["action"][0], \
                            request.args["object"][0], request.args["isChanged"][0], request.args["currentNode"][0], destNode)
                else:
                    activeClient = client

            if request.args["action"][0] == "done":
                if activeClient:
                    return "<body onload='location.replace(\"" + request.path + "?clientHandleId=" + activeClient.handleId + "\")'/>"
                else:
                    log.error("No active client")

        self.blocks = []
        self.__addBlocks(topNode)
        html = self.__renderHeader()
        html += u'<body onload="onLoadHandler();" class="exe-authoring-page js">\n'
        html += u"<form method=\"post\" "

        if request is None:
            html += u'action="NO_ACTION"'
        else:
            html += u"action=\"" + request.path + "#currentBlock\""
        html += u" id=\"contentForm\">"
        html += u'<div id="main">\n'
        html += common.hiddenField(u"action")
        html += common.hiddenField(u"object")
        html += common.hiddenField(u"isChanged", u"0")
        html += common.hiddenField(u"currentNode", unicode(topNode.id))
        html += common.hiddenField(u'clientHandleId',
                                   request.args['clientHandleId'][0])
        html += u'<!-- start authoring page -->\n'
        html += u'<div id="nodeDecoration">\n'
        html += u'<div id="headerContent">\n'
        html += u'<h1 id="nodeTitle">'
        html += escape(topNode.titleLong)
        html += u'</h1>\n'
        html += u'</div>\n'
        html += u'</div>\n'
        counter = 0
        msg = ''
        for block in self.blocks:
            # If we don't have a client, try to get it from request
            if activeClient is None:
                for client in self.parent.clientHandleFactory.clientHandles.values(
                ):
                    if request.args['clientHandleId'][0] == client.handleId:
                        activeClient = client

            if not activeClient is None:
                for resources in block.idevice.userResources:
                    if resources.warningMsg != u'':
                        counter += 1
                        msg += (_('Warning: %s') % resources.warningMsg)
                        # Remove warning message
                        resources.warningMsg = ''
            if counter > 0:
                activeClient.alert(msg)
            html += block.render(self.package.style)

        html += u'</div>'
        style = G.application.config.styleStore.getStyle(self.package.style)

        html += common.renderLicense(self.package.license, "authoring")
        html += common.renderFooter(self.package.footer)

        if style.hasValidConfig:
            html += style.get_edition_extra_body()
        html += '<script type="text/javascript">$exeAuthoring.ready()</script>\n'
        html += common.footer()

        html = html.encode('utf8')
        return html
Esempio n. 20
0
    def renderView(self, feedbackId=None, preview=False):
        
        # Shows the text with inputs for the missing parts
       

        if preview: 
            # to render, use the content with the preview-able resource paths:
            self.field.encodedContent = self.field.content_w_resourcePaths
        else:
            # to render, use the flattened content, withOUT resource paths: 
            self.field.encodedContent = self.field.content_wo_resourcePaths

        html = ['<div id="cloze%s">' % self.id]
        # Store our args in some hidden fields
        def storeValue(name):
            value = str(bool(getattr(self.field, name))).lower()
            return common.hiddenField('clozeFlag%s.%s' % (self.id, name), value)
        #html.append(storeValue('showScore'))
      
        if feedbackId:
            html.append(common.hiddenField('clozeVar%s.feedbackId' % self.id,
                                           'ta'+feedbackId))
        # Mix the parts together
        words = ""
        wordslista='<option selected="selected" > </option>'
        wordsarray=[]
        listaotras=[]
        listaotras2=[]
        wordsarraylimpo=[] 
        
        # 
        for i, (text, missingWord) in enumerate(self.field.parts):
            if missingWord:
                wordsarray.append([missingWord])
        listaotras=self.field.otras.split('|')
        for i, (missingWord) in enumerate(listaotras):
            if missingWord:
                listaotras2.append([missingWord])
        wordsarray=wordsarray + listaotras2 
        wordsarraylimpo= [wordsarray[i] for i in range(len(wordsarray)) if wordsarray[i] not in wordsarray[:i]]
        random.shuffle(wordsarraylimpo)
        for wdlista in wordsarraylimpo:
           wordslista +='<option value="%s">%s</option>' %(wdlista[0], wdlista[0])
          
        #
        for i, (text, missingWord) in enumerate(self.field.parts):
            if text:
                html.append(text)
            if missingWord:
                words += "'" + missingWord + "',"
                # The edit box for the user to type into
                inputHtml = [
                    '<select id="clozeBlank%s.%s">' % (self.id, i),                        
                     wordslista,
                    '</select>']
                html += inputHtml
                            
                # Hidden span with correct answer
                html += [
                    '<span style="display: none;" ',
                    'id="clozeAnswer%s.%s">%s</span>' % (
                    self.id, i, self.ecrypt(missingWord))]

        # Score string
        html += ['<div class="block">\n']
        
       
        html += [common.button('submit%s' % self.id,
                    _(u"Check"),
                    id='submit%s' % self.id,
                    onclick="clozeSubmit('%s')" % self.id),
                  common.button('submit%s' % self.id,
                    _(u"Check"),
                    id='restart%s' % self.id,                   
                    style="display: none;",
                    onclick="clozeSubmit('%s')" % self.id),
                ]
        
        codotras=self.ecrypt(self.field.otras)
        html += [common.hiddenField('clozeOtras%s' % self.id,codotras)]   
        html += ['<input type="hidden" name="clozeFlag%s.strictMarking" id="clozeFlag%s.strictMarking" value="false"/>' % (self.id,self.id)]
        html += ['<input type="hidden" name="clozeFlag%s.checkCaps" id="clozeFlag%s.checkCaps" value="false"/>' % (self.id,self.id)]
        html += ['<input type="hidden" name="clozeFlag%s.instantMarking" id="clozeFlag%s.instantMarking" value="false"/>' % (self.id,self.id)]
       
        html += ['<div id="clozeScore%s"></div>' % self.id]
        html += ['</div>\n']
        return '\n'.join(html) + '</div>'