From 85f7332e06b67cc94e709ac19e456d2727245625 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Mon, 7 Mar 2022 15:19:22 +0100 Subject: [PATCH 1/2] comment and attributes can be passed to uploaddocument --- op/op.Ajax.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/op/op.Ajax.php b/op/op.Ajax.php index 70a75c1f4..87b4e0815 100644 --- a/op/op.Ajax.php +++ b/op/op.Ajax.php @@ -743,6 +743,16 @@ switch($command) { } } + if(isset($_POST["attributes"])) + $attributes = $_POST["attributes"]; + else + $attributes = array(); + + if(isset($_POST["comment"])) + $comment = trim($_POST["comment"]); + else + $comment = ''; + // Get the list of reviewers and approvers for this document. $reviewers = array(); $approvers = array(); @@ -784,7 +794,7 @@ switch($command) { $controller->setParam('folder', $folder); $controller->setParam('fulltextservice', $fulltextservice); $controller->setParam('name', $name); - $controller->setParam('comment', ''); + $controller->setParam('comment', $comment); $controller->setParam('expires', $expires); $controller->setParam('keywords', ''); $controller->setParam('categories', $cats); @@ -802,7 +812,7 @@ switch($command) { $controller->setParam('approvers', $approvers); $controller->setParam('reqversion', 1); $controller->setParam('versioncomment', ''); - $controller->setParam('attributes', array()); + $controller->setParam('attributes', $attributes); $controller->setParam('attributesversion', array()); $controller->setParam('workflow', $workflow); $controller->setParam('notificationgroups', array()); From 22b054f764f5bad4c468d26c2eb89c4111e93c29 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Mon, 7 Mar 2022 15:19:42 +0100 Subject: [PATCH 2/2] comment and attributes can passed to document uploaded by drag&drop --- views/bootstrap/styles/application.js | 29 ++++++++++++++++++++++++++ views/bootstrap4/styles/application.js | 29 ++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/views/bootstrap/styles/application.js b/views/bootstrap/styles/application.js index 6795d4586..0d56d5d5b 100644 --- a/views/bootstrap/styles/application.js +++ b/views/bootstrap/styles/application.js @@ -777,6 +777,31 @@ function onAddClipboard(ev) { /* {{{ */ } } + // formData - instance of FormData object + // data - object to post + SeedDMSUpload.getFormData = function(formData, data, previousKey) { + if (data instanceof Object) { + Object.keys(data).forEach(key => { + const value = data[key]; + if (value instanceof Object && !Array.isArray(value)) { + return this.getFormData(formData, value, key); + } + if (previousKey) { + key = `${previousKey}[${key}]`; + } + if (Array.isArray(value)) { + value.forEach(val => { + formData.append(`${key}[]`, val); + }); + } else { + formData.append(key, value); + } + }); + } else { + formData.append(previousKey, data); + } + } + SeedDMSUpload.handleFileUpload = function(files,obj,statusbar) { /* target is set for the quick upload area */ var target_id = obj.data('target'); @@ -794,8 +819,12 @@ function onAddClipboard(ev) { /* {{{ */ fd.append('targettype', target_type); fd.append('folderid', target_id); fd.append('formtoken', obj.data('uploadformtoken')); + if (typeof obj.data('comment') !== 'undefined') { + fd.append('comment', obj.data('comment')); + } fd.append('userfile', files[i]); fd.append('command', 'uploaddocument'); + this.getFormData(fd, obj.data('attributes'), 'attributes'); // fd.append('path', files[i].webkitRelativePath); statusbar.parent().show(); diff --git a/views/bootstrap4/styles/application.js b/views/bootstrap4/styles/application.js index a404f2def..9064aae17 100644 --- a/views/bootstrap4/styles/application.js +++ b/views/bootstrap4/styles/application.js @@ -808,6 +808,31 @@ function onAddClipboard(ev) { /* {{{ */ } } + // formData - instance of FormData object + // data - object to post + SeedDMSUpload.getFormData = function(formData, data, previousKey) { + if (data instanceof Object) { + Object.keys(data).forEach(key => { + const value = data[key]; + if (value instanceof Object && !Array.isArray(value)) { + return this.getFormData(formData, value, key); + } + if (previousKey) { + key = `${previousKey}[${key}]`; + } + if (Array.isArray(value)) { + value.forEach(val => { + formData.append(`${key}[]`, val); + }); + } else { + formData.append(key, value); + } + }); + } else { + formData.append(previousKey, data); + } + } + SeedDMSUpload.handleFileUpload = function(files,obj,statusbar) { /* target is set for the quick upload area */ var target_id = obj.data('target'); @@ -825,8 +850,12 @@ function onAddClipboard(ev) { /* {{{ */ fd.append('targettype', target_type); fd.append('folderid', target_id); fd.append('formtoken', obj.data('uploadformtoken')); + if (typeof obj.data('comment') !== 'undefined') { + fd.append('comment', obj.data('comment')); + } fd.append('userfile', files[i]); fd.append('command', 'uploaddocument'); + this.getFormData(fd, obj.data('attributes'), 'attributes'); // fd.append('path', files[i].webkitRelativePath); statusbar.parent().show();