rejetto forum

Software => HFS ~ HTTP File Server => HTML & templates => Topic started by: Kremlin on February 05, 2009, 05:22:23 PM

Title: HELP: Search only for folders (without use of Javascript)
Post by: Kremlin on February 05, 2009, 05:22:23 PM
So.. i need some help on making the search default for only folders without the use of Javascript. The idea is to basically type your search in as input and when pressing the search button it will redirect you to a link like this:

http://localhost/?folders-filter=*{.$search-data.}*&recursive&files-filter=\

Can anyone write the code for this? A good starting point might be the ToG search form..

<form action="/" name="simpleSearch" method="get">
         <input class="formInput" type="text" name="search" size="13" maxlength="32" value="{.$search-data.}" onclick="if(this.value=='{.$search-data.}')this.value=''"/>
         <input type="submit" value="Go"/>
</form>

ps. from what i think, it needs to add an onclick value to the button "Go", unfortunately i can't figure out how it should be written
Title: Re: HELP: Search only for folders (without use of Javascript)
Post by: TSG on February 06, 2009, 12:42:55 PM
Can't believe no one has helped you yet. Might be cause there is no easy way to do this without javascript.

If you look at the advanced search function I have made in javascript, it basically builds a valid link for HFS to use. Without building a link I do not think it is possible with just a form. Especially the insertion of stars on either side of query, forgotten what they do, but I know its important.

Code: [Select]
/* RAWR Search Form. */
function searchQuery() {
 //Form to use.
frm = document.searchForm;
if(frm.query.value.length < 3) {
// Alert user if query is less than 3 characters, take the load off HFS.
alert(lv_searchAlert);
} else {
// Determine what choices are made in the form.
frm.recursive.checked ? recursive ="&recursive" : recursive ="";
for(x=0; x<frm.choice.length; x++) {
if(frm.choice[x].checked ==1) {
if(frm.choice[x].value =="file") {
searchMode ="?files-filter=";
filter="&folders-filter=%5C";
} else if(frm.choice[x].value =="folder") {
searchMode ="?folders-filter=";
filter="&files-filter=%5C";
} else {
searchMode ="?filter=";
filter="";
}
}
}
for(c=0; c<frm.root.length; c++) {
if(frm.root[c].checked ==1) {
frm.root[c].value =="current" ? searchFrom ="http://"+serverHost+serverFolder : searchFrom ="http://"+serverHost;
}
}
//Build a link and submit values to HFS.
document.location.href = searchFrom+searchMode+"*"+frm.query.value+"*"+recursive+filter;
}
}
Title: Re: HELP: Search only for folders (without use of Javascript)
Post by: Kremlin on February 06, 2009, 06:12:53 PM
This is what i've gotten so far (doesn't work though dunno why)

The javascript code from ToG modified for only folders:

Code: [Select]
function searchQuery() {
frm = document.searchForm;
if(frm.query.value.length < 3) {
alert(lv_searchAlert);
} else {
for(c=0; c<frm.root.length; c++) {
if(frm.root[c].checked ==1) {
frm.root[c].value =="current" ? searchFrom ="http://"+serverHost+serverFolder : searchFrom ="http://"+serverHost;
}
}
document.location.href = searchFrom+"?folders-filter="+"*"+frm.query.value+"*"+"&recursive"+"&files-filter=\";
}
}

And then in the template:

Code: [Select]
<form action="/" name="simpleSearch" method="get">
<input class="formInput" type="text" name="search" size="13" max-lengh="32" value="{.$search-data.}" onclick="if(this.value=='{.$search-data.}')this.value=''"/>
<input class="search" type="submit" size="13" value="Go" onclick="searchQuery()"/>
</form>

If anyone knows why this doesn't work please reply and help  ;)
Title: Re: HELP: Search only for folders (without use of Javascript)
Post by: TSG on February 07, 2009, 05:58:08 AM
Forum seems lazy, here is my simplest solution, for use with our templates. Sorry, I cant work it out just now without javascript, maybe the macro masters can have a try, but it wont be as simple as this.

Append this to main.js:
Code: [Select]
function folderQuery() {
    frm = document.folderForm;
    if(frm.query.value.length < 3) {
        alert(lv_searchAlert);
    } else {
        document.location.href = "http://"+serverHost+"?folders-filter=*"+frm.query.value+"*&recursive&files-filter=%5C";
    }
}

Put this in place of the advanced search link and the simple search form:
Code: [Select]
<form action="javascript:folderQuery();" name="folderForm" method="get">
    <input class="formInput" type="text" name="query" size="13" maxlength="32" value="{.$search-data.}" onclick="if(this.value=='{.$search-data.}')this.value=''"/>
    <input type="submit" value="Go"/>
</form>
Title: Re: HELP: Search only for folders (without use of Javascript)
Post by: Kremlin on February 07, 2009, 07:10:53 AM
Works perfectly.
Title: Re: HELP: Search only for folders (without use of Javascript)
Post by: rejetto on February 07, 2009, 04:22:43 PM
good to see you got it.
javascript is needed to get the ** part.
the rest can be done even without javascript

<form action='/'>
<input type='hidden' name='recursive' value='1'>
<input type='hidden' name='files-filter' value='\'>
<input name='folders-filter'>
<input type='submit'>
</form>


(untested)