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.popupBody.appendChild(self.lbl) self.popupFoot.appendChild( html5.ext.Button(translate("Refresh"), callback=self.startPolling)) self.popupFoot.appendChild( html5.ext.Button(translate("Login"), callback=self.showLoginWindow)) setInterval = html5.window.setInterval self.interval = setInterval(self.checkForSuspendResume, self.checkIntervall) self.hideMessage()
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 __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.addClass("select") self.langSelect["id"] = "lang-select" lbl = html5.Label(translate("Language selection")) lbl.addClass("label") lbl["for"] = "lang-select" div = html5.Div() div.appendChild(lbl) div.appendChild(self.langSelect) div.addClass("input-group") self.popupBody.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.addClass("select") self.encodingSelect["id"] = "encoding-select" lbl = html5.Label(translate("Encoding")) lbl.addClass("label") lbl["for"] = "encoding-select" div = html5.Div() div.appendChild(lbl) div.appendChild(self.encodingSelect) div.addClass("input-group") self.popupBody.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) self.cancelBtn = Button(translate("Cancel"), self.close, icon="icons-cancel") self.popupFoot.appendChild(self.cancelBtn) self.exportBtn = Button(translate("Export"), self.onExportBtnClick, icon="icons-download-file") self.exportBtn.addClass("btn--edit") self.popupFoot.appendChild(self.exportBtn)
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" fieldSets[cat] = EditWidgetFieldset(cat) fieldSets[cat].addClass("active") 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, listWdg, *args, **kwargs): if not listWdg._structure: return super(SelectFieldsPopup, self).__init__(title=translate("Select fields"), *args, **kwargs) self.removeClass("popup--center") self.addClass("popup--n popup--selectfields") self.listWdg = listWdg self.checkboxes = [] ul = html5.Ul() ul.addClass("option-group") self.popupBody.appendChild(ul) for key, bone in self.listWdg._structure: li = html5.Li() li.addClass("check") ul.appendChild(li) chkBox = html5.Input() chkBox.addClass("check-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) lbl.addClass("check-label") li.appendChild(lbl) # Functions for Selection div = html5.Div() div["class"].append("selectiontools input-group") self.popupBody.appendChild(div) self.selectAllBtn = Button(translate("Select all"), callback=self.doSelectAll) self.selectAllBtn["class"].append("btn--selectall") self.unselectAllBtn = Button(translate("Unselect all"), callback=self.doUnselectAll) self.unselectAllBtn["class"].append("btn--unselectall") self.invertSelectionBtn = Button(translate("Invert selection"), callback=self.doInvertSelection) self.invertSelectionBtn["class"].append("btn--selectinvert") div.appendChild(self.selectAllBtn) div.appendChild(self.unselectAllBtn) div.appendChild(self.invertSelectionBtn) # Function for Commit self.cancelBtn = Button(translate("Cancel"), callback=self.doCancel) self.cancelBtn.addClass("btn btn--danger") self.applyBtn = Button(translate("Apply"), callback=self.doApply) self.applyBtn.addClass("btn btn--primary") self.popupFoot.appendChild(self.cancelBtn) self.popupFoot.appendChild(self.applyBtn)
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 try: self.key = data["values"]["key"] except: self.key = None conf["mainWindow"].log("success",translate(self.logAction),modul=self.module,key=self.key,action=self.mode,data=data) 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 ]: html5.ext.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: html5.ext.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.desciptionLabels = {} self.actionbar.resetLoadingState() self.dataCache = data self.modified = False tmpDict = {k: v for k, v in data["structure"]} segments = {} firstCat = None currRow = 0 hasMissing = False defaultCat = conf["modules"][self.module].get("visibleName", self.module) adminCat = conf["modules"][self.module].get("defaultCategory",None) 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) }) errors = {} if conf["core.version"][0] == 3: for error in data["errors"]: errors[error["fieldPath"]] = error self.accordion.clearSegments() for key, bone in data["structure"]: if key in errors: bone["error"] = errors[key] else: bone[ "error" ] = None cat = defaultCat #meow! if ("params" in bone.keys() and isinstance(bone["params"], dict) and "category" in bone["params"].keys()): cat = bone["params"]["category"] if cat not in segments: segments[cat] = self.accordion.addSegment(cat) boneFactory = boneSelector.select(self.module, key, tmpDict)(self.module, key, tmpDict) widget = boneFactory.editWidget() 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.addClass("label", "vi-label", "vi-label--%s" % bone["type"].replace(".","-"), "vi-label--%s" % key) # Elements (TEMP TEMP TEMP) 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"]) # /Elements (TEMP TEMP TEMP) 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"]) or \ (bone["error"] and isinstance(bone["error"],str) and "dependency error:" in bone["error"]): descrLbl.addClass("is-required") if bone["error"] and ( (bone["error"]["severity"]%2==0 and bone["required"]) or\ (bone["error"]["severity"]%2 == 1) ): #todo if severity = 1 dependency error, we need to mark futher bones descrLbl.addClass("is-invalid") descrLbl["title"] = bone["error"] segments[cat].addClass("is-incomplete is-active") hasMissing = True elif not self.wasInitialRequest: # descrLbl.addClass( "is-valid" ) else: pass # first Call no highlighting 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(shortText=key if conf["showBoneNames"] else bone.get("descr", key), longText=bone["params"]["tooltip"])) segments[cat].addWidget(containerDiv) containerDiv.addClass("vi-bone", "vi-bone--%s" % bone["type"].replace(".","-"), "vi-bone--%s" % key) if "." in bone["type"]: for t in bone["type"].split("."): containerDiv.addClass("vi-bone--%s" % t) currRow += 1 self.bones[key] = widget self.containers[key] = containerDiv self.desciptionLabels[key] = descrLbl #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 and not adminCat: firstCat = segments[cat] elif adminCat and cat == adminCat: firstCat = segments[cat] # NO elif! if bone["params"] and bone["params"].get("logic.readonlyIf"): self.containers[key].disable() # Hide all segments where all fields are invisible for fs in segments.values(): fs.checkVisibility() # Show default category if firstCat: firstCat.activate() self.accordion.buildAccordion("asc") # order and add to dom # 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") 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] if vmodule not in segments: segments[vmodule] = self.accordion.addSegment(vmodule, vtitle or vdescr.get("name", vmodule),directAdd=True) segments[vmodule].addClass("editview") if vclass: segments[vmodule].addClass(*vclass) if vvariable: context = self.context.copy() if self.context else {} context[vvariable] = data["values"]["key"] else: context = self.context self.views[vmodule] = ListWidget(vmodule, filter=vfilter or vdescr.get("filter", {}), columns = vcolumns or vdescr.get("columns"), context = context) segments[vmodule].addWidget(self.views[vmodule]) 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!"),icon="icons-cancel",modul=self.module,key=self.key,action=self.mode,data=data) DeferredCall(self.performLogics)
def renderStructure(self, readOnly=False): self.bones = {} self.containers = {} tmpDict = {k: v for k, v in self.skelStructure} segments = {} currRow = 0 defaultCat = self.defaultCat firstCat = None errors = {} if conf["core.version"][0] == 3 and self.errorInformation: for error in self.errorInformation: errors[error["fieldPath"]] = error["errorMessage"] 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 segments.keys(): if self.accordion is None: self.accordion = Accordion() self.appendChild(self.accordion) segments[cat] = self.accordion.addSegment(cat, directAdd=True) if not firstCat: firstCat = segments[cat] boneFactory = boneSelector.select(self.module, key, tmpDict)(self.module, key, tmpDict) widget = boneFactory.editWidget() widget["id"] = "vi_%s_%s_%s_%s_bn_%s" % ( self.editIdx, None, "internal", cat or "empty", key) descrLbl = html5.Label(bone["descr"]) descrLbl.addClass("label", "vi-label", "vi-label--%s" % bone["type"].replace(".", "-"), "vi-label--%s" % key) 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 key in errors: bone["error"] = errors[key] if (bone["required"] and "error" in bone 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 segments and cat in segments: segments[cat]["class"].append("is-incomplete") if bone["required"] and "error" in bone 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( "vi-bone", "vi-bone--%s" % bone["type"].replace(".", "-"), "vi-bone--%s" % key) if "." in bone["type"]: for t in bone["type"].split("."): self.containers[key].addClass(t) if cat is not None: segments[cat].addWidget(self.containers[key]) else: self.appendChild(self.containers[key]) currRow += 1 self.bones[key] = widget #Hide invisible bones if not bone["visible"]: self.containers[key].hide() print(self.boneparams) if self.boneparams and "vi.style.rel.categories" in self.boneparams and self.boneparams[ "vi.style.rel.categories"] == "collapsed": pass else: if firstCat: firstCat.activate()