openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit cea2cf16e0bbff500ba9c85f1ed4bcd1a15eff84
parent c824052df0caaa7cef5542458b2618e2d104c549
Author: dankert <openrat@jandankert.de>
Date:   Mon,  6 Dec 2021 01:38:41 +0100

Fixed the file/image upload.

Diffstat:
Mmodules/cms/action/file/FileUploadAction.class.php | 26++++++++++++++++++++++++++
Mmodules/cms/model/File.class.php | 4++--
Mmodules/cms/ui/themes/default/html/views/file/upload.php | 38++++++++++++++++++++++++--------------
Mmodules/cms/ui/themes/default/html/views/file/upload.tpl.src.xml | 24++++++++++++++----------
Mmodules/cms/ui/themes/default/html/views/image/history.php | 2+-
Mmodules/cms/ui/themes/default/html/views/image/history.tpl.src.xml | 2+-
Mmodules/cms/ui/themes/default/style/openrat.css | 4++--
Mmodules/cms/ui/themes/default/style/openrat.min.css | 2+-
Mmodules/cms/ui/themes/default/style/theme/openrat-theme.less | 2+-
Mmodules/template_engine/components/html/component_upload/upload.js | 24+++++++++++++-----------
Mmodules/template_engine/components/html/component_upload/upload.less | 2+-
11 files changed, 86 insertions(+), 44 deletions(-)

