Advertisement
NikolayPaskulov

Untitled

Oct 29th, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.65 KB | None | 0 0
  1. var itemsList = {},
  2. clientsList = {},
  3. prevRow,
  4. prevCol = 0,
  5. tableHeader = document.getElementById('table-header'),
  6. docsWrapper = document.getElementById('docsWrapper'),
  7. mainWrapper = document.getElementById('main-wrapper'),
  8. firstDateInput = document.getElementById('firstDate'),
  9. clientSelect = document.getElementById('clientSelect'),
  10. storesSelect = document.getElementById('storesSelect'),
  11. secDateInput = document.getElementById('secDate'),
  12. checkBox = document.getElementById('checkBox'),
  13. clientsWithDocsBtn = document.getElementById('all-clients-with-docs'),
  14. table = document.getElementById('table'),
  15. storesList,
  16. motherShip = [],
  17. store = {};
  18.  
  19. var r1 = ['objects', 'ЛЕЙДИ СОФИЯ АД'],
  20. r2 = ['items', 'ЛЕЙДИ СОФИЯ АД', '{"warehouse":"ОБЕКТИ:10 НЕСТАНДАРТНА ПРОДУКЦИЯ"}'];
  21.  
  22.  
  23. sendRequestToServer(JSON.stringify(r1), storesList);
  24. //sendRequestToServer('ГОТОВА ПРОДУКЦИЯ', 'store');
  25.  
  26. document.getElementById('test').onclick = function () {
  27. sendRequestToServer(JSON.stringify(['write', 'test', itemsList]));
  28. }
  29.  
  30. function sendRequestToServer(arr, v, check) {
  31. var request = new XMLHttpRequest();
  32. request.onreadystatechange = function () {
  33. if (request.readyState == 4 && request.status == 200) {
  34. if (v == storesList) {
  35. storesList = request.responseText;
  36. storesList = JSON.parse(storesList);
  37. fillStoresSelect(storesList);
  38. }
  39. if (v == 'store') {
  40. v = request.responseText;
  41. v = v.replace(/""/g, '"');
  42. reformatString(v, 0, 0);
  43. v = JSON.parse(v);
  44. fillDocuments(v);
  45. changeStore(v);
  46. if (check) {
  47. var d2 = new Date();
  48. console.log(d2.valueOf());
  49. roundAllStores(motherShip);
  50. }
  51. }
  52.  
  53. }
  54. }
  55. request.open("POST", "http://192.168.1.184:8000/pm", true);
  56. //request.open("POST", "http://127.0.0.1:8888/", true);
  57. request.send(arr);
  58.  
  59. }
  60.  
  61.  
  62.  
  63. function reformatString(str, indexA, indexB) {
  64. console.log(str);
  65. var right = str.match(/{/g),
  66. left = str.match(/}/g),
  67. newStr;
  68. if (right.length == left.length) return
  69.  
  70. if (str.lastIndexOf('{') > str.lastIndexOf('}')) {
  71. newStr = str.slice(0, str.lastIndexOf(']')) + '}]';
  72. }
  73. if(str.lastIndexOf('}') == indexB) return
  74.  
  75. var firstIndexOfRight = str.indexOf('{', indexA),
  76. firstIndexOfLeft = str.indexOf('}', firstIndexOfRight + 1),
  77. nextIndexOfRight = str.indexOf('{', firstIndexOfRight + 1);
  78.  
  79. if (nextIndexOfRight < firstIndexOfLeft) {
  80. if (str.lastIndexOf(':', nextIndexOfRight) < str.lastIndexOf(',', nextIndexOfRight)) {
  81. var lastIndexOfQ = str.lastIndexOf('"', nextIndexOfRight);
  82. newStr = str.slice(0, lastIndexOfQ + 1) + '}' + str.slice(lastIndexOfQ + 1);
  83. }
  84. } else {
  85. newStr = str;
  86. }
  87.  
  88. reformatString(newStr, firstIndexOfRight + 1, firstIndexOfLeft);
  89. }
  90.  
  91.  
  92. function fillStoresSelect(arr) {
  93. strArray = ['<option style="display:none;">Избери склад</option><option>Всички</option>'];
  94.  
  95. for (var i = 0; i < arr.length; i++) {
  96. strArray.push("<option value='" + '{"warehouse":' + '"' + arr[i] + '"}' + "'>" + arr[i].slice(arr[i].lastIndexOf(':') + 1) + "</option>");
  97. }
  98. storesSelect.innerHTML += strArray.join('');
  99. }
  100.  
  101. storesSelect.onchange = function () {
  102. var selected = this.value;
  103. console.log(selected);
  104. if (selected == 'Всички') {
  105. motherShip = [];
  106. var d1 = new Date();
  107. console.log(d1.valueOf());
  108. for (var i = 0; i < storesList.length; i++) {
  109. if (i == storesList.length - 1) {
  110. sendRequestToServer(JSON.stringify(['items', 'ЛЕЙДИ СОФИЯ АД', storesList[i]]), 'store', true);
  111. } else {
  112. sendRequestToServer(JSON.stringify(['items', 'ЛЕЙДИ СОФИЯ АД', storesList[i]]), 'store');
  113. }
  114. }
  115. return;
  116. } else {
  117. sendRequestToServer(JSON.stringify(['items', 'ЛЕЙДИ СОФИЯ АД', selected]), 'store');
  118. }
  119. }
  120.  
  121. function roundAllStores(arr) {
  122. var d3 = new Date();
  123. console.log(d3.valueOf());
  124. store = arr[0];
  125. for (var i = 1; i < arr.length; i++) {
  126. for (var key in arr[i]) {
  127. if (store[key]) {
  128. if (arr[i][key].quantity) {
  129. store[key].quantity = Number(store[key].quantity) + Number(arr[i][key].quantity);
  130. } else {
  131. store[key].quantity = 0;
  132. }
  133.  
  134. } else {
  135. store[key] = {};
  136. if (arr[i][key].quantity) {
  137. store[key].quantity = Number(arr[i][key].quantity);
  138. } else {
  139. store[key].quantity = 0;
  140. }
  141. }
  142. }
  143. }
  144. var d4 = new Date();
  145. console.log(d4.valueOf());
  146. }
  147.  
  148. //Extract all items and clients from the main JSON and put them into two associative arrays
  149. function generateRef(obj) {
  150. for (var a = 0; a < obj.length; a++) {
  151. var currentDate = obj[a].date;
  152. if (checkIfDateIsValid(currentDate.slice(6, currentDate.length), currentDate.slice(4, 6), currentDate.slice(0, 4))) {
  153. fillclientsList(obj[a].partner, obj[a]);
  154. for (var b = 0; b < obj[a].Items.length; b++) {
  155. checkItems(obj[a].partner, obj[a].Items[b]);
  156. }
  157. }
  158. }
  159. }
  160.  
  161.  
  162.  
  163. //Convert store JSON into an object
  164. function changeStore(currentStore) {
  165. store = {};
  166. for (var i = 0; i < currentStore.length; i++) {
  167. store[currentStore[i].name] = currentStore[i];
  168. }
  169. motherShip.push(store);
  170. }
  171. //changeStore(storeFromJson);
  172.  
  173. //on every merchandise if array fill clients that have it with whole quantity
  174. function checkItems(client, march) {
  175. var client = client.slice(client.lastIndexOf(':') + 1);
  176. if (itemsList[march.name]) {
  177. if (itemsList[march.name][client]) {
  178. itemsList[march.name][client] = Number(itemsList[march.name][client]) + Number(march.quantity);
  179. } else {
  180. itemsList[march.name][client] = Number(march.quantity);
  181. }
  182. } else {
  183. itemsList[march.name] = {};
  184. itemsList[march.name][client] = Number(march.quantity);
  185. }
  186. }
  187.  
  188. //all clients with theys documents and full info on document
  189. function fillclientsList(name, obj) {
  190. var Items = {},
  191. name = name.slice(name.lastIndexOf(':') + 1);
  192.  
  193. if (clientsList[name]) {
  194. if (clientsList[name][obj.docNumber]) {
  195. return;
  196. } else {
  197. clientsList[name][obj.docNumber] = {
  198. date: obj.date,
  199. };
  200. }
  201. } else {
  202. clientsList[name] = {};
  203. clientsList[name][obj.docNumber] = {
  204. date: obj.date,
  205. };
  206. }
  207. for (var i = 0; i < obj.Items.length; i++) {
  208. if (Items[obj.Items[i].name]) {
  209. Items[obj.Items[i].name].quantity += Number(obj.Items[i].quantity);
  210. } else {
  211. Items[obj.Items[i].name] = {};
  212. Items[obj.Items[i].name].quantity = Number(obj.Items[i].quantity);
  213. }
  214. }
  215. clientsList[name][obj.docNumber]['Items'] = Items;
  216.  
  217. }
  218.  
  219. function buildTable(reUse) {
  220.  
  221. (function fillHeader() {
  222. var strArray = ['<div class="table-row"><div class="plain-cell">&nbsp;</div><div class="plain-cell">No</div>'],
  223. docArr = ['<div class="table-row"><div class="plain-cell">Док. номер</div><div class="plain-cell">&nbsp;</div>'],
  224. docDate = ['<div class="table-row"><div class="plain-cell">Док. дата</div><div class="plain-cell">&nbsp;</div>'];
  225. for (var key in clientsList) {
  226. if (reUse) {
  227. for (var prop in clientsList[key]) {
  228. var date = clientsList[key][prop].date;
  229. strArray.push('<div class="plain-cell no-print">' + key + '</div>')
  230. docArr.push('<div class="plain-cell">' + prop + '</div>');
  231. docDate.push('<div class="plain-cell">' + date.substr(6, 2) + '.' + date.substr(4, 2) + '.' + date.substr(0, 4) + '</div>');
  232. }
  233. }
  234. else {
  235. strArray.push('<div class="plain-cell no-print">' + key + '</div>');
  236. }
  237. }
  238. docArr.push('<div class="plain-cell">&nbsp;</div><div class="plain-cell">&nbsp;</div><div class="plain-cell">&nbsp;</div><div class="plain-cell">&nbsp;</div></div></div>')
  239. docDate.push('<div class="plain-cell">&nbsp;</div><div class="plain-cell">&nbsp;</div><div class="plain-cell">&nbsp;</div><div class="plain-cell">&nbsp;</div></div></div>')
  240. strArray.push('<div class="plain-cell">Общо планирани</div><div class="plain-cell">Количество от склад</div><div class="plain-cell">Блокирани</div><div class="plain-cell">Разлика</div></div>');
  241. if (reUse) {
  242. docsWrapper.innerHTML = docArr.join('') + docDate.join('');
  243. }
  244.  
  245. tableHeader.innerHTML = strArray.join('');
  246. resizeConteiners(tableHeader.children[0].children.length * 100 + 300);
  247. }());
  248.  
  249. (function fillRows() {
  250. var strArray = [],
  251. counter = 1,
  252. totalRowItems = 0;
  253.  
  254. for (var key in itemsList) {
  255. strArray.push('<div class="table-row"><div class="plain-cell">' + key + '</div><div class="plain-cell">' + counter + '</div>')
  256. for (var name in clientsList) {
  257. if (reUse) {
  258. var result = expandedRows(clientsList[name], key);
  259. strArray.push(result.html);
  260. totalRowItems += result.quantity;
  261. continue;
  262. }
  263. if (itemsList[key][name]) {
  264. strArray.push('<div class="plain-cell no-print">' + itemsList[key][name] + '</div>')
  265. totalRowItems += Number(itemsList[key][name]);
  266. } else {
  267. strArray.push('<div class="plain-cell no-print">&nbsp;</div>')
  268. }
  269. }
  270. var storeQuantity = (store[key].quantity === undefined) ? 0 : store[key].quantity,
  271. storeBlocked = (store[key].blocked != undefined) ? store[key].blocked : 0;
  272.  
  273.  
  274. quantitydifference = Number(storeQuantity) - 0 - totalRowItems;
  275. strArray.push('<div class="plain-cell">' + totalRowItems + '</div><div class="plain-cell">' + storeQuantity + '</div>' +
  276. '<div class="plain-cell">' + 0 + '</div>' +
  277. '<div class="plain-cell">' + quantitydifference + '</div></div>');
  278. counter++;
  279. totalRowItems = 0;
  280. }
  281.  
  282. if (reUse) {
  283. table.innerHTML = setSerialNumberRow(clientsList, true);
  284. }
  285. else {
  286. table.innerHTML = setSerialNumberRow(clientsList, false);
  287. }
  288. table.innerHTML += strArray.join('');
  289. printTotalQuantity();
  290. }());
  291. }
  292.  
  293. //Build row with serial number for each client or document
  294. function setSerialNumberRow(obj, isExpanded) {
  295. var strArr = [],
  296. prevProp,
  297. counter = 1;
  298.  
  299. strArr.push('<div class="table-row no-print"><div class="plain-cell">&nbsp;</div><div class="plain-cell">No</div>');
  300. for (var prop in obj) {
  301. strArr.push('<div class="plain-cell">' + counter + '</div>');
  302. counter++;
  303. if (isExpanded) {
  304. var countKeys = 0;
  305. for (var key in obj[prop]) {
  306. countKeys++;
  307. }
  308. for (var i = 0; i < countKeys - 1; i++) {
  309. strArr.push('<div class="plain-cell">&nbsp;</div>');
  310. }
  311. }
  312. prevProp = prop;
  313. }
  314. strArr.push('<div class="plain-cell">&nbsp;</div><div class="plain-cell">&nbsp;</div><div class="plain-cell">&nbsp;</div><div class="plain-cell">&nbsp;</div></div>');
  315. return strArr.join('');
  316. }
  317.  
  318. //expands basic table after click on chechbox
  319. function expandedRows(obj, itemName) {
  320. var strArray = [];
  321. totalRowItems = 0;
  322. for (var key in obj) {
  323. if (obj[key].Items[itemName]) {
  324. strArray.push('<div class="plain-cell no-print">' + obj[key].Items[itemName].quantity + '</div>');
  325. totalRowItems += Number(obj[key].Items[itemName].quantity);
  326. } else {
  327. strArray.push('<div class="plain-cell no-print">&nbsp;</div>');
  328. }
  329. }
  330. return {
  331. html: strArray.join(''),
  332. quantity: totalRowItems
  333. }
  334. }
  335.  
  336. //Visualize all documents from client chosen by click on the header
  337. tableHeader.onclick = function (e) {
  338.  
  339. var target = (typeof (event) != 'undefined') ? event.srcElement.outerText : e.target.innerHTML,
  340. checkBiggerWidth = 0;
  341. if (target == 'No' || target == 'Общо планирани' || target == 'Количество от склад' ||
  342. target == 'Блокирани' || target == 'Разлика' || target == '') {
  343. return;
  344. }
  345.  
  346. if (target == 'Всички') {
  347. clientsWithDocsBtn.disabled = false;
  348. clientsWithDocsBtn.checked = false;
  349. if (!checkBox.checked) {
  350. checkBox.click();
  351. }
  352. docsWrapper.style.display = 'none';
  353. buildTable();
  354. return;
  355. }
  356. docsWrapper.style.display = '';
  357. changeHeaderAfterClick(target);
  358. clientsWithDocsBtn.disabled = true;
  359. resizeConteiners(docsWrapper.childNodes[0].children.length * 100 + 300)
  360. };
  361.  
  362. //after click on some cell change color of a cell row and col
  363. table.onclick = function (ev) {
  364. var target = (typeof (event) != 'undefined') ? event.srcElement : ev.target;
  365. if (target.className == 'plain-cell no-print') {
  366. var rows = document.querySelectorAll('#table .table-row');
  367.  
  368. if (prevCol <= rows[0].children.length) {
  369. for (var z = 0; z < rows.length; z++) {
  370. rows[z].children[prevCol].style.backgroundColor = '';
  371. }
  372. }
  373. if (prevCol == Array.prototype.indexOf.call(target.parentNode.childNodes, target) && prevRow == target.parentNode) {
  374. prevRow.style.backgroundColor = '';
  375. prevCol = 0;
  376. return;
  377. }
  378. prevCol = Array.prototype.indexOf.call(target.parentNode.childNodes, target);
  379. for (var z = 0; z < rows.length; z++) {
  380. rows[z].children[prevCol].style.backgroundColor = 'lightBlue';
  381. }
  382.  
  383. if (prevRow) {
  384. prevRow.style.backgroundColor = '';
  385. }
  386. prevRow = target.parentNode;
  387. prevRow.style.backgroundColor = 'lightblue';
  388. target.style.backgroundColor = '#bde0eb';
  389. }
  390. };
  391.  
  392. //fill table with data for clicked client
  393. function fillTableAfterClick(targetName) {
  394. var strArray = [],
  395. invoiceNumber = [],
  396. invoiceDate = [],
  397. rowCounter = 1,
  398. iterationCounter = 0,
  399. countRowItems = 0;
  400.  
  401. invoiceNumber.push('<div class="table-row no-print"><div class="plain-cell">Док.ном</div><div class="plain-cell">&nbsp;</div>')
  402. invoiceDate.push('<div class="table-row no-print"><div class="plain-cell">Дата</div><div class="plain-cell">&nbsp;</div>')
  403.  
  404. var itemsArr = extractItemsFromClient(clientsList[targetName]);
  405. for (var name in itemsArr) {
  406. strArray.push('<div class="table-row"><div class="plain-cell">' + name + '</div><div class="plain-cell">' + rowCounter + '</div>');
  407. var clientKeys = 0;
  408. for (var keys in clientsList[targetName]) {
  409. clientKeys++;
  410. }
  411. for (var key in clientsList[targetName]) {
  412. if (iterationCounter < clientKeys) {
  413. var currentDate = clientsList[targetName][key].date;
  414. invoiceNumber.push('<div class="plain-cell">' + key + '</div>')
  415. invoiceDate.push('<div class="plain-cell">' + currentDate.slice(6, currentDate.length) + '.' + currentDate.slice(4, 6) + '.' + currentDate.slice(0, 4) + '</div>')
  416. }
  417. if (clientsList[targetName][key].Items[name]) {
  418. strArray.push('<div class="plain-cell no-print">' + clientsList[targetName][key].Items[name].quantity + '</div>');
  419. countRowItems += Number(clientsList[targetName][key].Items[name].quantity);
  420. } else {
  421. strArray.push('<div class="plain-cell no-print">&nbsp;</div>');
  422. }
  423. iterationCounter++;
  424. }
  425. var storeQuantity = (store[name].quantity != undefined) ? store[name].quantity : 0,
  426. quantitydifference = Number(storeQuantity) - 0 - countRowItems;
  427.  
  428. strArray.push('<div class="plain-cell">' + countRowItems + '</div><div class="plain-cell">' + storeQuantity + '</div>' +
  429. '<div class="plain-cell">' + 0 + '</div><div class="plain-cell">' + quantitydifference + '</div>');
  430. strArray.push('</div>');
  431. countRowItems = 0;
  432. rowCounter++;
  433. }
  434. invoiceNumber.push('<div class="plain-cell">&nbsp;</div><div class="plain-cell">&nbsp;</div><div class="plain-cell">&nbsp;</div><div class="plain-cell">&nbsp;</div></div>')
  435. invoiceDate.push('<div class="plain-cell">&nbsp;</div><div class="plain-cell">&nbsp;</div><div class="plain-cell">&nbsp;</div><div class="plain-cell">&nbsp;</div></div>')
  436. docsWrapper.innerHTML = invoiceNumber.join('') + invoiceDate.join('');
  437. table.innerHTML = setSerialNumberRow(clientsList[targetName], false) + strArray.join('');
  438. printTotalQuantity();
  439. }
  440.  
  441. //fill footer with calculated data from colums
  442. function printTotalQuantity() {
  443. var strArray = ['<div class="table-row"><div class="plain-cell">Общо</div><div class="plain-cell">&nbsp;</div>'],
  444. sum = 0;
  445. for (var i = 2; i < table.children[0].children.length; i++) {
  446. for (var z = 1; z < table.children.length - 1; z++) {
  447. sum += Number(table.children[z].children[i].innerHTML == '&nbsp;' ? '' : table.children[z].children[i].innerHTML);
  448. }
  449. if (i < table.children[0].children.length - 4) {
  450. strArray.push('<div class="plain-cell no-print">' + sum + '</div>')
  451. }
  452. else {
  453. strArray.push('<div class="plain-cell">' + sum + '</div>')
  454. }
  455. sum = 0;
  456. }
  457. strArray.push('</div>');
  458. table.innerHTML += strArray.join('');
  459. }
  460.  
  461. //extract only items that are in all clients
  462. function extractItemsFromClient(client) {
  463. var result = {};
  464. for (var doc in client) {
  465. for (var item in client[doc].Items) {
  466. if (!result[item]) result[item] = {};
  467. }
  468. }
  469. return result;
  470. }
  471.  
  472. document.getElementById('show-reference').onclick = checkIfDatesInputAreActive;
  473.  
  474. document.getElementById('firstDate').onchange = fillSelectWithClients;
  475.  
  476. document.getElementById('secDate').onchange = fillSelectWithClients;
  477.  
  478.  
  479. function fillSelectWithClients() {
  480. var strArray = [];
  481. if (firstDateInput.value && secDateInput.value) {
  482. strArray.push('<option>Всички</option>');
  483. itemsList = {};
  484. clientsList = {};
  485. generateRef(json);
  486.  
  487. for (var name in clientsList) {
  488. strArray.push('<option>' + name + '</option>');
  489. }
  490. }
  491. clientSelect.innerHTML = strArray.join('');
  492. }
  493.  
  494. //change header with only clicked client name and empty cells; call fillTableAfterClick with client name
  495. function changeHeaderAfterClick(name) {
  496. tableHeader.innerHTML = '<div class="table-row"><div class="plain-cell">&nbsp;</div><div class="plain-cell">No</div><div class="plain-cell no-print">' + name + '</div><div class="plain-cell no-print" id="empty-cell"></div><div class="plain-cell">Общо планирани</div>' +
  497. '<div class="plain-cell">Количество от склад</div><div class="plain-cell">Блокирани</div><div class="plain-cell">Разлика</div></div>';
  498. fillTableAfterClick(name);
  499. clientsWithDocsBtn.checked = true;
  500. clientsWithDocsBtn.disabled = true;
  501. tableHeader.childNodes[0].firstChild.innerHTML = 'Всички';
  502. }
  503.  
  504. function checkIfDatesInputAreActive() {
  505. var clientSelectValue = clientSelect.options[clientSelect.selectedIndex].value;
  506. if (firstDateInput.value && secDateInput.value) {
  507. checkBox.disabled = false;
  508. if (clientSelectValue != 'Всички') {
  509. docsWrapper.style.display = '';
  510. changeHeaderAfterClick(clientSelectValue);
  511. if (!checkBox.checked) {
  512. checkBox.click();
  513. }
  514. resizeConteiners(docsWrapper.children[0].children.length * 100 + 300)
  515. return;
  516. }
  517. clientsList = {};
  518. itemsList = {};
  519. generateRef(json);
  520.  
  521. if (!checkBox.checked) {
  522. checkBox.click();
  523. }
  524. if (clientsWithDocsBtn.disabled) {
  525. clientsWithDocsBtn.disabled = false;
  526. }
  527. if (clientsWithDocsBtn.checked) {
  528. clientsWithDocsBtn.checked = false;
  529. }
  530. docsWrapper.style.display = 'none';
  531. buildTable();
  532. }
  533. }
  534.  
  535. //find only dates that are in range
  536. function checkIfDateIsValid(day, month, year) {
  537. var firstDateInput = document.getElementById('firstDate'),
  538. secDateInput = document.getElementById('secDate'),
  539. regEx = /[0-9]+/g,
  540. firstDateArray,
  541. secDateArray;
  542.  
  543. firstDateArray = firstDateInput.value.match(regEx);
  544. secDateArray = secDateInput.value.match(regEx);
  545. if (firstDateArray && secDateArray) {
  546. var prevDate = new Date(firstDateArray[0], (firstDateArray[1] - 1), firstDateArray[2], 0, 0, 0, 0);
  547. var currentDate = new Date(secDateArray[0], (secDateArray[1] - 1), secDateArray[2], 0, 0, 0, 0);
  548.  
  549. if (prevDate > currentDate) {
  550. return;
  551. }
  552.  
  553. var productDate = new Date(year, (Number(month) - 1), Number(day), 0, 0, 0, 0);
  554. if (productDate.valueOf() >= prevDate.valueOf() && productDate.valueOf() <= currentDate.valueOf()) {
  555. return true;
  556. } else {
  557. return false;
  558. }
  559. }
  560. }
  561.  
  562. checkBox.onclick = function () {
  563. if (!this.checked) {
  564. document.head.innerHTML += '<style>.no-print{display:none}</style>';
  565. resizeConteiners(table.offsetWidth);
  566. docsWrapper.style.display = 'none';
  567. }
  568. else {
  569. document.head.removeChild(document.querySelectorAll('style')[0]);
  570. resizeConteiners(table.children[0].children.length * 100 + 300);
  571. if (clientsWithDocsBtn.checked) {
  572. docsWrapper.style.display = '';
  573. } else {
  574. docsWrapper.style.display = 'none';
  575. }
  576. }
  577. if (prevRow) {
  578. prevRow.style.backgroundColor = '';
  579. }
  580. };
  581.  
  582. clientsWithDocsBtn.onclick = function () {
  583. if (this.checked) {
  584. buildTable(true)
  585. docsWrapper.style.display = '';
  586. if (!checkBox.checked) checkBox.click();
  587. }
  588. else {
  589. buildTable();
  590. resizeConteiners(table.offsetWidth);
  591. docsWrapper.style.display = 'none';
  592. }
  593. };
  594.  
  595. function resizeConteiners(size) {
  596. docsWrapper.style.width = size + 'px';
  597. mainWrapper.style.width = size + 2 + 'px';
  598. tableHeader.childNodes[0].style.width = size + 'px';
  599.  
  600. if (docsWrapper.children.length == 0) {
  601. return;
  602. }
  603. if (!document.getElementById('empty-cell')) {
  604. return;
  605. }
  606. document.getElementById('empty-cell').style.width = (docsWrapper.offsetWidth - 1000) + 'px';
  607. if (docsWrapper.children[0].children.length <= 7) {
  608. document.getElementById('empty-cell').style.display = 'none'
  609. }
  610. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement