application.js.coffee.erb 3.7KB

    #= require jquery #= require jquery_ujs #= require bootstrap #= require select2 #= require json2 #= require jquery.json-editor #= require latlon_and_geo #= require ./worker-checker #= require_self setupJsonEditor = -> JSONEditor.prototype.ADD_IMG = '<%= image_path 'json-editor/add.png' %>' JSONEditor.prototype.DELETE_IMG = '<%= image_path 'json-editor/delete.png' %>' if $(".live-json-editor").length window.jsonEditor = new JSONEditor($(".live-json-editor"), 400, 500) window.jsonEditor.doTruncation true window.jsonEditor.showFunctionButtons() hideSchedule = -> $(".schedule-region select").hide() $(".schedule-region .cannot-be-scheduled").show() showSchedule = -> $(".schedule-region select").show() $(".schedule-region .cannot-be-scheduled").hide() hideLinks = -> $(".link-region .select2-container").hide() $(".link-region .cannot-receive-events").show() showLinks = -> $(".link-region .select2-container").show() $(".link-region .cannot-receive-events").hide() showEventDescriptions() showEventDescriptions = -> if $("#agent_source_ids").val() $.getJSON "/agents/event_descriptions", { ids: $("#agent_source_ids").val().join(",") }, (json) => if json.description_html? $(".event-descriptions").show().html(json.description_html) else $(".event-descriptions").hide() else $(".event-descriptions").html("").hide() $(document).ready -> # JSON Editor setupJsonEditor() # Select2 Selects $(".select2").select2(width: 'resolve') # Flash if $(".flash").length setTimeout((-> $(".flash").slideUp(-> $(".flash").remove())), 5000) # Agent Show fetchLogs = (e) -> agentId = $(e.target).closest("[data-agent-id]").data("agent-id") e.preventDefault() $("#logs .spinner").show() $("#logs .refresh, #logs .clear").hide() $.get "/agents/#{agentId}/logs", (html) => $("#logs .logs").html html $("#logs .spinner").stop(true, true).fadeOut -> $("#logs .refresh, #logs .clear").show() clearLogs = (e) -> if confirm("Are you sure you want to clear all logs for this Agent?") agentId = $(e.target).closest("[data-agent-id]").data("agent-id") e.preventDefault() $("#logs .spinner").show() $("#logs .refresh, #logs .clear").hide() $.post "/agents/#{agentId}/logs/clear", { "_method": "DELETE" }, (html) => $("#logs .logs").html html $("#logs .spinner").stop(true, true).fadeOut -> $("#logs .refresh, #logs .clear").show() $(".agent-show #show-tabs a[href='#logs']").on "click", fetchLogs $("#logs .refresh").on "click", fetchLogs $("#logs .clear").on "click", clearLogs # Editing Agents $("#agent_source_ids").on "change", showEventDescriptions $("#agent_type").on "change", -> if window.jsonEditor? $(".spinner").fadeIn(); $("#agent_source_ids").select2("val", {}); $(".event-descriptions").html("").hide() $.getJSON "/agents/type_details", { type: $(@).val() }, (json) => if json.can_be_scheduled showSchedule() else hideSchedule() if json.can_receive_events showLinks() else hideLinks() $(".description").html(json.description_html) if json.description_html? window.jsonEditor.json = json.options window.jsonEditor.rebuild() $(".spinner").stop(true, true).fadeOut(); $("#agent_type").change() if $("#agent_type").length if $(".schedule-region") if $(".schedule-region").data("can-be-scheduled") == true showSchedule() else hideSchedule() if $(".link-region") if $(".link-region").data("can-receive-events") == true showLinks() else hideLinks()