webroot/js/job_grid.js

This commit is contained in:
Karl Cordes 2011-03-24 14:41:54 +11:00
parent 593f5ad97e
commit 3fa7e3351d
7 changed files with 238 additions and 532 deletions

View file

@ -187,9 +187,6 @@ class UsersController extends AppController {
} }
else {
$this->redirect('/');
}
} }

View file

@ -8,7 +8,6 @@ class User extends AppModel {
var $validate = array( var $validate = array(
'first_name' => array('notEmpty'), 'first_name' => array('notEmpty'),
'last_name' => array('notEmpty'),
'email' => array('email') 'email' => array('email')
); );

View file

@ -1,20 +1,38 @@
<?php <?php
echo $javascript->link('jquery.jeditable.mini'); //echo $javascript->link('jquery.jeditable.mini');
echo $javascript->link('jobindex_editinplace'); //echo $javascript->link('jobindex_editinplace');
echo $javascript->link('addjob'); //echo $javascript->link('addjob');
echo $javascript->link('job_index');
?> ?>
<h2><?php __('Jobs');?></h2> <h2><?php __('Jobs');?></h2>
<button id="SwitchToGrid">
Edit Jobs
</button>
<button id="SwitchToTable">
View Jobs
</button>
<p> <p>
<?php <?php
echo $paginator->counter(array( echo $paginator->counter(array(
'format' => __('Page %page% of %pages%, showing %current% Jobs out of %count% total, starting on record %start%, ending on %end%', true) 'format' => __('Page %page% of %pages%, showing %current% Jobs out of %count% total, starting on record %start%, ending on %end%', true)
)); ));
?></p> ?></p>
<div class="paging">
<?php echo $paginator->prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));?>
| <?php echo $paginator->numbers();?>
<?php echo $paginator->next(__('next', true).' >>', array(), null, array('class' => 'disabled'));?>
</div>
<div id="jobsIndex">
<table cellpadding="0" cellspacing="0" class="mer"> <table cellpadding="0" cellspacing="0" class="mer">
<tr> <tr>
@ -222,6 +240,9 @@ echo $javascript->link('addjob');
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
</table> </table>
</div>
<div class="paging"> <div class="paging">
<?php echo $paginator->prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));?> <?php echo $paginator->prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));?>
| <?php echo $paginator->numbers();?> | <?php echo $paginator->numbers();?>

View file

