versiontooltip.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /**
  2. * Get the tooltip message to be displayed
  3. */
  4. function getContent() {
  5. var diff = getVersionDiff();
  6. var link = getLatestLink();
  7. var msg = "";
  8. // See file airtime_mvc/application/views/helpers/VersionNotify.php for more info
  9. if(isUpToDate()) {
  10. msg = $.i18n._("You are running the latest version");
  11. } else if (diff < 20) {
  12. msg = $.i18n._("New version available: ") + link;
  13. } else if (diff < 30) {
  14. msg = $.i18n._("This version will soon be obsolete.")+"<br/>"+$.i18n._("Please upgrade to ") + link;
  15. } else {
  16. msg = $.i18n._("This version is no longer supported.")+"<br/>"+$.i18n._("Please upgrade to ") + link;
  17. }
  18. return msg;
  19. }
  20. /**
  21. * Get major version difference b/w current and latest version, in int
  22. */
  23. function getVersionDiff() {
  24. return parseInt($("#version-diff").html());
  25. }
  26. /**
  27. * Get the current version
  28. */
  29. function getCurrentVersion() {
  30. return $("#version-current").html();
  31. }
  32. /**
  33. * Get the latest version
  34. */
  35. function getLatestVersion() {
  36. return $("#version-latest").html();
  37. }
  38. /**
  39. * Returns the download link to latest release in HTML
  40. */
  41. function getLatestLink() {
  42. return "<a href='' onclick='openLatestLink();'>" + getLatestVersion() + "</a>";
  43. }
  44. /**
  45. * Returns true if current version is up to date
  46. */
  47. function isUpToDate() {
  48. var diff = getVersionDiff();
  49. var current = getCurrentVersion();
  50. var latest = getLatestVersion();
  51. var temp = (diff == 0 && current == latest) || diff < 0;
  52. return (diff == 0 && current == latest) || diff < 0;
  53. }
  54. /**
  55. * Opens the link in a new window
  56. */
  57. function openLatestLink() {
  58. window.open($("#version-link").html());
  59. }
  60. /**
  61. * Sets up the tooltip for version notification
  62. */
  63. function setupVersionQtip(){
  64. var qtipElem = $('#version-icon');
  65. if (qtipElem.length > 0){
  66. qtipElem.qtip({
  67. id: 'version',
  68. content: {
  69. text: getContent(),
  70. title: {
  71. text: getCurrentVersion(),
  72. button: isUpToDate() ? false : true
  73. }
  74. },
  75. hide: {
  76. event: isUpToDate() ? 'mouseleave' : 'unfocus'
  77. },
  78. position: {
  79. my: "top right",
  80. at: "bottom left"
  81. },
  82. style: {
  83. border: {
  84. width: 0,
  85. radius: 4
  86. },
  87. classes: "ui-tooltip-dark ui-tooltip-rounded"
  88. }
  89. });
  90. }
  91. }
  92. $(document).ready(function() {
  93. if($('#version-icon').length > 0) {
  94. setupVersionQtip();
  95. }
  96. });