Class: HTabView

Inherits:
HDivTag show all
Defined in:
lib/hwidgets/htabview.rb

Instance Attribute Summary

Attributes inherited from HWidget

#tag

Class Method Summary collapse

Instance Method Summary collapse

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(tabs, header = nil) ⇒ HTabView

Returns a new instance of HTabView.



5
6
7
8
9
10
# File 'lib/hwidgets/htabview.rb', line 5

def initialize(tabs, header = nil)
  super("tabs")
  @header = header
  @tabs = tabs
  
end

Class Method Details

.test1Object



70
71
72
73
74
75
76
77
78
79
80
81
# 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

Instance Method Details

#checkSelectedObject



28
29
30
31
32
33
34
35
36
37
38
39
# 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

#htmlObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# 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) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# 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) ⇒ Object



12
13
14
15
# 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