rejetto forum

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - skb

Pages: 1 2 3 4
HTML & templates / %comment% in ~files.lst ?
« on: February 22, 2015, 11:23:43 PM »
I'm thinking this is by design rather than a bug, but wanted to check: It does not seem that the %comment% tag provides any output to the basic text "~files.lst" page.

I have a simple hfs.filelist.tpl that for files that currently does just: 
Code: [Select]


%item-name% %item-modified% %item-size-b%


This has been working as expected.

Today, I added "%comment%" after my %item-size-b% entry, restarted HFS, and got no change in output.

I've searched the forum for %comment%, and see that there's a long history of adding support for complex HTML and multiline output. My guess is that this makes it impossible to use comments in the text output for ~files.lst  .

But, just to confirm, is there any way to get say, just the bare first line of a comment into the text-only output?


Note: version 2.3e corrects the bug mentioned below. Now sorting columns work as expected.  :D

On the standard hfs.tpl, the default sort link goes through four states when you click it repeatedly. I'd like to change the code so it just toggles two states, forward and reverse sort of the given column.

E.g I have "Name" selected in HFS>Menu>Other Options>Default Sorting; so if I don't click anything, files are alphabetical.

When I repeatedly click the "Size" button, the search URL changes as follows:
?sort=s (that is, sorted by size, smallest first)
?rev=1(reversed, but no field specifier, so in my case, sorted Z-A by name)
?rev=1&sort=s(sorted by size, biggest first)
(fourth click gives no sort code, so in my case, sorted A-Z by name)
?sort=s ( cycle repeats... )

I'd like it to just toggle the order of the selected field, e.g. when size is clicked repeatedly, alternate between these two states:
?sort=s (that is, sorted by size, smallest first)
?rev=1&sort=s(sorted by size, biggest first)
?sort=s ( and repeat... )