diff --git a/modules/cms/action/file/FileUploadAction.class.php b/modules/cms/action/file/FileUploadAction.class.php @@ -4,7 +4,10 @@ namespace cms\action\file; use cms\action\FileAction; use cms\action\Method; +use cms\model\BaseObject; use cms\model\Permission; +use language\Messages; +use util\Upload; class FileUploadAction extends FileAction implements Method { @@ -19,5 +22,28 @@ class FileUploadAction extends FileAction implements Method { public function post() { + + // File was uploaded. + $upload = new Upload('file'); + + try + { + $upload->processUpload(); + } + catch( \Exception $e ) + { + // technical error. + throw new \RuntimeException('Exception while processing the upload: '.$e->getMessage(), 0, $e); + } + + $this->file->filename = $upload->filename; + $this->file->extension = $upload->extension; + $this->file->size = $upload->size; + $this->file->persist(); + + $this->file->value = $upload->value; + $this->file->saveValue(); + + $this->addNoticeFor( $this->file, Messages::SAVED ); } } diff --git a/modules/cms/model/File.class.php b/modules/cms/model/File.class.php @@ -591,8 +591,8 @@ SQL $sql = $db->sql( 'UPDATE {{file}}'. ' SET size={size} '. ' WHERE objectid={objectid}' ); - $sql->setString( 'objectid' ,$this->objectid ); - $sql->setInt ( 'size' ,strlen($this->value) ); + $sql->setInt( 'objectid' ,$this->objectid ); + $sql->setInt( 'size' ,strlen($this->value) ); $sql->execute(); diff --git a/modules/cms/ui/themes/default/html/views/file/upload.php b/modules/cms/ui/themes/default/html/views/file/upload.php @@ -6,27 +6,37 @@ <input type="<?php echo O::escapeHtml('hidden') ?>" name="<?php echo O::escapeHtml('action') ?>" value="<?php echo O::escapeHtml('file') ?>" /><?php echo O::escapeHtml('') ?> <input type="<?php echo O::escapeHtml('hidden') ?>" name="<?php echo O::escapeHtml('subaction') ?>" value="<?php echo O::escapeHtml('upload') ?>" /><?php echo O::escapeHtml('') ?> <input type="<?php echo O::escapeHtml('hidden') ?>" name="<?php echo O::escapeHtml('id') ?>" value="<?php echo O::escapeHtml(''.@$_id.'') ?>" /><?php echo O::escapeHtml('') ?> - <section class="<?php echo O::escapeHtml('or-fieldset') ?>"><?php echo O::escapeHtml('') ?> - <h3 class="<?php echo O::escapeHtml('or-fieldset-label') ?>"><?php echo O::escapeHtml('') ?></h3> - <div class="<?php echo O::escapeHtml('or-fieldset-value') ?>"><?php echo O::escapeHtml('') ?> - <input type="<?php echo O::escapeHtml('file') ?>" name="<?php echo O::escapeHtml('file') ?>" size="<?php echo O::escapeHtml('40') ?>" class="<?php echo O::escapeHtml('or-upload') ?>" /><?php echo O::escapeHtml('') ?> + <section class="<?php echo O::escapeHtml('or-group or-collapsible or-collapsible--is-open or-collapsible--is-visible or-collapsible--show') ?>"><?php echo O::escapeHtml('') ?> + <h2 class="<?php echo O::escapeHtml('or-collapsible-title or-group-title or-collapsible-act-switch') ?>"><?php echo O::escapeHtml('') ?> + <i class="<?php echo O::escapeHtml('or-image-icon or-image-icon--node-closed or-collapsible--on-closed') ?>"><?php echo O::escapeHtml('') ?></i> + <i class="<?php echo O::escapeHtml('or-image-icon or-image-icon--node-open or-collapsible--on-open') ?>"><?php echo O::escapeHtml('') ?></i> + <span><?php echo O::escapeHtml(''.@O::lang('upload').'') ?></span> + </h2> + <div class="<?php echo O::escapeHtml('or-collapsible-value or-group-value') ?>"><?php echo O::escapeHtml('') ?> + <section class="<?php echo O::escapeHtml('or-fieldset') ?>"><?php echo O::escapeHtml('') ?> + <h3 class="<?php echo O::escapeHtml('or-fieldset-label') ?>"><?php echo O::escapeHtml('') ?></h3> + <div class="<?php echo O::escapeHtml('or-fieldset-value') ?>"><?php echo O::escapeHtml('') ?> + <input type="<?php echo O::escapeHtml('file') ?>" multiple="<?php echo O::escapeHtml('multiple') ?>" name="<?php echo O::escapeHtml('file') ?>" size="<?php echo O::escapeHtml('40') ?>" class="<?php echo O::escapeHtml('or-upload') ?>" /><?php echo O::escapeHtml('') ?> + </div> + </section> + <section class="<?php echo O::escapeHtml('or-fieldset') ?>"><?php echo O::escapeHtml('') ?> + <h3 class="<?php echo O::escapeHtml('or-fieldset-label') ?>"><?php echo O::escapeHtml('') ?></h3> + <div class="<?php echo O::escapeHtml('or-fieldset-value') ?>"><?php echo O::escapeHtml('') ?> + <div class="<?php echo O::escapeHtml('or-dropzone-upload') ?>"><?php echo O::escapeHtml('') ?> + <br /><?php echo O::escapeHtml('') ?> + <br /><?php echo O::escapeHtml('') ?> + <br /><?php echo O::escapeHtml('') ?> + <br /><?php echo O::escapeHtml('') ?> + </div> + </div> + </section> </div> </section> - <div class="<?php echo O::escapeHtml('or-dropzone-upload') ?>"><?php echo O::escapeHtml('') ?> - <br /><?php echo O::escapeHtml('') ?> - <br /><?php echo O::escapeHtml('') ?> - <br /><?php echo O::escapeHtml('') ?> - <br /><?php echo O::escapeHtml('') ?> - </div> </div> <div class="<?php echo O::escapeHtml('or-form-actionbar') ?>"><?php echo O::escapeHtml('') ?> <div class="<?php echo O::escapeHtml('or-btn or-btn--control or-btn--secondary or-act-form-cancel') ?>"><?php echo O::escapeHtml('') ?> <i class="<?php echo O::escapeHtml('or-image-icon or-image-icon--form-cancel') ?>"><?php echo O::escapeHtml('') ?></i> <span class="<?php echo O::escapeHtml('or-form-btn-label') ?>"><?php echo O::escapeHtml(''.@O::lang('CANCEL').'') ?></span> </div> - <div class="<?php echo O::escapeHtml('or-btn or-btn--control or-btn--primary or-act-form-save') ?>"><?php echo O::escapeHtml('') ?> - <i class="<?php echo O::escapeHtml('or-image-icon or-image-icon--form-ok') ?>"><?php echo O::escapeHtml('') ?></i> - <span class="<?php echo O::escapeHtml('or-form-btn-label') ?>"><?php echo O::escapeHtml(''.@O::lang('button_ok').'') ?></span> - </div> </div> </form> \ No newline at end of file diff --git a/modules/cms/ui/themes/default/html/views/file/upload.tpl.src.xml b/modules/cms/ui/themes/default/html/views/file/upload.tpl.src.xml @@ -1,15 +1,19 @@ <output xmlns="http://www.openrat.de/template" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openrat.de/template ../../../../../../../template_engine/components/template.xsd"> - <form> - <fieldset > - <upload name="file"/> - </fieldset> + <form readonly="true"> + <group title="${message:upload}"> + <fieldset> + <upload name="file" multiple="true" /> + </fieldset> - <part class="dropzone-upload"> - <newline /> - <newline /> - <newline /> - <newline /> - </part> + <fieldset> + <part class="dropzone-upload"> + <newline/> + <newline/> + <newline/> + <newline/> + </part> + </fieldset> + </group> </form> </output> diff --git a/modules/cms/ui/themes/default/html/views/image/history.php b/modules/cms/ui/themes/default/html/views/image/history.php @@ -60,7 +60,7 @@ </td> <td><?php echo O::escapeHtml('') ?> <?php $if8=($releasable); if($if8) { ?> - <a title="<?php echo O::escapeHtml(''.@O::lang('RELEASE_DESC').'') ?>" target="<?php echo O::escapeHtml('_self') ?>" data-type="<?php echo O::escapeHtml('post') ?>" data-action="<?php echo O::escapeHtml('') ?>" data-method="<?php echo O::escapeHtml('release') ?>" data-id="<?php echo O::escapeHtml(''.@$objectid.'') ?>" data-extra-valueid="<?php echo O::escapeHtml(''.@$id.'') ?>" data-extra="<?php echo O::escapeHtml('{&quot;valueid&quot;:&quot;'.@$id.'&quot;}') ?>" data-data="<?php echo O::escapeHtml('{"action":"image","subaction":"release","id":"'.@$objectid.'","token":"'.@$_token.'","valueid":"'.@$id.'","none":0}') ?>" class="<?php echo O::escapeHtml('or-link') ?>"><?php echo O::escapeHtml('') ?> + <a title="<?php echo O::escapeHtml(''.@O::lang('RELEASE_DESC').'') ?>" target="<?php echo O::escapeHtml('_self') ?>" data-type="<?php echo O::escapeHtml('post') ?>" data-action="<?php echo O::escapeHtml('') ?>" data-method="<?php echo O::escapeHtml('release') ?>" data-id="<?php echo O::escapeHtml(''.@$objectid.'') ?>" data-extra-valueid="<?php echo O::escapeHtml(''.@$id.'') ?>" data-extra="<?php echo O::escapeHtml('{&quot;valueid&quot;:&quot;'.@$id.'&quot;}') ?>" data-data="<?php echo O::escapeHtml('{"action":"image","subaction":"release","id":"'.@$objectid.'","token":"'.@$_token.'","valueid":"'.@$id.'","none":0}') ?>" class="<?php echo O::escapeHtml('or-link or-act-clickable') ?>"><?php echo O::escapeHtml('') ?> <i class="<?php echo O::escapeHtml('or-image-icon or-image-icon--method-release') ?>"><?php echo O::escapeHtml('') ?></i> </a> <?php } ?> diff --git a/modules/cms/ui/themes/default/html/views/image/history.tpl.src.xml b/modules/cms/ui/themes/default/html/views/image/history.tpl.src.xml @@ -51,7 +51,7 @@ <!-- Actions --> <column> <if true="${releasable}"> - <link type="post" subaction="release" var1="valueid" value1="${id}" + <link clickable="true" type="post" subaction="release" var1="valueid" value1="${id}" id="${objectid}" title="${message:RELEASE_DESC}"> <image method="release"/> </link> diff --git a/modules/cms/ui/themes/default/style/openrat.css b/modules/cms/ui/themes/default/style/openrat.css @@ -1931,9 +1931,9 @@ a.editorlink:visited { } /*# sourceMappingURL=data:application/json,%7B%22version%22%3A3%2C%22sources%22%3A%5B%22var%5C%2Fwww%5C%2Flocalhost%5C%2Fcms%5C%2Fmodules%5C%2Ftemplate_eng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B%2COAAI%2CWAAW%3BCAC5B%2CSAAS%2CQAAT%3B%3BAArEZ%2CGAAC%2CMAyEG%2CGAAE%2CQAAW%3BCACT%3B%3BAA1ER%2CGAAC%2CMA6EG%2CGAAK%3BCACD%3BCACA%3BCACA%3B%3BAAhFR%2CGAAC%2CMAoFG%2CGAAE%3BCACE%3BCACA%3B%3BAAtFR%2CGAAC%2CMAwFG%2CGAAE%3BCACE%3BCACA%3B%3BAA1FR%2CGAAC%2CMA4FG%2CGAAE%3BCACE%3BCACA%3B%3BAA9FR%2CGAAC%2CMAiGG%2CGAAE%2CMAAS%2CMAAG%3BCACV%3B%3BAAlGR%2CGAAC%2CMAsGG%2CGAAG%2CGAAE%3BCACD%3B%3BAAvGR%2CGAAC%2CMA0GG%2CGAAE%2CYAAa%2CGAAE%3B%3B%3B%3BCAIb%3B%3BAAIJ%2CGAlHH%2CMAkHI%3BCACG%22%7D */ /* Include style: /../../../template_engine/components/html/component_upload/upload */ -div.or-dropzone-upload > div.input { +div.or-dropzone-upload { width: 100%; height: 100px; border: 1px dotted; } -/*# sourceMappingURL=data:application/json,%7B%22version%22%3A3%2C%22sources%22%3A%5B%22var%5C%2Fwww%5C%2Flocalhost%5C%2Fcms%5C%2Fmodules%5C%2Ftemplate_engine%5C%2Fcomponents%5C%2Fhtml%5C%2Fcomponent_upload%5C%2Fupload.less%22%5D%2C%22names%22%3A%5B%5D%2C%22mappings%22%3A%22AAAA%2CGAAG%2CmBAAsB%2CMAAG%3BCAE3B%3BCACA%3BCAEA%2CkBAAA%22%7D */ +/*# sourceMappingURL=data:application/json,%7B%22version%22%3A3%2C%22sources%22%3A%5B%22var%5C%2Fwww%5C%2Flocalhost%5C%2Fcms%5C%2Fmodules%5C%2Ftemplate_engine%5C%2Fcomponents%5C%2Fhtml%5C%2Fcomponent_upload%5C%2Fupload.less%22%5D%2C%22names%22%3A%5B%5D%2C%22mappings%22%3A%22AAAA%2CGAAG%3BCAEF%3BCACA%3BCAEA%2CkBAAA%22%7D */ diff --git a/modules/cms/ui/themes/default/style/openrat.min.css b/modules/cms/ui/themes/default/style/openrat.min.css @@ -24,4 +24,4 @@ html,body{width: 100%;height: 100%}@media only screen and (min-width: 56rem){bod .or-group{margin: 2em 0}.or-group-title{font-size: 1.1em;font-weight: normal;border-bottom: 1px solid} .or-table{overflow: auto;border: 2px;width: 100%;table-layout: fixed}.or-table-column-date{width: 12em}.or-table-column-user{width: 7em}.or-table-column-action{width: 5em}.or-table-column-auto{width: auto;max-width: 0}@media screen and (max-width: 40em){.or-table-area{overflow-x: auto}}.or-table-filter{width: 100%;text-align: right}.or-table-filter-input{border-radius: 3px;-moz-border-radius: 3px;-webkit-border-radius: 3px;-khtml-border-radius: 3px;padding: 0.5em;margin: 1em;border: 1px solid #000;width: 7.5em}.or-table tr.or-headline > td,.or-table tr{padding: 0.3em}.or-table tr.or-headline > td .or-row--on-hover,.or-table tr .or-row--on-hover{visibility: hidden}@media only screen and (max-width: 55rem){.or-table tr.or-headline > td .or-row--on-hover,.or-table tr .or-row--on-hover{visibility: visible}}.or-table tr.or-headline > td:hover .or-row--on-hover,.or-table tr:hover .or-row--on-hover{visibility: visible}.or-table tr > th{padding: 3px;font-weight: bold}.or-table tr > th.or-sort-asc > span:last-child:after{content: " \2193"}.or-table tr > th.or-sort-desc > span:last-child:after{content: " \2191"}.or-table tr.or-data > td{padding: 3px}.or-table tr > td{white-space: nowrap;text-overflow: ellipsis;overflow: hidden}.or-table td.or-readonly{font-style: italic;font-weight: normal}.or-table td.or-default{font-style: normal;font-weight: normal}.or-table td.or-changed{font-style: normal;font-weight: bold}.or-table td:hover > div.or-onrowvisible{visibility: visible}.or-table tr td.or-help{font-style: italic}.or-table tr.or-headline td.or-help{font-style: normal}.or-table-sort-value{display: none} -div.or-dropzone-upload > div.input{width: 100%;height: 100px;border: 1px dotted} +div.or-dropzone-upload{width: 100%;height: 100px;border: 1px dotted} diff --git a/modules/cms/ui/themes/default/style/theme/openrat-theme.less b/modules/cms/ui/themes/default/style/theme/openrat-theme.less @@ -370,7 +370,7 @@ html { } - &-dropzone-upload > .or-value { + &-dropzone-upload { background-color: @cms-main-title-text-color; border: 1px dotted @cms-main-text-color; } diff --git a/modules/template_engine/components/html/component_upload/upload.js b/modules/template_engine/components/html/component_upload/upload.js @@ -5,10 +5,10 @@ import $ from "../../../../cms/ui/themes/default/script/jquery-global.js export default function (element ) { - var form = $(element).find('form'); + let form = $(element).find('form'); // Dateiupload über Drag and Drop - var dropzone = $(element).find('div.or-dropzone-upload > div.input'); + let dropzone = $(element).find('div.or-dropzone-upload'); dropzone.on('dragenter', function (e) { e.stopPropagation(); @@ -24,7 +24,7 @@ export default function (element ) { { $(this).css('border','1px dotted red'); e.preventDefault(); - var files = e.originalEvent.dataTransfer.files; + let files = e.originalEvent.dataTransfer.files; //We need to send dropped files to Server Workbench.handleFileUpload(form,files); @@ -34,7 +34,7 @@ export default function (element ) { // Dateiupload über File-Input-Button $(element).find('input[type=file]').change( function() { - var files = $(this).prop('files'); + let files = this.files; Workbench.handleFileUpload(form,files); }); @@ -49,16 +49,18 @@ export default function (element ) { */ Workbench.handleFileUpload = function(form,files) { - for (let i = 0, f; f = files[i]; i++) + for (let i = 0; i < files.length; i++) { + let f = files[i]; let form_data = new FormData(); form_data.append('file' , f); - form_data.append('action' ,'folder'); - form_data.append('subaction',$(form).data('method')); - form_data.append('token' ,$(form).find('input[name=token]').val() ); - form_data.append('id' ,$(form).find('input[name=id]' ).val() ); + form_data.append('action' , $(form).data('action')); + form_data.append('subaction', $(form).data('method')); + form_data.append('token' , $(form).find('input[name=token]').val() ); + form_data.append('id' , $(form).find('input[name=id]' ).val() ); + form_data.append('output' , 'json' ); - let form = new Api(); - form.sendData( form_data ); + let api = new Api(); + api.sendData( form_data ); } } diff --git a/modules/template_engine/components/html/component_upload/upload.less b/modules/template_engine/components/html/component_upload/upload.less @@ -1,4 +1,4 @@ -div.or-dropzone-upload > div.input +div.or-dropzone-upload { width: 100%; height: 100px;