Densha: is there consensus about using custom task forms?

2 views
Skip to first unread message

Arjan van Bentem

unread,
Apr 21, 2008, 3:34:28 AM4/21/08
to openwfe...@googlegroups.com

First of all: I'm new to both Ruby, Rails and OpenWFE, so forgive if I'm
asking the obvious... Also excuse me for being a bit verbose here -- can
you tell I'm a bit insecure? ;-)

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.

John Mettraux

unread,
Apr 21, 2008, 10:38:35 AM4/21/08
to openwfe...@googlegroups.com
On Mon, Apr 21, 2008 at 4:34 PM, Arjan van Bentem
<Arjan.v...@bidnetwork.org> wrote:
>
>
> First of all: I'm new to both Ruby, Rails and OpenWFE, so forgive if I'm
> asking the obvious... Also excuse me for being a bit verbose here -- can
> you tell I'm a bit insecure? ;-)

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

Arjan van Bentem

unread,
Apr 21, 2008, 11:47:49 AM4/21/08
to openwfe...@googlegroups.com

> If I understood correctly, you are using the "activity" value as the
> name of the custom form/partial.

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.

Arjan van Bentem

unread,
Apr 23, 2008, 3:26:41 PM4/23/08
to openwfe...@googlegroups.com

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.

John Mettraux

unread,
Apr 24, 2008, 6:36:44 AM4/24/08
to openwfe...@googlegroups.com

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,

Reply all
Reply to author
Forward
0 new messages