Ejemplo n.º 1
0
    def __init__(self):
        super(Log, self).__init__()

        self["class"].append("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["class"].append("statuslist")
        self.appendChild(self.logUL)

        versionDiv = html5.Div()
        versionDiv["class"].append("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["server.version"]])))
            versionspan["class"].append("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"])
                 if conf["vi.version.appendix"] else ""))

            versionspan["class"].append("versionspan")
            versionDiv.appendChild(versionspan)

            #Try loading the revision and build date
            try:
                from version import builddate, revision

                revspan = html5.Span()
                revspan.appendChild(html5.TextNode("Rev %s" % revision))
                revspan["class"].append("revisionspan")

                datespan = html5.Span()
                datespan.appendChild(html5.TextNode("Built %s" % builddate))
                datespan["class"].append("datespan")

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

            except:
                pass

        if versionDiv.children():
            self.appendChild(versionDiv)
Ejemplo n.º 2
0
    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))
Ejemplo n.º 3
0
    def __init__(self,
                 text,
                 value="",
                 successHandler=None,
                 abortHandler=None,
                 successLbl="OK",
                 abortLbl="Cancel",
                 *args,
                 **kwargs):
        super(TextareaDialog, self).__init__(*args, **kwargs)
        self["class"].append("textareadialog")
        self.successHandler = successHandler
        self.abortHandler = abortHandler

        span = html5.Span()
        span.element.innerHTML = text
        self.appendChild(span)
        self.inputElem = html5.Textarea()
        self.inputElem["value"] = value
        self.appendChild(self.inputElem)
        okayBtn = Button(successLbl, self.onOkay)
        okayBtn["class"].append("btn_okay")
        self.appendChild(okayBtn)
        cancelBtn = Button(abortLbl, self.onCancel)
        cancelBtn["class"].append("btn_cancel")
        self.appendChild(cancelBtn)
        self.sinkEvent("onkeydown")
        self.inputElem.focus()
Ejemplo n.º 4
0
    def __init__(self,
                 question,
                 title=None,
                 yesCallback=None,
                 noCallback=None,
                 yesLabel="Yes",
                 noLabel="No",
                 *args,
                 **kwargs):
        super(YesNoDialog, self).__init__(title, *args, **kwargs)
        self["class"].append("yesnodialog")

        self.yesCallback = yesCallback
        self.noCallback = noCallback

        lbl = html5.Span()
        lbl["class"].append("question")
        self.appendChild(lbl)

        if isinstance(question, html5.Widget):
            lbl.appendChild(question)
        else:
            html5.utils.textToHtml(lbl, question)

        btnYes = html5.ext.Button(yesLabel, callback=self.onYesClicked)
        btnYes["class"].append("btn_yes")
        self.appendChild(btnYes)

        if len(noLabel):
            btnNo = html5.ext.Button(noLabel, callback=self.onNoClicked)
            btnNo["class"].append("btn_no")
            self.appendChild(btnNo)

        self.sinkEvent("onkeydown")
        btnYes.focus()
Ejemplo n.º 5
0
    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)
Ejemplo n.º 6
0
    def __init__(self,
                 msg,
                 title=None,
                 okCallback=None,
                 okLabel="OK",
                 *args,
                 **kwargs):
        super(Alert, self).__init__(title, *args, **kwargs)
        self.addClass("alert")

        self.okCallback = okCallback

        message = html5.Span()
        message.addClass("alert-msg")
        self.appendChild(message)

        if isinstance(msg, html5.Widget):
            message.appendChild(msg)
        else:
            html5.utils.textToHtml(message, msg)

        okBtn = html5.ext.Button(okLabel, callback=self.onOkBtnClick)
        okBtn.addClass("alert-btn-ok")
        self.appendChild(okBtn)

        self.sinkEvent("onKeyDown")
        okBtn.focus()
Ejemplo n.º 7
0
    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
Ejemplo n.º 8
0
    def __init__(self,
                 moduleName,
                 boneName,
                 readOnly,
                 _min=False,
                 _max=False,
                 precision=False,
                 currency=None,
                 *args,
                 **kwargs):
        super(NumericEditBone, self).__init__(*args, **kwargs)
        self.boneName = boneName
        self.readOnly = readOnly

        self.input = html5.Input()
        self.appendChild(self.input)

        if currency:
            self.appendChild(html5.Span(currency))

        self.input["type"] = "number"

        if _min:
            self.input["min"] = _min

        if _max:
            self.input["max"] = _max

        if precision:
            self.input["step"] = pow(10, -precision)
        else:  #Precision is zero, treat as integer input
            self.input["step"] = 1

        if self.readOnly:
            self.input["readonly"] = True
