6 .directive("attachmentDirective", attachmentDirective);
10 attachments : Array - list of existing attachments to display
11 idProperties : Object - portlet information needed to get/save attachments
12 isButton : Boolean - Don't save on add attachment juste build the js array (and don't display attachments menu)
13 saveOnAdd : Boolean - Save the attachment when added
14 deleteConfirm : Boolean (Optionnal) - Should we display confirm-dialog when removing an attachment
15 hasContextMenu : Boolean (Optional) - Should we display context menu on attachment click
17 function attachmentDirective() {
29 templateUrl: Global.Theme.getURLPortal() + Liferay.ThemeDisplay.getPathJavaScript() + "/angularjs/attachment/attachment.html?t="+Liferay.extTimestamp,
30 controller: AttachmentController,
31 controllerAs: "AttachmentCtrl",
32 bindToController: true
36 AttachmentController.$inject = ["attachmentService", "toastr", "$uibModal"];
38 function AttachmentController(attachmentService, toastr, $uibModal) {
40 vm.isEditionMode = isEditionMode;
41 vm.onViewAttachment = onViewAttachment;
42 vm.onSendToDropboxAttachment = onSendToDropboxAttachment;
43 vm.onDownloadAttachment = onDownloadAttachment;
44 vm.onAddAttachment = onAddAttachment;
45 vm.onDeleteAttachment = onDeleteAttachment;
46 vm.isDeleteWithConfirmDisplay = isDeleteWithConfirmDisplay;
47 vm.isDeleteWithoutConfirmDisplay = isDeleteWithoutConfirmDisplay;
49 if (vm.saveOnAdd == undefined) {
53 if (vm.deleteConfirm == undefined) {
54 vm.deleteConfirm = true;
57 if (vm.hasContextMenu == undefined) {
58 vm.hasContextMenu = !vm.isButton;
61 function isEditionMode() {
66 Display delete button with confirmation on click
68 function isDeleteWithConfirmDisplay() {
69 return (vm.isEditor && vm.deleteConfirm);
73 Display delete button without confirmation on click
75 function isDeleteWithoutConfirmDisplay() {
76 return (vm.isEditor && !vm.deleteConfirm);
82 function onViewAttachment(index) {
83 var modalInstance = $uibModal.open({
84 templateUrl: Global.Theme.getURLPortal() + Liferay.ThemeDisplay.getPathJavaScript() + "/angularjs/viewer/viewer.html?t="+Liferay.extTimestamp,
85 controller: "ViewerController",
86 controllerAs: "ViewerCtrl",
88 windowClass: "modal-viewer",
90 parameters: function() {
92 attachment: vm.attachments[index],
93 idProperties: vm.idProperties
97 backdrop: 'static', /* this prevent user interaction with the background (we have to stop the conversion) */
101 modalInstance.result.then(function() {
102 //No return value expected
107 function onSendToDropboxAttachment(index) {
108 attachmentService.sendAttachmentToDropbox(vm.attachments[index], vm.idProperties)
109 .then(function(data) {
110 toastr.success(data.message);
112 ["catch"](function(message) {
113 toastr.error(message);
118 Download attachment file
120 function onDownloadAttachment(attachment) {
121 window.open(attachment.fileLink + "&contentDispo=attachment");
125 Open the file selector
127 function onAddAttachment() {
128 var modalInstance = $uibModal.open({
129 templateUrl: Global.Theme.getURLPortal() + Liferay.ThemeDisplay.getPathJavaScript() + "/angularjs/file-selector/file-selector.html?t="+Liferay.extTimestamp,
130 controller: "FileSelectorController",
131 controllerAs: "FileSelectorCtrl",
133 parameters : function() {
139 modalInstance.result.then(function(attachFiles) {
142 vm.attachments.push.apply(vm.attachments, attachFiles);
146 attachmentService.addAttachments(attachFiles, vm.idProperties)
147 .then(function(data) {
148 vm.attachments.push.apply(vm.attachments, data.attachFiles);
149 toastr.success(data.message);
151 ["catch"](function(message) {
152 toastr.error(message);
156 // Cancel file selection so don't do anything
163 function onDeleteAttachment(index) {
166 vm.attachments.splice(index,1);
170 attachmentService.deleteAttachment(vm.attachments[index], vm.idProperties)
171 .then(function(data) {
172 // Remove attachment from array
173 vm.attachments.splice(index, 1);
174 toastr.success(data.message);
176 ["catch"](function(message) {
177 toastr.error(message);