Page 1 of 3

Browse screen

Posted: Wed Jul 24, 2013 7:50 pm
by johan
Hi,

I have a little library where my collegues can reservate some books. I've created a form with subform. On that subform I have some lookups. The form used for the lookups show only the books available on the selected date.

Is there a way that I can show all the books in the library but where the user only can select the books available in lookup. P.ex those who are already reservated shown in red and not selectable for the user.
Anyone an idea?

Johan

Re: Browse screen

Posted: Fri Jul 26, 2013 2:34 am
by massiws
Johan, sorry but I'm not sure I understand the problem.

Do you need to filter out some records from the looked-up table?
Do you need to pass a filter to looked-up table?
Have you a field on that table to store the reserved/not-reserved information? If so, can't you show only not-reserved books?

Re: Browse screen

Posted: Fri Jul 26, 2013 10:33 am
by johan
Max,


With sql I only show the books not reserved in the period. That part is alright.
Now my colleagues ask me if it is possible to show all the books, those who are reserved marked red and not selectable in lookup.

I could adjust my sql so I get a list with all the books and one extra column available yes/no.

But how to set colour red and item not selectable?

Johan

Re: Browse screen

Posted: Fri Jul 26, 2013 11:51 am
by massiws
Johan, I think you could not make this without hacking nuBuilder core (but perhaps someone could contradict me).

Have a look at this forum.
Following that approach, you can edit the standard browse.php file and add a class to column containing a specific value in your field; also, to make the row unselectable, remove the onlick attribute in each column.
So you could add a style to format these rows like you want (you can also apply the nuUnselectedRow style).

I've never tried this: let me know how you solve it.

Hope this helps,
Max

Re: Browse screen

Posted: Fri Jul 26, 2013 4:10 pm
by johan
Max,

Is it not possible with nuLoadThis() ? If i change browse.php it will affect all my forms / databases.

Johan

Re: Browse screen

Posted: Sun Jul 28, 2013 1:31 am
by massiws
mmm... nuLoadThis() is executed before nuBuilder load edit form, that is, after record in browse form is selected.
In nuLoadThis() you may insert a function to alert user with something like: "Please go back: this book is already reserved!".

Re: Browse screen

Posted: Sun Jul 28, 2013 9:56 pm
by johan
Max,

Thanks for your reply.

Perhaps a suggestion for the builders :D to add something simular as "nuloadThis()" that works before the browse screen opens a table.

Johan

Re: Browse screen

Posted: Mon Jul 29, 2013 12:26 am
by massiws
I have opened a post here: more suggestions are appreciated!

Max

Re: Browse screen

Posted: Mon Jul 29, 2013 9:20 am
by johan
Max,

Great meanwhile I try the solution with the alert.

Thanks for your help.

Johan

Re: Browse screen

Posted: Thu Aug 01, 2013 11:03 pm
by massiws
Johan, have a look at this solution from fester.

Inserting something like this in Custom Code > Before Open you can block editing of not-available book-records:

Code: Select all

// Get the 'available/not-available' field value
$sql = "SELECT available FROM myTable WHERE tableID = '#id#' ";
$field = db_fetch_object(nuRunQuery($sql));
$available = $field->available;

if ($available == true) {
    // add JavaScript function to stop Edit Screen
    $js  = "function notAvailable() {\n";
    $js .= "  alert('This book is not available: please go back!');\n";
    $js .= "  window.history.go(-1);\n";
    $js .= "}\n\n";
    
    $js .= "notAvailable();\n";

    addJSfunction($js);
}
So, when the user attempt to select a not-available book (open Edit Screen), he/her gets an alert message and is sent back to Browse Screen.

Max