You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

57 line
1.3 KiB

  1. frappe.provide('frappe.ui');
  2. frappe.ui.Sidebar = class Sidebar {
  3. constructor({ wrapper, css_class }) {
  4. this.wrapper = wrapper;
  5. this.css_class = css_class;
  6. this.make_dom();
  7. }
  8. make_dom() {
  9. this.wrapper.html(`
  10. <div class="${this.css_class} overlay-sidebar hidden-xs hidden-sm">
  11. </div>
  12. `);
  13. this.$sidebar = this.wrapper.find(this.css_class);
  14. }
  15. add_item(item, section) {
  16. let $section;
  17. if(!section && this.wrapper.find('.sidebar-menu').length === 0) {
  18. // if no section, add section with no heading
  19. $section = this.get_section();
  20. } else {
  21. $section = this.get_section(section);
  22. }
  23. const $li_item = $(`
  24. <li><a ${item.href ? `href="${item.href}"` : ''}>${item.label}</a></li>
  25. `).click(
  26. () => item.on_click && item.on_click()
  27. );
  28. $section.append($li_item);
  29. }
  30. get_section(section_heading="") {
  31. let $section = $(this.wrapper.find(
  32. `[data-section-heading="${section_heading}"]`));
  33. if($section.length) {
  34. return $section;
  35. }
  36. const $section_heading = section_heading ?
  37. `<li class="h6">${section_heading}</li>` : '';
  38. $section = $(`
  39. <ul class="list-unstyled sidebar-menu" data-section-heading="${section_heading || 'default'}">
  40. ${$section_heading}
  41. </ul>
  42. `);
  43. this.$sidebar.append($section);
  44. return $section;
  45. }
  46. };