Skip to content

Instantly share code, notes, and snippets.

@hayduke19us
Created April 15, 2015 20:54
Show Gist options
  • Save hayduke19us/fa072297dd1cad5af822 to your computer and use it in GitHub Desktop.
Save hayduke19us/fa072297dd1cad5af822 to your computer and use it in GitHub Desktop.
ActionModal = new Main.ActionModal
ActionModal.open( "#openSample", "#sampleModal");
ActionModal.open( "#openStand", "#standModal");
ActionModal.open( "#openRecommendation", "#recommendationModal" );
ActionModal.close( "#closeRecommendation", "#recommendationModal");
ActionModal.open( "#editReport", "#editReportModal");
ActionModal.close( "#closeEditModal", "#editReportModal")
ActionModal.close( "#deleteReport", "#editModal");
ActionModal.open( "#openYield", "#yieldModal")
ActionModal.open( ".sampleAddImage", "#sampleImageModal")
$(document).on( "click", ".sampleAddImage", ->
org = $(".organizationID").attr("id")
org_route = "/organizations/" + org
id = this.id
if $(this).hasClass("yieldCount")
action = org_route + "/corn_yield_samples/" + id + "/add_image"
controller = "corn_yield_samples"
else if $(this).hasClass("standCount")
action = org_route + "/corn_stand_count_samples/" + id + "/add_image"
controller = "corn_stand_count_samples"
else if $(this).hasClass("disorderImage")
action = org_route + "/disorder_samples/" + id + "/add_image"
controller = "disorder_samples"
else if $(this).hasClass("diseaseImage")
action = org_route + "/disease_samples/" + id + "/add_image"
controller = "disease_samples"
else if $(this).hasClass("weedImage")
action = org_route + "/weed_samples/" + id + "/add_image"
controller = "weed_samples"
else if $(this).hasClass("pestImage")
action = org_route + "/pest_samples/" + id + "/add_image"
controller = "pest_samples"
else if $(this).hasClass("otherImage")
action = org_route + "/other_samples/" + id + "/add_image"
controller = "other_samples"
$( ".imageForm" ).attr( "action", action)
$( ".imageForm" ).attr( "controller", controller)
false
)
# Disorder Modal
ActionModal.open( "#openDisorder", "#disorderModal")
# close actions need to return true
ActionModal.close( "#closeDisorder", "#disorderModal")
# Disease Modal
ActionModal.open( "#openDisease", "#diseaseModal")
ActionModal.close( "#closeDisease", "#diseaseModal")
# Weed Modal
ActionModal.open( "#openWeed", "#weedModal")
ActionModal.close( "#closeWeed", "#weedModal")
# Pest Modal
ActionModal.open( "#openPest", "#pestModal")
ActionModal.close( "#closePest", "#pestModal")
# Other Modal
ActionModal.open( "#openOther", "#otherModal")
ActionModal.open( "#closeOther", "#otherModal")
standHash = {}
standHash[15] = "34.833"
standHash[20] = "26.17"
standHash[30] = "17.417"
standHash[36] = "14.5"
standHash[38] = "13.750"
FillStandInput = (inches) ->
id = '#' + inches
$( document ).on( "click", id, ->
stand = $(this).hasClass("stand")
width = $( this ).attr('id');
$(".button.disabled").attr("class", "button");
$( this ).attr( "class", "button disabled");
$( "small#standWalk" ).html(standHash[inches]);
if stand
$("#corn_stand_count_sample_row_width").attr('value', width );
$("#corn_stand_count_sample_row_length").attr('value', standHash[inches]);
$("#cornStandDirections").fadeIn("slow");
$("#cornStandDirections").attr( "class", "slow");
else
$("#corn_yield_sample_row_width").attr('value', width );
$("#corn_yield_sample_row_length").attr('value', standHash[inches]);
$("#cornYieldDirections").fadeIn("slow");
$("#cornYieldDirections").attr( "class", "slow");
false
);
FillStandInput(15);
FillStandInput(20);
FillStandInput(30);
FillStandInput(36);
FillStandInput(38);
$(document).on( "click", "a.openObserve", ->
$( "#observeTitle").html( this.id + "Sample" );
$( "#observeModal" ).foundation( "reveal", "open" );
false
);
$(document).on( "click", "a.th", ->
$( "#imageTagZoom" ).attr( "src", this.id);
$( "#imageZoom" ).foundation( "reveal", "open" );
false
)
$( document ).on('click', '#addKernals', ->
kernalsDiv = $( ".kernalsWrapper" );
$(kernalsDiv).append('<div id="kernals_around"><input type="number"
name="corn_yield_sample[kernals][]" class="kernalCount" id="cornYieldSampleInput">
<a href="" id="removeKernalInput" class="kill-kernal button small alert">X</a></div>');
false;
);
$( document ).on('click', '#addStand', ->
standDiv = $( ".standCountsWrapper" );
$(standDiv).append('<div id="stand_count"><input type="number"
name="corn_stand_count_sample[stand_counts][]" class="standCount" id="cornStandSampleInput">
<a href="" id="removeStandInput" class="kill-stand button small alert">X</a></div>');
false;
);
$( document ).on('click', '#removeKernalInput', ->
$(this).parent().remove();
false
);
$( document ).on('click', '#removeStandInput', ->
$(this).parent().remove();
false
);
$( document ).on("click", "#mathCheck", ->
ears = $('#corn_yield_sample_harvest_ears').val()
bushel_size = $('#corn_yield_sample_bushel_size').val()
x = 0
kernals = $(".kernalsWrapper")
kernals.children().each( ->
$(this).children('input').each( ->
x += Math.floor((this.value))
);
);
y = (x/kernals.children().length * 1000 * Math.floor(ears))/Math.floor(bushel_size)
equation1 = '((' + x.toString() + '/' + kernals.children().length.toString() + ')'
equation2 = ' ' + '*' + ' ' + '(1000' + ' ' + '*' + ' ' + ears + '))' + ' '+ '/' + ' ' + bushel_size
full_equation = equation1 + equation2
$("#showEquation").html('<a class="closeEquation" href="#"><h2>' + full_equation + '</h2></a>')
if $("#showEquation").attr( "class") is "hide"
$("#showEquation").toggle('show');
$("#showEquation").attr('class', 'show')
false
);
$(document).on("click", ".closeEquation", ->
$("#showEquation").toggle('hide')
$("#showEquation").attr("class", "hide")
false
)
$(document).on("click", ".openReport", ->
id = "#" + $(this).attr("id") + "Content"
$(id).slideToggle()
false
)
$(document).on("click", "#shareReport", ->
path = this.dataset.path
r_id = this.dataset.report
org_id = this.dataset.org
key = this.dataset.key
end_point = path + "organizations/" + org_id + "/reports/" + r_id
full_path = end_point + "/client_dashboard/" + key
$("input#shareReportContent").attr("value", full_path)
$("#shareReportModal").foundation('reveal', 'open')
$ ->
$("input#shareReportContent").select()
false
)
$(document).on("click", "#quickSelection", ->
$("#rec_options").toggle()
)
$(document).on("change", "#rec_options", ->
key = this.options.selectedIndex
text = this.options.item(key).value
change_recommendation("#report_recommendation", text)
)
change_recommendation = (id, text) ->
self = $(id)
self.val(text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment