Refactor dialog code into separate include file

CSS changes for IE and for Dialog use
Switch fund types to use dialog (cant save yet)
This commit is contained in:
james 2008-10-24 22:29:14 +00:00
parent 18de1e13cf
commit b62fa76aab
5 changed files with 213 additions and 168 deletions

View File

@ -30,7 +30,8 @@ if($_POST['action']=="sponsorshipedit" || $_POST['action']=="sponsorshipadd") {
$sponsors_id=intval($_POST['sponsors_id']);
$sponsorships_id=intval($_POST['sponsorships_id']);
$fundraising_type=mysql_real_escape_string($_POST['fundraising_type']);
$value=intval($_POST['value']);
$value=mysql_real_escape_string($_POST['value']);
$status=mysql_real_escape_string($_POST['status']);
$probability=mysql_real_escape_string($_POST['probability']);
@ -46,8 +47,9 @@ if($_POST['action']=="sponsorshipedit") {
else
message_push(happy(i18n("Saved sponsorship changes")));
}
else
else {
message_push(error(i18n("Required fields were missing, please try again")));
}
}
if($_POST['action']=="sponsorshipadd") {
@ -68,114 +70,7 @@ if($_POST['action']=="sponsorshipadd") {
"fundraising"
);
require_once("../ajax.inc.php");
?>
<div class="SFIABDialog" id="SFIABDialog" style="position: absolute; visibility: hidden;">
<div class="SFIABDialogInner" id="SFIABDialogInner"></div>
</div>
<script type="text/javascript">
function SFIABDialogSubmit() {
//we let it submit the form, which reloads the page
return true;
}
function SFIABDialogCancel() {
var d=document.getElementById('SFIABDialog');
var di=document.getElementById('SFIABDialogInner');
d.style.visibility="hidden";
di.style.visibility="hidden";
return false;
}
var SFIABDialogGrowWidth=0;
var SFIABDialogGrowHeight=0;
var SFIABDialogFinalWidth=100;
var SFIABDialogFinalHeight=100;
var SFIABDialogGrowWidthStep=0;
var SFIABDialogGrowHeightStep=0;
var SFIABDialogGrowTime=200; //1 second
var SFIABDialogGrowSteps=10;
function SFIABDialog(e, url, width, height) {
var posx = 0;
var posy = 0;
//get this going while we do the other stuff
SFIABDialogFill(url);
if(!e) var e = window.event;
if (e.pageX || e.pageY) {
posx = e.pageX;
posy = e.pageY;
}
else if (e.clientX || e.clientY) {
posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
}
var d=document.getElementById('SFIABDialog');
var di=document.getElementById('SFIABDialogInner');
d.style.top=posy+'px';
d.style.left=posx+'px';
d.style.visibility='visible';
di.style.visibility='hidden';
SFIABDialogGrowWidth=1;
SFIABDialogGrowHeight=1;
SFIABDialogFinalWidth=width;
SFIABDialogFinalHeight=height;
d.style.width=SFIABDialogGrowWidth+"px";
d.style.height=SFIABDialogGrowHeight+"px";
SFIABDialogGrowWidthStep=Math.round(width/SFIABDialogGrowSteps);
SFIABDialogGrowHeightStep=Math.round(height/SFIABDialogGrowSteps);
setTimeout('growDialog()',Math.round(SFIABDialogGrowTime/SFIABDialogGrowSteps));
}
function growDialog() {
SFIABDialogGrowWidth+=SFIABDialogGrowWidthStep;
SFIABDialogGrowHeight+=SFIABDialogGrowHeightStep;
if(SFIABDialogGrowWidth>SFIABDialogFinalWidth)
SFIABDialogGrowWidth=SFIABDialogFinalWidth;
if(SFIABDialogGrowHeight>SFIABDialogFinalHeight)
SFIABDialogGrowHeight=SFIABDialogFinalHeight;
var d=document.getElementById('SFIABDialog');
d.style.width=SFIABDialogGrowWidth+"px";
d.style.height=SFIABDialogGrowHeight+"px";
if(SFIABDialogGrowWidth<SFIABDialogFinalWidth || SFIABDialogGrowHeight<SFIABDialogFinalHeight)
setTimeout('growDialog()',Math.round(SFIABDialogGrowTime/SFIABDialogGrowSteps));
else {
var di=document.getElementById('SFIABDialogInner');
di.style.visibility="visible";
}
}
function SFIABDialogFill(url) {
var d=document.getElementById('SFIABDialogInner');
d.innerHTML="";
http.open("GET",url,true);
http.onreadystatechange=SFIABDialogFillResponse;
http.send(null);
}
function SFIABDialogFillResponse() {
try {
if(http.readyState==4) {
var d=document.getElementById('SFIABDialogInner');
var objhtml=http.responseText;
d.innerHTML=objhtml;
}
}
catch (e) {
}
}
</script>
<?
require_once("../dialog.inc.php");
//first, insert any defaults
$q=mysql_query("SELECT * FROM fundraising WHERE year='".$config['FAIRYEAR']."'");
@ -186,7 +81,6 @@ function SFIABDialogFillResponse() {
}
}
//this table is eventually going to be massive, and probably not in a tableview format, it'll show goals as well as all ongoing fund pledges, probabilities, etc as well as over/under, etc, all prettily colour coded.. basically a good overview of the total fundraising status of the fair.
$q=mysql_query("SELECT * FROM fundraising WHERE year='{$config['FAIRYEAR']}' ORDER BY system,type");
echo "<table class=\"fundraisingtable\">";
@ -198,7 +92,8 @@ function SFIABDialogFillResponse() {
*/
while($r=mysql_fetch_object($q)) {
echo "<tr>";
echo "<th colspan=\"6\">".i18n($r->name)."</th>\n";
echo "<th width=\"30\"><a onclick=\"return SFIABDialog(event,'fundraising_types.php?id=$r->id',300,200)\" href=\"#\">edit</a></th>\n";
echo "<th colspan=\"5\">".i18n($r->name)."</th>\n";
echo "<th style=\"text-align: right\">".format_money($r->goal)."</th>\n";
echo "</tr>\n";
@ -213,7 +108,8 @@ function SFIABDialogFillResponse() {
WHERE (sponsorships.fundraising_type='$r->type' $orsql)
AND sponsorships.year='{$config['FAIRYEAR']}'");
while($sr=mysql_fetch_object($sq)) {
echo "<tr id=\"sponsorships_$sr->id\" class=\"fundraising{$sr->status}\"><td width=\"30\"><a onclick=\"return SFIABDialog(event,'sponsorship.php?id=$sr->id&fundraising_type=$r->type',300,200)\" href=\"#\">edit</a></td><td>$sr->organization</td>\n";
echo "<tr id=\"sponsorships_$sr->id\" class=\"fundraising{$sr->status}\">";
echo "<td width=\"30\"><a onclick=\"return SFIABDialog(event,'fundraising_sponsorship.php?id=$sr->id&fundraising_type=$r->type',400,200)\" href=\"#\">edit</a></td><td>$sr->organization</td>\n";
echo "<td>$sr->status</td>";
echo "<td>";
if($sr->status=="pending")
@ -232,7 +128,7 @@ function SFIABDialogFillResponse() {
$typetotal+=$probval;
}
echo "<tr>";
echo "<td><a onclick=\"return SFIABDialog(event,'sponsorship.php?fundraising_type=$r->type',300,200)\" href=\"#\">add</a></td>";
echo "<td><a onclick=\"return SFIABDialog(event,'fundraising_sponsorship.php?fundraising_type=$r->type',400,200)\" href=\"#\">add</a></td>";
echo "<td colspan=\"4\" style=\"text-align: right; font-weight: bold;\">".i18n("%1 Total",array($r->name),array("Fundraising type total, eg) Award Sponsorship Total"))."</td>\n";
echo "<td style=\"font-weight: bold; text-align: right;\">".format_money($typetotal)."</td>\n";
$typediff=$typetotal-$r->goal;
@ -243,9 +139,10 @@ function SFIABDialogFillResponse() {
$totaldiff+=$typediff;
echo "<tr><td colspan=\"7\">&nbsp;</td></tr>\n";
}
echo "<tr><td colspan=\"6\" style=\"font-weight: bold; text-align: right;\">".i18n("Total Net Position")."</td><td style=\"text-align: right; font-weight: bold;\">".format_money($totaldiff)."</td></tr>\n";
echo "<tr>";
echo "<td colspan=\"2\"><a onclick=\"return SFIABDialog(event,'fundraising_types.php',300,200)\" href=\"#\">add fund type</a></td>";
echo "<td colspan=\"4\" style=\"font-weight: bold; text-align: right;\">".i18n("Total Net Position")."</td><td style=\"text-align: right; font-weight: bold;\">".format_money($totaldiff)."</td></tr>\n";
echo "</table>\n";
echo "<a href=\"fundraising_types.php\">".i18n("Edit fund types and goals")."</a>\n";
send_footer();
?>

View File

@ -40,11 +40,10 @@
$fundraising_type=$_GET['fundraising_type'];
}
echo "<form method=\"post\" action=\"fundraising.php\">";
echo "<input type=\"hidden\" name=\"action\" value=\"$formaction\">";
echo "<input type=\"hidden\" name=\"sponsorships_id\" value=\"$id\">";
echo "<table cellspacing=0 cellpadding=0>";
echo "<tr><td>".i18n("Sponsor")."</td>";
echo "<table cellspacing=0 cellpadding=0 class=\"SFIABDialogTable\">";
echo "<tr><th>".i18n("Sponsor")."</th>";
echo "<td>";
$q=mysql_query("SELECT * FROM sponsors ORDER BY organization");
@ -58,7 +57,7 @@
echo "</select>\n";
echo "</td></tr>\n";
echo "<tr><td>".i18n("Type")."</td>";
echo "<tr><th>".i18n("Type")."</th>";
echo "<td>";
$q=mysql_query("SELECT * FROM fundraising WHERE year='{$config['FAIRYEAR']}' ORDER BY name");
echo mysql_error();
@ -70,9 +69,9 @@
}
echo "</select>\n";
echo "</td></tr>\n";
echo "<tr><td>".i18n("Amount")."</td><td><input type=\"text\" name=\"value\" value=\"$sponsorship->value\"></td></tr>\n";
echo "<tr><th>".i18n("Amount")."</th><td><input type=\"text\" name=\"value\" value=\"$sponsorship->value\"></td></tr>\n";
echo "<tr><td>".i18n("Status")."</td>";
echo "<tr><th>".i18n("Status")."</th>";
echo "<td>";
echo "<select name=\"status\">";
echo "<option value=\"\">".i18n("Choose")."</option>\n";
@ -84,7 +83,7 @@
echo "</select>\n";
echo "</td></tr>\n";
echo "<tr><td>".i18n("Probability")."</td>";
echo "<tr><th>".i18n("Probability")."</th>";
echo "<td>";
echo "<select name=\"probability\">";
echo "<option value=\"\">".i18n("Choose")."</option>\n";
@ -96,12 +95,6 @@
echo "</select>\n";
echo "</td></tr>\n";
echo "<tr><td colspan=\"2\" style=\"text-align: center;\">";
echo "<input onclick=\"return SFIABDialogSubmit()\" type=\"submit\" value=\"".i18n("Save")."\">\n";
echo "<input onclick=\"return SFIABDialogCancel()\" type=\"button\" value=\"".i18n("Cancel")."\">\n";
echo "</td></tr>\n";
echo "</table>\n";
echo "</form>\n";
?>

View File

@ -21,42 +21,38 @@
*/
?>
<?
require("../common.inc.php");
require("../tableeditor.class.php");
require_once("../user.inc.php");
require("../common.inc.php");
require_once("../user.inc.php");
//first, insert any defaults
$q=mysql_query("SELECT * FROM fundraising WHERE year='".$config['FAIRYEAR']."'");
if(!mysql_num_rows($q)) {
$q=mysql_query("SELECT * FROM fundraising WHERE year='-1'");
while($r=mysql_fetch_object($q)) {
mysql_query("INSERT INTO fundraising (`type`,`name`,`system`,`goal`,`year`) VALUES ('$r->type','".mysql_real_escape_string($r->name)."','$r->system','$r->goal','".$config['FAIRYEAR']."')");
}
}
user_auth_required('committee', 'admin');
//make sure storage folder exists
user_auth_required('committee', 'admin');
send_header("Types of Fundraising",
array('Committee Main' => 'committee_main.php',
'Administration' => 'admin/index.php',
'Fundraising' => 'admin/fundraising.php'),
"fundraising"
);
if($_GET['id']) {
$id=intval($_GET['id']);
$q=mysql_query("SELECT * FROM fundraising WHERE id='$id'");
echo "<h2>Edit Fund</h2>";
$fund=mysql_fetch_object($q);
$formaction="fundedit";
}
else {
echo "<h2>Create New Fund</h2>";
$formaction="fundadd";
}
$editor=new TableEditor("fundraising",
array("name"=>"Name",
"goal"=>"Goal",
),
array("name"=>"Name",
"goal"=>"Goal",
)
);
echo "<input type=\"hidden\" name=\"action\" value=\"$formaction\">";
echo "<input type=\"hidden\" name=\"fundraising_id\" value=\"$id\">";
$editor->filterList("year='".$config['FAIRYEAR']."'");
$editor->setPrimaryKey("id");
$editor->setDefaultSortField("system,name");
$editor->setRecordType("Fund Type");
$editor->execute();
echo "<table class=\"SFIABDialogTable\">";
if($fund->system=="yes") {
echo "<tr><th>".i18n("Type")."</th><td>".i18n("System (non-editable)")."</td></tr>\n";
echo "<tr><th>".i18n("Name")."</th><td>".htmlspecialchars($fund->name)."</td></tr>\n";
echo "<tr><th>".i18n("Key")."</th><td>".htmlspecialchars($fund->type)."</td></tr>\n";
}
else {
echo "<tr><th>".i18n("Type")."</th><td>".i18n("Custom (editable)")."</td></tr>\n";
echo "<tr><th>".i18n("Name")."</th><td><input type=\"text\" name=\"name\" value=\"".htmlspecialchars($fund->name)."\"></td></tr>\n";
echo "<tr><th>".i18n("Key")."</th><td><input type=\"text\" name=\"type\" value=\"".htmlspecialchars($fund->type)."\"></td></tr>\n";
}
echo "<tr><th>".i18n("Goal")."</th><td><input type=\"text\" size=\"8\" name=\"goal\" value=\"$fund->goal\"></td></tr>\n";
echo "</table>\n";
send_footer();
?>

133
dialog.inc.php Normal file
View File

@ -0,0 +1,133 @@
<? require_once("ajax.inc.php"); ?>
<div class="SFIABDialog" id="SFIABDialog" style="position: absolute; visibility: hidden;">
<div class="SFIABDialogInner" id="SFIABDialogInner"></div>
</div>
<div id="FadeScreenDiv" style="visibility: hidden; top: 0px; left: 0px;"></div>
<script type="text/javascript">
var SFIABDialogGrowWidth=0;
var SFIABDialogGrowHeight=0;
var SFIABDialogFinalWidth=100;
var SFIABDialogFinalHeight=100;
var SFIABDialogGrowWidthStep=0;
var SFIABDialogGrowHeightStep=0;
var SFIABDialogGrowTime=0; //0 means no animation, i dont know why i coded the animation thing to begin with, who knows, maybe we'll want it somewhere at some point
var SFIABDialogGrowSteps=5;
var SFIABDialogInnerPre='<form id="SFIABDialogForm" method="post" action="<?=$_SERVER['PHP_SELF']?>">';
var SFIABDialogInnerPost='<table width="100%"><tr><td style="width: 50%; text-align: center;"><input onclick="return SFIABDialogSubmit()" type="submit" value="<?=i18n("Save")?>"></td><td style="text-align: center;"><input onclick="return SFIABDialogCancel()" type="button" value="<?=i18n("Cancel")?>"></td></tr></table></form>';
function SFIABDialog(e, url, width, height) {
var posx = 0;
var posy = 0;
//get this going while we do the other stuff
SFIABDialogFill(url);
if(!e) var e = window.event;
if (e.pageX || e.pageY) {
posx = e.pageX;
posy = e.pageY;
}
else if (e.clientX || e.clientY) {
posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
}
var d=document.getElementById('SFIABDialog');
var di=document.getElementById('SFIABDialogInner');
var fs=document.getElementById('FadeScreenDiv');
fs.style.visibility="visible";
d.style.top=posy+'px';
d.style.left=posx+'px';
di.style.visibility='hidden';
if(SFIABDialogGrowTime==0) {
d.style.visibility='visible';
d.style.width=width+"px";
d.style.height=height+"px";
}
else
{
//expand it in over time...
SFIABDialogGrowWidth=1;
SFIABDialogGrowHeight=1;
//set the final width&&height
SFIABDialogFinalWidth=width;
SFIABDialogFinalHeight=height;
//set the steps
SFIABDialogGrowWidthStep=Math.round(width/SFIABDialogGrowSteps);
SFIABDialogGrowHeightStep=Math.round(height/SFIABDialogGrowSteps);
//set the size to start us off, and go visible
d.style.width=SFIABDialogGrowWidth+"px";
d.style.height=SFIABDialogGrowHeight+"px";
d.style.visibility='visible';
//startup the timer
setTimeout('growDialog()',Math.round(SFIABDialogGrowTime/SFIABDialogGrowSteps));
}
return false;
}
function growDialog() {
SFIABDialogGrowWidth+=SFIABDialogGrowWidthStep;
SFIABDialogGrowHeight+=SFIABDialogGrowHeightStep;
if(SFIABDialogGrowWidth>SFIABDialogFinalWidth)
SFIABDialogGrowWidth=SFIABDialogFinalWidth;
if(SFIABDialogGrowHeight>SFIABDialogFinalHeight)
SFIABDialogGrowHeight=SFIABDialogFinalHeight;
var d=document.getElementById('SFIABDialog');
d.style.width=SFIABDialogGrowWidth+"px";
d.style.height=SFIABDialogGrowHeight+"px";
if(SFIABDialogGrowWidth<SFIABDialogFinalWidth || SFIABDialogGrowHeight<SFIABDialogFinalHeight)
{
setTimeout('growDialog()',Math.round(SFIABDialogGrowTime/SFIABDialogGrowSteps));
}
else {
var di=document.getElementById('SFIABDialogInner');
di.style.visibility="visible";
}
}
function SFIABDialogFill(url) {
var d=document.getElementById('SFIABDialogInner');
d.innerHTML="";
d.style.visibility='hidden';
http.open("GET",url,true);
http.onreadystatechange=SFIABDialogFillResponse;
http.send(null);
}
function SFIABDialogFillResponse() {
try {
if(http.readyState==4) {
var di=document.getElementById('SFIABDialogInner');
var objhtml=http.responseText;
di.innerHTML=SFIABDialogInnerPre+objhtml+SFIABDialogInnerPost;
di.style.visibility='visible';
}
}
catch (e) {
}
}
function SFIABDialogSubmit() {
//we let it submit the form, which reloads the page
return true;
}
function SFIABDialogCancel() {
var d=document.getElementById('SFIABDialog');
var di=document.getElementById('SFIABDialogInner');
var fs=document.getElementById('FadeScreenDiv');
fs.style.visibility="hidden";
d.style.visibility="hidden";
di.style.visibility="hidden";
return false;
}
</script>

View File

@ -5,6 +5,7 @@ body
margin: 0;
padding: 0;
background: #E0E0FF;
height:100%;
}
input
@ -352,9 +353,8 @@ tr.externalaward {
}
.fundraisingtable th a{
font-size: 1.1em;
color: white;
font-weight: bold;
font-weight: normal;
}
.fundraisingtable td {
@ -384,16 +384,42 @@ tr.externalaward {
filter:alpha(opacity=50);
-moz-opacity:.50;
opacity:.50;
position: fixed;
display: block;
visibility: hidden;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
z-index: 100;
background-color: black;
position: fixed;
_background: none;
margin: 0px 0px 0px 0px;
clear: none;
}
* html #FadeScreenDiv {
position: absolute;
height: expression(document.body.scrollHeight &gt; document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
.SFIABDialogTable {
border-spacing: 1px;
color: black;
margin-left: 20px;
margin-right: 20px;
font-size: 0.9em;
border: 0px;
border-collapse: collapse;
}
.SFIABDialogTable td {
border: 0px solid #5C6F90;
padding: 1px;
}
.SFIABDialogTable th {
border: 1px solid #5C6F90;
font-weight: bold;
text-align: left;
color: #FFFFFF;
background-color: #5C6F90;
padding: 2px;
}