diff --git a/admin/award_awards.php b/admin/award_awards.php index 12d1c3b..ddf317a 100644 --- a/admin/award_awards.php +++ b/admin/award_awards.php @@ -34,13 +34,6 @@ echo json_encode($ret); exit; - case 'award_create': - $q=mysql_query("INSERT INTO award_awards (year,self_nominate,schedule_judges) - VALUES ('{$config['FAIRYEAR']}','yes','yes')"); - $ret = array('id' => mysql_insert_id() ); - echo json_encode($ret); - exit; - case 'award_delete': $id=intval($_GET['id']); mysql_query("DELETE FROM award_prizes WHERE award_awards_id='$id'"); @@ -53,6 +46,15 @@ /* Scrub the data while we save it */ $id=intval($_POST['id']); + if($id == -1) { + $q=mysql_query("INSERT INTO award_awards (year,self_nominate,schedule_judges) + VALUES ('{$config['FAIRYEAR']}','yes','yes')"); + $id = mysql_insert_id(); + happy_("Award Created"); + /* Set the award_id in the client */ + echo ""; + } + $q = "UPDATE award_awards SET name='".mysql_escape_string(stripslashes($_POST['name']))."', sponsors_id='".intval($_POST['sponsors_id'])."', @@ -65,7 +67,7 @@ criteria='".mysql_escape_string(stripslashes($_POST['criteria']))."', description='".mysql_escape_string(stripslashes($_POST['description']))."' WHERE id='$id'"; - happy_("Award Information Saved."); + happy_("Award information saved"); mysql_query($q); exit; @@ -113,7 +115,7 @@ mysql_query("INSERT INTO award_awards_projectdivisions (award_awards_id,projectdivisions_id,year) VALUES ('$id','$d','{$config['FAIRYEAR']}')"); } - happy_("Saved."); + happy_("Eligibility information saved"); exit; case 'prize_order': @@ -134,7 +136,7 @@ $order++; mysql_query("UPDATE `award_awards` SET `order`='$order' WHERE `id`='$id'"); } - happy_("Order Updated."); + happy_("Order updated"); exit; case 'prizeinfo_load': @@ -235,7 +237,7 @@ $ident=mysql_escape_string(stripslashes($_POST['identifier'])); mysql_query("UPDATE award_awards SET external_identifier='$ident' WHERE id='$id'"); - happy_("Saved"); + happy_("Feeder Fair information saved"); exit; } @@ -252,10 +254,25 @@ var award_id = 0; function update_awardinfo() { - var id = award_id; - if(!award_id) return false; -// alert("id="+award_id); - $.getJSON("=$_SERVER['PHP_SELF']?>?action=awardinfo_load&id="+id, +// alert(award_id); + if(award_id == -1) { + /* New award, set defaults and clear everythign else */ + $("#awardinfo_id").val(-1); + $("#awardinfo_name").val(""); + $("#awardinfo_sponsors_id").val(0); + $("#awardinfo_presenter").val(""); + $("#awardinfo_description").val(""); + $("#awardinfo_criteria").val(""); + $("#awardinfo_award_types_id").val(5); + // For some reason, with checkboxes, these have to be arrays + $("#awardinfo_excludefromac").val([]); + $("#awardinfo_cwsfaward").val([]); + $("#awardinfo_selfnominate").val(["yes"]); + $("#awardinfo_schedulejudges").val(["yes"]); + return; + } + + $.getJSON("=$_SERVER['PHP_SELF']?>?action=awardinfo_load&id="+award_id, function(json){ $("#awardinfo_id").val(json.id); $("#awardinfo_name").val(json.name); @@ -269,20 +286,36 @@ function update_awardinfo() $("#awardinfo_cwsfaward").val([json.cwsfaward]); $("#awardinfo_selfnominate").val([json.self_nominate]); $("#awardinfo_schedulejudges").val([json.schedule_judges]); + }); } function awardinfo_save() { - $("#debug").load("$_SERVER['PHP_SELF']?>?action=awardinfo_save", $("#awardinfo").serializeArray()); - return 0; + var reload = (award_id == -1) ? true : false; + /* This is sneaky, we're going to make the awardinfo_save possibly emit + * javascript to set a new award_id, so it will ALWAYS be correct + * after the .load finishes */ + $("#debug").load("$_SERVER['PHP_SELF']?>?action=awardinfo_save", $("#awardinfo").serializeArray(), + function(responseText, textStatus, XMLHttpRequest) + { + /* At this point, award_id has been updated by the load */ + /* We want to do this AFTER the load completes. + * Somehow, the value of reload properly makes + * it into this function */ + if(reload) { + $("#popup_editor").dialog('close'); + popup_editor(award_id, ''); + } + + }); + return false; } function update_eligibility() { - var id = award_id; - $.getJSON("=$_SERVER['PHP_SELF']?>?action=eligibilty_load&id="+id, + $.getJSON("=$_SERVER['PHP_SELF']?>?action=eligibilty_load&id="+award_id, function(json){ $("#eligibility_id").val(json.id); $("[name=categories\\[\\]]").val(json.categories); @@ -308,8 +341,8 @@ function prizelist_refresh() function update_prizeinfo() { - var id = award_id; - $.getJSON("=$_SERVER['PHP_SELF']?>?action=prizeinfo_load&id="+id, + /* This also works for the prize template, id=-1 */ + $.getJSON("=$_SERVER['PHP_SELF']?>?action=prizeinfo_load&id="+award_id, function(json) { $(".prizelist_tr").remove(); for( var i in json ) { @@ -354,14 +387,14 @@ function edit_prize(id) function eligibility_save() { $("#debug").load("$_SERVER['PHP_SELF']?>?action=eligibility_save", $("#eligibility").serializeArray()); - return 0; + return false; } function prize_save() { $("#debug").load("$_SERVER['PHP_SELF']?>?action=prize_save", $("#prizeinfo").serializeArray()); update_prizeinfo(); - return 0; + return false; } function prize_delete(id) @@ -378,8 +411,7 @@ function prize_delete(id) function prize_create() { - var id = award_id; - $.getJSON("=$_SERVER['PHP_SELF']?>?action=prize_create&award_awards_id="+id, + $.getJSON("=$_SERVER['PHP_SELF']?>?action=prize_create&award_awards_id="+award_id, function(json){ $(".prizeinfo").val(""); $("#prizeinfo_id").val(json.id); @@ -392,10 +424,9 @@ function prize_create() function update_feeder() { - var id = award_id; - $.getJSON("=$_SERVER['PHP_SELF']?>?action=feeder_load&id="+id, + $.getJSON("=$_SERVER['PHP_SELF']?>?action=feeder_load&id="+award_id, function(json) { - $("#feeder_id").val(id); + $("#feeder_id").val(award_id); $("#feeder_identifier").val(json.identifier); $("[name=feeder_dl\\[\\]]").val(json.dl); $("[name=feeder_ul\\[\\]]").val(json.ul); @@ -407,7 +438,7 @@ function update_feeder() function feeder_save() { $("#debug").load("$_SERVER['PHP_SELF']?>?action=feeder_save", $("#feeder_form").serializeArray()); - return 0; + return false; } @@ -416,7 +447,14 @@ $(document).ready(function() { $("#popup_editor").dialog({ bgiframe: true, autoOpen: false, modal: true, resizable: false, - draggable: false + draggable: false, + close: function() { + var $tabs = $('#editor_tabs').tabs(); + var selected = $tabs.tabs('option', 'selected'); + if(award_id == -1 && selected== 0) { + notice_("=i18n('New Award Cancelled')?>"); + } + } }); $("#editor_tabs").tabs({ @@ -435,8 +473,10 @@ $(document).ready(function() { update_feeder(); break; } + return true; }, - selected: 0, + collapsible: true, + selected: -1, /* None selected */ }); }); @@ -508,8 +548,9 @@ $(document).ready(function() {