Re: [Radiant] Customizing the user admin UI at the column level

2010-08-13 Thread Wes Gamble

 On 8/13/10 3:05 AM, William Ross wrote:

On 13 Aug 2010, at 05:01, Wes Gamble wrote:


On 8/12/10 6:47 PM, William Ross wrote:

On 13 Aug 2010, at 00:35, Wes Gamble wrote:


After looking into it, though, I see the admin/users/edit and 
admin/users/index views under the Radiant core are more or less 
hard-coded at the column level, but the error messages imply that I 
should be able to add a partial somewhere for my custom fields.


Questions:

What is the preferred way to customize at this level?


You're on the right lines, though I would normally use this kind of 
idiom to get more control:


admin.users.edit.add
:form, edit_program, :after = something
and
then you need to create the partial, which in this case would
be
vendor/extensions/your_extension/app/views/admin/users/_edit_program.html.haml

I did this, and created a file in the correct place, and entered the 
following in my activate method:


  admin.users.edit.add :form, edit_program, :after = edit_roles

My partial looks like this:

- form.edit_program do
  %p
= f.label :program_id, t('program'), :class = optional
= f.select :program_id, Program.all.collect {|p| [p.name, p.id]}

and I get the classic

 |wrong number of arguments (0 for 1)|

message when I try to render the form.  This is because, AFAIK, the 
partial hasn't been passed the form variable as a local.



No, you're right, and I've never found the right answer for that. The 
only way I know to use FormBuilder methods is to wrap a fields_for 
around the partial:


- fields_for :user, @user do |ff|
= ff.label :program_id, t('program'), :class = optional
= ff.select :program_id, Program.all.collect {|p| [p.name, p.id]}

which isn't very helpful when you're trying to reuse a bit of form, 
but it does work.
And then of course, there's no way (using this method) to handle inserts 
into the index page, a la


/Insert into column headers in index view
- thead.program_header do
  %th.program= t('program')

/Insert into column cells in index view
- tbody.program_cell do
  %td.program= user.program

Fair?

Wes


Re: [Radiant] Customizing the user admin UI at the column level

2010-08-12 Thread William Ross
On 13 Aug 2010, at 00:35, Wes Gamble wrote:

 I have reviewed the contents of 
 http://wiki.github.com/radiant/radiant/modifying-the-page-ui in depth.
 
 I have extension that modifies the user model to be attached to something 
 called a program, and I've made the change in the DB, and modified the user 
 model in my extension code like so:
 
 User  class User  ActiveRecord::Base
   belongs_to :program
 end
 
 so that the association will be there.
 
 Now, I would like to be able to display and edit program assignments for a 
 given user in the admin. UI.
 
 In my extension's activate method, I added the following lines in the hopes 
 of customizing the UI:
 
 admin.user.edit.form  'edit_program'
 admin.user.index.thead  'program_header'
 admin.user.index.tbody  'program_cell'
 
 thinking that the display of the user admin was super dynamic and it would 
 just figure out how to display the edit components based on attribute type.
 
 But when I try to look at the index view of users, I get:
 
 `program_header' default partial not found! `program_cell' default partial 
 not found! as errors in the index display.
 
 and 
 
 `edit_program' default partial not found! as an error in the edit display.
 
 After looking into it, though, I see the admin/users/edit and 
 admin/users/index views under the Radiant core are more or less hard-coded at 
 the column level, but the error messages imply that I should be able to add a 
 partial somewhere for my custom fields.
 
 Questions:
 
 What is the preferred way to customize at this level?  

You're on the right lines, though I would normally use this kind of idiom to 
get more control:

admin.users.edit.add :form, edit_program, :after = something
 
and then you need to create the partial, which in this case would be


vendor/extensions/your_extension/app/views/admin/users/_edit_program.html.haml

If you want it to live somewhere else - eg. to share a form component between 
several models - then you can specify the full path to the partial in the usual 
way:

admin.users.edit.add :form, admin/programs/edit_program, :after = 
something

 Do I need to just override the entire edit and index views?

Much better to avoid that: working through the UI you are relatively safe from 
interface changes and able to co-operate with other extensions.

 Is there some Javascript-y way to do this that I'm missing?

Nope.

best,

will

Re: [Radiant] Customizing the user admin UI at the column level

2010-08-12 Thread Wes Gamble

 On 8/12/10 6:47 PM, William Ross wrote:

On 13 Aug 2010, at 00:35, Wes Gamble wrote:

I have reviewed the contents of 
http://wiki.github.com/radiant/radiant/modifying-the-page-ui in depth.


I have extension that modifies the user model to be attached to 
something called a program, and I've made the change in the DB, and 
modified the user model in my extension code like so:


User  class User  ActiveRecord::Base
  belongs_to :program
end

so that the association will be there.

Now, I would like to be able to display and edit program assignments 
for a given user in the admin. UI.


In my extension's activate method, I added the following lines in 
the hopes of customizing the UI:


admin.user.edit.form  'edit_program'
admin.user.index.thead  'program_header'
admin.user.index.tbody  'program_cell'

thinking that the display of the user admin was super dynamic and it 
would just figure out how to display the edit components based on 
attribute type.


But when I try to look at the index view of users, I get:

`program_header' default partial not found! `program_cell' default 
partial not found! as errors in the index display.


and

`edit_program' default partial not found! as an error in the edit 
display.

**
After looking into it, though, I see the admin/users/edit and 
admin/users/index views under the Radiant core are more or less 
hard-coded at the column level, but the error messages imply that I 
should be able to add a partial somewhere for my custom fields.


Questions:

What is the preferred way to customize at this level?


You're on the right lines, though I would normally use this kind of 
idiom to get more control:


admin.users.edit.add :form, edit_program, :after = something
and then you need to create the partial, which in this case would be
vendor/extensions/your_extension/app/views/admin/users/_edit_program.html.haml


I did this, and created a file in the correct place, and entered the 
following in my activate method:


  admin.users.edit.add :form, edit_program, :after = edit_roles

My partial looks like this:

- form.edit_program do
  %p
= f.label :program_id, t('program'), :class = optional
= f.select :program_id, Program.all.collect {|p| [p.name, p.id]}

and I get the classic

 |wrong number of arguments (0 for 1)|

message when I try to render the form.  This is because, AFAIK, the 
partial hasn't been passed the form variable as a local.


How does the partial get rendered in the context of the existing form?

Thanks,
Wes