workers and ressources fusion improvements

This commit is contained in:
Serghei Mihai 2014-03-27 00:32:53 +01:00
parent 9433e99231
commit 349332916b
5 changed files with 57 additions and 95 deletions

View File

@ -1,4 +1,4 @@
<li class='ressource-{{ ressource_id }}'>
<li class='{{ type }}-{{ ressource_id }}'>
<ul>
<li class="initials" data-id="{{ ressource_id }}">
{{ initials }}

View File

@ -36,13 +36,13 @@
<dd><ul>
{% for worker in workers_type.workers %}
{% if worker|is_worker_in_service:service_name and worker|is_intervenant %}
<li id="selector-worker-{{worker.id}}" class="worker-item in_service intervenant" data-worker-id="{{worker.id}}" data-target=".worker-{{worker.id}}.agenda">{{ worker.first_name }} <span class="lastname">{{ worker.last_name }}</span>{% if not worker.services.all %} (Ext){% endif %}<span class="icon-toggle"></span></li>
<li id="worker-{{worker.id}}" class="item in_service intervenant worker" data-target=".worker-{{worker.id}}.agenda">{{ worker.first_name }} <span class="lastname">{{ worker.last_name }}</span>{% if not worker.services.all %} (Ext){% endif %}<span class="icon-toggle"></span></li>
{% elif worker|is_worker_in_service:service_name %}
<li id="selector-worker-{{worker.id}}" class="worker-item in_service" data-worker-id="{{worker.id}}" data-target=".worker-{{worker.id}}.agenda">{{ worker.first_name }} <span class="lastname">{{ worker.last_name }}</span>{% if not worker.services.all %} (Ext){% endif %} <span class="icon-toggle"></span></li>
<li id="worker-{{worker.id}}" class="item in_service worker" data-target=".worker-{{worker.id}}.agenda">{{ worker.first_name }} <span class="lastname">{{ worker.last_name }}</span>{% if not worker.services.all %} (Ext){% endif %} <span class="icon-toggle"></span></li>
{% elif worker|is_intervenant %}
<li id="selector-worker-{{worker.id}}" class="worker-item intervenant" data-worker-id="{{worker.id}}" data-target=".worker-{{worker.id}}.agenda">{{ worker.first_name }} <span class="lastname">{{ worker.last_name }}</span>{% if not worker.services.all %} (Ext){% endif %} <span class="icon-toggle"></span></li>
<li id="worker-{{worker.id}}" class="item intervenant worker" data-target=".worker-{{worker.id}}.agenda">{{ worker.first_name }} <span class="lastname">{{ worker.last_name }}</span>{% if not worker.services.all %} (Ext){% endif %} <span class="icon-toggle"></span></li>
{% else %}
<li id="selector-worker-{{worker.id}}" class="worker-item" data-worker-id="{{worker.id}}" data-target=".worker-{{worker.id}}.agenda">{{ worker.first_name }} <span class="lastname">{{ worker.last_name }}</span>{% if not worker.services.all %} (Ext){% endif %} <span class="icon-toggle"></span></li>
<li id="selector-worker-{{worker.id}}" class="item worker" data-target=".worker-{{worker.id}}.agenda">{{ worker.first_name }} <span class="lastname">{{ worker.last_name }}</span>{% if not worker.services.all %} (Ext){% endif %} <span class="icon-toggle"></span></li>
{% endif %}
{% endfor %}
</ul></dd>
@ -51,7 +51,7 @@
<dt>{{ ressources_type.type }}</dt>
<dd><ul>
{% for ressource in ressources_type.ressources %}
<li id="selector-ressource-{{ressource.id}}" class="ressource-item" data-ressource-id="{{ressource.id}}" data-target=".ressource-{{ressource.id}}.agenda">{{ ressource.name }} <span class="icon-toggle"></span></li>
<li id="ressource-{{ressource.id}}" class="item ressource" data-target=".ressource-{{ressource.id}}.agenda" data-type="ressource">{{ ressource.name }} <span class="icon-toggle"></span></li>
{% endfor %}
</ul></dd>
{% endfor %}
@ -86,20 +86,20 @@
<ul>
{% for worker in workers %}
<li style="display: none" class="worker-{{ worker.id }} agenda">
<a id="link-tab-worker-{{ worker.id }}" href="{% url "ajax-worker-tab" service date worker.id %}" class="tab" data-id="{{ worker.id }}">
<a id="worker-{{ worker.id }}" href="{% url "ajax-worker-tab" service date worker.id %}" class="tab">
{{ worker.first_name }}
<span class="lastname">{{ worker.last_name }}</span>
</a>
<a href="#" style="padding: 3px;cursor: auto;" class="close-tab" data-target="selector-worker-{{ worker.id }}"><span class="ui-icon ui-icon-circle-close"></span></a>
<a href="#" style="padding: 3px;cursor: auto;" class="close-tab" data-target="worker-{{ worker.id }}"><span class="ui-icon ui-icon-circle-close"></span></a>
</li>
{% endfor %}
{% for ressource in ressources_types.0.ressources %}
<li style="display: none" class="ressource-{{ ressource.id }} agenda">
<a id="link-tab-ressource-{{ ressource.id }}" href="{% url "ajax-ressource-tab" service date ressource.id %}" class="tab" data-id="{{ ressource.id }}">
<a id="ressource-{{ ressource.id }}" href="{% url "ajax-ressource-tab" service date ressource.id %}" class="tab">
{{ ressource }}
</a>
<a href="#" style="padding: 3px;cursor: auto;" class="close-tab" data-target="selector-ressource-{{ ressource.id }}"><span class="ui-icon ui-icon-circle-close"></span></a>
<a href="#" style="padding: 3px;cursor: auto;" class="close-tab" data-target="ressource-{{ ressource.id }}"><span class="ui-icon ui-icon-circle-close"></span></a>
</li>
{% endfor %}
</ul>

