mirror of
https://github.com/Oreolek/ifhub.club.git
synced 2024-06-02 16:18:12 +03:00
Доработка компонента poll
This commit is contained in:
parent
9436160996
commit
c476517b0d
|
@ -259,7 +259,7 @@ class ActionAjax extends Action
|
|||
$this->Session_SetCookie($this->Poll_GetCookieVoteName($oPoll), $oVote->getGuestKey(), time() + 60 * 60 * 24 * 90);
|
||||
}
|
||||
$oViewer = $this->Viewer_GetLocalViewer();
|
||||
$oViewer->Assign('oPoll', $oPoll);
|
||||
$oViewer->Assign('poll', $oPoll);
|
||||
$this->Viewer_AssignAjax('sText', $oViewer->Fetch("component@poll.result"));
|
||||
} else {
|
||||
return $this->EventErrorDebug();
|
||||
|
@ -284,8 +284,8 @@ class ActionAjax extends Action
|
|||
if ($oPoll->_Validate()) {
|
||||
if ($oPoll->Add()) {
|
||||
$oViewer = $this->Viewer_GetLocalViewer();
|
||||
$oViewer->Assign('oPoll', $oPoll);
|
||||
$this->Viewer_AssignAjax('sPollItem', $oViewer->Fetch("component@poll.manage.item"));
|
||||
$oViewer->Assign('poll', $oPoll);
|
||||
$this->Viewer_AssignAjax('item', $oViewer->Fetch("component@poll.manage.item"));
|
||||
return true;
|
||||
} else {
|
||||
$this->Message_AddError($this->Lang_Get('common.error.save'), $this->Lang_Get('common.error.error'));
|
||||
|
@ -328,9 +328,9 @@ class ActionAjax extends Action
|
|||
if ($oPoll->_Validate()) {
|
||||
if ($oPoll->Update()) {
|
||||
$oViewer = $this->Viewer_GetLocalViewer();
|
||||
$oViewer->Assign('oPoll', $oPoll);
|
||||
$this->Viewer_AssignAjax('sPollItem', $oViewer->Fetch("component@poll.manage.item"));
|
||||
$this->Viewer_AssignAjax('iPollId', $oPoll->getId());
|
||||
$oViewer->Assign('poll', $oPoll);
|
||||
$this->Viewer_AssignAjax('item', $oViewer->Fetch("component@poll.manage.item"));
|
||||
$this->Viewer_AssignAjax('id', $oPoll->getId());
|
||||
return true;
|
||||
} else {
|
||||
$this->Message_AddError($this->Lang_Get('common.error.save'), $this->Lang_Get('common.error.error'));
|
||||
|
@ -439,7 +439,7 @@ class ActionAjax extends Action
|
|||
}
|
||||
|
||||
$oViewer = $this->Viewer_GetLocalViewer();
|
||||
$oViewer->Assign('oPoll', $oPoll);
|
||||
$oViewer->Assign('poll', $oPoll);
|
||||
$oViewer->Assign('sTargetTmp', getRequestStr('target_tmp'));
|
||||
$this->Viewer_AssignAjax('sText', $oViewer->Fetch("component@poll.modal.create"));
|
||||
}
|
||||
|
|
|
@ -220,7 +220,7 @@
|
|||
this.answerIndex( list );
|
||||
|
||||
ls.ajax.submit( this.option( 'urls.add' ), form, function( response ) {
|
||||
this.elements.list.append( response.sPollItem );
|
||||
this.elements.list.append( response.item );
|
||||
modal.hide();
|
||||
}.bind(this), { submitButton: modal.element.find( 'button[type=submit]' ) });
|
||||
},
|
||||
|
@ -236,7 +236,7 @@
|
|||
this.answerIndex( list );
|
||||
|
||||
ls.ajax.submit( this.option( 'urls.update' ), form, function( response ) {
|
||||
this.elements.list.find( this.option( 'selectors.item' ) + '[data-poll-id=' + response.iPollId + ']' ).replaceWith( response.sPollItem );
|
||||
this.elements.list.find( this.option( 'selectors.item' ) + '[data-poll-id=' + response.id + ']' ).replaceWith( response.item );
|
||||
modal.hide();
|
||||
}.bind(this), { submitButton: modal.element.find( 'button[type=submit]' ) });
|
||||
},
|
||||
|
|
|
@ -3,13 +3,13 @@
|
|||
*}
|
||||
|
||||
{component 'modal'
|
||||
title = ( $oPoll ) ? {lang 'poll.form.title.edit'} : {lang 'poll.form.title.add'}
|
||||
title = ( $poll ) ? {lang 'poll.form.title.edit'} : {lang 'poll.form.title.add'}
|
||||
content = {component 'poll' template='form'}
|
||||
classes = 'js-modal-default'
|
||||
mods = 'poll-create'
|
||||
id = 'modal-poll-create'
|
||||
primaryButton = [
|
||||
'text' => ($oPoll) ? $aLang.common.save : $aLang.common.add,
|
||||
'text' => ($poll) ? $aLang.common.save : $aLang.common.add,
|
||||
'form' => 'js-poll-form',
|
||||
'classes' => 'js-poll-form-submit'
|
||||
]}
|
|
@ -1,35 +1,49 @@
|
|||
{**
|
||||
* Блок добавления ответа
|
||||
*
|
||||
* @styles poll.css
|
||||
* @scripts <common>/js/poll.js
|
||||
* @param boolean $item
|
||||
* @param integer $index
|
||||
* @param boolean $allowRemove
|
||||
* @param boolean $showRemove
|
||||
* @param boolean $isTemplate
|
||||
*}
|
||||
|
||||
<li class="ls-poll-form-answer-item js-poll-form-answer-item"
|
||||
{if $bPollItemIsTemplate|default:false}data-is-template="true"{/if}
|
||||
{if $bPollItemIsTemplate|default:false}style="display: none"{/if}>
|
||||
{$component = 'ls-poll-form-answer-item'}
|
||||
|
||||
{foreach [ 'item', 'index', 'allowRemove', 'showRemove', 'isTemplate' ] as $param}
|
||||
{assign var="$param" value=$smarty.local.$param}
|
||||
{/foreach}
|
||||
|
||||
{$allowUpdate = $allowUpdate|default:true}
|
||||
{$allowRemove = $allowRemove|default:true}
|
||||
{$showRemove = $showRemove|default:true}
|
||||
{$index = $index|default:0}
|
||||
|
||||
<li class="{$component} js-poll-form-answer-item"
|
||||
{if $isTemplate}data-is-template="true"{/if}
|
||||
{if $isTemplate}style="display: none"{/if}>
|
||||
|
||||
{* ID *}
|
||||
{component 'field' template='hidden'
|
||||
name = "answers[{$iPollItemIndex|default:0}][id]"
|
||||
value = "{if $oPollItem}{$oPollItem->getId()}{/if}"
|
||||
name = "answers[{$index}][id]"
|
||||
value = "{if $item}{$item->getId()}{/if}"
|
||||
classes = "js-poll-form-answer-item-id"}
|
||||
|
||||
{* Текст *}
|
||||
{component 'field' template='text'
|
||||
name = 'answers[]'
|
||||
value = ($oPollItem) ? $oPollItem->getTitle() : ''
|
||||
isDisabled = ! $bPollIsAllowUpdate|default:true
|
||||
value = ($item) ? $item->getTitle() : ''
|
||||
isDisabled = ! $allowUpdate
|
||||
inputClasses = 'width-full js-poll-form-answer-item-text'}
|
||||
|
||||
{* Кнопка удаления *}
|
||||
{if $bPollIsAllowRemove|default:true}
|
||||
{if $allowRemove}
|
||||
{component 'icon'
|
||||
icon='remove'
|
||||
classes='ls-poll-form-answer-item-remove js-poll-form-answer-item-remove'
|
||||
classes="{$component}-remove js-poll-form-answer-item-remove"
|
||||
attributes=[
|
||||
title => {lang 'blog.private'},
|
||||
style => "{if ! $smarty.local.showRemove|default:true}display: none{/if}"
|
||||
style => "{if ! $showRemove}display: none{/if}"
|
||||
]}
|
||||
{/if}
|
||||
</li>
|
|
@ -1,32 +1,27 @@
|
|||
{**
|
||||
* Форма добавления опроса
|
||||
*
|
||||
* @styles poll.css
|
||||
* @scripts <common>/js/poll.js
|
||||
*}
|
||||
|
||||
<form action="" method="post" id="js-poll-form" data-action="{if $oPoll}update{else}add{/if}">
|
||||
<form action="" method="post" id="js-poll-form" data-action="{if $poll}update{else}add{/if}">
|
||||
{* Заголовок *}
|
||||
{component 'field' template='text'
|
||||
name = 'poll[title]'
|
||||
value = {($oPoll) ? $oPoll->getTitle() : '' }
|
||||
value = {($poll) ? $poll->getTitle() : '' }
|
||||
label = $aLang.poll.form.fields.title
|
||||
inputAttributes= [ 'autofocus' => true ]}
|
||||
|
||||
|
||||
{component 'field' template='checkbox'
|
||||
name = 'poll[is_guest_allow]'
|
||||
checked = {($oPoll && $oPoll->getIsGuestAllow()) ? true : false }
|
||||
checked = {($poll && $poll->getIsGuestAllow()) ? true : false }
|
||||
label = $aLang.poll.form.fields.is_guest_allow}
|
||||
|
||||
|
||||
{component 'field' template='checkbox'
|
||||
name = 'poll[is_guest_check_ip]'
|
||||
checked = {($oPoll && $oPoll->getIsGuestCheckIp()) ? true : false }
|
||||
checked = {($poll && $poll->getIsGuestCheckIp()) ? true : false }
|
||||
label = $aLang.poll.form.fields.is_guest_check_ip}
|
||||
|
||||
{* Кол-во вариантов которые может выбрать пользователь *}
|
||||
{if $oPoll && $oPoll->getCountVote()}
|
||||
{if $poll && $poll->getCountVote()}
|
||||
{$bDisableChangeType = true}
|
||||
{/if}
|
||||
|
||||
|
@ -36,7 +31,7 @@
|
|||
name = 'poll[type]'
|
||||
value = 'one'
|
||||
label = $aLang.poll.form.fields.type.label_one
|
||||
checked = ! $oPoll or $oPoll->getCountAnswerMax() == 1
|
||||
checked = ! $poll or $poll->getCountAnswerMax() == 1
|
||||
isDisabled = $bDisableChangeType}
|
||||
|
||||
{component 'field' template='radio'
|
||||
|
@ -44,13 +39,13 @@
|
|||
name = 'poll[type]'
|
||||
value = 'many'
|
||||
label = $aLang.poll.form.fields.type.label_many
|
||||
checked = $oPoll && $oPoll->getCountAnswerMax() > 1
|
||||
checked = $poll && $poll->getCountAnswerMax() > 1
|
||||
isDisabled = $bDisableChangeType}
|
||||
|
||||
{component 'field' template='text'
|
||||
displayInline = true
|
||||
name = 'poll[count_answer_max]'
|
||||
value = ($oPoll) ? $oPoll->getCountAnswerMax() : 2
|
||||
value = ($poll) ? $poll->getCountAnswerMax() : 2
|
||||
classes = 'width-50'
|
||||
isDisabled = $bDisableChangeType}
|
||||
|
||||
|
@ -63,38 +58,38 @@
|
|||
|
||||
<div class="fieldset-body">
|
||||
<ul class="ls-poll-form-answer-list js-poll-form-answer-list">
|
||||
{if $oPoll}
|
||||
{$aAnswers = $oPoll->getAnswers()}
|
||||
{if $poll}
|
||||
{$aAnswers = $poll->getAnswers()}
|
||||
|
||||
{foreach $aAnswers as $oAnswer}
|
||||
{include './poll.form.item.tpl'
|
||||
oPollItem = $oAnswer
|
||||
iPollItemIndex = $oAnswer@index
|
||||
bPollIsAllowUpdate = $oPoll->isAllowUpdate()
|
||||
bPollIsAllowRemove = $oPoll->isAllowUpdate() && ! $oAnswer->getCountVote()}
|
||||
{component 'poll' template='form-item'
|
||||
item = $oAnswer
|
||||
index = $oAnswer@index
|
||||
allowUpdate = $poll->isAllowUpdate()
|
||||
allowRemove = $poll->isAllowUpdate() && ! $oAnswer->getCountVote()}
|
||||
{/foreach}
|
||||
{else}
|
||||
{include './poll.form.item.tpl' showRemove=false}
|
||||
{include './poll.form.item.tpl' showRemove=false}
|
||||
{component 'poll' template='form-item' showRemove=false}
|
||||
{component 'poll' template='form-item' showRemove=false}
|
||||
{/if}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
{if ! $oPoll or $oPoll->isAllowUpdate()}
|
||||
{if ! $poll or $poll->isAllowUpdate()}
|
||||
<footer class="fieldset-footer">
|
||||
{component 'button'
|
||||
type = 'button'
|
||||
text = $aLang.common.add
|
||||
attributes = [ 'title' => '[Ctrl + Enter]' ]
|
||||
classes = 'js-poll-form-answer-add'}
|
||||
type = 'button'
|
||||
text = $aLang.common.add
|
||||
attributes = [ 'title' => '[Ctrl + Enter]' ]
|
||||
classes = 'js-poll-form-answer-add'}
|
||||
</footer>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
|
||||
{* Скрытые поля *}
|
||||
{if $oPoll}
|
||||
{component 'field' template='hidden' name='poll_id' value=$oPoll->getId()}
|
||||
{if $poll}
|
||||
{component 'field' template='hidden' name='poll_id' value=$poll->getId()}
|
||||
{else}
|
||||
{component 'field' template='hidden' name='target[type]' value=$sTargetType}
|
||||
{component 'field' template='hidden' name='target[id]' value=$sTargetId}
|
||||
|
@ -104,4 +99,4 @@
|
|||
</form>
|
||||
|
||||
{* Шаблон ответа для добавления с помощью js *}
|
||||
{include './poll.form.item.tpl' bPollItemIsTemplate=true}
|
||||
{component 'poll' template='form-item' isTemplate=true}
|
|
@ -5,5 +5,5 @@
|
|||
*}
|
||||
|
||||
{foreach $polls as $poll}
|
||||
{include './poll.tpl' poll=$poll}
|
||||
{component 'poll' poll=$poll}
|
||||
{/foreach}
|
|
@ -1,26 +1,23 @@
|
|||
{**
|
||||
* Добавленный опрос в блоке управления опросами
|
||||
*
|
||||
* @param ModulePoll_EntityPoll $oPoll Опрос
|
||||
*
|
||||
* @styles poll.css
|
||||
* @scripts <common>/js/poll.js
|
||||
* @param ModulePoll_EntityPoll $poll Опрос
|
||||
*}
|
||||
|
||||
<li class="ls-poll-manage-item js-poll-manage-item" data-poll-id="{$oPoll->getId()}" data-poll-target-tmp="{$oPoll->getTargetTmp()}">
|
||||
<li class="ls-poll-manage-item js-poll-manage-item" data-poll-id="{$poll->getId()}" data-poll-target-tmp="{$poll->getTargetTmp()}">
|
||||
{* Заголовок *}
|
||||
{$oPoll->getTitle()}
|
||||
{$poll->getTitle()}
|
||||
|
||||
{* Действия *}
|
||||
<ul class="user-list-small-item-actions">
|
||||
{* Редактировать *}
|
||||
{* Показывает модальное окно с формой редактирования опроса *}
|
||||
<li class="js-poll-manage-item-edit" title="{$aLang.common.edit}" data-poll-id="{$oPoll->getId()}" data-poll-target-tmp="{$oPoll->getTargetTmp()}">
|
||||
<li class="js-poll-manage-item-edit" title="{$aLang.common.edit}" data-poll-id="{$poll->getId()}" data-poll-target-tmp="{$poll->getTargetTmp()}">
|
||||
{component 'icon' icon='edit'}
|
||||
</li>
|
||||
|
||||
{* Удалить *}
|
||||
<li class="js-poll-manage-item-remove" title="{$aLang.common.remove}" data-poll-id="{$oPoll->getId()}" data-poll-target-tmp="{$oPoll->getTargetTmp()}">
|
||||
<li class="js-poll-manage-item-remove" title="{$aLang.common.remove}" data-poll-id="{$poll->getId()}" data-poll-target-tmp="{$poll->getTargetTmp()}">
|
||||
{component 'icon' icon='remove'}
|
||||
</li>
|
||||
</ul>
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
{**
|
||||
* Список добавленных опросов в форме добавления
|
||||
*
|
||||
* @styles poll.css
|
||||
* @scripts <common>/js/poll.js
|
||||
*}
|
||||
|
||||
<ul class="ls-poll-manage-list js-poll-manage-list">
|
||||
{if $aPollItems}
|
||||
{foreach $aPollItems as $oPoll}
|
||||
{include './poll.manage.item.tpl' oPoll=$oPoll}
|
||||
{foreach $aPollItems as $poll}
|
||||
{component 'poll' template='manage.item' poll=$poll}
|
||||
{/foreach}
|
||||
{/if}
|
||||
</ul>
|
|
@ -3,9 +3,6 @@
|
|||
*
|
||||
* @param string $targetId
|
||||
* @param string $targetType
|
||||
*
|
||||
* @styles poll.css
|
||||
* @scripts <common>/js/poll.js
|
||||
*}
|
||||
|
||||
<div class="fieldset ls-poll-manage js-poll-manage" data-type="{$smarty.local.targetType}" data-target-id="{$smarty.local.targetId}">
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
{**
|
||||
* Результат опроса
|
||||
*
|
||||
* @param ModulePoll_EntityPoll $oPoll Опрос
|
||||
* @param ModulePoll_EntityPoll $poll Опрос
|
||||
*}
|
||||
|
||||
{* Список ответов *}
|
||||
<ul class="ls-poll-result js-poll-result">
|
||||
{$answers = $oPoll->getAnswers()}
|
||||
{$answers = $poll->getAnswers()}
|
||||
{$count = count($answers)}
|
||||
{$answersCurrent=$oPoll->getVoteCurrent()->getAnswers()}
|
||||
{$answersCurrent=$poll->getVoteCurrent()->getAnswers()}
|
||||
|
||||
{foreach $answers as $answer}
|
||||
{$votes = $answer->getCountVote()}
|
||||
{$percent = $oPoll->getAnswerPercent($answer)}
|
||||
{$percent = $poll->getAnswerPercent($answer)}
|
||||
|
||||
{* Ответ *}
|
||||
<li class="ls-poll-result-item
|
||||
{if $oPoll->getCountVoteAnswerMax() == $votes}poll-result-item--most{/if}
|
||||
{if $poll->getCountVoteAnswerMax() == $votes}poll-result-item--most{/if}
|
||||
{if in_array( $answer->getId(), $answersCurrent )}poll-result-item--voted{/if}
|
||||
js-poll-result-item"
|
||||
data-count = "{$votes}"
|
||||
|
@ -46,6 +46,6 @@
|
|||
|
||||
{* Статистика голосования *}
|
||||
<span class="ls-poll-result-total">
|
||||
{$aLang.poll.result.voted_total}: {$oPoll->getCountVote()} |
|
||||
{$aLang.poll.result.abstained_total}: {$oPoll->getCountAbstain()}
|
||||
{$aLang.poll.result.voted_total}: {$poll->getCountVote()} |
|
||||
{$aLang.poll.result.abstained_total}: {$poll->getCountAbstain()}
|
||||
</span>
|
|
@ -8,8 +8,8 @@
|
|||
<h3 class="ls-poll-title">{$poll->getTitle()}</h3>
|
||||
|
||||
{if ! $poll->getVoteCurrent()}
|
||||
{include './poll.vote.tpl' poll=$poll}
|
||||
{component 'poll' template='vote' poll=$poll}
|
||||
{else}
|
||||
{include './poll.result.tpl' oPoll=$poll}
|
||||
{component 'poll' template='result' poll=$poll}
|
||||
{/if}
|
||||
</div>
|
Loading…
Reference in a new issue