Merge branch 'devel' of dev.sourcefabric.org:airtime into devel

This commit is contained in:
lukabazuka 2011-11-15 20:30:19 +01:00
commit 9c649259dd
2 changed files with 59 additions and 17 deletions

View File

@ -26,35 +26,31 @@ class Airtime_View_Helper_VersionNotify extends Zend_View_Helper_Abstract{
return "";
}
// Calculate version diff
// Calculate major version diff;
// Example: if current = 1.9.5 and latest = 3.0.0, major diff = 11
// Note: algorithm assumes the number after 1st dot never goes above 9
$diff = (intval($latestMatch[1]) * 10 + intval($latestMatch[2]))
- (intval($curMatch[1]) * 10 + intval($curMatch[2]));
// Pick icon and tooltip msg
// Pick icon
$bg = "/css/images/";
$msg = "";
$link = "<a href='http://apt.sourcefabric.org/misc/'>" . $latest . "</a>";
if(($diff == 0 && $current == $latest) || $diff < 0) {
// current version is up to date
$bg .= "icon_uptodate.png";
$msg = "You are running the latest version";
} else if($diff <= 2) {
// 2 or less major versions back
$bg .= "icon_update.png";
$msg = "New version available: " . $link;
} else if($diff == 3) {
// 3 major versions back
$bg .= "icon_update2.png";
$msg = "This version will soon be obsolete.<br/>Please upgrade to " . $link;
} else {
// more than 3 major versions back
$bg .= "icon_outdated.png";
$msg = "This version is no longer supported.<br/>Please upgrade to " . $link;
}
$result = "<div id='version_message' style='display:none'>" . $msg . "</div>"
$result = "<div id='version_diff' style='display:none'>" . $diff . "</div>"
. "<div id='version_current' style='display:none'>" . $current . "</div>"
. "<div id='version_latest' style='display:none'>" . $latest . "</div>"
. "<div id='version_icon' style='background-image: url(" . $bg . ");'></div>";
return $result;
}

View File

@ -1,19 +1,63 @@
/**
* Get the tooltip message to be displayed,
* which is stored inside a pair of hidden div tags
* Get the tooltip message to be displayed
*/
function getContent() {
return $("#version_message").html();
var diff = getVersionDiff();
var link = getLatestLink();
var msg = "";
if(isUpToDate()) {
msg = "You are running the latest version";
} else if(diff <= 2) {
msg = "New version available: " + link;
} else if(diff == 3) {
msg = "This version will soon be obsolete.<br/>Please upgrade to " + link;
} else {
msg = "This version is no longer supported.<br/>Please upgrade to " + link;
}
return msg;
}
/**
* Get the current version,
* which is stored inside a pair of hidden div tags
* Get major version difference b/w current and latest version, in int
*/
function getVersionDiff() {
return parseInt($("#version_diff").html());
}
/**
* Get the current version
*/
function getCurrentVersion() {
return $("#version_current").html();
}
/**
* Get the latest version
*/
function getLatestVersion() {
return $("#version_latest").html();
}
/**
* Returns true if current version is up to date
*/
function isUpToDate() {
var diff = getVersionDiff();
var current = getCurrentVersion();
var latest = getLatestVersion();
var temp = (diff == 0 && current == latest) || diff < 0;
return (diff == 0 && current == latest) || diff < 0;
}
/**
* Returns the download link to latest release in HTML
*/
function getLatestLink() {
return "<a href='http://apt.sourcefabric.org/misc/'>" + getLatestVersion() + "</a>";
}
/**
* Sets up the tooltip for version notification
*/
@ -26,10 +70,12 @@ function setupVersionQtip(){
text: getContent(),
title: {
text: getCurrentVersion(),
button: true
button: isUpToDate() ? false : true
}
},
hide: false, /* Don't hide on mouseout */
hide: {
event: isUpToDate() ? 'mouseleave' : 'unfocus'
},
position: {
my: "top right",
at: "bottom left"
@ -46,7 +92,7 @@ function setupVersionQtip(){
}
$(document).ready(function() {
if($('#version_message').length > 0) {
if($('#version_icon').length > 0) {
setupVersionQtip();
}
});