Skip to content

Commit

Permalink
Overlay in available page (#1449)
Browse files Browse the repository at this point in the history
Added closable overlays helper method.
  • Loading branch information
natacha-beck authored Mar 3, 2025
1 parent 3ab6475 commit f8961e7
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 10 deletions.
22 changes: 22 additions & 0 deletions BrainPortal/app/helpers/rich_ui_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,28 @@ def overlay_content_link(name, options = {}, &block)
html.html_safe
end

# Create a link that will open a dialog box.
#
# +link_text+: clickable text that appears on the page in order to open the overlay
# +title+: title that will show up as a header at the top of the overlay
# +description+: text of the overlay content
# +size+: maximum height and width of the overlay
#
def closable_overlay_content_link(link_text, title, description="", size="50em", options = {})
return "" if description.blank?

link = overlay_content_link(link_text, :enclosing_element => "span") do
html = "<div style='overflow: auto; max-height: #{size}; max-width: #{size};'>" +
"<h1>#{h(title)}</h1><hr/>" +
"<p>#{h(description)}</p>" +
"</div>"

html.html_safe
end

return link
end

# Create a button with a drop down menu
#
# Options:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@
end
%>
<tr>
<td><%= overlay_description((name + "\n" + description).strip) %></td>
<td>
<%= name %>
<%= closable_overlay_content_link(" &#8505; ".html_safe, name, description) %>
</td>
<td><%= access %></td>
</tr>
<% end %>
Expand Down
5 changes: 4 additions & 1 deletion BrainPortal/app/views/portal/_available_tools_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@
end
%>
<tr>
<td><%= overlay_description((name + "\n" + description).strip) %></td>
<td>
<%= name %>
<%= closable_overlay_content_link(" &#8505; ".html_safe, name, description) %>
</td>
<td><%= versions %></td>
<td><%= tags.join(", ") %></td>
<td class="no_wrap"><%= access %></td>
Expand Down
2 changes: 1 addition & 1 deletion BrainPortal/app/views/portal/available.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Not all of them are available to all users.
<% open_tools = @tools.select { |tool| (tool.group_id == @everyone_gid) && tool.tool_configs.where(:group_id => @everyone_gid).exists? } %>
<% restrict_tools = @tools - open_tools %>

<%= build_tabs do |tb| %>
<%= build_tabs( :class => 'available_tabs' ) do |tb| %>
<%= tb.tab("Tools") do %>
<%= render :partial => 'available_tools_table', :locals => { :tools => open_tools } %>
<%= render :partial => 'available_tools_table', :locals => { :tools => restrict_tools } %>
Expand Down
29 changes: 22 additions & 7 deletions BrainPortal/public/javascripts/cbrain.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,16 @@
$(this).tabs();
});

// Find tabs in div with class available_tabs in order to close all overlay dialogs
loaded_element.find(".available_tabs").each( function(_, tab) {
$(tab).click( event => {
// Close all dialogs
$(".ui-dialog-content:visible").each(function(_, element) {
$(element).dialog('close');
});
});
});

loaded_element.find(".inline_text_field").each(function() {
var inline_text_field = $(this);
var data_type = inline_text_field.data("type") || "script";
Expand Down Expand Up @@ -382,23 +392,28 @@
return false;
});

//Overlay dialogs
//See overlay_dialog_with_button()
// Overlay dialogs
// See overlay_dialog_with_button()
loaded_element.find(".overlay_dialog").each( function(index,element) {
var enclosing_div = $(this);
var dialog_link = enclosing_div.children('.overlay_content_link');
var dialog = enclosing_div.children(".overlay_content")
var content_width = parseInt(dialog_link.data("width"), 10);
var enclosing_div = $(this);
var dialog_link = enclosing_div.children('.overlay_content_link');
var dialog = enclosing_div.children('.overlay_content');
var content_width = parseInt(dialog_link.data("width"), 10);
var content_height = parseInt(dialog_link.data("height"), 10);

dialog.dialog({
autoOpen: false,
position: "center",
width: content_width || 'auto',
height: content_height || 'auto'
});

dialog_link.click(function() {
// Close all other dialogs
$(".ui-dialog-content:visible").each(function(_, element) {
var visible_dialog = $(element);
visible_dialog.dialog('close');
});

dialog.dialog('open');
return false;
});
Expand Down

0 comments on commit f8961e7

Please sign in to comment.