Пример #1
0
    def log(self, type, msg, icon=None, date=None):
        """
			Adds a message to the log
			:param type: The type of the message.
			:type type: "success", "error", "warning", "info", "progress"
			:param msg: The message to append
			:type msg: str
		"""
        assert type in ["success", "error", "warning", "info", "progress"]

        msgWrap = html5.Li()
        msgWrap.addClass("msg--" + type, "msg", "is-active")
        msgWrap.addClass("is-new popup popup--s")

        if icon:
            svg = embedsvg.get(icon)
        else:
            svg = embedsvg.get("icons-%s" % type)

        if not svg:
            svg = embedsvg.get("icons-message-news")

        if svg:
            msgWrap.element.innerHTML = svg + msgWrap.element.innerHTML

        msgContent = html5.Div()
        msgContent.addClass("msg-content")
        msgWrap.appendChild(msgContent)
        if not date:
            adate = datetime.now().strftime("%d. %b. %Y, %H:%M:%S")
        else:
            adate = date
        msgDate = html5.Span()
        msgDate.appendChild(html5.TextNode(adate))
        msgDate.addClass("msg-date")
        msgContent.appendChild(msgDate)

        if isinstance(msg, html5.Widget):
            #Append that widget directly
            msgContent.appendChild(msg)

        else:
            #Create a span element for that message
            msgDescr = html5.Span()
            msgDescr.appendChild(html5.TextNode(html5.utils.unescape(msg)))
            msgDescr.addClass("msg-descr")
            msgContent.appendChild(msgDescr)

        DeferredCall(self.removeNewCls, msgWrap, _delay=2500)
        self.logUL.appendChild(msgWrap)

        if len(self.logUL._children) > 1:
            self.logUL.element.removeChild(msgWrap.element)
            self.logUL.element.insertBefore(
                msgWrap.element, self.logUL.element.children.item(0))
Пример #2
0
    def __init__(self):
        super(Log, self).__init__()

        self.addClass("vi-messenger")
        openLink = html5.ext.Button(translate("Open message center"),
                                    self.toggleMsgCenter)
        self.appendChild(openLink)

        self.logUL = html5.Ul()
        self.logUL["id"] = "statuslist"
        self.logUL.addClass("statuslist")
        self.appendChild(self.logUL)

        versionDiv = html5.Div()
        versionDiv.addClass("versiondiv")

        # Server name and version number
        name = conf["vi.viur"]
        if name:
            versionspan = html5.Span()
            versionspan.appendChild(
                "%s v%s" %
                (name, ".".join([str(x) for x in conf["core.version"]])))
            versionspan.addClass("serverspan")
            versionDiv.appendChild(versionspan)

        # Vi name and version number
        name = conf["vi.name"]
        if name:
            versionspan = html5.Span()
            versionspan.appendChild("%s v%s%s" % (name, ".".join(
                [str(x)
                 for x in conf["vi.version"]]), conf["vi.version.appendix"]))
            versionspan.addClass("versionspan")

            versionDiv.appendChild(versionspan)
            ''' fixme ... VI3.0
			revspan = html5.Span()
			revspan.appendChild(html5.TextNode("Rev %s" % revision))
			revspan.addClass("revisionspan")

			datespan = html5.Span()
			datespan.appendChild(html5.TextNode("Built %s" % builddate))
			datespan.addClass("datespan")

			versionDiv.appendChild(revspan)
			versionDiv.appendChild(datespan)
			'''

        if versionDiv.children():
            self.appendChild(versionDiv)
