PageRenderTime 73ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/opensourcepos/application/views/products/product_category_grid.php

https://bitbucket.org/jit_bec/shopifine
PHP | 287 lines | 228 code | 37 blank | 22 comment | 8 complexity | 4a0bf0fdc99a957b6354edbc5a79a206 MD5 | raw file
Possible License(s): LGPL-3.0
  1. <html>
  2. <head>
  3. <?php $this->load->view("common/header"); ?>
  4. <script type="text/javascript" src="http://static.jstree.com/v.1.0pre/jquery.jstree.js"></script>
  5. <style>
  6. .ui-combobox > input{
  7. width:20em;
  8. }
  9. .ui-combobox > a{
  10. left:170px;
  11. }
  12. .column {width:400px;}
  13. .field {width:45em;}
  14. </style>
  15. <script>
  16. $(document).ready(function(){
  17. $.validator.addMethod('treerequired', function(value, element) {
  18. var selArray = $('#treeViewDiv').jstree('get_selected');
  19. console.log(selArray.length);
  20. alert (selArray.length);
  21. if (selArray.length == 0){
  22. return false;
  23. }
  24. return true;
  25. }, 'Please select a category');
  26. $( "#productForm" ).validate({
  27. errorPlacement: function(error, element) {
  28. error.appendTo( element.parent());
  29. }//,
  30. // rules: {
  31. // mfrOp: {
  32. // comboBoxrequired: true
  33. // }
  34. // }
  35. }
  36. );
  37. $( "#dialog:ui-dialog" ).dialog( "destroy" );
  38. $("#productOp").combobox();
  39. $( "#dialog-form" ).dialog({
  40. autoOpen: false,
  41. height: 'auto',
  42. width: '40%',
  43. position:[350,25],
  44. modal: true,
  45. buttons: {
  46. "Create the Product": function() {
  47. var bValid = $("#productForm").valid();
  48. if (bValid ){
  49. var selectedIds = [];
  50. $('#treeViewDiv').jstree('get_selected').each(function(){
  51. selectedIds.push($(this).attr('id'));
  52. });
  53. $.ajax({
  54. url:"index.php/products/addcategoryToProduct",
  55. data: {
  56. productOp : $("#productOp").val(),
  57. productIp: $("#productOp-input").val(),
  58. // categoryOp: $("#categoryOp").val(),
  59. // categoryIp: $("#categoryOp-input").val(),
  60. category:JSON.stringify(selectedIds)
  61. },
  62. type:"POST",
  63. success:function(serverresponse)
  64. {
  65. // var response = JSON.parse(serverresponse);
  66. // emptyMessages();
  67. // if (response.status=='error'){
  68. //
  69. // showErrorMessage(response.message)
  70. // }
  71. // else {
  72. showSuccessMessage("Product Suceessfully Added To category");
  73. $("#resources").trigger("reloadGrid");
  74. //}
  75. }
  76. });
  77. $( this ).dialog( "close" );
  78. }
  79. },
  80. Cancel: function() {
  81. $( this ).dialog( "close" );
  82. }
  83. },
  84. close: function() {
  85. //allFields.val( "" ).removeClass( "ui-state-error" );
  86. $("#productForm").data('validator').resetForm();
  87. $('#productForm')[0].reset();
  88. }
  89. });
  90. //user grid
  91. var myGrid = $("#resources"),lastsel2;
  92. var editparameters = {
  93. "keys" : true,
  94. "oneditfunc" : null,
  95. "successfunc" : function(){
  96. var successStatus = "Resources successfully edited";
  97. showSuccessMessage(successStatus);
  98. lastsel2=undefined;
  99. myGrid.trigger("reloadGrid");
  100. return true;
  101. },
  102. "aftersavefunc" : null,
  103. "errorfunc": function(response)
  104. {
  105. var errorStatus = " Resources could not be updated due to internal error";
  106. showErrorMessage(errorStatus);
  107. lastsel2=undefined;
  108. },
  109. "afterrestorefunc" : null,
  110. "restoreAfterError" : true,
  111. "mtype" : "POST"
  112. };
  113. myGrid.jqGrid({
  114. url:'index.php/products/populateProductCategoryMapping',
  115. datatype: 'json',
  116. mtype: 'GET',
  117. colNames:['Product','Barcode','Product ID','Category ID','Category'],
  118. colModel :[
  119. {name:'product_name', index:'product_name', width:140, align:'right',editable:false,search:false},
  120. {name:'barcode', index:'barcode', width:140, align:'right',editable:false},
  121. {name:'product_id', index:'product_id', width:100, align:'right',hidden:true},
  122. {name:'category_id', index:'category_id', width:100, align:'right',hidden:true},
  123. {name:'category_name', index:'category_name', width:140, align:'right',editable:false},
  124. ],
  125. pager: '#pager',
  126. rowNum:10,
  127. rowList:[5,10,20],
  128. sortname: 'id',
  129. sortorder: 'desc',
  130. viewrecords: true,
  131. gridview: true,
  132. ignoreCase:true,
  133. rownumbers:true,
  134. height:'auto',
  135. width:'auto',
  136. multiselect:true,
  137. caption: 'Product Category Mapping',
  138. jsonReader : {
  139. root:"productcategorydata",
  140. page: "page",
  141. total: "total",
  142. records: "records",
  143. cell: "dprow",
  144. id: "id"
  145. },
  146. onSelectRow: function(id){if(id && id!==lastsel2){
  147. myGrid.restoreRow(lastsel2);
  148. myGrid.editRow(id,editparameters);
  149. lastsel2=id;
  150. }
  151. },
  152. editurl:'index.php/products/deleteProductCategoryMapping'
  153. }).navGrid("#pager",{edit:false,add:false,del:true,search:false},
  154. /* edit Option*/ {},
  155. /* Add Option*/ {reloadAfterSubmit:true,recreateForm:true},
  156. {},{},{});
  157. myGrid.jqGrid('filterToolbar', {stringResult: true, searchOnEnter: true, defaultSearch : "cn"});
  158. myGrid.jqGrid('navButtonAdd','#pager',{
  159. caption:"",
  160. title:"Add Category To Product",
  161. buttonicon:"ui-icon-plus",
  162. id:"add_resources",
  163. onClickButton : function () {
  164. $('#treeViewDiv').jstree('deselect_all');
  165. $( "#dialog-form" ).dialog( "open" );
  166. }
  167. });
  168. $("#add_resources").insertBefore("#del_resources")
  169. $("#treeViewDiv")
  170. .jstree({
  171. "plugins" : ["themes", "json_data", "ui"],
  172. "json_data" : {
  173. "ajax" : {
  174. "type": 'GET',
  175. "url": function (node) {
  176. var nodeId = "";
  177. var url = ""
  178. if (node == -1)
  179. {
  180. url = "index.php/utilities/renderParents";
  181. }
  182. else
  183. {
  184. nodeId = node.attr('id');
  185. url = "index.php/utilities/renderChildren";
  186. }
  187. return url;
  188. },
  189. data : function(node) {
  190. if (node != -1){
  191. return {
  192. "nodeid":$.trim(node.attr('id'))
  193. }
  194. }
  195. },
  196. "success": function (new_data) {
  197. return new_data;
  198. }
  199. }
  200. }});
  201. // $("#test").click(function (e){
  202. // e.preventDefault();
  203. // $("#resources").searchGrid();
  204. //
  205. // })
  206. });
  207. </script>
  208. </head>
  209. <body>
  210. <?php $this->load->view("common/menubar"); ?>
  211. <div id ="dialog-form">
  212. <h1 id="formHeader">Add New Product Entity</h1>
  213. <form id="productForm">
  214. <fieldset>
  215. <div class="row">
  216. <div class="column">
  217. <div class="field">
  218. <label for="productOp">Products:</label>
  219. <select name="productOp" id ="productOp" class="required">
  220. <option value="">Choose
  221. <?= $productOptions ?>
  222. </select>
  223. <!--<button id="test"> test</button>-->
  224. </div>
  225. </div>
  226. </div>
  227. <div class="row">
  228. <div class="column">
  229. <div class="field">
  230. <label for="categoryOp">Category:</label>
  231. <div id="treeViewDiv" style="display:inline-block">
  232. </div>
  233. <input id="treeViewHidden" name ="treeViewHidden" style="display:inline-block" class="treerequired" type="hidden"/>
  234. </div>
  235. </div>
  236. </div>
  237. </fieldset>
  238. </form>
  239. </div>
  240. <div style="display: block;height: 100%;left:0em;" class="shopifine-ui-dialog ui-dialog-extra-small ui-widget ui-widget-content ui-corner-all" tabindex="-1" role="dialog" aria-labelledby="ui-dialog-title-dialog-form">
  241. <?php $this->load->view("common/message"); ?>
  242. <div class="table-grid">
  243. <h1 id="table header">Products And Categories</h1>
  244. <table id="resources"><tr><td/></tr></table>
  245. <div id="pager"></div>
  246. </div>
  247. </div>
  248. <?php $this->load->view("partial/footer"); ?>
  249. </body>
  250. </html>