jstreeAJAX.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  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. displayDetail(false);
  112. $('#treeAjaxHTML').jstree({
  113. 'core': {
  114. 'themes': {
  115. variant: 'large'
  116. },
  117. 'data': tree_data,
  118. 'multiple': false,
  119. 'animation': 40,
  120. 'expand_selected_onload': true
  121. },
  122. 'types': {
  123. 'default': {
  124. 'icon': 'fa fa-folder'
  125. },
  126. 'file': {
  127. 'icon': 'fa fa-file'
  128. }
  129. },
  130. 'plugins': ['types', 'search', 'wholerow']
  131. }).bind("loaded.jstree", function (event, data) {
  132. var searchURL = window.location.search;
  133. searchURL = searchURL.substring(1, searchURL.length);
  134. if (searchURL.includes("=")) {
  135. type = decodeURIComponent(searchURL.split("&")[1].split("=")[1]);
  136. $(this).jstree("open_all");
  137. }
  138. }).on(
  139. 'select_node.jstree',
  140. function (event, data) {
  141. if (data.node.text.includes("-")) {
  142. $("#reset").prop("disabled", false);
  143. $("#header").empty();
  144. displayDetail(false);
  145. project_id = data.node.text.split("-")[0];
  146. project_name = data.node.text.split("-")[1];
  147. project = data.node.text;
  148. $("#project-id").val(project_id)
  149. $("#header").empty();
  150. category = $('#treeAjaxHTML').jstree(true).get_node(data.node.parents[0]).text;
  151. var span = $('<span>' + project + ' > </span>');
  152. span.on("click", function (e) {
  153. displayDetail(false);
  154. is_blueprint2 = false;
  155. for (var k = folderPath.length - 1; k > 0; k--) {
  156. $("#header").children().eq(k).remove();
  157. folderPath.pop();
  158. }
  159. let i = 1;
  160. table.clear().draw();
  161. tempTable = [];
  162. types.forEach(function (data) {
  163. let temp = [
  164. i,
  165. data,
  166. category,
  167. '',
  168. fileNums[i - 1].total,
  169. project,
  170. ];
  171. table.row.add(temp).draw();
  172. tempTable.push(temp);
  173. i++;
  174. });
  175. $("#tableDetail td").empty();
  176. });
  177. $("#header").append(span);
  178. let i = 1;
  179. table.clear().draw();
  180. tempTable = [];
  181. countFiles(project_id, "false");
  182. types.forEach(function (data) {
  183. let temp = [
  184. i,
  185. data,
  186. category,
  187. '',
  188. fileNums[i - 1].total,
  189. project,
  190. ];
  191. table.row.add(temp).draw();
  192. tempTable.push(temp);
  193. i++;
  194. });
  195. $("#tableDetail td").empty();
  196. } else {
  197. data.instance.toggle_node(data.node);
  198. }
  199. displayDetail(false);
  200. });
  201. $('#btn-search').click(function () {
  202. $("#reset").prop("disabled", true);
  203. $("#header").empty();
  204. $("#header").append("<span>搜尋結果</span>");
  205. $.ajax({
  206. url: "./script/php/search.php",
  207. data: {
  208. search: $("#search").val(),
  209. },
  210. async: false,
  211. contentType: "application/json",
  212. dataType: "json",
  213. type: "GET",
  214. })
  215. .success(function (response) {
  216. displayDetail(true);
  217. table.clear().draw();
  218. $("#tableDetail td").empty();
  219. response.forEach(function (data) {
  220. let temp = [
  221. data["SN"],
  222. data["original_name"],
  223. data["keyword"],
  224. '1.0.0',
  225. data["project_id"],
  226. data["project_name"],
  227. data["type_id"],
  228. data["category_name"],
  229. data["notes"],
  230. data["filename"],
  231. ];
  232. table.row.add(temp).draw();
  233. i++;
  234. });
  235. })
  236. .error(function (error) {
  237. console.log(error);
  238. })
  239. .complete(function () {});
  240. });
  241. $('#search').keyup(function (e) {
  242. if (e.keyCode == 13) {
  243. $('#btn-search').click();
  244. }
  245. });
  246. $('#reset').click(function () {
  247. if (folderPath.length != 1) {
  248. folderPath.pop();
  249. let index = folderPath.length;
  250. $("#header").children().eq(index).remove();
  251. table.clear().draw();
  252. if (is_blueprint2) {
  253. tempTable2.forEach(function (data) {
  254. table.row.add(data).draw();
  255. });
  256. is_blueprint2 = false;
  257. } else {
  258. tempTable.forEach(function (data) {
  259. table.row.add(data).draw();
  260. });
  261. }
  262. $("#tableDetail td").empty();
  263. displayDetail(false);
  264. }
  265. });
  266. $('#datatable-ajax tbody').on('click', 'tr', function () {
  267. $("#reset").prop("disabled", false);
  268. $(this).parent().find("tr").css('background-color', '');
  269. $(this).css("background-color", "#cccccc");
  270. $("#tableDetail td").empty();
  271. var data = table.row(this).data();
  272. if (data == null) {
  273. data = ["", "", "null", "", "", "", "", "", "", ""];
  274. }
  275. let project_id = data[5].split("-")[0];
  276. let SN = data[0];
  277. let is_blueprint = data[1] == "設計圖" ? true : false;
  278. let note = notes.includes(data[1]) ? data[1] : '';
  279. if (data[2] == 'null') {
  280. $("#tableDetail td").empty();
  281. } else if (data[3] == '') {
  282. path = data[1];
  283. $.ajax({
  284. url: "./script/php/getDetail.php",
  285. data: {
  286. project_id: project_id,
  287. type_id: SN,
  288. is_blueprint: is_blueprint,
  289. note: note
  290. },
  291. async: false,
  292. contentType: "application/json",
  293. dataType: "json",
  294. type: "GET",
  295. })
  296. .success(function (response) {
  297. var span = $('<span>' + data[1] + ' > </span>');
  298. span.on("click", function (e) {
  299. let clicked = $(e.target).text().split(" > ")[0];
  300. let index = folderPath.indexOf(clicked);
  301. for (k = index + 1; k < folderPath.length; k++) {
  302. $("#header").children().eq(k).remove();
  303. folderPath.pop();
  304. }
  305. addTable(data, notes, response, SN, path);
  306. is_blueprint2 = false;
  307. });
  308. $("#header").append(span);
  309. folderPath = $("#header").text().split(" > ");
  310. folderPath.pop();
  311. addTable(data, notes, response, SN, path);
  312. })
  313. .error(function (error) {
  314. console.log(error);
  315. })
  316. .complete(function () {});
  317. } else {
  318. let type = types[parseInt(data[7]) - 1];
  319. let path = '';
  320. //let category = data[8];
  321. if (data[7] == 3) {
  322. path = data[8] + "/" + data[5] + "-" + data[6] + "/" + data[7] + "_" + type + "/" + data[9] + "/" + data[10];
  323. } else {
  324. path = data[8] + "/" + data[5] + "-" + data[6] + "/" + data[7] + "_" + type + "/" + data[10];
  325. }
  326. $("#plan_code").text(data[5]);
  327. $("#plan_name").text(data[6]);
  328. $("#download").append('<img src="./assets/images/' + 'pdf-icon.png" style="height: 30px; display: inline-block;"> ');
  329. $("#download").append('<a target="_blank" href="./assets/建置資料/' + path + '">' + data[10] + '</a>');
  330. $("#version").text(data[3]);
  331. $("#fileName").text(data[1]);
  332. PDFObject.embed("./assets/建置資料/" + path, "#pdfFile");
  333. }
  334. });
  335. function displayDetail(status) {
  336. if (status) {
  337. table.column(2).visible(true);
  338. table.column(3).visible(true);
  339. table.column(4).visible(false);
  340. $(".table-responsive").show();
  341. $("#SN").text("圖號");
  342. $("#name").text("圖名");
  343. $('.nav-tabs a[href="#pdfTab"]').tab('show');
  344. } else {
  345. table.column(2).visible(false);
  346. table.column(3).visible(false);
  347. table.column(4).visible(true);
  348. $(".table-responsive").hide();
  349. $("#SN").text("項次");
  350. $("#name").text("類別");
  351. table.page.len(7).draw();
  352. $('.nav-tabs a[href="#arcgisTab"]').tab('show');
  353. }
  354. }
  355. function countFiles(project_id, is_blueprint) {
  356. $.ajax({
  357. url: "./script/php/get_file_count.php",
  358. data: {
  359. project_id: project_id,
  360. is_blueprint: is_blueprint,
  361. },
  362. async: false,
  363. //contentType: "application/json",
  364. dataType: "json",
  365. type: "POST",
  366. })
  367. .success(function (response) {
  368. console.log(response);
  369. fileNums = response;
  370. })
  371. .error(function (error) {
  372. console.log(error);
  373. })
  374. .complete(function () {});
  375. }
  376. function addTable(data, notes, response, SN, path) {
  377. table.clear().draw();
  378. table.page.len(10).draw();
  379. if (data[1] != "設計圖") {
  380. displayDetail(true);
  381. if (notes.includes(data[1])) {
  382. is_blueprint2 = true;
  383. }
  384. for (i = 0; i < response.length; i++) {
  385. table.row.add([
  386. response[i]["SN"],
  387. response[i]["original_name"],
  388. response[i]["keyword"],
  389. '1.0.0',
  390. '',
  391. response[i]["project_id"],
  392. response[i]["project_name"],
  393. response[i]["type_id"],
  394. response[i]["category_name"],
  395. response[i]["notes"],
  396. response[i]["filename"],
  397. ])
  398. table.draw();
  399. }
  400. } else {
  401. displayDetail(false);
  402. blueprint_SN = SN;
  403. blueprint_path = path;
  404. tempTable2 = [];
  405. countFiles(project_id, "true");
  406. for (i = 0; i < response.length; i++) {
  407. notes[i] = response[i]['notes'];
  408. let temp = [
  409. i + 1,
  410. response[i]['notes'],
  411. '',
  412. '',
  413. fileNums[i].total,
  414. data[5],
  415. ];
  416. table.row.add(temp);
  417. tempTable2.push(temp);
  418. }
  419. table.draw();
  420. }
  421. }
  422. });