Skip to content

Commit

Permalink
Added detail_foreign_key option to master_details to allow the attrib…
Browse files Browse the repository at this point in the history
…ute holding the master foreign key to be different to the attribute in the slave detail table holding the key to be matched.
  • Loading branch information
Dave Baldwin committed Dec 5, 2011
1 parent 741b461 commit b1360d3
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions lib/view.rb
Expand Up @@ -336,16 +336,14 @@ def inline_edit (url)
end
end

# The options hash key is now :master_details and the value for this key is either a hash (for a single detail)
# or an array of hashes (for multiple details). A detail hash has the following keys
# :grid_id the id of the grid to use to display the detail view
# :foreign_key_column the column in the master table holding the foreign key
# :caption caption string


# Problems still to fix:
# Display of error validation error messages
def master_details
# The options hash key is now :master_details and the value for this key is either a hash (for a single detail)
# or an array of hashes (for multiple details). A detail hash has the following keys
# :grid_id the id of the grid to use to display the detail view
# :caption caption string
# :foreign_key_column the column in the master table holding the foreign key
# :detail_foreign_key the attribute in the detail table to match the master foreign key against (can be omitted if the same)

def master_details
if details = @grid_options.delete(:master_details)
details = [details] if details.kind_of? Hash
details.each do |detail|
Expand All @@ -357,7 +355,7 @@ def master_details
function(ids) {
#{detail[:grid_id]}_foreign_id_attribute = '#{detail[:foreign_key_column]}'
#{detail[:grid_id]}_foreign_id = jQuery('##{@id}').getRowData (ids)['#{detail[:foreign_key_column]}']
jQuery("##{detail[:grid_id]}").setGridParam({postData: {foreign_id_attribute: '#{detail[:foreign_key_column]}', foreign_id: #{detail[:grid_id]}_foreign_id}})
jQuery("##{detail[:grid_id]}").setGridParam({postData: {foreign_id_attribute: '#{detail[:detail_foreign_key] || detail[:foreign_key_column]}', foreign_id: #{detail[:grid_id]}_foreign_id}})
.setCaption("#{detail[:caption]} : "+ #{detail[:grid_id]}_foreign_id)
.trigger('reloadGrid');
}^
Expand Down

0 comments on commit b1360d3

Please sign in to comment.