clean up javascript, added m2m

This commit is contained in:
Tyrel Souza 2014-02-13 00:47:27 -05:00
parent a13856ea64
commit 5820d816de
7 changed files with 117 additions and 210 deletions

View File

@ -1,3 +1,98 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
$ ->
$("#list_entry_localeze_categories").select2 maximumSelectionSize: 3
elem = $("#chars")
$("#list_entry_Phone").mask "(999) 999-9999"
$("#list_entry_altnumber").mask "(999) 999-9999"
$("#list_entry_fax").mask "(999) 999-9999"
$("#set_all").click all_days_same
$("#set_MF").click all_MF
$("#set_clear").click clear_times
$.each [
"sunday"
"monday"
"tuesday"
"wednesday"
"thursday"
"friday"
"saturday"
], (i, day) ->
$("#hours_" + day + "_close").insertAfter "#hours_" + day + "_open"
return
$("#hours_sunday_close").after "&nbsp;&nbsp; <a href='#' id='set_all'>[Apply To All]</a>"
$("#hours_monday_close").after "&nbsp;&nbsp; <a href='#' id='set_MF'>[Set Monday-Friday]</a>"
$("#set_all").click all_days_same
$("#set_MF").click all_MF
$("#set_clear").click clear_times
$("#how").click ->
$(".how").toggle()
return
$("#payment_types_commadelimited_0").click clear_payment_types
$("#payment_types_commadelimited_1").click check_payment_types
$("#payment_types_commadelimited_2").click check_payment_types
$("#payment_types_commadelimited_3").click check_payment_types
$("#payment_types_commadelimited_4").click check_payment_types
$("#payment_types_commadelimited_5").click check_payment_types
$("#payment_types_commadelimited_6").click check_payment_types
$("#payment_types_commadelimited_7").click check_payment_types
$("#payment_types_commadelimited_8").click check_payment_types
$("#payment_types_commadelimited_9").click check_payment_types
$("#open247").click open247
return
open247 = ->
if $(this).is(":checked")
$("select[id*=day_open]").prop "disabled", "disabled"
$("select[id*=day_close]").prop "disabled", "disabled"
$("#set_all").unbind "click"
$("#set_MF").unbind "click"
clear_times()
else
$("select[id*=day_open]").prop "disabled", ""
$("select[id*=day_close]").prop "disabled", ""
$("#set_all").click all_days_same
$("#set_MF").click all_MF
return
clear_payment_types = ->
unchecked = true
i = 1
while i <= 9
$("#payment_types_commadelimited_" + i).prop "checked", ""
i++
return
check_payment_types = ->
unchecked = true
i = 1
while i <= 9
if $("#payment_types_commadelimited_" + i).is(":checked")
$("#payment_types_commadelimited_0").prop "checked", ""
unchecked = false
i++
$("#payment_types_commadelimited_0").prop "checked", "checked" if unchecked
return
all_days_same = ->
open_time = $("#hours_sunday_open").val()
close_time = $("#hours_sunday_close").val()
$("select[id*=day_open]").val open_time
$("select[id*=day_close]").val close_time
false
all_MF = ->
open_time = $("#hours_monday_open").val()
close_time = $("#hours_monday_close").val()
$("select[id*=day_open]:not(select[id*=sunday]):not(select[id*=saturday])").val open_time
$("select[id*=day_close]:not(select[id*=sunday]):not(select[id*=saturday])").val close_time
false
clear_times = ->
open_time = ""
close_time = ""
$("select[id*=day_open]").val open_time
$("select[id*=day_close]").val close_time
return

View File

View File

@ -20,3 +20,6 @@ class ListEntry < ActiveRecord::Base
has_and_belongs_to_many :localeze_categories
end

View File

@ -1,4 +1,4 @@
class LocalezeCategory < ActiveRecord::Base
attr_accessible :name
belongs_to :list_entries
has_and_belongs_to_many :list_entries
end

View File