Ejemplo n.º 9
0
    def replaceWithMessage(self, message, logClass="success"):
        self.parent()["class"] = []
        self.parent()["class"].append("log_%s" % logClass)

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

        self.parent().appendChild(msg)
        self.parent().removeChild(self)
Ejemplo n.º 10
0
	def __init__(self, shortText="Tooltip", longText="", *args, **kwargs):
		super( ToolTip, self ).__init__( *args, **kwargs )
		self["class"] = "tooltip"
		a = html5.ext.Button(shortText, self.toggleMsgCenter )
		a.appendChild(html5.TextNode())
		#a["href"] = "#tooltip_contents_%s" % self.toolTipIdx
		self.appendChild(a)
		span = html5.Span()
		span.element.innerHTML = longText.replace( "\n", "<br />" )
		self.appendChild( span )
Ejemplo n.º 11
0
	def cloneComplete(self, request):
		logDiv = html5.Div()
		logDiv["class"].append("msg")
		spanMsg = html5.Span()
		spanMsg.appendChild( html5.TextNode( translate( u"The hierarchy will be cloned in the background." ) ) )
		spanMsg["class"].append("msgspan")
		logDiv.appendChild(spanMsg)

		conf["mainWindow"].log("success",logDiv)
		self.closeOrContinue()
Ejemplo n.º 12
0
    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
Ejemplo n.º 13
0
 def onStartSearch(self, searchStr, *args, **kwargs):
     if not searchStr:
         self.setRootNode(self.rootNode)
     else:
         for c in self.pathList._children[:]:
             self.pathList.removeChild(c)
         s = html5.Span()
         s.appendChild(html5.TextNode("Search"))
         self.pathList.appendChild(s)
         self.reloadData({"node": self.rootNode, "search": searchStr})
Ejemplo n.º 14
0
 def replaceWithMessage(self, message, isSuccess):
     self.parent()["class"].remove("is_uploading")
     self.parent()["class"].remove("log_progress")
     if isSuccess:
         self.parent()["class"].append("log_success")
     else:
         self.parent()["class"].append("log_failed")
     msg = html5.Span()
     msg.appendChild(html5.TextNode(message))
     self.parent().appendChild(msg)
     self.parent().removeChild(self)
Ejemplo n.º 15
0
	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"])
Ejemplo n.º 16
0
    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")
