mainJ.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /**
  2. * Created by Syusuke on 2017/3/17.
  3. */
  4. $(function(){
  5. getRationLibs();
  6. })
  7. function addressdirect(){
  8. $("tr:gt(0)").each(function() {
  9. var td, a;
  10. td = $("td:eq(0)", $(this));
  11. a = $('a', td);
  12. a.attr('href', "/rationLibEditor/rationLib" + "?rationname=" + a.text());
  13. })
  14. }
  15. function deleteLib(){
  16. $("tr:gt(0)").each(function() {
  17. var td0, a1,td2,a2;
  18. td2 = $("td:eq(2)", $(this));
  19. td0 = $("td:eq(0)", $(this));
  20. a1 = $('a', td0);
  21. var str = a1.text();
  22. a2 = $("a:eq(1)",td2);
  23. a2.click(function(){
  24. $("#did").val(str)
  25. })
  26. // a.attr('href', "/ration/rationLib" + "?rationname=" + a.text());
  27. })
  28. }
  29. function editLib(){
  30. $("tr:gt(0)").each(function() {
  31. var td0, a1,td2,a2;
  32. td2 = $("td:eq(2)", $(this));
  33. td0 = $("td:eq(0)", $(this));
  34. a1 = $('a', td0);
  35. var str = a1.text();
  36. a2 = $("a:eq(0)",td2);
  37. a2.click(function(){
  38. $("#did").val(str)
  39. })
  40. })
  41. }
  42. $("#deleteLib").click(function(){
  43. var rationLibName = $("#did").val();
  44. $.ajax({
  45. type:"POST",
  46. url:"http://localhost:6060/rationLibEditor/deleteRationLibs",
  47. dataType:"json",
  48. data:{"rationName": rationLibName},
  49. cache:false,
  50. timeout:50000,
  51. success:function(result){
  52. getRationLibs();
  53. },
  54. error:function(iqXHR,textStatus,errorThrown){
  55. }
  56. })
  57. });
  58. function getRationLibs(){
  59. $.ajax({
  60. type:"POST",
  61. url:"http://localhost:6060/rationLibEditor/getRationDisplayNames",
  62. dataType:"json",
  63. cache:false,
  64. timeout:50000,
  65. success:function(result){
  66. $("tbody tr").html("");
  67. for(var i=0;i<result.data.length;i++){
  68. addLibTag(result.data[i].displayName);
  69. }
  70. addressdirect();
  71. deleteLib();
  72. editLib();
  73. },
  74. error:function(iqXHR,textStatus,errorThrown){
  75. alert("error "+textStatus+" "+errorThrown);
  76. }
  77. })
  78. }
  79. function addLibTag(string){
  80. var $tr = $('<tr><td><a href="#"></a></td><td></td><td><a href="javacript:void(0);" data-toggle="modal" data-target="#edit" title="编辑"><i class="fa fa-pencil-square-o"></i></a> <a href="javacript:void(0);" data-toggle="modal" data-target="#del" class="text-danger" title="删除"><i class="fa fa-remove"></i></a></td></tr>')
  81. var $td0 = $("td:eq(0)",$tr);
  82. var $td1 = $("td:eq(1)",$tr);
  83. var a = $("a",$td0);
  84. var str = string;
  85. a.text(str);
  86. var date = new Date().format("yyyy-MM-dd");
  87. $td1.text(date);
  88. $tr.appendTo("tbody");
  89. }
  90. function addRation(str) {
  91. $.ajax({
  92. type:"POST",
  93. url:"http://localhost:6060/rationLibEditor/addRationLib",
  94. dataType:"json",
  95. data:{"rationDisPlayName": str},
  96. cache:false,
  97. timeout:50000,
  98. success:function(result){
  99. },
  100. error:function(iqXHR,textStatus,errorThrown){
  101. alert("error "+textStatus+" "+errorThrown);
  102. }
  103. })
  104. }
  105. $("#rationAdd").click(function(){
  106. var $tr = $('<tr><td><a href="#"></a></td><td></td><td><a href="javacript:void(0);" data-toggle="modal" data-target="#edit" title="编辑"><i class="fa fa-pencil-square-o"></i></a> <a href="javacript:void(0);" data-toggle="modal" data-target="#del" class="text-danger" title="删除"><i class="fa fa-remove"></i></a></td></tr>')
  107. var $td0 = $("td:eq(0)",$tr);
  108. var $td1 = $("td:eq(1)",$tr);
  109. var a = $("a",$td0);
  110. var str = $("#addInput").val();
  111. a.text(str);
  112. var date = new Date().format("yyyy-MM-dd");
  113. $td1.text(date);
  114. $tr.appendTo("tbody");
  115. addRation(str);
  116. addressdirect();
  117. deleteLib();
  118. });
  119. $("#edtOK").click(function(){
  120. var str = $("#did").val();
  121. var newStr = $("#inputRation").val();
  122. $.ajax({
  123. type:"POST",
  124. url:"http://localhost:6060/rationLibEditor/editRationLibs",
  125. dataType:"json",
  126. data:{"rationName": str,"newName":newStr},
  127. cache:false,
  128. timeout:50000,
  129. success:function(result){
  130. getRationLibs();
  131. },
  132. error:function(jqXHR){
  133. var err = JSON.parse(jqXHR.responseText);
  134. alert(err.error);
  135. }
  136. })
  137. });
  138. Date.prototype.format = function(fmt) {
  139. var o = {
  140. "M+" : this.getMonth()+1,
  141. "d+" : this.getDate(),
  142. "h+" : this.getHours(),
  143. "m+" : this.getMinutes(),
  144. "s+" : this.getSeconds(),
  145. "q+" : Math.floor((this.getMonth()+3)/3),
  146. "S" : this.getMilliseconds()
  147. };
  148. if(/(y+)/.test(fmt)) {
  149. fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
  150. }
  151. for(var k in o) {
  152. if(new RegExp("("+ k +")").test(fmt)){
  153. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
  154. }
  155. }
  156. return fmt;
  157. }
  158. autoFlashHeight();