Fix vfsUpload widget did not display its value

This commit is contained in:
Nathan Gray 2015-08-31 22:32:50 +00:00
parent 16e4ad1078
commit ed39c529da
4 changed files with 74 additions and 6 deletions

View File

@ -55,7 +55,11 @@ class etemplate_widget_vfs extends etemplate_widget_file
// Single file, already existing // Single file, already existing
if (substr($path,-1) != '/' && egw_vfs::file_exists($path) && !egw_vfs::is_dir($path)) if (substr($path,-1) != '/' && egw_vfs::file_exists($path) && !egw_vfs::is_dir($path))
{ {
$value = $path; $file = egw_vfs::stat($path);
$file['path'] = egw_vfs::resolve_url($path);
$file['name'] = egw_vfs::basename($file['path']);
$file['mime'] = egw_vfs::mime_content_type($file['path']);
$value = array($file);
} }
else if (substr($path, -1) == '/' && egw_vfs::is_dir($path)) else if (substr($path, -1) == '/' && egw_vfs::is_dir($path))
{ {
@ -63,6 +67,9 @@ class etemplate_widget_vfs extends etemplate_widget_file
foreach($value as &$file) foreach($value as &$file)
{ {
$file = egw_vfs::stat("$path$file"); $file = egw_vfs::stat("$path$file");
$file['path'] = $file['url'];
$file['name'] = egw_vfs::basename($file['path']);
$file['mime'] = egw_vfs::mime_content_type($file['path']);
} }
} }
} }
@ -73,7 +80,7 @@ class etemplate_widget_vfs extends etemplate_widget_file
parent::ajax_upload(); parent::ajax_upload();
foreach($_FILES as $field => $file) foreach($_FILES as $field => $file)
{ {
self::store_file($field, $file); self::store_file($_REQUEST['widget_id'], $file);
} }
} }
@ -134,7 +141,7 @@ class etemplate_widget_vfs extends etemplate_widget_file
* $content array and the application should deal with the file. * $content array and the application should deal with the file.
*/ */
public static function store_file($path, $file) { public static function store_file($path, $file) {
$name = $path; $name = $_REQUEST['widget_id'];
// Find real path // Find real path
if($path[0] != '/') if($path[0] != '/')

View File

@ -642,10 +642,15 @@ et2_register_widget(et2_vfsUid, ["vfs-uid","vfs-gid"]);
*/ */
var et2_vfsUpload = et2_file.extend( var et2_vfsUpload = et2_file.extend(
{ {
attributes: {
"value": {
"type": "any", // Either nothing, or an object with file info
}
},
legacyOptions: ["mime"], legacyOptions: ["mime"],
asyncOptions: { asyncOptions: {
url: egw.ajaxUrl("etemplate_widget_vfs::ajax_upload::etemplate") target: egw.ajaxUrl(self.egw().getAppName()+".etemplate_widget_vfs.ajax_upload.etemplate")
}, },
/** /**
@ -657,16 +662,64 @@ var et2_vfsUpload = et2_file.extend(
*/ */
init: function(_parent, attrs) { init: function(_parent, attrs) {
this._super.apply(this, arguments); this._super.apply(this, arguments);
this.input.addClass("et2_vfs"); $j(this.node).addClass("et2_vfs");
// If the ID is a directory, allow multiple uploads // If the ID is a directory, allow multiple uploads
if(this.options.id.substr(-1) == '/') if(this.options.id.substr(-1) == '/')
{ {
this.set_multiple(true); this.set_multiple(true);
} }
this.list = $j(document.createElement('table')).appendTo(this.node);
}, },
/**
* If there is a file / files in the specified location, display them
*
* @param {Object[]} _value
*/
set_value: function(_value) { set_value: function(_value) {
this.progress.empty();
this.list.empty();
for(var i = 0; i < _value.length; i++)
{
this._addFile(_value[i]);
}
},
getDOMNode: function(sender) {
if(sender !== this && sender._type.indexOf('vfs') >= 0 )
{
var value = sender.getValue && sender.getValue() || sender.options.value || {};
var row = $j('[data-path="'+(value.path)+'"]',this.list);
if(sender._type === 'vfs-mime')
{
return $j('.icon',row).get(0) || null;
}
else
{
return $j('.title',row).get(0) || null;
}
}
else
{
return this._super.apply(this, arguments);
}
},
_addFile: function(file_data) {
var row = $j(document.createElement("tr"))
.attr("data-path", file_data.url)
.attr("draggable", "true")
.appendTo(this.list);
var mime = $j(document.createElement("td"))
.addClass('icon')
.appendTo(row);
var title = $j(document.createElement("td"))
.addClass('title')
.appendTo(row);
var mime = et2_createWidget('vfs-mime',{value: file_data},this);
var vfs = et2_createWidget('vfs', {value: file_data}, this);
} }
}); });
et2_register_widget(et2_vfsUpload, ["vfs-upload"]); et2_register_widget(et2_vfsUpload, ["vfs-upload"]);

View File

@ -469,7 +469,7 @@ etemplate2.prototype.load = function(_name, _url, _data, _callback)
// Insert the document fragment to the DOM Container // Insert the document fragment to the DOM Container
this.DOMContainer.appendChild(frag); this.DOMContainer.appendChild(frag);
if(egw.debug_level >= 3 && console.groupEnd) if(egw.debug_level() >= 3 && console.groupEnd)
{ {
egw.window.console.groupEnd(); egw.window.console.groupEnd();
} }

View File

@ -865,6 +865,14 @@ ul.et2_vfs {
.et2_vfs li.vfsFilename:not(:last-child):after { .et2_vfs li.vfsFilename:not(:last-child):after {
padding: 0.25ex; padding: 0.25ex;
} }
.et2_vfs table {
width: 100%;
max-height: 6em;
overflow: auto;
}
.et2_vfs td.icon {
width: 16px;
}
button.et2_vfs_btn { button.et2_vfs_btn {
margin: 0; margin: 0;
text-align: left; text-align: left;