diff --git a/Modern Development/Service Portal Widgets/Custom attachment variable/README.md b/Modern Development/Service Portal Widgets/Custom attachment variable/README.md new file mode 100644 index 0000000000..726d5e9c36 --- /dev/null +++ b/Modern Development/Service Portal Widgets/Custom attachment variable/README.md @@ -0,0 +1,12 @@ +# Attachment variable widget + +This widget lets you use the oob attachment picker from the oob catalog item widget as a custom type variable giving you more control over attachment behaviour, you can for example use ui policies to hide and show the attachment picker. + +## Usage example + +Create new widget [sp_widget] +Copy template.html in the Body HTML template field +Copy controller.js in the Client controller field +Add custom type variable using newly created widget positioned as last variable +Set hide attachment for catalog item as true +Open cat item in portal and adjust widget as needed diff --git a/Modern Development/Service Portal Widgets/Custom attachment variable/controller.js b/Modern Development/Service Portal Widgets/Custom attachment variable/controller.js new file mode 100644 index 0000000000..ce5871e7b9 --- /dev/null +++ b/Modern Development/Service Portal Widgets/Custom attachment variable/controller.js @@ -0,0 +1,78 @@ +api.controller = function ($scope, nowAttachmentHandler, spUtil, spAttachmentUpload, $timeout, cabrillo, spModal) { + var c = this; + c.isNative = cabrillo.isNative() + /* + * change table and guid if you want to attach to some other record + */ + $scope.table = $scope.page.g_form.recordTableName; + $scope.guid = $scope.$parent.c.getAttachmentGuid(); + // + $scope.data.maxAttachmentSize = 24; + var ah = $scope.attachmentHandler = new nowAttachmentHandler(setAttachments, appendError); + ah.setParams($scope.table, $scope.guid, 1024 * 1024 * $scope.data.maxAttachmentSize); + + // implement logic to show drag and drop picker or clip icon with text + $scope.showDragAndDrop = function () { + if (true) + return true; + else + return false; + } + /* + * callback function called after attachment action happens + * e.g. implement mandatory attachment + */ + function setAttachments(attachments, action) { + if (!angular.equals($scope.attachments, attachments)) + $scope.attachments = attachments; + if (action === "added") { + // custom attachment added logic + } + if (action === "renamed") { + // custom attachment renamed logic + } + if (action === "deleted") { + // custom attachment deleted logic + } + spUtil.get($scope, { + action: "from_attachment" + }); + } + /* + * callback function called on error + */ + function appendError(error) { + spUtil.addErrorMessage(error.msg + error.fileName); + } + + // drag & drop handler + $scope.dropFiles = function (files) { + if (files && files.length > 0) { + $scope.attachmentUploadInProgress = true; + $scope.totalFilesBeingUploaded++; + spAttachmentUpload.uploadAttachments($scope.attachmentHandler, files); + } + $timeout(function () { + if ($scope.attachmentUploadInProgress != false) + spUtil.addInfoMessage("The attachment upload is in progress. Note that some actions are deactivated during the file upload process"); + }, 2000); + $scope.$on('attachment.upload.idle', function () { + $scope.attachmentUploadInProgress = false; + $scope.totalFilesBeingUploaded = 0; + }); + }; + //confirm delete dialog + $scope.confirmDeleteAttachment = function (attachment) { + if (c.isNative) { + if (confirm("delete attachment?")) { + $scope.data.attachment_action_in_progress = true; + $scope.attachmentHandler.deleteAttachment(attachment); + } + } else { + spModal.confirm("delete attachment?").then(function () { + $scope.data.attachment_action_in_progress = true; + $scope.attachmentHandler.deleteAttachment(attachment); + }); + } + } +}; diff --git a/Modern Development/Service Portal Widgets/Custom attachment variable/template.html b/Modern Development/Service Portal Widgets/Custom attachment variable/template.html new file mode 100644 index 0000000000..cb042ede35 --- /dev/null +++ b/Modern Development/Service Portal Widgets/Custom attachment variable/template.html @@ -0,0 +1,31 @@ +
+
+
+ + + + +
+
+ + + ${Uploading attachments} +
+
+
+
+
+
+ +