Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.87 KB | None | 0 0
  1. $(document).ready( function() {
  2. console.log('operations View');
  3. if (!localStorage.getItem('isLogged')) {
  4. $("#app").load("./views/login.html");
  5. return;
  6. }
  7. console.log(JSON.parse(localStorage.getItem('selectedAction')))
  8.  
  9. $('#test').on('click', function() {
  10. $("#app").load("./views/action.html");
  11. });
  12.  
  13. Operations.initialize();
  14. });
  15.  
  16. var Operations = {
  17.  
  18. initialize: function()
  19. {
  20. this.dockInfo = {};
  21. this.scanData = {};
  22. this.scan = '';
  23. this.operation = {};
  24. this.lp = 1;
  25. this.setOperation();
  26. this.setButtons();
  27. },
  28.  
  29. setOperation: function()
  30. {
  31. var urlParams = $.param({
  32. id: JSON.parse(localStorage.getItem('selectedAction')).id
  33. });
  34.  
  35. $.ajax({
  36. url: "http://192.168.0.204:63165/api/get/doknag" + '?' + urlParams,
  37. type: "PATCH",
  38. beforeSend: function(request) {
  39. request.setRequestHeader("Authorization", localStorage.getItem('token'));
  40. request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  41. },
  42. success: function() {
  43. Operations.getDockInfo();
  44. },
  45. error: function(err) {
  46.  
  47. }
  48. });
  49. },
  50.  
  51. getDockInfo: function()
  52. {
  53. $.ajax({
  54. url: "http://192.168.0.204:63165/api/get/get/?query=DockInfo",
  55. type: "get",
  56. beforeSend: function(request) {
  57. request.setRequestHeader("Authorization", localStorage.getItem('token'));
  58. request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  59. },
  60. success: function(response) {
  61. Operations.setDockInfo(response);
  62. Operations.fillStockInfoData();
  63. },
  64. error: function(err) {
  65.  
  66. }
  67. });
  68. },
  69.  
  70. setDockInfo: function(dockInfo)
  71. {
  72. this.dockInfo = dockInfo[0];
  73. },
  74.  
  75. fillStockInfoData: function()
  76. {
  77. if (!Operations.dockInfo) {
  78. return;
  79. }
  80.  
  81. $('#dokDok').text(Operations.dockInfo.dok);
  82. },
  83.  
  84. setButtons: function()
  85. {
  86. $('#scan').bind('click', function() {
  87. Operations.runScanner();
  88. });
  89.  
  90. $('#clearProductData').bind('click', function() {
  91. Operations.clearInputs();
  92. });
  93.  
  94. $('#clearProductCount').bind('click', function() {
  95. $('#productCount').val('');
  96. });
  97.  
  98. $('#save').bind('click', function() {
  99. Operations.saveOperation();
  100. });
  101.  
  102. $('#goBack').bind('click', function () {
  103. $("#app").load("./views/action.html");
  104. });
  105. },
  106.  
  107. runScanner: function()
  108. {
  109. cordova.plugins.barcodeScanner.scan(
  110. function (result) {
  111. var scanCodeResult = result.text;
  112.  
  113. if (!scanCodeResult) {
  114. alert('scan failed');
  115. return;
  116. }
  117.  
  118. Operations.scan = scanCodeResult;
  119.  
  120. Operations.clearInputs();
  121. Operations.getScanData(scanCodeResult)
  122. },
  123. function (error) {
  124. alert("Scanning failed: " + error);
  125. }
  126. );
  127. },
  128.  
  129. getScanData: function(code)
  130. {
  131.  
  132. console.log(code);
  133. if (!code) {
  134. return;
  135. }
  136.  
  137. $.ajax({
  138. url: "http://192.168.0.204:63165/api/get/get/?query=IndeksInfo&param=" + code,
  139. type: "get",
  140. beforeSend: function(request) {
  141. request.setRequestHeader("Authorization", localStorage.getItem('token'));
  142. request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  143. },
  144. success: function(response) {
  145. Operations.setScanData(response);
  146. Operations.fillCodeInfoData()
  147. },
  148. error: function(err) {
  149.  
  150. }
  151. });
  152. },
  153.  
  154. setScanData: function(scanData)
  155. {
  156. this.scanData = scanData[0];
  157. },
  158.  
  159. fillCodeInfoData: function ()
  160. {
  161. if (!Operations.scanData) {
  162. console.log('no scan data');
  163. return;
  164. }
  165.  
  166. $('#productCode').val(Operations.scan);
  167. $('#productCount').attr({
  168. "max" : Operations.scanData.ilosc,
  169. });
  170.  
  171. $('#productName').text(Operations.scanData.nazwa);
  172. $('#productMagCount').text(Operations.scanData.ilosc);
  173. $('#productUnit').text(Operations.scanData.jm);
  174. },
  175.  
  176. saveOperation: function()
  177. {
  178. if (0) { // inputs filled
  179. return;
  180. }
  181.  
  182. this.operation = {
  183. IdOp: JSON.parse(localStorage.getItem('selectedAction')).id,
  184. Nid: this.dockInfo.nid,
  185. Index: this.scan,
  186. Quantity: $('#productCount').val()
  187. };
  188.  
  189. console.log(this.operation);
  190. //DokPoz/?IdOp=1&Nid=2331239&Indeks=SBZSCA00400000001&Quantity=3
  191.  
  192. $.ajax({
  193. url: "http://192.168.0.204:63165/api/get/DokPoz/?" +
  194. 'IdOp=' + this.operation.IdOp +
  195. '&Nid=' + this.operation.Nid +
  196. '&Indeks=' + this.operation.Index +
  197. '&Quantity=' + this.operation.Quantity ,
  198. type: "PATCH",
  199. beforeSend: function(request) {
  200. request.setRequestHeader("Authorization", localStorage.getItem('token'));
  201. request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  202. },
  203. success: function(response) {
  204. Operations.setOperationResult()
  205. },
  206. error: function(err) {
  207.  
  208. }
  209. });
  210. },
  211.  
  212. setOperationResult: function()
  213. {
  214. $('#operationsResults').append($('<div>', {
  215. class: Operations.lp % 2 === 0 ? 'row bg' : 'row',
  216. }).append(
  217. $('<div>', {
  218. class: 'col-xs-1',
  219. text: Operations.lp
  220. })
  221. ).append(
  222. $('<div>', {
  223. class: 'col-xs-3',
  224. text: 'PKWIU'
  225. })
  226. ).append(
  227. $('<div>', {
  228. class: 'col-xs-5',
  229. text: Operations.scanData.nazwa
  230. })
  231. ).append(
  232. $('<div>', {
  233. class: 'col-xs-3',
  234. text: $('#productCount').val() + ' ' + Operations.scanData.jm
  235. })
  236. ));
  237.  
  238. Operations.lp++;
  239. },
  240.  
  241. clearInputs: function()
  242. {
  243. this.scanData = {};
  244.  
  245. $('#productCode').val('');
  246. $('#productCount').val('');
  247.  
  248. $('#productName').text('');
  249. $('#productMagCount').text('');
  250. $('#productUnit').text('');
  251. },
  252.  
  253.  
  254. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement