Beispiel #1
0
	def onDrop(self, event):
		"""
			We received a drop. Test wherever its means "make it a child of us", "insert before us" or
			"insert after us" and initiate the corresponding NetworkService requests.
		"""
		event.stopPropagation()
		event.preventDefault()

		data = event.dataTransfer.getData("Text")
		if not data:
			return

		srcKey, skelType = event.dataTransfer.getData("Text").split("/")

		if self.currentStatus == "inner":
			NetworkService.request(self.module, "move",
			                       {"skelType": skelType, "key": srcKey, "parentNode": self.data["key"]},
			                       secure=True, modifies=True)

		elif self.currentStatus == "top":
			parentID = self.data["parententry"]
			if parentID:
				lastIdx = 0
				for c in self.parent()._children:
					if "data" in dir(c) and "sortindex" in c.data.keys():
						if c == self:
							break
						lastIdx = float(c.data["sortindex"])
				newIdx = str((lastIdx + float(self.data["sortindex"])) / 2.0)
				req = NetworkService.request(self.module, "move",
				                             {"skelType": skelType, "key": srcKey, "parentNode": parentID,
				                              "sortindex": newIdx},
				                             secure=True, modifies=True)

		elif self.currentStatus == "bottom":
			parentID = self.data["parententry"]

			if parentID:
				lastIdx = time()
				doUseNextChild = False
				for c in self.parent()._children:
					if "data" in dir(c) and "sortindex" in c.data.keys():
						if doUseNextChild:
							lastIdx = float(c.data["sortindex"])
							break
						if c == self:
							doUseNextChild = True

				newIdx = str((lastIdx + float(self.data["sortindex"])) / 2.0)
				req = NetworkService.request(self.module, "move",
				                             {"skelType": skelType, "key": srcKey, "parentNode": parentID,
				                              "sortindex": newIdx},
				                             secure=True, modifies=True)
Beispiel #2
0
    def submitForm(self):
        res = self.collectCurrentFormValues()

        NetworkService.request(
            self.moduleName,
            self.actionName,
            res,
            secure=True,  #always with fresh skey
            successHandler=self.actionSuccess,
            failureHandler=self.actionFailed)

        return res
Beispiel #3
0
    def onSuccess(self, *args, **kwargs):
        """Internal callback - The upload succeeded."""
        if isinstance(self.responseValue["values"], list):
            for v in self.responseValue["values"]:
                self.uploadSuccess.fire(self, v)

        else:
            self.uploadSuccess.fire(self, self.responseValue["values"])

        NetworkService.notifyChange("file")
        if self.showResultMessage:
            self.replaceWithMessage("Upload complete", isSuccess=True)
Beispiel #4
0
    def onLoad(self, *args, **kwargs):
        """
			Internal callback - The state of our upload changed.
		"""
        if self.xhr.status in [200, 204]:
            NetworkService.request("file",
                                   "add", {
                                       "key": self.targetKey,
                                       "node": self.node,
                                       "skelType": "leaf"
                                   },
                                   successHandler=self.onUploadAdded,
                                   secure=True)
        else:
            DeferredCall(self.onFailed, self.xhr.status, _delay=1000)
Beispiel #5
0
	def onUploadUrlAvailable(self, req):
		"""
			Internal callback - the actual upload url (retrieved by calling /file/getUploadURL) is known.
		"""

		params = NetworkService.decode(req)["values"]

		formData = html5.jseval("new FormData();")

		#if self.context:
		#	for k, v in self.context.items():
		#		formData.append(k, v)

		#if req.node and str(req.node) != "null":
		#	formData.append("node", req.node)

		for key, value in params["params"].items():
			if key == "key":
				self.targetKey = value[:-16]  # Truncate source/file.dat
				fileName = req.file.name
				value = value.replace("file.dat", fileName)

			formData.append(key, value)
		formData.append("file", req.file)

		self.xhr = html5.jseval("new XMLHttpRequest()")
		self.xhr.open("POST", params["url"])
		self.xhr.onload = self.onLoad
		self.xhr.upload.onprogress = self.onProgress
		self.xhr.send(formData)
Beispiel #6
0
	def __init__(self, file, node, context=None, showResultMessage=True, *args, **kwargs):
		"""
			:param file: The file to upload
			:type file: A javascript "File" Object
			:param node: Key of the desired node of our parents tree application or None for an anonymous upload.
			:type node: str or None
			:param showResultMessage: if True replaces progressbar with complete message on success
			:type showResultMessage: bool
		"""
		super(Uploader, self).__init__()
		self.uploadSuccess = EventDispatcher("uploadSuccess")
		self.uploadFailed = EventDispatcher("uploadFailed")
		self.responseValue = None
		self.targetKey = None
		self.showResultMessage = showResultMessage
		self.context = context

		r = NetworkService.request("file", "getUploadURL",
			params={"node": node} if node else {},
			successHandler=self.onUploadUrlAvailable,
			failureHandler=self.onFailed,
			secure=True
		)
		r.file = file
		r.node = node
		self.node = node
Beispiel #7
0
    def actionSuccess(self, req):
        resp = NetworkService.decode(req)
        logging.debug("actionSuccess: %r", resp)
        '''
		severity cases:
			NotSet = 0
			InvalidatesOther = 1 <-- relevant
			Empty = 2
			Invalid = 3			 <-- relevant
		'''
        if "action" in resp and resp["action"].endswith("Success"):
            # form approved: Let's store the new skeleton values and fire the success event
            self.skel = resp["values"]
            self.formSuccessEvent.fire(self)

        else:
            #form rejected
            self.errors = resp["errors"]

            for error in self.errors:
                if error["fieldPath"] in self.bones:
                    boneField = self.bones[
                        error["fieldPath"]]  # todo dependency errors
                    if (error["severity"]%2 == 0 and boneField["required"]) or\
                     (error["severity"]%2 == 1): #invalid

                        boneField.setInvalid()
                    else:
                        boneField.setValid()

            self.createFormErrorMessage()
Beispiel #8
0
    def actionSuccess(self, req):
        resp = NetworkService.decode(req)
        logging.debug("actionSuccess: %r", resp)
        '''
		severity cases:
			NotSet = 0
			InvalidatesOther = 1 <-- relevant
			Empty = 2
			Invalid = 3			 <-- relevant
		'''
        if "action" in resp and resp["action"].endswith("Success"):
            # form approved: Let's store the new skeleton values and fire the success event
            self.skel = resp["values"]
            self.formSuccessEvent.fire(self)

        else:
            #form rejected
            self.errors = resp["errors"]
            self.handleErrors()
Beispiel #9
0
	def onSkeyAvailable(self, req):
		"""
			Internal callback - the Security-Key is known.
			# Only for core 2.x needed
		"""
		formData = html5.jseval("new FormData();")
		formData.append("file", req.file)

		if self.context:
			for k, v in self.context.items():
				formData.append(k, v)

		if req.node and str(req.node) != "null":
			formData.append("node", req.node)

		formData.append("skey", NetworkService.decode(req))
		self.xhr = html5.jseval("new XMLHttpRequest()")
		self.xhr.open("POST", req.destUrl)
		self.xhr.onload = self.onLoad
		self.xhr.upload.onprogress = self.onProgress
		self.xhr.send(formData)
Beispiel #10
0
	def onUploadAdded(self, req):
		self.responseValue = NetworkService.decode(req)
		DeferredCall(self.onSuccess, _delay=1000)