Class: SuperInteraction::Beyond
- Inherits:
-
Struct
- Object
- Struct
- SuperInteraction::Beyond
- Defined in:
- lib/super_interaction/beyond.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
- #b_alert(class_type, text) ⇒ Object
- #b_danger(message) ⇒ Object
- #b_notice(message) ⇒ Object
- #b_success(message) ⇒ Object
-
#close ⇒ Object
關閉 Modal.
- #cmd(js_code) ⇒ Object
-
#modal(partial: nil, size: 'md', title: '', desc: '', classname: '') ⇒ 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/beyond.rb', line 4 def commands @commands end |
#context ⇒ Object
Returns the value of attribute 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() cmd("alert('#{helpers.j()}');") 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() b_alert('danger', ) self end |
#b_notice(message) ⇒ Object
12 13 14 15 |
# File 'lib/super_interaction/beyond.rb', line 12 def b_notice() b_alert('info', ) self end |
#b_success(message) ⇒ Object
22 23 24 |
# File 'lib/super_interaction/beyond.rb', line 22 def b_success() b_alert('success', ) end |
#close ⇒ Object
關閉 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(partial: nil, size: 'md', title: '', desc: '', classname: '') ⇒ Object
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 |
#modal_saved_rediret_to(message, redirect_url) ⇒ Object
55 56 57 |
# File 'lib/super_interaction/beyond.rb', line 55 def modal_saved_rediret_to(, redirect_url) close.alert().redirect_to(redirect_url) end |
#modal_saved_reload(message) ⇒ Object
59 60 61 |
# File 'lib/super_interaction/beyond.rb', line 59 def modal_saved_reload() close.alert().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 |
#reload ⇒ Object
重新讀取頁面
46 47 48 |
# File 'lib/super_interaction/beyond.rb', line 46 def reload cmd("Turbolinks.visit(location.toString());"); end |
#run ⇒ Object
8 9 10 |
# File 'lib/super_interaction/beyond.rb', line 8 def run context.render js: (commands || []).join(";"), layout: false end |