Class: SuperInteraction::Beyond

Inherits:
Struct
  • Object
show all
Defined in:
lib/super_interaction/beyond.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#commandsObject

Returns the value of attribute commands.



4
5
6
# File 'lib/super_interaction/beyond.rb', line 4

def commands
  @commands
end

#contextObject

Returns the value of attribute context

Returns:

  • (Object)

    the current value of context



2
3
4
# File 'lib/super_interaction/beyond.rb', line 2

def context
  @context
end

Instance Method Details

#ajax_get(url) ⇒ Object



63
64
65
# File 'lib/super_interaction/beyond.rb', line 63

def ajax_get(url)
  cmd("$.get('#{url}');")
end

#alert(message) ⇒ Object



26
27
28
# File 'lib/super_interaction/beyond.rb', line 26

def alert(message)
  cmd("alert('#{helpers.j(message)}');")
end

#b_alert(class_type, text) ⇒ Object



67
68
69
# File 'lib/super_interaction/beyond.rb', line 67

def b_alert(class_type, text)
  cmd("if (typeof($.alert) === 'undefined') { alert('#{helpers.j(text)}'); } else { $.alert.#{class_type}('#{helpers.j(text)}'); }")
end

#b_danger(message) ⇒ Object



17
18
19
20
# File 'lib/super_interaction/beyond.rb', line 17

def b_danger(message)
  b_alert('danger', message)
  self
end

#b_notice(message) ⇒ Object



12
13
14
15
# File 'lib/super_interaction/beyond.rb', line 12

def b_notice(message)
  b_alert('info', message)
  self
end

#b_success(message) ⇒ Object



22
23
24
# File 'lib/super_interaction/beyond.rb', line 22

def b_success(message)
  b_alert('success', message)
end

#closeObject

關閉 Modal



41
42
43
# File 'lib/super_interaction/beyond.rb', line 41

def close
  cmd("$.uniqModal().modal('hide');")
end

#cmd(js_code) ⇒ Object



71
72
73
74
75
# File 'lib/super_interaction/beyond.rb', line 71

def cmd(js_code)
  self.commands ||= []
  self.commands.push(js_code)
  self
end

modal 裡如果有 javascript 需寫在 .modal 層size: sm / md / lg / xl / xxl 注意:不要包 respond_to :js 會有問題



33
34
35
36
37
38
# File 'lib/super_interaction/beyond.rb', line 33

def modal(partial: nil, size: 'md', title: '', desc: '', classname: '')
  partial ||= context.action_name
  locals = { size: size, title: title, desc: desc, classname: classname }
  modal_html = context.render_to_string(partial, layout: "beyond.haml", locals: locals)
  cmd("$(function() { $.uniqModal().modal('show', '#{helpers.j(modal_html)}'); });")
end


55
56
57
# File 'lib/super_interaction/beyond.rb', line 55

def modal_saved_rediret_to(message, redirect_url)
  close.alert(message).redirect_to(redirect_url)
end


59
60
61
# File 'lib/super_interaction/beyond.rb', line 59

def modal_saved_reload(message)
  close.alert(message).reload
end

#redirect_to(url) ⇒ Object

導入頁面



51
52
53
# File 'lib/super_interaction/beyond.rb', line 51

def redirect_to(url)
  cmd("Turbolinks.visit('#{url}');");
end

#reloadObject

重新讀取頁面



46
47
48
# File 'lib/super_interaction/beyond.rb', line 46

def reload
  cmd("Turbolinks.visit(location.toString());");
end

#runObject



8
9
10
# File 'lib/super_interaction/beyond.rb', line 8

def run
  context.render js: (commands || []).join(";"), layout: false
end