Skip to content

Commit

Permalink
feature(Addressbook) multiedit contact properties
Browse files Browse the repository at this point in the history
  • Loading branch information
corneliusweiss committed Jul 3, 2024
1 parent 50ae9a6 commit e6a7266
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 24 deletions.
35 changes: 29 additions & 6 deletions tine20/Addressbook/js/ContactPropertiesGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
export default (config) => {
const app = Tine.Tinebase.appMgr.get(config.recordClass.getMeta('appName'));

let editDialog;

const fieldManager = _.bind(
Tine.widgets.form.FieldManager.get,
Tine.widgets.form.FieldManager,
Expand All @@ -26,6 +28,17 @@ export default (config) => {
Tine.widgets.form.FieldManager.CATEGORY_PROPERTYGRID
);

const multiRenderer = (renderer, value, meta, record) => {
if (editDialog.useMultiple) {
const fieldName = record.get('name').replace(/^\d{3}_/, '');
const multiData = _.find(editDialog.interRecord.multiData, { name: fieldName });
if (multiData?.equalValues === false) {
meta.css += 'tinebase-editmultipledialog-noneedit ';
}
}
return renderer(value, meta, record);
}

config.propertyNames = {};
config.customEditors = {};
config.customRenderers = {};
Expand All @@ -43,7 +56,7 @@ export default (config) => {
const name = `${_.padStart( String(idx), 3, '0')}_${field.fieldName}`;
config.propertyNames[name] = editor.fieldLabel;
config.customEditors[name] = new Ext.grid.GridEditor(Ext.create(editor));
config.customRenderers[name] = Tine.widgets.grid.RendererManager.get(app.appName, config.recordClass, field.fieldName, Tine.widgets.grid.RendererManager.CATEGORY_GRIDPANEL);
config.customRenderers[name] = _.wrap(Tine.widgets.grid.RendererManager.get(app.appName, config.recordClass, field.fieldName, Tine.widgets.grid.RendererManager.CATEGORY_GRIDPANEL), multiRenderer);
});

const propertyGrid = new Ext.grid.PropertyGrid(Object.assign({
Expand All @@ -57,15 +70,14 @@ export default (config) => {
}, config));

propertyGrid.afterIsRendered().then(() => {
const editDialog = propertyGrid.findParentBy(function (c) {
editDialog = propertyGrid.findParentBy(function (c) {
return c instanceof Tine.widgets.dialog.EditDialog
});
editDialog.on('load', onRecordLoad);
editDialog.on('recordUpdate', onRecordUpdate);
//TODO: support propertyGrid im multiple edit mode ?
if (editDialog.useMultiple) {
propertyGrid.setDisabled(true);
}

editDialog.on('multipleRecordUpdate', onMultipleRecordUpdate);

// NOTE: in case we are rendered after record was load
onRecordLoad(editDialog, editDialog.record);
});
Expand Down Expand Up @@ -93,5 +105,16 @@ export default (config) => {
});
};

const onMultipleRecordUpdate = (p, changes) => {
// if currentValue differs from startValue add to changes
_.forEach(propertyGrid.getSource(), (value, name) => {
const fieldName = name.replace(/^\d{3}_/, '');
const multiData = _.find(p.interRecord.multiData, { name: fieldName });
if (multiData && multiData.startValue != value) {
changes.push({name: fieldName, value});
}
});
};

return propertyGrid;
}
5 changes: 3 additions & 2 deletions tine20/Tinebase/css/Tinebase.less
Original file line number Diff line number Diff line change
Expand Up @@ -1087,8 +1087,9 @@ span:hover.tinebase-showheaders-link {

.tinebase-editmultipledialog-noneedit,
input.tinebase-editmultipledialog-noneedit,
textarea.x-form-field.tinebase-editmultipledialog-noneedit {
background-color: #f4f1d3;
textarea.x-form-field.tinebase-editmultipledialog-noneedit,
.x-props-grid .x-grid3-body .x-grid3-td-value.tinebase-editmultipledialog-noneedit {
background-color: #f4f1d3 !important;
background-image:none!important;
}

Expand Down
5 changes: 3 additions & 2 deletions tine20/Tinebase/css/darkmode.less
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,9 @@ body.dark-mode {
}
.tinebase-editmultipledialog-noneedit,
input.tinebase-editmultipledialog-noneedit,
textarea.x-form-field.tinebase-editmultipledialog-noneedit {
background-color: #4f4021;
textarea.x-form-field.tinebase-editmultipledialog-noneedit,
.x-props-grid .x-grid3-body .x-grid3-td-value.tinebase-editmultipledialog-noneedit {
background-color: #4f4021 !important;
background-image:none!important;
}

Expand Down
44 changes: 30 additions & 14 deletions tine20/Tinebase/js/widgets/dialog/MultipleEditDialogPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,13 @@ Tine.widgets.dialog.MultipleEditDialogPlugin.prototype = {
ed.onRecordUpdate = Ext.emptyFn;
ed.initRecord = Ext.emptyFn;
ed.useMultiple = true;
ed.interRecord = new ed.recordClass({});
ed.interRecord = this.interRecord = new ed.recordClass({});
ed.loadRecord = true;
ed.checkUnsavedChanges = false;

this.app = Tine.Tinebase.appMgr.get(ed.app);
this.handleFields = [];
this.interRecord = ed.interRecord;


if (ed.action_saveAndClose) {
ed.action_saveAndClose.enable();
}
Expand Down Expand Up @@ -203,13 +202,11 @@ Tine.widgets.dialog.MultipleEditDialogPlugin.prototype = {
// disable fields which cannot be handled atm.
if (!ff) {
Tine.log.debug('Disabling key "' + field?.recordKey + '" with specialType : ' + field?.specialType + '. Cannot be handled atm.');
this.interRecord.set(field?.recordKey, '');
return true;
}
if ((!(ff.isXType('textfield'))) && (!(ff.isXType('checkbox'))) && (!(ff.isXType('datetimefield'))) || ff.multiEditable === false) {
Tine.log.debug('Disabling field for key "' + field.recordKey + '". Cannot be handled atm.');
ff.setDisabled(true);
this.interRecord.set(field.recordKey, '');
return true;
}
// remove empty text
Expand Down Expand Up @@ -531,31 +528,37 @@ Tine.widgets.dialog.MultipleEditDialogPlugin.prototype = {
* find out which fields have differences
*/
onRecordPrepare: function(records) {
Ext.each(this.handleFields, function(field) {
this.interRecord.multiData = [];
Ext.each(this.editDialog.recordClass.getFieldDefinitions(), function(fieldDef) {
var field = _.find(this.handleFields, {key: fieldDef.name});
var refData = false;
var multiData = {name: fieldDef.name};
this.interRecord.multiData.push(multiData);
Ext.each(records, function(record, index) {
if (field.type == 'relation') {
if (field && field.type == 'relation') {
this.setFieldValue(field, false);
} else {
// the first record of the selected is the reference
if (index === 0) {
refData = record.get(field.recordKey);
refData = record.get(fieldDef.name);
}
if ((Ext.encode(record.get(field.recordKey)) != Ext.encode(refData))) {
this.interRecord.set(field.recordKey, '');
this.setFieldValue(field, false);
if ((Ext.encode(record.get(fieldDef.name)) != Ext.encode(refData))) {
this.interRecord.set(fieldDef.name, '');
Object.assign(multiData, { equalValues: false, startValue: '' });
field && this.setFieldValue(field, false);
return false;
} else {
if (index == records.length - 1) {
this.interRecord.set(field.recordKey, refData);
this.setFieldValue(field, true);
this.interRecord.set(fieldDef.name, refData);
Object.assign(multiData, { equalValues: true, startValue: refData });
field && this.setFieldValue(field, true);
return true;
}
}
}
}, this);
}, this);

// TODO: grantsProperty not handled here, not needed at the moment but sometimes, perhaps.
// var cp = this.editDialog.recordClass.getMeta('containerProperty') ? this.editDialog.recordClass.getMeta('containerProperty') : 'container_id';
// if (this.interRecord.get(cp) !== undefined) {
Expand Down Expand Up @@ -759,6 +762,19 @@ Tine.widgets.dialog.MultipleEditDialogPlugin.prototype = {
this.changedHuman += '</li>';
}, this);

const humChanges = _.map(changes, 'name');

this.editDialog.fireEvent('multipleRecordUpdate', this, changes);

const rc = this.editDialog.recordClass;
_.forEach(changes, (change) => {
if (humChanges.indexOf(change.name) < 0) {
const label = this.editDialog.app.i18n._hidden(rc.getField(change.name).label);
const value = Tine.widgets.grid.RendererManager.get(rc.getAppName(), rc.getPhpClassName(), change.name, 'displayPanel')(change.value);

this.changedHuman += `<li><span style="font-weight:bold">${label}:</span> ${value}</li>`;
}
});
this.changedHuman += '</ul>';
var filter = this.selectionFilter;
if (changes.length > 0) {
Expand Down

0 comments on commit e6a7266

Please sign in to comment.