Some more WIP of attachment mime handling

This commit is contained in:
Hadi Nategh 2015-03-24 11:40:06 +00:00
parent 14cd9dfb34
commit 89a9ea4bb1
5 changed files with 63 additions and 18 deletions

View File

@ -15,6 +15,7 @@
/*egw:uses
jquery.jquery;
et2_core_baseWidget;
/etemplate/js/expose.js;
*/
/**
@ -22,7 +23,7 @@
*
* @augments et2_baseWidget
*/
var et2_description = et2_baseWidget.extend([et2_IDetachedDOM],
var et2_description = expose(et2_baseWidget.extend([et2_IDetachedDOM],
{
attributes: {
"label": {
@ -82,6 +83,18 @@ var et2_description = et2_baseWidget.extend([et2_IDetachedDOM],
"type": "string",
"description": "Link title which is displayed on mouse over.",
"translate": true
},
"expose_view":{
name: "Expose view",
type: "boolean",
default: false,
description: "Clicking on description with href value would popup an expose view, and will show content referenced by href."
},
mime:{
name: "Mime type",
type: "string",
default: '',
description: "Mime type of the registered link"
}
},
@ -142,7 +155,7 @@ var et2_description = et2_baseWidget.extend([et2_IDetachedDOM],
.addClass("et2_label");
this.getSurroundings().insertDOMNode(this._labelContainer[0]);
}
// Clear the label container.
this._labelContainer.empty();
@ -175,14 +188,33 @@ var et2_description = et2_baseWidget.extend([et2_IDetachedDOM],
}
this._labelContainer = null;
}
// Update the surroundings in order to reflect the change in the label
this.getSurroundings().update();
// Copy the given value
this.label = _value;
},
/**
* Function to get media content to feed the expose
* @param {type} _value
* @returns {Array|Array.getMedia.mediaContent}
*/
getMedia: function (_value)
{
var base_url = egw.webserverUrl.match(/^\//,'ig')?egw(window).window.location.origin :egw.webserverUrl + '/';
var mediaContent = [];
if (_value)
{
mediaContent = [{
title: this.options.label,
href: base_url + _value,
type: this.options.type + "/*",
thumbnail: base_url + _value
}];
}
return mediaContent;
},
set_value: function(_value) {
if (!_value) _value = "";
if (!this.options.no_lang) _value = this.egw().lang(_value);
@ -194,14 +226,19 @@ var et2_description = et2_baseWidget.extend([et2_IDetachedDOM],
this.span[0],
this.options.href ? this.options.extra_link_target : '_blank'
);
if(this.options.extra_link_popup)
if(this.options.extra_link_popup || this.options.mime)
{
var href = this.options.href;
var title = this.options.extra_link_title;
var popup = this.options.extra_link_popup;
var self= this;
jQuery('a',this.span)
.click(function(e) {
egw.open_link(href, title,popup);
if (self.options.expose_view && typeof self.options.mime !='undefined' && self.options.mime.match(/video\/|image\/|audio\//,'ig'))
{
self._init_blueimp_gallery(e,self.options.href);
}
else
{
egw(window).open_link(self.options.href, self.options.extra_link_title,self.options.extra_link_popup,null,null,self.options.mime);
}
e.preventDefault();
return false;
});
@ -280,6 +317,6 @@ var et2_description = et2_baseWidget.extend([et2_IDetachedDOM],
_nodes[0].setAttribute("class", _values["class"]);
}
}
});
}));
et2_register_widget(et2_description, ["description", "label"]);

View File

@ -373,6 +373,9 @@ function expose (widget)
set_value:function (_value)
{
if (typeof this._super == 'undefined') return;
this._super.apply(this,arguments);
// Do not run set value of expose if expose_view is not set
// it causes a wired error on nested image widgets which
// seems the expose is not its child widget
@ -380,7 +383,7 @@ function expose (widget)
{
return;
}
this._super.apply(this,arguments);
var self=this;
// If the media type is not supported do not bind the click handler
@ -488,6 +491,7 @@ function expose (widget)
* @param {DOMNode} slide
*/
expose_onslide: function (gallery, index, slide){
if (typeof this._super == 'undefined') return;
// First let parent try
this._super.apply(this, arguments);
var nm = find_nextmatch(this);

View File

@ -2181,24 +2181,25 @@ class mail_ui
$attachmentHTML[$key]['filename'] = $x;
}
}
//error_log(array2string($value));
//error_log(strtoupper($value['mimeType']) .'<->'. mime_magic::filename2mime($attachmentHTML[$key]['filename']));
//error_log(array2string($value));
//error_log(strtoupper($value['mimeType']) .'<->'. mime_magic::filename2mime($attachmentHTML[$key]['filename']));
if (strtoupper($value['mimeType']=='APPLICATION/OCTET-STREAM')) $value['mimeType'] = mime_magic::filename2mime($attachmentHTML[$key]['filename']);
$attachmentHTML[$key]['type']=$value['mimeType'];
$attachmentHTML[$key]['mimetype']=mime_magic::mime2label($value['mimeType']);
$attachmentHTML[$key]['size']=egw_vfs::hsize($value['size']);
$attachmentHTML[$key]['attachment_number']=$key;
$attachmentHTML[$key]['partID']=$value['partID'];
$attachmentHTML[$key]['mail_id'] = $rowID;
$attachmentHTML[$key]['winmailFlag']=$value['is_winmail'];
$attachmentHTML[$key]['classSaveAllPossiblyDisabled'] = "mail_DisplayNone";
switch(strtoupper($value['mimeType']))
{
case 'MESSAGE/RFC822':
$linkData = array
(
'menuaction' => 'mail.mail_ui.displayMessage',
//'mode' => 'display', //message/rfc822 attachments should be opened in display mode
'mode' => 'display', //message/rfc822 attachments should be opened in display mode
'id' => $rowID,
'part' => $value['partID'],
'is_winmail' => $value['is_winmail']
@ -2265,6 +2266,9 @@ class mail_ui
$linkView = "window.location.href = '".egw::link('/index.php',$linkData)."';";
break;
}
$attachmentHTML[$key]['href_link'] = egw::link('/index.php',$linkData);
$attachmentHTML[$key]['windowName'] = $windowName;
//error_log(__METHOD__.__LINE__.$linkView);
$attachmentHTML[$key]['link_view'] = '<a href="#" ." title="'.$attachmentHTML[$key]['filename'].'" onclick="'.$linkView.' return false;"><b>'.
($value['name'] ? ( $filename ? $filename : $value['name'] ) : lang('(no subject)')).

View File

@ -72,7 +72,7 @@
<description id="${row}[partID]" />
<description id="${row}[type]" />
<description id="${row}[winmailFlag]" />
<description class="useEllipsis et2_link" id="${row}[filename]" no_lang="1" onclick="app.mail.displayAttachment"/>
<description class="useEllipsis et2_link" id="${row}[filename]" expose_view="true" mime="$row_cont[type]" no_lang="1" href="$row_cont[href_link]" extra_link_title="$row_cont[windowName]" />
<description align="right" id="${row}[size]" />
<buttononly id="${row}[save]" value="save" image="fileexport" onclick="app.mail.saveAttachment"/>
<buttononly id="${row}[saveAsVFS]" value="save" image="filemanager/navbar" onclick="app.mail.saveAttachmentToVFS"/>

View File

@ -98,8 +98,8 @@
<description id="${row}[partID]" />
<description id="${row}[type]" />
<description id="${row}[winmailFlag]" />
<description class="et2_link useEllipsis" id="${row}[filename]" no_lang="1" onclick="app.mail.displayAttachment"/>
<description align="right" id="${row}[size]" />
<description class="et2_link useEllipsis" id="${row}[filename]" no_lang="1" expose_view="true" mime="$row_cont[type]" href="$row_cont[href_link]" extra_link_title="$row_cont[windowName]"/>
<description align="right" id="${row}[size]"/>
<buttononly id="${row}[save]" image="fileexport" onclick="app.mail.saveAttachment"/>
<buttononly id="${row}[saveAsVFS]" image="filemanager/navbar" onclick="app.mail.saveAttachmentToVFS"/>
<buttononly class="$row_cont[classSaveAllPossiblyDisabled]" id="${row}[save_all]" image="mail/save_all" onclick="app.mail.saveAllAttachmentsToVFS"/>