I'm trying to update a row inside an active scaffold list from an
action link attached to a column. I think I'm awfully close, but I
can't get the row to update without adding a yellow bar to the list.
The table in question has a column named 'active', which determines
whether a record is visible from the front-side application. I want
the user to click the active field in active scaffold to toggle it on
or off, and have the appropriate row update with the new active
value. I can toggle the active field, but I can't get the display to
refresh without the extra line.
Here's the controller code:
class RemsitesController < ApplicationController
active_scaffold :remsite do |config|
config.list.columns = [:active, :name, :ident]
config.columns[:active].set_link 'Toggle', :action =>
'toggle_active', :position => :replace
end
# toggle active flag
def toggle_active
@remsite = Remsite.find(params[:id])
@remsite.active = @remsite.active? ? false : true
@remsite.save
# redraw just the line in question
render :partial => 'list_record', :locals => {:record => @remsite}
end
end
This controller does what I need; however, it adds a yellow bar with a
close button above the record. I'd like to avoid the yellow bar.
I've tried :position => :replace, :position => false, :position
=> :false, all with the same results. I tried rendering the row
through RJS and got a page full of javascript code. Can someone help
me find the magic incantation to make this work?
Thanks,
Jack
The fix is pretty simple; in lib/data_structures/column.rb, line 73,
change:
options[:position] ||= :after
to:
options[:position] = :after unless options.has_key?(:position)
The controller now looks like:
class RemsitesController < ApplicationController
active_scaffold :remsite do |config|
config.list.columns = [:active, :name, :ident]
config.columns[:active].set_link 'Toggle', :action =>
'toggle_active', :position => false
end
# toggle active flag
def toggle_active
@remsite = Remsite.find(params[:id])
@remsite.active = @remsite.active? ? false : true
@remsite.save
end
end
The toggle_active.rjs view looks like:
page.replace_html element_row_id(:action => 'list', :id =>
params[:id]), :partial => 'list_record_element', :locals => {:record
=> @remsite}
page << "ActiveScaffold.stripe('#{active_scaffold_tbody_id}');"
I had to create a _list_record_element.rhtml partial to redraw the
row. _list_record.rhtml includes the <tr> tags which throws off the
display, _list_record_element.rhtml is just _list_record.rhtml without
the <tr> tags. _list_record_element.rhtml is in views/
active_scaffold_overrides and looks like:
<% url_options = params_for(:action => :list, :id => record.id) -%>
<% active_scaffold_config.list.columns.each do |column| %>
<% column_value = render_column(record, column) -%>
<td class="<%= column_class(column, column_value) %>" >
<% if column.link -%>
<% column.link.label = column_value %>
<%= render_action_link(column.link, url_options) %>
<% else -%>
<%= column_value %>
<% end -%>
</td>
<% end -%>
<% if active_scaffold_config.action_links.any? {|link| link.type
== :record } -%>
<td class="actions">
<%= render :partial => 'list_actions', :locals => {:record =>
record, :url_options => url_options} %>
</td>
<% end -%>
<% target_id = element_row_id(:action => :list, :id => record.id) -%>
<script type="text/javascript">
actions = new ActiveScaffold.Actions.Record(
$$('#<%= target_id -%> a.action'),
$('<%= target_id -%>'),
$('<%= loading_indicator_id(:action => :record, :id => record.id) -
%>'),
{refresh_url: '<%= url_for params_for(:action => :row, :id =>
record.id, :_method => :get, :escape => false) -%>'}
);
</script>
Is setting :position => false + rjs still the way to go to update a
record row after manipulating it with an action link, or is there an
easier way?
Thanks in advance
I followed the instructions in
http://groups.google.com/group/activescaffold/browse_thread/thread/60b264a79a0ade53/4a58624e90ad92f7?lnk=gst&q=update&rnum=4#4a58624e90ad92f7
and noticed a few quirks:
For an article model with a published attribute (boolean), and an
action link (config.action_links.add 'publish', :label =>
'Publicera', :type => :record, :parameters => {:action =>
'publish'}, :inline => true, :position => :replace) the output is:
1. The rjs code:
page.replace_html "articles-list-#{params[:id]}-row", :partial =>
'list_record', :locals => { :record => @article }
page << "ActiveScaffold.stripe('#{active_scaffold_tbody_id}');"
2. The controller correctly updates the published attribute for the
record
3. the row does not get updated, and there is an rjs error instead:
try { Element.update("articles-list-1-row", "\n
\n \n \n \n Huvudnyhet\n \n \n \n \n true\n \n \n \n \n Nyheter\n \n
\n
\r\n \r\n \r\n \"loading\r\n \r\n \r\n \r\n \r\n Publicera\r\n \r\n \r
\n \r\n \r\n Edit\r\n \r\n \r\n \r\n \r\n Delete\r\n \r\n \r\n \r\n
\r\n Show\r\n \r\n \r\n
\r\n
\n \n
\n\n\n"); ActiveScaffold.stripe('articles-tbody'); } catch (e)
{ alert('RJS error:\n\n' + e.toString());
alert('Element.update(\"articles-list-1--row\", \"\\n\\n \\n \\n \\n
Huvudnyhet\\n \\n \\n \\n \\n true\\n \\n \\n \\n \\n Nyheter\\n \\n
\\n
\\r\\n \\r\\n \\r\\n \\\"loading\\r\\n \\r\\n \\r\\n \\r\\n \\r\\n
Publicera\\r\\n \\r\\n \\r\\n \\r\\n \\r\\n Edit\\r\\n \\r\\n \\r\\n \
\r\\n \\r\\n Delete\\r\\n \\r\\n \\r\\n \\r\\n \\r\\n Show\\r\\n \\r\
\n \\r\\n
\\r\\n
\\n \\n
\\n\\n\\n\");\nActiveScaffold.stripe(\'articles-tbody\');'); throw e }
3. reading the source, I noticed that the record rows have an id that
looks like articles-list-1--row, a double dash after the id, which may
be wrong?
Changing the rjs to replace instead of replace_html and/or changing
the id for the row to contain two dashes instead of one makes no
significant difference. Can I debug this further to help you see
what's wrong?
Thanks in advance,
/Dimitris
On Apr 24, 6:31 pm, "Lance Ivy" <l...@cainlevy.net> wrote:
> Yep, that's the way to go still. You could make a request in the tracker for
> an official way ...
>
On 30 abr, 20:13, "Lance Ivy" <l...@cainlevy.net> wrote:
> Hmm, what's the actual RJS error? Also, what browser are you using?
>
> Also, you see how the bit you pasted in step #3 is split into two halves?
> The first half is the attempt at actually doing something, and the second
> half is the alert dialog in case something goes wrong. Well the double dash
> only exists in the second half; in the first it's normal.
>
> On 4/24/07, dimitris <jazzde...@gmail.com> wrote:
>
>
>
> > Hi Lance, thanks for your quick reply
>
> > I followed the instructions in
>
> >http://groups.google.com/group/activescaffold/browse_thread/thread/60...
On 30 abr, 20:13, "Lance Ivy" <l...@cainlevy.net> wrote:
> Hmm, what's the actual RJS error? Also, what browser are you using?
>
> Also, you see how the bit you pasted in step #3 is split into two halves?
> The first half is the attempt at actually doing something, and the second
> half is the alert dialog in case something goes wrong. Well the double dash
> only exists in the second half; in the first it's normal.
>
> On 4/24/07, dimitris <jazzde...@gmail.com> wrote:
>
>
>
> > Hi Lance, thanks for your quick reply
>
> > I followed the instructions in
>
> >http://groups.google.com/group/activescaffold/browse_thread/thread/60...
On 30 abr, 20:13, "Lance Ivy" <l...@cainlevy.net> wrote:
> Hmm, what's the actual RJS error? Also, what browser are you using?
>
> Also, you see how the bit you pasted in step #3 is split into two halves?
> The first half is the attempt at actually doing something, and the second
> half is the alert dialog in case something goes wrong. Well the double dash
> only exists in the second half; in the first it's normal.
>
> On 4/24/07, dimitris <jazzde...@gmail.com> wrote:
>
>
>
> > Hi Lance, thanks for your quick reply
>
> > I followed the instructions in
>
> >http://groups.google.com/group/activescaffold/browse_thread/thread/60...
tr class="inline-adapter">
<td style="background-image: none; background-color: transparent;"
colspan="99" class="inline-adapter-cell">
<div class="anular_pedido-view view">
<a href="" class="inline-adapter-close" title="close">Close</a>
try {
Element.update("privado__pedidos-list-7-row", "\n</div></td></tr><tr
\="" id="\"privado__pedidos-list-7-row\""
class="\"record">\n \n \n <td class="\"referencia-
column" \="">\n 2007-06-08-000012\n </td>\n
\n \n <td class="\"estado-column" \="">\n
ANULADO\n </td>\n \n \n <td
class="\"fecha_creacion-column" \="">\n 06/08/2007
10:42 PM\n </td>\n \n \n <td
class="\"fecha_actualizacion-column" \="">\n
06/08/2007 10:42 PM\n </td>\n \n \n <td
class="\"User-column" \="">\n 12345\n </td>
\n \n \n <td class="\"forma_pago-column" \="">
\n VISA/MASTERCARD\n </td>\n \n \n
<td class="\"forma_envio-column" \="">\n RECOGER
\n </td>\n \n \n <td class="\"pagado-column"
\="">\n NO\n </td>\n <td
class="\"actions\"">\n <table cellpadding="0"
cellspacing="0">\n <tbody><tr>\n <td class="\"indicator-
container\"">\n <img alt="\"loading" indicator\=""
class="\"loading-indicator\"" id="\"privado__pedidos-
record-7-loading-indicator\"" src="%5C%22/images/active_scaffold/
default/indicator.gif?1181390088%5C%22" style="">\n </td>
\n <td>\n <a href="%5C%22/privado/pedidos/nested/
7?_method=get&associations=Lineapedido%5C%22"
class="\"nested" action\="" id="\"privado__pedidos-nested-7-
link\"" position="\"after\"">Ver productos</a> </
td>\n <td>\n <a href="%5C%22/privado/pedidos/
nested/7?_method=get&associations=DireccionEntrega%5C%22"
class="\"nested" action\="" id="\"privado__pedidos-nested-7-
link\"" position="\"after\"">Direccion</a> </td>
\n <td>\n <a href="%5C%22/privado/pedidos/
anular_pedido/7?_method=get%5C%22" class="\"anular_pedido" action
\="" id="\"privado__pedidos-anular_pedido-7-link\""
position="\"replace\"">Anular</a> </td>
\n <td>\n <a href="%5C%22/privado/pedidos/edit/7?
_method=get%5C%22" class="\"edit" action\=""
id="\"privado__pedidos-edit-7-link\""
position="\"replace\"">Edit</a> </td>\n
<td>\n <a href="%5C%22/privado/pedidos/destroy/7?_method=delete
%5C%22" class="\"destroy" action\="" id="\"privado__pedidos-
destroy-7-link\"" onclick='\"return' confirm(="" are="" you=""
sure?="" );\="">Delete</a> </td>\n </tr>\n</tbody></table>
\n </td>\n </tr>\n\n\n");
ActiveScaffold.stripe('privado__pedidos-tbody');
} catch (e) { alert('RJS error:\n\n' + e.toString());
alert('Element.update(\"privado__pedidos-list-7-row\", \"\\n<tr \\\=""
id="\\\"privado__pedidos-list-7-row\\\"" class="\\
\"record">\\n \\n \\n <td class="\\\"referencia-
column" \\\="">\\n 2007-06-08-000012\\n </td>\
\n \\n \\n <td class="\\\"estado-column" \\\="">\
\n ANULADO\\n </td>\\n \\n \\n <td
class="\\\"fecha_creacion-column" \\\="">\\n
06/08/2007 10:42 PM\\n </td>\\n \\n \\n <td
class="\\\"fecha_actualizacion-column" \\\="">\\n
06/08/2007 10:42 PM\\n </td>\\n \\n \\n <td
class="\\\"User-column" \\\="">\\n 12345\\n
</td>\\n \\n \\n <td class="\\\"forma_pago-column" \\
\="">\\n VISA/MASTERCARD\\n </td>\\n \\n
\\n <td class="\\\"forma_envio-column" \\\="">\\n
RECOGER\\n </td>\\n \\n \\n <td class="\\
\"pagado-column" \\\="">\\n NO\\n </td>\
\n <td class="\\\"actions\\\"">\\n <table
cellpadding="0" cellspacing="0">\\n <tbody><tr>\\n <td class="\\
\"indicator-container\\\"">\\n <img alt="\\
\"loading" indicator\\\="" class="\\\"loading-indicator\\
\"" id="\\\"privado__pedidos-record-7-loading-indicator\\
\"" src="%5C%5C%5C%22/images/active_scaffold/default/
indicator.gif?1181390088%5C%5C%5C%22" style="">\\n </td>\
\n <td>\\n <a href="%5C%5C%5C%22/privado/pedidos/
nested/7?_method=get&associations=Lineapedido%5C%5C%5C%22" class="\
\\"nested" action\\\="" id="\\\"privado__pedidos-nested-7-
link\\\"" position="\\\"after\\\"">Ver productos</
a> </td>\\n <td>\\n <a href="%5C%5C%5C%22/
privado/pedidos/nested/7?_method=get&associations=DireccionEntrega
%5C%5C%5C%22" class="\\\"nested" action\\\="" id="\\
\"privado__pedidos-nested-7-link\\\"" position="\\
\"after\\\"">Direccion</a> </td>\\n <td>\
\n <a href="%5C%5C%5C%22/privado/pedidos/anular_pedido/7?
_method=get%5C%5C%5C%22" class="\\\"anular_pedido" action\\\=""
id="\\\"privado__pedidos-anular_pedido-7-link\\\""
position="\\\"replace\\\"">Anular</a> </td>\
\n <td>\\n <a href="%5C%5C%5C%22/privado/pedidos/
edit/7?_method=get%5C%5C%5C%22" class="\\\"edit" action\\\=""
id="\\\"privado__pedidos-edit-7-link\\\"" position="\\
\"replace\\\"">Edit</a> </td>\\n <td>\
\n <a href="%5C%5C%5C%22/privado/pedidos/destroy/7?
_method=delete%5C%5C%5C%22" class="\\\"destroy" action\\\="" id="\
\\"privado__pedidos-destroy-7-link\\\"" onclick='\\\"return'
confirm(\="" are="" you="" sure?\="" );\\\="">Delete</a> </td>\
\n </tr>\\n</tbody></table>\\n </td>\\n </tr>\\n\\n\\n\");
\nActiveScaffold.stripe(\'privado__pedidos-tbody\');'); throw e }
On 30 abr, 20:13, "Lance Ivy" <l...@cainlevy.net> wrote:
> Hmm, what's the actual RJS error? Also, what browser are you using?
>
> Also, you see how the bit you pasted in step #3 is split into two halves?
> The first half is the attempt at actually doing something, and the second
> half is the alert dialog in case something goes wrong. Well the double dash
> only exists in the second half; in the first it's normal.
>
> On 4/24/07, dimitris <jazzde...@gmail.com> wrote:
>
>
>
> > Hi Lance, thanks for your quick reply
>
> > I followed the instructions in
>
> >http://groups.google.com/group/activescaffold/browse_thread/thread/60...
> ...
>
> leer más »