Thanks for the thought and detail Bryan!  I'm going to give this more
thought....

Cheers,

Mike


----
Mike Karp
(m) 650.793.0695
(e) [email protected]


On Sun, Sep 16, 2012 at 10:13 PM, Bryan Larsen <[email protected]> wrote:

> Your solution is frustratingly close.  The problem is that both the
> input-many and the select-many both think they're "definitive".   In
> other words, they both think they comprise the entire list, and will
> try and delete items that aren't on their list.
>
> I just thought of a solution, though: virtual attributes.
>
> Create two methods on your person models:
>
> def new_companies_with_role
>   []
> end
>
> def new_companies_with_roles=(list)
>   list.each do |fields|
>      role_fields, company_fields = fields.partition_hash(:role)
>      company = Company.create!(company_fields)
>      roles.create!(:role => fields[:role], :company => company)
>   done
>   []
> end
>
> And create a class
>
> class CompanyWithRole
>   include ActiveModel::Validations
>   attr_accessor :name, :role
>
>   def initialize
>     # initialize with appropriate type
>     @name = "", @role=""
>   end
> end
>
> So then you can create two input-manys:   one on roles, and one on our
> virtual attribute new_companies_with_roles.
>
> Then you can do something like this:
>
> <field-list fields="..., roles, companies_with_roles">
>    <companies-with-roles-view:>
>       <input-many template="&CompanyWithRole.new" fields="name, role"/>
>     </companies-with-roles-view:>
> </field-list>
>
> Then the hard step: fixup Hobo so that this actually works.  It
> should, but there are a few places where Hobo assumes that we've got
> an ActiveRecord::Base rather than an ActiveModel.
>
> For instance, I hacked the permissions helper can_edit? by adding
>
>       return true unless object.respond_to?(:editable_by?)
>
> Obviously we'd be better off creating an ActiveModel style permissions
> mix in, but that will do for now.
>
> The next thing that errors is the translations helper.   I haven't
> fixed that up yet, it's getting late.   I don't know if that's the
> last error, but I wouldn't expect many more.
>
> If you want to go down this approach and get stuck, don't hesitate to
> email.    Replacing our ActiveRecord dependency with an ActiveModel
> dependency is something we want to do eventually anyways.
>
> cheers,
> Bryan
>
>
> On Sun, Sep 16, 2012 at 5:07 PM, Mike Karp <[email protected]> wrote:
> > Thanks Bryan - let me give that a go.
> >
> > I also had one other idea...see if this makes any sense to you.
> >
> > Make both the relationship table (i.e. roles) and the final entity (i.e.
> > companies) as accessible => true
> > Use a <select-many> on "roles" for existing companies (and modify the
> > select-many to have the role_type dropdown....will need to edit the
> > javascript so that the dropdown doesn't get picked up as the action to
> > create new rows
> > Use a <input-many> on "companies" for new companies....will have to
> modify
> > input-many to not show existing rows, only be there for new ones...
> >
> >
> > Do you think that's feasible?  Are those two modifications possible?  I
> was
> > having issues doing #2 above...although I saw that post in 2009 of
> someone
> > doing it by changing the class name of the object that triggers the
> > select-many new rows....
> >
> > Thanks!
> >
> > Mike
> >
> >
> > ----
> > Mike Karp
> > (m) 650.793.0695
> > (e) [email protected]
> >
> >
> > On Fri, Sep 14, 2012 at 3:03 PM, Bryan Larsen <[email protected]> wrote:
> >>
> >> On Fri, Sep 14, 2012 at 2:47 PM, Mike Karp <[email protected]> wrote:
> >> > It appears you cannot run a select-one-or-new-dialog for a phantom row
> >> > like
> >> > input-many creates...
> >> >
> >> > I am thinking about having the "+" sign on the hjq-input-many actually
> >> > commit the new row, so then I can run the dialog on it.  Just not sure
> >> > how
> >> > to do that yet.
> >> >
> >> > Any idea on how to make the "+"/"-"s commit and delete in realtime, so
> >> > then
> >> > I can use the dialog on it?
> >>
> >> That would be a lot of work.   You'd essentially have to rewrite the
> >> input-many tag, which is definitely the heaviest tag in Hobo.
> >>
> >> One hack that i used in a new app was to use after-submit with an
> >> additional submit button that sent the browser to the new page.
> >>
> >> Try something like this:
> >>
> >> <before-field-list:>
> >>     <after-submit uri="&persons_path"/>
> >> </before-field-list:>
> >> ...
> >> <company-view:>
> >>    <select-one/>
> >>    <submit label="Save Person and Create New Company"
> >> onclick="$('input[name=after_submit]').val('#{new_company_path}');
> >> return true;"/>
> >> </company-view:>
> >>
> >> And then have the new company form after-submit back.
> >>
> >> This won't work as well for you as it did for me because I was using a
> >> select-many, and the item being created was an owned item, so it got
> >> added to the list automatically on creation.
> >>
> >> Bryan
> >>
> >> --
> >> 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.
> >>
> >
> > --
> > 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.
>
> --
> 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.
>
>

-- 
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