diff --git a/etemplate/inc/class.etemplate_widget_vfs.inc.php b/etemplate/inc/class.etemplate_widget_vfs.inc.php index 6780f88e72..a8c5fba560 100644 --- a/etemplate/inc/class.etemplate_widget_vfs.inc.php +++ b/etemplate/inc/class.etemplate_widget_vfs.inc.php @@ -55,7 +55,11 @@ class etemplate_widget_vfs extends etemplate_widget_file // Single file, already existing 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)) { @@ -63,6 +67,9 @@ class etemplate_widget_vfs extends etemplate_widget_file foreach($value as &$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(); 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. */ public static function store_file($path, $file) { - $name = $path; + $name = $_REQUEST['widget_id']; // Find real path if($path[0] != '/') diff --git a/etemplate/js/et2_widget_vfs.js b/etemplate/js/et2_widget_vfs.js index 1316ce389a..7d595afa49 100644 --- a/etemplate/js/et2_widget_vfs.js +++ b/etemplate/js/et2_widget_vfs.js @@ -642,10 +642,15 @@ et2_register_widget(et2_vfsUid, ["vfs-uid","vfs-gid"]); */ var et2_vfsUpload = et2_file.extend( { + attributes: { + "value": { + "type": "any", // Either nothing, or an object with file info + } + }, legacyOptions: ["mime"], 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) { 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(this.options.id.substr(-1) == '/') { 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) { + 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"]); diff --git a/etemplate/js/etemplate2.js b/etemplate/js/etemplate2.js index 52d22e8156..09e79c4718 100644 --- a/etemplate/js/etemplate2.js +++ b/etemplate/js/etemplate2.js @@ -469,7 +469,7 @@ etemplate2.prototype.load = function(_name, _url, _data, _callback) // Insert the document fragment to the DOM Container this.DOMContainer.appendChild(frag); - if(egw.debug_level >= 3 && console.groupEnd) + if(egw.debug_level() >= 3 && console.groupEnd) { egw.window.console.groupEnd(); } diff --git a/etemplate/templates/default/etemplate2.css b/etemplate/templates/default/etemplate2.css index e5a435be72..141302c207 100644 --- a/etemplate/templates/default/etemplate2.css +++ b/etemplate/templates/default/etemplate2.css @@ -865,6 +865,14 @@ ul.et2_vfs { .et2_vfs li.vfsFilename:not(:last-child):after { padding: 0.25ex; } +.et2_vfs table { + width: 100%; + max-height: 6em; + overflow: auto; +} +.et2_vfs td.icon { + width: 16px; +} button.et2_vfs_btn { margin: 0; text-align: left;