Skip to content

Commit

Permalink
improve display of shared agents in form
Browse files Browse the repository at this point in the history
  • Loading branch information
albertsun committed Aug 30, 2016
1 parent d0b8704 commit ce9395d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
12 changes: 11 additions & 1 deletion app/assets/javascripts/components/core.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,17 @@ $ ->
$(".select2-linked-tags").select2(
width: 'resolve',
formatSelection: (obj) ->
"<a href=\"#{this.element.data('urlPrefix')}/#{obj.id}/edit\" onClick=\"Utils.select2TagClickHandler(event, this)\">#{Utils.escape(obj.text)}</a>"
origElement = $(obj.element)
if origElement.data('shared')
"<span class='label label-default'>#{origElement.data('username')}</span> #{Utils.escape(obj.text)}"
else
"<a href=\"#{this.element.data('urlPrefix')}/#{obj.id}/edit\" onClick=\"Utils.select2TagClickHandler(event, this)\">#{Utils.escape(obj.text)}</a>"
formatResult: (obj) ->
origElement = $(obj.element)
if origElement.data('shared')
"<span class='label label-default'>#{origElement.data('username')} (shared)</span> #{Utils.escape(obj.text)}"
else
"#{obj.text}"
)

# Helper for selecting text when clicked
Expand Down
2 changes: 2 additions & 0 deletions app/assets/javascripts/pages/agent-edit-page.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,13 @@ class @AgentEditPage

hideEventCreation: ->
$(".event-related-region .select2-container").hide()
$(".event-related-region .shared-agent").hide()
$(".event-related-region .cannot-create-events").show()
$(".event-related-region").data("can-create-events", false)

showEventCreation: ->
$(".event-related-region .select2-container").show()
$(".event-related-region .shared-agent").show()
$(".event-related-region .cannot-create-events").hide()
$(".event-related-region").data("can-create-events", true)

Expand Down
3 changes: 3 additions & 0 deletions app/assets/stylesheets/application.css.scss.erb
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@ $service-colors: (
color: yellow;
text-decoration: underline;
}
.select2-search-choice span.label {
display: inline-block;
}

.glyphicon-flipped {
-ms-transform: translateZ(0);
Expand Down
6 changes: 2 additions & 4 deletions app/views/agents/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<div class="link-region" data-can-receive-events="<%= @agent.can_receive_events? %>">
<% eventSources = (current_user.agents + Agent.shared - [@agent]).find_all { |a| a.can_create_events? } %>
<%= f.select(:source_ids,
options_for_select(eventSources.map {|s| [s.name, s.id] },
options_for_select(eventSources.map {|s| [s.name, s.id, {'data-username': s.user.username, 'data-shared': s.user != @agent.user}] },
@agent.source_ids),
{}, { :multiple => true, :size => 5, :class => 'select2-linked-tags form-control', data: {url_prefix: '/agents'} }) %>
<span class='cannot-receive-events text-info'>This type of Agent cannot receive events.</span>
Expand All @@ -108,14 +108,12 @@
options_for_select(eventTargets.map {|s| [s.name, s.id] },
@agent.receiver_ids),
{}, { :multiple => true, :size => 5, :class => 'select2-linked-tags form-control', data: {url_prefix: '/agents'} }) %>
<span class='cannot-create-events text-info'>This type of Agent cannot create events.</span>
<%= f.label :shared, :class => 'shared-agent' do %>Shared Agent
<%= f.check_box :shared %>
&nbsp;
<span class="glyphicon glyphicon-question-sign hover-help" data-content="Normally, an Agent's events are only accessible to agents owned by the same user. Marking it shared allows this agent's events to be received by an Agent created by any user."></span>
<% end %>

<span class='cannot-create-events text-info'>This type of Agent cannot create events.</span>
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion app/views/agents/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<p>
<b>Event sources:</b>
<% if (agents = @agent.sources).length > 0 %>
<%= agents.map { |agent| link_to(agent.name, agent_path(agent)) }.to_sentence.html_safe %>
<%= agents.map { |agent| current_user == agent.user ? link_to(agent.name, agent_path(agent)) : agent.name }.to_sentence.html_safe %>
<% else %>
None
<% end %>
Expand Down

0 comments on commit ce9395d

Please sign in to comment.