Add new preference to control default action of editing a document (open with:Collabora|CollabEditor|Download)

This commit is contained in:
Hadi Nategh 2018-08-03 11:08:00 +02:00
parent 8d94fc699d
commit a9a303a6ff
4 changed files with 38 additions and 7 deletions

View File

@ -1525,7 +1525,7 @@ var et2_link_string = (function(){ "use strict"; return expose(et2_valueWidget.e
.appendTo(this.list)
.addClass("et2_link loading")
.click( function(e){
var fe = egw_get_file_editor_prefered_mimes();
var fe = egw_get_file_editor_prefered_mimes(_link_data.type);
if (self.options.expose_view && typeof _link_data.type !='undefined'
&& _link_data.type.match(self.mime_regexp,'ig'))
{
@ -1916,7 +1916,7 @@ var et2_link_list = (function(){ "use strict"; return et2_link_string.extend(
if (_link_data && (typeof _link_data.download_url != 'undefined' || _link_data.app !='egw-data'))
{
$td.click( function(){
var fe_mime = egw_get_file_editor_prefered_mimes();
var fe_mime = egw_get_file_editor_prefered_mimes(_link_data.type);
// Check if the link entry is mime with media type, in order to open it in expose view
if (typeof _link_data.type != 'undefined' &&
(_link_data.type.match(self.mime_regexp,'ig') || (fe_mime && fe_mime.mime[_link_data.type])))

View File

@ -758,10 +758,20 @@ function addOption(id,label,value,do_onchange)
if (selectBox.onchange && do_onchange) selectBox.onchange();
}
function egw_get_file_editor_prefered_mimes(_data, _params)
/**
*
* @param {string} _mime current mime type
* @returns {object|null} returns object of filemanager editor hook
*/
function egw_get_file_editor_prefered_mimes(_mime)
{
var fe = jQuery.extend(true, {},egw.link_get_registry('filemanager-editor'));
var ex_mimes = egw.preference('collab_excluded_mimes', 'filemanager');
var dblclick_action = egw.preference('document_doubleclick_action', 'filemanager');
if (dblclick_action == 'download' && typeof _mime === 'string')
{
ex_mimes = !ex_mimes ? _mime : ex_mimes+','+_mime;
}
if (fe && fe.mime && ex_mimes)
{
ex_mimes = ex_mimes.split(',');
@ -818,3 +828,6 @@ jQuery(function(){
});
});
jQuery(document).ready(function() {
jQuery('head').append('<link rel="manifest" href="/egroupware/pixelegg/manifest.json">');
})

View File

@ -283,6 +283,18 @@ class filemanager_hooks
'name' => 'merge_open_handler',
'values' => array ('download' => lang('download'), 'collabora' => 'Collabora'),
'default' => 'collabora',
),
'document_doubleclick_action' => array (
'type' => 'select',
'label' => lang('Default action on double-click'),
'help' => lang('Defines how to handle double click action on a document file.'),
'name' => 'document_doubleclick_action',
'values' => array (
'collabora' => lang('open documents with Collabora, if permissions are given'),
'download' => lang('download documents'),
'collabeditor' => lang('open odt documents with CollabEditor')
),
'default' => 'collabora',
)
);
@ -333,11 +345,11 @@ class filemanager_hooks
foreach ($implemented as $app)
{
if (($access = \EGroupware\Api\Vfs\Links\StreamWrapper::check_app_rights($app)) &&
($l = Api\Hooks::process('filemanager-editor-link',$app, true)) && $l[$app])
($l = Api\Hooks::process('filemanager-editor-link',$app, true)) && $l[$app]
&& $GLOBALS['egw_info']['user']['preferences']['filemanager']['document_doubleclick_action'] == $app)
{
$link = $l[$app];
}
if ($app == 'collabora' && $access) break; // collabora is default
}
return $link;
}

View File

@ -785,6 +785,7 @@ app.classes.filemanager = AppJS.extend(
{
var data = egw.dataGetUIDdata(_senders[0].id);
var path = this.id2path(_senders[0].id);
this.et2 = this.et2 ? this.et2 : etemplate2.getById('filemanager-index').widgetContainer;
var mime = this.et2._inst.widgetContainer.getWidgetById('$row');
// try to get mime widget DOM node out of the row DOM
var mime_dom = jQuery(_senders[0].iface.getDOMNode()).find("span#filemanager-index_\\$row");
@ -809,8 +810,13 @@ app.classes.filemanager = AppJS.extend(
}
else
{
// Build ViewerJS url
if (data.data.mime.match(/application\/vnd\.oasis\.opendocument/)) var url = '/ViewerJS/#..' + data.data.download_url;
if (data.data.mime.match(/application\/vnd\.oasis\.opendocument/) &&
egw.preference('document_doubleclick_action', 'filemanager') == 'collabeditor')
{
var url = '/ViewerJS/#..' + data.data.download_url;
}
egw.open({path: path, type: data.data.mime, download_url: url}, 'file','view',null,'_browser');
}
@ -1293,7 +1299,7 @@ app.classes.filemanager = AppJS.extend(
if (_senders.length>1) return false;
var data = egw.dataGetUIDdata(_senders[0].id),
mime = this.et2._inst.widgetContainer.getWidgetById('$row');
var fe = egw_get_file_editor_prefered_mimes();
var fe = egw_get_file_editor_prefered_mimes(data.data.mime);
if (fe && fe.mime && !fe.mime[data.data.mime]) return false;
return data.data.mime.match(mime.mime_odf_regex)?true:false;
},