Class: HAccordionMenu
- Defined in:
- lib/hwidgets/haccordionmenu.rb
Instance Attribute Summary collapse
-
#mainView ⇒ Object
readonly
Returns the value of attribute mainView.
Attributes inherited from HWidget
Class Method Summary collapse
- .appendChild1(parent, root = []) ⇒ Object
- .loadMenuByModuleName(moduleName: nil, mainView: nil) ⇒ Object
- .test1 ⇒ Object
Instance Method Summary collapse
- #a(innerHTML = '', icon: nil, **args) ⇒ Object
- #addItem(value) ⇒ Object
- #appendChildren(parent, items) ⇒ Object
- #html ⇒ Object
-
#initialize(items: [], id: nil, mainView: nil) ⇒ HAccordionMenu
constructor
A new instance of HAccordionMenu.
- #onClick(moduleName: nil, modelName: nil) ⇒ Object
Methods inherited from HWidget
#_addJsSlot, #_set, #_setStyle, #addJsFunction, #appendChild, #appendChilds, #buildSignature, #closeTag, #connect, #copyConstructor, #get, #getChilds, #getElementBy, #getSystemProperty, #hotLog, #openTag, #replacePlaceholder, #reset, #set, #setChilds, #setCloseTag, #setClosedTag, #setEnablePlaceholder, #setInnerHTML, #setParent, #setPlaceholder, #setPlaceholders, #setProperties, #setSlots, #setStyle, #setStyles, #setSystemProperties, #setSystemProperty, #setTag, #storeSlots, #storeStyle, #strProperties, test, #unset, widgetSpace
Constructor Details
#initialize(items: [], id: nil, mainView: nil) ⇒ HAccordionMenu
Returns a new instance of HAccordionMenu.
5 6 7 8 9 10 11 |
# File 'lib/hwidgets/haccordionmenu.rb', line 5 def initialize(items: [], id: nil, mainView: nil) super(class: "haccordion-menu") self.set(id: id) if id #self.appendChild(HWidget.new("style", "##{id}:target { display: block; }", scoped: nil)); @items = items @mainView = mainView end |
Instance Attribute Details
#mainView ⇒ Object (readonly)
Returns the value of attribute mainView.
3 4 5 |
# File 'lib/hwidgets/haccordionmenu.rb', line 3 def mainView @mainView end |
Class Method Details
.appendChild1(parent, root = []) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/hwidgets/haccordionmenu.rb', line 94 def self.appendChild1(parent, root = []) parent.children.each do |item| next if item.name == "text" = item.to_h.symbolize_keys if item.name == "menusection" [:type] = "section" unless [:type] [:content] = self.appendChild1(item) elsif item.name == "menuitem" [:type] = "link" end root << end return root end |
.loadMenuByModuleName(moduleName: nil, mainView: nil) ⇒ Object
110 111 112 113 114 |
# File 'lib/hwidgets/haccordionmenu.rb', line 110 def self.loadMenuByModuleName(moduleName: nil, mainView: nil) = hv().viewByFileName(moduleName, "app/modules/#{moduleName}/menu_view.xml") items = self.appendChild1(.hypersonic) return HAccordionMenu.new(items: items, id: moduleName, mainView: mainView).html() end |
.test1 ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/hwidgets/haccordionmenu.rb', line 56 def self.test1() subSection = [ {type: 'section', name: 'Section-A', content:[ {type: 'link', name: 'Section-a1', href:'#'}, {type: 'link', name: 'Section-a2', href:'#'}, {type: 'link', name: 'Section-a3', href:'#'} ] }, {type: 'section', name: 'Section-B', content:[ {type: 'link', name: 'Section-b1', href:'#'}, {type: 'link', name: 'Section-b2', href:'#'}, {type: 'link', name: 'Section-b3', href:'#'} ] }, ] openSection = [{type: 'link', name: 'O-Section1', href:'#', icon: 'glyphicon glyphicon-user'}, {type: 'link', name: 'O-Section2', href:'#'}, {type: 'link', name: 'O-Section3', href:'#'} ] items = [ {type: 'section', name: 'Section-A', content:[ {type: 'link', name: 'Section-a1', href:'#'}, {type: 'link', name: 'Section-a2', href:'#'}, {type: 'link', name: 'Section-a3', href:'#'} ] }, {type: 'section', name: 'Section-B', content: subSection}, {type: 'open-section', name: 'Open Section', content: openSection}, ] return HAccordionMenu.new(items).html() end |
Instance Method Details
#a(innerHTML = '', icon: nil, **args) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/hwidgets/haccordionmenu.rb', line 18 def a(innerHTML = '', icon: nil, **args) a = HWidget.new("a", "", args) a << HWidget.new('span', class: icon) if icon a << HWidget.new('span', innerHTML) return a end |
#addItem(value) ⇒ Object
13 14 15 16 |
# File 'lib/hwidgets/haccordionmenu.rb', line 13 def addItem(value) @items << value return self end |
#appendChildren(parent, items) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/hwidgets/haccordionmenu.rb', line 33 def appendChildren(parent, items) items.each do |value| if(value[:type] == 'link') ref = eval(value[:ref]) if value[:ref] parent << link = (self.a(value[:name], icon: value[:icon])) link.connect(:onclick, self, "onClick", id: @mainView.oid, args: ref) elsif(value[:type].include? 'section' ) parent.appendChild( HDivTag.new(value[:name], class: "#{value[:type]}-name") ) sectionContentDiv = HDivTag.new(class: "#{value[:type]}-content") parent.appendChild(sectionContentDiv) self.appendChildren(sectionContentDiv, value[:content]) end end end |
#html ⇒ Object
51 52 53 54 |
# File 'lib/hwidgets/haccordionmenu.rb', line 51 def html() self.appendChildren(self, @items) return super end |
#onClick(moduleName: nil, modelName: nil) ⇒ Object
27 28 29 30 |
# File 'lib/hwidgets/haccordionmenu.rb', line 27 def onClick(moduleName: nil, modelName: nil) hl << "HAccordionMenu.onClick (#{moduleName} - #{modelName})".red return @mainView.html(moduleName: moduleName, modelName: modelName) end |