Пример #3
0
    def invoke(self):
        self.iconnav.removeAllChildren()

        newBtn = html5.A()
        newBtn["href"] = "https://www.viur.is"
        newBtn["target"] = "_blank"
        newBtn.addClass("btn")
        svg = embedsvg.get("icons-ribbon")
        if svg:
            newBtn.element.innerHTML = svg + newBtn.element.innerHTML
        newBtn.appendChild(translate("vi.topbar.newbtn"))
        #self.iconnav.appendChild(newBtn)

        newMarker = html5.Span()
        newMarker.addClass("marker")
        newMarker.appendChild(translate("vi.topbar.new"))
        newBtn.appendChild(newMarker)

        for icon in conf["toplevelactions"]:
            widget = toplevelActionSelector.select(icon)
            # register log Button as Loghandler
            if widget == LogButton:
                conf["mainWindow"].logWdg = widget()
                self.iconnav.appendChild(conf["mainWindow"].logWdg)
            elif widget:
                self.iconnav.appendChild(widget())
Пример #4
0
    def update(self):
        user = conf.get("currentUser")
        if not user:
            NetworkService.request("user",
                                   "view/self",
                                   successHandler=self.onCurrentUserAvailable,
                                   cacheable=False)
            return

        aitem = html5.Div()
        aitem["class"] = ["item", "has-hover", "item--small"]
        # userinfo
        usrinfo = html5.Div()
        usermail = html5.Span()
        usermail.appendChild(html5.TextNode(user["name"]))
        aitem.appendChild(usermail)
        self.popoutlist.appendChild(aitem)

        self["title"] = user["name"]
        self.currentUser = user["key"] or None
        self.addClass("vi-tb-accountmgnt")
        try:
            self.btn["text"] = "%s. %s" % (user["firstname"][0],
                                           user["lastname"])
        except:
            self.btn["text"] = user["name"]
Пример #5
0
    def __init__(self, ident, title=None):
        super(AccordionSegment, self).__init__()
        self.sinkEvent("onClick")

        self.addClass("vi-accordion-segment")
        self["name"] = ident

        legend = html5.Legend()
        legend.addClass("vi-accordion-legend")
        self.appendChild(legend)

        self.title = html5.Span()
        embedSvg = embedsvg.get("icons-arrow-right")
        if embedSvg:
            self.title.element.innerHTML = embedSvg
        self.title.appendChild(html5.TextNode(title or ident))
        self.title.addClass("vi-accordion-title")
        self.title["role"] = "button"
        legend.appendChild(self.title)

        # icon = html5.Div()
        # icon.addClass("vi-accordion-icon")
        # self.title.appendChild()

        self._section = html5.Section()
        self._section.addClass("vi-accordion-section")
        self.appendChild(self._section)
Пример #6
0
    def replaceWithMessage(self, message, logClass="success"):
        self.parent()["class"] = []
        self.parent().addClass("log-%s" % logClass)

        msg = html5.Span()
        html5.utils.textToHtml(msg, message)

        self.parent().appendChild(msg)
        self.parent().removeChild(self)
Пример #7
0
	def replaceWithMessage(self, message, isSuccess):
		self.parent().removeClass("is-uploading")
		self.parent().removeClass("log-progress")
		if isSuccess:
			self.parent().addClass("log-success")
		else:
			self.parent().addClass("log-failed")
		msg = html5.Span()
		msg.appendChild(html5.TextNode(message))
		self.parent().appendChild(msg)
		self.parent().removeChild(self)
Пример #8
0
	def onStartSearch(self, searchStr, *args, **kwargs):
		if not searchStr:
			self.setRootNode(self.rootNode)
		else:
			for c in self.entryFrame._children[ : ]:
				self.entryFrame.removeChild( c )

			for c in self.pathList._children[:]:
				self.pathList.removeChild(c)
			s = html5.Span()
			s.appendChild(html5.TextNode("Search"))
			self.pathList.appendChild(s)
			self.loadNode(node = self.rootNode ,overrideParams = {"search": searchStr})
