I have come up with a hack to do this by making a custom <my-table-
plus> and <custom my-table>.

<def tag="my-table-plus" attrs="sort-field, sort-direction, sort-
columns" >
  <% sort_field ||= @sort_field; sort_direction ||= @sort_direction;
sort_columns ||= {} %>
  <% sort_columns['this'] ||= this.member_class.name_attribute %>
  <div class="table-plus" merge-attrs="&attributes -
attrs_for(:with_fields) - attrs_for(:table)">
    <div class="header" param="header">
      <div class="search">
        <form param="search-form" method="get" action="">
          <hidden-fields for-query-string skip="page, search"/>
          <span>Search</span>
          <input class="search" type="search" name="search"
value="&params[:search]"/>
          <submit label="Go" class="search-button" param="search-
submit"/>
        </form>
      </div>
    </div>

    <my-table merge-attrs="&attributes & (attrs_for(:table) +
attrs_for(:with_fields))" empty merge-params>
      <field-heading-row:>
        <my-with-field-names merge-attrs="&all_attributes &
attrs_for(:with_fields)">
          <% col = sort_columns[scope.field_path] || scope.field_path
             sort = sort_field == col && sort_direction == 'asc' ?
                      "-#{col}" : col
             sort_url = url_for(params.merge(:sort => sort) - [:page])
%>

          <th param="#{scope.field-name}-heading">
            <a href="&sort_url" class="column-sort"
               param="#{scope.field-name}-heading-link"><%=
scope.field_name.titleize %></a>
            <if test="&col == sort_field">
              <do param="up-arrow" if="&sort_direction ==
'desc'">&uarr;</do>
              <do param="down-arrow" if="&sort_direction ==
'asc'">&darr;</do>
            </if>
          </th>
        </my-with-field-names>
        <th if="&all_parameters[:controls]" class="controls"></th>
      </field-heading-row>
    </my-table>
    <do param="empty-message" if="empty?">No <collection-name
lowercase/> to display</do>


    <page-nav param if="&this.respond_to? :page_count"/>
  </div>
</def>

The only change here is to call <my-table> instead of <table>

<def tag="my-table" attrs="fields, field-tag, empty">
  <if test="&!(fields || all_parameters.tr?)">
    <%= element("table", attributes, all_parameters.default) %>
  </if>
  <else>
    <% field_tag ||= "view" %>
    <unless test="&this.empty? && !empty">
      <% element "table", attributes - attrs_for(:with_fields) do %>
      <thead if="&all_parameters[:thead] || fields" param>
        <tr param="field-heading-row">
          <with-field-names merge-attrs="&all_attributes &
attrs_for(:with_fields)">
            <th param="#{scope.field_name}-heading"><%=
scope.field_name.titleize %></th>
          </with-field-names>
          <th if="&all_parameters[:controls]" class="controls"/>
        </tr>
      </thead>
      <tbody>
        <repeat>
          <tr param if="&can_view?"
              class="#{scope.even_odd} #{this_type.name.underscore}
#{model_id_class}">
            <if test="&fields">
              <% @thisrow = this %>
              <my-with-fields merge-attrs="&all_attributes &
attrs_for(:with_fields)" force-all>
                <td param="#{this_field.to_s.sub('?', '').gsub('.',
'-')}-view">
                  <% if not @thisrow["p_"+this_field.to_s].nil?
                       %>
                         <call-tag tag="&field_tag" class="chgd"/>
                       <%
                     else
                       %>
                         <call-tag tag="&field_tag"/>
                       <%
                     end
                  %>
                                </td>
              </my-with-fields>
              <td class="controls" param="controls"
if="&all_parameters[:controls]">
                <a param="edit-link" action="edit">Edit</a>
                <delete-button param/>
              </td>
            </if>
          </tr>
        </repeat>
      </tbody>
      <tfoot if="&all_parameters[:tfoot]" param/>
      <% end %>
    </unless>
  </else>
</def>

The change to the original <table> is to look for the existence of a
field of the similar name, just with a p_ prepended to the field
name.  If this field exists and is not null it will contain the
previous value of the field, this is implementation specific so you
would have to hack differently depnding on what you are doing.


I created a @thisrow to be accessible from the field context.

              <% @thisrow = this %>

Then checking for the existence of a p_<fieldname> that is not null I
add a class of "chgd" as a flag for CSS to change the color.

                  <% if not @thisrow["p_"+this_field.to_s].nil?
                       %>
                         <call-tag tag="&field_tag" class="chgd"/>
                       <%
                     else
                       %>
                         <call-tag tag="&field_tag"/>
                       <%
                     end
                  %>

The custom CSS in public/stylesheets/application.css is

.chgd {color: #f00008;}

To make the changed fields appear red.

Now to make a hover that shows the previous value....

Brett


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/hobousers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to