diff --git a/config/app_local.example.php b/config/app_local.example.php index 928e59b15..e8708f584 100644 --- a/config/app_local.example.php +++ b/config/app_local.example.php @@ -269,6 +269,8 @@ * for a complete list of icons * 'sidebar' - additional custom sidebar links added in modules index and single item view, * defined as associative array with 'index' and 'view' keys + * 'dropupload' - custom dropupload element to use for this module, f.i. 'MyPlugin.Form/dropupload' + * 'multiupload' - custom multiupload element to use for this module, f.i. 'MyPlugin.Form/multiupload' */ // 'Modules' => [ // 'objects' => [ @@ -283,6 +285,12 @@ // ], // 'documents' => [ // 'color' => '#cc4700', + // 'dropupload' => [ + // '_element' => 'MyPlugin.Form/dropupload', + // ], + // 'multiupload' => [ + // '_element' => 'MyPlugin.Form/multiupload', + // ], // ], // 'events' => [ // 'color' => '#09c', diff --git a/resources/js/app/app.js b/resources/js/app/app.js index e3c227423..5653c31b3 100644 --- a/resources/js/app/app.js +++ b/resources/js/app/app.js @@ -202,6 +202,7 @@ const _vueInstance = new Vue({ BEDITA.success = success; BEDITA.prompt = prompt; BEDITA.warning = warning; + BEDITA.formatDate = this.$helpers.formatDate; this.selectedTypes = this.queryFilter?.filter?.type || []; }); }, diff --git a/resources/js/app/helpers/view.js b/resources/js/app/helpers/view.js index 1f3b46165..c07e419c1 100644 --- a/resources/js/app/helpers/view.js +++ b/resources/js/app/helpers/view.js @@ -224,6 +224,17 @@ export default { return false; }, + getObjectTypeFromMime(mimeType) { + const mimes = BEDITA.uploadConfig?.accepted; + for (let type in mimes) { + if (this.checkAcceptedMime(mimes[type], mimeType)) { + return type; + } + } + + return null; + }, + titleFromFileName(filename) { let title = filename; title = title.replaceAll('-', ' '); diff --git a/resources/js/app/mixins/paginated-content.js b/resources/js/app/mixins/paginated-content.js index 77bbe7c1c..e552bf59d 100644 --- a/resources/js/app/mixins/paginated-content.js +++ b/resources/js/app/mixins/paginated-content.js @@ -158,7 +158,7 @@ export const PaginatedContentMixin = { formattedObj.type = obj.type; // search for meta.relation using this.formatObjectsFilter - const metaRelation = obj.meta.relation; + const metaRelation = obj?.meta?.relation || {}; if (metaRelation) { let formattedMeta = {}; this.formatObjectsFilter.forEach((filter) => { diff --git a/resources/js/app/pages/modules/index.js b/resources/js/app/pages/modules/index.js index b244ea557..ebe79c095 100644 --- a/resources/js/app/pages/modules/index.js +++ b/resources/js/app/pages/modules/index.js @@ -74,6 +74,9 @@ export default { watch: { selectedRows(val) { + if (!this.$refs.checkAllCB) { + return; + } if (!val.length) { this.$refs.checkAllCB.checked = false; this.$refs.checkAllCB.indeterminate = false; diff --git a/src/Controller/ModulesController.php b/src/Controller/ModulesController.php index 88e1d3143..af074bbb1 100644 --- a/src/Controller/ModulesController.php +++ b/src/Controller/ModulesController.php @@ -588,9 +588,13 @@ public function setObjectType(?string $objectType): void */ private function setupViewRelations(array $relations): void { + // setup relations schema + $relationsSchema = $this->Schema->getRelationsSchema(); + $this->set('relationsSchema', $relationsSchema); + // setup relations metadata $this->Modules->setupRelationsMeta( - $this->Schema->getRelationsSchema(), + $relationsSchema, $relations, $this->Properties->relationsList($this->objectType), $this->Properties->hiddenRelationsList($this->objectType), diff --git a/src/View/Helper/ElementHelper.php b/src/View/Helper/ElementHelper.php index bb46ac640..a3744d21d 100644 --- a/src/View/Helper/ElementHelper.php +++ b/src/View/Helper/ElementHelper.php @@ -47,6 +47,41 @@ public function custom(string $item, string $type = 'relation'): string return (string)Configure::read($path); } + /** + * Return dropupload element path by relation. + * This checks relation right types, and verify if there is a `Modules..dropupload._element` configuration. + * If not, return default `Form/dropupload` element. + * If there is a configuration, return it. + * + * @param array $rightTypes Right types of the relation + * @return string + */ + public function dropupload(array $rightTypes): string + { + foreach ($rightTypes as $name) { + $path = (string)Configure::read(sprintf('Modules.%s.dropupload._element', $name)); + if (!empty($path)) { + return $path; + } + } + + return 'Form/dropupload'; + } + + /** + * Return multiupload element via `Modules..multiupload._element` configuration + * + * @return string + */ + public function multiupload(): string + { + $currentModule = (array)$this->getView()->get('currentModule'); + $name = (string)Hash::get($currentModule, 'name'); + $path = sprintf('Modules.%s.multiupload._element', $name); + + return (string)Configure::read($path, 'Form/multiupload'); + } + /** * Return sidebar element via `Modules..sidebar._element` configuration * diff --git a/templates/Element/Form/dropupload.twig b/templates/Element/Form/dropupload.twig new file mode 100644 index 000000000..6743f1650 --- /dev/null +++ b/templates/Element/Form/dropupload.twig @@ -0,0 +1,7 @@ +{# :accepted-drop="[`.from-relation-${relationName}`,isRelationWithMedia && 'from-files']"> #} + + diff --git a/templates/Element/Form/multiupload.twig b/templates/Element/Form/multiupload.twig new file mode 100644 index 000000000..45f1b6856 --- /dev/null +++ b/templates/Element/Form/multiupload.twig @@ -0,0 +1,42 @@ +{% do _view.assign('title', __('Multi upload')) %} +{% if Perms.canSave() and not readonly %} + + + +{% else %} +
{{ __('You do not have the required permissions to view this page.') }}
+{% endif %} + +{# Add links to the module #} +{% do _view.append('app-module-links', + Html.link( + __('List'), + {'_name': 'modules:list', 'object_type': objectType}, + {'title': __('List'), 'class': 'icon-left-dir button button-outlined button-outlined-hover-module-' ~ objectType} + )|raw +) %} + diff --git a/templates/Element/Form/relation.twig b/templates/Element/Form/relation.twig index 02ab94701..5fd679de6 100644 --- a/templates/Element/Form/relation.twig +++ b/templates/Element/Form/relation.twig @@ -128,16 +128,9 @@

- {# DROP FILES #} {% if uploadableNum %} - {# :accepted-drop="[`.from-relation-${relationName}`,isRelationWithMedia && 'from-files']"> #} - - + {{ element(Element.dropupload(relationsSchema[relationName]['right'])) }} {% endif %} -