qualif: redo qualification panel (#10092)

This commit is contained in:
Frédéric Péters 2016-04-12 15:05:31 +02:00
parent 136358c9d4
commit f5627532c7
2 changed files with 118 additions and 4 deletions

View File

@ -610,3 +610,64 @@ p.required label::after {
border-bottom: 1px dotted #aaa;
padding-top: 0.5ex;
}
ul.select-formdata {
margin-top: 0;
width: calc(100% - 6ex);
}
ul.select-formdata ul {
display: none;
padding: 0;
}
.cell ul.select-formdata li {
margin: 0;
margin-top: -1px;
list-style: none;
list-style: none;
}
.cell ul.select-formdata li span {
cursor: pointer;
display: block;
padding: 1ex;
}
.cell ul.select-formdata.expanded > li {
display: none;
}
.cell ul.select-formdata.expanded > li.on {
display: block;
}
.cell ul.select-formdata.expanded > li.on span {
font-weight: bold;
}
.cell ul.select-formdata.expanded > li.on span::after {
content: "✖";
position: absolute;
right: 1ex;
}
ul.select-formdata li.on ul {
display: block;
margin: 0;
padding: 0;
}
ul.select-formdata li.on ul li {
border-width: 1px 0;
padding: 1ex 1ex;
cursor: pointer;
}
div.add-formdef-reference button.add {
display: none;
}
ul.select-formdata li li:hover {
background: #eee;
}

View File

@ -1,4 +1,42 @@
$(function() {
$.fn.extend({
select_2levels: function () {
this.each(function() {
var $orig_select = $(this);
$orig_select.hide();
var $new_div = $('<ul class="result select-formdata"></ul>');
$new_div.appendTo($orig_select.parent());
$orig_select.find('optgroup').each(function(idx, optgroup) {
var $new_li = $('<li class="cat"><span>' + $(optgroup).attr('label') + '</span><ul></ul></li>');
var $new_sub_ul = $new_li.find('ul');
$(optgroup).find('option').each(function(idx, option) {
$('<li data-value="' + $(option).attr('value') + '">' + $(option).text() + '</li>').appendTo($new_sub_ul);
});
$new_li.appendTo($new_div);
});
$new_div.find('li.cat span').on('welco:click-on', function() {
$(this).parents('ul').find('li').removeClass('on');
$(this).parent().addClass('on');
$new_div.addClass('expanded');
});
$new_div.find('li.cat span').on('click', function() {
if ($(this).parent().hasClass('on')) {
$(this).parent().removeClass('on');
$new_div.removeClass('expanded');
} else {
$(this).parents('ul').find('li').removeClass('on');
$(this).parent().addClass('on');
$new_div.addClass('expanded');
$('.cell.qualif').scrollTop(0);
}
});
$new_div.find('[data-value]').on('click', function() {
$orig_select.val($(this).data('value'));
$orig_select.parents('div.add-formdef-reference').find('button.add').trigger('click');
});
});
}
});
function refresh_bottom_cells(callback) {
var source_type = $('div.source div[data-source-type]').data('source-type');
var source_pk = $('div.source .active[data-source-pk]').data('source-pk');
@ -10,7 +48,7 @@ $(function() {
dataType: 'html',
success: function(data) {
$(zone).find('> div').replaceWith(data);
$(zone).find('select').select2();
$(zone).find('select').select_2levels();
$(zone).removeClass('has-page-displayed');
$(zone).removeClass('has-contact-displayed');
$('#create-new-contact').off('click').on('click', window.displayPopup);
@ -45,7 +83,16 @@ $(function() {
$('#postit').data('url', $('#postit').data('base-url') + '?mail=' + source_pk);
$('#postit').trigger('welco:load-mail-note');
$('#postit').show();
refresh_bottom_cells();
refresh_bottom_cells(function() {
var selected_category = $('#category-filter').val();
if (selected_category) {
$('.qualif ul.select-formdata span').each(function() {
if ($(this).text() == selected_category) {
$(this).trigger('welco:click-on');
};
});
}
});
});
$('.contacts').delegate('button.save', 'click', function() {
@ -79,7 +126,7 @@ $(function() {
success: function(data) {
var zone = $('.cell.qualif');
$(zone).find('> div').replaceWith(data);
$(zone).find('select').select2();
$(zone).find('select').select_2levels();
if ($('#id_post_date').length && !$('#id_post_date').val()) {
$('div.qualif button.done').attr('disabled', 'disabled');
} else {
@ -105,6 +152,7 @@ $(function() {
dataType: 'html',
success: function(data) {
$('.cell.qualif > div').replaceWith(data);
$('.cell.qualif').find('select').select_2levels();
if ($('#id_post_date').length && !$('#id_post_date').val()) {
$('div.qualif button.done').attr('disabled', 'disabled');
} else {
@ -224,7 +272,7 @@ $(function() {
});
}
$(zone).find('select').select2();
$(zone).find('select').select_2levels();
$(zone).removeClass('has-contact-displayed');
$(zone).removeClass('has-page-displayed');
},
@ -387,6 +435,7 @@ $(function() {
});
$('#category-filter').on('change', function() {
var selected_category = $(this).val();
window.sessionStorage.selected_category = selected_category;
if (selected_category == '') {
$('#source-sidebar li').removeClass('li-visible');
$('#source-sidebar li').show();
@ -408,6 +457,10 @@ $(function() {
}
}
});
if (window.sessionStorage.getItem('selected_category') !== null) {
var selected_category = window.sessionStorage.getItem('selected_category');
$('#category-filter').val(selected_category).trigger('change');
}
}
$('.document').delegate('button#take-phoneline', 'click', function() {