encoding and decoding of vfs special characters

This commit is contained in:
Ralf Becker 2012-03-28 13:58:18 +00:00
parent 2f62d7e3b5
commit b55250b81a
2 changed files with 71 additions and 26 deletions

View File

@ -77,7 +77,7 @@ var et2_vfs = et2_valueWidget.extend([et2_IDetachedDOM], {
var text; var text;
for(var i = 0; i < path_parts.length; i++) for(var i = 0; i < path_parts.length; i++)
{ {
text = path_parts[i]; text = decodeURIComponent(path_parts[i]);
// Nice human-readable stuff for apps // Nice human-readable stuff for apps
if(path_parts[1] == 'apps') if(path_parts[1] == 'apps')
@ -121,26 +121,26 @@ var et2_vfs = et2_valueWidget.extend([et2_IDetachedDOM], {
}, },
/** /**
* Code for implementing et2_IDetachedDOM (data grid) * Code for implementing et2_IDetachedDOM (data grid)
*/ */
getDetachedAttributes: function(_attrs) getDetachedAttributes: function(_attrs)
{ {
_attrs.push("value"); _attrs.push("value");
}, },
getDetachedNodes: function() getDetachedNodes: function()
{ {
return [this.span[0]]; return [this.span[0]];
}, },
setDetachedAttributes: function(_nodes, _values) setDetachedAttributes: function(_nodes, _values)
{ {
this.span = jQuery(_nodes[0]); this.span = jQuery(_nodes[0]);
if(typeof _values["value"] != 'undefined') if(typeof _values["value"] != 'undefined')
{ {
this.set_value(_values["value"]); this.set_value(_values["value"]);
} }
} }
}); });
@ -152,15 +152,19 @@ et2_register_widget(et2_vfs, ["vfs"]);
*/ */
var et2_vfsName = et2_textbox.extend({ var et2_vfsName = et2_textbox.extend({
init: function() { init: function() {
this._super.apply(this, arguments); this._super.apply(this, arguments);
this.input.addClass("et2_vfs"); this.input.addClass("et2_vfs");
}, },
set_value: function(_value) { set_value: function(_value) {
if(_value.path) if(_value.path)
{ {
_value = _value.path _value = _value.path;
} }
_value = egw.decodePath(_value);
this._super.apply(this,[_value]); this._super.apply(this,[_value]);
},
getValue: function() {
return egw.encodePath(this._super.apply(this));
} }
}); });
et2_register_widget(et2_vfsName, ["vfs-name"]); et2_register_widget(et2_vfsName, ["vfs-name"]);
@ -183,7 +187,7 @@ var et2_vfsMime = et2_valueWidget.extend([et2_IDetachedDOM], {
}, },
init: function() { init: function() {
this._super.apply(this, arguments); this._super.apply(this, arguments);
this.image = jQuery(document.createElement("img")); this.image = jQuery(document.createElement("img"));
this.image.addClass("et2_vfs vfsMimeIcon"); this.image.addClass("et2_vfs vfsMimeIcon");
this.setDOMNode(this.image[0]); this.setDOMNode(this.image[0]);
@ -262,7 +266,7 @@ var et2_vfsSize = et2_description.extend({
jQuery(this.node).text(this.human_size(_value)); jQuery(this.node).text(this.human_size(_value));
}, },
setDetachedAttributes: function(_nodes, _values) setDetachedAttributes: function(_nodes, _values)
{ {
if(typeof _values["value"] !== "undefined") { if(typeof _values["value"] !== "undefined") {
this.node = _nodes[0]; this.node = _nodes[0];
this.set_value(_values["value"]); this.set_value(_values["value"]);
@ -301,7 +305,7 @@ var et2_vfsMode = et2_description.extend({
'r': 0x4 // Read 'r': 0x4 // Read
}, },
init: function() { init: function() {
this._super.apply(this, arguments); this._super.apply(this, arguments);
this.span.addClass("et2_vfs"); this.span.addClass("et2_vfs");
}, },
@ -367,7 +371,7 @@ var et2_vfsMode = et2_description.extend({
}, },
setDetachedAttributes: function(_nodes, _values) setDetachedAttributes: function(_nodes, _values)
{ {
if(typeof _values["value"] !== "undefined") { if(typeof _values["value"] !== "undefined") {
this.node = _nodes[0]; this.node = _nodes[0];
this.set_value(_values["value"]); this.set_value(_values["value"]);

View File

@ -162,8 +162,49 @@ egw.extend('utils', egw.MODULE_GLOBAL, function() {
uid: function() { uid: function() {
return (uid_counter++).toString(16); return (uid_counter++).toString(16);
} },
/**
* Decode encoded vfs special chars
*
* @param string _path path to decode
* @return string
*/
decodePath: function(_path) {
return decodeURIComponent(_path);
},
/**
* Encode vfs special chars excluding /
*
* @param string _path path to decode
* @return string
*/
encodePath: function(_path) {
var components = _path.split('/');
for(var n=0; n < components.length; n++)
{
components[n] = this.encodePathComponent(components[n]);
}
return components.join('/');
},
/**
* Encode vfs special chars removing /
*
* //'%' => '%25', // % should be encoded, but easily leads to double encoding, therefore better NOT encodig it
* '#' => '%23',
* '?' => '%3F',
* '/' => '', // better remove it completly
*
* @param string _path path to decode
* @return string
*/
/*
*/
encodePathComponent: function(_comp) {
return _comp.replace(/#/g,'%23').replace(/\?/g,'%3F').replace(/\//g,'');
}
}; };
// Check whether the browser already supports encoding JSON -- if yes, use // Check whether the browser already supports encoding JSON -- if yes, use