From 2109e6cc27c4506932d6cc68a9e1e5a5a57c82d9 Mon Sep 17 00:00:00 2001 From: lauri457 <55710064+lauri457@users.noreply.github.com> Date: Mon, 13 Oct 2025 15:03:35 +1100 Subject: [PATCH 1/3] Create controller.js --- .../Custom attachment variable/controller.js | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 Modern Development/Service Portal Widgets/Custom attachment variable/controller.js 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); + }); + } + } +}; From 8bbb17971717ef9f3b21d6ab188af8e3078c62f3 Mon Sep 17 00:00:00 2001 From: lauri457 <55710064+lauri457@users.noreply.github.com> Date: Mon, 13 Oct 2025 15:03:56 +1100 Subject: [PATCH 2/3] Create template.html --- .../Custom attachment variable/template.html | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Modern Development/Service Portal Widgets/Custom attachment variable/template.html 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} +
+
+
+
+
+
+ +
From a61be2e9cbdebf7127dc056cf93275e1d2475c26 Mon Sep 17 00:00:00 2001 From: lauri457 <55710064+lauri457@users.noreply.github.com> Date: Mon, 13 Oct 2025 15:16:49 +1100 Subject: [PATCH 3/3] Create README.md --- .../Custom attachment variable/README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Modern Development/Service Portal Widgets/Custom attachment variable/README.md 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