rejetto forum
Software => HFS ~ HTTP File Server => HTML & templates => Topic started by: e4g on July 28, 2011, 09:39:39 PM
-
Hello. I searched around the forum and couldn't find the answer to this question. I apologize ahead of time if it's already been answered (or is obvious).
Is it possible to get the path of the currently selected file in HFS so that it can be used in an external script? I've created a button that will only execute an external program if a single file is selected, but I want to reference that file in the code.
Example:
<form><input type='submit' name='view' value='View' onclick='
var a = selectedItems();
if (a.size() != 1)
this.value = "Select One File";
else
this.value = "Run"'/></form>
{.if|{.?view = Run.}|{:
{.exec|python script.py -e C:\pathto\selected\file.}
:}.}
Any help would be appreciated.
-
HFS includes a function for getting file names... Try using it in your onclick. You'll find it in the standard lib.js.
function getItemName(el) {
if (typeof el == 'undefined')
return false;
// we handle elements, not jquery sets
if (el.jquery)
if (el.size())
el = el[0];
else
return false;
// take the url, and ignore any #anchor part
var s = el.getAttribute('href') || el.getAttribute('value');
s = s.split('#')[0];
// remove protocol and hostname
var i = s.indexOf('://');
if (i > 0)
s = s.slice(s.indexOf('/',i+3));
// current folder is specified. Remove it.
if (s.indexOf(HFS.folder) == 0)
s = s.slice(HFS.folder.length);
// folders have a trailing slash that's not truly part of the name
if (s.slice(-1) == '/')
s = s.slice(0,-1);
// it is encoded
s = (decodeURIComponent || unescape)(s);
return s;
} // getItemName
-
HFS includes a function for getting file names... Try using it in your onclick. You'll find it in the standard lib.js.
function getItemName(el) {
if (typeof el == 'undefined')
return false;
// we handle elements, not jquery sets
if (el.jquery)
if (el.size())
el = el[0];
else
return false;
// take the url, and ignore any #anchor part
var s = el.getAttribute('href') || el.getAttribute('value');
s = s.split('#')[0];
// remove protocol and hostname
var i = s.indexOf('://');
if (i > 0)
s = s.slice(s.indexOf('/',i+3));
// current folder is specified. Remove it.
if (s.indexOf(HFS.folder) == 0)
s = s.slice(HFS.folder.length);
// folders have a trailing slash that's not truly part of the name
if (s.slice(-1) == '/')
s = s.slice(0,-1);
// it is encoded
s = (decodeURIComponent || unescape)(s);
return s;
} // getItemName
Perhaps I'm missing something (I'm not very experienced with javascript) but how does that help me get the path to the selected file in a way that would allow it to be used in the macro? If I just needed the file name I could use "selectedFilesAsStr()" couldn't I? Can you perhaps give me an example of how this would work? Again, I appreciate the help.
-
EDIT: Nevermind, that doesn't actually work.
-
Thanks. I figured out part of it (I think) although there may be a better way.
This:
<form><input type='submit' name='view' value='View' onclick='
var a = selectedItems();
if (a.size() != 1)
this.value = "Select One File";
else
this.value = selectedFilesAsStr()'/></form>
{.if not|{.?view = Select One File.}|{:
{.notify|{.vfs to disk|{.?view.}.}.}
:}.}
gives me a notify bubble with the full path to the file. However, this:
<form><input type='submit' name='view' value='View' onclick='
var a = selectedItems();
if (a.size() != 1)
this.value = "Select One File";
else
this.value = selectedFilesAsStr()'/></form>
{.if not|{.?view = Select One File.}|{:
{.exec|notepad {.vfs to disk|{.?view.}.}.}
:}.}
does not open the selected file with notepad. Does this make sense?
EDIT: Solved it:
<form><input type='submit' name='view' value='View' onclick='
var a = selectedItems();
if (a.size() != 1)
this.value = 0;
else
this.value = selectedFilesAsStr()'/></form>
{.if not|{.?view.}||{:
{.exec|notepad|{.vfs to disk|{.?view.}.}.}
:}.}