Skip to content

Commit

Permalink
Added in a slick looking timezone selector for locatization options. #83
Browse files Browse the repository at this point in the history
  • Loading branch information
wilpig committed Nov 18, 2012
1 parent b2fdc11 commit c2146b8
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
86 changes: 86 additions & 0 deletions configuration.php
Expand Up @@ -51,6 +51,49 @@
}
$imageselect.="</div>";

function formatOffset($offset) {
$hours = $offset / 3600;
$remainder = $offset % 3600;
$sign = $hours > 0 ? '+' : '-';
$hour = (int) abs($hours);
$minutes = (int) abs($remainder / 60);

if ($hour == 0 AND $minutes == 0) {
$sign = ' ';
}
return 'GMT' . $sign . str_pad($hour, 2, '0', STR_PAD_LEFT)
.':'. str_pad($minutes,2, '0');

}

static $regions = array(
'Africa' => DateTimeZone::AFRICA,
'America' => DateTimeZone::AMERICA,
'Antarctica' => DateTimeZone::ANTARCTICA,
'Asia' => DateTimeZone::ASIA,
'Atlantic' => DateTimeZone::ATLANTIC,
'Europe' => DateTimeZone::EUROPE,
'Indian' => DateTimeZone::INDIAN,
'Pacific' => DateTimeZone::PACIFIC
);

foreach($regions as $name => $mask){
$tzlist[$name]=DateTimeZone::listIdentifiers($mask);
}

$tzmenu='<ul id="tzmenu">';
foreach($tzlist as $country => $cityarray){
$tzmenu.="\t<li>$country\n\t\t<ul>";
foreach($cityarray as $key => $city){
$z=new DateTimeZone($city);
$c=new DateTime(null, $z);
$adjustedtime=$c->format('H:i a');
$offset=formatOffset($z->getOffset($c));
$tzmenu.="\t\t\t<li><a href=\"#\" data=\"$city\">$adjustedtime - $offset $city</a></li>\n";
}
$tzmenu.="\t\t</ul>\t</li>";
}
$tzmenu.='</ul>';

?>
<html>
Expand Down Expand Up @@ -134,6 +177,40 @@
}
});
});
$("#tzmenu").menu();
$("#tzmenu ul > li").click(function(e){
e.preventDefault();
$("#timezone").val($(this).children('a').attr('data'));
$("#tzmenu").toggle();
});
$("#tzmenu").focusout(function(){
$("#tzmenu").toggle();
});
$('<button type="button">').attr({
id: 'btn_tzmenu'
}).appendTo("body");
$('#btn_tzmenu').each(function(){
var input=$("#timezone");
var offset=input.offset();
var height=input.innerHeight();
$(this).css({
'height': height+'px',
'width': height+'px',
'position': 'absolute',
'left': offset.left+input.innerWidth()-height+'px',
'top': offset.top+'px'
}).click(function(){
$("#tzmenu").toggle();
$("#tzmenu").focus().click();
});
offset=$(this).offset();
$("#tzmenu").css({
'position': 'absolute',
'left': offset.left+'px',
'top': offset.top+height+'px'
});
$(this).addClass('text-arrow');
});
});

</script>
Expand Down Expand Up @@ -174,6 +251,13 @@
<div><input type="text" defaultvalue="',$config->defaults["DefaultPanelVoltage"],'" name="DefaultPanelVoltage" value="',$config->ParameterArray["DefaultPanelVoltage"],'"></div>
</div>
</div> <!-- end table -->
<h3>',_("Time and Measurements"),'</h3>
<div class="table" id="timeandmeasurements">
<div>
<div><lable for="timezone">',_("Time Zone"),'</label></div>
<div><input type="text" id="timezone" defaultvalue="',$config->defaults["timezone"],'" name="timezone" value="',$config->ParameterArray["timezone"],'"></div>
</div>
</div> <!-- end table -->
<h3>',_("Users"),'</h3>
<div class="table">
<div>
Expand Down Expand Up @@ -384,5 +468,7 @@
<a href="index.php">Return to Main Menu</a>
</div>
</div>

<?php echo $tzmenu; ?>
</body>
</html>
3 changes: 3 additions & 0 deletions css/inventory.php
Expand Up @@ -64,6 +64,9 @@
#imageselection #preview { position: absolute; top: 0; right: 0; height: 200px; width: 200px; margin: 0.1em 0 0 0; padding: 0; border: 0px solid black;}
#imageselection #filelist { position: absolute; top: 0; left: 1em; height: 210px; width: 175px; overflow-y: scroll; overflow-x: hidden; }

.ui-menu-item ul { max-height: 200px; overflow: auto; }
#tzmenu {display: none;}

/* index */
.index .table, .index .table .title {background-color: white;}
.index .table .title {font-weight: bold; font-size: 1.25em;}
Expand Down
7 changes: 7 additions & 0 deletions db-1.5-to-2.0.sql
Expand Up @@ -116,3 +116,10 @@ UPDATE fac_PowerDistribution SET TemplateID=(select TemplateID from fac_CDUTempl
ALTER TABLE fac_PowerDistribution DROP COLUMN ManagementType;
ALTER TABLE fac_PowerDistribution DROP COLUMN Model;
ALTER TABLE fac_PowerDistribution DROP COLUMN NumOutputs;

--
-- Add a new configurable timezone parameter
--

INSERT INTO `fac_Config` (`Parameter`, `Value`, `UnitOfMeasure`, `ValType`, `DefaultVal`) VALUES
('timezone', 'America/Chicago', 'string', 'string', 'America/Chicago');

0 comments on commit c2146b8

Please sign in to comment.