diff --git a/app/assets/javascripts/items.js.coffee b/app/assets/javascripts/items.js.coffee index 76156794..416905ae 100644 --- a/app/assets/javascripts/items.js.coffee +++ b/app/assets/javascripts/items.js.coffee @@ -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/ \ No newline at end of file diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 63877dd3..9b503211 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -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; } diff --git a/app/assets/stylesheets/items.css.scss b/app/assets/stylesheets/items.css.scss index 8bb0ca56..31a799b8 100644 --- a/app/assets/stylesheets/items.css.scss +++ b/app/assets/stylesheets/items.css.scss @@ -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; diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index ba69d8a9..2cbcd0e6 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -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 diff --git a/app/views/items/_item.html.erb b/app/views/items/_item.html.erb index 861321e3..f04abd70 100644 --- a/app/views/items/_item.html.erb +++ b/app/views/items/_item.html.erb @@ -1,7 +1,8 @@ -<%= div_for item do %> -

<%= item.item_category.name %>

- <%= image_tag item.item_category.icon, :class => 'icon', :size => '50x50' %> - <%= link_to item.name, item_url(item), :class => 'title' %> -

<%=item.desc %>

- <%= 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%> +

<%= item.item_category.name %>

+ <%= image_tag item.item_category.icon, :class => 'icon', :size => '50x50' %> + <%= link_to item.name, item_url(item), :class => 'title' %> +

<%=item.desc %>

+ <%= link_to item.link, item.link, :class => 'link', :target => '_blank' %> <% end %> \ No newline at end of file diff --git a/app/views/items/destroy.js.erb b/app/views/items/destroy.js.erb new file mode 100644 index 00000000..fa847ae6 --- /dev/null +++ b/app/views/items/destroy.js.erb @@ -0,0 +1 @@ +$('#<%= dom_id(@item) %>').fadeOut('slow'); \ No newline at end of file