45 $(document).ready(function () { |
45 $(document).ready(function () { |
46 |
46 |
47 var steprow = 0; |
47 var steprow = 0; |
48 var stepData = {}; |
48 var stepData = {}; |
49 var dataRecord = {}; |
49 var dataRecord = {}; |
50 var url = "includes/db_profile_mash.php"; |
50 var url = 'includes/db_profile_mash.php'; |
51 |
51 |
52 // tooltips |
52 // tooltips |
53 $("#name").jqxTooltip({ content: 'De naam voor dit maisch profiel.' }); |
53 $("#name").jqxTooltip({ content: 'De naam voor dit maisch profiel.' }); |
54 $("#notes").jqxTooltip({ content: 'De uitgebreide opmerkingen over dit maisch profiel.' }); |
54 $("#notes").jqxTooltip({ content: 'De uitgebreide opmerkingen over dit maisch profiel.' }); |
55 // prepare the data |
55 // prepare the data |
56 var source = { |
56 var source = { |
57 datatype: "json", |
57 datatype: 'json', |
58 cache: false, |
58 cache: false, |
59 datafields: [ |
59 datafields: [ |
60 { name: 'record', type: 'number' }, |
60 { name: 'record', type: 'number' }, |
61 { name: 'name', type: 'string' }, |
61 { name: 'name', type: 'string' }, |
62 { name: 'notes', type: 'string' }, |
62 { name: 'notes', type: 'string' }, |
70 $.ajax({ |
70 $.ajax({ |
71 dataType: 'json', |
71 dataType: 'json', |
72 url: url, |
72 url: url, |
73 cache: false, |
73 cache: false, |
74 data: data, |
74 data: data, |
75 type: "POST", |
75 type: 'POST', |
76 success: function (data, status, xhr) { |
76 success: function (data, status, xhr) { |
77 // delete command is executed. |
|
78 commit(true); |
77 commit(true); |
|
78 console.log('mash deleterow ' + rowid + ' success'); |
79 }, |
79 }, |
80 error: function (jqXHR, textStatus, errorThrown) { |
80 error: function (jqXHR, textStatus, errorThrown) { |
81 commit(false); |
81 commit(false); |
|
82 console.log('mash deleterow ' + textStatus); |
82 } |
83 } |
83 }); |
84 }); |
84 }, |
85 }, |
85 addrow: function (rowid, rowdata, position, commit) { |
86 addrow: function (rowid, rowdata, position, commit) { |
86 var data = "insert=true&" + $.param(rowdata); |
87 var data = "insert=true&" + $.param(rowdata); |
90 cache: false, |
91 cache: false, |
91 data: data, |
92 data: data, |
92 type: "POST", |
93 type: "POST", |
93 success: function (data, status, xhr) { |
94 success: function (data, status, xhr) { |
94 commit(true); |
95 commit(true); |
|
96 console.log('mash addrow ' + rowid + ' success'); |
95 }, |
97 }, |
96 error: function(jqXHR, textStatus, errorThrown) { |
98 error: function(jqXHR, textStatus, errorThrown) { |
97 commit(false); |
99 commit(false); |
|
100 console.log('mash addrow ' + textStatus); |
98 } |
101 } |
99 }); |
102 }); |
100 }, |
103 }, |
101 updaterow: function (rowid, rowdata, commit) { |
104 updaterow: function (rowid, rowdata, commit) { |
102 var data = "update=true&" + $.param(rowdata); |
105 var data = "update=true&" + $.param(rowdata); |
105 url: url, |
108 url: url, |
106 cache: false, |
109 cache: false, |
107 data: data, |
110 data: data, |
108 type: "POST", |
111 type: "POST", |
109 success: function (data, status, xhr) { |
112 success: function (data, status, xhr) { |
110 // update command is executed. |
|
111 commit(true); |
113 commit(true); |
|
114 console.log('mash updaterow ' + rowid + ' success'); |
112 }, |
115 }, |
113 error: function(jqXHR, textStatus, errorThrown) { |
116 error: function(jqXHR, textStatus, errorThrown) { |
114 commit(false); |
117 commit(false); |
|
118 console.log('mash updaterow ' + textStatus); |
115 } |
119 } |
116 }); |
120 }); |
117 } |
121 } |
118 }; |
122 }; |
119 // Initialize the input fields. |
123 // Initialize the input fields. |
134 $("#m_step_time").jqxNumberInput( PosInt ); |
138 $("#m_step_time").jqxNumberInput( PosInt ); |
135 $("#m_step_time").jqxNumberInput({ Min: 1, Max: 120 }); |
139 $("#m_step_time").jqxNumberInput({ Min: 1, Max: 120 }); |
136 $("#m_ramp_time").jqxNumberInput( PosInt ); |
140 $("#m_ramp_time").jqxNumberInput( PosInt ); |
137 $("#m_ramp_time").jqxNumberInput({ Min: 1, Max: 30 }); |
141 $("#m_ramp_time").jqxNumberInput({ Min: 1, Max: 30 }); |
138 |
142 |
139 var dataAdapter = new $.jqx.dataAdapter(source); |
143 var dataAdapter = new $.jqx.dataAdapter(source), |
|
144 editrow = -1; |
|
145 |
140 // Inline steps editor |
146 // Inline steps editor |
141 var editsteps = function (data) { |
147 var editsteps = function (data) { |
142 var generaterow = function () { |
148 var generaterow = function () { |
143 var row = {}; |
149 var row = {}; |
144 row['step_name'] = "Stap 1"; |
150 row['step_name'] = "Stap 1"; |
174 source: stepAdapter, |
180 source: stepAdapter, |
175 theme: theme, |
181 theme: theme, |
176 selectionmode: 'singlerow', |
182 selectionmode: 'singlerow', |
177 showtoolbar: true, |
183 showtoolbar: true, |
178 rendertoolbar: function (toolbar) { |
184 rendertoolbar: function (toolbar) { |
179 var me = this; |
|
180 var container = $("<div style='margin: 5px;'></div>"); |
185 var container = $("<div style='margin: 5px;'></div>"); |
181 toolbar.append(container); |
186 toolbar.append(container); |
182 container.append('<input style="margin-left: 100px;" id="addrowbutton" type="button" value="Nieuwe stap" />'); |
187 container.append('<input style="margin-left: 100px;" id="addrowbutton" type="button" value="Nieuwe stap" />'); |
183 container.append('<input style="margin-left: 450px;" id="deleterowbutton" type="button" value="Verwijder stap" />'); |
188 container.append('<input style="margin-left: 450px;" id="deleterowbutton" type="button" value="Verwijder stap" />'); |
184 $("#addrowbutton").jqxButton({ template: "primary", theme: theme, width: 150 }); |
189 $("#addrowbutton").jqxButton({ template: "primary", theme: theme, width: 150 }); |
185 $("#deleterowbutton").jqxButton({ template: "danger", theme: theme, width: 150 }); |
190 $("#deleterowbutton").jqxButton({ template: "danger", theme: theme, width: 150 }); |
186 // create new row. |
191 // create new row. |
187 $("#addrowbutton").on('click', function () { |
192 $("#addrowbutton").on('click', function () { |
188 var datarow = generaterow(); |
193 var datarow = generaterow(); |
189 var commit = $("#grid").jqxGrid('addrow', null, datarow); |
194 $("#grid").jqxGrid('addrow', null, datarow); |
190 }); |
195 }); |
191 // delete row. |
196 // delete row. |
192 $("#deleterowbutton").on('click', function () { |
197 $("#deleterowbutton").on('click', function () { |
193 var selectedrowindex = $("#grid").jqxGrid('getselectedrowindex'); |
198 var selectedrowindex = $("#grid").jqxGrid('getselectedrowindex'); |
194 var rowscount = $("#grid").jqxGrid('getdatainformation').rowscount; |
199 var rowscount = $("#grid").jqxGrid('getdatainformation').rowscount; |
195 if (selectedrowindex >= 0 && selectedrowindex < rowscount) { |
200 if (selectedrowindex >= 0 && selectedrowindex < rowscount) { |
196 var id = $("#grid").jqxGrid('getrowid', selectedrowindex); |
201 var id = $("#grid").jqxGrid('getrowid', selectedrowindex); |
197 var commit = $("#grid").jqxGrid('deleterow', id); |
202 $("#grid").jqxGrid('deleterow', id); |
198 } |
203 } |
199 }); |
204 }); |
200 }, |
205 }, |
201 columns: [ |
206 columns: [ |
202 { text: 'Stap naam', datafield: 'step_name' }, |
207 { text: 'Stap naam', datafield: 'step_name' }, |
229 }; |
234 }; |
230 |
235 |
231 // initialize the input fields. |
236 // initialize the input fields. |
232 $("#name").jqxInput({ theme: theme, width: 480, height: 23 }); |
237 $("#name").jqxInput({ theme: theme, width: 480, height: 23 }); |
233 $("#notes").jqxInput({ theme: theme, width: 800, height: 100 }); |
238 $("#notes").jqxInput({ theme: theme, width: 800, height: 100 }); |
234 var editrow = -1; |
|
235 // initialize jqxGrid |
239 // initialize jqxGrid |
236 $("#jqxgrid").jqxGrid({ |
240 $("#jqxgrid").jqxGrid({ |
237 width: 1280, |
241 width: 1280, |
238 height: 630, |
242 height: 630, |
239 source: dataAdapter, |
243 source: dataAdapter, |
262 { text: '', datafield: 'Edit', width: 100, align: 'center', columntype: 'button', cellsrenderer: function () { |
266 { text: '', datafield: 'Edit', width: 100, align: 'center', columntype: 'button', cellsrenderer: function () { |
263 return "Wijzig"; |
267 return "Wijzig"; |
264 }, buttonclick: function (row) { |
268 }, buttonclick: function (row) { |
265 editrow = row; |
269 editrow = row; |
266 // get the clicked row's data and initialize the input fields. |
270 // get the clicked row's data and initialize the input fields. |
267 var dataRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow); |
271 dataRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow); |
268 $("#name").val(dataRecord.name); |
272 $("#name").val(dataRecord.name); |
269 $("#notes").val(dataRecord.notes); |
273 $("#notes").val(dataRecord.notes); |
270 editsteps(dataRecord); |
274 editsteps(dataRecord); |
271 // show the popup window. |
275 // show the popup window. |
272 $("#popupWindow").jqxWindow('open'); |
276 $("#popupWindow").jqxWindow('open'); |
326 } |
330 } |
327 $("#popupWindow").jqxWindow('hide'); |
331 $("#popupWindow").jqxWindow('hide'); |
328 }); |
332 }); |
329 $("#Cancel").jqxButton({ template: "primary", width: '90px', theme: theme }); |
333 $("#Cancel").jqxButton({ template: "primary", width: '90px', theme: theme }); |
330 $("#Save").jqxButton({ template: "success", width: '90px', theme: theme }); |
334 $("#Save").jqxButton({ template: "success", width: '90px', theme: theme }); |
331 // update the edited row when the user clicks the 'Save' button. |
|
332 $("#Save").click(function () { |
335 $("#Save").click(function () { |
333 var steprows = $('#grid').jqxGrid('getrows'); |
336 var steprows = $('#grid').jqxGrid('getrows'); |
334 var rowID = -1; |
337 var rowID = -1; |
335 if (editrow >= 0) { |
338 if (editrow >= 0) { |
336 rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); |
339 rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); |