Sha256: dc4e438671b14a0129e713460f2470a713635b51400bf1bdf05a7d37e3a516ba
Contents?: true
Size: 1.35 KB
Versions: 4
Compression:
Stored size: 1.35 KB
Contents
# encoding: utf-8 class MenuItemsController < ActionController::Base include Lolita::Controllers::UserHelpers before_filter :authenticate_lolita_user! def autocomplete_menu_item_url urls = Lolita::Menu::Autocomplete::Collector.new(params[:term]) render :json => urls.to_json end 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