Skip to content

Commit

Permalink
Merge branch 'pu/cw/fixSiteFilering' into 'main'
Browse files Browse the repository at this point in the history
Pu/cw/fix site filering

See merge request tine20/tine20!6631
  • Loading branch information
corneliusweiss committed Feb 24, 2025
2 parents 2c59b27 + 756a141 commit a5d164c
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 29 deletions.
9 changes: 0 additions & 9 deletions tine20/Addressbook/Model/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 => [
Expand Down
2 changes: 1 addition & 1 deletion tine20/Addressbook/Model/ContactSite.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
3 changes: 3 additions & 0 deletions tine20/Addressbook/translations/de.po
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,9 @@ msgid_plural "Sites"
msgstr[0] "Standort"
msgstr[1] "Standorte"

msgid "GENDER_Site"
msgstr "male"

msgid "GENDER_Group"
msgstr "female"

Expand Down
4 changes: 4 additions & 0 deletions tine20/Calendar/Model/EventFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]],
);
}
18 changes: 9 additions & 9 deletions tine20/Calendar/js/EventEditDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
}
},

Expand Down
10 changes: 7 additions & 3 deletions tine20/Calendar/js/Model/Event.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand All @@ -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',
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions tine20/Tinebase/js/data/GroupedStoreCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

/**
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 5 additions & 2 deletions tine20/Tinebase/js/data/Record.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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
*
Expand Down
4 changes: 1 addition & 3 deletions tine20/Tinebase/js/widgets/SiteFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions tine20/Tinebase/js/widgets/customfields/FilterModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 10 additions & 2 deletions tine20/Tinebase/js/widgets/grid/ForeignRecordFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 3 additions & 0 deletions tine20/Tinebase/translations/de.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit a5d164c

Please sign in to comment.