class HTabView

Public Class Methods

new(tabs, header = nil) click to toggle source
Calls superclass method HDivTag::new
# File lib/hwidgets/htabview.rb, line 5
def initialize(tabs, header = nil)
  super("tabs")
  @header = header
  @tabs = tabs
  
end
test1() click to toggle source
# File lib/hwidgets/htabview.rb, line 70
def self.test1()

  tabs = { :tab1 => {:tabCaption =>"Tab 1", :tabContain => "Tab1 Contain"},
           :tab2 => {:tabCaption =>"Tab 2", :tabContain => "Tab2 Contain"},
           :tab3 => {:tabCaption =>"Tab 3", :tabContain => "Tab3 Contain", :selected => true},
           :tab4 => {:tabCaption =>"Tab 4", :tabContain => "Tab4 Contain"},
           :tab5 => {:tabCaption =>"Tab 5", :tabContain => "Tab5 Contain"},
           :tab6 => {:tabCaption =>"Tab 6", :tabContain => "Tab6 Contain"},
  }
  return HTabView.new(tabs, "Tabs Controller").html() 

end

Public Instance Methods

checkSelected() click to toggle source
# File lib/hwidgets/htabview.rb, line 28
def checkSelected()

  isSelected = false
  @tabs.each do |key, value|
    if(value.key?(:selected))
      isSelected = true
      break
    end
  end
  @tabs[@tabs.keys[0]][:selected] = true if(!isSelected) and @tabs.any?

end
html() click to toggle source
Calls superclass method HWidget#html
# File lib/hwidgets/htabview.rb, line 41
def html()

  self.checkSelected() 

  ul = HWidget.new("ul").set(class: "nav nav-tabs")
  
  content = ""
  @tabs.each do |key, value|
    tabName = key 
    tabCaption = value[:tabCaption]
    content += self.newTab(tabName, tabCaption, value[:selected] == true)
  end    
  ul.setInnerHTML(content)

  content = HIO.htmlEcholn("<h3>#{@header}</h3>")

  tabContentDiv = HDivTag.new(class: "tab-content")

  @tabs.each do |key, value|
    tabContain = value[:tabContain]
    tabContain = tabContain.html() if(tabContain.class <= HWidget)
    content += self.newContain(key, tabContain, value[:selected] == true)
  end    
  tabContentDiv.setInnerHTML(content)
  self << ul << tabContentDiv
  return super()

end
newContain(tabName, text, selected = false) click to toggle source
# File lib/hwidgets/htabview.rb, line 17
def newContain(tabName, text, selected = false)

  active = "in active" if(selected)

  containerDiv = HDivTag.new(class: "tab-pane fade #{active}")
  containerDiv.set(id: tabName)
  containerDiv.setInnerHTML(text)
  return containerDiv.html()

end
newTab(tabName, tabCaption, selected = false) click to toggle source
# File lib/hwidgets/htabview.rb, line 12
def newTab(tabName, tabCaption, selected = false)
  className = "class='active'" if(selected)
  return HIO.htmlEcholn("<li #{className}><a data-toggle='tab' href='##{tabName}'>#{tabCaption}</a></li>")
end