Use Behavior to make table draggable on Ajax refresh
[order_line_extra.git] / item_schedule.php
index 04c7b4bcb49697faf2c9fdd1658d76a0e61fe74e..e5115b12014ff883f6d0b74a2e678cbea11ad973 100644 (file)
@@ -36,16 +36,26 @@ start_form();
 start_table(TABLESTYLE_NOBORDER);
 start_row();
 
+?>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 (list_updated('stock_id')) 
+       $Ajax->activate('item_schedule');
 
 //if (!@$_GET['popup'])
        start_form();
 
-if (!isset($_POST['stock_id']))
-       $_POST['stock_id'] = get_global_stock_item();
 
 $stock_id = $_POST['stock_id'];
        stock_costable_items_list_cells(_("Item:"), 'stock_id', $stock_id);
@@ -112,16 +122,22 @@ tr.tDnD_whileDrag :nth-child(4), tr.tDnD_whileDrag :nth-child(5) {
 <script src="js/jquery.tablednd.0.8.min.js"></script>
 <script text="text/javascript">
        console.log('hello')
-       $(document).ready(function() {
-               console.log('ready')
-               $('#item_schedule table').tableDnD({
-                       onDragStart: function (table, row) {
-                                       console.log(table)
-                                       console.log(row)}
-                       ,onDrop: function (table, row) {
-                                       console.log(table)
-                                       console.log(row)}
-               })
+       /**  add table DnD as behavior **/
+       function onDragStart (table, row) {
+       console.log(table)
+               console.log(row)
+       }
+       function onDrop(table, row) {
+                       console.log(table)
+                       console.log(row)
+       }
+
+       var inserts = {
+               '#item_schedule table': function (e) { 
+                       // We can't use e directly because we need a JQUery Object to call tableDnD
+
+                       $('#item_schedule table').tableDnD({onDragStart: onDragStart, onDrop: onDrop})
+               }
        }
-       )
+Behaviour.register(inserts);
 </script>