1 /***************************************************************************** |
|
2 * Copyright (C) 2014 |
|
3 * |
|
4 * Michiel Broek <mbroek at mbse dot eu> |
|
5 * |
|
6 * This file is part of ThermFerm |
|
7 * |
|
8 * This is free software; you can redistribute it and/or modify it |
|
9 * under the terms of the GNU General Public License as published by the |
|
10 * Free Software Foundation; either version 2, or (at your option) any |
|
11 * later version. |
|
12 * |
|
13 * ThermFerm is distributed in the hope that it will be useful, but |
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
16 * General Public License for more details. |
|
17 * |
|
18 * You should have received a copy of the GNU General Public License |
|
19 * along with ThermFerm; see the file COPYING. If not, write to the Free |
|
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
|
21 *****************************************************************************/ |
|
22 |
|
23 $(document).ready(function () { |
|
24 |
|
25 var data = {}; |
|
26 var theme = 'ui-redmond'; |
|
27 |
|
28 /* |
|
29 * 1-Wire bus |
|
30 */ |
|
31 var source_bus = { |
|
32 datatype: "json", |
|
33 datafields: [ |
|
34 { name: 'Address', type: 'string' }, |
|
35 { name: 'Refcnt', type: 'int' }, |
|
36 { name: 'Chip', type: 'string' }, |
|
37 { name: 'Description', type: 'string' } |
|
38 ], |
|
39 url: 'getbus.php' |
|
40 }; |
|
41 var dataAdapter_bus = new $.jqx.dataAdapter(source_bus); |
|
42 $("#jqxgrid_bus").jqxGrid( { |
|
43 width: 770, height: 280, |
|
44 source: dataAdapter_bus, |
|
45 theme: theme, |
|
46 columnsresize: true, |
|
47 columns: [ |
|
48 { text: 'Address', datafield: 'Address', width: 150 }, |
|
49 { text: 'References', datafield: 'Refcnt', width: 100 }, |
|
50 { text: 'Chipset', datafield: 'Chip', width: 120 }, |
|
51 { text: 'Description', datafield: 'Description', minwidth: 120 } |
|
52 ] |
|
53 }); |
|
54 |
|
55 /* |
|
56 * Profiles |
|
57 */ |
|
58 var source_profiles = { |
|
59 datatype: "json", |
|
60 datafields: [ |
|
61 { name: 'UUID', type: 'string' }, |
|
62 { name: 'Name', type: 'string' }, |
|
63 { name: 'Steps', type: 'int' } |
|
64 ], |
|
65 id: 'UUID', |
|
66 url: 'getprofiles.php', |
|
67 insertrow: function (rowid, commit) { |
|
68 var data = "insert=true&" + $.param({Name: rowid}); |
|
69 $.ajax({ |
|
70 dataType: 'json', |
|
71 url: 'getprofiles.php', |
|
72 data: data, |
|
73 cache: false, |
|
74 success: function (data, status, xhr) { |
|
75 // insert command is executed. |
|
76 commit(true); |
|
77 }, |
|
78 error: function(jqXHR, textStatus, errorThrown) { |
|
79 commit(false); |
|
80 } |
|
81 }); |
|
82 }, |
|
83 deleterow: function (rowid, commit) { |
|
84 var data = "delete=true&" + $.param({UUID: rowid}); |
|
85 $.ajax({ |
|
86 dataType: 'json', |
|
87 url: 'getprofiles.php', |
|
88 data: data, |
|
89 cache: false, |
|
90 success: function (data, status, xhr) { |
|
91 // insert command is executed. |
|
92 commit(true); |
|
93 }, |
|
94 error: function(jqXHR, textStatus, errorThrown) { |
|
95 commit(false); |
|
96 } |
|
97 }); |
|
98 }, |
|
99 updaterow: function (rowid, rowdata, commit) { |
|
100 // synchronize with the server - send update command |
|
101 var data = "update=true&UUID=" + rowdata.UUID + "&Name=" + rowdata.Name; |
|
102 $.ajax({ |
|
103 dataType: 'json', |
|
104 url: 'getprofiles.php', |
|
105 data: data, |
|
106 success: function (data, status, xhr) { |
|
107 // update command is executed. |
|
108 commit(true); |
|
109 }, |
|
110 error: function () { |
|
111 // cancel changes. |
|
112 commit(false); |
|
113 } |
|
114 }); |
|
115 } |
|
116 }; |
|
117 var dataAdapter_profiles = new $.jqx.dataAdapter(source_profiles); |
|
118 $("#jqxgrid_profiles").jqxGrid( { |
|
119 width: 770, height: 280, |
|
120 selectionmode: 'singlecell', |
|
121 source: dataAdapter_profiles, |
|
122 theme: theme, |
|
123 columnsresize: true, |
|
124 editable: true, |
|
125 showstatusbar: true, |
|
126 renderstatusbar: function (statusbar) { |
|
127 // appends buttons to the status bar. |
|
128 var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>"); |
|
129 var addButton = $("<div style='float: left; margin-left: 5px;'><img style='position: relative; margin-top: 2px;' src='../images/add.png'/><span style='margin-left: 4px; position: relative; top: -3px;'>Add</span></div>"); |
|
130 var deleteButton = $("<div style='float: left; margin-left: 5px;'><img style='position: relative; margin-top: 2px;' src='../images/close.png'/><span style='margin-left: 4px; position: relative; top: -3px;'>Delete</span></div>"); |
|
131 var reloadButton = $("<div style='float: left; margin-left: 5px;'><img style='position: relative; margin-top: 2px;' src='../images/refresh.png'/><span style='margin-left: 4px; position: relative; top: -3px;'>Reload</span></div>"); |
|
132 container.append(addButton); |
|
133 container.append(deleteButton); |
|
134 container.append(reloadButton); |
|
135 statusbar.append(container); |
|
136 addButton.jqxButton({ width: 60, height: 20 }); |
|
137 deleteButton.jqxButton({ width: 65, height: 20 }); |
|
138 reloadButton.jqxButton({ width: 65, height: 20 }); |
|
139 // add new row. |
|
140 addButton.click(function (event) { |
|
141 /* |
|
142 * Ask a new profile name using a popup window. |
|
143 * Send "ADD PROFILE name" to the server using the getprofiles.php script. |
|
144 * Refresh the data |
|
145 */ |
|
146 $("#jqxwindow_addprofile").jqxWindow('open'); |
|
147 $("#jqxgrid_profiles").jqxGrid({ source: dataAdapter_profiles }); |
|
148 }); |
|
149 // delete selected row. |
|
150 deleteButton.click(function (event) { |
|
151 var selectedrowindex = $("#jqxgrid_profiles").jqxGrid('getselectedrowindex'); |
|
152 var rowscount = $("#jqxgrid_profiles").jqxGrid('getdatainformation').rowscount; |
|
153 var id = $("#jqxgrid_profiles").jqxGrid('getrowid', selectedrowindex); |
|
154 $("#jqxgrid_profiles").jqxGrid('deleterow', id); |
|
155 }); |
|
156 // reload grid data. |
|
157 reloadButton.click(function (event) { |
|
158 $("#jqxgrid_profiles").jqxGrid({ source: dataAdapter_profiles }); |
|
159 }); |
|
160 }, |
|
161 columns: [ |
|
162 { text: 'UUID', editable: false, datafield: 'UUID', width: 280 }, |
|
163 { text: 'Name', datafield: 'Name', minwidth: 120 }, |
|
164 { text: 'Steps', editable: false, datafield: 'Steps', width: 50 } |
|
165 ] |
|
166 }); |
|
167 $("#jqxwindow_addprofile").jqxWindow({ |
|
168 theme: theme, |
|
169 resizable: false, |
|
170 isModal: true, |
|
171 modalOpacity: 0.5, |
|
172 autoOpen: false, |
|
173 width: 210, |
|
174 height: 180, |
|
175 cancelButton: $("#profile_cancelButton"), |
|
176 initContent: function () { |
|
177 $("#profile_addButton").jqxButton({ width: 70, height: 25, theme: theme }); |
|
178 $("#profile_cancelButton").jqxButton({ width: 70, height: 25, theme: theme }); |
|
179 $("#profile_addButton").click(function () { |
|
180 var id = $("#profile_inputField").val(); |
|
181 $("#jqxgrid_profiles").jqxGrid('insertrow', id); |
|
182 $("#jqxwindow_addprofile").jqxWindow('hide'); |
|
183 }); |
|
184 } |
|
185 }); |
|
186 |
|
187 /* |
|
188 * Units |
|
189 */ |
|
190 var source_units = { |
|
191 datatype: "json", |
|
192 datafields: [ |
|
193 { name: 'UUID', type: 'string' }, |
|
194 { name: 'Name', type: 'string' }, |
|
195 { name: 'Mode', type: 'string' } |
|
196 ], |
|
197 url: 'getunits.php' |
|
198 }; |
|
199 var dataAdapter_units = new $.jqx.dataAdapter(source_units); |
|
200 $("#jqxgrid_units").jqxGrid( { |
|
201 width: 770, height: 280, |
|
202 source: dataAdapter_units, |
|
203 theme: theme, |
|
204 columnsresize: true, |
|
205 editable: true, |
|
206 columns: [ |
|
207 { text: 'UUID', editable: false, datafield: 'UUID', width: 280 }, |
|
208 { text: 'Name', datafield: 'Name', minwidth: 120 }, |
|
209 { text: 'Mode', datafield: 'Mode', width: 70 } |
|
210 ] |
|
211 }); |
|
212 }); |
|