From d2f7fef83575de485e9e56a251bce0f4c24962c1 Mon Sep 17 00:00:00 2001 From: Connor Turland Date: Mon, 29 Oct 2012 23:40:38 -0400 Subject: [PATCH] added ability to add existing topics to map. also the ability to remove topics from a map that you've added by mistake or don't wan't there anymore. --- app/assets/stylesheets/maps.css.scss | 76 +++++++++++++++------------- app/controllers/items_controller.rb | 21 +++++--- app/controllers/maps_controller.rb | 12 ++++- app/views/maps/_newtopic.html.erb | 39 +++++++++----- app/views/maps/edit.html.erb | 2 + 5 files changed, 92 insertions(+), 58 deletions(-) diff --git a/app/assets/stylesheets/maps.css.scss b/app/assets/stylesheets/maps.css.scss index 4716c561..0fe6cfa1 100644 --- a/app/assets/stylesheets/maps.css.scss +++ b/app/assets/stylesheets/maps.css.scss @@ -1,35 +1,41 @@ -// Place all the styles related to the maps controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ - -.map { display:block; float:left; position:relative; width:170px; height:300px; padding:10px 10px 10px 35px; background: url('bg.png'); border-radius:15px; margin:30px 0 30px 50px; color:#000; } - -.map .delete {position: absolute; -top: -14px; -left: 0px; -background: none; -border: 0; -color: white; -border: none; -font-size: 14px; -margin: 0; -padding: 0; -cursor:pointer; -} - -.map .type {position: absolute; -color: white; -top: -22px; -right: 0; -font-weight: bold; -font-size: 20px; -line-height: 24px;} - -.map .icon { position:absolute; top:135px; left:-25px; } - -.map .title { font-size:22px; line-height:25px; display:block; border-bottom:2px solid #000; padding-bottom:5px; } - -.map .desc { font-style:italic; font-size:15px; } -.map .desc h3 { font-style:normal; margin-top:5px; } - -.map .link { position:absolute; width:170px; top:295px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } \ No newline at end of file +// Place all the styles related to the maps controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ + +.map { display:block; float:left; position:relative; width:170px; height:300px; padding:10px 10px 10px 35px; background: url('bg.png'); border-radius:15px; margin:30px 0 30px 50px; color:#000; } + +.map .delete {position: absolute; +top: -14px; +left: 0px; +background: none; +border: 0; +color: white; +border: none; +font-size: 14px; +margin: 0; +padding: 0; +cursor:pointer; +} + +.map .type {position: absolute; +color: white; +top: -22px; +right: 0; +font-weight: bold; +font-size: 20px; +line-height: 24px;} + +.map .icon { position:absolute; top:135px; left:-25px; } + +.map .title { font-size:22px; line-height:25px; display:block; border-bottom:2px solid #000; padding-bottom:5px; } + +.map .desc { font-style:italic; font-size:15px; } +.map .desc h3 { font-style:normal; margin-top:5px; } + +.map .link { position:absolute; width:170px; top:295px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } + + + +// add topic on maps pages +.selecttype { border:1px solid #000; margin-top: 20px; border-radius:15px; } +.mapspages .new_item h3 { padding: 10px 26px; display: block; cursor: pointer; color: #2d6a5d; float:left; } \ No newline at end of file diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index 369cea85..5bb1b89d 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -45,15 +45,20 @@ class ItemsController < ApplicationController def create @user = current_user - @item = Item.new() - @item.name = params[:item][:name] - @item.desc = params[:item][:desc] - @item.link = params[:item][:link] - @item.permission = params[:item][:permission] - @item.item_category = ItemCategory.find(params[:category]) - @item.user = @user - @item.save + if params[:initem] + @item = Item.find(params[:initem]) + else + @item = Item.new() + @item.name = params[:item][:name] + @item.desc = params[:item][:desc] + @item.link = params[:item][:link] + @item.permission = params[:item][:permission] + @item.item_category = ItemCategory.find(params[:category]) + @item.user = @user + + @item.save + end if params[:item][:map] @mapping = Mapping.new() diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb index fce39278..507dc47d 100644 --- a/app/controllers/maps_controller.rb +++ b/app/controllers/maps_controller.rb @@ -66,8 +66,10 @@ class MapsController < ApplicationController if not @map redirect_to root_url and return end + + @outitems = @map.items.order("name ASC").delete_if{|item| not item.authorize_to_view(@current)} - respond_with(@user, @map) + respond_with(@user, @map, @outitems) end # PUT /users/:user_id/maps/:id @@ -79,6 +81,14 @@ class MapsController < ApplicationController @map.attributes = params[:map] @map.save + if params[:outitems] + @outitems = params[:outitems] + @outitems.each do |item| + @mapping = Mapping.where("map_id = ? AND item_id = ?", @map.id, item).first + @mapping.delete + end + end + respond_with(@user, location: user_map_path(@user, @map)) do |format| end diff --git a/app/views/maps/_newtopic.html.erb b/app/views/maps/_newtopic.html.erb index 75fe05e3..86cd0b33 100644 --- a/app/views/maps/_newtopic.html.erb +++ b/app/views/maps/_newtopic.html.erb @@ -1,18 +1,29 @@ -
+
<%= form_for Item.new, url: user_items_url(user), remote: true do |form| %> -

Add Topic

- - <%= select_tag "category", options_from_collection_for_select(ItemCategory.order("name ASC").all, "id", "name") %> - - <%= form.text_field :name %> - - <%= form.text_area :desc, class: "description", :rows => 5 %> - - <%= form.text_field :link, class: "link" %> - - <%= form.select(:permission, options_for_select(['commons', 'public', 'private'])) %> - <%= form.hidden_field :map, :value => @map.id %> - <%= form.submit "Add Item", class: "addItem", id: "addItem" %> +
+

Add New Topic

+

Add Existing Topic

+
+
+
+ + <%= select_tag "category", options_from_collection_for_select(ItemCategory.order("name ASC").all, "id", "name") %> + + <%= form.text_field :name %> + + <%= form.text_area :desc, class: "description", :rows => 5 %> + + <%= form.text_field :link, class: "link" %> + + <%= form.select(:permission, options_for_select(['commons', 'public', 'private'])) %> + <%= form.hidden_field :map, :value => @map.id %> + <%= form.submit "Add Item", class: "addItem", id: "addItem" %> +
+ <% end %>
\ No newline at end of file diff --git a/app/views/maps/edit.html.erb b/app/views/maps/edit.html.erb index 64c46b3a..009b878e 100644 --- a/app/views/maps/edit.html.erb +++ b/app/views/maps/edit.html.erb @@ -4,6 +4,8 @@ <%= form.text_field :name %> <%= form.text_area :desc, class: "description", :rows => 5 %> + + <%= select_tag "outitems", options_from_collection_for_select(@outitems, "id", "name"), { :multiple => true } %> <%= form.select :permission, options_for_select(['commons', 'public', 'private'], @map.permission) %> <%= form.submit "Update", class: "update" %>