added ability to delete items
This commit is contained in:
parent
26c4e9cffc
commit
7d45a83776
6 changed files with 122 additions and 97 deletions
|
@ -1,3 +1,3 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
||||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
|
@ -28,7 +28,7 @@ h2 {display:block; text-align:center; background: #333; font-size:24px;}
|
|||
a {color:#2d6a5d; text-decoration:none;}
|
||||
.clearfloat {clear:both;}
|
||||
|
||||
form { display: block; width: 350px; margin: 0 auto; background: #D1D1D1; padding: 20px; border-radius: 15px; color: #000; }
|
||||
.new_session, .new_item, .new_synapse, .edit_item, .edit_synapse { display: block; width: 350px; margin: 0 auto; background: #D1D1D1; padding: 20px; border-radius: 15px; color: #000; }
|
||||
|
||||
label, select, input, textarea { display:block; }
|
||||
|
||||
|
|
|
@ -4,6 +4,19 @@
|
|||
|
||||
.item { display:block; float:left; position:relative; width:170px; height:300px; padding:10px 10px 10px 35px; background:#d1d1d1; border-radius:15px; margin:30px 0 30px 50px; color:#000; }
|
||||
|
||||
.item .delete {position: absolute;
|
||||
top: -14px;
|
||||
left: 0px;
|
||||
background: none;
|
||||
border: 0;
|
||||
color: white;
|
||||
border: none;
|
||||
font-size: 14px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
cursor:pointer;
|
||||
}
|
||||
|
||||
.item .type {position: absolute;
|
||||
color: white;
|
||||
top: -22px;
|
||||
|
|
|
@ -1,87 +1,97 @@
|
|||
class ItemsController < ApplicationController
|
||||
|
||||
before_filter :require_user, only: [:new, :create, :edit, :update]
|
||||
|
||||
respond_to :html, :js, :json
|
||||
|
||||
# GET /items
|
||||
def index
|
||||
@user = current_user
|
||||
@items = Item.all
|
||||
|
||||
respond_with(@items)
|
||||
end
|
||||
|
||||
# Get /item/new
|
||||
def new
|
||||
@item = Item.new
|
||||
@user = current_user
|
||||
|
||||
respond_with(@item)
|
||||
end
|
||||
|
||||
# GET /item/:id
|
||||
def show
|
||||
@item = Item.find(params[:id])
|
||||
|
||||
@relatives = @item.as_json.html_safe
|
||||
|
||||
respond_to do |format|
|
||||
format.html { respond_with(@item) }
|
||||
format.json { respond_with(@relatives) }
|
||||
end
|
||||
end
|
||||
|
||||
# POST /items
|
||||
def create
|
||||
|
||||
@user = current_user
|
||||
@item = Item.new()
|
||||
@item.name = params[:item][:name]
|
||||
@item.desc = params[:item][:desc]
|
||||
@item.link = params[:item][:link]
|
||||
@item.item_category = ItemCategory.find(params[:category])
|
||||
@item.user = @user
|
||||
|
||||
@item.save
|
||||
|
||||
respond_to do |format|
|
||||
format.html { respond_with(@user, location: item_url(@item)) }
|
||||
format.js { respond_with(@item) }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# GET /items/:id/edit
|
||||
def edit
|
||||
@item = Item.find_by_id(params[:id])
|
||||
|
||||
respond_with(@item)
|
||||
end
|
||||
|
||||
# PUT /actions/:id
|
||||
def update
|
||||
@item = Item.find_by_id(params[:id])
|
||||
|
||||
if @item
|
||||
@item.name = params[:item][:name]
|
||||
@item.desc = params[:item][:desc]
|
||||
@item.link = params[:item][:link]
|
||||
@item.item_category = ItemCategory.find(params[:category][:item_category_id])
|
||||
|
||||
@item.save
|
||||
end
|
||||
|
||||
respond_with(@user, location: item_url(@item)) do |format|
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# DELETE /items/:id
|
||||
def destroy
|
||||
@item = Item.find_by_id(params[:id])
|
||||
|
||||
@item.delete
|
||||
end
|
||||
|
||||
end
|
||||
class ItemsController < ApplicationController
|
||||
|
||||
before_filter :require_user, only: [:new, :create, :edit, :update]
|
||||
|
||||
respond_to :html, :js, :json
|
||||
|
||||
# GET /items
|
||||
def index
|
||||
@user = current_user
|
||||
@items = Item.all
|
||||
|
||||
respond_with(@items)
|
||||
end
|
||||
|
||||
# Get /item/new
|
||||
def new
|
||||
@item = Item.new
|
||||
@user = current_user
|
||||
|
||||
respond_with(@item)
|
||||
end
|
||||
|
||||
# GET /item/:id
|
||||
def show
|
||||
@item = Item.find(params[:id])
|
||||
|
||||
@relatives = @item.as_json.html_safe
|
||||
|
||||
respond_to do |format|
|
||||
format.html { respond_with(@item) }
|
||||
format.json { respond_with(@relatives) }
|
||||
end
|
||||
end
|
||||
|
||||
# POST /items
|
||||
def create
|
||||
|
||||
@user = current_user
|
||||
@item = Item.new()
|
||||
@item.name = params[:item][:name]
|
||||
@item.desc = params[:item][:desc]
|
||||
@item.link = params[:item][:link]
|
||||
@item.item_category = ItemCategory.find(params[:category])
|
||||
@item.user = @user
|
||||
|
||||
@item.save
|
||||
|
||||
respond_to do |format|
|
||||
format.html { respond_with(@user, location: item_url(@item)) }
|
||||
format.js { respond_with(@item) }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# GET /items/:id/edit
|
||||
def edit
|
||||
@item = Item.find_by_id(params[:id])
|
||||
|
||||
respond_with(@item)
|
||||
end
|
||||
|
||||
# PUT /actions/:id
|
||||
def update
|
||||
@item = Item.find_by_id(params[:id])
|
||||
|
||||
if @item
|
||||
@item.name = params[:item][:name]
|
||||
@item.desc = params[:item][:desc]
|
||||
@item.link = params[:item][:link]
|
||||
@item.item_category = ItemCategory.find(params[:category][:item_category_id])
|
||||
|
||||
@item.save
|
||||
end
|
||||
|
||||
respond_with(@user, location: item_url(@item)) do |format|
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# DELETE /items/:id
|
||||
def destroy
|
||||
@item = Item.find_by_id(params[:id])
|
||||
|
||||
@synapses = @item.synapses
|
||||
|
||||
@synapses.each do |synapse|
|
||||
synapse.delete
|
||||
end
|
||||
|
||||
@item.delete
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
<%= div_for item do %>
|
||||
<p class="type"><%= item.item_category.name %></p>
|
||||
<%= image_tag item.item_category.icon, :class => 'icon', :size => '50x50' %>
|
||||
<%= link_to item.name, item_url(item), :class => 'title' %>
|
||||
<div class="desc"><p><%=item.desc %></p></div>
|
||||
<%= link_to item.link, item.link, :class => 'link', :target => '_blank' %>
|
||||
<%= div_for item do %>
|
||||
<%= link_to 'Delete', item, :class => 'delete', :confirm => 'Delete this topic and all synapses linking to it?', :method => :delete, :remote => true%>
|
||||
<p class="type"><%= item.item_category.name %></p>
|
||||
<%= image_tag item.item_category.icon, :class => 'icon', :size => '50x50' %>
|
||||
<%= link_to item.name, item_url(item), :class => 'title' %>
|
||||
<div class="desc"><p><%=item.desc %></p></div>
|
||||
<%= link_to item.link, item.link, :class => 'link', :target => '_blank' %>
|
||||
<% end %>
|
1
app/views/items/destroy.js.erb
Normal file
1
app/views/items/destroy.js.erb
Normal file
|
@ -0,0 +1 @@
|
|||
$('#<%= dom_id(@item) %>').fadeOut('slow');
|
Loading…
Reference in a new issue