Skip to content

Commit 58570b3

Browse files
authored
Merge pull request #2090 from lauri457/widget/attachment
Widget/attachment
2 parents f9a60bc + a61be2e commit 58570b3

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Attachment variable widget
2+
3+
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.
4+
5+
## Usage example
6+
7+
Create new widget [sp_widget]
8+
Copy template.html in the Body HTML template field
9+
Copy controller.js in the Client controller field
10+
Add custom type variable using newly created widget positioned as last variable
11+
Set hide attachment for catalog item as true
12+
Open cat item in portal and adjust widget as needed
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+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<div ng-if="true" class="wrapper-md row no-margin" role="region" data-label="Attachments"
2+
aria-label="${Attachments}">
3+
<div
4+
ng-class="{'flex-center attachment-height': c.isNative == 'true', 'flex-start': c.isNative != 'true'}">
5+
<div ng-if="!submitting && !submitted" style="font-weight:normal;cursor:default;margin-bottom:2rem;">
6+
<sp-attachment-button ng-if="::!showDragAndDrop()" modal="true"
7+
required="{{data.mandatory_attachment}}"></sp-attachment-button>
8+
<sp-attachment-button ng-if="::showDragAndDrop()" modal="true"
9+
required="{{data.mandatory_attachment}}"
10+
ng-class="{'hidden-xs': false, 'hidden-sm': true, 'hidden-md': true, 'hidden-lg': true}"></sp-attachment-button>
11+
<span class="fa fa-asterisk mandatory" ng-if="data.mandatory_attachment"
12+
ng-class="{'mandatory-filled': data.mandatory_attachment && (data.attachment_submitted || attachments.length > 0)}"
13+
style="vertical-align:super" aria-hidden="true"></span>
14+
<span ng-class="{'attachment-text' : options.native_mobile == 'true'}" aria-hidden="true">${Add
15+
attachments}</span>
16+
</div>
17+
</div>
18+
<div ng-if="::showDragAndDrop()" class="panel panel-{{options.color}} b drag-and-drop-area"
19+
ng-class="{'hidden-xs': true}" aria-hidden="true">
20+
<sp-attachment-picker on-file-pick="dropFiles($files)"></sp-attachment-picker>
21+
</div>
22+
<span ng-if="attachmentUploadInProgress">
23+
${Uploading attachments}
24+
<div class="sp-loading-indicator la-sm" style="color:black;display:inline">
25+
<div></div>
26+
<div></div>
27+
<div></div>
28+
</div>
29+
</span>
30+
<now-attachments-list template="sp_attachment_single_line"></now-attachments-list>
31+
</div>

0 commit comments

Comments
 (0)