_similar_enterprises.html.erb
2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<div id="similar-enterprises" style="display: none; border-bottom: 2px solid #babdb6;">
<p><b><%= _('Existing enterprises:') %></b></p>
<p><i style="text-align: center;"><%= _('Were found %{count} enterprises with similar names on the same city, you can decide to associate one of them or create the new enterprise confirming the informations you typed in.') % {:count => content_tag('span', '', :id => 'similar-enterprises-count')} %></i></p>
<ul id="create-enterprise-similar-enterprises"></ul>
<% query = bsc.enterprises.map(&:id).join(',') %>
<script type="text/javascript">
update_enterprises = function(enterprises){
var association_url = <%= url_for({:controller => 'bsc_plugin_myprofile', :action => 'save_associations', :profile => bsc.identifier}).to_json %>;
jQuery('#create-enterprise-similar-enterprises').empty();
jQuery.each(enterprises, function(index, enterprise){
var id = enterprise[0]
var name = enterprise[1]
var query = <%= query.to_json %>;
if(query)
query += ',';
query += id.toString();
query = '?q='+query;
var url = association_url + query;
jQuery('#create-enterprise-similar-enterprises').append(
'<li>' + name + ' - <a href="' + url +'">' + <%= _('Associate').to_json %> + '</a></li>'
);
});
if (jQuery(enterprises).length > 0){
jQuery('#similar-enterprises-count').text(jQuery(enterprises).length.toString());
jQuery('#similar-enterprises').fadeIn();
}
else
jQuery('#similar-enterprises').fadeOut();
}
jQuery('#create_enterprise_name,#create_enterprise_city').change(function() {
var parameters = {};
if(jQuery('#create_enterprise_name').length)
parameters.name = jQuery('#create_enterprise_name').val();
if(jQuery('#create_enterprise_city').length)
parameters.city = jQuery('#create_enterprise_city').val();
jQuery.ajax({
url: <%= url_for({:controller => 'bsc_plugin_myprofile', :action => 'similar_enterprises', :profile => bsc.identifier}).to_json %>,
dataType: 'json',
data: parameters,
success: function(data){ update_enterprises(data); },
error: function(ajax, stat, errorThrown) {
alert(stat+': '+errorThrown);
}
});
});
</script>
</div>