component.js 1006 B

1234567891011121314151617181920212223242526272829303132
  1. {"label":"Component JS","syntax":"js"}
  2. function init_components_{{entity}}(input){
  3. var data = {};
  4. input.component_autocomplete('{{entity}}',$.extend(data,{
  5. skin : function(item){
  6. var html = '';
  7. var re = new RegExp(input.val(),"gi");
  8. label = item.label.replace(re, function (x) {
  9. return '<strong>'+x+'</strong>';
  10. });
  11. html += '<div class="media">';
  12. if(item.logo) html += '';
  13. html += '<div class="my-auto media-body {{entity}}-autocomplete {{entity}}-infos"><small class="d-flex flex-column">'
  14. html+='<span>'+label+'</span>';
  15. html += '</small></div></div>'
  16. return html;
  17. },
  18. onClick : function(selected,element){
  19. container = input.data("data-component");
  20. input.val(selected.id);
  21. var label = selected.label;
  22. if(selected.parentLabel) label+=' ('+selected.parentLabel+')';
  23. container.val(label);
  24. input.trigger('click').trigger('change');
  25. },
  26. onLoad : function(component,item){
  27. var label = item.label;
  28. component.container.val(label);
  29. }
  30. }));
  31. }