Page 1 of 1

css__tableRowClass

PostPosted: Wed Mar 28, 2012 9:38 am
by wisni1rr
I'm new to the web development scene.

I'm looking to use this function to change the color of a field based on the value of it. For example if the value is "STOP" then it would format the text red or if it's "GO" then it would format green.

My question is where do I put my actual css at to begin with?

Thanks

Re: css__tableRowClass

PostPosted: Wed Mar 28, 2012 9:46 am
by shannah
You need to include your own stylesheet. What I often do is use the addHeadContent() method of the Dataface_Application object. I place a call to this inside the beforeHandleRequest() method of the application delegate class.
http://xataface.com/dox/core/trunk/clas ... 5046c375b1

Code: Select all
function beforeHandleRequest(){
    $app = Dataface_Application::getInstance();
    $app->addHeadContent('<link rel="stylesheet" type="text/css" href="mystyles.css"/>');
}


In this case you would add a file named mystyles.css to your application's directory and add your own custom CSS in there.

-Steve

Re: css__tableRowClass

PostPosted: Wed Mar 28, 2012 10:09 am
by wisni1rr
I've added your call to my ApplicationDelegate.php.

I have created a file, "mystyles.css" with this content:

Code: Select all
<html>
<style>
tr.ACT td {color:green;}
tr.PEN td {color:orange;}
tr.CLO td {color:red;}
</style>
</html>

My table delegate contains this:
Code: Select all
    function css__tableRowClass( &$record ){
        if ( $record->val('Status') == "ACTIVE" ) return 'ACT';
        else return 'PEN';
    }


However, nothing changes is my list view.
Any Ideas?

Re: css__tableRowClass

PostPosted: Wed Mar 28, 2012 11:09 am
by shannah
The content of those cells are probably links (i.e. "a" tags) so their style is probably overriding the text style assigned to the td tag.

-Steve

Re: css__tableRowClass

PostPosted: Wed Mar 28, 2012 11:22 am
by wisni1rr
Would my desired result be best handled by using the renderCell method instead?

I just need to format the color of the text of a field in list view based on the value of its contents.

Re: css__tableRowClass

PostPosted: Wed Mar 28, 2012 11:33 am
by shannah
You can handle it any way you like. I was just pointing out that your CSS targets the td tag. But you should probably also target the a tags within the td tags.
Code: Select all
tr.ACT td, tr.ACT td a {color:green;}
tr.PEN td, tr.PEN td a {color:orange;}
tr.CLO td, tr.CLO td a {color:red;}



I now also notice that you had html tags in your CSS files. You don't need to put html tags (e.g. <html> <style> etc..) inside the CSS file. In fact this will cause it to break.

-Steve

Re: css__tableRowClass

PostPosted: Wed Mar 28, 2012 12:07 pm
by wisni1rr
Yes, they are links. I forgot to answer this in my last post. I have tried to add style to the "a" tags as you have described but I still do not see a change. The cells are all still the light blue link color.

Re: css__tableRowClass

PostPosted: Wed Mar 28, 2012 12:10 pm
by shannah
Did you still have the HTML markup in your stylesheet? CSS requires trial and error sometimes. Make sure that
1. Your stylesheet is being picked up. (e.g. make some crazy and easy style rules that will let you know if they are working).
2. Your particular rule is being picked up (try adding !important to some rules to make sure they can't be overridden by other rules).

-Steve

Re: css__tableRowClass

PostPosted: Wed Mar 28, 2012 12:37 pm
by wisni1rr
I'm thinking that by css is not getting pulled. My page source looks like this:

Code: Select all
         <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
      <title>Omitted</title>
      <link rel="stylesheet" type="text/css" href="http://bwaxatatest.elementfx.com/xataface/plone.css"/>      <!-- Stylesheets go here -->      
            <!-- Common Plone ECMAScripts -->