Valuelists depending on logged in user

A place for users and developers of the Xataface to discuss and receive support.

Postby ahouston » Thu Jun 14, 2007 11:33 am

Hi,

Hope someone can point me in the right direction - this problem is driving me nuts :)

I'm trying to filter the valuelist entries for a field based on records owned by the logged in user.

For example:

I have a "cash_accounts" table which has all the user's bank accounts:

mysql> describe cash_accounts;
+---------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+----------------+
| id | int(11) | | PRI | NULL | auto_increment |
| user_id | int(11) | | | 0 | |
| country_id | int(11) | | | 0 | |
| currency_id | int(11) | | | 0 | |
| description | varchar(100) | | | NULL | |
| interest_rate | float | | | 0 | |
+---------------+--------------+------+-----+---------+----------------+

..and for example the property_costs table - when I add a new record, I don't want to have all the bank account details from cash_accounts listed, only the one for this user.

mysql> describe property_costs;
+-----------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+--------------+------+-----+---------+----------------+
| id | int(11) | | PRI | NULL | auto_increment |
| user_id | int(11) | | | 0 | |
| property_id | int(11) | | | 0 | |
| cash_account_id | int(11) | | | 0 | |
| description | varchar(100) | | | NULL | |
| value | bigint(20) | | | 0 | |
+-----------------+--------------+------+-----+---------+----------------+


My fields.ini in tables/property_costs has:

[__filters__]
user_id="$user->val('id')"

My valuelists.ini has:

[cash_account_id]
__sql__ = "select id,description from cash_accounts order by id asc"

..which is obviously selecting all the records - can I use a delegate class to filter these results ?

Any help would be greatly appreciated !

Thanks,
Allan.

PS - thanks for an awesome product ;)
ahouston
 
Posts: 2
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Thu Jun 14, 2007 12:03 pm

Hi Allan,

You can define valuelists in the delegate class if you need them to be dynamic.Ê This post has a little bit of info on it:

http://framework.weblite.ca/forum/dataface-users/909107879

A couple things to be careful of if you do this:Ê Because of the way that Dataface loads its data you have to make sure that ALL values are available when you are displaying the data (e.g. list view).Ê Otherwise the fields that use the valuelist will show up blank.Ê You should do a check to see if the current action is an 'edit' action, and then - only then - use the filtered valuelist.Ê Otherwise output all of the values.

Because of this caveat, I generally use javascript to filter the values on the edit form - but don't really have any examples I can throw up right now of the Javascript way.. if you are interested in it, I'll see what I can dig up.

Best regards

Steve

--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Thu Jun 14, 2007 12:06 pm

Another place where dynamic valuelists have been discussed:

http://framework.weblite.ca/forum/dataface-users/378327080

This post makes a good point about caching the result of the valuelist method so that it doesn't get called every time.

-Steve

--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby ahouston » Fri Jun 15, 2007 8:26 am

Thanks Steve - this did exactly what I wanted :)
ahouston
 
Posts: 2
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 29 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved