Skip to content

Commit

Permalink
uses $ shortcut for jQuery and replace scriptalicous sortable with jQ…
Browse files Browse the repository at this point in the history
…uery ui sortable
  • Loading branch information
warp authored and steveyken committed Jan 9, 2014
1 parent 48c4cdf commit 2a5b14a
Show file tree
Hide file tree
Showing 115 changed files with 467 additions and 451 deletions.
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
//= require crm_classes
//= require crm_loginout
//= require crm_fields
//= require crm_sortable
//= require textarea_autocomplete
//= require crm_textarea_autocomplete
//= require ajax-chosen-jquery
Expand Down
28 changes: 28 additions & 0 deletions app/assets/javascripts/crm_sortable.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
(($) ->
window.crm ||= {}

crm.init_sortables = ->
$('[data-sortable]').each ->
$el = $(this)

checkEmpty = ->
$el.children('.empty').toggle($el.sortable('toArray').length is 1)

$el.sortable(
forcePlaceholderSize: true
connectWith: $el.data('sortable-connect-with')
handle: $el.data('sortable-handle')
create: checkEmpty
update: ->
ids = []
for dom_id in $el.sortable('toArray')
ids.push dom_id.replace(/[^\d]/g, '')
data = {}
data[$el.attr('id')] = ids
$.post($el.attr('data-sortable'), data)
checkEmpty()
)

$ ->
crm.init_sortables()
) jQuery
50 changes: 25 additions & 25 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def section(related, assets)
def load_select_popups_for(related, *assets)
js = generate_js_for_popups(related, *assets)
content_for(:javascript_epilogue) do
raw "jQuery(function() { #{js} });"
raw "$(function() { #{js} });"
end
end

Expand Down Expand Up @@ -91,7 +91,7 @@ def link_to_inline(id, url, options = {})
link_to(text,
url + "#{url.include?('?') ? '&' : '?'}cancel=false" + related,
:remote => true,
:onclick => "this.href = this.href.replace(/cancel=(true|false)/,'cancel='+ jQuery('##{id}').css('display') != 'none');",
:onclick => "this.href = this.href.replace(/cancel=(true|false)/,'cancel='+ $('##{id}').css('display') != 'none');",
:class => options[:class]
)
end
Expand Down Expand Up @@ -196,7 +196,7 @@ def visible; { :style => "visibility:visible;" }; end

#----------------------------------------------------------------------------
def one_submit_only(form='')
{ :onsubmit => "jQuery('#'+this.id+' input[type=\\'submit\\']').disable()".html_safe }
{ :onsubmit => "$('#'+this.id+' input[type=\\'submit\\']').disable()".html_safe }
end

