onDrop send data to backend.
[order_line_extra.git] / item_schedule.php
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL, 
5         as published by the Free Software Foundation, either version 3 
6         of the License, or (at your option) any later version.
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
10     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 $path_to_root = "../..";
13
14 include_once($path_to_root . "/includes/session.inc");
15 include_once($path_to_root . "/includes/ui/ui_lists.inc");
16 include_once($path_to_root . "/includes/ui/ui_globals.inc");
17 include_once($path_to_root . "/includes/ui/ui_input.inc");
18 include_once($path_to_root . "/reporting/includes/reporting.inc");
19
20 //include_once("includes/item_scheduler.inc");
21 include_once("hincludes/lib/php/Boot.class.php");
22
23 $page_security = 'SA_ORDERLINEX_EDIT';
24 add_access_extensions();
25
26 $_SESSION['page_title'] = _($help_context = "Item schedule");
27
28
29 $js = "";
30 page($_SESSION['page_title'], false, false, "", $js);
31
32 //---------------------------------------------------------------------------------------------
33
34 div_start('item_schedule');
35 start_form();
36
37 start_table(TABLESTYLE_NOBORDER);
38 start_row();
39
40 echo date('h:i:s <br>',time());
41 ?>GET<?php
42 print_r($_GET);
43 ?>POST<?php
44 print_r($_POST);
45
46 if (!isset($_POST['stock_id'])) {
47 if (isset($_GET['stock_id']))
48 {
49         $_POST['stock_id'] = $_GET['stock_id'];
50 }
51 else {
52         $_POST['stock_id'] = get_global_stock_item();
53         }
54 }
55
56 if (list_updated('stock_id')) 
57         $Ajax->activate('item_schedule');
58 if (in_ajax())
59         $Ajax->activate('item_schedule');
60
61 //if (!@$_GET['popup'])
62         start_form();
63
64
65 $stock_id = $_POST['stock_id'];
66         stock_costable_items_list_cells(_("Item:"), 'stock_id', $stock_id);
67
68 end_row();
69 end_table(1);
70
71 $scheduler = new ItemScheduler($stock_id, 'DEF');
72
73 start_table(TABLESTYLE);
74 $th = $scheduler->tableHeader();
75
76 table_header($th);
77
78 $scheduler->generateTable();
79
80 end_table();
81
82
83 submit_center_first('Update', _("Update"), '', 'default', false);
84 submit_center_last('Cancel', _("Cancel"), '', 'cancel', false);
85
86
87
88 end_form();
89 div_end();
90 end_page();
91 ?>
92 <style type='text/css'>
93 tr.partial {
94         color: darkred;
95 }
96
97 tr.partial  td:nth-child(5) {
98         background: pink;
99 }
100
101 tr.location {
102         font-weight: normal;
103                 background: #8f8;
104 }
105 tr.on_time {
106 }
107
108 tr.late {
109                 background: #fc8;
110 }
111
112 tr.soldout {
113                 background: pink;
114 }
115
116 tr.tDnD_whileDrag {
117         background: #ccc;
118         border: 2px solid black;
119 }
120 tr.tDnD_whileDrag :nth-child(4), tr.tDnD_whileDrag :nth-child(5) {
121         color: transparent;
122         background: transparent;
123 }
124 </style>
125 <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
126 <script src="js/jquery.tablednd.0.8.min.js"></script>
127 <script text="text/javascript">
128         console.log('hello')
129         /**  add table DnD as behavior **/
130         function onDragStart (table, row) {
131         console.log(table)
132                 console.log(row)
133         }
134         function findRowPosition(table, row) {
135         }
136         function addInput(form, name, value) {
137                 $(form).append('<input type="hidden" name="'+name+'" value="'+value+'">')
138                         }
139         function addInputs(form, name, values) {
140                 for(index = 0; index < values.length; index++) {
141                                 addInput(form, name+'['+index+']', values[index])
142                                 }
143                         }
144         function onDrop(table, row) {
145                 var row_ids = $.map(table.tBodies[0].rows, function(r) { return r.id} )
146                 var row_id = row.id
147                 var form = $(table).closest('form')[0]
148                 
149                 addInput(form, 'row_id', row.id)
150                 addInputs(form, 'row_order', row_ids )
151                 
152                 JsHttpRequest.request(this, form);
153                 
154         }
155
156         var inserts = {
157                 '#item_schedule table': function (e) { 
158                         $(e).tableDnD({onDragStart: onDragStart, onDrop: onDrop})
159                 }
160         }
161 Behaviour.register(inserts);
162 </script>