Last active
March 24, 2017 07:21
-
-
Save vita78/9f13240efddd27b2795a362edb0834c5 to your computer and use it in GitHub Desktop.
СЭД: удаление состояния selected в мультиселекте
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//_flags.html.twig | |
<script> | |
$('.b-bage-filters__clear').on('click', function() { | |
$('.b-bage-filters__select option[selected]').removeAttr('selected'); | |
$('.b-bage-filters__select').trigger('chosen:updated'); | |
}); | |
</script> | |
//аналог на БЭМ | |
_clearMultiSelect: function () { | |
var bageFilters = this; | |
console.log('1'); | |
bageFilters.findChildElem('select').domElem.find('option[selected]').removeAttr('selected'); | |
bageFilters.findChildElem('select').domElem.trigger('change'); | |
} | |
<script> | |
$(document).ready(function(){ | |
var l = $('.b-bage-filters__select option[selected]').length; | |
(l) ? $('.b-bage-filters__clear').removeClass('b-bage-filters__clear_invisible'): $('.b-bage-filters__clear').addClass('b-bage-filters__clear_invisible'); | |
}); | |
</script> | |
//аналог на БЭМ | |
_buttonVisibility : function () { | |
var bageFilters = this; | |
(bageFilters.findChildElem('select').domElem.find('option[selected]').length)? | |
bageFilters.findChildElem('clear').domElem.removeClass('b-bage-filters__clear_invisible'): | |
bageFilters.findChildElem('clear').domElem.addClass('b-bage-filters__clear_invisible') | |
} | |
======================================================= | |
<form class="b-bage-filters i-bem" data-bem='{"b-bage-filters": {}}' action="#"> | |
<div class="b-bage-filters__label"> Фильтр</div> | |
<div class="b-bage-filters__box"> | |
<select multiple name="tableFilter" class="b-bage-filters__select" data-placeholder="Введите запрос"> | |
{#"{% trans %}main.document.filter.filter{% endtrans %}">#} | |
<option value=""></option> | |
<option value="approveTo" {% if documentFilters is defined and "approveTo" in documentFilters %}selected="selected"{% endif %}>{% trans %}main.document.filter.label.approveTo{% endtrans %}</option> | |
<option value="approveBy" {% if documentFilters is defined and "approveBy" in documentFilters %}selected="selected"{% endif %}>{% trans %}main.document.filter.label.approveBy{% endtrans %}</option> | |
<option value="approveByWithStatusTrue" {% if documentFilters is defined and "approveByWithStatusTrue" in documentFilters %}selected="selected"{% endif %}>{% trans %}main.document.filter.label.approveByWithStatusTrue{% endtrans %}</option> | |
<option value="withControl" {% if documentFilters is defined and "withControl" in documentFilters %}selected="selected"{% endif %}>{% trans %}main.document.filter.label.withControl{% endtrans %}</option> | |
<option value="withAdditionalControl" {% if documentFilters is defined and "withAdditionalControl" in documentFilters %}selected="selected"{% endif %}>{% trans %}main.document.filter.label.withAdditionalControl{% endtrans %}</option> | |
<option value="takenFromTheControl" {% if documentFilters is defined and "takenFromTheControl" in documentFilters %}selected="selected"{% endif %}>{% trans %}main.document.filter.label.takenFromTheControl{% endtrans %}</option> | |
<option value="new" {% if documentFilters is defined and "new" in documentFilters %}selected="selected"{% endif %}>{% trans %}main.document.filter.label.new{% endtrans %}</option> | |
<option value="favorite" {% if documentFilters is defined and "favorite" in documentFilters %}selected="selected"{% endif %}>{% trans %}main.document.filter.label.favorite{% endtrans %}</option> | |
<option value="signed" {% if documentFilters is defined and "signed" in documentFilters %}selected="selected"{% endif %} >{% trans %}main.document.filter.label.signed{% endtrans %}</option> | |
<option value="unsigned" {% if documentFilters is defined and "unsigned" in documentFilters %}selected="selected"{% endif %}>{% trans %}main.document.filter.label.unsigned{% endtrans %}</option> | |
<option value="unApproveByMe" {% if documentFilters is defined and "unApproveByMe" in documentFilters %}selected="selected"{% endif %}>{% trans %}main.document.filter.label.unApproveByMe{% endtrans %}</option> | |
<option value="approvalProject" {% if documentFilters is defined and "approvalProject" in documentFilters %}selected="selected"{% endif %}>{% trans %}main.document.filter.label.approvalProject{% endtrans %}</option> | |
</select> | |
</div> | |
{#<button class="b-bage-filters__clear"><i class="fa fa-minus-circle"></i></button>#} | |
{% if getData.isOld is defined and getData.isOld is not null %}> | |
<input type="hidden" name="isOld" value="{{getData.isOld}}" /> | |
{% endif %} | |
{% if getData.showAllYearsDocs is defined and getData.showAllYearsDocs is not null %} | |
<input type="hidden" name="showAllYearsDocs" value="{{getData.showAllYearsDocs}}" /> | |
{% endif %} | |
<input type="hidden" name="filterEntity" value="DocumentEntities" /> | |
<input type="hidden" name="filterDocumentTypeId" {% if documentTypeId is defined %}value="{{documentTypeId}}" {% endif %} /> | |
<input type="hidden" name="documentTypeId" id="documentTypeIdForSettings" value="{{documentTypeId}}" /> | |
<span class="b-bage-filters__clear" >X</span> | |
</form> | |
============================================== | |
modules.define('b-bage-filters', ['jquery', 'i-bem-dom'], function (provide, $, bemDom) { | |
provide(bemDom.declBlock(this.name, { | |
onSetMod: { | |
js: { | |
inited: function () { | |
var bageFilters = this; | |
this.findChildElem('select').domElem.chosen({ | |
width: '100%', | |
// eslint-disable-next-line camelcase | |
allow_single_deselect: true | |
}); | |
this._buttonVisibility(); | |
this._domEvents().on('change', function () { | |
bageFilters.saveFilterSettings().then( | |
function () { | |
window.location.search = bageFilters.formDataToURL(); | |
}, | |
function () { | |
throw new Error('Ошибка сохранения фильтров.'); | |
} | |
); | |
}); | |
this._domEvents('clear').on('click', this._clearMultiSelect); | |
} | |
} | |
}, | |
formDataToURL: function () { | |
return this.domElem.serialize().split('&').map(function (s) { | |
if (s.split('=')[0] === 'tableFilter') { | |
return ['tableFilter[' + s.split('=')[1] + ']=on']; | |
} else { | |
return s; | |
} | |
}).join('&'); | |
}, | |
saveFilterSettings: function () { | |
var bageFilters = this; | |
return $.ajax({ | |
type: 'POST', | |
url: Routing.generate('core_helper_filter_save_filter_settings'), | |
data: bageFilters.formDataToURL() | |
}); | |
}, | |
_clearMultiSelect: function () { | |
var bageFilters = this; | |
bageFilters.findChildElem('select').domElem.find('option[selected]').removeAttr('selected'); | |
bageFilters.findChildElem('select').domElem.trigger('change'); | |
}, | |
_buttonVisibility : function () { | |
var bageFilters = this; | |
(bageFilters.findChildElem('select').domElem.find('option[selected]').length)? | |
bageFilters.findChildElem('clear').domElem.removeClass('b-bage-filters__clear_invisible'): | |
bageFilters.findChildElem('clear').domElem.addClass('b-bage-filters__clear_invisible') | |
} | |
})); | |
}); | |
===================== | |
.b-bage-filters | |
{ | |
font-size: 0.9em; | |
margin: 5px 10px 5px 0; | |
} | |
.b-bage-filters__box | |
{ | |
display: inline-block; | |
width: 600px; | |
} | |
.b-bage-filters__label | |
{ | |
line-height: 27px; | |
display: inline-block; | |
margin-right: 10px; | |
} | |
.b-bage-filters .chosen-container-multi .chosen-choices | |
{ | |
line-height: 25px; | |
} | |
.b-bage-filters .chosen-container-multi .chosen-choices::after | |
{ | |
font-family: 'FontAwesome'; | |
font-size: 15px; | |
position: absolute; | |
top: 1px; | |
right: 5px; | |
content: '\f067'; | |
color: #2f7094; | |
} | |
.b-bage-filters__clear | |
{ | |
font-size: 13px; | |
line-height: 25px; | |
position: relative; | |
display: inline-block; | |
width: auto; | |
margin: 0 5px; | |
padding: 0 10px 1px 20px; | |
text-align: center; | |
color: #fff; | |
border: none; | |
border-radius: 4px; | |
background: #6baacf; | |
} | |
.b-bage-filters__clear:hover | |
{ | |
background: #3a8fbc; | |
} | |
.b-bage-filters__clear:after | |
{ | |
font-family: 'FontAwesome'; | |
font-size: 15px; | |
position: absolute; | |
top: 1px; | |
left: 5px; | |
content: '\f00d'; | |
color: #fff; | |
} | |
.b-bage-filters__clear_invisible | |
{ | |
display: none; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment