Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
feature(Tinebase): create new local records in recordsPickerGrid
Browse files Browse the repository at this point in the history
Change-Id: Ice7f224c9ccf3e253288b237f80c10749cdadcc3
Reviewed-on: http://gerrit.tine20.com/customers/18541
Tested-by: Jenkins CI (http://ci.tine20.com/) <tine20-jenkins@metaways.de>
Reviewed-by: Cornelius Weiss <c.weiss@metaways.de>
  • Loading branch information
corneliusweiss committed Nov 30, 2020
1 parent 2d0090f commit 73e0f2d
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 275 deletions.
4 changes: 0 additions & 4 deletions tine20/HumanResources/HumanResources.jsb2
Expand Up @@ -86,10 +86,6 @@
{
"text": "WorkingTimeSchemeEditDialog.js",
"path": "js/"
},
{
"text": "StreamEditDialog.js",
"path": "js/"
}
]
},
Expand Down
237 changes: 0 additions & 237 deletions tine20/HumanResources/js/StreamEditDialog.js

This file was deleted.

30 changes: 0 additions & 30 deletions tine20/HumanResources/js/StreamGridPanel.js

This file was deleted.

2 changes: 2 additions & 0 deletions tine20/Tinebase/js/widgets/form/FieldManager.js
Expand Up @@ -207,6 +207,8 @@ Tine.widgets.form.FieldManager = function() {
if (category === 'editDialog') {
field.xtype = 'wdgt.pickergrid';
field.recordClass = Tine[fieldDefinition.config.appName].Model[fieldDefinition.config.modelName];
field.allowCreateNew = _.get(fieldDefinition, 'config.dependentRecords', false);
field.enableTbar = !_.get(fieldDefinition, 'config.dependentRecords', false);
field.isFormField = true;
field.fieldName = fieldDefinition.fieldName;
field.hideHeaders = true;
Expand Down
2 changes: 1 addition & 1 deletion tine20/Tinebase/js/widgets/form/RecordPickerComboBox.js
Expand Up @@ -126,7 +126,7 @@ Tine.Tinebase.widgets.form.RecordPickerComboBox = Ext.extend(Ext.ux.form.Clearab
this.disableClearer = ! this.allowBlank;

this.emptyText = this.emptyText ||
(this.readOnly || this.disabled ? '' : String.format(i18n._('Search for {0} ...'), this.recordClass.getRecordName()));
(this.readOnly || this.disabled ? '' : String.format(i18n._('Search for {0} ...'), this.recordClass.getRecordName() || _('Record')));

this.loadingText = i18n._('Searching...');

Expand Down
41 changes: 38 additions & 3 deletions tine20/Tinebase/js/widgets/grid/PickerGridPanel.js
Expand Up @@ -108,6 +108,12 @@ Tine.widgets.grid.PickerGridPanel = Ext.extend(Ext.grid.EditorGridPanel, {
*/
readOnly: false,

/**
* @cfg {Bool} allowCreateNew
* allow to create new records (local mode only atm.!)
*/
allowCreateNew: false,

/**
* config spec for additionalFilters - passed to RecordPicker
*
Expand Down Expand Up @@ -136,6 +142,8 @@ Tine.widgets.grid.PickerGridPanel = Ext.extend(Ext.grid.EditorGridPanel, {
this.searchComboConfig.additionalFilterSpec = this.additionalFilterSpec;

this.labelField = this.labelField ? this.labelField : (this.recordClass && this.recordClass.getMeta ? this.recordClass.getMeta('titleProperty') : null);
this.recordName = this.recordName ? this.recordName : (this.recordClass && this.recordClass.getRecordName ? this.recordClass.getRecordName() || _('Record') : _('Record'));

if (String(this.labelField).match(/{/)) {
this.labelField = this.labelField.match(/(?:{{\s*)(\w+)/)[1];
}
Expand Down Expand Up @@ -222,13 +230,21 @@ Tine.widgets.grid.PickerGridPanel = Ext.extend(Ext.grid.EditorGridPanel, {
* init actions and toolbars
*/
initActionsAndToolbars: function() {

this.actionCreate = new Ext.Action({
text: String.format(i18n._('Create {0}'), this.recordName),
hidden: !this.recordClass || !this.allowCreateNew,
scope: this,
handler: this.onCreate,
iconCls: 'action_add'
});

this.actionRemove = new Ext.Action({
text: i18n._('Remove record'),
text: String.format(i18n._('Remove {0}'), this.recordName),
disabled: true,
scope: this,
handler: this.onRemove,
iconCls: 'action_deleteContact',
iconCls: 'action_delete',
actionUpdater: this.actionRemoveUpdater
});

Expand All @@ -238,14 +254,15 @@ Tine.widgets.grid.PickerGridPanel = Ext.extend(Ext.grid.EditorGridPanel, {
evalGrants: this.evalGrants
});
this.actionUpdater.addActions([
this.actionCreate,
this.actionRemove
]);

this.selModel.on('selectionchange', function(sm) {
this.actionUpdater.updateActions(sm);
}, this);

var contextItems = [this.actionRemove];
var contextItems = [this.actionCreate, this.actionRemove];
this.contextMenu = new Ext.menu.Menu({
plugins: [{
ptype: 'ux.itemregistry',
Expand All @@ -267,6 +284,7 @@ Tine.widgets.grid.PickerGridPanel = Ext.extend(Ext.grid.EditorGridPanel, {
if (this.enableBbar) {
this.bbar = new Ext.Toolbar({
items: [
this.actionCreate,
this.actionRemove
].concat(this.contextMenuItems)
});
Expand Down Expand Up @@ -446,6 +464,23 @@ Tine.widgets.grid.PickerGridPanel = Ext.extend(Ext.grid.EditorGridPanel, {

picker.reset();
},

onCreate: function() {
const record = Tine.Tinebase.data.Record.setFromJson(Ext.apply(this.recordClass.getDefaultData(), this.recordDefaults || {}), this.recordClass);
const editDialogClass = this.editDialogClass || Tine.widgets.dialog.EditDialog.getConstructor(this.recordClass);

editDialogClass.openWindow({
mode: 'local',
record: Ext.encode(record.data),
recordId: record.getId(),
listeners: {
update: (recordData) => {
const record = Tine.Tinebase.data.Record.setFromJson(recordData, this.recordClass);
this.store.add(record);
}
}
});
},

/**
* remove handler
Expand Down

0 comments on commit 73e0f2d

Please sign in to comment.