@ -65,9 +65,8 @@
<%= f.collection_select(:localeze_categories , LocalezeCategory.find(:all), :id , :name, {}, { :multiple => true, :size => 3 }) %>
{{form.localeze_categories_tabdelimited}}
{{form.payment_types_commadelimited}}
@ -77,26 +76,26 @@
<div class="well">
<h6><a href='#' id='set_clear'>[Clear]</a></h6>
<%= select( "id_hours_sunday", "open", hours_hash) %>
<%= select( "id_hours_sunday", "close", hours_hash) %><br>
<%= select( "hours_sunday", "open", hours_hash) %>
<%= select( "hours_sunday", "close", hours_hash) %><br>
<%= select( "id_hours_monday", "open", hours_hash) %>
<%= select( "id_hours_monday", "close", hours_hash) %><br>
<%= select( "hours_monday", "open", hours_hash) %>
<%= select( "hours_monday", "close", hours_hash) %><br>
<%= select( "id_hours_tuesday", "open", hours_hash) %>
<%= select( "id_hours_tuesday", "close", hours_hash) %><br>
<%= select( "hours_tuesday", "open", hours_hash) %>
<%= select( "hours_tuesday", "close", hours_hash) %><br>
<%= select( "id_hours_wednesday", "open", hours_hash) %>
<%= select( "id_hours_wednesday", "close", hours_hash) %><br>
<%= select( "hours_wednesday", "open", hours_hash) %>
<%= select( "hours_wednesday", "close", hours_hash) %><br>
<%= select( "id_hours_thursday", "open", hours_hash) %>
<%= select( "id_hours_thursday", "close", hours_hash) %><br>
<%= select( "hours_thursday", "open", hours_hash) %>
<%= select( "hours_thursday", "close", hours_hash) %><br>
<%= select( "id_hours_friday", "open", hours_hash) %>
<%= select( "id_hours_friday", "close", hours_hash) %><br>
<%= select( "hours_friday", "open", hours_hash) %>
<%= select( "hours_friday", "close", hours_hash) %><br>
<%= select( "id_hours_satday", "open", hours_hash) %>
<%= select( "id_hours_satday", "close", hours_hash) %><br>
<%= select( "hours_saturday", "open", hours_hash) %>
<%= select( "hours_saturday", "close", hours_hash) %><br>
</div>

View File

@ -1,110 +0,0 @@
function limitText(limitField, limitNum) {
if (limitField.val().length > limitNum) {
limitField.val(limitField.val().substring(0, limitNum));
}
}
// var execption = /^[A-Za-z0-9!?\. -,'&():|"+@%]*(.*)/.exec(str)[1];
// var result = /^([A-Za-z0-9!?\. -,'&():|"+@%]*)(.*)/.exec(str);
$(function() {
// validations();
var elem = $("#chars");
$("#id_phone_number").mask("(999) 999-9999");
$("#id_alternate_phone").mask("(999) 999-9999");
$("#id_fax_number").mask("(999) 999-9999");
$("#set_all").click(all_days_same);
$("#set_MF").click(all_MF);
$("#set_clear").click(clear_times);
$.each(['sunday','monday','tuesday','wednesday','thursday','friday','saturday'], function(i, day) {
$("#id_hours_"+day+"_close").insertAfter("#id_hours_"+day+"_open");
});
$("#id_hours_sunday_close").after("&nbsp;&nbsp; <a href='#' id='set_all'>[Apply To All]</a>");
$("#id_hours_monday_close").after("&nbsp;&nbsp; <a href='#' id='set_MF'>[Set Monday-Friday]</a>");
$("#set_all").click(all_days_same);
$("#set_MF").click(all_MF);
$("#set_clear").click(clear_times);
$("#how").click(function(){$(".how").toggle();});
$("#id_localeze_categories").select2({ maximumSelectionSize: 3 });
$("#id_payment_types_commadelimited_0").click(clear_payment_types);
$("#id_payment_types_commadelimited_1").click(check_payment_types);
$("#id_payment_types_commadelimited_2").click(check_payment_types);
$("#id_payment_types_commadelimited_3").click(check_payment_types);
$("#id_payment_types_commadelimited_4").click(check_payment_types);
$("#id_payment_types_commadelimited_5").click(check_payment_types);
$("#id_payment_types_commadelimited_6").click(check_payment_types);
$("#id_payment_types_commadelimited_7").click(check_payment_types);
$("#id_payment_types_commadelimited_8").click(check_payment_types);
$("#id_payment_types_commadelimited_9").click(check_payment_types);
$("#id_open247").click(open247);
});
var open247 = function(){
if( $(this).is(":checked")){
$("select[id*=day_open]").prop('disabled', 'disabled');
$("select[id*=day_close]").prop('disabled', 'disabled');
$("#set_all").unbind("click");
$("#set_MF").unbind("click");
clear_times();
} else {
$("select[id*=day_open]").prop('disabled', '');
$("select[id*=day_close]").prop('disabled', '');
$("#set_all").click(all_days_same);
$("#set_MF").click(all_MF);
}
};
var clear_payment_types = function(){
var unchecked = true;
for (var i = 1; i <= 9; i++){
$("#id_payment_types_commadelimited_"+i).prop("checked","");
}
};
var check_payment_types = function(){
var unchecked = true;
for (var i = 1; i <= 9; i++){
if ($("#id_payment_types_commadelimited_"+i).is(":checked")){
$("#id_payment_types_commadelimited_0").prop("checked","");
unchecked = false;
}
}
if (unchecked){
$("#id_payment_types_commadelimited_0").prop("checked","checked");
}
};
var all_days_same = function(){
var open_time = $("#id_hours_sunday_open").val();
var close_time = $("#id_hours_sunday_close").val();
$("select[id*=day_open]").val(open_time);
$("select[id*=day_close]").val(close_time);
return false;
};
var all_MF = function(){
var open_time = $("#id_hours_monday_open").val();
var close_time = $("#id_hours_monday_close").val();
$("select[id*=day_open]:not(select[id*=sunday]):not(select[id*=saturday])").val(open_time);
$("select[id*=day_close]:not(select[id*=sunday]):not(select[id*=saturday])").val(close_time);
return false;
};
var clear_times = function(){
var open_time = "";
var close_time = "";
$("select[id*=day_open]").val(open_time);
$("select[id*=day_close]").val(close_time);
};

