def __init__(self, parent): """ Initialize """ RenderableResource.__init__(self, parent) self.editorPane = EditorPane(self.webServer) self.url = "" self.elements = [] self.isNewIdevice = True self.message = ""
def __init__(self, parent): """ Initialize """ RenderableResource.__init__(self, parent) self.editorPane = EditorPane(self.webServer, self) self.url = "" self.elements = [] self.isNewIdevice = True #JR: Anado esta variable para que los genericos no se puedan previsualizar self.isGeneric = False self.message = ""
def __init__(self, parent): """ Initialize """ RenderableResource.__init__(self, parent) self.editorPane = EditorPane(self.webServer, self) self.url = "" self.elements = [] self.isNewIdevice = True # JR: Anado esta variable para que los genericos no se puedan previsualizar self.isGeneric = False self.message = ""
class EditorPage(RenderableResource): """ The EditorPage is responsible for managing user created iDevices create / edit / delete """ name = "editor" def __init__(self, parent): """ Initialize """ RenderableResource.__init__(self, parent) self.editorPane = EditorPane(self.webServer, self) self.url = "" self.elements = [] self.isNewIdevice = True # JR: Anado esta variable para que los genericos no se puedan previsualizar self.isGeneric = False self.message = "" def getChild(self, name, request): """ Try and find the child for the name given """ if name == "": return self else: return Resource.getChild(self, name, request) def process(self, request): """ Process current package """ log.debug("process " + repr(request.args)) self.editorPane.process(request, "old") if "action" in request.args: if request.args["action"][0] == "changeIdevice": genericIdevices = self.ideviceStore.generic if not self.isNewIdevice: ideviceId = self.editorPane.idevice.id for idevice in genericIdevices: if idevice.id == ideviceId: break copyIdevice = self.editorPane.idevice.clone() self.__saveChanges(idevice, copyIdevice) selected_idevice = request.args["object"][0].decode("utf-8") self.isGeneric = False for idevice in genericIdevices: if idevice.title == selected_idevice: self.isGeneric = True break self.isNewIdevice = False self.editorPane.setIdevice(idevice) self.editorPane.process(request, "new") if ("action" in request.args and request.args["action"][0] == "newIdevice") or "new" in request.args: self.__createNewIdevice(request) if "delete" in request.args: self.ideviceStore.delIdevice(self.editorPane.idevice) # Lo borramos tambien de la lista factoryiDevices idevice = self.editorPane.idevice exist = False for i in self.ideviceStore.getFactoryIdevices(): if i.title == idevice.title: idevice.id = i.id exist = True break if exist: self.ideviceStore.factoryiDevices.remove(idevice) self.ideviceStore.save() self.__createNewIdevice(request) if "action" in request.args and request.args["action"][0] == "new": if self.editorPane.idevice.title == "": self.message = _("Please enter an idevice name.") else: newIdevice = self.editorPane.idevice.clone() # TODO could IdeviceStore set the id in addIdevice??? newIdevice.id = self.ideviceStore.getNewIdeviceId() self.ideviceStore.addIdevice(newIdevice) self.editorPane.setIdevice(newIdevice) self.ideviceStore.save() self.isNewIdevice = False if "action" in request.args and request.args["action"][0] == "save": genericIdevices = self.ideviceStore.generic for idevice in genericIdevices: if idevice.title == self.editorPane.idevice.title: break copyIdevice = self.editorPane.idevice.clone() self.__saveChanges(idevice, copyIdevice) self.ideviceStore.save() if "action" in request.args and request.args["action"][0] == "export": filename = request.args["pathpackage"][0] self.__exportIdevice(filename) if "action" in request.args and request.args["action"][0] == "import": filename = request.args["pathpackage"][0] self.__importIdevice(filename) def __createNewIdevice(self, request): """ Create a new idevice and add to idevicestore """ idevice = GenericIdevice("", "", "", "", "") idevice.icon = "" idevice.id = self.ideviceStore.getNewIdeviceId() self.editorPane.setIdevice(idevice) self.editorPane.process(request, "new") self.isNewIdevice = True def __saveChanges(self, idevice, copyIdevice): """ Save changes to generic idevice list. """ idevice.title = copyIdevice._title idevice.author = copyIdevice._author idevice.purpose = copyIdevice._purpose idevice.tip = copyIdevice._tip idevice.fields = copyIdevice.fields idevice.emphasis = copyIdevice.emphasis idevice.icon = copyIdevice.icon idevice.systemResources = copyIdevice.systemResources def __importIdevice(self, filename): """ import the idevices which are not existed in current package from another package """ try: newPackage = Package.load(filename) except: self.message = _("Sorry, wrong file format.") return if newPackage: newIdevice = newPackage.idevices[-1].clone() for currentIdevice in self.ideviceStore.generic: if newIdevice.title == currentIdevice.title: newIdevice.title += "1" break self.ideviceStore.addIdevice(newIdevice) self.ideviceStore.save() else: self.message = _("Sorry, wrong file format.") def __exportIdevice(self, filename): """ export the current generic idevices. """ if not filename.endswith(".idp"): filename = filename + ".idp" name = Path(filename).namebase package = Package(name) package.idevices.append(self.editorPane.idevice.clone()) package.save(filename) 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/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" ' 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") render_POST = render_GET def renderList(self): """ Render the list of generic iDevice """ html = "<fieldset><legend><b>" + _("Edit") + "</b></legend>" html += '<select onchange="submitIdevice();" name="ideviceSelect" id="ideviceSelect">\n' html += '<option value = "newIdevice" ' if self.isNewIdevice: html += "selected " html += ">" + _("New iDevice") + "</option>" for prototype in self.ideviceStore.generic: html += '<option value="' + prototype.title + '" ' if self.editorPane.idevice.id == prototype.id: html += "selected " title = prototype.title if len(title) > 16: title = title[:16] + "..." html += ">" + title + "</option>\n" html += "</select> \n" html += "</fieldset>\n" self.message = "" return html
class EditorPage(RenderableResource): """ The EditorPage is responsible for managing user created iDevices create / edit / delete """ name = 'editor' def __init__(self, parent): """ Initialize """ RenderableResource.__init__(self, parent) self.editorPane = EditorPane(self.webServer, self) self.url = "" self.elements = [] self.isNewIdevice = True self.showHide = False #JR: Anado esta variable para que los genericos no se puedan previsualizar self.isGeneric = False self.message = "" def getChild(self, name, request): """ Try and find the child for the name given """ if name == "": return self else: return Resource.getChild(self, name, request) def process(self, request): """ Process current package """ log.debug("process " + repr(request.args)) self.editorPane.process(request,"old") if "action" in request.args: if request.args["action"][0] == "changeIdevice": genericIdevices = self.ideviceStore.generic if not self.isNewIdevice: ideviceId = self.editorPane.idevice.id for idevice in genericIdevices: if idevice.id == ideviceId: break copyIdevice = self.editorPane.idevice.clone() self.__saveChanges(idevice, copyIdevice) selected_idevice = request.args["object"][0].decode("utf-8") self.isGeneric = False for idevice in genericIdevices: if idevice.title == selected_idevice: self.isGeneric = True break self.isNewIdevice = False self.editorPane.setIdevice(idevice) self.editorPane.process(request, "new") if (("action" in request.args and request.args["action"][0] == "newIdevice") or "new" in request.args): self.__createNewIdevice(request) if "delete" in request.args: self.ideviceStore.delIdevice(self.editorPane.idevice) self.ideviceStore.save() self.__createNewIdevice(request) if ("action" in request.args and request.args["action"][0] == "new"): if self.editorPane.idevice.title == "": self.message = _("Please enter an idevice name.") else: newIdevice = self.editorPane.idevice.clone() #TODO could IdeviceStore set the id in addIdevice??? newIdevice.id = self.ideviceStore.getNewIdeviceId() self.ideviceStore.addIdevice(newIdevice) self.editorPane.setIdevice(newIdevice) self.ideviceStore.save() self.isNewIdevice = False if ("action" in request.args and request.args["action"][0] == "save"): genericIdevices = self.ideviceStore.generic for idevice in genericIdevices: if idevice.title == self.editorPane.idevice.title: break copyIdevice = self.editorPane.idevice.clone() self.__saveChanges(idevice, copyIdevice) self.ideviceStore.save() if ("action" in request.args and request.args["action"][0] == "export"): filename = request.args["pathpackage"][0] self.__exportIdevice(filename) if ("action" in request.args and request.args["action"][0] == "import"): filename = request.args["pathpackage"][0] self.__importIdevice(filename) if ("action" in request.args and request.args["action"][0] == "saveSH" and self.showHide == True): self.__saveSHiDevices(request) if ("showHide" in request.args): self.showHide = True def __createNewIdevice(self, request): """ Create a new idevice and add to idevicestore """ idevice = GenericIdevice("", "", "", "", "") idevice.icon = "" idevice.id = self.ideviceStore.getNewIdeviceId() self.editorPane.setIdevice(idevice) self.editorPane.process(request, "new") self.isNewIdevice = True self.showHide = False def __saveChanges(self, idevice, copyIdevice): """ Save changes to generic idevice list. """ idevice.title = copyIdevice.title idevice.author = copyIdevice.author idevice.purpose = copyIdevice.purpose idevice.tip = copyIdevice.tip idevice.fields = copyIdevice.fields idevice.emphasis = copyIdevice.emphasis idevice.icon = copyIdevice.icon idevice.systemResources = copyIdevice.systemResources def __importIdevice(self, filename): """ import the idevices which are not existed in current package from another package """ try: newPackage = Package.load(filename) except: self.message = _("Sorry, wrong file format.") return if newPackage: newIdevice = newPackage.idevices[-1].clone() for currentIdevice in self.ideviceStore.generic: if newIdevice.title == currentIdevice.title: newIdevice.title += "1" break self.ideviceStore.addIdevice(newIdevice) self.ideviceStore.save() else: self.message = _("Sorry, wrong file format.") def __exportIdevice(self, filename): """ export the current generic idevices. """ if not filename.endswith('.idp'): filename = filename + '.idp' name = Path(filename).namebase package = Package(name) package.idevices.append(self.editorPane.idevice.clone()) package.save(filename) 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') render_POST = render_GET def renderList(self): """ Render the list of generic iDevice """ html = "<fieldset><legend><b>" + _("Edit")+ "</b></legend>" #JR: Desabilitamos el select si estamos mostrando/ocultando iDevices if self.showHide: html += '<select onchange="submitIdevice();" name="ideviceSelect" id="ideviceSelect" disabled="disabled">\n' else: html += '<select onchange="submitIdevice();" name="ideviceSelect" id="ideviceSelect">\n' html += "<option value = \"newIdevice\" " if self.isNewIdevice: html += "selected " html += ">"+ _("New iDevice") + "</option>" for prototype in self.ideviceStore.generic: html += "<option value=\""+prototype.title+"\" " if self.editorPane.idevice.id == prototype.id: html += "selected " title = prototype.title if len(title) > 16: title = title[:16] + "..." html += ">" + title + "</option>\n" html += "</select> \n" html += "</fieldset>\n" self.message = "" return html def __saveSHiDevices(self, request): """ JR: Esta funcion procesa los iDevices que no se quieren mostrar """ idt_checked = [] for i in request.args.keys(): if (request.args[i] == ['on']): idt_checked.append(i) for i in self.ideviceStore.getFactoryIdevices(): if i.title in idt_checked: self.ideviceStore.delIdevice(i) else: self.ideviceStore.addIdevice(i) """for i in request.args.keys(): if (request.args[i] == ['on']): lista_idevices = self.ideviceStore.getIdevices() generic = self.ideviceStore.generic extended = self.ideviceStore.extended for idevice in lista_idevices: if (idevice.title == i): if (idevice in generic): self.ideviceStore.__delGenericIdevice(idevice) else: self.ideviceStore.delExtendedIdevice(idevice)""" self.ideviceStore.save() self.showHide = False self.__createNewIdevice(request)
class EditorPage(RenderableResource): """ The EditorPage is responsible for managing user created iDevices create / edit / delete """ name = 'editor' def __init__(self, parent): """ Initialize """ RenderableResource.__init__(self, parent) self.editorPane = EditorPane(self.webServer) self.url = "" self.elements = [] self.isNewIdevice = True self.message = "" def getChild(self, name, request): """ Try and find the child for the name given """ if name == "": return self else: return Resource.getChild(self, name, request) def process(self, request): """ Process current package """ log.debug("process " + repr(request.args)) self.editorPane.process(request,"old") if "action" in request.args: if request.args["action"][0] == "changeIdevice": genericIdevices = self.ideviceStore.generic if not self.isNewIdevice: ideviceId = self.editorPane.idevice.id for idevice in genericIdevices: if idevice.id == ideviceId: break copyIdevice = self.editorPane.idevice.clone() self.__saveChanges(idevice, copyIdevice) for idevice in genericIdevices: if idevice.title == request.args["object"][0]: break self.isNewIdevice = False self.editorPane.setIdevice(idevice) self.editorPane.process(request, "new") if (("action" in request.args and request.args["action"][0] == "newIdevice") or "new" in request.args): self.__createNewIdevice(request) if "delete" in request.args: self.ideviceStore.delGenericIdevice(self.editorPane.idevice) self.ideviceStore.save() self.__createNewIdevice(request) if ("action" in request.args and request.args["action"][0] == "new"): if self.editorPane.idevice.title == "": self.message = _("Please enter an idevice name.") else: newIdevice = self.editorPane.idevice.clone() newIdevice.id = self.ideviceStore.getNewIdeviceId() self.ideviceStore.addIdevice(newIdevice) self.editorPane.setIdevice(newIdevice) self.ideviceStore.save() self.isNewIdevice = False if ("action" in request.args and request.args["action"][0] == "save"): genericIdevices = self.ideviceStore.generic for idevice in genericIdevices: if idevice.title == self.editorPane.idevice.title: break copyIdevice = self.editorPane.idevice.clone() self.__saveChanges(idevice, copyIdevice) self.ideviceStore.save() if ("action" in request.args and request.args["action"][0] == "export"): filename = request.args["pathpackage"][0] self.__exportIdevice(filename) if ("action" in request.args and request.args["action"][0] == "import"): filename = request.args["pathpackage"][0] self.__importIdevice(filename) def __createNewIdevice(self, request): """ Create a new idevice and add to idevicestore """ idevice = GenericIdevice("", "", "", "", "") idevice.icon = "" idevice.id = self.ideviceStore.getNewIdeviceId() self.editorPane.setIdevice(idevice) self.editorPane.process(request, "new") self.isNewIdevice = True def __saveChanges(self, idevice, copyIdevice): """ Save changes to generic idevice list. """ idevice.title = copyIdevice.title idevice.author = copyIdevice.author idevice.purpose = copyIdevice.purpose idevice.tip = copyIdevice.tip idevice.fields = copyIdevice.fields idevice.emphasis = copyIdevice.emphasis idevice.icon = copyIdevice.icon def __importIdevice(self, filename): """ import the idevices which are not existed in current package from another package """ newPackage = Package.load(filename) for idevice in newPackage.idevices: isExisted = False for currentIdevice in self.ideviceStore.generic: if idevice.title == currentIdevice.title: isExisted = True break if not isExisted: newIdevice = idevice.clone() self.ideviceStore.addIdevice(newIdevice) self.ideviceStore.save() def __exportIdevice(self, filename): """ export the current generic idevices. """ if not filename.endswith('.idp'): filename = filename + '.idp' name = Path(filename).namebase package = Package(name) for idevice in self.ideviceStore.generic: package.idevices.append(idevice.clone()) package.save(filename) 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 iDevices") html += u'<br/><input class="button" type="button" name="export" onclick="exportPackage(\'package\')"' html += u' value="%s" />' % _("Export iDevices") 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') render_POST = render_GET def renderList(self): """ Render the list of generic iDevice """ html = "<fieldset><legend><b>" + _("Edit")+ "</b></legend>" html += '<select onchange="submitIdevice();" name="ideviceSelect" id="ideviceSelect">\n' html += "<option value = \"newIdevice\" " if self.isNewIdevice: html += "selected " html += ">"+ _("New iDevice") + "</option>" for prototype in self.ideviceStore.generic: html += "<option value=\""+prototype.title+"\" " if self.editorPane.idevice.id == prototype.id: html += "selected " title = prototype.title if len(title) > 16: title = title[:16] + "..." html += ">" + title + "</option>\n" html += "</select> \n" html += "</fieldset>\n" self.message = "" return html
class EditorPage(RenderableResource): """ The EditorPage is responsible for managing user created iDevices create / edit / delete """ name = "editor" def __init__(self, parent): """ Initialize """ RenderableResource.__init__(self, parent) self.editorPane = EditorPane(self.webServer) self.url = "" self.elements = [] self.isNewIdevice = True self.message = "" def getChild(self, name, request): """ Try and find the child for the name given """ if name == "": return self else: return Resource.getChild(self, name, request) def process(self, request): """ Process current package """ log.debug("process " + repr(request.args)) self.editorPane.process(request, "old") if "action" in request.args: if request.args["action"][0] == "changeIdevice": genericIdevices = self.ideviceStore.generic if not self.isNewIdevice: ideviceId = self.editorPane.idevice.id for idevice in genericIdevices: if idevice.id == ideviceId: break copyIdevice = self.editorPane.idevice.clone() self.__saveChanges(idevice, copyIdevice) for idevice in genericIdevices: if idevice.id == request.args["object"][0]: break self.isNewIdevice = False self.editorPane.setIdevice(idevice) self.editorPane.process(request, "new") if ("action" in request.args and request.args["action"][0] == "newIdevice") or "new" in request.args: self.__createNewIdevice(request) if "delete" in request.args: self.ideviceStore.delGenericIdevice(self.editorPane.idevice) self.ideviceStore.save() self.__createNewIdevice(request) if "add" in request.args: if self.editorPane.idevice.title == "": self.message = _("Please enter an idevice name.") else: newIdevice = self.editorPane.idevice.clone() newIdevice.id = self.ideviceStore.getNewIdeviceId() self.ideviceStore.addIdevice(newIdevice) self.editorPane.setIdevice(newIdevice) self.ideviceStore.save() self.isNewIdevice = False if "save" in request.args: genericIdevices = self.ideviceStore.generic for idevice in genericIdevices: if idevice.id == self.editorPane.idevice.id: break copyIdevice = self.editorPane.idevice.clone() self.__saveChanges(idevice, copyIdevice) def __createNewIdevice(self, request): """ Create a new idevice and add to idevicestore """ idevice = GenericIdevice("", "", "", "", "") idevice.icon = "" idevice.id = self.ideviceStore.getNewIdeviceId() self.editorPane.setIdevice(idevice) self.editorPane.process(request, "new") self.isNewIdevice = True def __saveChanges(self, idevice, copyIdevice): """ Save changes to generic idevice list. """ idevice.title = copyIdevice.title idevice.author = copyIdevice.author idevice.purpose = copyIdevice.purpose idevice.tip = copyIdevice.tip idevice.fields = copyIdevice.fields idevice.emphasis = copyIdevice.emphasis idevice.icon = copyIdevice.icon 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") render_POST = render_GET def renderList(self): """ Render the list of generic iDevice """ html = "<fieldset><legend><b>" + _("Edit") + "</b></legend>" html += '<select onchange="submitIdevice();" name="ideviceSelect">\n' html += '<option value = "newIdevice" ' if self.isNewIdevice: html += "selected " html += ">" + _("New iDevice") + "</option>" for prototype in self.ideviceStore.generic: html += '<option value="' + prototype.id + '" ' if self.editorPane.idevice.id == prototype.id: html += "selected " title = prototype.title if len(title) > 16: title = title[:16] + "..." html += ">" + title + "</option>\n" html += "</select> \n" html += "</fieldset>\n" self.message = "" return html