implemented search for adding and editing line items.
This commit is contained in:
parent
44026e53d9
commit
dcf2501f6e
|
|
@ -176,7 +176,6 @@ class ProductsController extends AppController {
|
|||
}
|
||||
|
||||
App::import('Core', 'Sanitize');
|
||||
|
||||
$query = Sanitize::clean($query);
|
||||
|
||||
$products = $this->Product->find('list', array(
|
||||
|
|
@ -187,8 +186,6 @@ class ProductsController extends AppController {
|
|||
'order' => array('Product.title ASC')
|
||||
));
|
||||
|
||||
//Cakephp. You are awful. Past Karl was an idiot
|
||||
|
||||
$products_json = json_encode($products);
|
||||
|
||||
$this->set('products_json', $products_json);
|
||||
|
|
|
|||
|
|
@ -1 +1,6 @@
|
|||
<?=$form->input('product', array('label'=>'Product', 'id'=>'productSelect', 'empty'=>'Choose Products', 'options'=>$products));?>
|
||||
|
||||
<span class="products_json" style="display: none;"><?=json_encode($products); ?></span>
|
||||
|
||||
|
||||
<?=$form->input('product_search', array('label'=>'Search Product title', 'id'=>'productSearch'));?>
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
<? echo $form->input('Product.principle_id', array('id'=>'principleSelect', 'label'=>'Principle','empty'=>'Select Principle'));?>
|
||||
|
||||
|
||||
<?=$form->input('product_search', array('label'=>'Search Product title', 'id'=>'productSearch'));?>
|
||||
|
||||
<ul id="productList"></ul>
|
||||
|
||||
<div id="productsDiv"></div>
|
||||
<div id="productDetails"></div>
|
||||
<br><br>
|
||||
<div class="autocomplete">
|
||||
<span>OR search for product</span>
|
||||
<label for="productAutocomplete">Product title</label>
|
||||
<input id="productAutocomplete"/>
|
||||
|
||||
</div>
|
||||
|
||||
<div id="lineItemDetails">
|
||||
<?
|
||||
|
|
|
|||
|
|
@ -279,21 +279,56 @@ $(function() {
|
|||
});
|
||||
|
||||
|
||||
var products = {};
|
||||
$("#principleSelect").live('change',function() {
|
||||
|
||||
|
||||
var principleID = getSelectedID('#principleSelect');
|
||||
|
||||
$("#productDetails").hide();
|
||||
|
||||
$.get('/documents/getProducts/'+principleID, function(data) {
|
||||
$('#productsDiv').html(data);
|
||||
|
||||
var resp = $(data).filter(".products_json");
|
||||
products = jQuery.parseJSON(resp.html());
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
//ProductSearch
|
||||
$("#productSearch").live('change', function() {
|
||||
console.log("CHANGING");
|
||||
var searchVal = $("#productSearch").val();
|
||||
|
||||
|
||||
searchVal = searchVal.toLowerCase();
|
||||
var param = "term="+searchVal;
|
||||
|
||||
$.getJSON("/products/autocomplete", param, function(data) {
|
||||
|
||||
$("#productList").empty();
|
||||
|
||||
for(var id in data) {
|
||||
var link = "<li><a href=\"#\" class=\"search_product\" data-product-id=\""+id+"\">"+data[id]+"</a></li>";
|
||||
$("#productList").append(link);
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
$(".search_product").live('click', function() {
|
||||
var productID = $(this).data('product-id');
|
||||
getProductDetails(productID);
|
||||
});
|
||||
|
||||
$("#productSelect").live('change',function() {
|
||||
|
||||
var productID = getSelectedID('#productSelect');
|
||||
|
||||
getProductDetails(productID);
|
||||
|
||||
});
|
||||
|
|
@ -326,16 +361,22 @@ $(function() {
|
|||
}
|
||||
|
||||
//Autocomplete product title for adding lineItem
|
||||
|
||||
|
||||
|
||||
$( "#productAutocomplete" ).live('focus', function() {
|
||||
$(this).autocomplete({
|
||||
source: "/products/autocomplete",
|
||||
minLength: 2,
|
||||
select: function( event, ui ) {
|
||||
console.log(ui);
|
||||
}
|
||||
},
|
||||
appendTo: '#searchProducts'
|
||||
});
|
||||
});
|
||||
|
||||
$("#productAutocomplete").insertAfter();
|
||||
|
||||
// Initialize the editor.
|
||||
// Callback function can be passed and executed after full instance creation.
|
||||
$('.page').ckeditor(config);
|
||||
|
|
|
|||
Loading…
Reference in a new issue