Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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);
});
}
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<div ng-if="true" class="wrapper-md row no-margin" role="region" data-label="Attachments"
aria-label="${Attachments}">
<div
ng-class="{'flex-center attachment-height': c.isNative == 'true', 'flex-start': c.isNative != 'true'}">
<div ng-if="!submitting && !submitted" style="font-weight:normal;cursor:default;margin-bottom:2rem;">
<sp-attachment-button ng-if="::!showDragAndDrop()" modal="true"
required="{{data.mandatory_attachment}}"></sp-attachment-button>
<sp-attachment-button ng-if="::showDragAndDrop()" modal="true"
required="{{data.mandatory_attachment}}"
ng-class="{'hidden-xs': false, 'hidden-sm': true, 'hidden-md': true, 'hidden-lg': true}"></sp-attachment-button>
<span class="fa fa-asterisk mandatory" ng-if="data.mandatory_attachment"
ng-class="{'mandatory-filled': data.mandatory_attachment && (data.attachment_submitted || attachments.length > 0)}"
style="vertical-align:super" aria-hidden="true"></span>
<span ng-class="{'attachment-text' : options.native_mobile == 'true'}" aria-hidden="true">${Add
attachments}</span>
</div>
</div>
<div ng-if="::showDragAndDrop()" class="panel panel-{{options.color}} b drag-and-drop-area"
ng-class="{'hidden-xs': true}" aria-hidden="true">
<sp-attachment-picker on-file-pick="dropFiles($files)"></sp-attachment-picker>
</div>
<span ng-if="attachmentUploadInProgress">
${Uploading attachments}
<div class="sp-loading-indicator la-sm" style="color:black;display:inline">
<div></div>
<div></div>
<div></div>
</div>
</span>
<now-attachments-list template="sp_attachment_single_line"></now-attachments-list>
</div>
Loading