jstreeAJAX.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. $(document).ready(function () {
  2. const types = ["工程概要", "工程計算書", "設計圖", "數量計算書", "工程預算書", "施工規範及特定條款", "設計報告書"];
  3. var path = '';
  4. var category = '';
  5. var project_id = '';
  6. var project_name = '';
  7. var project = '';
  8. var blueprint_SN = '';
  9. var blueprint_path = '';
  10. var notes = [];
  11. var tempTable = [];
  12. var tempTable2 = [];
  13. var tree_data; //save getTree ajax data
  14. var start = true;
  15. var folderPath = "";
  16. var fileNums = [];
  17. var is_blueprint2 = false;
  18. PDFObject.embed("./assets/null.pdf", "#pdfFile");
  19. var table = $('#datatable-ajax').DataTable({
  20. bProcessing: true,
  21. responsive: true,
  22. "pagingType": "full_numbers",
  23. "bLengthChange": true,
  24. "lengthMenu": [
  25. [7, 10, 25, -1],
  26. [7, 10, 25, "全部"]
  27. ],
  28. "searching": false,
  29. "pageLength": 7,
  30. "language": {
  31. "processing": "處理中...",
  32. "loadingRecords": "載入中...",
  33. "lengthMenu": "顯示 _MENU_ 項結果",
  34. "zeroRecords": "沒有符合的結果或是沒有資料",
  35. "info": "顯示第 _START_ 至 _END_ 項結果,共 _TOTAL_ 項",
  36. "infoEmpty": "顯示第 0 至 0 項結果,共 0 項",
  37. "infoFiltered": "(從 _MAX_ 項結果中過濾)",
  38. "infoPostFix": "",
  39. "search": "搜尋:",
  40. "paginate": {
  41. "first": '<i class="fa fa-step-backward"></i>',
  42. "previous": '<i class="fa fa-backward"></i>',
  43. "next": '<i class="fa fa-forward"></i>',
  44. "last": '<i class="fa fa-step-forward"></i>'
  45. },
  46. "aria": {
  47. "sortAscending": ": 升冪排列",
  48. "sortDescending": ": 降冪排列"
  49. }
  50. },
  51. "columns": [{
  52. "width": "5%"
  53. },
  54. null,
  55. null,
  56. {
  57. "width": "5%"
  58. }, {
  59. "width": "5%"
  60. },
  61. ],
  62. data: [
  63. [
  64. " ", "", "", "", "",
  65. ],
  66. [
  67. " ", "", "", "", "",
  68. ],
  69. [
  70. " ", "", "", "", "",
  71. ],
  72. [
  73. " ", "", "", "", "",
  74. ],
  75. [
  76. " ", "", "", "", "",
  77. ],
  78. [
  79. " ", "", "", "", "",
  80. ],
  81. [
  82. " ", "", "", "", "",
  83. ]
  84. ],
  85. drawCallback: function () {
  86. if (!start) {
  87. var api = this.api();
  88. var rowCount = api.rows({
  89. page: 'current'
  90. }).count();
  91. for (var i = 0; i < api.page.len() - (rowCount === 0 ? 1 : rowCount); i++) {
  92. $('#datatable-ajax tbody').append($("<tr><td>&nbsp;</td><td></td><td></td><td></td></tr>"));
  93. }
  94. }
  95. start = false;
  96. },
  97. });
  98. $("#datatable-ajax_length").append($("#reset"))
  99. $.ajax({
  100. url: "./script/php/getTree.php",
  101. contentType: "application/json",
  102. dataType: "json",
  103. type: "GET",
  104. async: false
  105. })
  106. .success(function (response) {
  107. tree_data = response;
  108. }).error(function (error) {
  109. console.log(error);
  110. });
  111. //var table = $('#datatable-ajax').DataTable();
  112. displayDetail(false);
  113. $('#treeAjaxHTML').jstree({
  114. 'core': {
  115. 'themes': {
  116. variant: 'large'
  117. },
  118. 'data': tree_data,
  119. 'multiple': false,
  120. 'animation': 40,
  121. 'expand_selected_onload': true
  122. },
  123. 'types': {
  124. 'default': {
  125. 'icon': 'fa fa-folder'
  126. },
  127. 'file': {
  128. 'icon': 'fa fa-file'
  129. }
  130. },
  131. 'plugins': ['types', 'search', 'wholerow']
  132. }).bind("loaded.jstree", function (event, data) {
  133. var searchURL = window.location.search;
  134. searchURL = searchURL.substring(1, searchURL.length);
  135. if (searchURL.includes("=")) {
  136. type = decodeURIComponent(searchURL.split("&")[0].split("=")[1]);
  137. $(this).jstree("open_all");
  138. }
  139. }).on(
  140. 'select_node.jstree',
  141. function (event, data) {
  142. if (data.node.text.includes("-")) {
  143. $("#reset").prop("disabled", false);
  144. $("#header").empty();
  145. displayDetail(false);
  146. project_id = data.node.text.split("-")[0];
  147. project_name = data.node.text.split("-")[1];
  148. project = data.node.text;
  149. $("#project-id").val(project_id)
  150. $("#header").empty();
  151. category = $('#treeAjaxHTML').jstree(true).get_node(data.node.parents[0]).text;
  152. var span = $('<span>' + project + ' > </span>');
  153. span.on("click", function (e) {
  154. displayDetail(false);
  155. is_blueprint2 = false;
  156. for (var k = folderPath.length - 1; k > 0; k--) {
  157. $("#header").children().eq(k).remove();
  158. folderPath.pop();
  159. }
  160. let i = 1;
  161. table.clear().draw();
  162. tempTable = [];
  163. types.forEach(function (data) {
  164. let temp = [
  165. i,
  166. data,
  167. category,
  168. '',
  169. fileNums[i - 1].total,
  170. project,
  171. ];
  172. table.row.add(temp).draw();
  173. tempTable.push(temp);
  174. i++;
  175. });
  176. $("#tableDetail td").empty();
  177. });
  178. $("#header").append(span);
  179. //$("#header").append("<span>" + project + " > </span>");
  180. let i = 1;
  181. table.clear().draw();
  182. tempTable = [];
  183. countFiles(project_id, "false");
  184. types.forEach(function (data) {
  185. let temp = [
  186. i,
  187. data,
  188. category,
  189. '',
  190. fileNums[i - 1].total,
  191. project,
  192. ];
  193. table.row.add(temp).draw();
  194. tempTable.push(temp);
  195. i++;
  196. });
  197. $("#tableDetail td").empty();
  198. } else {
  199. data.instance.toggle_node(data.node);
  200. }
  201. displayDetail(false);
  202. });
  203. $('#btn-search').click(function () {
  204. $("#reset").prop("disabled", true);
  205. $("#header").empty();
  206. $("#header").append("<span>搜尋結果</span>");
  207. $.ajax({
  208. url: "./script/php/search.php",
  209. data: {
  210. search: $("#search").val(),
  211. },
  212. async: false,
  213. contentType: "application/json",
  214. dataType: "json",
  215. type: "GET",
  216. })
  217. .success(function (response) {
  218. displayDetail(true);
  219. table.clear().draw();
  220. $("#tableDetail td").empty();
  221. response.forEach(function (data) {
  222. let temp = [
  223. data["SN"],
  224. data["original_name"].slice(6),
  225. data["keyword"],
  226. '1.0.0',
  227. data["project_id"],
  228. data["project_name"],
  229. data["type_id"],
  230. data["category_name"],
  231. data["notes"],
  232. data["filename"],
  233. ];
  234. table.row.add(temp).draw();
  235. i++;
  236. });
  237. })
  238. .error(function (error) {
  239. console.log(error);
  240. })
  241. .complete(function () {});
  242. });
  243. $('#search').keyup(function (e) {
  244. if (e.keyCode == 13) {
  245. $('#btn-search').click();
  246. }
  247. });
  248. $('#reset').click(function () {
  249. if (folderPath.length != 1) {
  250. folderPath.pop();
  251. let index = folderPath.length;
  252. $("#header").children().eq(index).remove();
  253. table.clear().draw();
  254. if (is_blueprint2) {
  255. tempTable2.forEach(function (data) {
  256. table.row.add(data).draw();
  257. });
  258. is_blueprint2 = false;
  259. } else {
  260. tempTable.forEach(function (data) {
  261. table.row.add(data).draw();
  262. });
  263. }
  264. $("#tableDetail td").empty();
  265. displayDetail(false);
  266. }
  267. });
  268. $('#datatable-ajax tbody').on('click', 'tr', function () {
  269. $("#reset").prop("disabled", false);
  270. $(this).parent().find("tr").css('background-color', '');
  271. $(this).css("background-color", "#cccccc");
  272. $("#tableDetail td").empty();
  273. var data = table.row(this).data();
  274. if (data == null) {
  275. data = ["", "", "null", "", "", "", "", "", "", ""];
  276. }
  277. let project_id = data[5].split("-")[0];
  278. let SN = data[0];
  279. let is_blueprint = data[1] == "設計圖" ? true : false;
  280. let note = notes.includes(data[1]) ? data[1] : '';
  281. if (data[2] == 'null') {
  282. $("#tableDetail td").empty();
  283. } else if (data[3] == '') {
  284. path = data[1];
  285. $.ajax({
  286. url: "./script/php/getDetail.php",
  287. data: {
  288. project_id: project_id,
  289. type_id: SN,
  290. is_blueprint: is_blueprint,
  291. note: note
  292. },
  293. async: false,
  294. contentType: "application/json",
  295. dataType: "json",
  296. type: "GET",
  297. })
  298. .success(function (response) {
  299. var span = $('<span>' + data[1] + ' > </span>');
  300. span.on("click", function (e) {
  301. let clicked = $(e.target).text().split(" > ")[0];
  302. let index = folderPath.indexOf(clicked);
  303. for (k = index + 1; k < folderPath.length; k++) {
  304. $("#header").children().eq(k).remove();
  305. folderPath.pop();
  306. }
  307. addTable(data, notes, response, SN, path);
  308. is_blueprint2 = false;
  309. });
  310. $("#header").append(span);
  311. folderPath = $("#header").text().split(" > ");
  312. folderPath.pop();
  313. addTable(data, notes, response, SN, path);
  314. })
  315. .error(function (error) {
  316. console.log(error);
  317. })
  318. .complete(function () {});
  319. } else {
  320. let type = types[parseInt(data[7]) - 1];
  321. let path = '';
  322. //let category = data[8];
  323. if (data[7] == 3) {
  324. path = data[8] + "/" + data[5] + "-" + data[6] + "/" + data[7] + "_" + type + "/" + data[9] + "/" + data[10];
  325. } else {
  326. path = data[8] + "/" + data[5] + "-" + data[6] + "/" + data[7] + "_" + type + "/" + data[10];
  327. }
  328. $("#plan_code").text(data[5]);
  329. $("#plan_name").text(data[6]);
  330. $("#download").append('<img src="./assets/images/' + 'pdf-icon.png" style="height: 30px; display: inline-block;"> ');
  331. $("#download").append('<a target="_blank" href="./assets/建置資料/' + path + '">' + data[10] + '</a>');
  332. $("#version").text(data[3]);
  333. $("#fileName").text(data[1]);
  334. PDFObject.embed("./assets/建置資料/" + path, "#pdfFile");
  335. }
  336. });
  337. function displayDetail(status) {
  338. if (status) {
  339. table.column(2).visible(true);
  340. table.column(3).visible(true);
  341. table.column(4).visible(false);
  342. $(".table-responsive").show();
  343. $("#SN").text("圖號");
  344. $("#name").text("圖名");
  345. $('.nav-tabs a[href="#pdfTab"]').tab('show');
  346. } else {
  347. table.column(2).visible(false);
  348. table.column(3).visible(false);
  349. table.column(4).visible(true);
  350. $(".table-responsive").hide();
  351. $("#SN").text("項次");
  352. $("#name").text("類別");
  353. table.page.len(7).draw();
  354. $('.nav-tabs a[href="#arcgisTab"]').tab('show');
  355. }
  356. }
  357. function countFiles(project_id, is_blueprint) {
  358. $.ajax({
  359. url: "./script/php/get_file_count.php",
  360. data: {
  361. project_id: project_id,
  362. is_blueprint: is_blueprint,
  363. },
  364. async: false,
  365. //contentType: "application/json",
  366. dataType: "json",
  367. type: "POST",
  368. })
  369. .success(function (response) {
  370. console.log(response);
  371. fileNums = response;
  372. })
  373. .error(function (error) {
  374. console.log(error);
  375. })
  376. .complete(function () {});
  377. }
  378. function addTable(data, notes, response, SN, path) {
  379. table.clear().draw();
  380. table.page.len(10).draw();
  381. if (data[1] != "設計圖") {
  382. displayDetail(true);
  383. if (notes.includes(data[1])) {
  384. is_blueprint2 = true;
  385. }
  386. for (i = 0; i < response.length; i++) {
  387. table.row.add([
  388. response[i]["SN"],
  389. response[i]["original_name"].slice(6),
  390. response[i]["keyword"],
  391. '1.0.0',
  392. '',
  393. response[i]["project_id"],
  394. response[i]["project_name"],
  395. response[i]["type_id"],
  396. response[i]["category_name"],
  397. response[i]["notes"],
  398. response[i]["filename"],
  399. ])
  400. table.draw();
  401. }
  402. } else {
  403. displayDetail(false);
  404. blueprint_SN = SN;
  405. blueprint_path = path;
  406. tempTable2 = [];
  407. countFiles(project_id, "true");
  408. for (i = 0; i < response.length; i++) {
  409. notes[i] = response[i]['notes'];
  410. let temp = [
  411. i + 1,
  412. response[i]['notes'],
  413. '',
  414. '',
  415. fileNums[i].total,
  416. data[5],
  417. ];
  418. table.row.add(temp);
  419. tempTable2.push(temp);
  420. }
  421. table.draw();
  422. }
  423. }
  424. });