Make the "Controllers" field read-only.

This commit is contained in:
Akinori MUSHA 2014-09-04 13:55:49 +09:00
parent 12f18398f1
commit 38de860670
3 changed files with 27 additions and 15 deletions

View file

@ -60,6 +60,10 @@ img.odin {
display: none;
}
.controller-region[data-has-controllers=false] {
display: none;
}
img.spinner {
display: none;
vertical-align: bottom;

View file

@ -19,10 +19,22 @@ module AgentHelper
def agent_schedule(agent, delimiter = ', ')
return 'n/a' unless agent.can_be_scheduled?
controllers = agent.controllers
[
*(CGI.escape_html(agent.schedule.humanize.titleize) unless agent.schedule == 'never' && agent.controllers.length > 0),
*controllers.map { |agent| link_to(agent.name, agent_path(agent)) },
].join(delimiter).html_safe
case agent.schedule
when nil, 'never'
agent_controllers(agent, delimiter) || 'Never'
else
[
agent.schedule.humanize.titleize,
*(agent_controllers(agent, delimiter))
].join(delimiter).html_safe
end
end
def agent_controllers(agent, delimiter = ', ')
unless agent.controllers.empty?
agent.controllers.map { |agent|
link_to(agent.name, agent_path(agent))
}.join(delimiter).html_safe
end
end
end

View file

@ -44,16 +44,12 @@
</div>
</div>
<div class="schedule-region" data-can-be-scheduled="<%= @agent.can_be_scheduled? %>">
<div class="can-be-scheduled">
<div class="form-group">
<%= f.label :controllers %>
<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>
<% eventControllers = current_user.agents.select(&:can_control_other_agents?) %>
<%= f.select(:controller_ids,
options_for_select(eventControllers.map {|s| [s.name, s.id] },
@agent.controller_ids),
{}, { multiple: true, size: 5, class: 'select2 form-control' }) %>
<div class="controller-region" data-has-controllers="<%= !@agent.controllers.empty? %>">
<div class="form-group">
<%= f.label :controllers %>
<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 these user-defined Agents."></span>
<div class="controller-list">
<%= agent_controllers(@agent) || 'None' %>
</div>
</div>
</div>