@ -22,7 +22,7 @@
echo $javascript->link('slickgrid/plugins/slick.cellrangeselector'); echo $javascript->link('slickgrid/plugins/slick.cellrangeselector');
echo $javascript->link('slickgrid/plugins/slick.cellrangedecorator'); echo $javascript->link('slickgrid/plugins/slick.cellrangedecorator');
echo $javascript->link('slickgrid/plugins/slick.cellselectionmodel'); echo $javascript->link('slickgrid/plugins/slick.cellselectionmodel');
echo $javascript->link('jobindex'); echo $javascript->link('job_grid');
echo $scripts_for_layout; ?> echo $scripts_for_layout; ?>
<style> <style>
.cell-title { .cell-title {

View file

@ -5,46 +5,51 @@ $(function() {
*/ */
var _loadingDiv = $("#ajaxLoading"); //var _loadingDiv = $("#ajaxLoading");
$('#submitUserButton').button(); $('#submitUserButton').button();
$('#UserAddUserForm').submit(function(){ $('#UserAddUserForm').submit(function(){
_loadingDiv.show();
$.post('/users/add_user', $('#submitUserButton').button('disable');
$(this).serializeArray(),
afterValidate, $.post("/users/add_user",
"json"
); $('#UserAddUserForm').serializeArray(),
function(data) {
var dataArray = $.parseJSON(data);
if (dataArray.errors) {
onError(dataArray.errors);
} else if (dataArray.success) {
onSuccess(dataArray.success);
}
});
return false; return false;
}); });
// Post-submit callback
function afterValidate(data, status) {
$(".message").remove();
$(".error-message").remove();
if (data.errors) {
onError(data.errors);
} else if (data.success) {
onSuccess(data.success);
}
}
function onSuccess(data) { function onSuccess(data) {
flashMessage(data.message);
_loadingDiv.hide();
$('#submitUserButton').button('disable');
$(".message").remove();
flashMessage(data.message);
//_loadingDiv.hide();
window.setTimeout(function() { window.setTimeout(function() {
// window.location.href = '/posts';
window.location.reload(true); window.location.reload(true);
}, 500); }, 2000);
}; };
function onError(data) { function onError(data) {
$('#submitUserButton').button('enable');
flashMessage(data.message); flashMessage(data.message);
$.each(data.data, function(model, errors) { $.each(data.data, function(model, errors) {
for (fieldName in this) { for (fieldName in this) {
@ -59,7 +64,7 @@ $(function() {
function flashMessage(message) { function flashMessage(message) {
var _insert = $(document.createElement('div')).css('display', 'none'); var _insert = $(document.createElement('div')).css('display', 'none');
_insert.attr('id', 'flashMessage').addClass('message').text(message); _insert.attr('id', 'flashMessage').addClass('message').text(message);
_insert.insertAfter($("#UserAddUserForm")).fadeIn(); _insert.insertAfter($('#UserAddUserForm')).fadeIn();
} }
function camelize(string) { function camelize(string) {
@ -70,7 +75,13 @@ $(function() {
} }
s = s.join(''); s = s.join('');
return s; return s;
} }
}); });

View file

@ -1,322 +0,0 @@
function requiredFieldValidator(value) {
if (value == null || value == undefined || !value.length)
return {
valid:false,
msg:"This is a required field"
};
else
return {
valid:true,
msg:null
};
}
var grid;
var data = [];
var columns = [
{
id:"id",
name:"ID",
field:"id",
width:50,
cssClass:""
},
{
id:"created",
name:"Date Created",
field:"created",
width: 100
},
{
id:"title",
name:"Job",
field:"title",
width:120
},
{
id:"customer",
name:"Customer",
field:"customer"
},
{
id:"customer_order_number",
name:"Customer Ref",
field:"customer_order_number",
width:120,
resizable:true,
editor:TextCellEditor
},
{
id:"supplier_reference",
name:"Supplier Ref",
field:"supplier_reference",
width:120,
resizable:true,
editor:TextCellEditor
},
{
id:"date_order_received",
name:"Order Received",
field:"date_order_received",
minWidth:60,
editor:DateCellEditor
},
{
id:"date_order_placed_on_principle",
name:"Date Order Placed on Principle",
field:"date_order_placed_on_principle",
minWidth:60,
editor:DateCellEditor
},
{
id:"date_scheduled_ex_works",
name:"Scheduled Ex Works",
field:"date_scheduled_ex_works",
minWidth:60,
editor:DateCellEditor
},
{
id:"date_order_sent_to_customer",
name:"Date Sent to Customer",
field:"date_order_sent_to_customer",
minWidth:60,
editor:DateCellEditor
},
{
id:"domestic_freight_paid_by",
name:"Dom Freight Paid By",
field:"domestic_freight_paid_by",
minWidth:60
},
{
id:"sale_category",
name:"Sale Category",
field:"sale_category",
minWidth:60
},
{
id:"shipment_category",
name:"Shipment Category",
field:"shipment_category",
minWidth:60
},
{
id:"domestic_freight_paid_by",
name:"Dom Freight Paid By",
field:"domestic_freight_paid_by",
minWidth:60
},
{
id:"comments",
name:"Comments",
field:"comments",
minWidth:60,
editor:LongTextCellEditor
},
{
id:"company_gross_sales_aud",
name:"Gross Sales AUD",
field:"company_gross_sales_aud",
minWidth:60,
editor:TextCellEditor
},
{
id:"net_sales_aud",
name:"Net Sales AUD",
field:"net_sales_aud",
minWidth:60,
editor:TextCellEditor
},
{
id:"gross_profit_aud",
name:"Gross Profit AUD",
field:"gross_profit_aud",
minWidth:60,
editor:TextCellEditor
},
{
id:"ato_exchange_rate",
name:"ATO Exchange Rate",
field:"ato_exchange_rate",
minWidth:60,
editor:TextCellEditor
},
{
id:"gst",
name:"GST",
field:"gst",
minWidth:60,
editor:TextCellEditor
},
{
id:"currency_id",
name:"Currency",
field:"currency_id",
minWidth:60,
editor:TextCellEditor
},
{
id:"gst_amount",
name:"GST Amount",
field:"gst_amount",
minWidth:60,
editor:TextCellEditor
},
{
id:"gross_commisions",
name:"Gross Commisions",
field:"gross_commisions",
minWidth:60,
editor:TextCellEditor
},
{
id:"invoiced_amount_inc_gst",
name:"invoiced amount inc gst",
field:"invoiced_amount_inc_gst",
minWidth:60,
editor:TextCellEditor
},
{
id:"net_export_sales_aud",
name:"Net Export Sales AUD",
field:"net_export_sales_aud",
minWidth:60,
editor:TextCellEditor
},
{
id:"gross_profit_exports_aud",
name:"Gross Profit Exports AUD",
field:"gross_profit_exports_aud",
minWidth:60,
editor:TextCellEditor
},
{
id:"gp_percent",
name:"GP %",
field:"gp_percent",
minWidth:60,
editor:TextCellEditor
},
{
id:"gross_australian_sales_foreign_currency",
name:"Gross Australian Sales Foreign Currency",
field:"gross_australian_sales_foreign_currency",
minWidth:60,
editor:TextCellEditor
},
{
id:"net_australian_sales_foreign_currency",
name:"Net Australian Sales Foreign Currency",
field:"net_australian_sales_foreign_currency",
minWidth:60,
editor:TextCellEditor
},
{
id:"gross_profit_value_australian_sales_foreign_currency",
name:"Gross Profit Value Aust Sales Foreign Currency",
field:"gross_profit_value_australian_sales_foreign_currency",
minWidth:60,
editor:TextCellEditor
},
{
id:"gross_export_sales_foreign_currency",
name:"Gross Export Sales Foreign Currency",
field:"gross_export_sales_foreign_currency",
minWidth:60,
editor:TextCellEditor
},
{
id:"net_export_sales_foreign_currency",
name:"Net Export Sales Foreign Currency",
field:"net_export_sales_foreign_currency",
minWidth:60,
editor:TextCellEditor
},
{
id:"gross_profit_value_after_discount_exports_foreign_currency",
name:"GP Amount After Discount Exports Foreign Currency",
field:"gross_profit_value_after_discount_exports_foreign_currency",
minWidth:60,
editor:TextCellEditor
},
{
id:"gross_commissions",
name:"Gross Commissions",
field:"gross_commissions",
minWidth:60,
editor:TextCellEditor
},
{
id:"net_commissions",
name:"Net Commissions",
field:"net_commissions",
minWidth:60,
editor:TextCellEditor
},
];
var options = {
editable: true,
enableAddRow: false,
enableCellNavigation: true,
asyncEditorLoading: false,
autoEdit: false
};
$(function()
{
data = $.parseJSON($("#jsonObj").html());
grid = new Slick.Grid("#myGrid", data, columns, options);
//grid.registerPlugin(new Slick.CellRangeSelector());
grid.setSelectionModel(new Slick.CellSelectionModel());
grid.onAddNewRow.subscribe(function(e, args) {
var item = args.item;
var column = args.column;
grid.invalidateRow(data.length);
data.push(item);
grid.updateRowCount();
grid.render();
});
});