John Mettraux (thanks for a great OpenWFE and Densha) explained that
Densha can use another "form handler" via the field
"__workitem_partial". In
http://openwferu.rubyforge.org/svn/trunk/densha/app/helpers/workitem_hel
per.rb one finds:
TEMPLATE_PREFIX = "#{RAILS_ROOT}/app/views/workitem/_"
def find_partial (key, default)
t_name = @workitem.fields_hash[key]
return default unless t_name
t_name_view = t_name + "_view"
if @view_only and
File.exist?("#{TEMPLATE_PREFIX}#{t_name_view}.rhtml")
t_name_view
elsif File.exist?("#{TEMPLATE_PREFIX}#{t_name}.rhtml")
t_name
else
default
end
end
So, using
set :f => "__workitem_partial", :value => "my_activity"
will render /app/views/workitem/_my_activity.rhtml, if it is found.
For this to work, one needs to change the value of __workitem_partial
for each activity that needs its own form. So, if I understand correctly
then http://openwferu.rubyforge.org/examples/about_state.rb would then
read:
sequence do
set :f => "__workitem_partial", :value => "write"
alice :tag => "redaction"
set :f => "__workitem_partial", :value => "correct"
sequence :tag => "correction" do
bob
alice
end
set :f => "__workitem_partial", :value => "approve"
charly :tag => "approval"
end
So: is this indeed how "__workitem_partial" should be used?
Of course I know one can easily change Densha to specific needs. In my
little app I've changed find_partial to fall back to using the activity
name if __workitem_partial is not set:
def find_partial (key, default)
t_name = @workitem.fields_hash[key]
unless t_name
if key == '__workitem_partial'
t_activity = @workitem.fields_hash['params']['activity']
t_name = t_activity.downcase.gsub(/[^a-z0-9]/, '_')
end
end
return default unless t_name
[the rest as above]
end
Thanks for any thoughts on this!
Arjan.
Hello Arjan,
thanks for your feedback.
If I understood correctly, you are using the "activity" value as the
name of the custom form/partial. I think it's a great idea, way
simpler that using the "__workitem_partial" thing.
http://rubyforge.org/tracker/index.php?func=detail&aid=19684&group_id=2609&atid=10195
I will integrate your idea.
Sorry for not having integrated your :tag suggestion as well, but I
was on other things :
http://github.com/jmettraux/ruote/commits/master/
Have I understood you correctly ?
--
John Mettraux - http://jmettraux.wordpress.com
Yes, you understood well what I did (though it was merely a hack for me,
not being sure how to use the "__workitem_partial" thing without
repeating the same form name everywhere) :-)
By the way, if you're indeed implementing it: I kind of abuse the
activity name to get nice Fluo diagrams. So, to support activity names
such as "Read the Manual", I use the
t_activity.downcase.gsub(/[^a-z0-9]/, '_')
in my hack to get "read_the_manual" to find the partial. Any other
"translation" would be fine as well, of course. Like maybe only
replacing spaces and dashes with an underscore, and simply remove all
other odd characters.
> Sorry for not having ...
Huh? No way you need to say sorry for anything!
Thanks!
Arjan.
And for the archives:
> t_activity.downcase.gsub(/[^a-z0-9]/, '_')
... would need a check to ensure t_activity is not nil to start with ;-)
Arjan.
Hello Arjan,
it's in : http://github.com/jmettraux/ruote-web/commit/fa0ac581413be03710d79d56a14d721e10d9cf5b
It's not much tested though :(
Thanks a lot for this contribution,