From 258ec68178554c9cfe4e149c3c018e1d2e8573c6 Mon Sep 17 00:00:00 2001 From: Mzhelskiy Maxim Date: Tue, 3 May 2011 15:39:24 +0000 Subject: [PATCH] --- .../actions/ActionQuestion/add.tpl | 4 +- templates/skin/developer-jquery/js/poll.js | 68 ++++++++++++------- templates/skin/developer-jquery/topic.tpl | 4 +- 3 files changed, 48 insertions(+), 28 deletions(-) diff --git a/templates/skin/developer-jquery/actions/ActionQuestion/add.tpl b/templates/skin/developer-jquery/actions/ActionQuestion/add.tpl index 689bfd19..b0645349 100644 --- a/templates/skin/developer-jquery/actions/ActionQuestion/add.tpl +++ b/templates/skin/developer-jquery/actions/ActionQuestion/add.tpl @@ -43,7 +43,7 @@ {foreach from=$_aRequest.answer item=sAnswer key=i}
  • - {if !$bEditDisabled} {$aLang.topic_poll_delete_item}{/if} + {if !$bEditDisabled and $i>1} {$aLang.topic_poll_delete_item}{/if}
  • {/foreach} {else} @@ -51,7 +51,7 @@
  • {/if} - {if !$bEditDisabled}

    {$aLang.topic_poll_add_item}

    {/if} + {if !$bEditDisabled}

    {$aLang.topic_poll_add_item}

    {/if}


    diff --git a/templates/skin/developer-jquery/js/poll.js b/templates/skin/developer-jquery/js/poll.js index d710795e..8884a745 100644 --- a/templates/skin/developer-jquery/js/poll.js +++ b/templates/skin/developer-jquery/js/poll.js @@ -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($(''+LANG_DELETE+'').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($(''+LANG_DELETE+'').bind("click", deleteField)); - newItem.find('input').val(''); -} - -// Удаляет вариант ответа -function deleteField() { - $(this).parent("li").remove(); - return false; -} \ No newline at end of file + + return this; +}).call(ls.poll || {},jQuery); \ No newline at end of file diff --git a/templates/skin/developer-jquery/topic.tpl b/templates/skin/developer-jquery/topic.tpl index d5b709e3..fe584900 100644 --- a/templates/skin/developer-jquery/topic.tpl +++ b/templates/skin/developer-jquery/topic.tpl @@ -36,8 +36,8 @@ {/foreach} - - + + {else} {include file='topic_question.tpl'}