
AWASA.schools={bindSchoolsAndGroupsMenu:function(){$("a[name=sg-add-school]").click(function(){AWASA.schools.getAddSchoolForm();return false;});$("a[name=sg-add-group]").click(function(){AWASA.groups.getAddGroupForm();return false;});$("a[name=sg-search-schools]").click(function(){AWASA.schools.bindSearchSchoolsForm();$(".sg-search-schools-form").slideDown();return false;});$("a[name=sg-search-groups]").click(function(){AWASA.groups.bindSearchGroupsForm();$(".sg-search-groups-form").slideDown();return false;});},storeNewSchool:function(){var form_data={'school_name':$('input[name=add-school-school-name]').val(),'school_type':$('select[name=add-school-school-type]').val(),'school_city':$('input[name=add-school-school-city]').val(),'school_state':$('select[name=add-school-school-state]').val()}
var request={'json_decode_these[]':['form_data'],'form_data':JSON.stringify(form_data),'class':'SchoolController','action':'storeNewSchool'}
AWASA.core.JSONRequest(request,AWASA.init.urls.school,AWASA.schools.onStoreSchool);return false;},onStoreSchool:function(response,code){if($('#overlay').length>0){$('#overlay').fadeOut('normal',function(){$('#overlay').remove();});AWASA.temp={'school_id':response.school_id}
AWASA.registration.getSchoolSelect($('select[name=student_types]').val());return;}
$("#add-edit .tab-content-message-space").html(response.message);$("input[name=add-school-school-name]").val("");$("input[name=add-school-school-city]").val("");$("select[name=add-school-school-type] option:first").attr("selected","selected");$("select[name=add-school-school-state] option:first").attr("selected","selected");},getAddSchoolForm:function(){AWASA.core.JSONRequest({"class":"FormServer","which":"AddSchool"},AWASA.init.urls.school,function(response,code){$("#add-edit .tab-content-title").html("<h2>Add School</h2>");$("#add-edit .tab-content-content").html(response.content);AWASA.schools.bindAddSchoolForm();});},bindAddSchoolForm:function(){$("button[name=add-school-cancel]").hide();$("button[name=add-school-store]").click(function(){AWASA.schools.storeNewSchool();return false;});},getSearchSchoolsForm:function(){AWASA.core.JSONRequest({"class":"FormServer","which":"SearchSchools"},AWASA.init.urls.school,function(response,code){$("a[name=sg-add-school]").after(response.content).slideDown();AWASA.schools.bindSearchSchoolsForm(response,code);});},bindSearchSchoolsForm:function(response,code){$("button[name=search-schools-submit-search]").click(function(){AWASA.schools.searchForSchools();});$("button[name=search-schools-hide-search]").click(function(){$(".sg-search-schools-form").slideUp();});},searchForSchools:function(){AWASA.core.JSONRequest({"class":"SearchController","method":"searchforschools"},AWASA.init.urls.schools,AWASA.schools.displaySchoolsResults);},getSchoolsSelect:function(school_type){var request={'school_type':school_type,"class":"RegistrationController","action":'GetSchoolsSelect',"selector":"#modify-contact-school-select-wrapper"}
AWASA.core.showSmallSpinner("select[name=modify-contact-schools-select]");AWASA.core.JSONRequest(request,AWASA.init.urls.school,AWASA.schools.loadSchoolsSelect);},loadSchoolsSelect:function(resp,code){$(resp.selector).html(resp.content).css('class','float-left');AWASA.core.hideSmallSpinner('select[name=schools]');$('select[name=schools]').change(function(){var request={"school_id":$(this).val(),"class":'RegistrationController',"action":'GetGroupsSelect',"selector":"#modify-contact-groups-select-wrapper"}
AWASA.core.showSmallSpinner('select[name=modify-contact-groups-select]');AWASA.core.JSONRequest(request,AWASA.init.urls.school,AWASA.groups.loadGroupsSelect);});if(typeof AWASA.registration.user!="undefined"){$('select[name=schools] option[value='+AWASA.registration.user.school_id+']').attr('selected','selected').change();}
if(typeof AWASA.temp!="undefined"){$('select[name=schools] option[value='+AWASA.temp.school_id+']').attr('selected','selected').change();AWASA.temp=undefined;}},bindSearchResultSet:function(){$(".search-schools-view-groups").click(function(){AWASA.core.JSONRequest({"class":"SchoolController","action":"viewGroups","school_id":$(this).attr('name')},AWASA.init.urls.school,function(response,code){AWASA.core.showOverlay({},response.content,AWASA.schools.bindSchoolGroupsList);});});$(".search-schools-view-people").click(function(){AWASA.core.JSONRequest({"class":"SchoolController","action":"viewPeople","school_id":$(this).attr('name')},AWASA.init.urls.school,function(response,code){AWASA.core.showOverlay({},response.content,AWASA.schools.bindSchoolContactsList);});});$(".search-schools-delete-school").click(function(){if(confirm('Are you sure you wish to remove this school?')){AWASA.core.JSONRequest({"class":"SchoolController","action":"hideSchool","school_id":$(this).attr('name')},AWASA.init.urls.school,function(){AWASA.search.showPage(AWASA.search.settings.page_num);return false;});}});$(".search-schools-edit-school").click(function(){AWASA.core.JSONRequest({"class":"SchoolController","action":"loadSchoolForEdit","school_id":$(this).attr('name')},AWASA.init.urls.school,AWASA.schools.call_back);});$('.search-schools-edit-school-notes').click(function(){var school_id=$(this).attr('name');var content="<div class='input-group light-blue-border ui-corner-all'>"+"<div class='input-group-label ui-corner-all'>Notes</div>"+"<textarea name='"+school_id+"' class='search-schools-school-notes-textarea'>"+
$('.search-schools-school-notes').val()
+"</textarea>"
+"<button class='close light-blue-border ui-corner-all float-left clear-left' type='button'><img src='theme/images/disk.png' alt='' />&nbsp;Close & Save</button>"
+"</div>";AWASA.core.showOverlay({},content,AWASA.schools.bindEditSchoolNotes);});},bindSchoolContactsList:function(){$('.search-schools-people-list-edit').click(function(){});$('.search-schools-people-list-remove').click(function(){if(confirm("Are you sure you wish to remove this person from this school?")){AWASA.jr({"class":"SchoolController","action":"removePersonFromSchool","contact_id":$(this).attr('name')},AWASA.init.urls.school,function(response,code){$('#overlay').remove();AWASA.jr({"class":"SchoolController","action":"viewPeople","school_id":$('.search-schools-popup-school-id').attr('name')},AWASA.init.urls.school,function(response,code){AWASA.core.showOverlay({},response.content,AWASA.schools.bindSchoolContactsList);});});}});},bindSchoolGroupsList:function(){$(".search-schools-group-list-edit").click(function(){});$(".search-schools-group-list-remove").click(function(){if(confirm("Are you sure you wish to remove this group from this school?")){AWASA.jr({"class":"SchoolController","action":"removeGroupFromSchool","grp_id":$(this).attr('name')},AWASA.init.urls.school,function(response,code){$('#overlay').remove();AWASA.jr({"class":"SchoolController","action":"viewGroups","school_id":$('.search-schools-popup-school-id').attr('name')},AWASA.init.urls.school,function(response,code){AWASA.core.showOverlay({},response.content,AWASA.schools.bindSchoolGroupsList);});});}});},bindEditSchoolNotes:function(){$('.search-schools-school-notes-textarea').blur(function(){$('.search-schools-school-notes').val($(this).val());AWASA.core.JSONRequest({"class":"SchoolController","action":"storeSingleValue","var":"school_notes","val":$(this).val(),"use_quotes":true,"school_id":$(this).attr('name')},AWASA.init.urls.school,function(){});});}}