PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/site_media/static/js/global.js

https://bitbucket.org/LifeEquity/leap-v2.0
JavaScript | 142 lines | 111 code | 28 blank | 3 comment | 13 complexity | 41c6349071da85387b065d543d87357e MD5 | raw file
  1. $(document).ready(function() {
  2. $(".policy_detail_overlay").click(function(){
  3. return show_overlay("/leap/policy_detail/table/", $(this).attr('rel'), 'Policy Details');
  4. });
  5. $(".insured_detail_overlay").click(function(){
  6. return show_overlay("/leap/insured_detail/table/", $(this).attr('rel'), 'Insured Details');
  7. });
  8. $("tr.life_expectancy_overlay").dblclick(function(){
  9. return show_overlay("/leap/life_expectancy_table/", $(this).attr('rel'), 'Life Expectancy Details');
  10. });
  11. $("tr.grace_event_overlay").dblclick(function(){
  12. return show_overlay("/leap/grace_event_table/", $(this).attr('rel'), 'Grace Event Details');
  13. });
  14. $("tr.maturity_claim_overlay").dblclick(function(){
  15. return show_overlay("/leap/maturity_claim_table/", $(this).attr('rel'), 'Maturity Claim Details');
  16. });
  17. $("tr.premium_overlay").dblclick(function(){
  18. return show_overlay("/leap/premium_table/", $(this).attr('rel'), 'Premium Details');
  19. });
  20. $("tr.insured_events_overlay").dblclick(function(){
  21. return show_overlay("/leap/insured_events_table/", $(this).attr('rel'), 'Insured Event Details');
  22. });
  23. $(".policy_event_overlay").dblclick(function(){
  24. return show_overlay("/leap/policy_event_table/", $(this).attr('rel'), 'Policy Event Details');
  25. });
  26. $("tr.insurance_company_overlay").dblclick(function(){
  27. return show_overlay("/leap/insurance_company_table/", $(this).attr('rel'), 'Insurance Company Details');
  28. });
  29. $('.panel .collapse').click(function(){
  30. if ($(this).closest('.panel').hasClass('collapsed')){
  31. var restoreHeight = $(this).attr('id');
  32. $(this).closest('.panel').animate({height:restoreHeight+'px'}, function() {
  33. $(this).removeClass('collapsed');
  34. });
  35. }else{
  36. var currentHeight = $(this).closest('.panel').height();
  37. $(this).attr('id', currentHeight);
  38. $(this).closest('.panel').addClass('collapsed').animate({height:'45px'}, function(){ });
  39. }
  40. });
  41. function pieHover(event, pos, obj){
  42. if (!obj) return;
  43. percent = parseFloat(obj.series.percent).toFixed(2);
  44. $("#hover").html('<span style="font-weight: bold; color: '+obj.series.color+'">'+obj.series.label+' ('+percent+'%)</span>');
  45. }
  46. function pieClick(event, pos, obj){
  47. if (!obj) return;
  48. percent = parseFloat(obj.series.percent).toFixed(2);
  49. alert(''+obj.series.label+': '+percent+'%');
  50. }
  51. function log(message){
  52. //console.log(message);
  53. }
  54. function init_sideNavigation(){
  55. $("#navigation > li > a").click(function(){
  56. var parent = $(this).closest('li');
  57. if ($('ul',parent).size()){
  58. if ($(parent).hasClass('active')){
  59. $('ul',parent).slideUp('fast',function(){
  60. $(parent).removeClass('active');
  61. });
  62. }else{
  63. $('ul',parent).slideDown('fast');
  64. $(parent).addClass('active');
  65. }
  66. return false;
  67. }
  68. });
  69. }
  70. init_sideNavigation();
  71. jQuery.fn.dataTableExt.oSort['currency-asc'] = function(a,b) {
  72. /* Remove any formatting */
  73. var x = a == "-" ? 0 : a.replace( /[^\d\-\.]/g, "" );
  74. var y = b == "-" ? 0 : b.replace( /[^\d\-\.]/g, "" );
  75. /* Parse and return */
  76. x = parseFloat( x );
  77. y = parseFloat( y );
  78. return x - y;
  79. };
  80. jQuery.fn.dataTableExt.oSort['currency-desc'] = function(a,b) {
  81. var x = a == "-" ? 0 : a.replace( /[^\d\-\.]/g, "" );
  82. var y = b == "-" ? 0 : b.replace( /[^\d\-\.]/g, "" );
  83. x = parseFloat( x );
  84. y = parseFloat( y );
  85. return y - x;
  86. };
  87. });
  88. function formatCurrency(num) {
  89. num = num.toString().replace(/\$|\,/g, '');
  90. if (isNaN(num)) num = "0";
  91. sign = (num == (num = Math.abs(num)));
  92. num = Math.floor(num * 100 + 0.50000000001);
  93. cents = num % 100;
  94. num = Math.floor(num / 100).toString();
  95. if (cents < 10) cents = "0" + cents;
  96. for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
  97. num = num.substring(0, num.length - (4 * i + 3)) + ',' + num.substring(num.length - (4 * i + 3));
  98. return (((sign) ? '' : '-') + '$' + num + '.' + cents);
  99. }
  100. function show_overlay(url, id, title){
  101. var NewDialog = $('<div></div>');
  102. NewDialog.load(url + id + "/", function() {
  103. var container = $(this);
  104. NewDialog.dialog({
  105. height: 500,
  106. title: title,
  107. width: 400
  108. });
  109. container.dialog({
  110. modal: true
  111. })
  112. });
  113. return false;
  114. }