schedule.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /**
  2. * 定时任务管理初始化
  3. */
  4. var Schedule = {
  5. id: "ScheduleTable", //表格id
  6. seItem: null, //选中的条目
  7. table: null,
  8. layerIndex: -1
  9. };
  10. /**
  11. * 初始化表格的列
  12. */
  13. Schedule.initColumn = function () {
  14. return [
  15. {field: 'selectItem', checkbox: true},
  16. {title: '名称', field: 'name', visible: true, align: 'center', valign: 'middle'},
  17. {title: '请求url', field: 'url', visible: true, align: 'center', valign: 'middle'},
  18. {title: '时间设置', field: 'timeStr', visible: true, align: 'center', valign: 'middle'},
  19. {title: '状态', field: 'state', visible: true, align: 'center', valign: 'middle',
  20. formatter(value,row,index){
  21. if (value == 1) {
  22. return "<button type=\"button\" style=\"line-height: 1.3\" class=\"btn btn-primary btn-xs\">启用</button>";
  23. }
  24. if (value == 2) {
  25. return "<button type=\"button\" style=\"line-height: 1.3\" class=\"btn btn-warning btn-xs\">未启用</button>";
  26. }
  27. }
  28. },
  29. {title: '说明', field: 'description', visible: true, align: 'center', valign: 'middle'}
  30. ];
  31. };
  32. /**
  33. * 检查是否选中
  34. */
  35. Schedule.check = function () {
  36. var selected = $('#' + this.id).bootstrapTable('getSelections');
  37. if(selected.length == 0){
  38. Feng.info("请先选中表格中的某一记录!");
  39. return false;
  40. }else{
  41. Schedule.seItem = selected[0];
  42. return true;
  43. }
  44. };
  45. /**
  46. * 点击添加定时任务
  47. */
  48. Schedule.openAddSchedule = function () {
  49. var index = layer.open({
  50. type: 2,
  51. title: '添加定时任务',
  52. area: ['800px', '420px'], //宽高
  53. fix: false, //不固定
  54. maxmin: true,
  55. content: Feng.ctxPath + '/schedule/schedule_add'
  56. });
  57. this.layerIndex = index;
  58. };
  59. /**
  60. * 打开查看定时任务详情
  61. */
  62. Schedule.openScheduleDetail = function () {
  63. if (this.check()) {
  64. var index = layer.open({
  65. type: 2,
  66. title: '定时任务详情',
  67. area: ['800px', '420px'], //宽高
  68. fix: false, //不固定
  69. maxmin: true,
  70. content: Feng.ctxPath + '/schedule/schedule_update/' + Schedule.seItem.id
  71. });
  72. this.layerIndex = index;
  73. }
  74. };
  75. /**
  76. * 删除定时任务
  77. */
  78. Schedule.delete = function () {
  79. if (this.check()) {
  80. var ajax = new $ax(Feng.ctxPath + "/schedule/delete", function (data) {
  81. Feng.success("删除成功!");
  82. Schedule.table.refresh();
  83. }, function (data) {
  84. Feng.error("删除失败!" + data.responseJSON.message + "!");
  85. });
  86. ajax.set("scheduleId",this.seItem.id);
  87. ajax.start();
  88. }
  89. };
  90. Schedule.open = function(){
  91. if (this.check()) {
  92. var selected = $('#' + this.id).bootstrapTable('getSelections');
  93. var ids = "";
  94. for(var key in selected){
  95. ids = ids+ selected[key].id +",";
  96. }
  97. var ajax = new $ax(Feng.ctxPath + "/schedule/open", function (data) {
  98. Feng.success("启用成功!");
  99. Schedule.table.refresh();
  100. }, function (data) {
  101. Feng.error("启用成功!" + data.responseJSON.message + "!");
  102. });
  103. ajax.set("ids",ids);
  104. ajax.start();
  105. }
  106. }
  107. /**
  108. * 查询定时任务列表
  109. */
  110. Schedule.search = function () {
  111. var queryData = {};
  112. queryData['condition'] = $("#condition").val();
  113. Schedule.table.refresh({query: queryData});
  114. };
  115. $(function () {
  116. var defaultColunms = Schedule.initColumn();
  117. var table = new BSTable(Schedule.id, "/schedule/list", defaultColunms);
  118. table.setPaginationType("client");
  119. table.setSingleSelect(false);
  120. Schedule.table = table.init();
  121. });