Skip to content

Commit

Permalink
fix(Tinebase/js): select new created grid node in filemanager
Browse files Browse the repository at this point in the history
  • Loading branch information
ccheng-dev committed Jul 30, 2024
1 parent 6457965 commit 5703fda
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 59 deletions.
2 changes: 1 addition & 1 deletion tine20/Felamimail/js/RecipientPickerFavoritePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Tine.Felamimail.RecipientPickerFavoritePanel = Ext.extend(Tine.widgets.persisten
const filterValue = [];
const emailRegExp = /<([^>]*)/;
let filter = [{field: 'container_id', operator: 'in', value: []}];
debugger

Ext.each(emailRecipients, function(email) {
emailRegExp.exec(email);
if (RegExp.$1 !== '') {
Expand Down
45 changes: 19 additions & 26 deletions tine20/Filemanager/js/NodeGridPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,10 @@ Tine.Filemanager.NodeGridPanel = Ext.extend(Tine.widgets.grid.GridPanel, {
*/
onRecordChanges: function(data, e) {
const existingRecord = this.getRecordByData(data);

if (!existingRecord && e.topic.match(/\.create/)) {
this.onUpdateGridPanel(data);
if (e.topic.match(/\.create/)) {
if (!existingRecord || !existingRecord.data?.id) {
this.onUpdateGridPanel(data);
}
} else if (e.topic.match(/\.update/)) {
this.onUpdateGridPanel(data);
} else if (existingRecord && e.topic.match(/\.delete/)) {
Expand All @@ -201,17 +202,12 @@ Tine.Filemanager.NodeGridPanel = Ext.extend(Tine.widgets.grid.GridPanel, {
* @param {String} mode
*/
onUpdateGridPanel: function (record, mode) {
if (!this.rendered) {
return;
}

const store = this.getStore();
if (!this.rendered) return;

if (record.status === 'failed' || record.status === 'cancelled') {
this.bufferedLoadGridData({
removeStrategy: 'keepBuffered'
});

return;
}

Expand All @@ -221,31 +217,26 @@ Tine.Filemanager.NodeGridPanel = Ext.extend(Tine.widgets.grid.GridPanel, {
Tine.log.debug('Tine.Filemanager.NodeGridPanel::onUpdateRecord() -> record:');
Tine.log.debug(record, mode);

let isSelected = false;
this.selection = this.getGrid().getSelectionModel().getSelections()[0];

const store = this.getStore();

if (record && Ext.isFunction(record.copy)) {
if (this.isInCurrentGrid(record.get('path'))) {
if (existingRecord) {
const idx = store.indexOf(existingRecord);
isSelected = this.getGrid().getSelectionModel().isSelected(idx);
if (isSelected) {
this.selection = existingRecord;
}
const isSelected = this.getGrid().getSelectionModel().isSelected(idx);

store.removeAt(idx);
store.insert(idx, [record]);

if (isSelected) {
this.getGrid().getSelectionModel().selectRow(idx);
}
} else {
store.add([record]);
this.localSort();
}
} else {
return;
}
}

if (this.selection?.data?.path) {
this.getGrid().getSelectionModel().selectRow(store.find('path', this.selection.data.path), true);
}
},

localSort: function() {
Expand All @@ -257,10 +248,6 @@ Tine.Filemanager.NodeGridPanel = Ext.extend(Tine.widgets.grid.GridPanel, {
_.get(store, 'sortInfo.direction', this.defaultSortInfo.direction)
);
store.remoteSort = this.storeRemoteSort;

if (this.selection?.data?.path) {
this.getGrid().getSelectionModel().selectRow(store.find('path', this.selection.data.path), true);
}
},

/**
Expand Down Expand Up @@ -901,6 +888,12 @@ Tine.Filemanager.NodeGridPanel = Ext.extend(Tine.widgets.grid.GridPanel, {
className += ' x-type-data-failed'
}
}
const selections = this.getGrid().getSelectionModel().getSelections();
selections.forEach((item) => {
if (record.id === item.id) {
className += ' x-grid3-row-selected';
}
})

return className;
},
Expand Down
4 changes: 3 additions & 1 deletion tine20/Filemanager/js/nodeActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ Tine.Filemanager.nodeActions.CreateFolder = {
Ext.Msg.alert(String.format(app.i18n._('Not renamed {0}'), nodeName), app.i18n._('Illegal characters: ') + text);
return;
}

return await Tine.Filemanager.nodeBackend.createFolder(`${currentPath}${localRecord.get('name')}/`)
.then((result) => {
if (result.data.path === `/shared/${text}/`) {
Expand All @@ -202,6 +202,7 @@ Tine.Filemanager.nodeActions.CreateFolder = {
activeTabName: 'Grants'
});
}
return result;
})
.catch((e) => {
window.postal.publish({
Expand All @@ -213,6 +214,7 @@ Tine.Filemanager.nodeActions.CreateFolder = {
if (e.message === "file exists") {
Ext.Msg.alert(String.format(app.i18n._('No {0} added'), nodeName), app.i18n._('Folder with this name already exists!'));
}
return false;
}).finally(() => {
this.editing = false;
});
Expand Down
18 changes: 1 addition & 17 deletions tine20/Tinebase/js/widgets/grid/FilterSelectionModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,23 +110,7 @@ Tine.widgets.grid.FilterSelectionModel = Ext.extend(Ext.grid.RowSelectionModel,

Tine.widgets.grid.FilterSelectionModel.superclass.selectAll.call(this);
},

/**
* @private
*/
onRefresh : function(){
this.clearSelections(true);
Tine.widgets.grid.FilterSelectionModel.superclass.onRefresh.call(this);
},

/**
* @private
*/
onRemove : function(v, index, r){
this.clearSelections(true);
Tine.widgets.grid.FilterSelectionModel.superclass.onRemove.call(this, v, index, r);
},


/**
* Deselects a row.
* @param {Number} row The index of the row to deselect
Expand Down
21 changes: 7 additions & 14 deletions tine20/Tinebase/js/widgets/grid/GridPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,10 @@ Ext.extend(Tine.widgets.grid.GridPanel, Ext.Panel, {
});
},

onClick: function(e, target) {
debugger
},

getRecordByData(data) {
const idProperty = this.recordClass.getMeta('idProperty');
return this.store.getById(_.get(data, idProperty));
Expand Down Expand Up @@ -1361,22 +1365,11 @@ Ext.extend(Tine.widgets.grid.GridPanel, Ext.Panel, {
this.pagingToolbar.refresh.disable();
this.store.remove(localRecord);
this.store.addSorted(localRecord);
this.grid.getSelectionModel().selectRow(this.store.indexOf(localRecord));
const selectedIdx = this.store.indexOf(localRecord);

await proxyFn(localRecord)
.then((result) => {
if (result?.data) {
window.postal.publish({
channel: "recordchange",
topic: 'Filemanager.Node.delete',
data: localRecord.data
});

window.postal.publish({
channel: "recordchange",
topic: (result.data.path === 'tempFile' ? 'Tinebase.TempFile' : 'Filemanager.Node') + '.create',
data: result.data
});
}
this.grid.getSelectionModel().selectRow(selectedIdx);
})
.catch((e) => {
window.postal.publish({
Expand Down
4 changes: 4 additions & 0 deletions tine20/Tinebase/js/widgets/persistentfilter/PickerPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ Tine.widgets.persistentfilter.PickerPanel = Ext.extend(Ext.tree.TreePanel, {
// removed
store.on('beforeload', this.storeOnBeforeload, this);
store.load({persistentFilter : persistentFilter});

if (this.getGrid()?.grid) {
this.getGrid().grid.getSelectionModel().clearSelections();
}
},

/**
Expand Down
1 change: 1 addition & 0 deletions tine20/library/ExtJS/src/widgets/grid/GridView.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
import {getLayoutClassByWidth, getLayoutClassByMode} from "../../../../../Tinebase/js/util/responsiveLayout";

/**
/**
* @class Ext.grid.GridView
* @extends Ext.util.Observable
Expand Down

0 comments on commit 5703fda

Please sign in to comment.