From 5a2d4a1cdc0e1d7f4300a6477fa693059bc60c7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cornelius=20Wei=C3=9F?= Date: Mon, 24 Feb 2025 20:06:40 +0100 Subject: [PATCH 1/2] fix(Tinebase): make new Tinebase.site filters working in adb --- tine20/Addressbook/Model/Contact.php | 9 --------- tine20/Addressbook/Model/ContactSite.php | 2 +- tine20/Addressbook/translations/de.po | 3 +++ tine20/Calendar/Model/EventFilter.php | 4 ++++ tine20/Calendar/js/EventEditDialog.js | 18 +++++++++--------- tine20/Calendar/js/Model/Event.js | 10 +++++++--- tine20/Tinebase/js/widgets/SiteFilter.js | 4 +--- .../js/widgets/customfields/FilterModel.js | 4 ++++ .../js/widgets/grid/ForeignRecordFilter.js | 12 ++++++++++-- tine20/Tinebase/translations/de.po | 3 +++ 10 files changed, 42 insertions(+), 27 deletions(-) diff --git a/tine20/Addressbook/Model/Contact.php b/tine20/Addressbook/Model/Contact.php index 17df8e56554..55d45a23a5f 100644 --- a/tine20/Addressbook/Model/Contact.php +++ b/tine20/Addressbook/Model/Contact.php @@ -326,15 +326,6 @@ class Addressbook_Model_Contact extends Tinebase_Record_NewAbstract 'adr_two_countryname' => [ 'filter' => Tinebase_Model_Filter_Country::class, ], - 'sites' => [ - 'filter' => Tinebase_Model_Filter_ForeignRecords::class, - 'label' => 'Sites', // _('Sites') - 'options' => [ - 'controller' => Addressbook_Controller_ContactSite::class, - 'recordClassName' => Addressbook_Model_ContactSite::class, - 'refIdField' => 'record', - ] - ], ], self::FIELDS => [ diff --git a/tine20/Addressbook/Model/ContactSite.php b/tine20/Addressbook/Model/ContactSite.php index 6cf211bf902..3bf9c66a4e3 100644 --- a/tine20/Addressbook/Model/ContactSite.php +++ b/tine20/Addressbook/Model/ContactSite.php @@ -32,7 +32,7 @@ class Addressbook_Model_ContactSite extends Tinebase_Record_NewAbstract */ protected static $_modelConfiguration = [ self::VERSION => 1, - self::RECORD_NAME => 'Site', + self::RECORD_NAME => 'Site', // ngettext('GENDER_Site') self::RECORDS_NAME => 'Sites', // ngettext('Site', 'Sites', n) self::TITLE_PROPERTY => "{{ renderTitle(site, 'Addressbook_Model_Contact') }}", self::DEFAULT_SORT_INFO => [self::FIELD => self::FLD_SITE], diff --git a/tine20/Addressbook/translations/de.po b/tine20/Addressbook/translations/de.po index 6b34fd35c4e..cccf3986860 100644 --- a/tine20/Addressbook/translations/de.po +++ b/tine20/Addressbook/translations/de.po @@ -861,6 +861,9 @@ msgid_plural "Sites" msgstr[0] "Standort" msgstr[1] "Standorte" +msgid "GENDER_Site" +msgstr "male" + msgid "GENDER_Group" msgstr "female" diff --git a/tine20/Calendar/Model/EventFilter.php b/tine20/Calendar/Model/EventFilter.php index 37cc301ba7e..ac229075767 100644 --- a/tine20/Calendar/Model/EventFilter.php +++ b/tine20/Calendar/Model/EventFilter.php @@ -79,5 +79,9 @@ class Calendar_Model_EventFilter extends Tinebase_Model_Filter_FilterGroup 'recordClassName' => Calendar_Model_EventTypes::class, 'refIdField' => 'record', ]], + 'event_site' => ['filter' => Tinebase_Model_Filter_ForeignId::class, 'options' => [ + 'controller' => Addressbook_Controller_Contact::class, + 'filtergroup' => Addressbook_Model_ContactFilter::class, + ]], ); } diff --git a/tine20/Calendar/js/EventEditDialog.js b/tine20/Calendar/js/EventEditDialog.js index dd6180ee960..48eb9f2676e 100644 --- a/tine20/Calendar/js/EventEditDialog.js +++ b/tine20/Calendar/js/EventEditDialog.js @@ -577,6 +577,7 @@ Tine.Calendar.EventEditDialog = Ext.extend(Tine.widgets.dialog.EditDialog, { setLocationRecord: function(resource, overwrite = false) { const locationField = this.getForm().findField('location'); const locationRecordField = this.getForm().findField('location_record'); + const siteField = this.getForm().findField('event_site'); if (! locationField.getValue() || overwrite) { locationField.setValue( @@ -586,19 +587,18 @@ Tine.Calendar.EventEditDialog = Ext.extend(Tine.widgets.dialog.EditDialog, { var relations = _.get(resource, 'data.user_id.relations'), locationId = relations ? _.findIndex(relations, function(k) { return k.type == 'LOCATION'; }) : -1, - locationContact = locationId >= 0 ? relations[locationId].related_record : null; + locationContact = locationId >= 0 ? relations[locationId].related_record : null, + siteId = relations ? _.findIndex(relations, function (k) { return k.type == 'SITE'; }) : -1, + siteContact = siteId >= 0 ? relations[siteId].related_record : null; if (locationContact && (!locationRecordField.getValue() || overwrite)) { locationRecordField.setValue(locationContact); - } else { - var siteId = relations ? _.findIndex(relations, function (k) { - return k.type == 'SITE'; - }) : -1, - siteContact = siteId >= 0 ? relations[siteId].related_record : null; + } else if (siteContact && (!locationRecordField.getValue() || overwrite)) { + locationRecordField.setValue(siteContact); + } - if (siteContact && (!locationRecordField.getValue() || overwrite)) { - locationRecordField.setValue(siteContact); - } + if (Tine.Tinebase.featureEnabled('featureSite') && siteContact && (!siteField.getValue || overwrite)) { + siteField.setValue(siteContact) } }, diff --git a/tine20/Calendar/js/Model/Event.js b/tine20/Calendar/js/Model/Event.js index 3fa4293aa6c..a25bef0079b 100644 --- a/tine20/Calendar/js/Model/Event.js +++ b/tine20/Calendar/js/Model/Event.js @@ -30,7 +30,11 @@ const Event = Record.create(Record.genericFields.concat([ { name: 'adr_lat' }, { name: 'location' }, { name: 'location_record' }, - { name: 'event_site' }, + { name: 'event_site', type: 'record', fieldDefinition: { config: { + // we need some fieldDef to get grouping store working + appName: 'Addressbook', + modelName: 'Contact', + }}}, { name: 'organizer_type' }, { name: 'organizer' }, { name: 'organizer_email' }, @@ -47,7 +51,7 @@ const Event = Record.create(Record.genericFields.concat([ { name: 'tags' }, { name: 'notes'}, { name: 'attachments'}, - { name: 'event_types', fieldDefinition: {config: { + { name: 'event_types', type: 'records', fieldDefinition: { config: { // we need some fieldDef to get filter working appName: 'Calendar', modelName: 'EventTypes', @@ -521,7 +525,7 @@ Event.getFilterModel = function() { filter.push({filtertype: 'foreignrecord', linkType: 'foreignId', app: app, ownRecordClass: 'Calendar.Event', ownField: 'event_types', foreignRecordClass: 'Calendar.EventTypes'}); } if (Tine.Tinebase.featureEnabled('featureSite')) { - filter.push({filtertype: 'tinebase.site', app: app}); + filter.push({filtertype: 'tinebase.site', app: app, field: 'event_site'}); } return filter; diff --git a/tine20/Tinebase/js/widgets/SiteFilter.js b/tine20/Tinebase/js/widgets/SiteFilter.js index 986dbdcce88..3e6e3b1ff20 100644 --- a/tine20/Tinebase/js/widgets/SiteFilter.js +++ b/tine20/Tinebase/js/widgets/SiteFilter.js @@ -18,15 +18,13 @@ Tine.Tinebase.SiteFilter = Ext.extend(Tine.widgets.grid.ForeignRecordFilter, { // private field: 'site', - valueType: 'relation', /** * @private */ initComponent: function() { - var i18n = Tine.Tinebase.appMgr.get('Tinebase').i18n; this.label = i18n._('Site'); - this.foreignRecordClass = Tine.Addressbook.Model.Contact; + this.gender = i18n._('GENDER_Site'); this.pickerConfig = { emptyText: i18n._('no site association'), allowBlank: true, diff --git a/tine20/Tinebase/js/widgets/customfields/FilterModel.js b/tine20/Tinebase/js/widgets/customfields/FilterModel.js index 10437328f6d..5e433b7868a 100644 --- a/tine20/Tinebase/js/widgets/customfields/FilterModel.js +++ b/tine20/Tinebase/js/widgets/customfields/FilterModel.js @@ -111,6 +111,10 @@ Tine.widgets.customfields.FilterModel = Ext.extend(Tine.widgets.grid.FilterModel switch (cfDefinition.type) { case 'record': if (_.get(window, cfDefinition.recordConfig.value.records)) { + // @TODO remove on EBHH #1690 cleanup + if (modelName === 'Calendar_Model_Event' && _.get(cfDefinition, 'recordConfig.value.records') === 'Tine.Addressbook.Model.Contact' && Tine.Tinebase.featureEnabled('featureSite')) { + return; + } result.push({ filtertype: 'foreignrecord', label: cfDefinition.label, diff --git a/tine20/Tinebase/js/widgets/grid/ForeignRecordFilter.js b/tine20/Tinebase/js/widgets/grid/ForeignRecordFilter.js index 647d56dc8d5..2e7d3e20f29 100644 --- a/tine20/Tinebase/js/widgets/grid/ForeignRecordFilter.js +++ b/tine20/Tinebase/js/widgets/grid/ForeignRecordFilter.js @@ -99,9 +99,17 @@ Tine.widgets.grid.ForeignRecordFilter = Ext.extend(Tine.widgets.grid.FilterModel this.ownRecordClass = Tine.Tinebase.data.RecordMgr.get(this.ownRecordClass); } if (!this.ownRecordClass) { - this.ownRecordClass = Tine.Tinebase.data.RecordMgr.get(this.appName, this.modelName); + this.ownRecordClass = Tine.Tinebase.data.RecordMgr.get(this.appName, this.modelName) + || this.ftb.recordClass; + } + + if (!this.foreignRecordClass) { + // NOTE: def is equal to mc, but we can fake it in legacy models + const def = this.ownRecordClass.getField(this.field)?.fieldDefinition; + if (def && def.config) { + this.foreignRecordClass = `${def.config.appName}.${def.config.modelName}` + } } - if (this.foreignRecordClass) { this.foreignRecordClass = Tine.Tinebase.data.RecordMgr.get(this.foreignRecordClass); } diff --git a/tine20/Tinebase/translations/de.po b/tine20/Tinebase/translations/de.po index bbdca5d091c..1fd774ae84d 100644 --- a/tine20/Tinebase/translations/de.po +++ b/tine20/Tinebase/translations/de.po @@ -3642,6 +3642,9 @@ msgstr "Entferne nur die { ownRecordName } Verknüpfunge zu dieser { relatedReco msgid "Site" msgstr "Standort" +msgid "GENDER_Site" +msgstr "male" + msgid "no site association" msgstr "Keine Standort Zuordnung" From 756a141f7221145b722bba9686fa80193e407584 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cornelius=20Wei=C3=9F?= Date: Mon, 24 Feb 2025 20:07:51 +0100 Subject: [PATCH 2/2] fix(Tinebase): client side grouping not working for record fields --- tine20/Tinebase/js/data/GroupedStoreCollection.js | 13 +++++++++++++ tine20/Tinebase/js/data/Record.js | 7 +++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/tine20/Tinebase/js/data/GroupedStoreCollection.js b/tine20/Tinebase/js/data/GroupedStoreCollection.js index d62fdd26462..4da5091cae0 100644 --- a/tine20/Tinebase/js/data/GroupedStoreCollection.js +++ b/tine20/Tinebase/js/data/GroupedStoreCollection.js @@ -6,6 +6,9 @@ * @copyright Copyright (c) 2017 Metaways Infosystems GmbH (http://www.metaways.de) */ +import recordMgr from './RecordMgr' +import Record from './Record' + Ext.ns('Tine.Tinebase.data'); /** @@ -159,6 +162,16 @@ Ext.extend(Tine.Tinebase.data.GroupedStoreCollection, Ext.util.MixedCollection, groupNames = [groupNames]; } + groupNames = groupNames.map((groupName) => { + if (_.isObject(groupName) && ! _.isFunction(groupName.getTitle) && _.isString(this.group)) { + const conf = _.get(record.constructor.getField(this.group), 'fieldDefinition.config'); + let recordClass + if (conf && conf.appName && conf.modelName && (recordClass = recordMgr.get(conf.appName, conf.modelName))) { + return Record.setFromJson(groupName, recordClass) + } + } + return groupName; + }) groupNames = await this.sanitizeGroupNames(groupNames); if (this.fixedGroups.length) { diff --git a/tine20/Tinebase/js/data/Record.js b/tine20/Tinebase/js/data/Record.js index e3bf2071ffd..df262f4c3f0 100644 --- a/tine20/Tinebase/js/data/Record.js +++ b/tine20/Tinebase/js/data/Record.js @@ -10,7 +10,7 @@ const { apply, extend, isPrimitive, isArray, isString } = require("Ext/core/core/Ext"); const { emptyFn } = require("Ext/core/Ext-more"); -const { lowerFirst, get, find, forEach, isFunction, isObject, indexOf, map, difference, compact } = require('lodash'); +const { lowerFirst, get, set, find, forEach, isFunction, isObject, indexOf, map, difference, compact } = require('lodash'); const ExtRecord = require("Ext/data/Record"); const MixedCollection = require("Ext/util/MixedCollection"); const Field = require("Ext/data/DataField"); @@ -180,7 +180,10 @@ extend(Record, ExtRecord, { this.afterEdit(); } }, - + + getData: function() { + return set(ExtRecord.prototype.getData.call(this), '__meta.recordClass', `${this.appName}.${this.modelName}`); + }, /** * returns title of this record *