Sha256: b0f0b0007c0025adf221b88f09d91a34ec59ab749b68a236295978a1e9a458b6

Contents?: true

Size: 1.21 KB

Versions: 4

Compression:

Stored size: 1.21 KB

Contents

# encoding: utf-8
class MenuItemsController < ActionController::Base
  include Lolita::Controllers::UserHelpers

  before_filter :authenticate_lolita_user!

  def create
    menu=Menu.find_by_id(params[:menu_id])
    item=MenuItem.create!(:name=>"new item",:url=>"/",:menu_id => params[:menu_id])
    menu.append(item)
    response.headers["Lolita-Notice"] = I18n.t("lolita.menu.branch created")
    render_component "lolita/menu_items", :row, :item => item, :menu => menu
  end

  def update
    if item=MenuItem.find_by_id(params[:id])
      item.send(:"#{params[:attribute]}=",params[:value])
      item.save
      render :json=>{:status=>item.errors.any? ? "error" : "saved"}
    else
      render :json=>{:status=>"error"}
    end
  end

  def update_tree
    menu=Menu.find_by_id(params[:menu_id])

    if menu && menu.update_whole_tree(params[:items])
      response.headers["Lolita-Notice"] = I18n.t("lolita.menu.notice")
    else
      response.headers["Lolita-Error"] = I18n.t("lolita.menu.error")
    end

    render :nothing=>true
  end

  def destroy
    item=MenuItem.find_by_id(params[:id])
    item.destroy
    response.headers["Lolita-Notice"] = I18n.t("lolita.menu.branch deleted")
    render :json=>{:id=>item.id}
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lolita-menu-0.0.11 app/controllers/menu_items_controller.rb
lolita-menu-0.0.10 app/controllers/menu_items_controller.rb
lolita-menu-0.0.9 app/controllers/menu_items_controller.rb
lolita-menu-0.0.8 app/controllers/menu_items_controller.rb