component.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. Pour un client :
  3. <input type="text" data-type="client" class="form-control" id="my_client">
  4. Pour un contact lié au client #7
  5. <input type="text" data-type="contact" data-scope="client" data-uid="7" class="form-control" id="my_contact">
  6. */
  7. function init_components_client(input){
  8. var data = {
  9. editData: function(){
  10. return {before : input.attr('data-before')}
  11. },
  12. data: function(){
  13. return {
  14. before: input.attr('data-before'),
  15. firm: input.attr('data-firm'),
  16. parent: input.attr('data-parent')
  17. }
  18. }
  19. };
  20. input.component_autocomplete('client',$.extend(data,{
  21. skin: function(item){
  22. var html = '';
  23. var re = new RegExp(input.val(),"gi");
  24. label = item.label.replace(re, function (x) {
  25. return '<strong>'+x+'</strong>';
  26. });
  27. html += '<div class="media">';
  28. if(item.logo) html += '<img src="'+item.logo+'" class="avatar-mini avatar-rounded align-self-center mr-2" alt="Logo client">';
  29. html += '<div class="my-auto media-body client-autocomplete user-infos"><small class="d-flex flex-column">'
  30. if(item.parentLabel) html+='<small class="text-muted">'+item.parentLabel+'</small>' ;
  31. html+='<span>'+label ;
  32. if(input.attr('data-extra') && input.attr('data-extra').split(',').indexOf('id')!=-1) html += '<small> #' + item.id+'</small>';
  33. html +='</span>';
  34. html += '</small></div>'
  35. html += '</div>'
  36. return html;
  37. },
  38. onClick: function(selected,element){
  39. container = input.data("data-component");
  40. input.val(selected.id);
  41. var label = selected.label;
  42. if(selected.parentLabel) label +=' ('+selected.parentLabel+')';
  43. container.val(label);
  44. input.trigger('click').trigger('change');
  45. },
  46. onLoad: function(component,item){
  47. var label = item.label;
  48. if(item.parent) label+=' ('+item.parent.label+')';
  49. component.container.val(label);
  50. }
  51. }));
  52. }