Sha256: c733e4857ca2fc00dcdd0f9b95defa6573adc306b5fb1e54f554325d9cc214bd

Contents?: true

Size: 1.85 KB

Versions: 5

Compression:

Stored size: 1.85 KB

Contents

// Source for remote product search by name
function acSource(request, response) {
  $.ajax({
    type: "POST",
    url: "/remote_products/search",
    data: "term=" + request.term,
    success: function(data) {
      var parsed = JSON.parse(data);
      response(parsed);
    }
  });
}

// All search-remote-ajax inputs should autocomplete from remote product search
function installAutocompletion(jQuery) {
  $("input.search-remote-ajax").each( function() {
    field = $(this);
    field.autocomplete({
      source: acSource,
      minLength: 2,
      open: function() {
        $(this).removeClass("ui-corner-all").addClass("ui-corner-top");
      },
      close: function() {
        $(this).removeClass("ui-corner-top").addClass("ui-corner-all");
      },
      select: function(event, ui) {
        $(this).val(ui.item.name);
        $(this).parent().children("input.remote_product_id").val(ui.item.product_id);
        return false;
      },
    }).autocomplete("instance")._renderItem = function(ul, item) {
     return $("<li>").append(item.name).appendTo(ul);
    };
  });
}

// Links in link widget should link
function installAjaxLinkAction(jQuery) {
  $(".ajax_product_link").click(function(e){
    local_product_id = $(this).parent().parent().parent().children("input.local_product_id").val();
    input = $(this).parent().children("input.remote_product_id");

    remote_product_id = input.val();
    $.ajax({
      type: "POST",
      url: "/product/" + local_product_id + "/link",
      data: "remote_product_id=" + remote_product_id,
      success: function(data) {
        input.parent().parent().html(data);
      },
      error: function(data) {
        console.log(data);
        input.parent().parent().html("!" + data);
      }
    });

    e.preventDefault();
    return false;
  });
}

$(document).ready(installAutocompletion);
$(document).ready(installAjaxLinkAction);

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rawbotz-0.2.0 lib/rawbotz/public/rawbotz_ajax_product_link.js
rawbotz-0.1.5 lib/rawbotz/public/rawbotz_ajax_product_link.js
rawbotz-0.1.4 lib/rawbotz/public/rawbotz_ajax_product_link.js
rawbotz-0.1.3 lib/rawbotz/public/rawbotz_ajax_product_link.js
rawbotz-0.1.2 lib/rawbotz/public/rawbotz_ajax_product_link.js