But to me the existing sortlink macro is hard going! Here it is:
Code: [Select]
            {.set|sortlink| {:<a href="{.trim|
                    {.get|url|sort=$1| {.if| {.{.?sort.} = $1.} |  rev={.not|{.?rev.} .} /if.} /get.}
                /trim.}">{.!$2.}{.if| {.{.?sort.} = $1.} | &{.if|{.?rev.}|u|d.}arr;.}</a>:} .}

Can someone explain how to modify the sortlink macro so that that it skips those other two parts of the cycle?


Yes. I was a bit confused by the concept that even though the Javascript source is in my hfs.tpl file that is located on the server, it is being executed in the client's browser. Thus, to do anything affecting the files on the server (rename, delete, etc) there has to be some GET or POST call to the server.

In general, the HFS macros provide the way to do this "server-side" interaction. Also, it seems that your "Events" interface is the best way for working with these server processes.

That is, at first I was thinking I had to mess with the {.rename .} macro to have it adjust timestamps when it renamed a file. In fact, the solution was to apply the code at the  [+on macro rename] event rather than in the hfs template.

Thanks again!

HTML & templates / Re: Can I set the filter programatically?
« on: February 21, 2015, 09:55:34 PM »
Thanks for the additional info.

For my simple case, when they click my "Apply Filter" button, then in the Javascript click handler, I build the ?filter string as variable newFilterStr from the pieces the user had entered in some custom fields, and then apply the resulting filter by using: = newFilterStr .

When they click my "Clear Filter" button, I just use: = "" , and this clears the filter from the URL. 

(Note that setting also clears any other options such as custom sort orders and stuff, but I don't worry about that. If you cared, you could read the existing value of and modify it, but it is easier to just replace it.)

Also, setting causes a page reload, which resets the custom fields that the user used to enter their desired filter back to default values. This makes it annoying to edit a filter you've applied, as the values you previously entered are gone. So, I use a jquery "$( document ).ready" function, which is called at page load, to parse the filter string (if any) and reset my fields to the id values that generated it.

(Again, all my fancy filtering depends on the fact that we use specific character positions in our data file names as fields with specific meanings, so we can filter on these character positions to show particular subsets of our data files. None of this would be any use for general file upload/download service.)

In any case, I'm all set on this topic.

Those pesky global variables; they get me every time.

Thanks for a very useful product!


HTML & templates / Re: Can I set the filter programatically?
« on: February 12, 2015, 06:53:53 AM »
Never mind! Turns out to be basic Javascript, nothing custom to hfs:

All set. :P

HTML & templates / Can I set the filter programatically?
« on: February 11, 2015, 08:02:08 AM »
I hope this is basic, but I guess I don't really get how it works. I would like to generate a particular ?filter string in response to a user button press and apply it to the current folder view.

In my application, which is based on the standard hfs.tpl, our data files are named in a particular way, which makes it useful to show only certain subsets based on the names. Rather than making the users type ?filter lines into their address bar, I'd like to have buttons and scripts for some common filters, similar to the idea of the "Select" box of the template, e.g. A button to show all files, which would clear the ?filter from the URL; a button to filter by specific file name codes; and also a "Mask" button for the user to enter the pattern they want, which gets expanded to a filter line.

BUT: what do I do with my filter string to refresh the page with that filter added to the URL? Can I do it from Javascript, or from a HFS macro, or either way?

E.g. for project code "A31", I'd prompt the user for the code, and make a filter string like "?filter=BD_A31_*" . Once I've generated that string, how do I apply it to the current folder view?

Thanks for any hints and pointers!

Thank you for your help. You're right, it would be much easier to just use the Live template! But, it is too complex for my simple application.

Reading through the forum, I found a post where Rejetto recommended the tool Fiddler to capture the actual POST requests from the browser to HFS. (Fiddler is really cool!)

With a clean stock hfs.tpl, I tried a delete, then an archive, and then then another delete, which shows the bug: The archive command adds ?mode=archive to the URL in the POST, and this doesn't get cleared out by the delete command. Delete adds "&action=delete" to the end of the selection list, but this is overridden by the ?mode.

Here are the key lines of the raw POSTs from fidder. First, the initial Delete, which works properly:
POST http://localhost/BUS/ HTTP/1.1

Next, an Archive of two files, which also works:
POST http://localhost/BUS/?mode=archive&recursive HTTP/1.1

Now try Delete on those same two files. This fails, and does another archive, because the "mode" string is still there:
POST http://localhost/BUS/?mode=archive&recursive HTTP/1.1

SO, the call to archive sets the mode, but the call to delete doesn't clear it.

Here's the post code for the Archive button (hfs.tpl line 201):
Code: [Select]
        <button id='archiveBtn' onclick='if (confirm("{.!confirm.}")) submit({}, "{.get|url|mode=archive|recursive.}")'>{.!Archive.}</button>
And the original code for the Delete button (hfs.tpl line 187):
Code: [Select]
        <button id='deleteBtn' onclick='if (confirm("{.!confirm.}")) submit({action:"delete"})'>{.!Delete.}</button>
The fix :) is to explicitly pass a URL with no mode string (REVISED hfs.tpl line 187): 
Code: [Select]
        <button id='deleteBtn' onclick='if (confirm("{.!confirm.}")) submit({action:"delete"}, "{.get|url.}")'>{.!Delete.}</button>

Seems the bug is in the stock hfs.tpl

I tested using RAWR Designs' excellent "Live" template, and this confirmed that my bug is in the default hfs.tpl only, not intrinsic to the in the hfs server code.

I was hoping to find a simple example of the working logic for archives and deleting, but unfortunately the Live template is well beyond me; I could not even find their archiving and deleting code to compare it to the stock hfs.tpl version.

And, I while I haven't tried all of them yet, it seems most of the templates don't include the file-select-and-delete action. (Or, if they have it, I couldn't figure out how to access it as a logged-in user.)

The test case is: select some files, download an archvie, and then delete them. This works flawlessly and also mysteriously and incomprehensibly in RAWR's Live template; and yet it fails on a clean install of the base hfs.tpl . (And, honestly, I can't really understand it well enough to debug it there, either!)

I'm using HFS to host an Android-based data collection system, so it is all about the devices doing very simple .CSV input file downloads; and then simple uploads of the finished data files. These transfers are all one file at a time; archive .tar files are used only for loading the site with data for the collection tablets, and for fetching back the completed data files.

SO, the back office people will download a selected batch of uploaded data, and then delete these files from the server. So unfortunately, this possibly obscure "Download Archive, then Delete the files" bug is one that we'll step into all the time.

Are there other simple templates that allow selection and deletion that I can check for this bug?

Or, is there someone that can explain the archive and deletion code in either the stock hfs.tpl or in Live-3.0.1.tpl ?


After selecting and archiving some files, if you try to delete that set of files, you get the delete prompt, but the action that happens is a second archive download.

To reproduce, go to a folder with some files, where you have delete privileges. (Bug occurs either with a user with delete rights, or else with "anyone" can delete.) Select one or more files and click the "Archive" button, and download the .tar file.

Then, with the same files selected, click "Delete". After the prompt, the "archive" file save prompt is shown again, rather than the files being deleted.

In fact, even if you change the selection, all attempts to delete are instead seem to give archive prompts.

To clear this, navigate back to home, and then return to the folder. Now selecting files and deleting works.

After I first found this bug with my system, I re-tested it with a clean download and all settings reset and a new VFS.

I'm running Win8.1 64-bit. Bug happens with both Chrome and Firefox.

Much simpler than I feared: Events are really handy! Using "on macro rename", and the touch.exe util from it is a one liner to update a file's timestamp after it is renamed:

[+on macro rename]
{.exec|C:\hfs\bin\touch.exe -c {.vfs to disk|%new-name%.}.}

Thanks for a great tool!


Thanks for that, very helpful.

And, re-reading the default template source, I see what is happening now with that ajax("rename", ...) call. I'd thought before that it was jumping off into the bowels of secret server code to do some magic thing. But now I see that it is just building a section name (e.g. "ajax.rename") and POSTing that section! Way clever! This POST triggers execution of the macro code.

So the code I need to modify to get the time stamps on rename is indeed standard macro stuff, in the [ajax.rename] section.

Thanks for the pointers!

Kind of a general question, more about "why" to code things a particular way, but also a specific "how". What sorts of things do you do with the built-in macros rather than Javascript? I'm trying to gain understanding of each, but don't really get how they fit together.

Are macros only for HFS events, whereas Javascript is necessary for button onclick handling? Is it possible to mix them? Are there pluses and minuses to either approach? Can I trigger an HFS event from a Javascript button click handler?

I'm currently reading through the docs and  the standard template code, and exploring how to modify it in some simple ways. As an example, I want to make a custom version of rename, to process a list of specific file names in a particular way; we will change only a few ID character positions of each file name, so we can process a batch in one go.

When I read the scripting commands page, I found the rename macro:
   {.rename | A | B.}
which renames the file A to B. I assumed I'd be using this macro for each file in my list, as well as .cut and .set  and all to build the new file names.

I'd also like to change each file's timestamp to the current time when it is renamed, which I was thinking to do via {.exec| touch <filename>.}, but it is not clear how to blend macro functions in with Javascript actions.

However, the built-in "Rename" button handler does it in pure Javascript instead, e.g.:

[...some setup code ommitted...]
    {"type":"text", "default":getItemName(a[0])},
    function(s){ajax("rename", {from:getItemName(a[0]), to:s});}

Is this just because it is the event handler for the button, or are there other reasons to use Javascript rather than macros? Not clear to me how or if it is possible to mix macros and Javascript functions; when do macros "execute" with respect to the Java script functions on the page?

Is there any way to get at the {.exec .} macro from within a click handler for rename? Or, conversely, is there any way to have Javascript run commands on files on the host system? (I've only used Javascript in client side code, which is restricted from such access by the browser.)

Thanks for any general light you can shed!


HTML & templates / Re: filelist.tpl ignored?
« on: December 22, 2014, 11:31:13 PM »
Awesome, thanks!

(Can someone with wiki credentials add hfs. to the doc page at  ?)

HTML & templates / Re: register end after to see the file in our server
« on: December 22, 2014, 04:05:40 AM »
Sorry, not really clear (to me, at least) what you are asking for help with. Do you have a specific question? You should be able to serve files with HFS regardless of being registered in the forum or not.

Pages: 1 2 3 4