commissions.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. function showSliders(maxPercentage, type, defaultValues) {
  7. defaultValues = defaultValues || "0";
  8. var sliderCounter = 1;
  9. var percentage = 0;
  10. var minPercentage = 0;
  11. $("#selectBox option:selected").each(function() {
  12. var count = $("#selectBox option:selected").length;
  13. percentage = maxPercentage / count;
  14. percentage = parseInt(percentage);
  15. verifyMaxPercentage = percentage * count;
  16. if (verifyMaxPercentage !== maxPercentage && sliderCounter === 1) {
  17. percentage = percentage + (maxPercentage - verifyMaxPercentage);
  18. }
  19. beneficiaryId = $(this).val();
  20. beneficiaryName = $(this).text();
  21. var verify;
  22. var slidersValue = defaultValues.toString().split(',');
  23. if (type === 'default') {
  24. percentage = slidersValue[sliderCounter - 1];
  25. percentage = parseInt(percentage);
  26. $("#panelSliders").append("<span id=" + beneficiaryId + ">" + beneficiaryName + "</span> - [ <span class='value' >" + percentage + "</span> % ] <div class='panelSliders'></div>");
  27. } else if (type === 'renew') {
  28. $("#panelSliders").append("<span id=" + beneficiaryId + " >" + beneficiaryName + "</span> - [ <span class='value' >" + percentage + "</span> % ] <div class='panelSliders'></div>");
  29. }
  30. verifyPaypalAccountByBeneficiary(beneficiaryId);
  31. sliderCounter++;
  32. stepSlide = count - 1;
  33. if (stepSlide === 0) {
  34. (type === 'default') ? minPercentage = 0 : minPercentage = 100;
  35. (type === 'default') ? stepSlide = 100 : stepSlide = 1;
  36. }
  37. $( "#panelSliders .panelSliders" ).slider({
  38. value: percentage,
  39. min: minPercentage,
  40. max: maxPercentage,
  41. step: stepSlide,
  42. animate: true,
  43. slide: function( event, ui ) {
  44. $(this).prev(".value").text(ui.value);
  45. var total = 0;
  46. var sliders = $( "#panelSliders .panelSliders" );
  47. sliders.not(this).each(function() {
  48. value = $(this).slider("option", "value");
  49. total += value;
  50. });
  51. total += ui.value;
  52. var delta = 100 - total;
  53. sliders.not(this).each(function() {
  54. var t = $(this);
  55. value = t.slider("option", "value");
  56. var newValue = value + (delta/stepSlide);
  57. if (newValue < 0 || ui.value == 100)
  58. newValue = 0;
  59. if (newValue > 100)
  60. newValue = 100;
  61. t.prev('.value').text(newValue);
  62. t.slider('value', newValue);
  63. });
  64. $("[name=\'commissions\']").val(getSlidersValues());
  65. }
  66. });
  67. });
  68. $("[name=\'commissions\']").val(getSlidersValues());
  69. showCorrectSliderHandler();
  70. };
  71. function getSlidersValues() {
  72. var commissions = "";
  73. $( "#panelSliders .panelSliders" ).each(function() {
  74. commissions += $(this).prev(".value").text() + ',';
  75. });
  76. commissions = commissions.substring(0, commissions.length-1);
  77. return commissions;
  78. }
  79. function showCorrectSliderHandler() {
  80. var correctHandler = [];
  81. $("#panelSliders > span").each(function () {
  82. if ($(this).hasClass('value')) {
  83. correctHandler.push($(this).text());
  84. }
  85. });
  86. var counter = 0;
  87. $("#panelSliders .panelSliders > span").each(function () {
  88. if ($(this).hasClass('ui-slider-handle')) {
  89. $(this).css('left', correctHandler[counter]+'%');
  90. counter++;
  91. }
  92. });
  93. }
  94. function verifyPaypalAccountByBeneficiary(userId) {
  95. return $.ajax({
  96. data: 'id='+userId,
  97. url: 'buycourses.ajax.php?a=verifyPaypal',
  98. type: 'POST',
  99. success: function(response) {
  100. $("#"+userId).append(' '+response);
  101. }
  102. });
  103. }