From e330a7bfdcff275baab77701f2281f1c011eec49 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Mon, 26 Mar 2012 19:46:51 +0000 Subject: [PATCH] Start of vfs widget --- etemplate/js/et2_widget_vfs.js | 122 +++++++++++++++++++++ etemplate/js/etemplate2.js | 1 + etemplate/templates/default/etemplate2.css | 11 ++ 3 files changed, 134 insertions(+) create mode 100644 etemplate/js/et2_widget_vfs.js diff --git a/etemplate/js/et2_widget_vfs.js b/etemplate/js/et2_widget_vfs.js new file mode 100644 index 0000000000..a8bcd2dbd0 --- /dev/null +++ b/etemplate/js/et2_widget_vfs.js @@ -0,0 +1,122 @@ +/** + * eGroupWare eTemplate2 - JS VFS widgets + * + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @package etemplate + * @subpackage api + * @link http://www.egroupware.org + * @author Nathan Gray + * @copyright Nathan Gray 2012 + * @version $Id$ +*/ + +"use strict"; + +/*egw:uses + jquery.jquery; + et2_core_inputWidget; + et2_core_valueWidget; +*/ + +/** + * Class which implements the "vfs" XET-Tag + */ +var et2_vfs = et2_valueWidget.extend({ + + attributes: { + "value": { + "type": "any", // Object + "description": "Label of the button" + } + }, + + /** + * Mime type of directories + */ + DIR_MIME_TYPE: 'httpd/unix-directory', + + init: function() { + this._super.apply(this, arguments); + + this.value = ""; + this.span = $j(document.createElement("ul")) + .addClass('et2_vfs'); + + this.setDOMNode(this.span[0]); + }, + + set_value: function(_value) { + var path = ''; + if(_value.path) + { + path = _value.path + } + else if (typeof _value !== 'object') + { + this.egw().debug("warn", "%s only has path, needs full array", this.id); + this.span.empty().text(_value); + return; + } + var path_parts = path ? path.split('/') : []; + + // TODO: This is apparently not used in old etemplate + //this._make_path(path_parts); + this._make_path([path_parts[path_parts.length-1]]); + + // TODO: check perms + if(_value.mime && _value.mime == this.DIR_MIME_TYPE) + { + } + // Make it clickable + var data = {path: path, type: _value.mime} + jQuery("li",this.span).addClass("et2_clickable et2_link") + .click({data:data, egw: this.egw()}, function(e) { + e.data.egw.open(e.data.data, "file"); + }); + }, + + /** + * Create a list of clickable path components + */ + _make_path: function(path_parts) { + for(var i = 0; i < path_parts.length; i++) + { + var text = path_parts[i]; + + // Nice human-readable stuff for apps + if(path_parts[1] == 'apps') + { + switch(path_parts.length) + { + case 2: + if(i == 1) + { + text = this.egw().lang('applications'); + } + break; + case 3: + if( i == 2) + { + text = this.egw().lang(path_parts[2]); + } + break; + case 4: + if(!isNaN(text)) + { + text = this.egw().link_title(path_parts[2],path_parts[3]); + } + break; + } + } + path_parts[i] = text; + + var part = $j(document.createElement("li")) + .addClass("vfsFilename") + .text(text) + .appendTo(this.span); + } + } + +}); + +et2_register_widget(et2_vfs, ["vfs", "vfs-name", "vfs-size", "vfs-mode","vfs-mime","vfs-uid","vfs-gid"]); diff --git a/etemplate/js/etemplate2.js b/etemplate/js/etemplate2.js index 7e3ff8a4a5..f7b43fe9e0 100644 --- a/etemplate/js/etemplate2.js +++ b/etemplate/js/etemplate2.js @@ -37,6 +37,7 @@ et2_widget_progress; et2_widget_selectAccount; et2_widget_ajaxSelect; + et2_widget_vfs; et2_extension_nextmatch; et2_extension_customfields; diff --git a/etemplate/templates/default/etemplate2.css b/etemplate/templates/default/etemplate2.css index dd939259e0..26043f0da3 100644 --- a/etemplate/templates/default/etemplate2.css +++ b/etemplate/templates/default/etemplate2.css @@ -448,6 +448,17 @@ ul.et2_link_string { background-repeat: repeat-x; } +/** + * VFS widget(s) + */ +.et2_vfs li.vfsFilename { + display: inline; + margin-left: -30px; +} +.et2_vfs li.vfsFilename:not(:last-child):after { + content: '/'; + padding: 0.25ex; +} /** * Validation