Skip to content

Commit 2109e6c

Browse files
authored
Create controller.js
1 parent 695d030 commit 2109e6c

File tree

1 file changed

+78
-0
lines changed
  • Modern Development/Service Portal Widgets/Custom attachment variable

1 file changed

+78
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
api.controller = function ($scope, nowAttachmentHandler, spUtil, spAttachmentUpload, $timeout, cabrillo, spModal) {
2+
var c = this;
3+
c.isNative = cabrillo.isNative()
4+
/*
5+
* change table and guid if you want to attach to some other record
6+
*/
7+
$scope.table = $scope.page.g_form.recordTableName;
8+
$scope.guid = $scope.$parent.c.getAttachmentGuid();
9+
//
10+
$scope.data.maxAttachmentSize = 24;
11+
var ah = $scope.attachmentHandler = new nowAttachmentHandler(setAttachments, appendError);
12+
ah.setParams($scope.table, $scope.guid, 1024 * 1024 * $scope.data.maxAttachmentSize);
13+
14+
// implement logic to show drag and drop picker or clip icon with text
15+
$scope.showDragAndDrop = function () {
16+
if (true)
17+
return true;
18+
else
19+
return false;
20+
}
21+
/*
22+
* callback function called after attachment action happens
23+
* e.g. implement mandatory attachment
24+
*/
25+
function setAttachments(attachments, action) {
26+
if (!angular.equals($scope.attachments, attachments))
27+
$scope.attachments = attachments;
28+
if (action === "added") {
29+
// custom attachment added logic
30+
}
31+
if (action === "renamed") {
32+
// custom attachment renamed logic
33+
}
34+
if (action === "deleted") {
35+
// custom attachment deleted logic
36+
}
37+
spUtil.get($scope, {
38+
action: "from_attachment"
39+
});
40+
}
41+
/*
42+
* callback function called on error
43+
*/
44+
function appendError(error) {
45+
spUtil.addErrorMessage(error.msg + error.fileName);
46+
}
47+
48+
// drag & drop handler
49+
$scope.dropFiles = function (files) {
50+
if (files && files.length > 0) {
51+
$scope.attachmentUploadInProgress = true;
52+
$scope.totalFilesBeingUploaded++;
53+
spAttachmentUpload.uploadAttachments($scope.attachmentHandler, files);
54+
}
55+
$timeout(function () {
56+
if ($scope.attachmentUploadInProgress != false)
57+
spUtil.addInfoMessage("The attachment upload is in progress. Note that some actions are deactivated during the file upload process");
58+
}, 2000);
59+
$scope.$on('attachment.upload.idle', function () {
60+
$scope.attachmentUploadInProgress = false;
61+
$scope.totalFilesBeingUploaded = 0;
62+
});
63+
};
64+
//confirm delete dialog
65+
$scope.confirmDeleteAttachment = function (attachment) {
66+
if (c.isNative) {
67+
if (confirm("delete attachment?")) {
68+
$scope.data.attachment_action_in_progress = true;
69+
$scope.attachmentHandler.deleteAttachment(attachment);
70+
}
71+
} else {
72+
spModal.confirm("delete attachment?").then(function () {
73+
$scope.data.attachment_action_in_progress = true;
74+
$scope.attachmentHandler.deleteAttachment(attachment);
75+
});
76+
}
77+
}
78+
};

0 commit comments

Comments
 (0)