Merge branch 'add_jquery_sortable'
[order_line_extra.git] / item_schedule.php
index 6a7614f78086963a7b8d3ddaf6880d578c87fcfb..36b10b935b86acbb09900d50a25db7d9dfa1f999 100644 (file)
@@ -1,4 +1,3 @@
-
 <?php
 /**********************************************************************
     Copyright (C) FrontAccounting, LLC.
@@ -18,7 +17,8 @@ include_once($path_to_root . "/includes/ui/ui_globals.inc");
 include_once($path_to_root . "/includes/ui/ui_input.inc");
 include_once($path_to_root . "/reporting/includes/reporting.inc");
 
-//include_once("includes/item_schedule.inc");
+//include_once("includes/item_scheduler.inc");
+include_once("hincludes/lib/php/Boot.class.php");
 
 $page_security = 'SA_ORDERLINEX_EDIT';
 add_access_extensions();
@@ -31,31 +31,130 @@ page($_SESSION['page_title'], false, false, "", $js);
 
 //---------------------------------------------------------------------------------------------
 
+div_start('item_schedule');
 start_form();
 
 start_table(TABLESTYLE_NOBORDER);
 start_row();
 
+echo date('h:i:s <br>',time());
+?>GET<?php
+print_r($_GET);
+?>POST<?php
+print_r($_POST);
+
+if (!isset($_POST['stock_id'])) {
 if (isset($_GET['stock_id']))
 {
        $_POST['stock_id'] = $_GET['stock_id'];
 }
+else {
+       $_POST['stock_id'] = get_global_stock_item();
+       }
+}
 
-if (!@$_GET['popup'])
+if (list_updated('stock_id') || in_ajax()) $Ajax->activate('item_schedule');
+
+//if (!@$_GET['popup'])
        start_form();
 
-if (!isset($_POST['stock_id']))
-       $_POST['stock_id'] = get_global_stock_item();
 
-       stock_costable_items_list_cells(_("Item:"), 'stock_id', $_POST['stock_id']);
+$stock_id = $_POST['stock_id'];
+       stock_costable_items_list_cells(_("Item:"), 'stock_id', $stock_id);
 
-end_row();
 
+end_row();
 end_table(1);
 
-submit_center_first('Update', _("Update"), true, '', 'default', true);
-submit_center_last('Cancel', _("Cancel"), true, '', 'cancel', true);
+$scheduler = new ItemScheduler($stock_id, 'DEF');
+
+start_table(TABLESTYLE);
+$th = $scheduler->tableHeader();
+
+table_header($th);
+
+$scheduler->generateTable();
+
+end_table();
+
+
+submit_center_first('Update', _("Update"), '', 'default', false);
+submit_center_last('Cancel', _("Cancel"), '', 'cancel', false);
+
 
-       end_form();
-       end_page();
+
+end_form();
+div_end();
+end_page();
 ?>
+<style type='text/css'>
+tr.partial {
+       color: darkred;
+}
+
+tr.partial  td:nth-child(5) {
+       background: pink;
+}
+
+tr.location {
+       font-weight: normal;
+               background: #8f8;
+}
+tr.on_time {
+}
+
+tr.late {
+               background: #fc8;
+}
+
+tr.soldout {
+               background: pink;
+}
+
+tr.tDnD_whileDrag {
+       background: #ccc;
+       border: 2px solid black;
+}
+tr.tDnD_whileDrag :nth-child(4), tr.tDnD_whileDrag :nth-child(5) {
+       color: transparent;
+       background: transparent;
+}
+</style>
+<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
+<script src="js/jquery.tablednd.0.8.min.js"></script>
+<script text="text/javascript">
+       console.log('hello')
+       /**  add table DnD as behavior **/
+       function onDragStart (table, row) {
+       console.log(table)
+               console.log(row)
+       }
+       function findRowPosition(table, row) {
+       }
+       function addInput(form, name, value) {
+               $(form).append('<input type="hidden" name="'+name+'" value="'+value+'">')
+                       }
+       function addInputs(form, name, values) {
+               for(index = 0; index < values.length; index++) {
+                               addInput(form, name+'['+index+']', values[index])
+                               }
+                       }
+       function onDrop(table, row) {
+               var row_ids = $.map(table.tBodies[0].rows, function(r) { return r.id} )
+               var row_id = row.id
+               var form = $(table).closest('form')[0]
+               
+               addInput(form, 'row_id', row.id)
+               addInputs(form, 'row_order', row_ids )
+               
+               JsHttpRequest.request(this, form);
+               
+       }
+
+       var inserts = {
+               '#item_schedule table': function (e) { 
+                       $(e).tableDnD({onDragStart: onDragStart, onDrop: onDrop})
+               }
+       }
+Behaviour.register(inserts);
+</script>