mailto or http link for data in forms

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

mailto or http link for data in forms

Postby stevie » Tue Nov 27, 2007 8:20 am

I'm a total Dataface newbie, so I'm not sure I'm using the right vocabulary for this, but I would like to be able to display little icons or something in both the list view and the record view, so the user could make use of email addresses and URLs stored in the data.

I have a simple table, looking something like:

Code: Select all
ID - name  -     emailaddress  -     website
------------------------------------------
1     Bill      billg@microsoft.com     http://www.microsoft.com
2     Steve    sjobs@apple.com         http://www.apple.com


In the list view, the email addresses and URLs are "clickable" but they go to the record view. In the record view, they're not "clickable" at all.

I don't care too much about the format, but what's an easy way to put an icon or a bit of text (like "send mail" or "visit") next to the items so that the user can click on them and either invoke their email app or visit the web site?

Thanks very much. -Steve
stevie
 
Posts: 12
Joined: Tue Nov 20, 2007 7:45 pm

Postby shannah » Tue Nov 27, 2007 3:58 pm

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

Postby stevie » Wed Nov 28, 2007 8:46 pm

Thanks for the tip, but I have to admit to being a little scared... :cry: I haven't tried to use delegate classes before, I'm not sure I understand what they are.

But, I guess I should use the renderCell() method, in a delegate class. If I understand the doc right, I should:

* create a tables directory in my main directory

* create a "tablename" directory with the name of my sql table, inside the tables directory

* create a file called Program.php within the tablename directory, containing the following:

Code: Select all

class table_tablename {
    ...
    function email__renderCell( &$record ){
       return $record->strval('email').' ( Email this person)';
    }

?>


And at this point the list view will have a mailto link for the email field? Am I missing any big steps?

Once I get the mailto link working, I'll see if I can figure out the http link.

Thanks for your help and the great open source program! -Steve
stevie
 
Posts: 12
Joined: Tue Nov 20, 2007 7:45 pm

Postby shannah » Thu Nov 29, 2007 1:31 am

In general you're right ... I just want to make sure that you understand that the "tablename" directory is actually named after the table associated with this delegate class.
E.g. for the table named "People", the delegate class would be located at
tables/People/People.php

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

Postby stevie » Thu Nov 29, 2007 6:47 am

Thanks, I think I have the tablename directory named properly. But I've done these steps, and it seems to make no effect. Clicking on the "email" field in the list view still just jumps to the record view, and there is no text displayed that says "email this person". There is no error message of any kind displayed either.

As I said, I don't really understand how the delegate classes and methods etc. work.

Is there some other step I need to take, so that Dataface "pays attention" to the fact that I have this new class installed, with the email_renderCell function? Does the function have to be "called" in some way?

Thanks for any tips. -Steve
stevie
 
Posts: 12
Joined: Tue Nov 20, 2007 7:45 pm

Postby stevie » Thu Nov 29, 2007 6:59 am

BTW, here's some specifics about what I've done:

mysql info:
Code: Select all
CREATE TABLE `sample` (
  `id` smallint(5) unsigned NOT NULL default '0',
  `name` varchar(50) default NULL,
  `email` varchar(100) default NULL,
  `url` varchar(200) default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `sample`
--

INSERT INTO `sample` (`id`, `name`, `email`, `url`) VALUES
(1, 'Bill', 'billg@microsoft.com', 'http://www.microsoft.com');


directory structure:
Code: Select all
\\Evita2\intranet\dfsample 
\\Evita2\intranet\dfsample\conf.ini
\\Evita2\intranet\dfsample\index.php
\\Evita2\intranet\dfsample\tables 

\\Evita2\intranet\dfsample\tables\sample\

\\Evita2\intranet\dfsample\tables\sample\Program.php


and lastly, here are the contents of conf.ini, index.php, and Program.php:

Code: Select all
[[[[[[[[[[[[conf.ini]]]]]]]]]]]]]]]]
[_database]
host = "localhost"
user = "datafaceuser"
password = "xxxxxxxxxx"
name = "dataface"

[_tables]
sample = "sample"


[[[[[[index.php]]]]]]]]
session_save_path('/intranet/dataface/tmp');

require_once '/intranet/dataface/dataface-public-api.php';
df_init(__FILE__, 'http://www.xxxxxxxxxxx.edu/intranet/dataface');
$app =& Dataface_Application::getInstance();
$app->display();
?>


[[[[[[[[Program.php]]]]]]]]]]]]]]]]
class table_sample {
 