#----------------------------------------------------------------------------
Expand All @@ -213,9 +213,9 @@ def invisible_if(you_ask)
def confirm_delete(model, params = {})
question = %(<span class="warn">#{t(:confirm_delete, model.class.to_s.downcase)}</span>).html_safe
yes = link_to(t(:yes_button), params[:url] || model, :method => :delete)
no = link_to_function(t(:no_button), "jQuery('#menu').html(jQuery('#confirm').html());")
text = "jQuery('#confirm').html( jQuery('#menu').html() );\n"
text << "jQuery('#menu').html('#{question} #{yes} : #{no}');"
no = link_to_function(t(:no_button), "$('#menu').html($('#confirm').html());")
text = "$('#confirm').html( $('#menu').html() );\n"
text << "$('#menu').html('#{question} #{yes} : #{no}');"
text.html_safe
end

Expand All @@ -234,8 +234,8 @@ def refresh_sidebar(action = nil, shake = nil)
#----------------------------------------------------------------------------
def refresh_sidebar_for(view, action = nil, shake = nil)
text = ""
text << "jQuery('#sidebar').html('#{ j render(:partial => "layouts/sidebar", :locals => { :view => view, :action => action }) }');"
text << "jQuery('##{j shake.to_s}').effect('shake', { duration:200, distance: 3 });" if shake
text << "$('#sidebar').html('#{ j render(:partial => "layouts/sidebar", :locals => { :view => view, :action => action }) }');"
text << "$('##{j shake.to_s}').effect('shake', { duration:200, distance: 3 });" if shake
text.html_safe
end

Expand All @@ -262,11 +262,11 @@ def redraw(option, value, url = send("redraw_#{controller.controller_name}_path"
param, value = value.first, value.last
end
%Q{
if (jQuery('##{option}').html() != '#{value}') {
jQuery('##{option}').html('#{value}');
jQuery('#loading').show();
jQuery.post('#{url}', {#{option}: '#{param || value}'}, function () {
jQuery('#loading').hide();
if ($('##{option}').html() != '#{value}') {
$('##{option}').html('#{value}');
$('#loading').show();
$.post('#{url}', {#{option}: '#{param || value}'}, function () {
$('#loading').hide();
});
}
}
Expand All @@ -277,11 +277,11 @@ def options_menu_item(option, key, url = send("redraw_#{controller.controller_na
name = t("option_#{key}")
"{ name: \"#{name.titleize}\", on_select: function() {" +
%Q{
if (jQuery('##{option}').html() != '#{name}') {
jQuery('##{option}').html('#{name}');
jQuery('#loading').show();
jQuery.post('#{url}', {#{option}: '#{key}', query: jQuery('#query').val()}, function () {
jQuery('#loading').hide();
if ($('##{option}').html() != '#{name}') {
$('##{option}').html('#{name}');
$('#loading').show();
$.post('#{url}', {#{option}: '#{key}', query: $('#query').val()}, function () {
$('#loading').hide();
});
}
} + "}}"
Expand All @@ -291,7 +291,7 @@ def options_menu_item(option, key, url = send("redraw_#{controller.controller_na
#----------------------------------------------------------------------------
def get_browser_timezone_offset
unless session[:timezone_offset]
"jQuery.get('#{timezone_path}', {offset: (new Date()).getTimezoneOffset()});"
"$.get('#{timezone_path}', {offset: (new Date()).getTimezoneOffset()});"
end
end

Expand Down Expand Up @@ -390,14 +390,14 @@ def entity_filter_checkbox(name, value, count)
checked = (session["#{controller_name}_filter"].present? ? session["#{controller_name}_filter"].split(",").include?(value.to_s) : count.to_i > 0)
url = url_for(:action => :filter)
onclick = %Q{
var query = jQuery('#query').val(),
var query = $('#query').val(),
values = [];
jQuery('input[name=&quot;#{name}[]&quot;]').filter(':checked').each(function () {
$('input[name=&quot;#{name}[]&quot;]').filter(':checked').each(function () {
values.push(this.value);
});
jQuery('#loading').show();
jQuery.post('#{url}', {#{name}: values.join(','), query: query}, function () {
jQuery('#loading').hide();
$('#loading').show();
$.post('#{url}', {#{name}: values.join(','), query: query}, function () {
$('#loading').hide();
});
}.html_safe
check_box_tag("#{name}[]", value, checked, :id => value, :onclick => onclick)
Expand Down Expand Up @@ -474,7 +474,7 @@ def view_buttons
end

#----------------------------------------------------------------------------
# Generate the html for jQuery.timeago function
# Generate the html for $.timeago function
# <span class="timeago" datetime="2008-07-17T09:24:17Z">July 17, 2008</span>
def timeago(time, options = {})
options[:class] ||= "timeago"
Expand Down
6 changes: 3 additions & 3 deletions app/helpers/leads_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ def link_to_reject(lead)
def confirm_reject(lead)
question = %(<span class="warn">#{t(:reject_lead_confirm)}</span>)
yes = link_to(t(:yes_button), reject_lead_path(lead), :method => :put)
no = link_to_function(t(:no_button), "jQuery('#menu').html(jQuery('#confirm').html());")
text = "jQuery('#confirm').html( jQuery('#menu').html() );\n"
text << "jQuery('#menu').html('#{question} #{yes} : #{no}');"
no = link_to_function(t(:no_button), "$('#menu').html($('#confirm').html());")
text = "$('#confirm').html( $('#menu').html() );\n"
text << "$('#menu').html('#{question} #{yes} : #{no}');"
text.html_safe
end

Expand Down
24 changes: 12 additions & 12 deletions app/helpers/tasks_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ def task_filter_checkbox(view, filter, count)
checked = (session[name] ? session[name].split(",").include?(filter.to_s) : count > 0)
url = url_for(:action => :filter, :view => view)
onclick = %Q{
jQuery('#loading').show();
jQuery.post('#{url}', {filter: this.value, checked: this.checked}, function () {
jQuery('#loading').hide();
$('#loading').show();
$.post('#{url}', {filter: this.value, checked: this.checked}, function () {
$('#loading').hide();
});
}
check_box_tag("filters[]", filter, checked, :onclick => onclick, :id => "filters_#{filter.to_s.underscore}")
Expand Down Expand Up @@ -46,8 +46,8 @@ def link_to_task_delete(task, bucket)

#----------------------------------------------------------------------------
def link_to_task_complete(pending, bucket)
onclick = %Q{jQuery("##{dom_id(pending, :name)}").css(textDecoration: "line-through");}
onclick << %Q{jQuery.ajax(#{complete_task_path(pending)}, {type: 'PUT', data: {bucket: '#{bucket}'}});}
onclick = %Q{$("##{dom_id(pending, :name)}").css(textDecoration: "line-through");}
onclick << %Q{$.ajax(#{complete_task_path(pending)}, {type: 'PUT', data: {bucket: '#{bucket}'}});}
end

# Task summary for RSS/ATOM feed.
Expand Down Expand Up @@ -80,30 +80,30 @@ def task_summary(task)

#----------------------------------------------------------------------------
def hide_task_and_possibly_bucket(task, bucket)
text = "jQuery('##{dom_id(task)}').remove();\n"
text << "jQuery('#list_#{h bucket.to_s}').fadeOut({ duration:500 });\n" if Task.bucket_empty?(bucket, current_user, @view)
text = "$('##{dom_id(task)}').remove();\n"
text << "$('#list_#{h bucket.to_s}').fadeOut({ duration:500 });\n" if Task.bucket_empty?(bucket, current_user, @view)
text.html_safe
end

#----------------------------------------------------------------------------
def replace_content(task, bucket = nil)
partial = (task.assigned_to && task.assigned_to != current_user.id) ? "assigned" : "pending"
html = render(:partial => "tasks/#{partial}", :collection => [ task ], :locals => { :bucket => bucket })
text = "jQuery('##{dom_id(task)}').html('#{ j html }');\n".html_safe
text = "$('##{dom_id(task)}').html('#{ j html }');\n".html_safe
end

#----------------------------------------------------------------------------
def insert_content(task, bucket, view)
text = "jQuery('#list_#{bucket}').show();\n".html_safe
text = "$('#list_#{bucket}').show();\n".html_safe
html = render(:partial => view, :collection => [ task ], :locals => { :bucket => bucket })
text << "jQuery('##{h bucket.to_s}').prepend('#{ j html }');\n".html_safe
text << "jQuery('##{dom_id(task)}').effect('highlight', { duration:1500 });\n".html_safe
text << "$('##{h bucket.to_s}').prepend('#{ j html }');\n".html_safe
text << "$('##{dom_id(task)}').effect('highlight', { duration:1500 });\n".html_safe
text
end

#----------------------------------------------------------------------------
def tasks_flash(message)
text = "jQuery('#flash').html('#{ message }');\n"
text = "$('#flash').html('#{ message }');\n"
text << "crm.flash('notice', true)\n"
text.html_safe
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/fields/custom_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def add_ransack_translation
ransack: {attributes: {klass.model_name.singular => {name => label}}}
})
# Reset Ransack cache
Ransack::Helpers::FormBuilder.cached_searchable_attributes_for_base = {}
# Ransack::Helpers::FormBuilder.cached_searchable_attributes_for_base = {}
end

# Change database column type only if safe to do so
Expand Down
18 changes: 9 additions & 9 deletions app/views/accounts/create.js.haml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
- create_id = "create_#{entity_name}" # create_account

- if @entity.valid?
jQuery('##{create_id}_arrow').html(crm.COLLAPSED);
jQuery('##{create_id}_title').html('#{ j t(entity_name.pluralize) }');
jQuery('##{create_id}').slideUp(250);
jQuery('##{entity_name.pluralize}').prepend('#{ j render(:partial => entity_name, :collection => [ @entity ]) }');
jQuery('##{dom_id(@entity)}').effect("highlight", { duration:1500 });
$('##{create_id}_arrow').html(crm.COLLAPSED);
$('##{create_id}_title').html('#{ j t(entity_name.pluralize) }');
$('##{create_id}').slideUp(250);
$('##{entity_name.pluralize}').prepend('#{ j render(:partial => entity_name, :collection => [ @entity ]) }');
$('##{dom_id(@entity)}').effect("highlight", { duration:1500 });
= refresh_sidebar(:index, :filters)
jQuery('#paginate').html('#{ j render(:partial => "shared/paginate_with_per_page") }');
$('#paginate').html('#{ j render(:partial => "shared/paginate_with_per_page") }');
crm.flick('empty', 'remove');
- else
jQuery('##{create_id}').html('#{ j render(:partial => "new") }');
jQuery('##{create_id}').effect("shake", { duration:250, distance: 6 });
jQuery('#new_#{entity_name} input[type!=hidden]').first().focus();
$('##{create_id}').html('#{ j render(:partial => "new") }');
$('##{create_id}').effect("shake", { duration:250, distance: 6 });
$('#new_#{entity_name} input[type!=hidden]').first().focus();
4 changes: 2 additions & 2 deletions app/views/accounts/destroy.js.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- entity_name = controller.controller_name.singularize.underscore
- @entity = instance_variable_get("@#{entity_name}")

jQuery('##{dom_id(@entity)}').css('background-color', '#ffe4e1').slideUp(250);
$('##{dom_id(@entity)}').css('background-color', '#ffe4e1').slideUp(250);
= refresh_sidebar(:index, :filters)
jQuery('#paginate').replaceWith('#{ j render(:partial => "shared/paginate_with_per_page") }');
$('#paginate').replaceWith('#{ j render(:partial => "shared/paginate_with_per_page") }');
10 changes: 5 additions & 5 deletions app/views/accounts/edit.js.haml
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@
crm.flip_form('edit_#{entity_name}');
crm.set_title('edit_#{entity_name}', '#{h @entity.name}');
- else # Called from index page...
jQuery('##{id}').replaceWith('#{ j render(:partial => entity_name, :collection => [ @entity ]) }');
$('##{id}').replaceWith('#{ j render(:partial => entity_name, :collection => [ @entity ]) }');

- else # <---------------------------------------- Show [Edit] form.

- if params[:cancel].blank? # Called from index page...
- if @previous # Hide open [Edit] form if any.
- if @previous.is_a?(@entity.class)
jQuery('##{dom_id(@previous)}').replaceWith('#{ j render(:partial => entity_name, :collection => [ @previous ]) }');
$('##{dom_id(@previous)}').replaceWith('#{ j render(:partial => entity_name, :collection => [ @previous ]) }');
- else
crm.flick('#{entity_name}_#{@previous}', 'remove');
-# Disable onMouseOver for the list item.
crm.highlight_off('#{id}');
-# Hide [Create] form if any.
crm.hide_form('create_#{entity_name}');
-# Show [Edit] form.
jQuery('##{id}').html('#{ j render(:partial => "edit") }');
$('##{id}').html('#{ j render(:partial => "edit") }');

- elsif params[:cancel].false? # Called from title of the landing page...
jQuery('#edit_#{entity_name}').html('#{ j render(:partial => "edit") }');
$('#edit_#{entity_name}').html('#{ j render(:partial => "edit") }');
crm.flip_form('edit_#{entity_name}');
crm.set_title('edit_#{entity_name}', "#{t :edit} #{h @entity.name}");
jQuery('#new_#{entity_name} input[type!=hidden]').first().focus();
$('#new_#{entity_name} input[type!=hidden]').first().focus();
10 changes: 5 additions & 5 deletions app/views/accounts/index.js.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
- @entities = instance_variable_get("@#{entities}")

- if @entities.any?
jQuery('##{entities}').html('#{ j render(@entities) }');
$('##{entities}').html('#{ j render(@entities) }');
- else
jQuery('##{entities}').html('#{ j render(:partial => "shared/empty") }');
$('##{entities}').html('#{ j render(:partial => "shared/empty") }');

jQuery('#paginate').html('#{ j render(:partial => "shared/paginate_with_per_page") }');
jQuery('#export').html('#{ j render(:partial => "shared/export") }');
jQuery('#search_results_count').html('#{ j render(:text => t('search_results_count', :count => @search_results_count)) }');
$('#paginate').html('#{ j render(:partial => "shared/paginate_with_per_page") }');
$('#export').html('#{ j render(:partial => "shared/export") }');
$('#search_results_count').html('#{ j render(:text => t('search_results_count', :count => @search_results_count)) }');
2 changes: 1 addition & 1 deletion app/views/accounts/new.js.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ crm.flick('empty', 'toggle');
crm.flip_form('#{create_id}');

- unless params[:cancel].true?
jQuery('##{create_id}').html('#{ j render(:partial => "new") }');
$('##{create_id}').html('#{ j render(:partial => "new") }');
crm.set_title('#{create_id}', '#{ j t(create_id) }');
- else
crm.set_title('#{create_id}', '#{ j t(entity_name.pluralize) }');
2 changes: 1 addition & 1 deletion app/views/accounts/show.js.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- entity_name = controller.controller_name.singularize.underscore #account
- @entity = instance_variable_get("@#{entity_name}")

jQuery('#main').html('#{ j (render :template => "#{entity_name.pluralize}/show.html", entity_name => @entity) }');
$('#main').html('#{ j (render :template => "#{entity_name.pluralize}/show.html", entity_name => @entity) }');
= raw generate_js_for_popups(@entity, :tasks, :contacts, :opportunities)
10 changes: 5 additions & 5 deletions app/views/accounts/update.js.haml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
crm.set_title('edit_#{entity_name}', '#{h @entity.name}');
= refresh_sidebar(:show, :summary)
- else
jQuery('##{id}').replaceWith('#{ j render(:partial => entity_name, :collection => [ @entity ]) }');
jQuery('##{id}').effect("highlight", { duration:1500 });
$('##{id}').replaceWith('#{ j render(:partial => entity_name, :collection => [ @entity ]) }');
$('##{id}').effect("highlight", { duration:1500 });
= refresh_sidebar(:index, :filters)
- else
jQuery('##{id}').html('#{ j render(:partial => "edit") }');
jQuery('##{id}').effect("shake", { duration:250, distance: 6 });
jQuery('##{dom_id(@entity, :edit)} input[type!=hidden]').first().focus();
$('##{id}').html('#{ j render(:partial => "edit") }');
$('##{id}').effect("shake", { duration:250, distance: 6 });
$('##{dom_id(@entity, :edit)} input[type!=hidden]').first().focus();
9 changes: 4 additions & 5 deletions app/views/admin/field_groups/_field_group.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@

.remote{ hidden.merge(:id => edit_form_id) }

.list{ :id => dom_id(field_group, :fields) }
- if (fields = field_group.fields.without_pairs).present?
= render :partial => "admin/fields/field", :collection => fields
- else
.empty{:id => "empty_#{asset}_field_group_#{field_group.id}"}
.list
%ul{ :id => dom_id(field_group, :fields), :class => 'fields', 'data-sortable' => sort_admin_fields_path(:field_group_id => field_group.id), 'data-sortable-connect-with' => '.fields', 'data-sortable-handle' => '.handle' }
= render :partial => "admin/fields/field", :collection => field_group.fields.without_pairs
%li.empty
= t(:field_group_empty)
= link_to t(:create_field), '#', :class => 'create', 'data-for' => create_form_id

Expand Down
4 changes: 2 additions & 2 deletions app/views/admin/field_groups/confirm.js.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
- id = dom_id(@field_group, :confirm)

if (jQuery('##{id}').size() > 0) {
if ($('##{id}').size() > 0) {
crm.flick('#{id}', 'remove');
} else {
jQuery('##{dom_id(@field_group)}').prepend('#{ j (render :partial => "confirm") }');
$('##{dom_id(@field_group)}').prepend('#{ j (render :partial => "confirm") }');
}
Loading

0 comments on commit 2a5b14a

Please sign in to comment.