Skip to content

Commit

Permalink
fixes behaviour of select related popup
Browse files Browse the repository at this point in the history
  • Loading branch information
warp committed Dec 22, 2013
1 parent e93914f commit 834ffba
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
9 changes: 5 additions & 4 deletions app/assets/javascripts/crm.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,8 @@
#----------------------------------------------------------------------------
jumper: (controller) ->
name = controller.capitalize()
for link in $("#jumpbox_menu a")
$(link).toggleClass("selected", link.innerHTML is name)
$("#jumpbox_menu a").each ->
$(this).toggleClass("selected", link.innerHTML is name)

@auto_complete controller, null, true

Expand All @@ -387,8 +387,9 @@
$.ajax(@base_url + "/" + related + "/attach", type: 'PUT', data: {
assets: controller
asset_id: ui.item.value
}, -> $("#jumpbox").hide()
)
}
).then ->
$("#auto_complete_query").val ""
else
window.location.href = @base_url + "/" + controller + "/" + ui.item.value
)
Expand Down
10 changes: 4 additions & 6 deletions app/assets/javascripts/crm_classes.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@
@set_position e
@options.after_show e
else
@popup.show()
@set_position e
@popup.hide()
@popup.fadeIn(
@options.appear
@options.after_show
Expand All @@ -82,6 +80,7 @@

#----------------------------------------------------------------------------
hide_popup: (e) ->
e.preventDefault() if e
@options.before_hide e
unless @options.fade
@popup.hide()
Expand All @@ -94,12 +93,11 @@

set_position: (e) ->
if @options.under
position = $(@options.under).position()
under = $(@options.under)
popup = $(@popup)
y_offset = window.pageYOffset or document.documentElement.scrollTop or document.body.scrollTop
x = (position.left + under.width() - popup.width()) + "px"
y = (position.top + under.height() + y_offset) + "px"
offset = under.offset()
x = (offset.left + under.width() - popup.width()) + "px"
y = (offset.top + under.height()) + "px"
@popup.css
left: x
top: y
Expand Down
34 changes: 16 additions & 18 deletions app/views/shared/_select_popup.html.haml
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
- singular = popup.to_s.singularize

:plain
(function ($) {
new crm.Popup({
trigger : "#select_#{singular}",
target : "#jumpbox",
under : "#select_#{singular}",
appear : 300,
fade : 300,
before_show : function() {
$("#jumpbox_menu").hide();
$("#jumpbox_label").html("#{t(popup)}:");
$("#jumpbox_label").show();
crm.auto_complete("#{popup}", "#{related.class.to_s.downcase.pluralize}/#{related.id}");
},
after_show : function() {
$("#auto_complete_query").focus();
}
});
})($);
new crm.Popup({
trigger : "#select_#{singular}",
target : "#jumpbox",
under : "#select_#{singular}",
appear : 300,
fade : 300,
before_show : function() {
$("#jumpbox_menu").hide();
$("#jumpbox_label").html("#{t(popup)}:");
$("#jumpbox_label").show();
crm.auto_complete("#{popup}", "#{related.class.to_s.downcase.pluralize}/#{related.id}");
},
after_show : function() {
$("#auto_complete_query").focus();
}
});

0 comments on commit 834ffba

Please sign in to comment.