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.
|
# Place all the behaviors and hooks related to the matching controller here.
|
||||||
# All this logic will automatically be available in application.js.
|
# All this logic will automatically be available in application.js.
|
||||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
# 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;}
|
a {color:#2d6a5d; text-decoration:none;}
|
||||||
.clearfloat {clear:both;}
|
.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; }
|
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 { 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;
|
.item .type {position: absolute;
|
||||||
color: white;
|
color: white;
|
||||||
top: -22px;
|
top: -22px;
|
||||||
|
|
|
@ -1,87 +1,97 @@
|
||||||
class ItemsController < ApplicationController
|
class ItemsController < ApplicationController
|
||||||
|
|
||||||
before_filter :require_user, only: [:new, :create, :edit, :update]
|
before_filter :require_user, only: [:new, :create, :edit, :update]
|
||||||
|
|
||||||
respond_to :html, :js, :json
|
respond_to :html, :js, :json
|
||||||
|
|
||||||
# GET /items
|
# GET /items
|
||||||
def index
|
def index
|
||||||
@user = current_user
|
@user = current_user
|
||||||
@items = Item.all
|
@items = Item.all
|
||||||
|
|
||||||
respond_with(@items)
|
respond_with(@items)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get /item/new
|
# Get /item/new
|
||||||
def new
|
def new
|
||||||
@item = Item.new
|
@item = Item.new
|
||||||
@user = current_user
|
@user = current_user
|
||||||
|
|
||||||
respond_with(@item)
|
respond_with(@item)
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /item/:id
|
# GET /item/:id
|
||||||
def show
|
def show
|
||||||
@item = Item.find(params[:id])
|
@item = Item.find(params[:id])
|
||||||
|
|
||||||
@relatives = @item.as_json.html_safe
|
@relatives = @item.as_json.html_safe
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { respond_with(@item) }
|
format.html { respond_with(@item) }
|
||||||
format.json { respond_with(@relatives) }
|
format.json { respond_with(@relatives) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# POST /items
|
# POST /items
|
||||||
def create
|
def create
|
||||||
|
|
||||||
@user = current_user
|
@user = current_user
|
||||||
@item = Item.new()
|
@item = Item.new()
|
||||||
@item.name = params[:item][:name]
|
@item.name = params[:item][:name]
|
||||||
@item.desc = params[:item][:desc]
|
@item.desc = params[:item][:desc]
|
||||||
@item.link = params[:item][:link]
|
@item.link = params[:item][:link]
|
||||||
@item.item_category = ItemCategory.find(params[:category])
|
@item.item_category = ItemCategory.find(params[:category])
|
||||||
@item.user = @user
|
@item.user = @user
|
||||||
|
|
||||||
@item.save
|
@item.save
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { respond_with(@user, location: item_url(@item)) }
|
format.html { respond_with(@user, location: item_url(@item)) }
|
||||||
format.js { respond_with(@item) }
|
format.js { respond_with(@item) }
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /items/:id/edit
|
# GET /items/:id/edit
|
||||||
def edit
|
def edit
|
||||||
@item = Item.find_by_id(params[:id])
|
@item = Item.find_by_id(params[:id])
|
||||||
|
|
||||||
respond_with(@item)
|
respond_with(@item)
|
||||||
end
|
end
|
||||||
|
|
||||||
# PUT /actions/:id
|
# PUT /actions/:id
|
||||||
def update
|
def update
|
||||||
@item = Item.find_by_id(params[:id])
|
@item = Item.find_by_id(params[:id])
|
||||||
|
|
||||||
if @item
|
if @item
|
||||||
@item.name = params[:item][:name]
|
@item.name = params[:item][:name]
|
||||||
@item.desc = params[:item][:desc]
|
@item.desc = params[:item][:desc]
|
||||||
@item.link = params[:item][:link]
|
@item.link = params[:item][:link]
|
||||||
@item.item_category = ItemCategory.find(params[:category][:item_category_id])
|
@item.item_category = ItemCategory.find(params[:category][:item_category_id])
|
||||||
|
|
||||||
@item.save
|
@item.save
|
||||||
end
|
end
|
||||||
|
|
||||||
respond_with(@user, location: item_url(@item)) do |format|
|
respond_with(@user, location: item_url(@item)) do |format|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# DELETE /items/:id
|
# DELETE /items/:id
|
||||||
def destroy
|
def destroy
|
||||||
@item = Item.find_by_id(params[:id])
|
@item = Item.find_by_id(params[:id])
|
||||||
|
|
||||||
@item.delete
|
@synapses = @item.synapses
|
||||||
end
|
|
||||||
|
@synapses.each do |synapse|
|
||||||
end
|
synapse.delete
|
||||||
|
end
|
||||||
|
|
||||||
|
@item.delete
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.js
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
<%= div_for item do %>
|
<%= div_for item do %>
|
||||||
<p class="type"><%= item.item_category.name %></p>
|
<%= link_to 'Delete', item, :class => 'delete', :confirm => 'Delete this topic and all synapses linking to it?', :method => :delete, :remote => true%>
|
||||||
<%= image_tag item.item_category.icon, :class => 'icon', :size => '50x50' %>
|
<p class="type"><%= item.item_category.name %></p>
|
||||||
<%= link_to item.name, item_url(item), :class => 'title' %>
|
<%= image_tag item.item_category.icon, :class => 'icon', :size => '50x50' %>
|
||||||
<div class="desc"><p><%=item.desc %></p></div>
|
<%= link_to item.name, item_url(item), :class => 'title' %>
|
||||||
<%= link_to item.link, item.link, :class => 'link', :target => '_blank' %>
|
<div class="desc"><p><%=item.desc %></p></div>
|
||||||
|
<%= link_to item.link, item.link, :class => 'link', :target => '_blank' %>
|
||||||
<% end %>
|
<% 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