Module: RocketCMS::Menu
- Defined in:
- lib/rocket_cms/menu.rb
Class Method Summary collapse
- .btn_js ⇒ Object
- .build_toggles(view, model, obj, btn_size, btn_style = '') ⇒ Object
- .get_menus ⇒ Object
Class Method Details
.btn_js ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rocket_cms/menu.rb', line 14 def btn_js <<-END.strip_heredoc.gsub("\n", ' ').gsub(/ +/, ' ') var $t = $(this); $.ajax({ type: "POST", url: $t.attr("href"), data: {ajax: true}, success: function(r) { $t.attr("href", r.href); $t.removeClass("btn-success btn-danger"); $t.addClass(r.class); }, error: function(e) { alert(e.responseText); } }); return false; END end |
.build_toggles(view, model, obj, btn_size, btn_style = '') ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rocket_cms/menu.rb', line 34 def build_toggles(view, model, obj, btn_size, btn_style = '') ret = [] .each do |m| if RocketCMS.mongoid? on = obj..include?(BSON::ObjectId.from_string(m[:id])) else on = obj..include?(m[:id].to_i) end ret << view.link_to( m[:name], view.(model_name: model, id: obj.id, menu: m[:id], on: !on), #method: :post, title: m[:name], class: "btn btn-#{btn_size} #{on ? "btn-success" : "btn-danger"}", style: btn_style, onclick: btn_js ) end ret end |