Ejemplo n.º 17
0
    def log(self, type, msg):
        """
			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"]

        liwrap = html5.Li()
        liwrap["class"].append("log_" + type)
        liwrap["class"].append("is_new")

        spanDate = html5.Span()
        spanDate.appendChild(
            html5.TextNode(datetime.now().strftime("%H:%M:%S")))
        spanDate["class"].append("date")
        liwrap.appendChild(spanDate)

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

        else:
            #Create a span element for that message
            spanMsg = html5.Span()
            spanMsg.appendChild(html5.TextNode(html5.utils.unescape(msg)))
            spanMsg["class"].append("msg")
            liwrap.appendChild(spanMsg)

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

        if len(self.logUL._children) > 1:
            self.logUL.element.removeChild(liwrap.element)
            self.logUL.element.insertBefore(
                liwrap.element, self.logUL.element.children.item(0))
Ejemplo n.º 18
0
 def __init__(self, extension, view, module, *args, **kwargs):
     super(RelationalSearch, self).__init__(*args, **kwargs)
     self.view = view
     self.extension = extension
     self.module = module
     self.currentSelection = None
     self.filterChangedEvent = EventDispatcher("filterChanged")
     self.appendChild(html5.TextNode("RELATIONAL SEARCH"))
     self.appendChild(html5.TextNode(extension["name"]))
     self.currentEntry = html5.Span()
     self.appendChild(self.currentEntry)
     btn = html5.ext.Button("Select", self.openSelector)
     self.appendChild(btn)
     btn = html5.ext.Button("Clear", self.clearSelection)
     self.appendChild(btn)
Ejemplo n.º 19
0
    def setActions(self, actions):
        """
			Sets the list of valid actions for this modul.
			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 avaiable.
			@type actions: List of String
		"""
        for c in self._children[:]:
            self.removeChild(c)
        if self.currentAction is not None:
            h3 = html5.H3()
            h3["class"].append("modul_%s" % self.module)
            h3["class"].append("apptype_%s" % self.appType)
            h3["class"].append("action_%s" % self.currentAction)

            h3.appendChild(html5.TextNode(translate(self.currentAction)))
            self.appendChild(h3)

        self.widgets = {}
        self.actions = actions

        for action in actions:
            if action == "|":
                span = html5.Span()
                span["class"].append("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)
                    self.widgets[action] = actionWdg
Ejemplo n.º 20
0
	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"])
Ejemplo n.º 21
0
    def __init__(self, title=None, id=None, className=None, *args, **kwargs):
        super(Popup, self).__init__(*args, **kwargs)

        self["class"] = "alertbox"
        if className is not None and len(className):
            self["class"].append(className)

        if title:
            lbl = html5.Span()
            lbl["class"].append("title")
            lbl.appendChild(html5.TextNode(title))
            self.appendChild(lbl)

        # id can be used to pass information to callbacks
        self.id = id

        self.frameDiv = html5.Div()
        self.frameDiv["class"] = "popup"

        self.frameDiv.appendChild(self)
        html5.Body().appendChild(self.frameDiv)
Ejemplo n.º 22
0
Archivo: file.py Proyecto: Xeon2003/vi
    def renderFileentry(self, fileEntry):
        if not "dest" in fileEntry.keys():
            return None

        fileEntry = fileEntry["dest"]

        if not "name" in fileEntry.keys() and not "dlkey" in fileEntry.keys():
            return None

        adiv = html5.Div()
        if "mimetype" in fileEntry.keys():
            try:
                ftype, fformat = fileEntry["mimetype"].split("/")
                adiv["class"].append("type_%s" % ftype)
                adiv["class"].append("format_%s" % fformat)
            except:
                pass

        adiv.appendChild(FilePreviewImage(fileEntry))

        aspan = html5.Span()
        aspan.appendChild(html5.TextNode(str(fileEntry.get(
            "name", ""))))  #fixme: formatstring!
        adiv.appendChild(aspan)

        adiv["class"].append("fileBoneViewCell")
        #adiv["draggable"]=True
        #metamime="application/octet-stream"

        #if "mimetype" in fileEntry.keys():
        #   metamime=str(fileEntry["mimetype"])

        #adiv["download"]="%s:%s:/file/download/%s?download=1&fileName=%s" % (metamime, str(fileEntry["name"]),
        #                                                            str(fileEntry["dlkey"]), str(fileEntry["name"]))
        #adiv["href"]="/file/download/%s?download=1&fileName=%s" % (str(fileEntry["dlkey"]), str(fileEntry["name"]))
        return adiv
Ejemplo n.º 23
0
	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
Ejemplo n.º 24
0
Archivo: list.py Proyecto: Xeon2003/vi
    def __init__(self,
                 module,
                 filter=None,
                 columns=None,
                 isSelector=False,
                 filterID=None,
                 filterDescr=None,
                 batchSize=None,
                 context=None,
                 autoload=True,
                 *args,
                 **kwargs):
        """
			@param module: Name of the modul we shall handle. Must be a list application!
			@type module: string
		"""
        if not module in conf["modules"].keys():
            conf["mainWindow"].log(
                "error",
                translate("The module '{module}' does not exist.",
                          module=module))
            assert module in conf["modules"].keys()

        super(ListWidget, self).__init__()
        self._batchSize = batchSize or conf[
            "batchSize"]  # How many rows do we fetch at once?
        self.isDetaching = False  #If set, this widget is beeing about to be removed - dont issue nextBatchNeeded requests
        self.module = module
        self.context = context

        self.actionBar = ActionBar(module, "list", currentAction="list")
        self.appendChild(self.actionBar)

        self.sideBar = SideBar()
        self.appendChild(self.sideBar)

        myView = None

        if filterID:
            if conf["modules"] and module in conf["modules"].keys():
                if "views" in conf["modules"][module].keys(
                ) and conf["modules"][module]["views"]:
                    for v in conf["modules"][module]["views"]:
                        if v["__id"] == filterID:
                            myView = v
                            break
            if myView and "extendedFilters" in myView.keys(
            ) and myView["extendedFilters"]:
                self.appendChild(CompoundFilter(myView, module, embed=True))

        checkboxes = (conf["modules"] and module in conf["modules"].keys() and
                      "checkboxSelection" in conf["modules"][module].keys()
                      and conf["modules"][module]["checkboxSelection"])
        indexes = (conf["modules"] and module in conf["modules"].keys()
                   and "indexes" in conf["modules"][module].keys()
                   and conf["modules"][module]["indexes"])

        self.table = DataTable(checkboxes=checkboxes,
                               indexes=indexes,
                               *args,
                               **kwargs)
        self.appendChild(self.table)
        self._currentCursor = None
        self._structure = None
        self._currentRequests = []
        self.columns = []

        if isSelector and filter is None and columns is None:
            #Try to select a reasonable set of cols / filter
            if conf["modules"] and module in conf["modules"].keys():
                tmpData = conf["modules"][module]
                if "columns" in tmpData.keys():
                    columns = tmpData["columns"]
                if "filter" in tmpData.keys():
                    filter = tmpData["filter"]

        self.table.setDataProvider(self)
        self.filter = filter.copy() if isinstance(filter, dict) else {}
        self.columns = columns[:] if isinstance(columns, list) else []
        self.filterID = filterID  #Hint for the sidebarwidgets which predefined filter is currently active
        self.filterDescr = filterDescr  #Human-readable description of the current filter
        self._tableHeaderIsValid = False
        self.isSelector = isSelector

        #Proxy some events and functions of the original table
        for f in [
                "selectionChangedEvent", "selectionActivatedEvent",
                "cursorMovedEvent", "tableChangedEvent", "getCurrentSelection"
        ]:
            setattr(self, f, getattr(self.table, f))

        self.actionBar.setActions(self.getDefaultActions(myView))

        if isSelector:
            self.selectionActivatedEvent.register(self)

        self.emptyNotificationDiv = html5.Div()
        self.emptyNotificationDiv.appendChild(
            html5.TextNode(translate("Currently no entries")))
        self.emptyNotificationDiv["class"].append("emptynotification")
        self.appendChild(self.emptyNotificationDiv)
        self.emptyNotificationDiv["style"]["display"] = "none"
        self.table["style"]["display"] = "none"
        self.filterDescriptionSpan = html5.Span()
        self.appendChild(self.filterDescriptionSpan)
        self.filterDescriptionSpan["class"].append("filterdescription")
        self.updateFilterDescription()

        if autoload:
            self.reloadData()
Ejemplo n.º 25
0
	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)
Ejemplo n.º 26
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"
		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
Ejemplo n.º 27
0
    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)
Ejemplo n.º 28
0
    def __init__(self,
                 prompt,
                 items=None,
                 title=None,
                 okBtn="OK",
                 cancelBtn="Cancel",
                 forceSelect=False,
                 callback=None,
                 *args,
                 **kwargs):
        super(SelectDialog, self).__init__(title, *args, **kwargs)
        self["class"].append("selectdialog")

        self.callback = callback
        self.items = items
        assert isinstance(self.items, list)

        # Prompt
        if prompt:
            lbl = html5.Span()
            lbl["class"].append("prompt")

            if isinstance(prompt, html5.Widget):
                lbl.appendChild(prompt)
            else:
                html5.utils.textToHtml(lbl, prompt)

            self.appendChild(lbl)

        # Items
        if not forceSelect and len(items) <= 3:
            for idx, item in enumerate(items):
                if isinstance(item, dict):
                    title = item.get("title")
                    cssc = item.get("class")
                elif isinstance(item, tuple):
                    title = item[1]
                    cssc = None
                else:
                    title = item

                btn = html5.ext.Button(title, callback=self.onAnyBtnClick)
                btn.idx = idx

                if cssc:
                    btn.addClass(cssc)

                self.appendChild(btn)
        else:
            self.select = html5.Select()
            self.appendChild(self.select)

            for idx, item in enumerate(items):
                if isinstance(item, dict):
                    title = item.get("title")
                elif isinstance(item, tuple):
                    title = item[1]
                else:
                    title = item

                opt = html5.Option(title)
                opt["value"] = str(idx)

                self.select.appendChild(opt)

            if okBtn:
                self.appendChild(
                    html5.ext.Button(okBtn, callback=self.onOkClick))

            if cancelBtn:
                self.appendChild(
                    html5.ext.Button(cancelBtn, callback=self.onCancelClick))