adopt-a-hydrant/public/assets/application.js

1 line
15 KiB
JavaScript

$(function(){function j(a,b,c){var j=new google.maps.MarkerImage(c,new google.maps.Size(27,37),new google.maps.Point(0,0),new google.maps.Point(13,18)),k=new google.maps.MarkerImage("/assets/markers/shadow.png",new google.maps.Size(46,37),new google.maps.Point(0,0),new google.maps.Point(13,18)),l=new google.maps.Marker({animation:google.maps.Animation.DROP,icon:j,map:d,position:b,shadow:k});google.maps.event.addListener(l,"click",function(){g&&g.close();var b=new google.maps.InfoWindow({maxWidth:230});google.maps.event.addListener(b,"closeclick",function(){h=!1}),g=b,e=a,f=l,$.ajax({type:"GET",url:"/info_window",data:{thing_id:a},success:function(a){b==g&&(b.setContent(a),b.open(d,l),h=!0)}})}),i.push(a)}function k(b,c){$.ajax({type:"GET",url:"/things.json",data:{utf8:"✓",authenticity_token:$('#address_form input[name="authenticity_token"]').val(),lat:b,lng:c,limit:$('#address_form input[name="limit"]').val()},success:function(e){if(e.errors)$("#address_label").addClass("error",500),$("#address").addClass("error",500),$("#address").focus();else{$("#address_label").removeClass("error",500),$("#address").removeClass("error",500);var f=-1;$(e).each(function(a,b){if($.inArray(b.id,i)==-1)f+=1;else return!0;setTimeout(function(){point=new google.maps.LatLng(b.lat,b.lng),b.user_id?image_path="/assets/markers/green.png":image_path="/assets/markers/red.png",j(b.id,point,image_path)},f*100)}),a=new google.maps.LatLng(b,c),d.setCenter(a),d.setZoom(18)}}})}function l(){$('#combo-form input[type="text"]:visible, #combo-form input[type="password"]:visible, #combo-form input[type="submit"]:visible, #combo-form button:visible').each(function(a){if($(this).val()===""||$(this).attr("type")==="submit"||this.tagName.toLowerCase()==="button")return $(this).focus(),!1})}var a=new google.maps.LatLng(42.358431,-71.059773),b=15,c={center:a,mapTypeControl:!1,zoomControl:!1,mapTypeId:google.maps.MapTypeId.ROADMAP,panControl:!1,scrollwheel:!1,zoom:b},d=new google.maps.Map(document.getElementById("map"),c),e,f,g,h=!1,i=[];google.maps.event.addListener(d,"dragend",function(){if(h==1)return;a=d.getCenter(),k(a.lat(),a.lng())}),$("#address_form").live("submit",function(){var a=$("#address_form input[type='submit']");$(a).attr("disabled",!0);var b=$(a).attr("value");return $(a).attr("value","Please Wait..."),$("#address").val()===""?($(a).attr("disabled",!1),$(a).attr("value",b),$("#address_label").addClass("error",500),$("#address").addClass("error",500),$("#address").focus()):$.ajax({type:"GET",url:"/address.json",data:{utf8:"✓",authenticity_token:$('#address_form input[name="authenticity_token"]').val(),city_state:$("#city_state").val(),address:$("#address").val()},success:function(c){$(a).attr("disabled",!1),$(a).attr("value",b),c.errors?($("#address_label").addClass("error",500),$("#address").addClass("error",500),$("#address").focus()):k(c[0],c[1])}}),!1}),$('#combo-form input[type="radio"]').live("click",function(){var a=$(this);"new"==a.val()?($("#combo-form").data("state","user_sign_up"),$("#user_forgot_password_fields").slideUp(),$("#user_sign_in_fields").slideUp(),$("#user_sign_up_fields").slideDown(function(){l()})):"existing"==a.val()&&($("#user_sign_up_fields").slideUp(),$("#user_sign_in_fields").slideDown(function(){$("#combo-form").data("state","user_sign_in"),l(),$("#user_forgot_password_link").click(function(){$("#combo-form").data("state","user_forgot_password"),$("#user_sign_in_fields").slideUp(),$("#user_forgot_password_fields").slideDown(function(){l(),$("#user_remembered_password_link").click(function(){$("#combo-form").data("state","user_sign_in"),$("#user_forgot_password_fields").slideUp(),$("#user_sign_in_fields").slideDown(function(){l()})})})})}))}),$("#combo-form").live("submit",function(){var a=$("#combo-form input[type='submit']");$(a).attr("disabled",!0);var b=[];return/[\w\.%\+\]+@[\w\]+\.+[\w]{2,}/.test($("#user_email").val())?($("#user_email_label").removeClass("error"),$("#user_email").removeClass("error")):(b.push($("#user_email")),$("#user_email_label").addClass("error",500),$("#user_email").addClass("error",500)),!$(this).data("state")||$(this).data("state")==="user_sign_up"?($("#user_name").val()===""?(b.push($("#user_name")),$("#user_name_label").addClass("error",500),$("#user_name").addClass("error",500)):($("#user_name_label").removeClass("error"),$("#user_name").removeClass("error")),$("#user_password_confirmation").val().length<6||$("#user_password_confirmation").val().length>20?(b.push($("#user_password_confirmation")),$("#user_password_confirmation_label").addClass("error",500),$("#user_password_confirmation").addClass("error",500)):($("#user_password_confirmation_label").removeClass("error"),$("#user_password_confirmation").removeClass("error")),b.length>0?($(a).attr("disabled",!1),b[0].focus()):$.ajax({type:"POST",url:"/users.json",data:{utf8:"✓",authenticity_token:$('#combo-form input[name="authenticity_token"]').val(),user:{email:$("#user_email").val(),name:$("#user_name").val(),organization:$("#user_organization").val(),voice_number:$("#user_voice_number").val(),sms_number:$("#user_sms_number").val(),password:$("#user_password_confirmation").val(),password_confirmation:$("#user_password_confirmation").val()}},error:function(c){data=$.parseJSON(c.responseText),$(a).attr("disabled",!1),data.errors.email&&(b.push($("#user_email")),$("#user_email_label").addClass("error",500),$("#user_email").addClass("error",500)),data.errors.name&&(b.push($("#user_name")),$("#user_name_label").addClass("error",500),$("#user_name").addClass("error",500)),data.errors.organization&&(b.push($("#user_organization")),$("#user_organization_label").addClass("error",500),$("#user_organization").addClass("error",500)),data.errors.voice_number&&(b.push($("#user_voice_number")),$("#user_voice_number_label").addClass("error",500),$("#user_voice_number").addClass("error",500)),data.errors.sms_number&&(b.push($("#user_sms_number")),$("#user_sms_number_label").addClass("error",500),$("#user_sms_number").addClass("error",500)),data.errors.password&&(b.push($("#user_password_confirmation")),$("#user_password_confirmation_label").addClass("error",500),$("#user_password_confirmation").addClass("error",500)),b[0].focus()},success:function(a){$.ajax({type:"GET",url:"/sidebar/search",data:{flash:{notice:"Thanks for signing up!"}},success:function(a){$("#content").html(a)}})}})):$(this).data("state")==="user_sign_in"?($("#user_password").val().length<6||$("#user_password").val().length>20?(b.push($("#user_password")),$("#user_password_label").addClass("error",500),$("#user_password").addClass("error",500)):($("#user_password_label").removeClass("error"),$("#user_password").removeClass("error")),b.length>0?($(a).attr("disabled",!1),b[0].focus()):$.ajax({type:"POST",url:"/users/sign_in.json",data:{utf8:"✓",authenticity_token:$('#combo-form input[name="authenticity_token"]').val(),user:{email:$("#user_email").val(),password:$("#user_password").val(),remember_me:$("#user_remember_me").val()}},error:function(b){$(a).attr("disabled",!1),$("#user_password_label").addClass("error",500),$("#user_password").addClass("error",500),$("#user_password").focus()},success:function(a){$.ajax({type:"GET",url:"/sidebar/search",data:{flash:{notice:"Signed in!"}},success:function(a){$("#content").html(a)}})}})):$(this).data("state")==="user_forgot_password"&&(b.length>0?($(a).attr("disabled",!1),b[0].focus()):$.ajax({type:"POST",url:"/users/password.json",data:{utf8:"✓",authenticity_token:$('#combo-form input[name="authenticity_token"]').val(),user:{email:$("#user_email").val()}},error:function(b){$(a).attr("disabled",!1),$("#user_email_label").addClass("error",500),$("#user_email").addClass("error",500),$("#user_email").focus()},success:function(){$(a).attr("disabled",!1),$("#user_remembered_password_link").click(),$("#user_password").focus()}})),!1}),$("#adoption_form").live("submit",function(){var a=$("#adoption_form input[type='submit']");return $(a).attr("disabled",!0),$.ajax({type:"POST",url:"/things.json",data:{id:$("#thing_id").val(),utf8:"✓",authenticity_token:$('#adoption_form input[name="authenticity_token"]').val(),_method:"put",thing:{user_id:$("#thing_user_id").val(),name:$("#thing_name").val()}},beforeSend:function(){$("#info_window").hide(),$("#loader").show()},error:function(b){$("#loader").hide(),$("#info_window").show(),$(a).attr("disabled",!1)},success:function(a){$.ajax({type:"GET",url:"/info_window",data:{thing_id:e,flash:{notice:"You just adopted a hydrant!"}},success:function(a){g.setContent(a),image=new google.maps.MarkerImage("/assets/markers/green.png",new google.maps.Size(27,37),new google.maps.Point(0,0),new google.maps.Point(13,18)),f.setIcon(image),f.setAnimation(google.maps.Animation.BOUNCE)}})}}),!1}),$("#abandon_form").live("submit",function(){var a=window.confirm("Are you sure you want to abandon this hydrant?");if(a){var b=$("#abandon_form input[type='submit']");$(b).attr("disabled",!0),$.ajax({type:"POST",url:"/things.json",data:{id:$("#thing_id").val(),utf8:"✓",authenticity_token:$('#abandon_form input[name="authenticity_token"]').val(),_method:"put",thing:{user_id:$("#thing_user_id").val(),name:$("#thing_name").val()}},beforeSend:function(){$("#info_window").hide(),$("#loader").show()},error:function(a){$("#loader").hide(),$("#info_window").show(),$(b).attr("disabled",!1)},success:function(a){$.ajax({type:"GET",url:"/info_window",data:{thing_id:e,flash:{warning:"Hydrant abandoned!"}},success:function(a){g.setContent(a),image=new google.maps.MarkerImage("/assets/markers/red.png",new google.maps.Size(27,37),new google.maps.Point(0,0),new google.maps.Point(13,18)),f.setIcon(image),f.setAnimation(null)}})}})}return!1}),$("#edit_profile_form").live("submit",function(){var a=$("#edit_profile_form input[type='submit']");return $(a).attr("disabled",!0),$.ajax({type:"GET",url:"/users/edit",data:{utf8:"✓",authenticity_token:$('#edit_profile_form input[name="authenticity_token"]').val()},error:function(b){$(a).attr("disabled",!1)},success:function(a){$("#content").html(a)}}),!1}),$("#edit_form").live("submit",function(){var a=$("#edit_form input[type='submit']");$(a).attr("disabled",!0);var b=[];return/[\w\.%\+\]+@[\w\]+\.+[\w]{2,}/.test($("#user_email").val())?($("#user_email_label").removeClass("error"),$("#user_email").removeClass("error")):(b.push($("#user_email")),$("#user_email_label").addClass("error",500),$("#user_email").addClass("error",500)),$("#user_name").val()===""?(b.push($("#user_name")),$("#user_name_label").addClass("error",500),$("#user_name").addClass("error",500)):($("#user_name_label").removeClass("error"),$("#user_name").removeClass("error")),$("#user_password").val()&&($("#user_password").val().length<6||$("#user_password").val().length>20)?(b.push($("#user_password")),$("#user_password_label").addClass("error",500),$("#user_password").addClass("error",500)):($("#user_password_label").removeClass("error"),$("#user_password").removeClass("error")),$("#user_current_password").val().length<6||$("#user_current_password").val().length>20?(b.push($("#user_current_password")),$("#user_current_password_label").addClass("error",500),$("#user_current_password").addClass("error",500)):($("#user_current_password_label").removeClass("error"),$("#user_current_password").removeClass("error")),b.length>0?($(a).attr("disabled",!1),b[0].focus()):$.ajax({type:"POST",url:"/users.json",data:{id:$("#id").val(),thing_id:e,utf8:"✓",authenticity_token:$('#edit_form input[name="authenticity_token"]').val(),_method:"put",user:{email:$("#user_email").val(),name:$("#user_name").val(),organization:$("#user_organization").val(),voice_number:$("#user_voice_number").val(),sms_number:$("#user_sms_number").val(),password:$("#user_password").val(),password_confirmation:$("#user_password").val(),current_password:$("#user_current_password").val()}},error:function(c){data=$.parseJSON(c.responseText),$(a).attr("disabled",!1),data.errors.email&&(b.push($("#user_email")),$("#user_email_label").addClass("error",500),$("#user_email").addClass("error",500)),data.errors.name&&(b.push($("#user_name")),$("#user_name_label").addClass("error",500),$("#user_name").addClass("error",500)),data.errors.organization&&(b.push($("#user_organization")),$("#user_organization_label").addClass("error",500),$("#user_organization").addClass("error",500)),data.errors.voice_number&&(b.push($("#user_voice_number")),$("#user_voice_number_label").addClass("error",500),$("#user_voice_number").addClass("error",500)),data.errors.sms_number&&(b.push($("#user_sms_number")),$("#user_sms_number_label").addClass("error",500),$("#user_sms_number").addClass("error",500)),data.errors.password&&(b.push($("#user_password")),$("#user_password_label").addClass("error",500),$("#user_password").addClass("error",500)),data.errors.current_password&&(b.push($("#user_current_password")),$("#user_current_password_label").addClass("error",500),$("#user_current_password").addClass("error",500)),b[0].focus()},success:function(a){$("#content").html(a)}}),!1}),$("#sign_out_form").live("submit",function(){var a=$("#sign_out_form input[type='submit']");return $(a).attr("disabled",!0),$.ajax({type:"GET",url:"/users/sign_out.json",data:{utf8:"✓",authenticity_token:$('#sign_out_form input[name="authenticity_token"]').val()},error:function(b){$(a).attr("disabled",!1)},success:function(a){$.ajax({type:"GET",url:"/sidebar/combo_form",data:{flash:{warning:"Signed out."}},success:function(a){$("#content").html(a)}})}}),!1}),$("#sign_in_form").live("submit",function(){var a=$("#sign_in_form input[type='submit']");return $(a).attr("disabled",!0),$.ajax({type:"GET",url:"/users/sign_in",data:{utf8:"✓",authenticity_token:$('#sign_in_form input[name="authenticity_token"]').val()},beforeSend:function(){$("#info_window").hide(),$("#loader").show()},error:function(b){$("#loader").hide(),$("#info_window").show(),$(a).attr("disabled",!1)},success:function(a){g.setContent(a)}}),!1}),$("#back_form").live("submit",function(){var a=$("#back_form input[type='submit']");return $(a).attr("disabled",!0),$.ajax({type:"GET",url:"/sidebar/search",error:function(b){$(a).attr("disabled",!1)},success:function(a){$("#content").html(a)}}),!1}),$("#reminder_form").live("submit",function(){var a=$("#reminder_form input[type='submit']");return $(a).attr("disabled",!0),$.ajax({type:"POST",url:"/reminders.json",data:{utf8:"✓",authenticity_token:$('#reminder_form input[name="authenticity_token"]').val(),reminder:{from_user_id:$("#reminder_from_user_id").val(),to_user_id:$("#reminder_to_user_id").val(),thing_id:e}},beforeSend:function(){$("#info_window").hide(),$("#loader").show()},error:function(b){$("#loader").hide(),$("#info_window").show(),$(a).attr("disabled",!1)},success:function(a){$.ajax({type:"GET",url:"/info_window",data:{thing_id:e,flash:{notice:"Reminder sent!"}},success:function(a){g.setContent(a)}})}}),!1}),$("#tos_link").live("click",function(){return $.ajax({type:"GET",url:"/tos",beforeSend:function(){$("#info_window").hide(),$("#loader").show()},error:function(a){$("#loader").hide(),$("#info_window").show()},success:function(a){g.setContent(a)}}),!1}),$("#notice").live("click",function(){$(this).fadeOut("slow")}),$("#error").live("click",function(){$(this).fadeOut("slow")})})