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

Commit

Permalink
fix(Felamimail): file location can not be chosen
Browse files Browse the repository at this point in the history
NOTE: this also removes the functionality for filing
 mails into the MailFiler. MailFiler is considered
 deprecated and will be moved to the community apps
 branch: https://github.com/tine20/tine20/tree/community_apps

Change-Id: Ie99c074fd2ba9b1f4dc9709a814dc3313c03f42e
Reviewed-on: http://gerrit.tine20.com/customers/10805
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Philipp Schüle <p.schuele@metaways.de>
  • Loading branch information
corneliusweiss authored and pschuele committed Nov 6, 2018
1 parent 257ef52 commit 6ec044e
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 149 deletions.
140 changes: 10 additions & 130 deletions tine20/Felamimail/js/GridPanel.js
Expand Up @@ -725,141 +725,21 @@ Tine.Felamimail.GridPanel = Ext.extend(Tine.widgets.grid.GridPanel, {
},

/**
* file selected messages to a Filemanager
* file selected messages to Filemanager
*/
onFileRecords: function() {
// show filemanager tree to get target
// allow to decide which Filemanager to file the messages in (config or combo?)
var filePicker = new Tine.Filemanager.FilePickerDialog({
windowTitle: this.app.i18n._('Select Save Location'),
singleSelect: true,
requiredGrants: ['addGrant'],
constraint: 'folder'
});

var appStore = [],
app = null,
dlgItems = [];
Ext.each(['MailFiler', 'Filemanager'], function(appName) {
if (Tine.Tinebase.common.hasRight('run', appName)) {
// TODO remove ctx menus from tree selection panel?
switch(appName) {
case 'MailFiler':
this.folderCombo = this.mailFilerFolderCombo = new Tine.widgets.container.SelectionComboBox({
recordClass: Tine.MailFiler.Model.Node,
// TODO make this work & remove mode:local
//remoteMethod: 'MailFiler.searchNodes',
mode: 'local',
treePanelClass: Tine.MailFiler.NodeTreePanel,
allowNodeSelect: true,
allowToplevelNodeSelect: false,
label: 'save in folder',
listWidth: 230,
// TODO should be auto width
width: 242
});
break;
case 'Filemanager':
this.folderCombo = this.filemanagerFolderCombo = new Tine.widgets.container.SelectionComboBox({
recordClass: Tine.Filemanager.Model.Node,
// TODO make this work & remove mode:local
//remoteMethod: 'Filemanager.searchNodes',
mode: 'local',
treePanelClass: Tine.Filemanager.NodeTreePanel,
allowNodeSelect: true,
allowToplevelNodeSelect: false,
listWidth: 230,
width: 242
});
break;
}
app = Tine.Tinebase.appMgr.get(appName);
appStore.push([appName, app.i18n._(appName)]);
}
filePicker.on('selected', function (node) {
this.fileRecords('Filemanager', node[0].path);
}, this);

if (appStore.length > 1) {
this.fileAppCombo = new Ext.form.ComboBox({
label: 'choose app',
store: appStore,
value: appStore[0][0],
listeners: {
scope: this,
select: function (combo, value) {
// set visible state for folder combos
// TODO generalize?
if (value === 'MailFiler') {
this.mailFilerFolderCombo.show();
this.filemanagerFolderCombo.hide();
this.folderCombo = this.mailFilerFolderCombo;
} else {
this.mailFilerFolderCombo.hide();
this.filemanagerFolderCombo.show();
this.folderCombo = this.filemanagerFolderCombo;
}
}
}
});

// set visible state for folder combos
if (appStore[0][0] === 'MailFiler') {
this.mailFilerFolderCombo.hidden = false;
this.filemanagerFolderCombo.hidden = true;
this.folderCombo = this.mailFilerFolderCombo;
} else {
this.mailFilerFolderCombo.hidden = true;
this.filemanagerFolderCombo.hidden = false;
this.folderCombo = this.filemanagerFolderCombo;
}
dlgItems = [
this.fileAppCombo,
this.filemanagerFolderCombo,
this.mailFilerFolderCombo
];
} else {
dlgItems.push(this.folderCombo);
}

var fileRecordsWin = Tine.WindowFactory.getWindow({
layout: 'fit',
width: 250,
height: 100,
padding: '5px',
modal: true,
title: this.app.i18n._('File Messages To Folder'),
items: [{
xtype: 'form',
buttonAlign: 'right',
border: false,
layout: 'fit',
items: dlgItems,
buttons: [{
text: i18n._('Cancel'),
minWidth: 70,
scope: this,
handler: function () {
fileRecordsWin.close();
},
iconCls: 'action_cancel'
}, {
text: i18n._('Ok'),
minWidth: 70,
scope: this,
handler: function() {
if (this.folderCombo.getValue() == '') {
return;
}

// get path from combo
// TODO use stat path???
var folder = this.folderCombo.getStore().getById(this.folderCombo.getValue()),
path = folder ? folder.get('path') : null,
appName = this.fileAppCombo
? this.fileAppCombo.getValue()
: (Tine.Tinebase.common.hasRight('run', 'MailFiler') ? 'MailFiler' : 'Filemanager');
if (path) {
this.fileRecords(appName, path);
fileRecordsWin.close();
}
},
iconCls: 'action_saveAndClose'
}]
}]
});
filePicker.openWindow();
},

/**
Expand Down
50 changes: 35 additions & 15 deletions tine20/Filemanager/js/FilePicker.js
Expand Up @@ -71,6 +71,12 @@ Tine.Filemanager.FilePicker = Ext.extend(Ext.Container, {
*/
constraint: null,

/**
* @cfg {Array} requiredGrants
* grants which are required to select nodes
*/
requiredGrants: ['readGrant'],

/**
* Constructor.
*/
Expand Down Expand Up @@ -223,7 +229,8 @@ Tine.Filemanager.FilePicker = Ext.extend(Ext.Container, {
var valid = true;

Ext.each(nodes, function (node) {
if (!me.checkNodeConstraint(node.data || node)) {
node = node.data ? node : new Tine.Filemanager.Model.Node(node);
if (!me.checkNodeConstraint(node)) {
valid = false;
return false;
}
Expand All @@ -240,7 +247,11 @@ Tine.Filemanager.FilePicker = Ext.extend(Ext.Container, {
*/
checkNodeConstraint: function (node) {
// Minimum information to proceed here
if (!node.path || !node.id) {
if (!node.get('path') || !node.id) {
return false;
}

if (! this.hasGrant(node, this.requiredGrants)) {
return false;
}

Expand All @@ -249,22 +260,31 @@ Tine.Filemanager.FilePicker = Ext.extend(Ext.Container, {
return true;
}

switch (this.constraint) {
case 'file':
if (node.type !== 'file') {
return false;
}
break;
case 'folder':
if (node.type !== 'folder') {
return false;
}
break;
}
return node.get('type') == this.constraint;
},

/**
* checkes if user has requested grant for given node
*
* @param {Tine.Filemanager.Model.Node} node
* @param {Array} grant
* @return bool
*/
hasGrant: function(node, grants) {
var _ = window.lodash,
condition = true;

_.each(grants, function(grant) {
condition = condition && _.get(node, 'data.account_grants.' + grant, false);
if (grant == 'addGrant' && node.isVirtual()) {
condition = false;
}
});

return true;
return condition;
},


/**
* Customized column model for the grid
* @returns {*}
Expand Down
11 changes: 11 additions & 0 deletions tine20/Filemanager/js/FilePickerDialog.js
Expand Up @@ -46,6 +46,12 @@ Tine.Filemanager.FilePickerDialog = Ext.extend(Tine.Tinebase.dialog.Dialog, {
*/
constraint: null,

/**
* @cfg {Array} requiredGrants
* grants which are required to select nodes
*/
requiredGrants: ['readGrant'],

windowNamePrefix: 'FilePickerDialog_',

/**
Expand All @@ -67,6 +73,10 @@ Tine.Filemanager.FilePickerDialog = Ext.extend(Tine.Tinebase.dialog.Dialog, {
]
}];

this.on('apply', function() {
this.fireEvent('selected', this.nodes);
}, this);

Tine.Filemanager.FilePickerDialog.superclass.initComponent.call(this);
},

Expand All @@ -80,6 +90,7 @@ Tine.Filemanager.FilePickerDialog = Ext.extend(Tine.Tinebase.dialog.Dialog, {
*/
getFilePicker: function () {
var picker = new Tine.Filemanager.FilePicker({
requiredGrants: this.requiredGrants,
constraint: this.constraint,
singleSelect: this.singleSelect
});
Expand Down
30 changes: 27 additions & 3 deletions tine20/Filemanager/js/SearchCombo.js
Expand Up @@ -31,6 +31,9 @@ Ext.ns('Tine.Filemanager');
Tine.Filemanager.SearchCombo = Ext.extend(Ext.form.TriggerField, {

allowBlank: false,
singleSelect: true,
constraint: 'file',

itemSelector: 'div.search-item',
minListWidth: 200,

Expand All @@ -47,6 +50,27 @@ Tine.Filemanager.SearchCombo = Ext.extend(Ext.form.TriggerField, {
this.app = Tine.Tinebase.appMgr.get('Filemanager');
}

if (! this.title) {
if (this.constraint == 'file') {
if (this.singleSelect) {
this.title = this.app.i18n._('Select a file');
} else {
this.title = this.app.i18n._('Select files');
}
} else if (this.constraint == 'folder') {
if (this.singleSelect) {
this.title = this.app.i18n._('Select a folder');
} else {
this.title = this.app.i18n._('Select folders');
}
} else {
if (this.singleSelect) {
this.title = this.app.i18n._('Select an item');
} else {
this.title = this.app.i18n._('Select items');
}
}
}
this.supr().initComponent.call(this);

this.addEvents(
Expand All @@ -59,9 +83,9 @@ Tine.Filemanager.SearchCombo = Ext.extend(Ext.form.TriggerField, {

onTriggerClick: function () {
var filepicker = new Tine.Filemanager.FilePickerDialog({
title: this.app.i18n._('Select a file'),
singleSelect: true,
constraint: 'file'
title: this.title,
singleSelect: this.singleSelect,
constraint: this.constraint
});

filepicker.on('selected', function (node) {
Expand Down
2 changes: 1 addition & 1 deletion tine20/Tinebase/js/widgets/container/TreePanel.js
Expand Up @@ -378,7 +378,7 @@ Ext.extend(Tine.widgets.container.TreePanel, Ext.tree.TreePanel, {
var result = null;

Ext.each(selection, function(node) {
if (node && node.attributes.leaf) {
if (node && this.nodeAcceptsContents(node.attributes)) {
if (! requiredGrants || this.hasGrant(node, requiredGrants)) {
result = node.attributes.container;
// take the first one
Expand Down

0 comments on commit 6ec044e

Please sign in to comment.