_form.html.erb 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <% if @agent.errors.any? %>
  2. <div class="row well">
  3. <h2><%= pluralize(@agent.errors.count, "error") %> prohibited this Agent from being saved:</h2>
  4. <% @agent.errors.full_messages.each do |msg| %>
  5. <p class='text-warning'><%= msg %></p>
  6. <% end %>
  7. </div>
  8. <% end %>
  9. <%= form_for(@agent,
  10. :as => :agent,
  11. :url => @agent.new_record? ? agents_path : agent_path(@agent),
  12. :method => @agent.new_record? ? "POST" : "PUT") do |f| %>
  13. <div class="row">
  14. <div class="col-md-6">
  15. <div class="row">
  16. <!-- Form controls width restricted -->
  17. <div class="col-md-8">
  18. <% if @agent.new_record? %>
  19. <div class="form-group type-select">
  20. <%= f.label :type %>
  21. <%= f.select :type, options_for_select(Agent.types.map(&:to_s).sort.map {|type| [type.gsub(/^.*::/, ''), type] }, @agent.type), {}, :class => 'select2 form-control' %>
  22. </div>
  23. <% end %>
  24. <div class="form-group type-select">
  25. <%= f.label :name %>
  26. <%= f.text_field :name, :class => 'form-control' %>
  27. </div>
  28. <div class='oauthable-form'>
  29. <%= render partial: 'oauth_dropdown' %>
  30. </div>
  31. <div class="form-group">
  32. <%= f.label :schedule, :class => 'control-label' %>
  33. <div class="schedule-region" data-can-be-scheduled="<%= @agent.can_be_scheduled? %>">
  34. <div class="can-be-scheduled">
  35. <%= f.select :schedule, options_for_select(Agent::SCHEDULES.map {|s| [s.humanize.titleize, s] }, @agent.schedule), {}, :class => 'form-control' %>
  36. </div>
  37. <span class='cannot-be-scheduled text-info'>This type of Agent cannot be scheduled.</span>
  38. </div>
  39. </div>
  40. <div class="schedule-region" data-can-be-scheduled="<%= @agent.can_be_scheduled? %>">
  41. <div class="can-be-scheduled">
  42. <div class="form-group">
  43. <%= f.label :controllers %>
  44. <span class="glyphicon glyphicon-question-sign hover-help" data-content="Other than the system-defined schedule above, this agent may be run or controlled by user-defined Agents."></span>
  45. <% eventControllers = current_user.agents.select(&:can_control_other_agents?) %>
  46. <%= f.select(:controller_ids,
  47. options_for_select(eventControllers.map {|s| [s.name, s.id] },
  48. @agent.controller_ids),
  49. {}, { multiple: true, size: 5, class: 'select2 form-control' }) %>
  50. </div>
  51. </div>
  52. </div>
  53. <div class="chain-region" data-can-control-other-agents="<%= @agent.can_control_other_agents? %>">
  54. <div class="can-control-other-agents">
  55. <div class="form-group">
  56. <%= f.label :control_targets %>
  57. <% eventControlTargets = current_user.agents.select(&:can_be_scheduled?) %>
  58. <%= f.select(:control_target_ids,
  59. options_for_select(eventControlTargets.map {|s| [s.name, s.id] },
  60. @agent.control_target_ids),
  61. {}, { multiple: true, size: 5, class: 'select2 form-control' }) %>
  62. </div>
  63. </div>
  64. </div>
  65. <div class='event-related-region' data-can-create-events="<%= @agent.can_create_events? %>">
  66. <div class="form-group">
  67. <%= f.label :keep_events_for, "Keep events" %>
  68. <span class="glyphicon glyphicon-question-sign hover-help" data-content="In order to conserve disk space, you can choose to have events created by this Agent expire after a certain period of time. Make sure you keep them long enough to allow any subsequent Agents to make use of them."></span>
  69. <%= f.select :keep_events_for, options_for_select(Agent::EVENT_RETENTION_SCHEDULES, @agent.keep_events_for), {}, :class => 'form-control' %>
  70. </div>
  71. </div>
  72. <div class="form-group">
  73. <%= f.label :sources %>
  74. <div class="link-region" data-can-receive-events="<%= @agent.can_receive_events? %>">
  75. <% eventSources = (current_user.agents - [@agent]).find_all { |a| a.can_create_events? } %>
  76. <%= f.select(:source_ids,
  77. options_for_select(eventSources.map {|s| [s.name, s.id] },
  78. @agent.source_ids),
  79. {}, { :multiple => true, :size => 5, :class => 'select2 form-control' }) %>
  80. <span class='cannot-receive-events text-info'>This type of Agent cannot receive events.</span>
  81. <%= f.label :propagate_immediately, :class => 'propagate-immediately' do %>Propagate immediately
  82. <%= f.check_box :propagate_immediately %>
  83. <% end %>
  84. </div>
  85. </div>
  86. <% if current_user.scenario_count > 0 %>
  87. <div class="form-group">
  88. <%= f.label :scenarios %>
  89. <span class="glyphicon glyphicon-question-sign hover-help" data-content="Use Scenarios to group sets of Agents, both for organization, and to make them easy to export and share."></span>
  90. <%= f.select(:scenario_ids,
  91. options_for_select(current_user.scenarios.pluck(:name, :id), @agent.scenario_ids),
  92. {}, { :multiple => true, :size => 5, :class => 'select2 form-control' }) %>
  93. </div>
  94. <% end %>
  95. </div>
  96. <!-- Form controls full width -->
  97. <div class="col-md-12">
  98. <div class="form-group">
  99. <%= f.label :options %>
  100. <span class="glyphicon glyphicon-question-sign hover-help" data-content="In this JSON hash, interpolation is available in almost all values using the Liquid templating language.<p>Available template variables include the following:<dl><dt><code>message</code>, <code>url</code>, etc.</dt><dd>Refers to the corresponding key's value of each incoming event's payload.</dd><dt><code>agent</code></dt><dd>Refers to the agent that created each incoming event. It has attributes like <code>type</code>, <code>name</code> and <code>options</code>, so <code>{{agent.type}}</code> will expand to <code>WebsiteAgent</code> if an incoming event is created by that agent.</dd></dl></p><p>To access user credentials, use the <code>credential</code> tag like this: <code>{% credential <em>bare_key_name</em> %}</code></p>"></span>
  101. <textarea rows="15" id="agent_options" name="agent[options]" class="form-control live-json-editor <%= (@agent.new_record? && @agent.options == {}) ? "showing-default" : "" %>">
  102. <%= Utils.jsonify((@agent.new_record? && @agent.options == {}) ? @agent.default_options : @agent.options) %>
  103. </textarea>
  104. </div>
  105. </div>
  106. </div>
  107. </div>
  108. <div class="col-md-6">
  109. <div class="row">
  110. <div class="col-md-12">
  111. <div class='well description'>
  112. <%= @agent.html_description unless @agent.new_record? %>
  113. </div>
  114. </div>
  115. </div>
  116. <div class="row">
  117. <div class="col-md-12">
  118. <div class='well event-descriptions' style='display: none'></div>
  119. </div>
  120. </div>
  121. </div>
  122. </div>
  123. <div class='row'>
  124. <div class="col-md-12">
  125. <%= f.submit "Save", :class => "btn btn-primary" %>
  126. </div>
  127. </div>
  128. <% end %>