PageRenderTime 28ms CodeModel.GetById 20ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

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