Guest User

Untitled

a guest
May 23rd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.64 KB | None | 0 0
  1. $(document).ready(function(){
  2.  
  3. /* */
  4. displayProductsInterface();
  5. displayCustomerInterface();
  6. diaplaySuppliersInterface();
  7. /* */
  8. insertArticle();
  9. selectArticle();
  10. editArticle();
  11. deleteArticle();
  12. /* */
  13. insertSupplier();
  14. selectSupplier();
  15. editSupplier();
  16. deleteSupplier();
  17.  
  18. });
  19.  
  20. function displayCustomerInterface(){
  21. $('#manage-customers').on('click',function(e){
  22. e.preventDefault();
  23. $.ajax({
  24. type:'GET',
  25. url: 'customers.html',
  26. success: function(interface){
  27. $('#products,#suppliers').empty();
  28. $('#customers').html(interface);
  29. }
  30. });
  31. });
  32.  
  33. }
  34.  
  35. function displayProductsInterface(){
  36. $('#manage-products').on('click',function(e){
  37. e.preventDefault();
  38. $.ajax({
  39. type:'GET',
  40. url: 'products.php',
  41. success: function(interface){
  42. $('#customers,#suppliers').empty();
  43. $('#products').html(interface);
  44. loadProductsList();
  45. }
  46. });
  47. });
  48.  
  49. }
  50.  
  51. function diaplaySuppliersInterface(){
  52. $('#manage-suppliers').on('click',function(e){
  53. e.preventDefault();
  54. $.ajax({
  55. type:'GET',
  56. url: 'suppliers.php',
  57. cache: false,
  58. success: function(interface){
  59. $('#products,#customers').empty();
  60. $('#suppliers').html(interface);
  61. loadSuppliersList();
  62. }
  63. });
  64. });
  65.  
  66. }
  67.  
  68. function loadProductsList(){
  69. $.ajax({
  70. type: 'GET',
  71. url: 'do.php?action=productsList',
  72. cache: false,
  73. success: function(response){
  74. var table = '';
  75. $.each(JSON.parse(response), function(i, item){
  76. table = '<tr><td>'+ item.code +'</td><td>'+ item.name +'</td><td>'+ item.brand +'</td><td>'+ item.type +'</td><td>'+ item.pieces +'</td><td>'+ item.price +'</td><td>'+ item.tax +'</td><td>'+ item.supplier +'</td><td>'+ item.shelf +'</td><td>'+ item.note +'</td><td><button type="button" class="btn-link edit" value="?action=selectArticle&id='+ item.id +'" data-toggle="modal" data-target="#editForms">Modifica</button>&nbsp;<button class="btn-link delete" value="'+ item.id +'">Elimina</button></td>';
  77. $('#productsTable tbody').append(table);
  78. });
  79. }
  80. });
  81. }
  82.  
  83. function loadSuppliersList(){
  84. $.ajax({
  85. type: 'GET',
  86. url: 'do.php?action=suppliersList',
  87. cache: false,
  88. success: function(response){
  89. var table = '';
  90. $.each(JSON.parse(response), function(i, item){
  91. table = '<tr><td>'+ item.code +'</td><td>'+ item.name +'</td><td>'+ item.taxid +'</td><td>'+ item.phone +'</td><td>'+ item.fax +'</td><td>'+ item.email +'</td><td><button type="button" class="btn-link edit" value="?action=selectSupplier&id='+ item.id +'" data-toggle="modal" data-target="#editForms">Modifica</button>&nbsp;<button class="btn-link delete" value="'+ item.id +'">Elimina</button></td>';
  92. $('#suppliersTable tbody').append(table);
  93. });
  94. }
  95. });
  96. }
  97.  
  98. function insertArticle(){
  99. $(document).on('submit','#productsForm',function(e){
  100. e.preventDefault();
  101. var action = 'insertArticle';
  102. var code = $('#productCode').val();
  103. var pieces = $('#productPieces').val();
  104. var brand = $('#productBrand').val();
  105. var name = $('#productName').val();
  106. var type = $('#productType').val();
  107. var supplier = $('#productSupplier').val();
  108. var shelf = $('#productShelf').val();
  109. var price = $('#productPrice').val();
  110. var taxRate = $('#productTaxRate').val();
  111. var note = $('#productNote').val();
  112. $.ajax({
  113. url: 'do.php',
  114. type: 'POST',
  115. data: {action:action,code:code,pieces:pieces,name:name,brand:brand,type:type,supplier:supplier,shelf:shelf,price:price,tax:taxRate,note:note},
  116. cache: false,
  117. success: function(response){
  118. console.log(response);
  119. $('#productsTable tbody').fadeOut()
  120. .empty()
  121. .fadeIn('slow',function(){
  122. loadProductsList();
  123. });
  124. }
  125. });
  126. });
  127. }
  128.  
  129. function insertSupplier(){
  130. $(document).on('submit','#supplierForm',function(e){
  131. e.preventDefault();
  132. var action = 'insertSupplier';
  133. var code = $('#supplierCode').val();
  134. var name = $('#supplierName').val();
  135. var taxid = $('#supplierTaxNumber').val();
  136. var phone = $('#supplierPhone').val();
  137. var fax = $('#supplierFax').val();
  138. var email = $('#supplierEmail').val();
  139. var address = $('#supplierAddress').val();
  140. var cap = $('#supplierCap').val();
  141. var city = $('#supplierCity').val();
  142. var province = $('#supplierProvince').val();
  143. var note = $('#supplierNote').val();
  144.  
  145. $.ajax({
  146. url: 'do.php',
  147. type: 'POST',
  148. data: {action:action,code:code,name:name,taxid:taxid,phone:phone,fax:fax,email:email,address:address,cap:cap,city:city,province:province,note:note},
  149. cache: false,
  150. success: function(response){
  151. console.log(response);
  152. $('#suppliersTable tbody').fadeOut()
  153. .empty()
  154. .fadeIn('slow',function(){
  155. loadSuppliersList();
  156. });
  157. }
  158. });
  159.  
  160. });
  161. }
  162.  
  163. function selectArticle(){
  164. $(document).on('click','button.btn-link.edit',function(e){
  165. e.preventDefault();
  166. var href = $(this).val();
  167. $('.modal-body').empty();
  168. $.ajax({
  169. type: 'GET',
  170. url: 'view/productsForm.html',
  171. cache: false,
  172. success: function(interface){
  173. $('.modal-body').html(interface);
  174. $.ajax({
  175. type: 'GET',
  176. url: 'do.php'+href,
  177. cache: false,
  178. success: function(response){
  179. var data = JSON.parse(response);
  180. console.log(data);
  181. $('.article-id').attr('value',data.id);
  182. $('#editCode').attr('value',data.code);
  183. $('#editPieces').attr('value',data.pieces);
  184. $('#editBrand').attr('value',data.brand);
  185. $('#editName').attr('value',data.name);
  186. $('#editType').attr('value',data.type);
  187. $('#editSupplier').attr('value',data.supplier);
  188. $('#editShelf').attr('value',data.shelf);
  189. $('#editPrice').attr('value',data.price);
  190. $('#editTaxRate').attr('value',data.tax);
  191. $('#editNote').attr('value',data.note);
  192. }
  193. });
  194. }
  195. });
  196. });
  197. }
  198.  
  199.  
  200. function selectSupplier(){
  201. $(document).on('click','button.btn-link.edit',function(e){
  202. e.preventDefault();
  203. var href = $(this).val();
  204. $('.modal-body').empty();
  205. $.ajax({
  206. type: 'GET',
  207. url: 'view/suppliersForm.html',
  208. cache: false,
  209. success: function(interface){
  210. $('.modal-body').html(interface);
  211. $.ajax({
  212. type:'GET',
  213. url: 'do.php'+href,
  214. cache: false,
  215. success: function(response){
  216. var data = JSON.parse(response);
  217. $('.supplier-id').attr('value',data.id);
  218. $('#editCode').attr('value',data.code);
  219. $('#editName').attr('value',data.name);
  220. $('#editTaxNumber').attr('value',data.taxid);
  221. $('#editPhone').attr('value',data.phone);
  222. $('#editFax').attr('value',data.fax);
  223. $('#editEmail').attr('value',data.email);
  224. $('#editAddress').attr('value',data.address);
  225. $('#editCity').attr('value',data.city);
  226. $('#editCap').attr('value',data.cap);
  227. $('#editProvince').attr('value',data.province);
  228. $('#editNote').attr('value',data.note);
  229. }
  230. });
  231. }
  232. });
  233. });
  234. }
  235.  
  236. function editArticle(){
  237. $(document).on('submit','#editProductForm',function(e){
  238. e.preventDefault();
  239. var action = 'editArticle';
  240. var id = $('.article-id').val();
  241. var code = $('#editCode').val();
  242. var pieces = $('#editPieces').val();
  243. var brand = $('#editBrand').val();
  244. var name = $('#editName').val();
  245. var type = $('#editType').val();
  246. var supplier = $('#editSupplier').val();
  247. var shelf = $('#editShelf').val();
  248. var price = $('#editPrice').val();
  249. var taxRate = $('#editTaxRate').val();
  250. var note = $('#editNote').val();
  251. $.ajax({
  252. type: 'POST',
  253. url: 'do.php',
  254. data:{action:action,id:id,code:code,pieces:pieces,name:name,brand:brand,type:type,supplier:supplier,shelf:shelf,price:price,tax:taxRate,note:note},
  255. cache: false,
  256. success: function(response){
  257. console.log(response);
  258. $('#editForms').modal('hide');
  259. $('#productsTable tbody').fadeOut()
  260. .empty()
  261. .fadeIn('slow',function(){
  262. loadProductsList();
  263. });
  264. }
  265. });
  266. });
  267. }
  268.  
  269. function editSupplier(){
  270. $(document).on('submit','#editSupplierForm',function(e){
  271. e.preventDefault();
  272. var action = 'editSupplier';
  273. var id = $('.supplier-id').val();
  274. var code = $('#editCode').val();
  275. var name = $('#editName').val();
  276. var taxid = $('#editTaxNumber').val();
  277. var phone = $('#editPhone').val();
  278. var fax = $('#editFax').val();
  279. var email = $('#editEmail').val();
  280. var address = $('#editAddress').val();
  281. var cap = $('#editCap').val();
  282. var city = $('#editCity').val();
  283. var province = $('#editProvince').val();
  284. var note = $('#editNote').val();
  285.  
  286. $.ajax({
  287. url: 'do.php',
  288. type: 'POST',
  289. data: {action:action,id:id,code:code,name:name,taxid:taxid,phone:phone,fax:fax,email:email,address:address,cap:cap,city:city,province:province,note:note},
  290. cache: false,
  291. success: function(response){
  292. console.log(response);
  293. $('#editForms').modal('hide');
  294. $('#suppliersTable tbody').fadeOut()
  295. .empty()
  296. .fadeIn('slow',function(){
  297. loadSuppliersList();
  298. });
  299.  
  300. }
  301. });
  302.  
  303. });
  304. }
  305.  
  306. function deleteArticle(){
  307. $(document).on('click','button.btn-link.delete',function(e){
  308. e.preventDefault();
  309. var action = 'deleteArticle';
  310. var id = $(this).val();
  311. $.ajax({
  312. type: 'POST',
  313. data: {action:action,id:id},
  314. url: 'do.php',
  315. cache: false,
  316. success: function(response){
  317. $('#productsTable tbody').fadeOut()
  318. .empty()
  319. .fadeIn('fast',function(){
  320. loadProductsList();
  321. });
  322. }
  323. });
  324. });
  325. }
  326.  
  327. function deleteSupplier(){
  328. $(document).on('click','button.btn-link.delete',function(e){
  329. e.preventDefault();
  330. var action = 'deleteSupplier';
  331. var id = $(this).val();
  332. $.ajax({
  333. type: 'POST',
  334. data: {action:action,id:id},
  335. url: 'do.php',
  336. cache: false,
  337. success: function(response){
  338. $('#suppliersTable tbody').fadeOut()
  339. .empty()
  340. .fadeIn('slow',function(){
  341. loadSuppliersList();
  342. });
  343. }
  344. });
  345. });
  346. }
Add Comment
Please, Sign In to add comment