Skip to content

Commit

Permalink
fixing the parent_id when creating a new taxon solidusio#569
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammed Gharbi committed Jan 27, 2016
1 parent 88f2f96 commit a35ac1a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,15 @@ handle_delete = (e) ->
delete_taxon({id: el.data('taxon-id')})
el.remove()

get_create_handler = (taxonomy_id) ->
get_create_handler = (parent_id) ->
handle_create = (e) ->
e.preventDefault()
name = 'New node'
parent_id = taxonomy_id
child_index = 0
create_taxon({name, parent_id, child_index})

@setup_taxonomy_tree = (taxonomy_id) ->
return unless taxonomy_id?
@setup_taxonomy_tree = (parent_id) ->
return unless parent_id?
taxons_template_text = $('#taxons-list-template').text()
taxons_template = Handlebars.compile(taxons_template_text)
Handlebars.registerPartial( 'taxons', taxons_template_text )
Expand All @@ -90,4 +89,4 @@ get_create_handler = (taxonomy_id) ->
sortupdate: (e, ui) ->
handle_move(ui.item) unless ui.sender?
.on('click', '.delete-taxon-button', handle_delete)
$('.add-taxon-button').on('click', get_create_handler(taxonomy_id))
$('.add-taxon-button').on('click', get_create_handler(parent_id))
4 changes: 2 additions & 2 deletions backend/app/views/spree/admin/taxonomies/_js_head.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<% content_for :head do %>
<%= javascript_tag "var taxonomy_id = #{@taxonomy.id};
<%= javascript_tag "var parent_id = #{@taxonomy.root.id};
var loading = '#{escape_javascript Spree.t(:loading)}';
var new_taxon = '#{escape_javascript Spree.t(:new_taxon)}';
var server_error = '#{escape_javascript Spree.t(:server_error)}';
var taxonomy_tree_error = '#{escape_javascript Spree.t(:taxonomy_tree_error)}';

$(document).ready(function(){
setup_taxonomy_tree(taxonomy_id);
setup_taxonomy_tree(parent_id);
});
"
%>
Expand Down

0 comments on commit a35ac1a

Please sign in to comment.