Project

General

Profile

« Previous | Next » 

Revision 2fcd3fce

Added by Jérôme Schneider over 13 years ago

agenda: cleaning occurrence deleting

View differences:

calebasse/agenda/templates/agenda/index.html
{% extends "calebasse/base.html" %}
{% load url from future %}
{% block extrascripts %}
<script>
function replace_anchor(url, anchor) {
<script>
function replace_anchor(url, anchor) {
var splitted = url.split('#');
return splitted[0] + '#' + encodeURI(anchor);
}
function extract_anchor() {
return splitted[0] + '#' + encodeURI(anchor);
}
function extract_anchor() {
if (window.location.href.indexOf('#') == -1) {
return "";
return "";
}
var splitted = window.location.href.split('#');
return decodeURI(splitted[1]).split(',');
}
function make_anchor() {
}
function make_anchor() {
return $.makeArray($('.person-item.active').map(function (v, i) { return '_' + $(i).attr('id'); })).join(',');
}
function toggle_worker(worker_selector) {
}
function toggle_worker(worker_selector) {
$(worker_selector).toggleClass('active');
// update the anchor
var anchor = make_anchor();
......
console.log(new_uri);
window.location.href = new_uri;
$('a[href^="../"]').each(function (i, a) {
$(a).attr('href', replace_anchor($(a).attr('href'), anchor));
$(a).attr('href', replace_anchor($(a).attr('href'), anchor));
});
var $target = $($(worker_selector).data('target'));
$target.toggle();
if ($target.is(':visible')) {
$target.click();
$target.click();
}
}
function delete_appointment(id, title) {
var r=confirm("Etes-vous sûr de vouloir supprimer le rendez-vous "+ title + " ?");
if (r == true)
{
$.ajax({
url: '/api/occurrence/' + id + '/',
type: 'DELETE',
success: function(data) {
window.location.reload(true);
}
});
}
}
$(function() {
$('#tabs').tabs();
}
$(function() {
$('#tabs').tabs();
$('div.agenda > div').accordion({active: false, autoHeight: false});
$('div.agenda > div').accordion({active: false, autoHeight: false});
$('.person-item').on('click', function() {
toggle_worker(this);
});
// select all anchors
$.each(extract_anchor(), function (i, anchor) {
$('#'+anchor.substr(1)).each(function (i, worker_selector) { toggle_worker(worker_selector); });
});
$('.person-item').on('click', function() {
toggle_worker(this);
});
// select all anchors
$.each(extract_anchor(), function (i, anchor) {
$('#'+anchor.substr(1)).each(function (i, worker_selector) { toggle_worker(worker_selector); });
});
$('.textedit').on('keydown', function() {
$('button', this).removeAttr("disabled");
});
$('.textedit button').on('click', function() {
var textarea = $(this).prev();
var span = textarea.prev()
var btn = $(this)
$.ajax({
url: '/api/event/' + $(this).data("event-id") + '/?format=json',
type: 'PATCH',
contentType: 'application/json',
data: '{"description": "' + textarea.val() + '"}',
success: function(data) {
btn.attr('disabled', 'disabled');
span.html('Commentaire modifiée avec succès');
}
$('.textedit').on('keydown', function() {
$('button', this).removeAttr("disabled");
});
$('.textedit button').on('click', function() {
var textarea = $(this).prev();
var span = textarea.prev()
var btn = $(this)
$.ajax({
url: '/api/event/' + $(this).data("event-id") + '/?format=json',
type: 'PATCH',
contentType: 'application/json',
data: '{"description": "' + textarea.val() + '"}',
success: function(data) {
btn.attr('disabled', 'disabled');
span.html('Commentaire modifiée avec succès');
}
});
});
$('.appointment').on('click', function() {
$('.textedit span', this).html('');
});
});
$('.appointment').on('click', function() {
$('.textedit span', this).html('');
});
$('.remove-appointment').on('click', function() {
var r = confirm("Etes-vous sûr de vouloir supprimer le rendez-vous " + $(this).data('rdv') + " ?");
if (r == true)
{
$.ajax({
url: '/api/occurrence/' + $(this).data('occurrence-id') + '/',
type: 'DELETE',
success: function(data) {
window.location.reload(true);
return false;
}
});
}
return false;
});
/* Gestion du filtre sur les utilisateurs */
$('#filtre input').keyup(function() {
var filtre = $(this).val();
if (filtre) {
$('#users li').each(function() {
if ($(this).text().match(filtre)) {
$(this).show();
} else {
$(this).hide();
}
});
} else {
$('#users li').show();
}
/* Gestion du filtre sur les utilisateurs */
$('#filtre input').keyup(function() {
var filtre = $(this).val();
if (filtre) {
$('#users li').each(function() {
if ($(this).text().match(filtre)) {
$(this).show();
} else {
$(this).hide();
}
});
} else {
$('#users li').show();
}
});
$('#agenda-date').datepicker({
dateFormat: "DD d MM yy",
onClose: function(dateText, inst) {
console.log('close');
}
});
$('#agenda-date').on('change', function () {
window.location.href=replace_anchor('../' + $(this).datepicker('getDate').toISOString().substr(0,10), make_anchor());
});
$('.date').datepicker({showOn: 'button'});
$('#add-intervenant-btn').click(function() {
var text = $(this).prev().val();
$('#intervenants ul').append('<li><input type="checkbox" value="' + text + '" checked="checked">' + text + '</input></li>');
$(this).prev().val('').focus();
return false;
});
$('#newrdv').click(function() {
var participants = $('.person-item.active').map(function (i, v) { return $(v).data('worker-id'); });
var qs = $.param({participants: $.makeArray(participants) }, true);
var new_appointment_url = "{% url 'nouveau-rdv' service=service date=date %}?" + qs;
$('#rdv').load(new_appointment_url,
function () {
function onsuccess(response, status, xhr, form) {
var parse = $(response);
if ($('.errorlist', parse).length != 0) {
$('#rdv').html(response);
$('#rdv form').ajaxForm({
success: onsuccess,
});
$('#rdv .datepicker-date').datepicker({dateFormat: 'yy-m-d', showOn: 'button'});
console.log('error');
} else {
console.log('success');
window.location.reload(true);
$('#agenda-date').datepicker({
dateFormat: "DD d MM yy",
onClose: function(dateText, inst) {
console.log('close');
}
}
$('#rdv .datepicker-date').datepicker({dateFormat: 'yy-m-d', showOn: 'button'});
$('form', this).ajaxForm({
success: onsuccess
});
$(this).dialog({title: 'Nouveau rendez-vous',
width: '800px',
buttons: [ { text: "Fermer",
click: function() { $(this).dialog("close"); } },
{ text: "Ajouter",
click: function() { $("#rdv form").submit(); } }]});
});
});
$('#agenda-date').on('change', function () {
window.location.href=replace_anchor('../' + $(this).datepicker('getDate').toISOString().substr(0,10), make_anchor());
});
$('.date').datepicker({showOn: 'button'});
$('#add-intervenant-btn').click(function() {
var text = $(this).prev().val();
$('#intervenants ul').append('<li><input type="checkbox" value="' + text + '" checked="checked">' + text + '</input></li>');
$(this).prev().val('').focus();
return false;
});
$('#newrdv').click(function() {
var participants = $('.person-item.active').map(function (i, v) { return $(v).data('worker-id'); });
var qs = $.param({participants: $.makeArray(participants) }, true);
var new_appointment_url = "{% url 'nouveau-rdv' service=service date=date %}?" + qs;
$('#rdv').load(new_appointment_url,
function () {
function onsuccess(response, status, xhr, form) {
var parse = $(response);
if ($('.errorlist', parse).length != 0) {
$('#rdv').html(response);
$('#rdv form').ajaxForm({
success: onsuccess,
});
$('#rdv .datepicker-date').datepicker({dateFormat: 'yy-m-d', showOn: 'button'});
console.log('error');
} else {
console.log('success');
window.location.reload(true);
}
}
$('#rdv .datepicker-date').datepicker({dateFormat: 'yy-m-d', showOn: 'button'});
$('form', this).ajaxForm({
success: onsuccess
});
$(this).dialog({title: 'Nouveau rendez-vous',
width: '800px',
buttons: [ { text: "Fermer",
click: function() { $(this).dialog("close"); } },
{ text: "Ajouter",
click: function() { $("#rdv form").submit(); } }]});
});
});
});
});
</script>
</script>
<style>
.person-item span { display: none; }
.person-item.active span { display: inline; }
......
{% endif %}
{% if appointment.event_id %}
<button type="button"><img title="Editer un rendez-vous" src="{{ STATIC_URL }}images/accessories-text-editor.png"></button>
<button type="button"  onclick="javascript:delete_appointment({{ appointment.occurrence_id }}, '{{ appointment.title }}')"><img title="Supprimer un rendez-vous" src="{{ STATIC_URL }}images/list-remove.png"></button>
<button data-occurrence-id="{{ appointment.occurrence_id }}" data-rdv="{{ appointment.title }}" type="button" class="remove-appointment">
<img title="Supprimer un rendez-vous" src="{{ STATIC_URL }}images/list-remove.png">
</button>
{% endif %}
</span>
</h3>

Also available in: Unified diff