Top Level Namespace

Defined Under Namespace

Modules: Breeze

Instance Method Summary collapse

Instance Method Details

#buttonObject



11
12
13
# File 'app/assets/javascript/breeze_application.js.rb', line 11

def button
  Element.find("#hidden_button")
end

#get_data(type, id) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/assets/javascript/breeze_application.js.rb', line 44

def get_data(type , id )
  $$.sections.each do |section|
    if type == "Section"
      return section if section['id'] == id
    else
      section[:cards].each do | card_data |
        return card_data if card_data['id'] == id
      end
    end
  end
  raise "No data found for #{type}_#{id}"
end

#init_sectionObject



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'app/assets/javascript/breeze_application.js.rb', line 87

def init_section()
  $$.sections.each do |section_data|
    set_click("Section" , section_data )
    section_data[:cards].each do | card_data |
      set_click( "Card" , card_data)
    end
  end
  button.on(:click) do |event|
    b = event.target
    send_data(b.data("id") , b.data("type"))
  end
  Document.on(:keydown) do |event|
    switch_overlay("none") if (event[:key] == "Escape")
  end
end

#reset_html(type, id, header, text) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'app/assets/javascript/breeze_application.js.rb', line 57

def reset_html( type , id , header , text )
  target_id = "##{type}_#{id}"
  data = get_data(type , id )
  data[:header] = header
  data[:text] = text
  target = Element.find(target_id)
  target.find(".#{type.downcase}_header").html( header)
  target.find(".#{type.downcase}_text").html( $$.marked.parse(text) )
  puts "setting #{type} header: #{header}"
end

#send_data(id, type) ⇒ Object



77
78
79
80
81
82
83
84
85
# File 'app/assets/javascript/breeze_application.js.rb', line 77

def send_data( id , type)
  text_elem = Element.find("#text")
  head = text_elem.find(".header").value
  text = text_elem.find(".textarea").val
  puts "ID #{id}:#{type}"
  reset_html( type , id , head , text)
  server_put( type , id , head , text)
  switch_overlay("none")
end

#server_put(type, id, header, text) ⇒ Object



68
69
70
71
72
73
74
75
# File 'app/assets/javascript/breeze_application.js.rb', line 68

def server_put(type , id , header , text)
  data = {authenticity_token: $$.authenticity_token }
  data[:header] = header
  data[:text] = text
  HTTP.patch("/breeze/#{type.downcase}s/#{id}.json" , payload: data ) do |res|
    alert "Saving failed, please reload page" unless res.ok?
  end
end

#set_button_data(id, type) ⇒ Object



22
23
24
25
26
# File 'app/assets/javascript/breeze_application.js.rb', line 22

def set_button_data( id , type)
  b = button
  b.data("id" , id)
  b.data("type" , type)
end

#set_click(clazz, target_data) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/assets/javascript/breeze_application.js.rb', line 28

def set_click(clazz , target_data )
  id = target_data['id']
  target = Element.find("##{clazz}_#{id}")
  text = Element.find("#text")
  ['text' , 'header'].each do |kind|
    element = target.find(".#{clazz.downcase}_#{kind}")
    element.on(:click) do |event|
      set_position(element , text)
      set_button_data( id , clazz)
      switch_overlay( "block")
      text.find(".header").value = target_data[:header]
      text.find(".textarea").val( target_data[:text] )
    end
  end
end

#set_position(section, text) ⇒ Object



14
15
16
17
18
19
20
# File 'app/assets/javascript/breeze_application.js.rb', line 14

def set_position(section , text)
  left = section.offset.left * 0.6
  top = section.offset.top - Document.scroll_top
  #puts "top #{top}"
  text.css(:left , "#{left}px")
  text.css(:top , "#{top}px")
end

#switch_overlay(vis) ⇒ Object



6
7
8
9
10
# File 'app/assets/javascript/breeze_application.js.rb', line 6

def switch_overlay(vis)
  overlay = Element.find("#overlay")
  overlay.css(:display ,vis)
  overlay
end