View File

@ -71,10 +71,10 @@ agenda_patterns = patterns('',
url(r'^ajax-ressource-tab/(?P<ressource_id>\d+)$',
AjaxRessourceTabView.as_view(),
name='ajax-ressource-tab'),
url(r'^ajax-worker-disponibility-column/(?P<worker_id>\d+)$',
url(r'^disponibility/worker-(?P<worker_id>\d+)$',
AjaxWorkerDisponibilityColumnView.as_view(),
name='ajax-worker-disponibility-column'),
url(r'^ajax-ressource-disponibility-column/(?P<ressource_id>\d+)$',
url(r'^disponibility/ressource-(?P<ressource_id>\d+)$',
AjaxRessourceDisponibilityColumnView.as_view(),
name='ajax-ressource-disponibility-column'),
url(r'^rendez-vous-periodiques/$',

View File

@ -637,6 +637,7 @@ class AjaxWorkerDisponibilityColumnView(TemplateView):
holidays_workers = {worker.id: holidays_worker}
context['initials'] = worker.initials
context['type'] = 'worker'
context['ressource_id'] = worker.id
context['disponibility'] = Event.objects.daily_disponibilities(self.date,
events_workers, [worker], time_tables_workers, holidays_workers)
@ -647,7 +648,7 @@ class AjaxRessourceDisponibilityColumnView(AjaxWorkerDisponibilityColumnView):
def get_context_data(self, ressource_id, **kwargs):
context = {}
ressource = Room.objects.get(pk = ressource_id)
context = {'initials': ressource.name[:3], 'ressource_id': ressource.id}
context = {'initials': ressource.name[:3], 'ressource_id': ressource.id, 'type': 'ressource'}
disponibility = dict()
start_datetime = datetime.datetime(self.date.year,
self.date.month,

View File

@ -250,58 +250,52 @@ function enable_events(base) {
});
}
function toggle_ressource(ressource_selector, ressource) {
function toggle_ressource(ressource) {
var ressource_id = $(ressource_selector).data(ressource + '-id');
if (!ressource_id) {
var ressource_id = $(ressource).attr('id');
var ressource_target = $(ressource).data('target');
if (!ressource_target) {
return;
}
$(ressource_selector).toggleClass('active');
if (!($.cookie('agenda-' + ressource + '-tabs'))) {
$.cookie('agenda-' + ressource + '-tabs', new Array(), { path: COOKIE_PATH });
$(ressource).toggleClass('active');
if (!($.cookie('agenda-tabs'))) {
$.cookie('agenda-tabs', new Array(), { path: COOKIE_PATH });
}
if ($(ressource_selector).hasClass('active')) {
var tabs = $.cookie('agenda-' + ressource + '-tabs');
if ($.inArray($(ressource_selector).attr('id'), tabs) == -1)
if ($(ressource).hasClass('active')) {
var tabs = $.cookie('agenda-tabs');
if ($.inArray(ressource_id, tabs) == -1)
{
tabs.push($(ressource_selector).attr('id'));
$.cookie('agenda-' + ressource + '-tabs', tabs, { path: COOKIE_PATH });
tabs.push(ressource_id);
$.cookie('agenda-tabs', tabs, { path: COOKIE_PATH });
}
}
else {
var agendatabs = $.cookie('agenda-' + ressource + '-tabs');
var agendatabs = $.cookie('agenda-tabs');
$.each(agendatabs, function (i, value) {
if (value == $(ressource_selector).attr('id')) {
if (value == ressource_id) {
agendatabs.splice(i, 1);
}
});
$.cookie('agenda-' + ressource + '-tabs', agendatabs, { path: COOKIE_PATH });
$.cookie('agenda-tabs', agendatabs, { path: COOKIE_PATH });
}
var target = $($(ressource_selector).data('target'));
target.toggle()
$(ressource_target).toggle()
$('#close-all-agendas').toggle($('#users li.active').length != 0);
if (! $('#users li.active').length) {
$('#agendas #tabs div').hide();
}
var tab = $('#link-tab-' + ressource + '-' + ressource_id).parent().get(0);
var tab = $(ressource_target);
var tab_list = $(tab).parent().get(0);
$(tab).detach().appendTo(tab_list);
var url = $("#date-selector").data('url');
var tab_selector = '';
if (ressource == 'worker') {
tab_selector = '#selector-' + ressource + '-' + ressource_id + '.active';
} else {
tab_selector = '#selector-ressource-' + ressource_id + '.active';
}
var tab_selector = '#' + ressource_id + '.active';
if ($(tab_selector).length) {
/* load disponibility column */
$.get(url + 'ajax-' + ressource + '-disponibility-column/' + ressource_id,
$.get(url + 'disponibility/' + ressource_id,
function(data) {
if ($(tab_selector).hasClass('active')) {
var availability_block = $('ul#availability');
@ -311,9 +305,9 @@ function toggle_ressource(ressource_selector, ressource) {
);
} else {
// remove hidden ressource availability
$('ul#availability li.ressource-'+ressource_id).remove();
$('ul#availability li.' + ressource_id).remove();
}
return target.find('a.tab');
return $(ressource_target).find('a.tab');
}
function event_dialog(url, title, width, btn_text) {
@ -336,9 +330,9 @@ function event_dialog(url, title, width, btn_text) {
enable_new_event();
enable_new_appointment();
if ($('.worker-item').length) {
$('.worker-item').on('click', function() {
var target = toggle_ressource(this, 'worker');
if ($('#users .item').length) {
$('#users .item').on('click', function() {
var target = toggle_ressource(this);
if ($(target).is(':visible')) {
$(target).click();
@ -354,49 +348,19 @@ function event_dialog(url, title, width, btn_text) {
});
$('a.tab').click(function() {
$.cookie('active-worker-agenda', $(this).data('id'), { path: COOKIE_PATH });
$.cookie('active-agenda', $(this).attr('id'), { path: COOKIE_PATH });
});
if ($.cookie('agenda-worker-tabs')) {
$.each($.cookie('agenda-worker-tabs'), function (i, worker_selector) {
toggle_ressource('#' + worker_selector, 'worker');
if ($.cookie('agenda-tabs')) {
$.each($.cookie('agenda-tabs'), function (i, selector) {
toggle_ressource($('#' + selector));
});
if ($.cookie('active-worker-agenda'))
if ($.cookie('active-agenda'))
{
var target = $('#link-tab-worker-' + $.cookie('active-worker-agenda'));
if (target.is(':visible')) {
target.click();
}
}
}
}
if ($('.ressource-item').length) {
$('.ressource-item').on('click', function() {
var target = toggle_ressource(this, 'ressource');
if ($(target).is(':visible')) {
$(target).click();
}
if ($('#filtre input').val()) {
$('#filtre input').val('');
$('#filtre input').keyup();
$('#filtre input').focus();
}
});
$('a.tab').click(function() {
$.cookie('active-ressource-agenda', $(this).data('id'), { path: COOKIE_PATH });
});
if ($.cookie('agenda-ressource-tabs')) {
$.each($.cookie('agenda-ressource-tabs'), function (i, ressource_selector) {
toggle_ressource('#' + ressource_selector, 'ressource');
});
if ($.cookie('active-ressource-agenda'))
{
var target = $('#link-tab-ressource-' + $.cookie('active-ressource-agenda'));
if (target.is(':visible')) {
target.click();
var target = $("#" + $.cookie('active-agenda')).data('target');
if (!$('#tabs ' + target).hasClass('ui-state-active')) {
$("#tabs " + target + ' a.tab').click();
}
}
}
@ -405,13 +369,12 @@ function event_dialog(url, title, width, btn_text) {
$('a.close-tab').click(function() {
var target = '#' + $(this).data('target');
$(target).click();
if ($.cookie('active-ressource-agenda') == $(target).data('ressource-id')) {
$.cookie('active-ressource-agenda','', { path: COOKIE_PATH });
if ($.cookie('active-agenda') == $(target).attr('id')) {
$.cookie('active-agenda', '', { path: COOKIE_PATH });
}
});
/* Gestion du filtre sur les utilisateurs */
$('#filtre input').keyup(function() {
var filtre = $(this).val();
@ -432,8 +395,8 @@ function event_dialog(url, title, width, btn_text) {
} else {
$('#users li').show();
if (! everybody) {
$('.worker-item:not(.in_service)').hide();
$('.worker-item:not(.intervenant)').hide();
$('.item.worker:not(.in_service)').hide();
$('.item.worker:not(.intervenant)').hide();
}
}
/* hide worker type titles that do not have a single visible person */
@ -461,15 +424,13 @@ function event_dialog(url, title, width, btn_text) {
})
$('#filtre input').keyup();
$.each({'persons': {'button': 'worker', 'element': 'worker'},
'rooms': {'button': 'ressource', 'element': 'ressource'}
},
$.each({'persons': 'worker',
'rooms': 'ressource'},
function(key, value) {
$('#close-all-agendas').click(function() {
console.log(value);
$.cookie('active-' + value.element + '-agenda', '', {path: COOKIE_PATH});
$('.' + value.element + '-item.active').each(function (i, v) {
toggle_ressource(v, value.element);
$.cookie('active-agenda', '', {path: COOKIE_PATH});
$('#users .item.active').each(function (i, v) {
toggle_ressource(v, value);
});
});
});