activescaffold / active_scaffold

Save time and headaches, and create a more easily maintainable set of pages, with ActiveScaffold. ActiveScaffold handles all your CRUD (create, read, update, delete) user interface needs, leaving you more time to focus on more challenging (and interesting!) problems.
MIT License
1.09k stars 327 forks source link

embeded and config.action_links.member.add #410

Open markmcdonald51 opened 9 years ago

markmcdonald51 commented 9 years ago

HI All,

I think I might have found a few bugs in AS. The first as to do with embeded sacffolds when they are called on a blank page by themselves.

so if I do something like in slim:

h3= "New #{@aasm_state}" = render active_scaffold: 'google_search_results', constraints: { :aasm_state => @aasm_state }

My param is passed but it doesn't make any rows. When I do the same page with a target of 'self' or blank it does work...hmmm. Not sure what the problems is.

This works but pops a new window: = link_to "View Details", pursuing_aasm_path('rejected'),{target: 'self'}

I wanted to make a single page that would display certain aasm_states...

The other potential problem is config.action_links.member.add

This seems to work fantastic as long as it is a nested scaffold. I want to use the pages above to do the same thing as what happens when it is in the nested scaffold but for some reason when it goes into a 'blank' page it drops the fields search_type, :aasm_state. Not sure why this is being dropped but it breaks the convention I am working on.

config.columns = [:entity, :phrase, :title, :content, :uri, :created_at, :search_type, :aasm_state]
config.actions = [:list, :search]   
config.action_links.member.add 'get_states', position: false  

Any help would be totally appreciated.

Thanks so much! Mark

scambra commented 9 years ago

For render active_scaffold:, you can try with conditions: or params: instead of constraints:

If you set constraints, column won't be displayed

markmcdonald51 commented 9 years ago

Hi Scambra,

Yeah that fixed the display. Thanks! What is strange is I have set up an action_links member that polls the object for current state transitions and will switch them if need be to a desired state. This works very well when it is nested but when I put it by itself as a embeded scaffold controller it seems to not do the javascript update --that is update the row. It does the update behind the scenes but just doesnt complete the front end update. Not sure what the problem is.

Thanks for the info scambra. You are a master at AS!

config.action_links.member.add 'get_states', position: false

scambra commented 9 years ago

Check if that action is sending eid (eid is the key to get conditions of embedded scaffold) and post here server response for that action

markmcdonald51 commented 9 years ago

New unseen

![screenshot from 2015-03-12 11 25 47](https://cloud.githubusercontent.com/assets/39400/6621056/b42f744e-c8aa-11e4-99de-4eb806415943.png) It is almost doing what it is suppost to do. It just aint updating the frontend. I looked in the firebug console and it looks like a js error: TypeError: action_link is undefined ...tiveScaffold.find_action_link(e.target);t.loading_indicator&&t.loading_indicator... applica...cf1d.js (line 28, col 21350) which is this line in active_scaffold.js if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','hidden');
scambra commented 9 years ago

it's weird because it's inside If (action_link) and it has been used in previous lines:

  if (action_link.position) {
    action_link.insert(response);
    if (action_link.hide_target) action_link.target.hide();
  } else {
    if (action_link.tag.hasClass('toggle')) {
      action_link.tag.closest('.action_group,.actions').find('.toggle.active').removeClass('active');
      action_link.tag.addClass('active');
    }
    action_link.enable();
  }
  jQuery(this).trigger('as:action_success', action_link);
  if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','hidden');

Do you have any listener for as:action_success? Please post server response from firebug

markmcdonald51 commented 9 years ago

Hi Scambra, This is what I am doing which is working beautifully as a nested scaffold in a different view. But when I try to make it an embedded scaffold on a separate page it doesnt seem to work. Strange too, if I dont spawn it in a new browser with a call to target=top then the embeded scaffold doesnt seem to work, however when it is in a new browser it works.... not sure about what is going on there either. Thank for the comment Scambra.

  def get_states
    @record = find_if_allowed(params[:id], :read)
  end

  def state_change
    #@record = find_if_allowed(params[:id], :update)   
    event_name = params[:event]

    # call the event on AASM (state_machine)
    event = "#{event_name}!".to_sym    

    # this will update the row in the database and the table.
    process_action_link_action do |record|
      if (record.send(event))
        puts "CALLED RECORD SEND" 
        flash[:info] = as_("Record Updated: #{record.title} to: #{event_name}".to_sym)
      else
        flash[:error] = as_(:error)
      end
    end       
  end
markmcdonald51 commented 9 years ago

The embed stuff not working seems really strange. It only works if I do a target = top like such:

= link_to "View Details", pursuing_aasm_path('pursuing'), {target: 'self'}

otherwise it doesnt display any rows unless I do a reload. The it displays them.

scambra commented 9 years ago

I don't follow you

What's not working? are reject, keep and pursue links working on normal scaffolds and failing on embedded ones? Or is displaying a embedded scaffold not working? Please don't mix issues

markmcdonald51 commented 9 years ago

I have a controller like: config.action_links.member.add 'get_states', position: false

which seems to work just fine for this ajax function when it is nested. It update the gui (as stated above) when called as an embeded scaffold it doesnt complete the javascript update. It does the model update fine and dandy though.

scambra commented 9 years ago

So, it's displaying submenu when it's nested, but not when embedded, right?

markmcdonald51 commented 9 years ago

That is right. Not sure why but it works great when it is a submenu for some reason. It doesnt update the html on the embed, but it does do the database update. So it is halfway working...

scambra commented 9 years ago

What database update? I don't see any update on get_states action