Class: SuperInteraction::Command
- Inherits:
-
Struct
- Object
- Struct
- SuperInteraction::Command
- Defined in:
- lib/super_interaction/command.rb
Instance Attribute Summary collapse
-
#commands ⇒ Object
Returns the value of attribute commands.
-
#context ⇒ Object
Returns the value of attribute context.
Instance Method Summary collapse
- #ajax_get(url) ⇒ Object
- #alert(message) ⇒ Object
- #bs_alert(class_type, text) ⇒ Object
- #bs_danger(message) ⇒ Object
- #bs_notice(message) ⇒ Object
- #bs_success(message) ⇒ Object
-
#close ⇒ Object
關閉 Modal.
- #cmd(js_code) ⇒ Object
-
#modal(partial: nil, size: 'md', title: '', desc: '') ⇒ Object
modal 裡如果有 javascript 需寫在 .modal 層 size: sm / md / lg / xl / xxl 注意:不要包 respond_to :js 會有問題.
- #modal_saved_rediret_to(message, redirect_url) ⇒ Object
- #modal_saved_reload(message) ⇒ Object
-
#redirect_to(url) ⇒ Object
導入頁面.
-
#reload ⇒ Object
重新讀取頁面.
- #run ⇒ Object
Instance Attribute Details
#commands ⇒ Object
Returns the value of attribute commands.
4 5 6 |
# File 'lib/super_interaction/command.rb', line 4 def commands @commands end |
#context ⇒ Object
Returns the value of attribute context
2 3 4 |
# File 'lib/super_interaction/command.rb', line 2 def context @context end |
Instance Method Details
#ajax_get(url) ⇒ Object
62 63 64 |
# File 'lib/super_interaction/command.rb', line 62 def ajax_get(url) cmd("$.get('#{url}');") end |
#alert(message) ⇒ Object
26 27 28 |
# File 'lib/super_interaction/command.rb', line 26 def alert() cmd("alert('#{helpers.j()}');") end |
#bs_alert(class_type, text) ⇒ Object
66 67 68 |
# File 'lib/super_interaction/command.rb', line 66 def bs_alert(class_type, text) cmd("if (typeof($.alert) == undefined) { alert('#{helpers.j(text)}'); } else { $.alert.#{class_type}('#{helpers.j(text)}'); }") end |
#bs_danger(message) ⇒ Object
17 18 19 20 |
# File 'lib/super_interaction/command.rb', line 17 def bs_danger() bs_alert('danger', ) self end |
#bs_notice(message) ⇒ Object
12 13 14 15 |
# File 'lib/super_interaction/command.rb', line 12 def bs_notice() bs_alert('info', ) self end |
#bs_success(message) ⇒ Object
22 23 24 |
# File 'lib/super_interaction/command.rb', line 22 def bs_success() bs_alert('success', ) end |
#close ⇒ Object
關閉 Modal
40 41 42 |
# File 'lib/super_interaction/command.rb', line 40 def close cmd("$.modal.close();") end |
#cmd(js_code) ⇒ Object
70 71 72 73 74 |
# File 'lib/super_interaction/command.rb', line 70 def cmd(js_code) self.commands ||= [] self.commands.push(js_code) self end |
#modal(partial: nil, size: 'md', title: '', desc: '') ⇒ Object
modal 裡如果有 javascript 需寫在 .modal 層 size: sm / md / lg / xl / xxl 注意:不要包 respond_to :js 會有問題
33 34 35 36 37 |
# File 'lib/super_interaction/command.rb', line 33 def modal(partial: nil, size: 'md', title: '', desc: '') partial ||= context.action_name modal_html = context.render_to_string(partial, layout: 'modal.html.haml', locals: { bs_modal_size: size, title: title, desc: desc }) cmd("$(function() { $.modal.show('#{helpers.j(modal_html)}'); });") end |
#modal_saved_rediret_to(message, redirect_url) ⇒ Object
54 55 56 |
# File 'lib/super_interaction/command.rb', line 54 def modal_saved_rediret_to(, redirect_url) close.alert().redirect_to(redirect_url) end |
#modal_saved_reload(message) ⇒ Object
58 59 60 |
# File 'lib/super_interaction/command.rb', line 58 def modal_saved_reload() close.alert().reload end |
#redirect_to(url) ⇒ Object
導入頁面
50 51 52 |
# File 'lib/super_interaction/command.rb', line 50 def redirect_to(url) cmd("Turbolinks.visit('#{url}');"); end |
#reload ⇒ Object
重新讀取頁面
45 46 47 |
# File 'lib/super_interaction/command.rb', line 45 def reload cmd("Turbolinks.visit(location.toString());"); end |
#run ⇒ Object
8 9 10 |
# File 'lib/super_interaction/command.rb', line 8 def run context.render js: (commands || []).join(";") end |