Skip to content
This repository

admin/orders javascript needs to be updated for spree 1.0 #27

Closed
jsqu99 opened this Issue March 25, 2012 · 13 comments

4 participants

Jeff Squires Jeff Dutil Matthias Wagner Fabio Daguer Esposito
Jeff Squires
Owner

admin/orders/flexi_configuration.js wasn't properly propagated to the .70 & 1.0 versions. Currently working on plugging that in

Matthias Wagner

Got in trouble with admin js in fresh installed demostore (1.0.x and edge).
Tree at taxons configuration disappears and sorting isn't possible...
Removing admin/orders/flexi_configuration from my admin/all.js manifest solves this issues.

Maybe we should include this script at another position, it is loaded on every page at the moment or change the workflow....

@jsqu99 could you give me some information about your use of js in admin area?

Jeff Squires
Owner

This is the one open problem related to the upgrade ( i thought 0.70 worked though ).

From memory, i need custom js for creating orders from the admin/orders section (most likely for exclusisions).

It has been a while since I've looked at this so I'm foggy.

Unfortunatley my javascript isn't awesome enough to append to spree's javascript, so I need to keep it in synch w/ changes in spree. Feel free to help if you can :-)

Matthias Wagner

thanks to the comments I figured out the following (I paste the code here so we can see them all together at one page)

Original code from spee_flexi_variants that causes the issue:
(https://github.com/jsqu99/spree_flexi_variants/blob/master/app/assets/javascripts/admin/orders/flexi_configuration.js)

jQuery.fn.product_autocomplete = function(){
  $(this).autocomplete("/admin/products.json?authenticity_token=" + $('meta[name=csrf-token]').attr("content"), {
      parse: prep_autocomplete_data,
      formatItem: function(item) {
        return format_autocomplete(item);
      }
    }).result(function(event, data, formatted) {
      if (data){

        if(data['variant']==undefined){
          // product
          $('#add_variant_id').val(data['product']['master']['id']);
        }else{
          // variant
          $('#add_variant_id').val(data['variant']['id']);
        }

        // we might have some flexi-content to load for this product
        $.getScript('/admin/variant_configurations/' + $('#add_variant_id').val());
      } else {
        $('#configurations').hide();
      }
    });
}

was copied from sprees admin/admin.js from line 108 ...
(https://github.com/spree/spree/blob/0-70-stable/core/app/assets/javascripts/admin/admin.js.erb)

$.fn.product_autocomplete = function(){
  $(this).autocomplete("/admin/products.json?authenticity_token=" + encodeURIComponent($('meta[name=csrf-token]').attr("content")), {
      parse: prep_product_autocomplete_data,
      formatItem: function(item) {
        return format_product_autocomplete(item);
      }
    }).result(function(event, data, formatted) {
      if (data){
        if(data['variant']==undefined){
          // product
          $('#add_variant_id').val(data['product']['master']['id']);
        }else{
          // variant
          $('#add_variant_id').val(data['variant']['id']);
        }
      }
    });
}

Current code from admin/admin.js (edge) looks quite different:
(https://github.com/spree/spree/blob/1-1-stable/core/app/assets/javascripts/admin/admin.js.erb#L119)

$.fn.product_autocomplete = function(){
  return this.each(function() {
    $(this).autocomplete({
      source: function(request, response) {
        $.get("/admin/products.json?q=" + $('#add_product_name').val() + "&authenticity_token=" + encodeURIComponent($('meta[name=csrf-token]').attr("content")), function(data) {
          result = prep_product_autocomplete_data(data)
          response(result);
        });
      },
      minLength: 4,
      focus: function(event, ui) {
        $('#add_product_name').val(ui.item.label);
        return false;
      },
      select: function(event, ui) {
        $('#add_product_name').val(ui.item.label);
        product = ui.item.data;
        if (product['variant'] == undefined) {
          // product
          $('#add_variant_id').val(product['product']['master']['id']);
        } else {
          // variant
          $('#add_variant_id').val(product['variant']['id']);
        }
        return false;
      }
    }).data("autocomplete")._renderItem = function(ul, item) {
      $(ul).addClass('ac_results');
      html = format_product_autocomplete(item);
      return $("<li></li>")
              .data("item.autocomplete", item)
              .append("<a>" + html + "</a>")
              .appendTo(ul);
    }

    $(this).data("autocomplete")._resizeMenu = function() {
      var ul = this.menu.element;
      ul.outerWidth(this.element.outerWidth());
    }
  });
}

I think we have to decide if we adopt this javascript or find another solution, or maybe both.

Matthias Wagner

The script included doesn't exists?!
I think we get problems with assets pipeline because if I add this file to my app, it gets included in all.js?
Do we need this feature really?

Matthias Wagner

First step: file was not properly included in assets pipeline

#37

Todo: I don't know if it works like expected, but the issues on other admin pages disappeared in fresh spree 1.1.0
Not heavily tested at the moment

Fabio Daguer Esposito

I'm using spree 1.1.2 and adding products to a new order using admin doesn't work after using spree_flexi_variants. Is this relationed to this issue?

Jeff Squires
Owner

someone else reported this recently and I haven't had time to research. feel free to investigate and submit a pull request. thanks for reporting

Fabio Daguer Esposito

Ok, I'll probably have to work around something, because this is essential to the project.
thanks!

Jeff Dutil
Collaborator

@fabiode yes the inability to add products to an order in the admin is related to this issue as I've just run into it as well.

@jsqu99 will see what I can come up with for a solution here shortly.

Jeff Dutil
Collaborator

The issue with adding items to the order appears to be that the form is submitted twice. First with the variant id and then a second time without it which causes the error. I've been trying several different things such as adding preventDefault and stuff to stop the link from submitting but it still occurs anyway...

Jeff Squires
Owner

in times past i recall there was a version of spree that had jquery included twice and that was causing double submissions (not sure if relevant)

Jeff Dutil
Collaborator

Interesting think I've solved it... Appears to be that using .live for tracking the click event causes it. After updating some of the js to the latest versions within Spree it appears changing from .live to .on fixed it.

Jeff Dutil JDutil closed this May 14, 2013
Jeff Dutil
Collaborator
JDutil commented May 14, 2013

This was resolved by 8f9bcb4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.