Remove snippet
This commit is contained in:
parent
f3f405c1b4
commit
962bf03af2
|
@ -1,52 +0,0 @@
|
||||||
class Admin::SnippetsController < ApplicationController
|
|
||||||
|
|
||||||
layout "admin"
|
|
||||||
before_filter :authenticate_user!
|
|
||||||
before_filter :find_parent_item
|
|
||||||
before_filter :is_admin?
|
|
||||||
|
|
||||||
#Snippet is a object admin user can define his own tag and being used later on in parser
|
|
||||||
|
|
||||||
def show
|
|
||||||
#TODO
|
|
||||||
end
|
|
||||||
|
|
||||||
def new
|
|
||||||
@snippet = Snippet.new
|
|
||||||
@snippet.parent_id = @parent_item.id
|
|
||||||
end
|
|
||||||
|
|
||||||
def edit
|
|
||||||
@snippet = Snippet.find(params[:id])
|
|
||||||
end
|
|
||||||
|
|
||||||
def create
|
|
||||||
@snippet = Snippet.new(params[:snippet])
|
|
||||||
|
|
||||||
if @snippet.save
|
|
||||||
flash[:notice] = t('admin.create_success_snippet')
|
|
||||||
redirect_to admin_items_url( :parent_id => @snippet.parent_id )
|
|
||||||
else
|
|
||||||
render :action => "new"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def update
|
|
||||||
@snippet = Snippet.find(params[:id])
|
|
||||||
|
|
||||||
if @snippet.update_attributes(params[:snippet])
|
|
||||||
flash[:notice] = t('admin.update_success_snippet')
|
|
||||||
redirect_to admin_items_url( :parent_id => @snippet.parent_id )
|
|
||||||
else
|
|
||||||
render :action => "edit"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def destroy
|
|
||||||
@snippet = Snippet.find(params[:id])
|
|
||||||
@snippet.destroy
|
|
||||||
|
|
||||||
redirect_to admin_items_url( :parent_id => @snippet.parent_id )
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
|
@ -1,38 +0,0 @@
|
||||||
class Snippet
|
|
||||||
|
|
||||||
include Mongoid::Document
|
|
||||||
include Mongoid::Timestamps
|
|
||||||
|
|
||||||
field :name, :index => true
|
|
||||||
field :full_name, :index => true
|
|
||||||
|
|
||||||
field :parent_id, :index => true
|
|
||||||
field :parent_name
|
|
||||||
|
|
||||||
field :content
|
|
||||||
|
|
||||||
before_validation :setup_default_value
|
|
||||||
validates_presence_of :name, :full_name, :parent_id
|
|
||||||
validates_uniqueness_of :name, :scope => :parent_id
|
|
||||||
|
|
||||||
referenced_in :parent, :class_name => "Item", :foreign_key => :parent_id
|
|
||||||
|
|
||||||
# Get an array of ancestors
|
|
||||||
def ancestors
|
|
||||||
node, nodes = self, []
|
|
||||||
nodes << node = node.parent while !node.parent.blank? rescue nil
|
|
||||||
nodes.reverse
|
|
||||||
end
|
|
||||||
|
|
||||||
def setup_default_value
|
|
||||||
# Set the parent value
|
|
||||||
self.parent_name = Item.find( self.parent_id ).name rescue nil
|
|
||||||
|
|
||||||
# Build the full_name from the ancestors array
|
|
||||||
full_node = self.ancestors.map{ |a| a.name }.push( self.name )
|
|
||||||
# Remove root node if not root
|
|
||||||
full_node.shift if full_node.size >= 2
|
|
||||||
self.full_name = full_node.join("/")
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
|
@ -1,11 +0,0 @@
|
||||||
<%= f.hidden_field :parent_id %>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<%= f.label :name, t('admin.name') %>
|
|
||||||
<%= f.text_field :name, :class => 'text' %>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<%= f.label "content", t('admin.content') %>
|
|
||||||
<%= f.text_area "content", :size => '100x30' %>
|
|
||||||
</p>
|
|
|
@ -1,11 +0,0 @@
|
||||||
<h1><%= t('admin.editing_snippet') %></h1>
|
|
||||||
|
|
||||||
<%= form_for @snippet, :url => admin_snippet_path(@snippet) do |f| %>
|
|
||||||
<%= f.error_messages %>
|
|
||||||
|
|
||||||
<%= render :partial => "form", :locals => { :f => f } %>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<%= f.submit 'Update' %> <%= link_back %>
|
|
||||||
</p>
|
|
||||||
<% end %>
|
|
|
@ -1,11 +0,0 @@
|
||||||
<h1><%= t('admin.new_snippet') %></h1>
|
|
||||||
|
|
||||||
<% form_for :snippet, :url => admin_snippets_path do |f| %>
|
|
||||||
<%= f.error_messages %>
|
|
||||||
|
|
||||||
<%= render :partial => "form", :locals => { :f => f } %>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<%= f.submit t('create') %> <%= link_back %>
|
|
||||||
</p>
|
|
||||||
<% end %>
|
|
Loading…
Reference in New Issue