function lancerPomodoroItem(id) {
    let cur_type=null;
    let modal_header='';
    let modal_body='';
    let modal_footer='';
  
    items.filter(item => item.idlignes == id).forEach(resultat => {
      let flagDisabled='disabled';    
  
      modal_header = getItemDialogHeader(resultat, cur_type);

      modal_body += resultat.client+' > '+getTrigrammeCollaborateur(resultat.intervenant)+' : '+resultat.libelle+'<br>';
      modal_body += '<textarea id="notes" data-aatribute="'+resultat.id+'" ';
      modal_body += 'style="width: 100%;height: 100%;overflow: hidden;border: none;outline: none" placeholder="Saisir vos notes...">';
      modal_body += '</textarea>';
    
      modal_footer += '<div align="left" width="50%" style="float:left;padding-top:2vh">';
      modal_footer += '<button onclick="todo()">Notes</button>';
      modal_footer += '<button onclick="todo()">RIDA</button>';
      modal_footer += '<button onclick="todo()">Documents</button>';
      modal_footer += '<button onclick="todo()">Conversation</button>';
      modal_footer += '</div>';     
      
      modal_footer += '<div align="right" width="50%" style="float:right;padding-top:2vh">';
      modal_footer += '<button onclick="enregistrerNotes('+resultat.idlignes+')">Sauver</button>';
      modal_footer += '<button onclick="arreterPomodoroItem('+resultat.idlignes+')">Fermer</button>';
      modal_footer += '</div>';    
    });
        
    modal_footer += '<div style="clear:both">';
  
    modalSetHeader(modal_header);
    modalSetBody(modal_body);
    modalSetFooter(modal_footer);
    
    lireNotes(id);
}

function arreterPomodoroItem(id) {
    // STOP le chrono

    // enregistrer la saisie en cours
    enregistrerNotes(id);

    // Aficher les infos
    itemInfo(id);
}

function enregistrerNotes(_id){
  let _notes=document.getElementById('notes').value;
  postData("../backend/notes.php", {id: _id, action: 'write', notes: _notes}).then((data) => {
    console.log(data); // JSON data parsed by `data.json()` call
  });
}

function lireNotes(_id){
    postData("../backend/notes.php", {id: _id, action: 'read', notes: ''}).then((data) => {
      document.getElementById('notes').value = data.notes;
    });
}

/*
 * Ajouter la prise en charge de "Ctrl + S" dans la textarea
 */
document.onkeydown = function(e) {
  if (e.ctrlKey && e.key === 's') {
      let notes = document.getElementById('notes');
      if (notes) {
        enregistrerNotes(notes.getAttribute('data-attribute'));
      }
      return false;
  }
};

