/upload/templates/default/viewtopic_poll.tpl

http://torrentpier2.googlecode.com/ · Smarty Template · 151 lines · 128 code · 23 blank · 0 comment · 6 complexity · d025acfbf404962b638ef6e0026f8472 MD5 · raw file

  1. <script type="text/javascript">
  2. var bb_poll = {};
  3. bb_poll.data = {POLL_VOTES_JS}; // [["?????????", "result"], ...]
  4. bb_poll.title = '';
  5. bb_poll.votes_data = {};
  6. bb_poll.votes_sum = 0;
  7. bb_poll.max_img_len = 205; // 100% = this length
  8. $(function(){
  9. $.each(bb_poll.data, function(vote_id, vote_data){
  10. var vote_text = vote_data[0];
  11. var vote_result = parseInt(vote_data[1]);
  12. if (vote_id == 0) {
  13. bb_poll.title = vote_text;
  14. }
  15. else {
  16. bb_poll.votes_sum += vote_result;
  17. bb_poll.votes_data[vote_id] = [vote_text, vote_result];
  18. }
  19. });
  20. $('#poll-title').html(bb_poll.title);
  21. $('#votes-sum-val').text(bb_poll.votes_sum);
  22. $.each(bb_poll.votes_data, function(vote_id, vote_data){
  23. var vote_caption = vote_data[0];
  24. var vote_result = parseInt(vote_data[1]);
  25. var vote_percent = (bb_poll.votes_sum) ? Math.round(vote_result / bb_poll.votes_sum * 100) : 0;
  26. var vote_img_width = Math.round(vote_percent * bb_poll.max_img_len / 100);
  27. $('#poll-results-tpl tbody')
  28. .clone()
  29. .find('span.poll-vote-caption').html(vote_caption).end()
  30. .find('img.poll-vote-img').css({ width: vote_img_width }).end()
  31. .find('span.poll-vote-percent').text(vote_percent+'%').end()
  32. .find('span.poll-vote-result').text(vote_result).end()
  33. .appendTo('#poll-results-block')
  34. ;
  35. });
  36. $('#poll').show();
  37. });
  38. function build_votes ()
  39. {
  40. $.each(bb_poll.votes_data, function(vote_id, vote_data){
  41. var vote_caption = vote_data[0];
  42. var vote_el_id = 'vote-'+ vote_id;
  43. $('#poll-results-block').hide();
  44. $('#poll-votes-tpl tbody')
  45. .clone()
  46. .find('input').val(vote_id).attr({id: vote_el_id}).end()
  47. .find('label').html(vote_caption).attr({'for': vote_el_id}).end()
  48. .appendTo('#poll-votes-block')
  49. ;
  50. });
  51. $('#votes-sum-block, #vote-btn-a, #poll-manage').hide();
  52. $('#vote-btn-input').show();
  53. }
  54. function submit_vote ()
  55. {
  56. var $voted_id = $('input.vote-inp:checked');
  57. if ($voted_id.length == 0) {
  58. alert('?? ?? ???????, ?? ??? ?????????');
  59. }
  60. else {
  61. $('#poll-mode').val('poll_vote');
  62. $voted_id.clone().appendTo('#poll-form');
  63. $('#vote-id').val( $voted_id.val() );
  64. $('#poll-submit-btn').click();
  65. }
  66. }
  67. function build_poll_edit_form ()
  68. {
  69. $('#poll').empty().append( $('#poll-edit-tpl').contents() )
  70. $('#poll-legend').html('???????? ?????');
  71. $('#poll-edit-submit-btn').click(function(){
  72. return poll_manage('poll_edit', '???????? ????? (?????? ?????????? ????? ???????)?');
  73. });
  74. $('#poll-caption-inp').val( html2text(bb_poll.title) );
  75. var votes_text = [];
  76. $.each(bb_poll.votes_data, function(vote_id, vote_data){
  77. votes_text.push( html2text(vote_data[0]) );
  78. });
  79. $('#poll-votes-inp').val( votes_text.join('\n') );
  80. return false;
  81. }
  82. function html2text (str)
  83. {
  84. return $('<span></span>').html(str).text();
  85. }
  86. </script>
  87. <table id="poll-votes-tpl" style="display: none;">
  88. <tbody>
  89. <tr>
  90. <td><input type="radio" name="vote_id" class="vote-inp" value="" /></td>
  91. <td><label class="wrap"></label></td>
  92. </tr>
  93. </tbody>
  94. </table>
  95. <table id="poll-results-tpl" style="display: none;">
  96. <tbody>
  97. <tr>
  98. <td class="tLeft"><span class="poll-vote-caption"></span></td>
  99. <td>&nbsp;</td>
  100. <td class="nowrap"><img src="{IMG}/vote_lcap.gif" width="4" height="12" alt="" /><img src="{IMG}/voting_bar.gif" class="poll-vote-img" width="1" height="12" alt="" /><img src="{IMG}/vote_rcap.gif" width="4" height="12" alt="" /></td>
  101. <td class="nowrap tRight bold">&nbsp;<span class="poll-vote-percent"></span>&nbsp;</td>
  102. <td class="nowrap tCenter">[ <span class="poll-vote-result"></span> ]</td>
  103. </tr>
  104. </tbody>
  105. </table>
  106. <div class="mrg_12 tCenter"><b id="poll-title"></b></div>
  107. <table id="poll-results-block" class="borderless bCenter"></table>
  108. <table id="poll-votes-block" class="borderless bCenter"></table>
  109. <!-- IF SHOW_VOTE_BTN -->
  110. <div id="vote-btn-a" class="mrg_8 tCenter">[ <a href="#" onclick="build_votes(); return false;" class="gen"><b>{L_SUBMIT_VOTE}</b></a> ]</div>
  111. <div id="vote-btn-input" class="mrg_6 tCenter" style="display: none;"><input type="button" onclick="submit_vote(); return false;" value="{L_SUBMIT_VOTE}" class="bold" /></div>
  112. <!-- ELSE -->
  113. <div class="mrg_8 tCenter">[ <b>????? ????????</b> ]</div>
  114. <!-- ENDIF -->
  115. <div id="votes-sum-block" class="mrg_8 tCenter">????? ?????????????: <span id="votes-sum-val"></span><b></b></div>
  116. <!-- IF CAN_MANAGE_POLL -->
  117. <div id="poll-manage" class="mrg_8 tCenter">
  118. [ <a href="#" onclick="return poll_manage('poll_delete', '{L_CONFIRM_DELETE_POLL}');" class="med">{L_DELETE_POLL}</a> ]&nbsp;&nbsp;
  119. <!-- IF POLL_IS_EDITABLE -->
  120. [ <a href="#" onclick="return build_poll_edit_form();" class="med">{L_EDIT}</a> ]&nbsp;&nbsp;
  121. <!-- IF POLL_IS_FINISHED -->
  122. [ <a href="#" onclick="return poll_manage('poll_start', '???????? ??????');" class="med">???????? ?????</a> ]&nbsp;&nbsp;
  123. <!-- ELSE -->
  124. [ <a href="#" onclick="return poll_manage('poll_finish', '????????? ??????');" class="med">????????? ?????</a> ]&nbsp;&nbsp;
  125. <!-- ENDIF -->
  126. <!-- ENDIF -->
  127. </div>
  128. <!-- ENDIF -->