jstreeAJAX.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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. $('#datatable-ajax').dataTable({
  17. bProcessing: true,
  18. responsive: true,
  19. "pagingType": "full_numbers",
  20. "bLengthChange": false,
  21. "searching": false,
  22. "pageLength": 7,
  23. "language": {
  24. "processing": "處理中...",
  25. "loadingRecords": "載入中...",
  26. "lengthMenu": "顯示 _MENU_ 項結果",
  27. "zeroRecords": "沒有符合的結果或是沒有資料",
  28. "info": "顯示第 _START_ 至 _END_ 項結果,共 _TOTAL_ 項",
  29. "infoEmpty": "顯示第 0 至 0 項結果,共 0 項",
  30. "infoFiltered": "(從 _MAX_ 項結果中過濾)",
  31. "infoPostFix": "",
  32. "search": "搜尋:",
  33. "paginate": {
  34. "first": '<i class="fa fa-step-backward"></i>',
  35. "previous": '<i class="fa fa-backward"></i>',
  36. "next": '<i class="fa fa-forward"></i>',
  37. "last": '<i class="fa fa-step-forward"></i>'
  38. },
  39. "aria": {
  40. "sortAscending": ": 升冪排列",
  41. "sortDescending": ": 降冪排列"
  42. }
  43. },
  44. "columns": [{
  45. "width": "5%"
  46. },
  47. null,
  48. null,
  49. {
  50. "width": "5%"
  51. },
  52. ],
  53. data: [
  54. [
  55. " ", "", "", "",
  56. ],
  57. [
  58. " ", "", "", "",
  59. ],
  60. [
  61. " ", "", "", "",
  62. ],
  63. [
  64. " ", "", "", "",
  65. ],
  66. [
  67. " ", "", "", "",
  68. ],
  69. [
  70. " ", "", "", "",
  71. ],
  72. [
  73. " ", "", "", "",
  74. ]
  75. ],
  76. drawCallback: function() {
  77. if (!start) {
  78. var api = this.api();
  79. var rowCount = api.rows({
  80. page: 'current'
  81. }).count();
  82. for (var i = 0; i < api.page.len() - (rowCount === 0 ? 1 : rowCount); i++) {
  83. $('#datatable-ajax tbody').append($("<tr ><td>&nbsp;</td><td></td><td></td><td></td></tr>"));
  84. }
  85. }
  86. start = false;
  87. }
  88. });
  89. $.ajax({
  90. url: "./script/php/getTree.php",
  91. contentType: "application/json",
  92. dataType: "json",
  93. type: "GET",
  94. async: false
  95. })
  96. .success(function(response) {
  97. tree_data = response;
  98. }).error(function(error) {
  99. console.log(error);
  100. });
  101. var table = $('#datatable-ajax').DataTable();
  102. displayDetail(false);
  103. $('#treeAjaxHTML').jstree({
  104. 'core': {
  105. 'themes': {
  106. variant: 'large'
  107. },
  108. 'data': tree_data,
  109. 'multiple': false,
  110. 'animation': 40,
  111. 'expand_selected_onload': true
  112. },
  113. 'types': {
  114. 'default': {
  115. 'icon': 'fa fa-folder'
  116. },
  117. 'file': {
  118. 'icon': 'fa fa-file'
  119. }
  120. },
  121. 'plugins': ['types', 'search', 'wholerow']
  122. }).bind("loaded.jstree", function(event, data) {
  123. var searchURL = window.location.search;
  124. searchURL = searchURL.substring(1, searchURL.length);
  125. if (searchURL.includes("=")) {
  126. type = decodeURIComponent(searchURL.split("&")[0].split("=")[1]);
  127. $(this).jstree("open_all");
  128. }
  129. /*var typeNode = $(".jstree-anchor").filter(function() {
  130. return $(this).text() == type;
  131. });
  132. var typeId = typeNode[0].attributes.id.value;
  133. $(this).jstree("select_node", typeId);*/
  134. }).on(
  135. 'select_node.jstree',
  136. function(event, data) {
  137. if (data.node.text.includes("-")) {
  138. $("#folderPath").empty();
  139. displayDetail(false);
  140. project_id = data.node.text.split("-")[0];
  141. project_name = data.node.text.split("-")[1];
  142. project = data.node.text;
  143. $("#project-id").val(project_id)
  144. $("#header").text(project);
  145. category = $('#treeAjaxHTML').jstree(true).get_node(data.node.parents[0]).text;
  146. let i = 1;
  147. table.clear().draw();
  148. tempTable = [];
  149. types.forEach(function(data) {
  150. let temp = [
  151. i,
  152. data,
  153. category,
  154. '',
  155. project,
  156. ];
  157. table.row.add(temp).draw();
  158. tempTable.push(temp);
  159. i++;
  160. });
  161. $("#tableDetail td").empty();
  162. } else {
  163. data.instance.toggle_node(data.node);
  164. }
  165. });
  166. $('#btn-search').click(function() {
  167. $("#folderPath").empty();
  168. $("#header").text("搜尋結果");
  169. $.ajax({
  170. url: "./script/php/search.php",
  171. data: {
  172. search: $("#search").val(),
  173. },
  174. async: false,
  175. contentType: "application/json",
  176. dataType: "json",
  177. type: "GET",
  178. })
  179. .success(function(response) {
  180. displayDetail(true);
  181. table.clear().draw();
  182. $("#tableDetail td").empty();
  183. response.forEach(function(data) {
  184. let temp = [
  185. data["SN"],
  186. data["original_name"].slice(6),
  187. data["keyword"],
  188. '1.0.0',
  189. data["project_id"],
  190. data["project_name"],
  191. data["type_id"],
  192. data["category_name"],
  193. data["notes"],
  194. data["filename"],
  195. ];
  196. table.row.add(temp).draw();
  197. i++;
  198. });
  199. })
  200. .error(function(error) {
  201. console.log(error);
  202. })
  203. .complete(function() {});
  204. });
  205. $('#search').keyup(function(e) {
  206. if (e.keyCode == 13) {
  207. $('#btn-search').click();
  208. }
  209. });
  210. $('#reset').click(function() {
  211. $("#folderPath").empty();
  212. folderPath.splice(folderPath.length - 2, 1);
  213. if (folderPath[0] != " ") {
  214. $("#folderPath").text(folderPath.join(">"));
  215. }
  216. table.clear().draw();
  217. if (!is_blueprint2) {
  218. tempTable.forEach(function(data) {
  219. table.row.add(data).draw();
  220. });
  221. } else {
  222. tempTable2.forEach(function(data) {
  223. table.row.add(data).draw();
  224. });
  225. is_blueprint2 = false;
  226. }
  227. $("#tableDetail td").empty();
  228. displayDetail(false);
  229. });
  230. var is_blueprint2 = false;
  231. $('#datatable-ajax tbody').on('click', 'tr', function() {
  232. $(this).parent().find("tr").css('background-color', '');
  233. $(this).css("background-color", "#cccccc");
  234. $("#tableDetail td").empty();
  235. var data = table.row(this).data();
  236. console.log(data);
  237. if (data == null) {
  238. data = ["", "", "null", "", "", "", "", "", "", ""];
  239. }
  240. let project_id = data[4].split("-")[0];
  241. let SN = data[0];
  242. let is_blueprint = data[1] == "設計圖" ? true : false;
  243. let note = notes.includes(data[1]) ? data[1] : '';
  244. if (data[2] == 'null') {
  245. $("#tableDetail td").empty();
  246. } else if (data[3] == '') {
  247. path = data[1];
  248. $.ajax({
  249. url: "./script/php/getDetail.php",
  250. data: {
  251. project_id: project_id,
  252. type_id: SN,
  253. is_blueprint: is_blueprint,
  254. note: note
  255. },
  256. async: false,
  257. contentType: "application/json",
  258. dataType: "json",
  259. type: "GET",
  260. })
  261. .success(function(response) {
  262. table.clear().draw();
  263. $("#folderPath").text($("#folderPath").text() + data[1] + " > ");
  264. folderPath = $("#folderPath").text().split(">");
  265. if (data[1] != "設計圖") {
  266. displayDetail(true);
  267. if (notes.includes(data[1])) {
  268. is_blueprint2 = true;
  269. }
  270. for (i = 0; i < response.length; i++) {
  271. table.row.add([
  272. response[i]["SN"],
  273. response[i]["original_name"].slice(6),
  274. response[i]["keyword"],
  275. '1.0.0',
  276. response[i]["project_id"],
  277. response[i]["project_name"],
  278. response[i]["type_id"],
  279. response[i]["category_name"],
  280. response[i]["notes"],
  281. response[i]["filename"],
  282. ])
  283. table.draw();
  284. }
  285. } else {
  286. blueprint_SN = SN;
  287. blueprint_path = path;
  288. tempTable2 = [];
  289. for (i = 0; i < response.length; i++) {
  290. notes[i] = response[i]['notes'];
  291. let temp = [
  292. i + 1,
  293. response[i]['notes'],
  294. '',
  295. '',
  296. data[4],
  297. ];
  298. table.row.add(temp);
  299. tempTable2.push(temp);
  300. }
  301. table.draw();
  302. }
  303. })
  304. .error(function(error) {
  305. console.log(error);
  306. })
  307. .complete(function() {});
  308. } else {
  309. let type = types[parseInt(data[6]) - 1];
  310. let path = '';
  311. //let category = data[8];
  312. if (data[6] == 3) {
  313. path = data[7] + "/" + data[4] + "-" + data[5] + "/" + data[6] + "_" + type + "/" + data[8] + "/" + data[9];
  314. } else {
  315. path = data[7] + "/" + data[4] + "-" + data[5] + "/" + data[6] + "_" + type + "/" + data[9];
  316. }
  317. $("#plan_code").text(data[4]);
  318. $("#plan_name").text(data[5]);
  319. $("#download").append('<img src="./assets/images/' + 'pdf-icon.png" style="height: 30px; display: inline-block;"> ');
  320. $("#download").append('<a target="_blank" href="./assets/建置資料/' + path + '">' + data[9] + '</a>');
  321. $("#version").text(data[3]);
  322. $("#fileName").text(data[1]);
  323. }
  324. });
  325. function displayDetail(status) {
  326. if (status) {
  327. table.column(2).visible(true);
  328. table.column(3).visible(true);
  329. $(".table-responsive").show();
  330. $("#SN").text("圖號");
  331. $("#name").text("圖名");
  332. } else {
  333. table.column(2).visible(false);
  334. table.column(3).visible(false);
  335. $(".table-responsive").hide();
  336. $("#SN").text("項次");
  337. $("#name").text("類別");
  338. }
  339. }
  340. });