    function email__renderCell( &$record ){
       return $record->strval('email').' ( send email)';
    }
?>



I hope this will be useful information - and I hope that solving this issue will make it easier for the next person if they are as confused as I am.

Thanks again!
stevie
 
Posts: 12
Joined: Tue Nov 20, 2007 7:45 pm

Postby shannah » Thu Nov 29, 2007 10:46 am

Hi stevie,

Thanks for posting this info. It makes it very easy to diagnose the problem.

There are actually 2 problems:
1. The name of the file should be sample.php, not Program.php
2. The name of the class should be tables_sample, not table_sample

Best regards

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

Postby stevie » Thu Nov 29, 2007 11:55 am

:D

BINGO!

Those two changes did it. (Well, I also had a missing close brace in my sample.php (formerly Program.php)).

It was easy to add a web page link the same way - my "sample.php" file now looks like this:


class tables_sample {

function email__renderCell( &$record ){
return $record->strval('email').' ( send email)';
}

function url__renderCell( &$record ){
return $record->strval('url').' ( visit)';
}

}
?>



Thanks a ton, Steve!

Is there any way to also apply this kind of magic to the record-view window? Actually, it's "good enough" to have it in the list view for my application, but it would be sweet to be able to do it in record-view as well.

-Steve
stevie
 
Posts: 12
Joined: Tue Nov 20, 2007 7:45 pm

Postby shannah » Thu Nov 29, 2007 1:28 pm

Is there any way to also apply this kind of magic to the record-view window?


If you want to appy this change in the browse tab you can define an htmlValue for the field in the delegate class.

e.g.
Code: Select all
function email__htmlValue(&$record){
    return $record->strval('email').' ( send email)';
}


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

Postby stevie » Thu Nov 29, 2007 2:15 pm

Thanks so much, that worked perfectly also.

If anyone wants to copy this, here's my final php file, it prints nice links next to my email and url fields in both the list view and the current record detail view:


Code: Select all

class tables_sample {
 
    function email__renderCell( &$record ){
       return $record->strval('email').' ( send email)';
    }
   
   function url__renderCell( &$record ){
       return $record->strval('url').' ( visit)';
    }
   
   
   function email__htmlValue( &$record ){
       return $record->strval('email').' ( send email)';
}
   
  function url__htmlValue( &$record ){
       return $record->strval('url').' ( visit)';
    }
      
}
?>
stevie
 
Posts: 12
Joined: Tue Nov 20, 2007 7:45 pm

making mailto and href links in list views etc

Postby tomhousley » Wed Jul 08, 2009 1:26 pm

I have tried the php code as posted previously by stevie having changed the relevant fields for my table.

My table name is tbl_organisation

The delegate class is called tbl_organisation.php and is in /tables/tbl_organisation

My code is:

Code: Select all
<?php

class tables_tbl_organisation {

    function email__renderCell( &$record ){
       return $record->strval('org_email').' (<a href="mailto:'.$record->strval('org_email').'"> send email</a>)';
    }
   
   function url__renderCell( &$record ){
       return $record->strval('org_webaddress').' (<a href="'.$record->strval('org_webaddress').'"> visit</a>)';
    }
   
   
   function email__htmlValue( &$record ){
       return $record->strval('org_email').' (<a href="mailto:'.$record->strval('org_email').'"> send email</a>)';
}
   
