- Add a notice_ javascript function for testing, yup, it works

- Reimplement the new award functionality
- Fix the reloading of the dialog by disabling all tabs and reselecting one.  It works properly now.
This commit is contained in:
dave 2009-09-18 07:50:32 +00:00
parent 7b22ff39e7
commit 2762a12eb0
2 changed files with 119 additions and 69 deletions

View File

@ -34,13 +34,6 @@
echo json_encode($ret); echo json_encode($ret);
exit; 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': case 'award_delete':
$id=intval($_GET['id']); $id=intval($_GET['id']);
mysql_query("DELETE FROM award_prizes WHERE award_awards_id='$id'"); mysql_query("DELETE FROM award_prizes WHERE award_awards_id='$id'");
@ -53,6 +46,15 @@
/* Scrub the data while we save it */ /* Scrub the data while we save it */
$id=intval($_POST['id']); $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 "<script type=\"text/javascript\">award_id=$id;</script>";
}
$q = "UPDATE award_awards SET $q = "UPDATE award_awards SET
name='".mysql_escape_string(stripslashes($_POST['name']))."', name='".mysql_escape_string(stripslashes($_POST['name']))."',
sponsors_id='".intval($_POST['sponsors_id'])."', sponsors_id='".intval($_POST['sponsors_id'])."',
@ -65,7 +67,7 @@
criteria='".mysql_escape_string(stripslashes($_POST['criteria']))."', criteria='".mysql_escape_string(stripslashes($_POST['criteria']))."',
description='".mysql_escape_string(stripslashes($_POST['description']))."' description='".mysql_escape_string(stripslashes($_POST['description']))."'
WHERE id='$id'"; WHERE id='$id'";
happy_("Award Information Saved."); happy_("Award information saved");
mysql_query($q); mysql_query($q);
exit; exit;
@ -113,7 +115,7 @@
mysql_query("INSERT INTO award_awards_projectdivisions (award_awards_id,projectdivisions_id,year) mysql_query("INSERT INTO award_awards_projectdivisions (award_awards_id,projectdivisions_id,year)
VALUES ('$id','$d','{$config['FAIRYEAR']}')"); VALUES ('$id','$d','{$config['FAIRYEAR']}')");
} }
happy_("Saved."); happy_("Eligibility information saved");
exit; exit;
case 'prize_order': case 'prize_order':
@ -134,7 +136,7 @@
$order++; $order++;
mysql_query("UPDATE `award_awards` SET `order`='$order' WHERE `id`='$id'"); mysql_query("UPDATE `award_awards` SET `order`='$order' WHERE `id`='$id'");
} }
happy_("Order Updated."); happy_("Order updated");
exit; exit;
case 'prizeinfo_load': case 'prizeinfo_load':
@ -235,7 +237,7 @@
$ident=mysql_escape_string(stripslashes($_POST['identifier'])); $ident=mysql_escape_string(stripslashes($_POST['identifier']));
mysql_query("UPDATE award_awards SET external_identifier='$ident' WHERE id='$id'"); mysql_query("UPDATE award_awards SET external_identifier='$ident' WHERE id='$id'");
happy_("Saved"); happy_("Feeder Fair information saved");
exit; exit;
} }
@ -252,10 +254,25 @@ var award_id = 0;
function update_awardinfo() function update_awardinfo()
{ {
var id = award_id; // alert(award_id);
if(!award_id) return false; if(award_id == -1) {
// alert("id="+award_id); /* New award, set defaults and clear everythign else */
$.getJSON("<?=$_SERVER['PHP_SELF']?>?action=awardinfo_load&id="+id, $("#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){ function(json){
$("#awardinfo_id").val(json.id); $("#awardinfo_id").val(json.id);
$("#awardinfo_name").val(json.name); $("#awardinfo_name").val(json.name);
@ -269,20 +286,36 @@ function update_awardinfo()
$("#awardinfo_cwsfaward").val([json.cwsfaward]); $("#awardinfo_cwsfaward").val([json.cwsfaward]);
$("#awardinfo_selfnominate").val([json.self_nominate]); $("#awardinfo_selfnominate").val([json.self_nominate]);
$("#awardinfo_schedulejudges").val([json.schedule_judges]); $("#awardinfo_schedulejudges").val([json.schedule_judges]);
}); });
} }
function awardinfo_save() function awardinfo_save()
{ {
$("#debug").load("<?$_SERVER['PHP_SELF']?>?action=awardinfo_save", $("#awardinfo").serializeArray()); var reload = (award_id == -1) ? true : false;
return 0; /* 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() function update_eligibility()
{ {
var id = award_id; $.getJSON("<?=$_SERVER['PHP_SELF']?>?action=eligibilty_load&id="+award_id,
$.getJSON("<?=$_SERVER['PHP_SELF']?>?action=eligibilty_load&id="+id,
function(json){ function(json){
$("#eligibility_id").val(json.id); $("#eligibility_id").val(json.id);
$("[name=categories\\[\\]]").val(json.categories); $("[name=categories\\[\\]]").val(json.categories);
@ -308,8 +341,8 @@ function prizelist_refresh()
function update_prizeinfo() function update_prizeinfo()
{ {
var id = award_id; /* This also works for the prize template, id=-1 */
$.getJSON("<?=$_SERVER['PHP_SELF']?>?action=prizeinfo_load&id="+id, $.getJSON("<?=$_SERVER['PHP_SELF']?>?action=prizeinfo_load&id="+award_id,
function(json) { function(json) {
$(".prizelist_tr").remove(); $(".prizelist_tr").remove();
for( var i in json ) { for( var i in json ) {
@ -354,14 +387,14 @@ function edit_prize(id)
function eligibility_save() function eligibility_save()
{ {
$("#debug").load("<?$_SERVER['PHP_SELF']?>?action=eligibility_save", $("#eligibility").serializeArray()); $("#debug").load("<?$_SERVER['PHP_SELF']?>?action=eligibility_save", $("#eligibility").serializeArray());
return 0; return false;
} }
function prize_save() function prize_save()
{ {
$("#debug").load("<?$_SERVER['PHP_SELF']?>?action=prize_save", $("#prizeinfo").serializeArray()); $("#debug").load("<?$_SERVER['PHP_SELF']?>?action=prize_save", $("#prizeinfo").serializeArray());
update_prizeinfo(); update_prizeinfo();
return 0; return false;
} }
function prize_delete(id) function prize_delete(id)
@ -378,8 +411,7 @@ function prize_delete(id)
function prize_create() function prize_create()
{ {
var id = award_id; $.getJSON("<?=$_SERVER['PHP_SELF']?>?action=prize_create&award_awards_id="+award_id,
$.getJSON("<?=$_SERVER['PHP_SELF']?>?action=prize_create&award_awards_id="+id,
function(json){ function(json){
$(".prizeinfo").val(""); $(".prizeinfo").val("");
$("#prizeinfo_id").val(json.id); $("#prizeinfo_id").val(json.id);
@ -392,10 +424,9 @@ function prize_create()
function update_feeder() function update_feeder()
{ {
var id = award_id; $.getJSON("<?=$_SERVER['PHP_SELF']?>?action=feeder_load&id="+award_id,
$.getJSON("<?=$_SERVER['PHP_SELF']?>?action=feeder_load&id="+id,
function(json) { function(json) {
$("#feeder_id").val(id); $("#feeder_id").val(award_id);
$("#feeder_identifier").val(json.identifier); $("#feeder_identifier").val(json.identifier);
$("[name=feeder_dl\\[\\]]").val(json.dl); $("[name=feeder_dl\\[\\]]").val(json.dl);
$("[name=feeder_ul\\[\\]]").val(json.ul); $("[name=feeder_ul\\[\\]]").val(json.ul);
@ -407,7 +438,7 @@ function update_feeder()
function feeder_save() function feeder_save()
{ {
$("#debug").load("<?$_SERVER['PHP_SELF']?>?action=feeder_save", $("#feeder_form").serializeArray()); $("#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({ $("#popup_editor").dialog({
bgiframe: true, autoOpen: false, bgiframe: true, autoOpen: false,
modal: true, resizable: 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({ $("#editor_tabs").tabs({
@ -435,8 +473,10 @@ $(document).ready(function() {
update_feeder(); update_feeder();
break; break;
} }
return true;
}, },
selected: 0, collapsible: true,
selected: -1, /* None selected */
}); });
}); });
@ -508,8 +548,9 @@ $(document).ready(function() {
<tr><td class="left"> <tr><td class="left">
<input type="checkbox" id="awardinfo_schedulejudges" name="schedule_judges" value="yes"></td> <input type="checkbox" id="awardinfo_schedulejudges" name="schedule_judges" value="yes"></td>
<td class="right"><?=i18n("Allow the Automatic Judge Scheduler to assign judges to this award (usually checked)")?></td></tr> <td class="right"><?=i18n("Allow the Automatic Judge Scheduler to assign judges to this award (usually checked)")?></td></tr>
</table></form> </table>
<input type="submit" onClick="awardinfo_save();" value="Save" /> <input type="submit" onClick="awardinfo_save();return false;" value="Save" />
</form>
</div> </div>
<? /* Next Tab */ ?> <? /* Next Tab */ ?>
@ -544,8 +585,8 @@ $(document).ready(function() {
?> ?>
</td></tr></table> </td></tr></table>
<input type="submit" onClick="eligibility_save();return false;" value="Save" />
</form> </form>
<input type="submit" onClick="eligibility_save();" value="Save" />
</div> </div>
<? /* Next Tab */ ?> <? /* Next Tab */ ?>
@ -609,8 +650,10 @@ $(document).ready(function() {
</table> </table>
</form> </form>
<br /> <br />
<input type="submit" onClick="prize_create();" value="<?=i18n("Create New Prize")?>" /> <form>
<input type="submit" id="prizeinfo_save" onClick="prize_save();" value="<?=i18n("Save Prize")?>" disabled="disabled" /> <input type="submit" onClick="prize_create();return false;" value="<?=i18n("Create New Prize")?>" />
<input type="submit" id="prizeinfo_save" onClick="prize_save();return false;" value="<?=i18n("Save Prize")?>" disabled="disabled" />
</form>
</div> </div>
<? /* Next Tab */ ?> <? /* Next Tab */ ?>
@ -642,10 +685,9 @@ $(document).ready(function() {
} }
?> ?>
</table> </table>
</form>
<br /> <br />
<input type="submit" onClick="feeder_save();return false;" value="<?=i18n("Save")?>" />
<input type="submit" onClick="feeder_save();" value="<?=i18n("Save")?>" /> </form>
</div> </div>
@ -659,25 +701,42 @@ $(document).ready(function() {
<script type="text/javascript"> <script type="text/javascript">
function popup_editor(id) function popup_editor(id, mode)
{ {
var w = (document.documentElement.clientWidth * 0.8); var w = (document.documentElement.clientWidth * 0.8);
var h = (document.documentElement.clientHeight * 0.8); var h = (document.documentElement.clientHeight * 0.8);
award_id = id;
/* Force no tabs to be selected, need to set collapsible
* to true first */
$('#editor_tabs').tabs('option', 'collapsible', true);
$('#editor_tabs').tabs('option', 'selected', -1);
/* Then we'll select a tab to force a reload */
switch(mode) {
case 'new':
$('#editor_tabs').tabs('option', 'disabled', [1, 2, 3]);
$('#editor_tabs').tabs('select', 0);
break;
case 'template':
$('#editor_tabs').tabs('option', 'disabled', [0, 1, 3]);
$('#editor_tabs').tabs('select', 2);
break;
default:
$('#editor_tabs').tabs('option', 'disabled', []);
$('#editor_tabs').tabs('select', 0);
break;
}
/* Don't let anything collapse */
$('#editor_tabs').tabs('option', 'collapsible', false);
/* Show the dialog */
$('#popup_editor').dialog('option', 'width', w); $('#popup_editor').dialog('option', 'width', w);
$('#popup_editor').dialog('option', 'height', h); $('#popup_editor').dialog('option', 'height', h);
$("#popup_editor").dialog('open'); $("#popup_editor").dialog('open');
award_id = id; return true;
if(id == -1) {
$('#editor_tabs').tabs('option', 'selected', 2);
$('#editor_tabs').tabs('option', 'disabled', [0, 1, 3]);
} else {
$('#editor_tabs').tabs('option', 'disabled', []);
$('#editor_tabs').tabs('option', 'selected', 0);
update_awardinfo();
}
return 0;
} }
function awardlist_refresh() function awardlist_refresh()
@ -701,19 +760,6 @@ function awardlist_refresh()
}); });
} }
function award_create()
{
$.getJSON("<?=$_SERVER['PHP_SELF']?>?action=award_create",
function(json) {
popup_editor(json.id);
/* Ensure we open on the first tab */
$('#editor_tabs').tabs('option', 'selected', 0);
});
// alert("ok");
return 0;
}
function award_delete(id) function award_delete(id)
{ {
var conf = confirmClick('<?=i18n("Are you sure you want to remove this award?")?>'); var conf = confirmClick('<?=i18n("Are you sure you want to remove this award?")?>');
@ -731,8 +777,6 @@ function award_delete(id)
$(document).ready(function() { $(document).ready(function() {
awardlist_refresh(); awardlist_refresh();
// $(".awardlist_tr#166").css('background-color','red');
}); });
</script> </script>
@ -825,8 +869,8 @@ echo "</table>";
?> ?>
<br /> <br />
<form> <form>
<input type="button" onClick="award_create();" value="<?=i18n("Create New Award")?>" /> <input type="button" onClick="popup_editor(-1, 'new');" value="<?=i18n("Create New Award")?>" />
<input type="button" onClick="popup_editor(-1);" value="<?=i18n("Edit Generic Prize Template")?>" /> <input type="button" onClick="popup_editor(-1, 'template');" value="<?=i18n("Edit Generic Prize Template")?>" />
</form> </form>
<br /><br /> <br /><br />
@ -880,7 +924,7 @@ if(mysql_num_rows($q))
$hasexternal=false; $hasexternal=false;
while($r=mysql_fetch_object($q)) { while($r=mysql_fetch_object($q)) {
$cl = ($r->award_source_fairs_id) ? externalaward : ''; $cl = ($r->award_source_fairs_id) ? externalaward : '';
$eh = "style=\"cursor:pointer;\" onclick=\"popup_editor({$r->id});\""; $eh = "style=\"cursor:pointer;\" onclick=\"popup_editor({$r->id},'');\"";
echo "<tr class=\"$cl awardlist_tr\" id=\"{$r->id}\" >\n"; echo "<tr class=\"$cl awardlist_tr\" id=\"{$r->id}\" >\n";
echo " <td id=\"awardlist_order_{$r->id}\" class=\"drag_handle\" style=\"cursor:move; text-align:right;\">{$r->order}</td>\n"; echo " <td id=\"awardlist_order_{$r->id}\" class=\"drag_handle\" style=\"cursor:move; text-align:right;\">{$r->order}</td>\n";
echo " <td $eh>{$r->organization}</td>\n"; echo " <td $eh>{$r->organization}</td>\n";
@ -912,7 +956,7 @@ if(mysql_num_rows($q))
?><script type="text/javascript"> ?><script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
popup_editor(-1); popup_editor(-1,'template');
}); });
</script> </script>
<? <?

View File

@ -49,6 +49,7 @@ function notice_delete(id)
function notice_create(type,str,timeout) function notice_create(type,str,timeout)
{ {
if(timeout == -1) timeout = 5000;
_notice_id++; _notice_id++;
$("#notice_area").append("<div id=\"notice_"+_notice_id+"\" class=\"notice "+type+"\" >"+str+"</div>"); $("#notice_area").append("<div id=\"notice_"+_notice_id+"\" class=\"notice "+type+"\" >"+str+"</div>");
$("#notice_"+_notice_id).show('puff'); $("#notice_"+_notice_id).show('puff');
@ -56,6 +57,11 @@ function notice_create(type,str,timeout)
setTimeout("notice_delete("+_notice_id+")", timeout); setTimeout("notice_delete("+_notice_id+")", timeout);
} }
function notice_(str)
{
notice_create('notice',str,-1);
}
/* Stuff to do after the document loads */ /* Stuff to do after the document loads */
$(document).ready(function() $(document).ready(function()
{ {