Нет описания http://j1x-huginn.herokuapp.com

application.js.coffee.erb 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #= require jquery
  2. #= require jquery_ujs
  3. #= require bootstrap
  4. #= require select2
  5. #= require json2
  6. #= require jquery.json-editor
  7. #= require latlon_and_geo
  8. #= require ./worker-checker
  9. #= require_self
  10. setupJsonEditor = ->
  11. JSONEditor.prototype.ADD_IMG = '<%= image_path 'json-editor/add.png' %>'
  12. JSONEditor.prototype.DELETE_IMG = '<%= image_path 'json-editor/delete.png' %>'
  13. if $(".live-json-editor").length
  14. window.jsonEditor = new JSONEditor($(".live-json-editor"), 400, 500)
  15. window.jsonEditor.doTruncation true
  16. window.jsonEditor.showFunctionButtons()
  17. hideSchedule = ->
  18. $(".schedule-region select").hide()
  19. $(".schedule-region .cannot-be-scheduled").show()
  20. showSchedule = ->
  21. $(".schedule-region select").show()
  22. $(".schedule-region .cannot-be-scheduled").hide()
  23. hideLinks = ->
  24. $(".link-region .select2-container").hide()
  25. $(".link-region .cannot-receive-events").show()
  26. showLinks = ->
  27. $(".link-region .select2-container").show()
  28. $(".link-region .cannot-receive-events").hide()
  29. showEventDescriptions()
  30. showEventDescriptions = ->
  31. if $("#agent_source_ids").val()
  32. $.getJSON "/agents/event_descriptions", { ids: $("#agent_source_ids").val().join(",") }, (json) =>
  33. if json.description_html?
  34. $(".event-descriptions").show().html(json.description_html)
  35. else
  36. $(".event-descriptions").hide()
  37. else
  38. $(".event-descriptions").html("").hide()
  39. $(document).ready ->
  40. # JSON Editor
  41. setupJsonEditor()
  42. # Select2 Selects
  43. $(".select2").select2(width: 'resolve')
  44. # Flash
  45. if $(".flash").length
  46. setTimeout((-> $(".flash").slideUp(-> $(".flash").remove())), 5000)
  47. # Agent Navigation
  48. $agentNavigate = $('#agent-navigate')
  49. $agentNavigate.typeahead(
  50. minLength: 0,
  51. items: 15,
  52. source: agentNames
  53. ).on("change", (e) ->
  54. if agentPaths[$agentNavigate.val()]
  55. $('#agent-navigate').closest(".navbar-search").find(".spinner").show();
  56. window.location = agentPaths[$agentNavigate.val()]
  57. ).on("focus", (e) ->
  58. $agentNavigate.val ''
  59. ).on("blur", (e) ->
  60. $agentNavigate.val ''
  61. )
  62. # Pressing '/' selects the search box.
  63. $("body").on "keypress", (e) ->
  64. if e.keyCode == 47 # The '/' key
  65. if e.target.nodeName == "BODY"
  66. e.preventDefault()
  67. $agentNavigate.focus()
  68. # Agent Show
  69. fetchLogs = (e) ->
  70. agentId = $(e.target).closest("[data-agent-id]").data("agent-id")
  71. e.preventDefault()
  72. $("#logs .spinner").show()
  73. $("#logs .refresh, #logs .clear").hide()
  74. $.get "/agents/#{agentId}/logs", (html) =>
  75. $("#logs .logs").html html
  76. $("#logs .spinner").stop(true, true).fadeOut ->
  77. $("#logs .refresh, #logs .clear").show()
  78. clearLogs = (e) ->
  79. if confirm("Are you sure you want to clear all logs for this Agent?")
  80. agentId = $(e.target).closest("[data-agent-id]").data("agent-id")
  81. e.preventDefault()
  82. $("#logs .spinner").show()
  83. $("#logs .refresh, #logs .clear").hide()
  84. $.post "/agents/#{agentId}/logs/clear", { "_method": "DELETE" }, (html) =>
  85. $("#logs .logs").html html
  86. $("#logs .spinner").stop(true, true).fadeOut ->
  87. $("#logs .refresh, #logs .clear").show()
  88. $(".agent-show #show-tabs a[href='#logs'], #logs .refresh").on "click", fetchLogs
  89. $(".agent-show #logs .clear").on "click", clearLogs
  90. if tab = window.location.href.match(/tab=(\w+)\b/i)?[1]
  91. if tab in ["details", "logs"]
  92. $(".agent-show .nav-tabs li a[href='##{tab}']").click()
  93. # Editing Agents
  94. $("#agent_source_ids").on "change", showEventDescriptions
  95. $("#agent_type").on "change", ->
  96. if window.jsonEditor?
  97. $("#agent-spinner").fadeIn();
  98. $("#agent_source_ids").select2("val", {});
  99. $(".event-descriptions").html("").hide()
  100. $.getJSON "/agents/type_details", { type: $(@).val() }, (json) =>
  101. if json.can_be_scheduled
  102. showSchedule()
  103. else
  104. hideSchedule()
  105. if json.can_receive_events
  106. showLinks()
  107. else
  108. hideLinks()
  109. $(".description").html(json.description_html) if json.description_html?
  110. window.jsonEditor.json = json.options
  111. window.jsonEditor.rebuild()
  112. $("#agent-spinner").stop(true, true).fadeOut();
  113. $("#agent_type").change() if $("#agent_type").length
  114. if $(".schedule-region")
  115. if $(".schedule-region").data("can-be-scheduled") == true
  116. showSchedule()
  117. else
  118. hideSchedule()
  119. if $(".link-region")
  120. if $(".link-region").data("can-receive-events") == true
  121. showLinks()
  122. else
  123. hideLinks()