  function url__htmlValue( &$record ){
       return $record->strval('org_webaddress').' (<a href="'.$record->strval('org_webaddress').'"> visit</a>)';
    }
     
}
?>


Here is the mysql table

Code: Select all
FIELD                 TYPE          COLLATION        NULL    KEY     DEFAULT         Extra           PRIVILEGES            COMMENT     
--------------------  ------------  ---------------  ------  ------  --------------  --------------  --------------------  -------------
org_id                INT(6)        (NULL)           NO      PRI     (NULL)          AUTO_INCREMENT  SELECT,INSERT,UPDATE               
org_name              CHAR(255)     utf8_general_ci  YES             (NULL)                          SELECT,INSERT,UPDATE               
org_address1          CHAR(255)     utf8_general_ci  YES             (NULL)                          SELECT,INSERT,UPDATE               
org_address2          CHAR(255)     utf8_general_ci  YES             (NULL)                          SELECT,INSERT,UPDATE               
org_address3          CHAR(255)     utf8_general_ci  YES             (NULL)                          SELECT,INSERT,UPDATE               
org_address4          CHAR(255)     utf8_general_ci  YES             (NULL)                          SELECT,INSERT,UPDATE               
org_countyorstate     CHAR(255)     utf8_general_ci  YES             (NULL)                          SELECT,INSERT,UPDATE               
org_ziporpostal       CHAR(255)     utf8_general_ci  YES             (NULL)                          SELECT,INSERT,UPDATE               
org_country           CHAR(255)     utf8_general_ci  YES             United Kingdom                  SELECT,INSERT,UPDATE               
org_status            DECIMAL(6,1)  (NULL)           YES             (NULL)                          SELECT,INSERT,UPDATE               
org_contactaccounts   CHAR(255)     utf8_general_ci  YES             (NULL)                          SELECT,INSERT,UPDATE               
org_typeofwork        CHAR(255)     utf8_general_ci  YES             (NULL)                          SELECT,INSERT,UPDATE               
org_omitfromdatabase  TINYINT(1)    (NULL)           YES             (NULL)                          SELECT,INSERT,UPDATE               
org_description       TEXT          utf8_general_ci  YES             (NULL)                          SELECT,INSERT,UPDATE               
org_dateofimport      DATE          (NULL)           YES             (NULL)                          SELECT,INSERT,UPDATE               
org_webaddress        CHAR(255)     utf8_general_ci  YES             (NULL)                          SELECT,INSERT,UPDATE               
org_enteredby         INT(6)        (NULL)           YES             (NULL)                          SELECT,INSERT,UPDATE               
pay_id                INT(6)        (NULL)           YES             (NULL)                          SELECT,INSERT,UPDATE  Payment Terms
org_email             CHAR(255)     utf8_general_ci  YES             (NULL)                          SELECT,INSERT,UPDATE


When i view the list view and click on an email or web field, it takes me to the detail view as though I hadnt used a delegate class.

Any help would be appreciated.

Many thanks, Tom
tomhousley
 
Posts: 52
Joined: Thu Feb 26, 2009 1:02 am
Location: United Kingdom

Postby shannah » Wed Jul 08, 2009 2:51 pm

Xataface is still putting its own link around your renderCell() method. Use the noLinkFromListView=1 directive in the fields.ini file for the fields in question. This will tell xataface to stop messing with your links.

e.g.

[mail]
noLinkFromListView=1
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

__renderCell and __htmlValue

Postby tomhousley » Thu Jul 09, 2009 12:29 am

Hi Steve,

Thank you for that.

I put that into actions.ini but it just made the email or web address non-linkable to anything and still no link to click for either.

I relaised after searching on the forum that

Code: Select all
    function email__renderCell( &$record ){
       return $record->strval('org_email').' (<a href="mailto:'.$record->strval('org_email').'"> send email</a>)';
    }


the function email__renderCell part of that should refer to the field in my table.

I changed it to

Code: Select all
function org_email__renderCell( &$record ){
       return $record->strval('org_email').' (<a href="mailto:'.$record->strval('org_email').'"> send email</a>)';
    }


function org_email__renderCell

and now it works fine.

I have since modified the delegate class which I think makes it a little more elegant.

Code: Select all
<?php

class tables_tbl_organisation {

//EMAIL FIELD IN LIST VIEW//
    function org_email__renderCell( &$record ){
//checks if email field is empty//
      if ( $record->strval('org_email') =="" ) {
//if it is, it adds text to cell//
         return 'Click to add Email';
      } else {
//iif it isnt blank, it prints the email address//
      return '<a href="mailto:'.$record->strval('org_email').'">'.$record->strval('org_email').'</a>';
}
    }
   
   
//WEB FIELD IN LIST VIEW//
    function org_webaddress__renderCell( &$record ){
//checks if web url is empty//
      if ( $record->strval('org_webaddress') =="" ) {
//if it is, it adds text to cell//
         return 'Click to add URL';
//checks to see if it has http:// at the start of url//
      } elseif (substr($record->strval('org_webaddress'),0,7) == "http://") {
//if it does have http:// it strips it so that only www. is visible//
         return '<a href='.$record->strval('org_webaddress').'>'.(substr($record->strval('org_webaddress'),7)).'</a>';
      } else {
//if it doesnt have http:// it adds it to the hyperlink//
      return '<a href=http://'.$record->strval('org_webaddress').'>'.$record->strval('org_webaddress').'</a>';
}
    }

    //EMAIL FIELD IN DETAIL VIEW//
    function org_email__htmlValue( &$record ){
//checks if email field is empty//
      if ( $record->strval('org_email') =="" ) {
//if it is, it adds text to cell//
         return '';
      } else {
//if it isnt blank, it prints the email address//
      return '<a href="mailto:'.$record->strval('org_email').'">'.$record->strval('org_email').'</a>';
}
    }
   
   
//WEB FIELD IN DETAIL VIEW//
    function org_webaddress__htmlValue( &$record ){
//checks if web url is empty//
      if ( $record->strval('org_webaddress') =="" ) {
//if it is, it adds text to cell//
         return '';
//checks to see if it has http:// at the start of url//
      } elseif (substr($record->strval('org_webaddress'),0,7) == "http://") {
//if it does have http:// it strips it so that only www. is visible//
         return '<a href='.$record->strval('org_webaddress').'>'.(substr($record->strval('org_webaddress'),7)).'</a>';
      } else {
//if it doesnt have http:// it adds it to the hyperlink//
      return '<a href=http://'.$record->strval('org_webaddress').'>'.$record->strval('org_webaddress').'</a>';
}
    } 
}
?>


Hope this post if useful to others.

Many thanks, Tom
tomhousley
 
Posts: 52
Joined: Thu Feb 26, 2009 1:02 am
Location: United Kingdom

Postby shannah » Thu Jul 09, 2009 5:23 am

The noLinkFromListView goes in the fields.ini file, not the actions.ini file. This needs to be combined with explicitly creating a link in the renderCell() method for it to work - otherwise there will be no link.

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


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