def __init__(self, *args, **kwargs): super(ImageEditor, self).__init__(*args, **kwargs) self["class"].append("imageeditor") self["style"]["display"] = "none" self.widthInput = html5.Input() self.widthInput["type"] = "number" self.appendChild(self.widthInput) l = html5.Label(translate("Width"), self.widthInput) l["class"].append("widthlbl") self.appendChild(l) self.keepAspectRatio = html5.Input() self.keepAspectRatio["type"] = "checkbox" self.appendChild(self.keepAspectRatio) l = html5.Label(translate("Keep aspect ratio"), self.keepAspectRatio) l["class"].append("aspectlbl") self.appendChild(l) self.heightInput = html5.Input() self.heightInput["type"] = "number" self.appendChild(self.heightInput) l = html5.Label(translate("Height"), self.heightInput) l["class"].append("heightlbl") self.appendChild(l) self.titleInput = html5.Input() self.titleInput["type"] = "text" self.appendChild(self.titleInput) l = html5.Label(translate("Title"), self.titleInput) l["class"].append("titlelbl") self.appendChild(l) self.currentElem = None self.sinkEvent("onChange")
def __init__(self, targetNode, *args, **kwargs): super(CreateTablePopup, self).__init__(*args, **kwargs) assert targetNode while not "innerHTML" in dir(targetNode): targetNode = targetNode.parentNode self.targetNode = targetNode self["class"].append("createtable") self.rowInput = html5.Input() self.rowInput["type"] = "number" self.rowInput["value"] = 3 self.appendChild(self.rowInput) l = html5.Label(translate("Rows"), forElem=self.rowInput) l["class"].append("rowlbl") self.appendChild(l) self.colInput = html5.Input() self.colInput["type"] = "number" self.colInput["value"] = 4 self.appendChild(self.colInput) l = html5.Label(translate("Cols"), forElem=self.colInput) l["class"].append("collbl") self.appendChild(l) self.insertHeader = html5.Input() self.insertHeader["type"] = "checkbox" self.appendChild(self.insertHeader) l = html5.Label(translate("Insert Table Header"), forElem=self.insertHeader) l["class"].append("headerlbl") self.appendChild(l) self.appendChild(html5.ext.Button("Cancel", callback=self.doClose)) self.appendChild(html5.ext.Button("Create", callback=self.createTable))
def _renderObject(self, obj, tableIsPrepared=False): """ Renders the object to into the table. Does nothing if the list of _shownFields is empty. :param obj: Dictionary of values for this row :type obj: dict """ if not self._shownFields: return rowIdx = self._model.index(obj) cellIdx = 0 if not tableIsPrepared: self.table.prepareCol(rowIdx, len(self._shownFields) - 1) for field in self._shownFields: if field in self._cellRender.keys(): lbl = self._cellRender[field].render(obj, field) elif field in obj.keys(): lbl = html5.Label(obj[field]) else: lbl = html5.Label("...") self.table.setCell(rowIdx, cellIdx, lbl) cellIdx += 1
def render(self, data, field): if not (self.boneName in self.skelStructure and data and data.get(field)): return html5.Label(conf["empty_value"]) structure = self.skelStructure[self.boneName] val = data[field] try: if structure["date"] and structure["time"]: try: dt = datetime.strptime(val, "%d.%m.%Y %H:%M:%S") except: return html5.TextNode(translate("Error parsing Date")) span = html5.Span() span["class"].append("datetime") dateSpan = html5.Span() dateSpan["class"].append("date") dateSpan.appendChild(html5.TextNode(dt.strftime("%d.%m.%Y"))) timeSpan = html5.Span() timeSpan["class"].append("time") timeSpan.appendChild(html5.TextNode(dt.strftime("%H:%M:%S"))) span.appendChild(dateSpan) span.appendChild(timeSpan) return span elif structure["date"] and not structure["time"]: try: dt = datetime.strptime(val, "%d.%m.%Y") except: return html5.TextNode(translate("Error parsing Date")) dateSpan = html5.Span() dateSpan["class"].append("date") dateSpan.appendChild(html5.TextNode(dt.strftime("%d.%m.%Y"))) return dateSpan elif not structure["date"] and structure["time"]: try: dt = datetime.strptime(val, "%H:%M:%S") except: return html5.TextNode(translate("Error parsing Date")) timeSpan = html5.Span() timeSpan["class"].append("time") timeSpan.appendChild(html5.TextNode(dt.strftime("%H:%M:%S"))) return timeSpan except: #Something got wrong parsing the date return html5.Label(str(val))
def __init__(self): #DOM.setAttribute( self.element, "class", "vi_topbar") super(TopBarWidget, self).__init__() self["class"] = "vi_topbar" anav = html5.Nav() anav["class"].append("iconnav") self.iconnav = html5.Ul() #self.logoContainer = html5.Div() #self.logoContainer["class"].append("logo") #self.appendChild( self.logoContainer ) self.sinkEvent("onClick") self.modulH1 = html5.H1() self.modulH1._setClass("module") self.appendChild(self.modulH1) self.modulContainer = html5.Div() self.modulContainer["class"].append("currentmodul") self.appendChild(self.modulContainer) self.modulImg = html5.Label() self.modulContainer.appendChild(self.modulImg) self.moduleName = html5.Span() self.modulContainer.appendChild(self.moduleName) anav.appendChild(self.iconnav) self.appendChild(anav) DeferredCall(self.setTitle, _delay=500)
def __init__(self, moduleName, boneName, readOnly, verify=True, *args, **kwargs): super(PasswordEditBone, self).__init__(*args, **kwargs) self.boneName = boneName self.readOnly = readOnly self.primeinput = html5.Input() self.primeinput["type"] = "password" self.appendChild(self.primeinput) if verify and not readOnly: lbl = html5.Label(translate("reenter password")) lbl["for"] = (moduleName or "") + "_" + boneName + "_reenterpwd" self.appendChild(lbl) self.secondinput = html5.Input() self.secondinput["type"] = "password" self.secondinput["name"] = lbl["for"] self.appendChild(self.secondinput) else: self.secondinput = None if self.readOnly: self["disabled"] = True
def __init__(self, *args, **kwargs): super(UserLogoutMsg, self).__init__(title=translate("Session terminated"), enableShortcuts=False, *args, **kwargs) self.addClass("userloggedoutmsg") self.isCurrentlyFailed = False self.loginWindow = None self.lastChecked = datetime.now() self.lbl = html5.Label( translate( "Your session was terminated by our server. " "Perhaps your computer fall asleep and broke connection?\n" "Please relogin to continue your mission.")) self.appendChild(self.lbl) self.appendChild( html5.ext.Button(translate("Refresh"), callback=self.startPolling)) self.appendChild( html5.ext.Button(translate("Login"), callback=self.showLoginWindow)) setInterval = eval("window.setInterval") self.interval = setInterval(self.checkForSuspendResume, self.checkIntervall) self.hideMessage()
def __init__(self, moduleName, boneName, readOnly, values, *args, **kwargs): super(SelectMultiEditBone, self).__init__(*args, **kwargs) self.boneName = boneName self.readOnly = readOnly # Compatibility mode if isinstance(values, dict): self.values = [(k, v) for k, v in values.items()] else: self.values = values # Perform valuesOrder list for key, value in self.values: alabel = html5.Label() acheckbox = html5.Input() acheckbox["type"] = "checkbox" acheckbox["name"] = key alabel.appendChild(acheckbox) aspan = html5.Span() aspan.element.innerHTML = value alabel.appendChild(aspan) self.appendChild(alabel) if self.readOnly: self["disabled"] = True
def render(self, data, field): if field in data.keys(): result = html5.Ul() options = {k: v for k, v in self.skelStructure[field]["values"]} for i, fieldKey in enumerate(data[field]): if conf["maxMultiBoneEntries"] and i + 1 > conf[ "maxMultiBoneEntries"]: ali = html5.Li() ali.appendChild( html5.TextNode( translate("and {count} more", count=len(data[field]) - conf["maxMultiBoneEntries"]))) ali["class"].append("selectmulti_more_li") result.appendChild(ali) break ali = html5.Li() ali.appendChild(html5.TextNode(options.get(fieldKey, fieldKey))) ali["Title"] = fieldKey result.appendChild(ali) return result return html5.Label(conf["empty_value"])
def render(self, data, field): if field in data.keys(): can = html5.Div() can["style"]["width"] = "60px" adiv = html5.Div() adiv["style"]["width"] = "10px" adiv["style"]["height"] = "10px" adiv["style"]["background-Color"] = str(data[field]) adiv["style"]["float"] = "left" adiv["style"]["margin-top"] = "6px" adiv["style"]["margin-right"] = "3px" lbl = html5.Label(str(data[field])) can.appendChild(adiv) can.appendChild(lbl) return (can) return (html5.Label(conf["empty_value"]))
def __init__(self, *args, **kwargs): super(LinkEditor, self).__init__(*args, **kwargs) self["class"].append("linkeditor") self["style"]["display"] = "none" self.linkTxt = html5.Input() self.linkTxt["type"] = "text" self.appendChild(self.linkTxt) l = html5.Label(translate("URL"), forElem=self.linkTxt) l["class"].append("urllbl") self.appendChild(l) self.newTab = html5.Input() self.newTab["type"] = "checkbox" self.appendChild(self.newTab) l = html5.Label(translate("New window"), forElem=self.newTab) l["class"].append("newwindowlbl") self.appendChild(l) self.currentElem = None
def __init__(self, listWdg, *args, **kwargs): if not listWdg._structure: return super( SelectFieldsPopup, self ).__init__( title=translate("Select fields"), *args, **kwargs ) self["class"].append("selectfields") self.listWdg = listWdg self.checkboxes = [] ul = html5.Ul() self.appendChild( ul ) for key, bone in self.listWdg._structure: li = html5.Li() ul.appendChild( li ) chkBox = html5.Input() chkBox["type"] = "checkbox" chkBox["value"] = key li.appendChild(chkBox) self.checkboxes.append( chkBox ) if key in self.listWdg.getFields(): chkBox["checked"] = True lbl = html5.Label(bone["descr"],forElem=chkBox) li.appendChild(lbl) # Functions for Selection div = html5.Div() div[ "class" ].append( "selectiontools" ) self.appendChild( div ) self.selectAllBtn = html5.ext.Button( translate( "Select all" ), callback=self.doSelectAll ) self.selectAllBtn[ "class" ].append( "icon" ) self.selectAllBtn[ "class" ].append( "selectall" ) self.unselectAllBtn = html5.ext.Button( translate( "Unselect all" ), callback=self.doUnselectAll ) self.unselectAllBtn[ "class" ].append( "icon" ) self.unselectAllBtn[ "class" ].append( "unselectall" ) self.invertSelectionBtn = html5.ext.Button( translate( "Invert selection" ), callback=self.doInvertSelection ) self.invertSelectionBtn[ "class" ].append( "icon" ) self.invertSelectionBtn[ "class" ].append( "selectinvert" ) div.appendChild(self.selectAllBtn) div.appendChild(self.unselectAllBtn) div.appendChild(self.invertSelectionBtn) # Function for Commit self.cancelBtn = html5.ext.Button( translate( "Cancel" ), callback=self.doCancel) self.cancelBtn["class"].append("btn_no") self.applyBtn = html5.ext.Button( translate( "Apply" ), callback=self.doApply) self.applyBtn["class"].append("btn_yes") self.appendChild(self.applyBtn) self.appendChild(self.cancelBtn)
def getViewElement(self, labelstr, datafield): labelstr = html5.utils.unescape(labelstr) if not datafield: return html5.Label(labelstr) else: aspan = html5.Span() aspan.appendChild(html5.TextNode(labelstr)) aspan["title"] = str(datafield) return aspan
def render(self, data, field): if field in data.keys(): ##multilangs if isinstance(data[field], dict): resstr = "" if "currentlanguage" in conf.keys(): if conf["currentlanguage"] in data[field].keys(): resstr = data[field][conf["currentlanguage"]] else: if data[field].keys().length > 0: resstr = data[field][data[field].keys()[0]] aspan = html5.Span() aspan.appendChild(html5.TextNode(resstr)) aspan["Title"] = str(data[field]) return (aspan) else: # no langobject return html5.Label(str(data[field])) return html5.Label(conf["empty_value"])
def render( self, data, field ): if field in data.keys(): if data and field and field in self.skelStructure: options = {k: v for k, v in self.skelStructure[field]["values"]} aspan = html5.Span() aspan.appendChild(html5.TextNode(options.get(data[field], data[field]))) aspan["Title"]=data[field] return aspan return html5.Label(conf["empty_value"])
def __init__(self, extension, view, module, *args, **kwargs): super(DateRangeFilterPlugin, self).__init__(*args, **kwargs) self.view = view self.extension = extension self.module = module self.mutualExclusiveGroupTarget = "daterange-filter" self.mutualExclusiveGroupKey = extension["target"] self.filterChangedEvent = EventDispatcher("filterChanged") title = html5.H2() title.appendChild(html5.TextNode(extension["name"])) self.appendChild(title) # from daterange value self.beginDatepicker = html5.Input() self.beginDatepicker["type"] = "date" self.beginDatepicker["id"] = "begin-date-%s" % self.extension["target"] self.beginDatepicker["class"] = "js-extended-date-range-filter" beginLabel = html5.Label(translate("Begin date")) beginLabel["for"] = "begin-date-%s" % self.extension["target"] span = html5.Span() span.appendChild(beginLabel) span.appendChild(self.beginDatepicker) self.appendChild(span) # to daterange value self.toDatepicker = html5.Input() self.toDatepicker["type"] = "date" self.toDatepicker["id"] = "to-date-%s" % self.extension["target"] self.toDatepicker[ "class"] = "extended-date-range-filter %s" % self.extension[ "target"] toLabel = html5.Label(translate("End date")) toLabel["for"] = "to-date-%s" % self.extension["target"] span2 = html5.Span() span2.appendChild(toLabel) span2.appendChild(self.toDatepicker) self.appendChild(span2) self.clearButton = html5.ext.Button(translate("Clear filter"), self.clearFilter) self.appendChild(self.clearButton) self.sinkEvent("onChange")
def render(self, data, field): s = conf["empty_value"] if field in data.keys(): try: prec = self.skelStructure[field].get("precision") if prec and data[field] is not None: s = ("%." + str(prec) + "f") % data[field] else: s = str(data[field]) except: s = str(data[field]) return html5.Label(s)
def render(self, data, field): assert field == self.boneName, "render() was called with field %s, expected %s" % ( field, self.boneName) val = data.get(field) lbl = html5.Label() if val is None: lbl.appendChild(conf["empty_value"]) return lbl structure = self.structure[self.boneName] try: if not isinstance(val, list): val = [val] count = 1 else: count = len(val) if conf["maxMultiBoneEntries"] and count >= conf[ "maxMultiBoneEntries"]: val = val[:conf["maxMultiBoneEntries"] - 1] res = "\n".join([ utils.formatString(self.format, x, structure["using"], language=conf["currentlanguage"]) for x in val ]) if conf["maxMultiBoneEntries"] and count >= conf[ "maxMultiBoneEntries"]: res += "\n%s" % translate( "and {count} more", count=count - conf["maxMultiBoneEntries"] - 1) except: # We probably received some garbage print( "%s: RecordViewBoneDelegate.render cannot build relational format, maybe garbage received?" % self.boneName) print(val) res = "" html5.utils.textToHtml(lbl, html5.utils.unescape(res)) return lbl
def __init__(self, moduleName, boneName, readOnly, *args, **kwargs): super(SpatialBone, self).__init__(*args, **kwargs) self.boneName = boneName self.readOnly = readOnly self.latitude = html5.Input() self.longitude = html5.Input() self.latitude["type"] = "number" self.longitude["type"] = "number" self.appendChild(self.latitude) lbl = html5.Label(translate("longitude")) lbl["for"] == moduleName + "_" + boneName + "_longitude" self.appendChild(lbl) self.longitude["name"] = moduleName + "_" + boneName + "_longitude" self.appendChild(self.longitude) if self.readOnly: self["disabled"] = True
def prepareCol(self, row, col): """ Lets hook up the original removeRow function to optionally provide index and checkbox columns. """ super(SelectTable, self).prepareCol(row, col + self._extraCols() - 1) if self.checkboxes: checkbox = html5.Input() checkbox["type"] = "checkbox" checkbox["class"].append("check") checkbox["checked"] = False self["cell"][row][self.checkboxes_col] = checkbox self._checkboxes[row] = checkbox if self.indexes: lbl = html5.Label(str(row + 1)) lbl["class"].append("index") self["cell"][row][self.indexes_col] = lbl self.tableChangedEvent.fire(self, self.getRowCount())
def setData(self, request=None, data=None, ignoreMissing=False, askHierarchyCloning=True): """ Rebuilds the UI according to the skeleton received from server :param request: A finished NetworkService request :type request: NetworkService :type data: dict :param data: The data received """ assert (request or data) if request: data = NetworkService.decode(request) if "action" in data and (data["action"] == "addSuccess" or data["action"] == "editSuccess"): self.modified = False logDiv = html5.Div() logDiv["class"].append("msg") spanMsg = html5.Span() spanMsg.appendChild( html5.TextNode( translate( self.logaction ) ) ) spanMsg["class"].append("msgspan") logDiv.appendChild(spanMsg) if self.module in conf["modules"].keys(): spanMsg = html5.Span() if self.module.startswith( "_" ): spanMsg.appendChild( html5.TextNode( self.key ) ) else: spanMsg.appendChild( html5.TextNode( conf["modules"][self.module]["name"] )) spanMsg["class"].append("modulespan") logDiv.appendChild(spanMsg) if "values" in data.keys() and "name" in data["values"].keys(): spanMsg = html5.Span() name = data["values"].get("name") or data["values"].get("key", "") if isinstance(name, dict): if conf["currentlanguage"] in name.keys(): name = name[conf["currentlanguage"]] else: name = name.values() if isinstance(name, list): name = ", ".join(name) spanMsg.appendChild(html5.TextNode(str(html5.utils.unescape(name)))) spanMsg["class"].append("namespan") logDiv.appendChild(spanMsg) try: self.key = data["values"]["key"] except: self.key = None conf["mainWindow"].log("success",logDiv) if askHierarchyCloning and self.clone: # for lists, which are rootNode entries of hierarchies, ask to clone entire hierarchy if self.applicationType == EditWidget.appList and "rootNodeOf" in conf[ "modules" ][ self.module ]: YesNoDialog( translate( u"Do you want to clone the entire hierarchy?" ), yesCallback=self.doCloneHierarchy, noCallback=self.closeOrContinue ) return # for cloning within a hierarchy, ask for cloning all subentries. elif self.applicationType == EditWidget.appHierarchy: YesNoDialog( translate( u"Do you want to clone all subentries of this item?" ), yesCallback=self.doCloneHierarchy, noCallback=self.closeOrContinue ) return self.closeOrContinue() return #Clear the UI self.clear() self.bones = {} self.views = {} self.containers = {} self.actionbar.resetLoadingState() self.dataCache = data self.modified = False tmpDict = {k: v for k, v in data["structure"]} fieldSets = {} firstCat = None currRow = 0 hasMissing = False defaultCat = conf["modules"][self.module].get("visibleName", self.module) contextVariable = conf["modules"][self.module].get("editContext") if self.mode == "edit" and contextVariable: if not self.context: self.context = {} if "=" in contextVariable: contextVariable, contextKey = contextVariable.split("=", 1) else: contextKey = "key" self.context.update({ contextVariable: data["values"].get(contextKey) }) for key, bone in data["structure"]: cat = defaultCat #meow! if ("params" in bone.keys() and isinstance(bone["params"], dict) and "category" in bone["params"].keys()): cat = bone["params"]["category"] if not cat in fieldSets.keys(): fieldSets[cat] = EditWidgetFieldset(cat) wdgGen = editBoneSelector.select(self.module, key, tmpDict) widget = wdgGen.fromSkelStructure(self.module, key, tmpDict) widget["id"] = "vi_%s_%s_%s_%s_bn_%s" % (self.editIdx, self.module, self.mode, cat, key) if "setContext" in dir(widget) and callable(widget.setContext): widget.setContext(self.context) if "changeEvent" in dir(widget): widget.changeEvent.register(self) descrLbl = html5.Label(key if conf["showBoneNames"] else bone.get("descr", key)) descrLbl["class"].append(key) descrLbl["class"].append(bone["type"].replace(".","_")) # Elements if ("params" in bone.keys() and isinstance(bone["params"], dict) and "elements.source" in bone["params"].keys()): descrLbl.addClass("elements-%s" % bone["params"]["elements.source"]) descrLbl["for"] = "vi_%s_%s_%s_%s_bn_%s" % (self.editIdx, self.module, self.mode, cat, key) if bone["required"] or (bone.get("unique") and bone["error"]): descrLbl["class"].append("is_required") if bone["error"] is not None: descrLbl["class"].append("is_invalid") descrLbl["title"] = bone["error"] fieldSets[ cat ]["class"].append("is_incomplete") # Put info into message center conf["mainWindow"].log("info", "%s: %s" % (bone.get("descr", key), translate(bone["error"]))) hasMissing = True elif bone["error"] is None and not self.wasInitialRequest: descrLbl["class"].append("is_valid") if isinstance(bone["error"], dict): widget.setExtendedErrorInformation(bone["error"]) containerDiv = html5.Div() containerDiv.appendChild(descrLbl) containerDiv.appendChild(widget) if ("params" in bone.keys() and isinstance(bone["params"], dict) and "tooltip" in bone["params"].keys()): containerDiv.appendChild(ToolTip(longText=bone["params"]["tooltip"])) fieldSets[cat]._section.appendChild(containerDiv) containerDiv.addClass("bone", "bone_%s" % key, bone["type"].replace(".","_")) if "." in bone["type"]: for t in bone["type"].split("."): containerDiv["class"].append(t) currRow += 1 self.bones[key] = widget self.containers[key] = containerDiv #Hide invisible bones or logic-flavored bones with their default desire if not bone["visible"] or (bone["params"] and bone["params"].get("logic.visibleIf")): self.containers[key].hide() elif bone["visible"] and not firstCat: firstCat = fieldSets[cat] # NO elif! if bone["params"] and bone["params"].get("logic.readonlyIf"): self.containers[key].disable() # Hide all fieldSets where all fields are invisible for fs in fieldSets.values(): fs.checkVisibility() # Show default category if firstCat: firstCat.removeClass("inactive") firstCat.addClass("active") tmpList = [(k,v) for (k,v) in fieldSets.items()] tmpList.sort(key=lambda x:x[0]) for k, v in tmpList: self.form.appendChild( v ) v._section = None # Views views = conf["modules"][self.module].get("editViews") if self.mode == "edit" and isinstance(views, list): for view in views: vmodule = view.get("module") vvariable = view.get("context") vclass = view.get("class") vtitle = view.get("title") vcolumns = view.get("columns") vfilter = view.get("filter") vactions = view.get("actions") if not vmodule: print("Misconfiured view: %s" % view) continue if vmodule not in conf["modules"]: print("Module '%s' is not described." % vmodule) continue vdescr = conf["modules"][vmodule] fs = EditWidgetFieldset(vmodule, vtitle or vdescr.get("name", vmodule)) fs.addClass("editview", "inactive") if vclass: fs.addClass(*vclass) fieldSets[vmodule] = EditWidgetFieldset(vmodule, vtitle or vdescr.get("name", vmodule)) if vvariable: context = self.context.copy() if self.context else {} if "=" in vvariable: vkey, vvalue = vvariable.split("=", 1) if vvalue[0] == "$": vvalue = data["values"].get(vvalue[1:]) else: vkey = vvariable vvalue = data["values"].get("key") context[vkey] = vvalue else: context = self.context self.views[vmodule] = ListWidget( vmodule, filter=vfilter or vdescr.get("filter", {}), columns=vcolumns or vdescr.get("columns"), context=context, actions=vactions ) fs._section.appendChild(self.views[vmodule]) self.form.appendChild(fs) self.unserialize(data["values"]) if self._hashArgs: #Apply the default values (if any) self.unserialize(self._hashArgs) self._hashArgs = None self._lastData = data if hasMissing and not self.wasInitialRequest: conf["mainWindow"].log("warning",translate("Could not save entry!")) DeferredCall(self.performLogics)
def __init__(self, parent, module, data, using=None, errorInfo=None, *args, **kwargs): """ :param parent: Reference to the RelationalMultiSelectionBone we belong to :type parent: RelationalMultiSelectionBone :param module: Name of the module which references :type module: str :param data: Values of the entry we shall display :type data: dict """ super(RelationalMultiSelectionBoneEntry, self).__init__(*args, **kwargs) self.sinkEvent("onDrop", "onDragOver", "onDragLeave", "onDragStart", "onDragEnd", "onChange") self.relationalBone = parent self.module = module self.data = data self.txtLbl = html5.Label() self.txtLbl["draggable"] = not parent.readOnly self.addClass("selectioncontainer-entry") wrapperDiv = html5.Div() wrapperDiv.appendChild(self.txtLbl) wrapperDiv["class"].append("labelwrapper") if not parent.readOnly: remBtn = html5.ext.Button(translate("Remove"), self.onRemove) remBtn["class"].append("icon") remBtn["class"].append("cancel") wrapperDiv.appendChild(remBtn) self.appendChild(wrapperDiv) if using: self.ie = InternalEdit(using, data["rel"], errorInfo, readOnly=parent.readOnly, defaultCat=parent.usingDescr) self.ie.addClass("relationwrapper") self.appendChild(self.ie) else: self.ie = None # Edit button if (self.relationalBone.destModule in conf["modules"].keys() and ("root" in conf["currentUser"]["access"] or self.relationalBone.destModule + "-edit" in conf["currentUser"]["access"])): self.editBtn = html5.ext.Button(translate("Edit"), self.onEdit) self.editBtn["class"].append("icon") self.editBtn["class"].append("edit") wrapperDiv.appendChild(self.editBtn) else: self.editBtn = None self.updateLabel()
def setData( self, request=None, data=None, ignoreMissing=False ): """ Rebuilds the UI according to the skeleton received from server @param request: A finished NetworkService request @type request: NetworkService @type data: dict @param data: The data received """ assert (request or data) if request: data = NetworkService.decode( request ) try: skelStructure = {k: v for k, v in data["structure"]} except AttributeError: NetworkService.notifyChange(self.module) conf["mainWindow"].removeWidget( self ) return print print("data", data) print("action", data["action"]) if "action" in data and (data["action"] in ["addSuccess", "editSuccess"]): NetworkService.notifyChange(self.module) logDiv = html5.Div() logDiv["class"].append("msg") spanMsg = html5.Span() spanMsg.appendChild( html5.TextNode( translate("Entry saved!") )) spanMsg["class"].append("msgspan") logDiv.appendChild(spanMsg) if self.module in conf["modules"].keys(): spanMsg = html5.Span() spanMsg.appendChild( html5.TextNode( conf["modules"][self.module]["name"] )) spanMsg["class"].append("modulspan") logDiv.appendChild(spanMsg) if "values" in data.keys() and "name" in data["values"].keys(): spanMsg = html5.Span() spanMsg.appendChild( html5.TextNode( str(data["values"]["name"]) )) spanMsg["class"].append("namespan") logDiv.appendChild(spanMsg) conf["mainWindow"].log("success",logDiv) if self.closeOnSuccess: conf["mainWindow"].removeWidget( self ) return self.clear() # self.bones = {} self.reloadData() return self.clear() self.actionbar.resetLoadingState() self.dataCache = data fieldSets = {} cat = "byweek" fs = html5.Fieldset() fs["class"] = cat if cat=="byweek": fs["class"].append("active") fs["name"] = cat legend = html5.Legend() fshref = fieldset_A() fshref.appendChild(html5.TextNode(cat) ) legend.appendChild( fshref ) fs.appendChild(legend) section = html5.Section() fs.appendChild(section) fs._section = section fieldSets[ cat ] = fs self.dtstart = data["values"]["startdate"] startdateLabel = html5.Label("Termin") startdateLabel["class"].append("termin") startdateLabel["class"].append("date") startdate_id = "vi_%s_%s_edit_bn_%s" % ( self.editIdx, self.module, "repeatdate") startdateLabel["for"] = startdate_id startdate = date.DateViewBoneDelegate("termin", "startdate", skelStructure).render(data["values"], "startdate") startdate["id"] = startdate_id containerDiv = html5.Div() containerDiv.appendChild(startdateLabel) containerDiv.appendChild(startdate) containerDiv["class"].append("bone") containerDiv["class"].append("bone_startdate") containerDiv["class"].append("date") fieldSets[ cat ]._section.appendChild( containerDiv ) countLabel = html5.Label("Wiederholungen") countLabel["class"].append("count") countLabel["class"].append("numeric") count_id = "vi_%s_%s_edit_bn_%s" % ( self.editIdx, self.module, "count") countLabel["for"] = count_id self.count = html5.Input() self.count["id"] = count_id containerDiv2 = html5.Div() containerDiv2["class"].append("bone") containerDiv2["class"].append("bone_count") containerDiv2["class"].append("date") containerDiv2.appendChild(countLabel) containerDiv2.appendChild(self.count) # containerDiv3 = html5.Div() # self.byweekday = list() # for key, value in [["MO", "Mo"], ["TU", "Di"], ["TH", "Mi"], ["WE", "Do"], ["FR", "Fr"], ["SA", "Sa"], ["SU", "So"]]: # alabel=html5.Label() # acheckbox=html5.Input() # acheckbox["type"]="checkbox" # acheckbox["name"]=key # alabel.appendChild(acheckbox) # aspan=html5.Span() # aspan.element.innerHTML=value # alabel.appendChild(aspan) # containerDiv3.appendChild(alabel) # containerDiv2["class"].append("bone") # containerDiv2["class"].append("bone_count") # containerDiv2["class"].append("byweekday") # self.byweekday.append(acheckbox) fieldSets[ cat ]._section.appendChild(containerDiv2) # fieldSets[ cat ]._section.appendChild(containerDiv3) for (k,v) in fieldSets.items(): if not "active" in v["class"]: v["class"].append("active") tmpList = [(k,v) for (k,v) in fieldSets.items()] tmpList.sort( key=lambda x:x[0]) for k,v in tmpList: self.form.appendChild( v ) v._section = None
def __init__(self, moduleName, boneName, readOnly, values, *args, **kwargs): super(AccessMultiSelectBone, self).__init__(*args, **kwargs) self.boneName = boneName self.moduleName = moduleName self.readOnly = readOnly print(values) self.values = {k: v for k, v in values} self.modules = {} self.modulesbox = {} self.flags = {} self.sinkEvent("onClick") for value in self.values: module = self.parseskelaccess(value) if not module: self.flags[value] = None elif not module[0] in self.modules.keys(): self.modules[module[0]] = {} # Render static / singleton flags first for flag in sorted(self.flags.keys()): label = html5.Label() checkbox = html5.Input() checkbox["type"] = "checkbox" checkbox["name"] = flag label.appendChild(checkbox) self.flags[flag] = checkbox span = html5.Span() span.appendChild(html5.TextNode(flag)) label.appendChild(span) self.appendChild(label) # Render module access flags then for module in sorted(self.modules.keys()): label = html5.Label() span = html5.Span() span.appendChild(html5.TextNode(module)) label.appendChild(span) ul = html5.Ul() checkbox = html5.Input() checkbox["type"] = "checkbox" checkbox["name"] = module self.modulesbox[module] = checkbox li = html5.Li() li.appendChild(checkbox) ul.appendChild(li) for state in self.states: li = html5.Li() li["class"] = ["access-state", state] # Some modules may not support all states if ("%s-%s" % (module, state)) not in self.values: li["class"].append("disabled") ul.appendChild(li) self.modules[module][state] = li label.appendChild(ul) self.appendChild(label)
def renderStructure(self, readOnly = False): self.bones = {} self.containers = {} tmpDict = {k: v for k, v in self.skelStructure} fieldSets = {} currRow = 0 defaultCat = self.defaultCat firstCat = True for key, bone in self.skelStructure: #Enforcing readOnly mode if readOnly: tmpDict[key]["readonly"] = True cat = defaultCat if ("params" in bone.keys() and isinstance(bone["params"],dict) and "category" in bone["params"].keys()): cat = bone["params"]["category"] if cat is not None and not cat in fieldSets.keys(): fs = html5.Fieldset() fs["class"] = cat if firstCat: fs["class"].append("active") firstCat = False if self.form is self: self.form = html5.Form() self.appendChild(self.form) fieldSets[cat] = EditWidgetFieldset(cat) wdgGen = editBoneSelector.select(self.module, key, tmpDict) widget = wdgGen.fromSkelStructure(self.module, key, tmpDict) widget["id"] = "vi_%s_%s_%s_%s_bn_%s" % (self.editIdx, None, "internal", cat or "empty", key) descrLbl = html5.Label(bone["descr"]) descrLbl["class"].append(key) descrLbl["class"].append(bone["type"].replace(".","_")) descrLbl["for"] = "vi_%s_%s_%s_%s_bn_%s" % ( self.editIdx, None, "internal", cat or "empty", key) if bone["required"]: descrLbl["class"].append("is_required") if (bone["required"] and (bone["error"] is not None or (self.errorInformation and key in self.errorInformation.keys()))): descrLbl["class"].append("is_invalid") if bone["error"]: descrLbl["title"] = bone["error"] else: descrLbl["title"] = self.errorInformation[ key ] if fieldSets and cat in fieldSets: fieldSets[cat]["class"].append("is_incomplete") if bone["required"] and not (bone["error"] is not None or (self.errorInformation and key in self.errorInformation.keys())): descrLbl["class"].append("is_valid") if "params" in bone.keys() and isinstance(bone["params"], dict) and "tooltip" in bone["params"].keys(): tmp = html5.Span() tmp.appendChild(descrLbl) tmp.appendChild( ToolTip(longText=bone["params"]["tooltip"]) ) descrLbl = tmp self.containers[key] = html5.Div() self.containers[key].appendChild(descrLbl) self.containers[key].appendChild(widget) self.containers[key].addClass("bone", "bone_%s" % key, bone["type"].replace(".","_")) if "." in bone["type"]: for t in bone["type"].split("."): self.containers[key].addClass(t) if cat is not None: fieldSets[cat]._section.appendChild(self.containers[key]) else: self.form.appendChild(self.containers[key]) currRow += 1 self.bones[key] = widget #Hide invisible bones if not bone["visible"]: self.containers[key].hide() if len(fieldSets)==1: for (k,v) in fieldSets.items(): if not "active" in v["class"]: v["class"].append("active") tmpList = [(k,v) for (k,v) in fieldSets.items()] tmpList.sort( key=lambda x:x[0]) for k,v in tmpList: self.form.appendChild( v ) v._section = None
def __init__(self, widget, *args, **kwargs): super(ExportCsvStarter, self).__init__(title=translate("CSV Export")) self.widget = widget if "viur.defaultlangsvalues" in conf["server"].keys(): self.langSelect = html5.Select() self.langSelect["id"] = "lang-select" lbl = html5.Label(translate("Language selection")) lbl["for"] = "lang-select" div = html5.Div() div.appendChild(lbl) div.appendChild(self.langSelect) div.addClass("bone") self.appendChild(div) for key, value in conf["server"]["viur.defaultlangsvalues"].items( ): opt = html5.Option() opt["value"] = key opt.appendChild(html5.TextNode(value)) if key == conf["currentlanguage"]: opt["selected"] = True self.langSelect.appendChild(opt) else: self.langSelect = None # Encoding self.encodingSelect = html5.Select() self.encodingSelect["id"] = "encoding-select" lbl = html5.Label(translate("Encoding")) lbl["for"] = "encoding-select" div = html5.Div() div.appendChild(lbl) div.appendChild(self.encodingSelect) div.addClass("bone") self.appendChild(div) for i, (k, v) in enumerate([("iso-8859-15", "ISO-8859-15"), ("utf-8", "UTF-8")]): opt = html5.Option() opt["value"] = k if i == 0: opt["selected"] = True opt.appendChild(html5.TextNode(v)) self.encodingSelect.appendChild(opt) div = html5.Div() div.addClass("button-container") self.appendChild(div) self.cancelBtn = html5.ext.Button(translate("Cancel"), self.close) div.appendChild(self.cancelBtn) self.exportBtn = html5.ext.Button(translate("Export"), self.onExportBtnClick) div.appendChild(self.exportBtn)
def render( self, data, field ): if field in data.keys(): return html5.Label(translate(str(data[field]))) return html5.Label(conf["empty_value"])