123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- /**
- * Created by Syusuke on 2017/3/17.
- */
- $(function(){
- getRationLibs();
- })
- function addressdirect(){
- $("tr:gt(0)").each(function() {
- var td, a;
- td = $("td:eq(0)", $(this));
- a = $('a', td);
- a.attr('href', "/rationLibEditor/rationLib" + "?rationname=" + a.text());
- })
- }
- function deleteLib(){
- $("tr:gt(0)").each(function() {
- var td0, a1,td2,a2;
- td2 = $("td:eq(2)", $(this));
- td0 = $("td:eq(0)", $(this));
- a1 = $('a', td0);
- var str = a1.text();
- a2 = $("a:eq(1)",td2);
- a2.click(function(){
- $("#did").val(str)
- })
- // a.attr('href', "/ration/rationLib" + "?rationname=" + a.text());
- })
- }
- function editLib(){
- $("tr:gt(0)").each(function() {
- var td0, a1,td2,a2;
- td2 = $("td:eq(2)", $(this));
- td0 = $("td:eq(0)", $(this));
- a1 = $('a', td0);
- var str = a1.text();
- a2 = $("a:eq(0)",td2);
- a2.click(function(){
- $("#did").val(str)
- })
- })
- }
- $("#deleteLib").click(function(){
- var rationLibName = $("#did").val();
- $.ajax({
- type:"POST",
- url:"http://localhost:6060/rationLibEditor/deleteRationLibs",
- dataType:"json",
- data:{"rationName": rationLibName},
- cache:false,
- timeout:50000,
- success:function(result){
- getRationLibs();
- },
- error:function(iqXHR,textStatus,errorThrown){
- }
- })
- });
- function getRationLibs(){
- $.ajax({
- type:"POST",
- url:"http://localhost:6060/rationLibEditor/getRationDisplayNames",
- dataType:"json",
- cache:false,
- timeout:50000,
- success:function(result){
- $("tbody tr").html("");
- for(var i=0;i<result.data.length;i++){
- addLibTag(result.data[i].displayName);
- }
- addressdirect();
- deleteLib();
- editLib();
- },
- error:function(iqXHR,textStatus,errorThrown){
- alert("error "+textStatus+" "+errorThrown);
- }
- })
- }
- function addLibTag(string){
- 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>')
- var $td0 = $("td:eq(0)",$tr);
- var $td1 = $("td:eq(1)",$tr);
- var a = $("a",$td0);
- var str = string;
- a.text(str);
- var date = new Date().format("yyyy-MM-dd");
- $td1.text(date);
- $tr.appendTo("tbody");
- }
- function addRation(str) {
- $.ajax({
- type:"POST",
- url:"http://localhost:6060/rationLibEditor/addRationLib",
- dataType:"json",
- data:{"rationDisPlayName": str},
- cache:false,
- timeout:50000,
- success:function(result){
- },
- error:function(iqXHR,textStatus,errorThrown){
- alert("error "+textStatus+" "+errorThrown);
- }
- })
- }
- $("#rationAdd").click(function(){
- 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>')
- var $td0 = $("td:eq(0)",$tr);
- var $td1 = $("td:eq(1)",$tr);
- var a = $("a",$td0);
- var str = $("#addInput").val();
- a.text(str);
- var date = new Date().format("yyyy-MM-dd");
- $td1.text(date);
- $tr.appendTo("tbody");
- addRation(str);
- addressdirect();
- deleteLib();
- });
- $("#edtOK").click(function(){
- var str = $("#did").val();
- var newStr = $("#inputRation").val();
- $.ajax({
- type:"POST",
- url:"http://localhost:6060/rationLibEditor/editRationLibs",
- dataType:"json",
- data:{"rationName": str,"newName":newStr},
- cache:false,
- timeout:50000,
- success:function(result){
- getRationLibs();
- },
- error:function(jqXHR){
- var err = JSON.parse(jqXHR.responseText);
- alert(err.error);
- }
- })
- });
- Date.prototype.format = function(fmt) {
- var o = {
- "M+" : this.getMonth()+1,
- "d+" : this.getDate(),
- "h+" : this.getHours(),
- "m+" : this.getMinutes(),
- "s+" : this.getSeconds(),
- "q+" : Math.floor((this.getMonth()+3)/3),
- "S" : this.getMilliseconds()
- };
- if(/(y+)/.test(fmt)) {
- fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
- }
- for(var k in o) {
- if(new RegExp("("+ k +")").test(fmt)){
- fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
- }
- }
- return fmt;
- }
- autoFlashHeight();
|