database.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. define(['jquery', 'bootstrap', 'backend', 'template'], function ($, undefined, Backend, Template) {
  2. var Controller = {
  3. index: function () {
  4. //如果有备份权限
  5. if ($("#backuplist").length > 0) {
  6. Fast.api.ajax({
  7. url: "general/database/backuplist",
  8. type: 'get'
  9. }, function (data) {
  10. $("#backuplist").html(Template("backuptpl", {backuplist: data.backuplist}));
  11. return false;
  12. });
  13. return false;
  14. }
  15. //禁止在操作select元素时关闭dropdown的关闭事件
  16. $("#database").on('click', '.dropdown-menu input, .dropdown-menu label, .dropdown-menu select', function (e) {
  17. e.stopPropagation();
  18. });
  19. //提交时检查是否有删除或清空操作
  20. $("#database").on("submit", "#sqlexecute", function () {
  21. var v = $("#sqlquery").val().toLowerCase();
  22. if ((v.indexOf("delete ") >= 0 || v.indexOf("truncate ") >= 0) && !confirm(__('Are you sure you want to delete or turncate?'))) {
  23. return false;
  24. }
  25. });
  26. //事件按钮操作
  27. $("#database").on("click", "ul#subaction li input", function () {
  28. $("#topaction").val($(this).attr("rel"));
  29. return true;
  30. });
  31. //窗口变更的时候重设结果栏高度
  32. $(window).on("resize", function () {
  33. $("#database .well").height($(window).height() - $("#database #sqlexecute").height() - $("#ribbon").outerHeight() - $(".panel-heading").outerHeight() - 130);
  34. });
  35. //修复iOS下iframe无法滚动的BUG
  36. if (/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream) {
  37. $("#resultparent").css({"-webkit-overflow-scrolling": "touch", "overflow": "auto"});
  38. }
  39. $(document).on("click", ".btn-compress", function () {
  40. Fast.api.ajax({
  41. url: "general/database/backuplist",
  42. type: 'get'
  43. }, function (data) {
  44. Layer.open({
  45. area: ["780px", "500px"],
  46. btn: [],
  47. title: "备份与还原",
  48. content: Template("backuptpl", {backuplist: data.backuplist})
  49. });
  50. return false;
  51. });
  52. return false;
  53. });
  54. $(document).on("click", ".btn-backup", function () {
  55. Fast.api.ajax({
  56. url: "general/database/backup",
  57. data: {action: 'backup'}
  58. }, function (data) {
  59. Layer.closeAll();
  60. $(".btn-compress").trigger("click");
  61. });
  62. });
  63. $(document).on("click", ".btn-restore", function () {
  64. var that = this;
  65. Layer.confirm("确定恢复备份?<br><font color='red'>建议先备份当前数据后再进行恢复操作!!!</font><br><font color='red'>当前数据库将被清空覆盖,请谨慎操作!!!</font>", {
  66. type: 5,
  67. skin: 'layui-layer-dialog layui-layer-fast'
  68. }, function (index) {
  69. Fast.api.ajax({
  70. url: "general/database/restore",
  71. data: {action: 'restore', file: $(that).data('file')}
  72. }, function (data) {
  73. Layer.closeAll();
  74. Fast.api.ajax({
  75. url: 'ajax/wipecache',
  76. data: {type: 'all'},
  77. }, function () {
  78. Layer.alert("备份恢复成功,点击确定将刷新页面", function () {
  79. top.location.reload();
  80. });
  81. return false;
  82. });
  83. });
  84. });
  85. });
  86. $(document).on("click", ".btn-delete", function () {
  87. var that = this;
  88. Layer.confirm("确定删除备份?", {type: 5, skin: 'layui-layer-dialog layui-layer-fast', title: '温馨提示'}, function (index) {
  89. Fast.api.ajax({
  90. url: "general/database/restore",
  91. data: {action: 'delete', file: $(that).data('file')}
  92. }, function (data) {
  93. $(that).closest("tr").remove();
  94. Layer.close(index);
  95. });
  96. });
  97. });
  98. $(window).resize();
  99. }
  100. };
  101. return Controller;
  102. });