jstreeAJAX.js 14 KB

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