Hi all,
In my workflow application, based on ruote-web, I not only need to update workflow fields, but also some external data (which outlives the process when it is completed or canceled). Does anyone have some specific thoughts on that? The following works allright for me: Densha / ruote-web allows for using custom forms, by either setting __workitem_partial or by having a file /view/workitem/ _my_activity.rhtml based on the value of :activity in the workflow. That works great; see also http://groups.google.com/group/openwferu-users/browse_thread/thread/b65de46a8f46560e Trying to make things a bit generic, I've now extended ruote-web's WorkItemController to search for some specific variables or fields defining my external data. For example, MyClass could simply be derived from ActiveRecord, and in the database has columns "my_id" and "my_field_a" through "my_field_c". In my process definition: set :v => "external_data_class", :value => "MyClass" set :v => "external_data_finder", :value => "find_by_my_id" set :f => "external_data_id", :value => "(set after starting the process)" In my custom view simply using HTML form fields: <% form_tag "/workitem/update/[EMAIL PROTECTED]" %> <% fields_for :external_data, @workitem.external_data do |f| %> a: <%= f.text_field :my_field_a %> b: <%= f.text_field :my_field_b %> c: <%= f.text_field :my_field_c %> <% end %> : : <% end %> In WorkItemController I added a method "external_data" to OpenWFE::Extras::WorkItem, and persist incoming form fields: # Opening up OpenWFE::Extras::WorkItem (see vendor/openwfe/extras/ activeparticipants.rb) # to access external data, based on process variables or fields. module OpenWFE module Extras class Workitem # Gets the object holding any non-workflow data, if defined using variables or # fields, like: # set :v => "external_data_class", :value => "MyClass" # set :v => "external_data_finder", :value => "find_by_my_id" # set :v => "external_data_id", :value => "123" # or # set :f => "external_data_id", :value => "123" # # When your class exends ActiveRecord, then it will have dynamic attribute-based # finders; see http://api.rubyonrails.com/classes/ActiveRecord/Base.html # def external_data # Some caching, just in case @workitem.external_data is used multiple times # in the same view return @_external_data if @_external_data external_data_id = get_field_or_var('external_data_id') return nil unless external_data_id && external_data_id.strip ! = "" external_data_class = get_field_or_var('external_data_class') external_data_finder = get_field_or_var('external_data_finder') begin # All the built-in classes, along with the classes you define, have a # corresponding global constant with the same name as the class. Or, using # plain Ruby: c = Kernel.const_get(external_data_class) c = external_data_class.constantize @_external_data = c.send(external_data_finder, external_data_id) return @_external_data if @_external_data rescue => e # Of course, the process definition should be correct, but let's avoid # running into "const_missing': uninitialized constant" anyhow: RAILS_DEFAULT_LOGGER.error("#{e.class}: #{e.message}") end RAILS_DEFAULT_LOGGER.error("External data not found; " + "#{external_data_class}.#{external_data_finder} (#{external_data_id})") return nil end protected # Gets the value for the given workitem field, or the process variable if the # field is not set. def get_field_or_var(key) value = fields_hash[key] unless value value = $openwferu_engine.lookup_variable(key, full_fei.wfid) end value end end end end # OpenWFE::Extras::WorkItem : : class WorkitemController < ApplicationController : def update : return error_wi_not_owner(action) \ unless Densha::Locks.owns_lock?(user, workitem.id) # AVBENTEM START # See if there's a specific class for storage of some user input # like <input name="external_data[my_field_a]" ..> external_data_params = params[:external_data] if external_data_params # As defined in the extended OpenWFE::Extras::WorkItem above o = workitem.external_data external_data_params.each do |k, v| o.send("#{k}=".intern, v.strip) end o.save! end # AVBENTEM END json = params[:hash_form_json] : end : end Thanks for any feedback! Arjan. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "OpenWFEru 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/openwferu-users?hl=en -~----------~----~----~----~------~----~------~--~---