Пример #9
0
    def onTableChanged(self, table, rowCount):
        if "elementSpan" in dir(self):
            self.removeChild(self.elementSpan)

        pages = self.currentModule.loadedPages
        currentpage = self.currentModule.currentPage
        #print(table._model)
        if table._dataProvider:
            #self.elementSpan = html5.Span(html5.TextNode(translate("current Page {cpg}, loaded elements: {amt}, pages: {pg}",amt=rowCount, pg=pages, cpg=currentpage )))
            self.elementSpan = html5.Span(
                html5.TextNode(
                    translate("loaded elements: {amt}, pages: {pg}",
                              amt=len(table._model),
                              pg=pages)))
        else:
            #self.elementSpan = html5.Span(html5.TextNode(translate("current Page {cpg}, all elements loaded: {amt}, pages: {pg}",amt=rowCount, pg=pages, cpg=currentpage)))
            self.elementSpan = html5.Span(
                html5.TextNode(
                    translate("all elements loaded: {amt}, pages: {pg}",
                              amt=len(table._model),
                              pg=pages)))
        self.appendChild(self.elementSpan)
Пример #10
0
    def setActions(self, actions, widget=None):
        """
			Sets the list of valid actions for this module.
			This function tries to resolve a suitable action-widget for each
			given action-name and adds them on success.
			All previous actions are removed.
			:param actions: List of names of actions which should be available.
			:type actions: list of str
		"""
        for c in self._children[:]:
            self.removeChild(c)

        self.widgets = {}
        self.actions = actions

        for action in actions:
            if action == "|":
                span = html5.Span()
                span.addClass("vi-ab-spacer")
                self.appendChild(span)
            else:
                if self.module is not None and self.module in conf[
                        "modules"].keys():
                    handler = conf["modules"][self.module]["handler"]
                else:
                    handler = ""

                actionWdg = actionDelegateSelector.select(
                    self.module, handler, action)
                if actionWdg is not None:
                    try:
                        actionWdg = actionWdg(self.module, handler, action)
                    except:
                        actionWdg = actionWdg()

                    self.appendChild(actionWdg)

                    if "postInit" in dir(actionWdg):
                        actionWdg.postInit(widget=widget)

                    self.widgets[action] = actionWdg
                else:  # We may have a server-defined action
                    if handler and "customActions" in conf["modules"][
                            self.module]:
                        if action in conf["modules"][
                                self.module]["customActions"]:
                            actionWdg = ServerSideActionWdg(
                                self.module, handler, action, conf["modules"][
                                    self.module]["customActions"][action])
                            self.appendChild(actionWdg)
                            self.widgets[action] = actionWdg
Пример #11
0
    def msgOverlay(self, logObj):
        assert logObj["type"] in [
            "success", "error", "warning", "info", "progress"
        ]

        msgwrap = html5.Div()
        msgwrap["class"] = [
            "msg", "is-active", "popup", "popup--se",
            "msg--%s" % logObj["type"]
        ]

        msgcontent = html5.Div()
        msgcontent["class"] = ["msg-content"]
        msgwrap.appendChild(msgcontent)

        date = html5.Span()
        date["class"] = ["msg-date"]
        date.appendChild(html5.TextNode(logObj["date"]))
        msgcontent.appendChild(date)

        msgdescr = html5.Div()
        msgdescr["class"] = ["msg-descr"]
        msgcontent.appendChild(msgdescr)

        if isinstance(logObj["msg"], html5.Widget):
            msgdescr.appendChild(logObj["msg"])
        else:
            msgdescr.appendChild(
                html5.TextNode(html5.utils.unescape(logObj["msg"])))

        if logObj["icon"]:
            svg = embedsvg.get(logObj["icon"])
        else:
            svg = embedsvg.get("icons-%s" % logObj["type"])

        if not svg:
            svg = embedsvg.get("icons-message-news")

        if svg:
            msgwrap.element.innerHTML = svg + msgwrap.element.innerHTML

        self.appendChild(msgwrap)
        DeferredCall(self.removeInfo, msgwrap, _delay=2500)
Пример #12
0
    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
Пример #13
0
    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()