Model.js (tine20-2020.08.3) | : | Model.js (tine20-2020.08.4) | ||
---|---|---|---|---|
skipping to change at line 20 | skipping to change at line 20 | |||
require('Tinebase/js/widgets/container/GrantsGrid'); | require('Tinebase/js/widgets/container/GrantsGrid'); | |||
/** | /** | |||
* @namespace Tine.Filemanager.Model | * @namespace Tine.Filemanager.Model | |||
* @class Tine.Filemanager.Model.Node | * @class Tine.Filemanager.Model.Node | |||
* @extends Tine.Tinebase.data.Record | * @extends Tine.Tinebase.data.Record | |||
* Example record definition | * Example record definition | |||
* | * | |||
* @author Cornelius Weiss <c.weiss@metaways.de> | * @author Cornelius Weiss <c.weiss@metaways.de> | |||
*/ | */ | |||
Tine.Filemanager.Model.Node = Tine.Tinebase.data.Record.create(Tine.Tinebase.Mod | Tine.Filemanager.Model.NodeMixin = { | |||
el.Tree_NodeArray, { | ||||
appName: 'Filemanager', | ||||
modelName: 'Node', | ||||
idProperty: 'id', | ||||
titleProperty: 'name', | ||||
// ngettext('File', 'Files', n); gettext('File'); | ||||
recordName: 'File', | ||||
recordsName: 'Files', | ||||
// ngettext('Folder', 'Folders', n); gettext('Folder'); | ||||
containerName: 'Folder', | ||||
containersName: 'Folders', | ||||
/** | /** | |||
* virtual nodes are part of the tree but don't exists / are editable | * virtual nodes are part of the tree but don't exists / are editable | |||
* | * | |||
* NOTE: only "real" virtual node is node with path "otherUsers". all other nodes exist | * NOTE: only "real" virtual node is node with path "otherUsers". all other nodes exist | |||
* | * | |||
* @returns {boolean} | * @returns {boolean} | |||
*/ | */ | |||
isVirtual: function() { | isVirtual: function() { | |||
var _ = window.lodash, | var _ = window.lodash, | |||
path = this.get('path'), | path = this.get('path'), | |||
skipping to change at line 53 | skipping to change at line 42 | |||
return _.indexOf(['/', '/personal', '/shared'], path) >= 0 || (parts.len gth == 2 && parts[0] == 'personal'); | return _.indexOf(['/', '/personal', '/shared'], path) >= 0 || (parts.len gth == 2 && parts[0] == 'personal'); | |||
}, | }, | |||
getSystemLink: function() { | getSystemLink: function() { | |||
var _ = window.lodash, | var _ = window.lodash, | |||
encodedPath = _.map(String(this.get('path')).replace(/(^\/|\/$)/, '' ).split('/'), Ext.ux.util.urlCoder.encodeURIComponent).join('/') + | encodedPath = _.map(String(this.get('path')).replace(/(^\/|\/$)/, '' ).split('/'), Ext.ux.util.urlCoder.encodeURIComponent).join('/') + | |||
(this.get('type') === 'folder' ? '/' : ''); | (this.get('type') === 'folder' ? '/' : ''); | |||
return [Tine.Tinebase.common.getUrl().replace(/\/$/, ''), '#/Filemanager /showNode', encodedPath].join('/'); | return [Tine.Tinebase.common.getUrl().replace(/\/$/, ''), '#/Filemanager /showNode', encodedPath].join('/'); | |||
} | }, | |||
}); | ||||
Tine.Filemanager.Model.Node.getExtension = function(filename) { | statics: { | |||
return filename.split('.').pop(); | getExtension: function(filename) { | |||
}; | return filename.split('.').pop(); | |||
}, | ||||
registerStyleProvider: function(provider) { | ||||
const ns = Tine.Filemanager.Model.Node; | ||||
ns._styleProviders = ns._styleProviders || []; | ||||
ns._styleProviders.push(provider); | ||||
}, | ||||
getStyles: function(node) { | ||||
const ns = Tine.Filemanager.Model.Node; | ||||
return _.uniq(_.compact(_.map(ns._styleProviders || [], (styleProvid | ||||
er) => { | ||||
return styleProvider(node); | ||||
}))); | ||||
}, | ||||
createFromFile: function(file) { | ||||
return new Tine.Filemanager.Model.Node(Tine.Filemanager.Model.Node.g | ||||
etDefaultData({ | ||||
name: file.name ? file.name : file.fileName, // safari and chro | ||||
me use the non std. fileX props | ||||
size: file.size || 0, | ||||
contenttype: file.type ? file.type : file.fileType, // missing i | ||||
f safari and chrome | ||||
})); | ||||
}, | ||||
Tine.Filemanager.Model.Node.registerStyleProvider = function(provider) { | getDefaultData: function (defaults) { | |||
const ns = Tine.Filemanager.Model.Node; | return _.assign({ | |||
ns._styleProviders = ns._styleProviders || []; | type: 'file', | |||
ns._styleProviders.push(provider); | size: 0, | |||
}; | creation_time: new Date(), | |||
created_by: Tine.Tinebase.registry.get('currentAccount'), | ||||
revision: 0, | ||||
revision_size: 0, | ||||
isIndexed: false | ||||
}, defaults); | ||||
}, | ||||
/** | ||||
* get filtermodel of Node records | ||||
* | ||||
* @namespace Tine.Filemanager.Model | ||||
* @static | ||||
* @return {Object} filterModel definition | ||||
*/ | ||||
getFilterModel: function() { | ||||
var app = Tine.Tinebase.appMgr.get('Filemanager'); | ||||
Tine.Filemanager.Model.Node.getStyles = function(node) { | return [ | |||
const ns = Tine.Filemanager.Model.Node; | {label : i18n._('Quick Search'), field : 'query', operators : [ | |||
return _.uniq(_.compact(_.map(ns._styleProviders || [], (styleProvider) => { | 'contains' ]}, | |||
return styleProvider(node); | // {label: app.i18n._('Type'), field: 'type'}, // -> should be a combo | |||
}))); | {label: app.i18n._('Content Type'), field: 'contenttype'}, | |||
{label: app.i18n._('Creation Time'), field: 'creation_time', val | ||||
ueType: 'date'}, | ||||
{label: app.i18n._('Description'), field: 'description', valueTy | ||||
pe: 'fulltext'}, | ||||
{filtertype : 'tine.filemanager.pathfiltermodel', app : app}, | ||||
{filtertype : 'tinebase.tag', app : app}, | ||||
{label : app.i18n._('Name'), field : 'name', operators : [ 'cont | ||||
ains' ]} | ||||
].concat(Tine.Tinebase.configManager.get('filesystem.index_content', | ||||
'Tinebase') ? [ | ||||
{label : app.i18n._('File Contents'), field : 'content', operato | ||||
rs : [ 'wordstartswith' ]}, | ||||
{label : i18n._('Indexed'), field : 'isIndexed', valueType: 'boo | ||||
l'} | ||||
] : []); | ||||
} | ||||
} | ||||
}; | }; | |||
// register grants for nodes | // register grants for nodes | |||
Tine.widgets.container.GrantsManager.register('Filemanager_Model_Node', function (container) { | Tine.widgets.container.GrantsManager.register('Filemanager_Model_Node', function (container) { | |||
// TODO get default grants and remove export | // TODO get default grants and remove export | |||
// var grants = Tine.widgets.container.GrantsManager.defaultGrants(); | // var grants = Tine.widgets.container.GrantsManager.defaultGrants(); | |||
//grants.push('download', 'publish'); | //grants.push('download', 'publish'); | |||
var grants = ['read', 'add', 'edit', 'delete', 'sync', 'download', 'publish' ]; | var grants = ['read', 'add', 'edit', 'delete', 'sync', 'download', 'publish' ]; | |||
return grants; | return grants; | |||
}); | }); | |||
Ext.override(Tine.widgets.container.GrantsGrid, { | Ext.override(Tine.widgets.container.GrantsGrid, { | |||
downloadGrantTitle: 'Download', // i18n._('Download') | downloadGrantTitle: 'Download', // i18n._('Download') | |||
downloadGrantDescription: 'The grant to download files', // i18n._('The gran t to download files') | downloadGrantDescription: 'The grant to download files', // i18n._('The gran t to download files') | |||
publishGrantTitle: 'Publish', // i18n._('Publish') | publishGrantTitle: 'Publish', // i18n._('Publish') | |||
publishGrantDescription: 'The grant to create anonymous download links for f iles', // i18n._('The grant to create anonymous download links for files') | publishGrantDescription: 'The grant to create anonymous download links for f iles', // i18n._('The grant to create anonymous download links for files') | |||
}); | }); | |||
/** | ||||
* create Node from File | ||||
* | ||||
* @param {File} file | ||||
*/ | ||||
Tine.Filemanager.Model.Node.createFromFile = function(file) { | ||||
return new Tine.Filemanager.Model.Node(Tine.Filemanager.Model.Node.getDefaul | ||||
tData({ | ||||
name: file.name ? file.name : file.fileName, // safari and chrome use t | ||||
he non std. fileX props | ||||
size: file.size || 0, | ||||
contenttype: file.type ? file.type : file.fileType, // missing if safari | ||||
and chrome | ||||
})); | ||||
}; | ||||
Tine.Filemanager.Model.Node.getDefaultData = function (defaults) { | ||||
return _.assign({ | ||||
type: 'file', | ||||
size: 0, | ||||
creation_time: new Date(), | ||||
created_by: Tine.Tinebase.registry.get('currentAccount'), | ||||
revision: 0, | ||||
revision_size: 0, | ||||
isIndexed: false | ||||
}, defaults); | ||||
}; | ||||
// NOTE: atm the activity records are stored as Tinebase_Model_Tree_Node records | // NOTE: atm the activity records are stored as Tinebase_Model_Tree_Node records | |||
Tine.widgets.grid.RendererManager.register('Tinebase', 'Tree_Node', 'revision', function(revision, metadata, record) { | Tine.widgets.grid.RendererManager.register('Tinebase', 'Tree_Node', 'revision', function(revision, metadata, record) { | |||
revision = parseInt(revision, 10); | revision = parseInt(revision, 10); | |||
var revisionString = Tine.Tinebase.appMgr.get('Filemanager').i18n._('Revisio n') + " " + revision, | var revisionString = Tine.Tinebase.appMgr.get('Filemanager').i18n._('Revisio n') + " " + revision, | |||
availableRevisions = record.get('available_revisions'); | availableRevisions = record.get('available_revisions'); | |||
// NOTE we have to encode the path here because it might contain quotes or o ther bad chars | // NOTE we have to encode the path here because it might contain quotes or o ther bad chars | |||
if (Ext.isArray(availableRevisions) && availableRevisions.indexOf(String(rev ision)) >= 0) { | if (Ext.isArray(availableRevisions) && availableRevisions.indexOf(String(rev ision)) >= 0) { | |||
/* if (revision.is_quarantined == '1') { | /* if (revision.is_quarantined == '1') { | |||
return '<img src="images/icon-set/icon_virus.svg" >' + revisionStrin g; @ToDo needs field revision_quarantine | return '<img src="images/icon-set/icon_virus.svg" >' + revisionStrin g; @ToDo needs field revision_quarantine | |||
}*/ | }*/ | |||
return '<a href="#"; onclick="Tine.Filemanager.downloadFileByEncodedPath (\'' + btoa(record.get('path')) + '\',' + revision | return '<a href="#"; onclick="Tine.Filemanager.downloadFileByEncodedPath (\'' + btoa(record.get('path')) + '\',' + revision | |||
+ '); return false;">' + revisionString + '</a>'; | + '); return false;">' + revisionString + '</a>'; | |||
}else { | }else { | |||
return revisionString; | return revisionString; | |||
} | } | |||
}); | }); | |||
/** | Tine.Filemanager.nodeBackendMixin = { | |||
* default ExampleRecord backend | ||||
*/ | ||||
Tine.Filemanager.FileRecordBackend = Ext.extend(Tine.Tinebase.data.RecordProxy, | ||||
{ | ||||
appName: 'Filemanager', | ||||
modelName: 'Node', | ||||
recordClass: Tine.Filemanager.Model.Node, | ||||
/** | /** | |||
* creating folder | * creating folder | |||
* | * | |||
* @param name folder name | * @param name folder name | |||
* @param options additional options | * @param options additional options | |||
* @returns | * @returns | |||
*/ | */ | |||
createFolder: function(name, options) { | createFolder: function(name, options) { | |||
options = options || {}; | options = options || {}; | |||
skipping to change at line 371 | skipping to change at line 375 | |||
// grid.getStore().reload(); | // grid.getStore().reload(); | |||
}, | }, | |||
failure: function(response, request) { | failure: function(response, request) { | |||
var nodeData = Ext.util.JSON.decode(response.responseText), | var nodeData = Ext.util.JSON.decode(response.responseText), | |||
request = Ext.util.JSON.decode(request.jsonData); | request = Ext.util.JSON.decode(request.jsonData); | |||
this.loadMask.hide(); | this.loadMask.hide(); | |||
app.getMainScreen().getWestPanel().setDisabled(false); | app.getMainScreen().getWestPanel().setDisabled(false); | |||
app.getMainScreen().getNorthPanel().setDisabled(false); | app.getMainScreen().getNorthPanel().setDisabled(false); | |||
Tine.Filemanager.fileRecordBackend.handleRequestException(nodeDa ta.data, request); | Tine.Filemanager.nodeBackend.handleRequestException(nodeData.dat a, request); | |||
} | } | |||
}); | }); | |||
}, | }, | |||
/** | /** | |||
* upload files | * upload files | |||
* | * | |||
* @param {} params Request parameters | * @param {} params Request parameters | |||
* @param [] uploadKeyArray | * @param [] uploadKeyArray | |||
* @param Boolean addToGridStore | * @param Boolean addToGridStore | |||
skipping to change at line 414 | skipping to change at line 418 | |||
var nodeRecord = Tine.Tinebase.data.Record.setFromJson(nodeD ata[i], Tine.Filemanager.Model.Node); | var nodeRecord = Tine.Tinebase.data.Record.setFromJson(nodeD ata[i], Tine.Filemanager.Model.Node); | |||
var existingRecordIdx = gridStore.find('name', fileRecord.ge t('name')); | var existingRecordIdx = gridStore.find('name', fileRecord.ge t('name')); | |||
if (existingRecordIdx > -1) { | if (existingRecordIdx > -1) { | |||
gridStore.removeAt(existingRecordIdx); | gridStore.removeAt(existingRecordIdx); | |||
gridStore.insert(existingRecordIdx, nodeRecord); | gridStore.insert(existingRecordIdx, nodeRecord); | |||
} else { | } else { | |||
gridStore.add(nodeRecord); | gridStore.add(nodeRecord); | |||
} | } | |||
fileRecord = Tine.Filemanager.fileRecordBackend.updateNodeRe cord(nodeData[i], fileRecord); | fileRecord = Tine.Filemanager.nodeBackend.updateNodeRecord(n odeData[i], fileRecord); | |||
nodeRecord.fileRecord = fileRecord; | nodeRecord.fileRecord = fileRecord; | |||
} | } | |||
} | } | |||
}).createDelegate({uploadKeyArray: uploadKeyArray, addToGridStore: addTo GridStore}); | }).createDelegate({uploadKeyArray: uploadKeyArray, addToGridStore: addTo GridStore}); | |||
var onFailure = (function (response, request) { | var onFailure = (function (response, request) { | |||
var nodeData = Ext.util.JSON.decode(response.responseText), | var nodeData = Ext.util.JSON.decode(response.responseText), | |||
request = Ext.util.JSON.decode(request.jsonData); | request = Ext.util.JSON.decode(request.jsonData); | |||
nodeData.data.uploadKeyArray = this.uploadKeyArray; | nodeData.data.uploadKeyArray = this.uploadKeyArray; | |||
nodeData.data.addToGridStore = this.addToGridStore; | nodeData.data.addToGridStore = this.addToGridStore; | |||
Tine.Filemanager.fileRecordBackend.handleRequestException(nodeData.d ata, request); | Tine.Filemanager.nodeBackend.handleRequestException(nodeData.data, r equest); | |||
}).createDelegate({uploadKeyArray: uploadKeyArray, addToGridStore: addTo GridStore}); | }).createDelegate({uploadKeyArray: uploadKeyArray, addToGridStore: addTo GridStore}); | |||
Ext.Ajax.request({ | Ext.Ajax.request({ | |||
params: params, | params: params, | |||
timeout: 300000, // 5 minutes | timeout: 300000, // 5 minutes | |||
scope: this, | scope: this, | |||
success: onSuccess || Ext.emptyFn, | success: onSuccess || Ext.emptyFn, | |||
failure: onFailure || Ext.emptyFn | failure: onFailure || Ext.emptyFn | |||
}); | }); | |||
skipping to change at line 517 | skipping to change at line 521 | |||
} | } | |||
if (allRecordsComplete) { | if (allRecordsComplete) { | |||
this.pagingToolbar.refresh.enable(); | this.pagingToolbar.refresh.enable(); | |||
} | } | |||
}, | }, | |||
/** | /** | |||
* copies uploaded temporary file to target location | * copies uploaded temporary file to target location | |||
* | * | |||
* @param proxy {Tine.Filemanager.fileRecordBackend} | * @param proxy {Tine.Filemanager.nodeBackend} | |||
* @param upload {Ext.ux.file.Upload} | * @param upload {Ext.ux.file.Upload} | |||
* @param file {Ext.ux.file.Upload.file} | * @param file {Ext.ux.file.Upload.file} | |||
*/ | */ | |||
onUploadComplete: function(proxy, upload, file) { | onUploadComplete: function(proxy, upload, file) { | |||
Ext.Ajax.request({ | Ext.Ajax.request({ | |||
timeout: 10*60*1000, // Overriding Ajax timeout - important! | timeout: 10*60*1000, // Overriding Ajax timeout - important! | |||
params: { | params: { | |||
method: proxy.appName + '.createNode', | method: proxy.appName + '.createNode', | |||
filename: upload.fileRecord.get('path'), | filename: upload.fileRecord.get('path'), | |||
type: 'file', | type: 'file', | |||
skipping to change at line 566 | skipping to change at line 570 | |||
/** | /** | |||
* updates given record with nodeData from from response | * updates given record with nodeData from from response | |||
*/ | */ | |||
updateNodeRecord : function(nodeData, nodeRecord) { | updateNodeRecord : function(nodeData, nodeRecord) { | |||
for(var field in nodeData) { | for(var field in nodeData) { | |||
nodeRecord.set(field, nodeData[field]); | nodeRecord.set(field, nodeData[field]); | |||
} | } | |||
return nodeRecord; | return nodeRecord; | |||
} | }, | |||
}); | ||||
Tine.Filemanager.fileRecordBackend = new Tine.Filemanager.FileRecordBackend({}); | ||||
/** | statics: { | |||
* get filtermodel of Node records | ||||
* | ||||
* @namespace Tine.Filemanager.Model | ||||
* @static | ||||
* @return {Object} filterModel definition | ||||
*/ | ||||
Tine.Filemanager.Model.Node.getFilterModel = function() { | ||||
var app = Tine.Tinebase.appMgr.get('Filemanager'); | ||||
return [ | } | |||
{label : i18n._('Quick Search'), field : 'query', operators : [ 'contain | ||||
s' ]}, | ||||
// {label: app.i18n._('Type'), field: 'type'}, // -> should be a combo | ||||
{label: app.i18n._('Content Type'), field: 'contenttype'}, | ||||
{label: app.i18n._('Creation Time'), field: 'creation_time', valueType: | ||||
'date'}, | ||||
{label: app.i18n._('Description'), field: 'description', valueType: 'ful | ||||
ltext'}, | ||||
{filtertype : 'tine.filemanager.pathfiltermodel', app : app}, | ||||
{filtertype : 'tinebase.tag', app : app}, | ||||
{label : app.i18n._('Name'), field : 'name', operators : [ 'contains' ]} | ||||
].concat(Tine.Tinebase.configManager.get('filesystem.index_content', 'Tineba | ||||
se') ? [ | ||||
{label : app.i18n._('File Contents'), field : 'content', operators : [ ' | ||||
wordstartswith' ]}, | ||||
{label : i18n._('Indexed'), field : 'isIndexed', valueType: 'bool'} | ||||
] : []); | ||||
}; | }; | |||
/** | /** | |||
* @namespace Tine.Filemanager.Model | * @namespace Tine.Filemanager.Model | |||
* @class Tine.Filemanager.Model.DownloadLink | * @class Tine.Filemanager.Model.DownloadLink | |||
* @extends Tine.Tinebase.data.Record | * @extends Tine.Tinebase.data.Record | |||
* Example record definition | * Example record definition | |||
*/ | */ | |||
Tine.Filemanager.Model.DownloadLink = Tine.Tinebase.data.Record.create(Tine.Tine base.Model.modlogFields.concat([ | Tine.Filemanager.Model.DownloadLink = Tine.Tinebase.data.Record.create(Tine.Tine base.Model.modlogFields.concat([ | |||
{ name: 'id' }, | { name: 'id' }, | |||
End of changes. 14 change blocks. | ||||
99 lines changed or deleted | 82 lines changed or added |