simplify Ajax activation test.
[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') || in_ajax()) $Ajax->activate('item_schedule');
57
58 //if (!@$_GET['popup'])
59         start_form();
60
61
62 $stock_id = $_POST['stock_id'];
63         stock_costable_items_list_cells(_("Item:"), 'stock_id', $stock_id);
64
65
66 end_row();
67 end_table(1);
68
69 $scheduler = new ItemScheduler($stock_id, 'DEF');
70
71 start_table(TABLESTYLE);
72 $th = $scheduler->tableHeader();
73
74 table_header($th);
75
76 $scheduler->generateTable();
77
78 end_table();
79
80
81 submit_center_first('Update', _("Update"), '', 'default', false);
82 submit_center_last('Cancel', _("Cancel"), '', 'cancel', false);
83
84
85
86 end_form();
87 div_end();
88 end_page();
89 ?>
90 <style type='text/css'>
91 tr.partial {
92         color: darkred;
93 }
94
95 tr.partial  td:nth-child(5) {
96         background: pink;
97 }
98
99 tr.location {
100         font-weight: normal;
101                 background: #8f8;
102 }
103 tr.on_time {
104 }
105
106 tr.late {
107                 background: #fc8;
108 }
109
110 tr.soldout {
111                 background: pink;
112 }
113
114 tr.tDnD_whileDrag {
115         background: #ccc;
116         border: 2px solid black;
117 }
118 tr.tDnD_whileDrag :nth-child(4), tr.tDnD_whileDrag :nth-child(5) {
119         color: transparent;
120         background: transparent;
121 }
122 </style>
123 <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
124 <script src="js/jquery.tablednd.0.8.min.js"></script>
125 <script text="text/javascript">
126         console.log('hello')
127         /**  add table DnD as behavior **/
128         function onDragStart (table, row) {
129         console.log(table)
130                 console.log(row)
131         }
132         function findRowPosition(table, row) {
133         }
134         function addInput(form, name, value) {
135                 $(form).append('<input type="hidden" name="'+name+'" value="'+value+'">')
136                         }
137         function addInputs(form, name, values) {
138                 for(index = 0; index < values.length; index++) {
139                                 addInput(form, name+'['+index+']', values[index])
140                                 }
141                         }
142         function onDrop(table, row) {
143                 var row_ids = $.map(table.tBodies[0].rows, function(r) { return r.id} )
144                 var row_id = row.id
145                 var form = $(table).closest('form')[0]
146                 
147                 addInput(form, 'row_id', row.id)
148                 addInputs(form, 'row_order', row_ids )
149                 
150                 JsHttpRequest.request(this, form);
151                 
152         }
153
154         var inserts = {
155                 '#item_schedule table': function (e) { 
156                         $(e).tableDnD({onDragStart: onDragStart, onDrop: onDrop})
157                 }
158         }
159 Behaviour.register(inserts);
160 </script>