diff --git a/op/op.Ajax.php b/op/op.Ajax.php index 44c2a9220..f7d42f8a7 100644 --- a/op/op.Ajax.php +++ b/op/op.Ajax.php @@ -755,6 +755,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(); @@ -796,7 +806,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); @@ -814,7 +824,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()); 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();