1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-06-29 04:55:02 +03:00
This commit is contained in:
Mzhelskiy Maxim 2011-05-03 15:39:24 +00:00
parent d9bb325652
commit 258ec68178
3 changed files with 48 additions and 28 deletions

View file

@ -43,7 +43,7 @@
{foreach from=$_aRequest.answer item=sAnswer key=i}
<li>
<input type="text" value="{$sAnswer}" name="answer[]" class="input input-300" {if $bEditDisabled}disabled{/if} />
{if !$bEditDisabled}&nbsp;<a href="#" onClick="dropField(this); return false;">{$aLang.topic_poll_delete_item}</a>{/if}
{if !$bEditDisabled and $i>1} <a href="#" onClick="return ls.poll.removeAnswer(this);">{$aLang.topic_poll_delete_item}</a>{/if}
</li>
{/foreach}
{else}
@ -51,7 +51,7 @@
<li><input type="text" value="" name="answer[]" class="input input-300" {if $bEditDisabled}disabled{/if} /></li>
{/if}
</ul>
{if !$bEditDisabled}<p><a href="#" onClick="addField(); return false;">{$aLang.topic_poll_add_item}</a></p>{/if}
{if !$bEditDisabled}<p><a href="#" onClick="ls.poll.addAnswer(); return false;">{$aLang.topic_poll_add_item}</a></p>{/if}
<p><label for="topic_text">{$aLang.topic_question_create_text}:</label><br />
<textarea name="topic_text" id="topic_text" rows="20" class="input-wide">{$_aRequest.topic_text}</textarea></p>

View file

@ -1,27 +1,47 @@
function ajaxPollVote(idTopic, idAnswer) {
$.post(aRouter['ajax']+'vote/question/', { idTopic: idTopic, idAnswer: idAnswer, security_ls_key: LIVESTREET_SECURITY_KEY }, function(result) {
if (result.bStateError) {
$.notifier.error(null, result.sMsg);
} else {
$.notifier.notice(null, result.sMsg);
$('#topic_question_area_'+idTopic).html(result.sText);
}
});
}
var ls = ls || {};
// Добавляет вариант ответа
function addField() {
if($("#question_list li").length == 20) {
$.notifier.error(null, LANG_POLL_ERROR);
/**
* Опросы
*/
ls.poll = (function ($) {
/**
* Голосование в опросе
*/
this.vote = function(idTopic, idAnswer) {
ls.ajax(aRouter['ajax']+'vote/question/', {idTopic: idTopic, idAnswer: idAnswer}, function(result) {
if (result.bStateError) {
ls.msg.error(null, result.sMsg);
} else {
ls.msg.notice(null, result.sMsg);
$('#topic_question_area_'+idTopic).html(result.sText);
}
});
}
/**
* Добавляет вариант ответа
*/
this.addAnswer = function() {
if($("#question_list li").length == 20) {
ls.msg.error(null, LANG_POLL_ERROR);
return false;
}
var newItem = $("#question_list li:first-child").clone();
newItem.find('a').remove();
newItem.appendTo("#question_list").append($('<a href="#">'+LANG_DELETE+'</a>').click(function(ev){
return this.removeAnswer(ev.target);
}.bind(this)));
newItem.find('input').val('');
}
/**
* Удаляет вариант ответа
*/
this.removeAnswer = function(obj) {
$(obj).parent("li").remove();
return false;
}
var newItem = $("#question_list li:first-child").clone();
newItem.appendTo("#question_list").append($('<a href="#" style="margin-left: 5px;">'+LANG_DELETE+'</a>').bind("click", deleteField));
newItem.find('input').val('');
}
// Удаляет вариант ответа
function deleteField() {
$(this).parent("li").remove();
return false;
}
return this;
}).call(ls.poll || {},jQuery);

View file

@ -36,8 +36,8 @@
{/foreach}
</ul>
<input type="submit" value="{$aLang.topic_question_vote}" onclick="ajaxPollVote({$oTopic->getId()},$('#topic_answer_{$oTopic->getId()}_value').val());" />
<input type="submit" value="{$aLang.topic_question_abstain}" onclick="ajaxPollVote({$oTopic->getId()},-1)" />
<input type="submit" value="{$aLang.topic_question_vote}" onclick="ls.poll.vote({$oTopic->getId()},$('#topic_answer_{$oTopic->getId()}_value').val());" />
<input type="submit" value="{$aLang.topic_question_abstain}" onclick="ls.poll.vote({$oTopic->getId()},-1)" />
<input type="hidden" id="topic_answer_{$oTopic->getId()}_value" value="-1" />
{else}
{include file='topic_question.tpl'}