Dynamic activity description in a value-list.

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

Dynamic activity description in a value-list.

Postby pdesbois » Wed Apr 29, 2009 5:26 am

Hello,
I’m a new Xataface user. Thanks to provide this very good tool :D

I made a table to store some activity (activity_list). In this table there is a name and a little description for each activity. In another table, I store the user weeklies. So, users can select an activity in a value-list. But in this value-list there are only activities name.
Is it possible to display the description of the activity selected when the user place the cursor into the value-list ?

Thanks and regards,
Patrice.
pdesbois
 
Posts: 9
Joined: Wed Apr 29, 2009 5:21 am
Location: france

Postby shannah » Wed Apr 29, 2009 7:36 am

This would require some custom javascript. Basically you would want to load all of the activities and their descriptions into a javascript array, then add an onchange handler to the select list to display the corresponding description some place on the screen.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby pdesbois » Wed Apr 29, 2009 11:13 pm

Thanks a lot.
I will try this...
pdesbois
 
Posts: 9
Joined: Wed Apr 29, 2009 5:21 am
Location: france

Postby pdesbois » Tue May 05, 2009 8:50 am

Ok, I tried but I have a problem :oops:
How to load the activities and their descriptions into a javascript array (from MySql table) ? (I'm a new user, sorry...)
Regards,
Patrice.
pdesbois
 
Posts: 9
Joined: Wed Apr 29, 2009 5:21 am
Location: france

Postby shannah » Tue May 05, 2009 9:39 am

The easiest way to do this to use JSON to convert a PHP array into javascript. Then embed this code into your template.

e.g.
Code: Select all
$res = mysql_query("select id,name from foo order by name", df_db());
if ( !$res ) trigger_error(mysql_error(df_db()), E_USER_ERROR);
$activities = array();
while ( $row = mysql_fetch_row($res) ){
    $activities[$row[0]] = $row[1];
}

$jsonActivities = json_encode($activities);
// $jsonActivities is a string representation of an javascript object.

...



This example merely shows how to form the javascript array. You will need to combine this with:
1. Insert javascript in an appropriate block or slot
2. Add onchange handler to your select list.

-steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby pdesbois » Wed May 06, 2009 12:22 am

Hi steve,
Thanks a lot, everything works correctly :D.

In the \tables\weekly.php file :
Code: Select all
class tables_weekly {
      ...

      function block__before_items_widget() {
            $app =& Dataface_Application::getInstance();
            $auth =& Dataface_AuthenticationTool::getInstance();
            $user =& $auth->getLoggedInUser();
            $team = $user->val('TEAM');
            $sql = "select NAME,DESCRIPTION from activity_list where TEAM='".$team."'";
            $res = mysql_query($sql);
            if ( !$res ) trigger_error(mysql_error(df_db()), E_USER_ERROR);
            $activities = array();
            while ( $row = mysql_fetch_row($res) ){
                  $activities[$row[0]] = $row[1];
            }
            $jsonActivities = json_encode($activities);
            // $jsonActivities is a string representation of an javascript object.
echo <<<END
            <script>
                  function displayPopup(listObj){
END;
            echo 'var arr = '.$jsonActivities.';';
echo <<< END
                        //Display pop-up if description is not null
                        if(arr[listObj.value] != null)
                              listObj.title=arr[listObj.value];
                        else
                              listObj.title="";
                  }
            </script>
END;
      }

      ...
}


In the tables\weekly_item\fields.ini :
Code: Select all
[ACTIVITYREF]
      widget:label            = "Activity"
      widget:type             = select
      widget:atts:onMouseOver="displayPopup(this);"
      vocabulary  = ...
pdesbois
 
Posts: 9
Joined: Wed Apr 29, 2009 5:21 am
Location: france


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 17 guests

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