Implemented POs

This commit is contained in:
Karl Cordes 2013-06-23 12:05:59 +10:00
parent 58da2bd273
commit 6549c00b49
3 changed files with 71 additions and 1 deletions

View file

@ -21,6 +21,27 @@
echo $form->input('PurchaseOrder.id');
echo $form->input('PurchaseOrder.principle_id');
echo $form->input('PurchaseOrder.principle_reference');
?>
<div id="job" class="hiddenDefault">
<?
echo $form->input('job', array('id'=>'job_autocomplete', array('label'=>'Job (start typing and select from the list)')));
?>
<span class="moreInfo">Jobs in this Shipment will be updated as "sent"</span>
<ul id="jobsList" class="habtmList">
<?php foreach($this->data['Job'] as $job):?>
<li id="JobID_<?=$job['id']?>">
<button class="removeFromList">X</button>
<?=$job['title'];?>
<input type="hidden" name="data[PurchaseOrder][Job][]" value="<?=$job['id']?>">
</li>
<?php endforeach?>
</ul>
</div>
<?php
echo $form->input('PurchaseOrder.currency_id');
echo $form->input('PurchaseOrder.dispatch_date');
echo $form->input('PurchaseOrder.date_arrived'); //ARGH. Really Karl?

View file

@ -15,7 +15,6 @@ echo $javascript->link('edit_product');
echo $form->input('description');
echo $form->input('notes');
echo $form->input('item_code');
echo $form->input('item_description');

View file

@ -9,6 +9,36 @@
$(function() {
/**
* A more generic way of handling the HABTM <ul> <li>[REMOVE BUTTON] NAME [HIDDEN INPUT]</li> </ul>
* Copypasta'd from add_edit_shipment.js.
*/
function addToList(modelName, id, value, ULelement) {
var thisLI = $('<li></li>');
var thisButton = $('<button>X</button>');
thisButton.addClass('removeFromList');
thisButton.button();
var thisHiddenInput = $('<input type="hidden">');
var modelString = '['+modelName+']';
thisHiddenInput.attr('name', 'data[PurchaseOrder]'+modelString+'[]');
thisHiddenInput.attr('value', id);
thisLI.attr('id', modelName+'ID_'+id);
thisLI.html(value);
thisLI.prepend(thisButton);
thisLI.append(thisHiddenInput);
ULelement.append(thisLI);
}
// var config defined in global.js
loadLineItems();
var docID = $('#documentID').html();
@ -433,6 +463,25 @@ $(function() {
setAddress(address, '#DocumentShipTo', 'Ship To');
});
//Fuck it. Copypaste. Autocompletion of jobs on PO document view
$( "#job_autocomplete" ).autocomplete({
source: "/jobs/autocomplete",
minLength: 2,
select: function( event, ui ) {
if($('#JobID_'+ui.item.id).length == 0) { //This Job is already in the List. Don't do anything.'
addToList('Job', ui.item.id, ui.item.value, $('#jobsList'));
}
}
});
});
@ -690,4 +739,5 @@ function checkNaN(value) {
}