View File

@ -1,80 +0,0 @@
$ ->
elem = $("#chars")
$("#id_phone_number").mask "(999) 999-9999"
$("#id_alternate_phone").mask "(999) 999-9999"
$("#id_fax_number").mask "(999) 999-9999"
$("#set_all").click all_days_same
$("#set_MF").click all_MF
$("#set_clear").click clear_times
$.each [
"sunday"
"monday"
"tuesday"
"wednesday"
"thursday"
"friday"
"saturday"
], (i, day) ->
$("#id_hours_" + day + "_close").insertAfter "#id_hours_" + day + "_open"
$("#id_hours_sunday_close").after "&nbsp;&nbsp; <a href='#' id='set_all'>[Apply To All]</a>"
$("#id_hours_monday_close").after "&nbsp;&nbsp; <a href='#' id='set_MF'>[Set Monday-Friday]</a>"
$("#set_all").click all_days_same
$("#set_MF").click all_MF
$("#set_clear").click clear_times
$("#how").click ->
$(".how").toggle()
$("#id_localeze_categories").select2 maximumSelectionSize: 3
$("#id_payment_types_commadelimited_0").click clear_payment_types
$("#id_payment_types_commadelimited_1").click check_payment_types
$("#id_payment_types_commadelimited_2").click check_payment_types
$("#id_payment_types_commadelimited_3").click check_payment_types
$("#id_payment_types_commadelimited_4").click check_payment_types
$("#id_payment_types_commadelimited_5").click check_payment_types
$("#id_payment_types_commadelimited_6").click check_payment_types
$("#id_payment_types_commadelimited_7").click check_payment_types
$("#id_payment_types_commadelimited_8").click check_payment_types
$("#id_payment_types_commadelimited_9").click check_payment_types
$("#id_open247").click open247
clear_payment_types = ->
unchecked = true
i = 1
while i <= 9
$("#id_payment_types_commadelimited_" + i).prop "checked", ""
i++
check_payment_types = ->
unchecked = true
i = 1
while i <= 9
if $("#id_payment_types_commadelimited_" + i).is(":checked")
$("#id_payment_types_commadelimited_0").prop "checked", ""
unchecked = false
i++
$("#id_payment_types_commadelimited_0").prop "checked", "checked" if unchecked
all_days_same = ->
open_time = $("#id_hours_sunday_open").val()
close_time = $("#id_hours_sunday_close").val()
$("select[id*=day_open]").val open_time
$("select[id*=day_close]").val close_time
false
all_MF = ->
open_time = $("#id_hours_monday_open").val()
close_time = $("#id_hours_monday_close").val()
$("select[id*=day_open]:not(select[id*=sunday]):not(select[id*=saturday])").val open_time
$("select[id*=day_close]:not(select[id*=sunday]):not(select[id*=saturday])").val close_time
false
clear_times = ->
open_time = ""
close_time = ""
$("select[id*=day_open]").val open_time
$("select[id*=day_close]").val close_time