Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.47 KB | None | 0 0
  1. var source = {
  2. dataType: "json",
  3. dataFields: [{
  4. name: 'name',
  5. type: 'string'
  6. }, {
  7. name: 'description',
  8. type: 'string'
  9. }, {
  10. name: 'date',
  11. type: 'string'
  12. }, {
  13. name: 'user',
  14. type: 'string'
  15. }, {
  16. name: 'path',
  17. type: 'string'
  18. }, {
  19. name: 'active',
  20. type: 'boolean'
  21. }, {
  22. name: 'seq',
  23. type: 'int'
  24. }, {
  25. name: 'topic',
  26. type: 'string'
  27. }],
  28. id: 'programId',
  29. url: '${pageContext.request.contextPath}/program-list/getProgramLi',
  30. type: 'GET',
  31. async: true,
  32. updaterow: function(rowid, data, commit) {
  33. data.id = rowid;
  34. $.ajax({
  35. type: 'POST',
  36. url: '${pageContext.request.contextPath}/program-list/updateProgram',
  37. data: data,
  38. success: function(data, textStatus, jqXHR) {
  39. commit(true);
  40. },
  41. error: function(jqXHR, textStatus, errorThrown) {
  42. alert("Error");
  43. commit(false);
  44. }
  45. });
  46. },
  47. addrow: function (rowid, rowdata, position, commit) {
  48. var data = $.extend({}, rowdata);
  49. $.ajax({
  50. type: 'POST',
  51. url: '${pageContext.request.contextPath}/program-list/addProgram',
  52. data: data,
  53. success: function(data, textStatus, jqXHR) {
  54. var newRowId = data != undefined ? parseInt(data) : 0
  55. commit(true, newRowId);
  56. },
  57. error: function(jqXHR, textStatus, errorThrown) {
  58. alert("Error");
  59. commit(false);
  60. }
  61. });
  62. }
  63. };
  64. var dataAdapter = new $.jqx.dataAdapter(source);
  65. $("#grid").jqxGrid({
  66. source: dataAdapter,
  67. altRows: true,
  68. filterable: true,
  69. height: 500,
  70. autorowheight: true,
  71. sortable: true,
  72. pageable: true,
  73. editable: true,
  74. pagesizeoptions: ['10', '20', '50', '100', '1000'],
  75. theme: 'energyblue',
  76. width: '100%',
  77. showtoolbar: true,
  78. toolbarheight: 40,
  79. rendertoolbar: function (statusbar) {
  80. // appends buttons to the status bar.
  81. var container = $("<div style='overflow: hidden; position: relative; margin: 7px;'></div>");
  82. var titletable = $("<div style='float: left; margin-left: 5px; position: relative; bottom: 3px;'><h6><b>PROGRAM LIST</b></h6></div>");
  83. var exportButton = $("<div style='float: right; margin-right: 5px;'><a class='btn btn-icon' style='text-decoration: none; color: #000;' data-toggle=\"modal\" data-target=\"#export-modal\"><span class=\"glyphicon glyphicon-export\" aria-hidden=\"true\"></span></a></div>");
  84. var reloadButton = $("<div class='btn btn-icon' style='float: right; margin-right: 5px;'><span class=\"glyphicon glyphicon-refresh\" aria-hidden=\"true\"></span></div>");
  85. var deleteButton = $("<div class='btn btn-icon' style='float: right; margin-right: 5px;'><span class=\"glyphicon glyphicon-remove\" aria-hidden=\"true\"></span></div>");
  86. var addButton = $("<div class='btn btn-icon' style='float: right; margin-right: 5px;'><span class=\"glyphicon glyphicon-plus\" aria-hidden=\"true\"></span></div>");
  87.  
  88. container.append(titletable);
  89. container.append(exportButton);
  90. container.append(reloadButton);
  91. container.append(deleteButton);
  92. container.append(addButton);
  93. statusbar.append(container);
  94.  
  95. addButton.jqxButton({width: 30});
  96. deleteButton.jqxButton({width: 30});
  97. reloadButton.jqxButton({width: 30});
  98.  
  99. // add new row.
  100. exportButton.click(function () {
  101. var offset = $("#grid").offset();
  102. $("#AddpopupWindow").jqxWindow({ position: { x: parseInt(offset.left) + 60, y: parseInt(offset.top) + 60 } });
  103.  
  104. });
  105. addButton.click(function (row) {
  106. //$("#grid").jqxGrid('addrow', null, {}, "first");
  107. addrow = row;
  108. var offset = $("#grid").offset();
  109. $("#AddpopupWindow").jqxWindow({ position: { x: parseInt(offset.left) + 60, y: parseInt(offset.top) + 60 } });
  110. // get the clicked row's data and initialize the input fields.
  111. var dataRecord = $("#grid").jqxGrid('getrowdata', addrow);
  112. $("#nameadd");
  113. $("#descriptionadd");
  114. $("#dateadd").val(formatAMPM());
  115. $("#useradd");
  116. $("#pathadd");
  117. $("#activeadd");
  118. $("#seqadd");
  119. $("#topicadd");
  120. // show the popup window.
  121. $("#AddpopupWindow").jqxWindow('open');
  122. });
  123. $("#AddpopupWindow").jqxWindow({
  124. width: 500, height: 300, resizable: true, isModal: true, autoOpen: false, cancelButton: $("#CancelAdd"), modalOpacity: 0.3
  125. });
  126. $("#AddpopupWindow").on('open', function () {
  127. $("#nameadd").jqxInput('selectAll');
  128. });
  129.  
  130. $("#CancelAdd").jqxButton({ theme: theme });
  131. $("#SaveAdd").jqxButton({ theme: theme });
  132. // update the edited row when the user clicks the 'Save' button.
  133. $("#SaveAdd").click(function () {
  134. var row = { name: $("#nameadd").val(), description: $("#descriptionadd").val(), date: $("#dateadd").val(), user: $("#useradd").val(), path: $("#pathadd").val(), active: $("#activeadd").val(), seq: $("#seqadd").val(), topic: $("#topicadd").val()
  135. };
  136. $('#grid').jqxGrid('addrow', null, row, "last");
  137. $("#AddpopupWindow").jqxWindow('hide');
  138. });
  139. // delete selected row.
  140. deleteButton.click(function (event) {
  141. var selectedrowindex = $("#grid").jqxGrid('getselectedrowindex');
  142. var rowscount = $("#grid").jqxGrid('getdatainformation').rowscount;
  143. var id = $("#grid").jqxGrid('getrowid', selectedrowindex);
  144. $("#grid").jqxGrid('deleterow', id);
  145. });
  146. // reload grid data.
  147. reloadButton.click(function (event) {
  148. $("#grid").jqxGrid({ source: dataAdapter });
  149. });
  150. },
  151. columns: [{
  152. text: 'Program name',
  153. dataField: 'name',
  154. cellsAlign: 'center',
  155. align: 'center',
  156. width: '15%',
  157. editable: false
  158. }, {
  159. text: 'Description',
  160. dataField: 'description',
  161. cellsAlign: 'center',
  162. align: 'center',
  163. editable: false
  164. }, {
  165. text: 'Date',
  166. dataField: 'date',
  167. cellsAlign: 'center',
  168. align: 'center',
  169. editable: false
  170. }, {
  171. text: 'User',
  172. dataField: 'user',
  173. cellsAlign: 'center',
  174. align: 'center',
  175. width: '5%',
  176. editable: false
  177. }, {
  178. text: 'Program path',
  179. dataField: 'path',
  180. cellsAlign: 'center',
  181. align: 'center',
  182. width: '10%',
  183. editable: false
  184. }, {
  185. text: 'Active',
  186. dataField: 'active',
  187. cellsAlign: 'center',
  188. align: 'center',
  189. width: '5%',
  190. columntype: 'checkbox'
  191. }, {
  192. text: 'Sequency',
  193. dataField: 'seq',
  194. cellsAlign: 'center',
  195. align: 'center',
  196. width: '7%',
  197. editable: false
  198. }, {
  199. text: 'Topic',
  200. dataField: 'topic',
  201. cellsAlign: 'center',
  202. align: 'center',
  203. width: '10%',
  204. editable: false
  205. }, {
  206. text: 'Action',
  207. datafield: 'Edit',
  208. width: '7%',
  209. cellsAlign: 'center',
  210. align: 'center',
  211. editable: false,
  212. filterable: false,
  213. sortable: false,
  214. createwidget: function (row, column, value, htmlElement) {
  215. var editImgUrl = 'https://www.jqwidgets.com/jquery-widgets-demo/images/add.png';
  216. var delImgUrl = 'https://www.jqwidgets.com/jquery-widgets-demo/images/close.png';
  217.  
  218. var editImg = '<img height="30" width="30" src="' + editImgUrl + '"/>';
  219. var delImg = '<img height="30" width="30" src="' + delImgUrl + '"/>';
  220.  
  221. var editButton = $("<div style='border:none; display:inline-block;'>" + editImg + "</div>");
  222. var delButton = $("<div style='border:none; display:inline-block;'>" + delImg + "</div>");
  223.  
  224. $(htmlElement).append(editButton);
  225. $(htmlElement).append(delButton);
  226. editButton.jqxButton({ height: 30, width: 30 });
  227. editButton.click(function (event) {
  228. editrow = row;
  229. var offset = $("#grid").offset();
  230. $("#popupWindow").jqxWindow({ position: { x: parseInt(offset.left) + 60, y: parseInt(offset.top) + 60 } });
  231. // get the clicked row's data and initialize the input fields.
  232. var dataRecord = $("#grid").jqxGrid('getrowdata', editrow);
  233. $("#name").val(dataRecord.name);
  234. $("#description").val(dataRecord.description);
  235. $("#date").val(formatAMPM());
  236. $("#user").val(dataRecord.user);
  237. $("#path").val(dataRecord.path);
  238. $("#active").val(dataRecord.active);
  239. $("#seq").val(dataRecord.seq);
  240. $("#topic").val(dataRecord.topic);
  241. // show the popup window.
  242. $("#popupWindow").jqxWindow('open');
  243. });
  244.  
  245. delButton.jqxButton({ height: 30, width: 30 });
  246. delButton.click(function (event) {
  247. let id = $("#grid").jqxGrid('getrowid', row.boundindex);
  248. $("#grid").jqxGrid('deleterow', id);
  249. });
  250. },
  251. }]
  252. });
  253. $("#popupWindow").jqxWindow({
  254. width: 500, height: 300, resizable: true, isModal: true, autoOpen: false, cancelButton: $("#Cancel"), modalOpacity: 0.3
  255. });
  256. $("#popupWindow").on('open', function () {
  257. $("#name").jqxInput('selectAll');
  258. });
  259.  
  260. $("#Cancel").jqxButton({ theme: theme });
  261. $("#Save").jqxButton({ theme: theme });
  262. // update the edited row when the user clicks the 'Save' button.
  263. $("#Save").click(function () {
  264. if (editrow >= 0) {
  265. var row = { name: $("#name").val(), description: $("#description").val(), date: $("#date").val(), user: $("#user").val(), path: $("#path").val(), active: $("#active").val(), seq: $("#seq").val(), topic: $("#topic").val()
  266. };
  267. var rowID = $('#grid').jqxGrid('getrowid', editrow);
  268. $('#grid').jqxGrid('updaterow', rowID, row);
  269. $("#popupWindow").jqxWindow('hide');
  270. }
  271. });
  272. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement