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.

This commit is contained in:
Connor Turland 2012-10-29 23:40:38 -04:00
parent f9c355cddb
commit d2f7fef835
5 changed files with 92 additions and 58 deletions

View file

@ -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; }
// 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; }

View file

@ -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()

View file

@ -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

View file

@ -1,18 +1,29 @@
<div class="anypage">
<div class="anypage mapspages">
<%= form_for Item.new, url: user_items_url(user), remote: true do |form| %>
<button id="closenewtopic" onclick="$('#new_item').fadeOut('fast'); $('#new_item')[0].reset(); return false;">close</button>
<h3>Add Topic</h3>
<label for="category">Category</label>
<%= select_tag "category", options_from_collection_for_select(ItemCategory.order("name ASC").all, "id", "name") %>
<label for="item_name">Title</label>
<%= form.text_field :name %>
<label for="item_desc">Description</label>
<%= form.text_area :desc, class: "description", :rows => 5 %>
<label for="item_link">Link</label>
<%= form.text_field :link, class: "link" %>
<label for="item_permission">Permission</label>
<%= form.select(:permission, options_for_select(['commons', 'public', 'private'])) %>
<%= form.hidden_field :map, :value => @map.id %>
<%= form.submit "Add Item", class: "addItem", id: "addItem" %>
<div class="selecttype">
<h3 onclick="$('.existingtopic').fadeOut('fast', function () { $('.newtopic').fadeIn('fast'); });" style="border-right:1px solid #000;">Add New Topic</h3>
<h3 onclick="$('.newtopic').fadeOut('fast', function () { $('.existingtopic').fadeIn('fast'); });">Add Existing Topic</h3>
<div style="clear:both;"></div>
</div>
<div class="newtopic">
<label for="category">Category</label>
<%= select_tag "category", options_from_collection_for_select(ItemCategory.order("name ASC").all, "id", "name") %>
<label for="item_name">Title</label>
<%= form.text_field :name %>
<label for="item_desc">Description</label>
<%= form.text_area :desc, class: "description", :rows => 5 %>
<label for="item_link">Link</label>
<%= form.text_field :link, class: "link" %>
<label for="item_permission">Permission</label>
<%= form.select(:permission, options_for_select(['commons', 'public', 'private'])) %>
<%= form.hidden_field :map, :value => @map.id %>
<%= form.submit "Add Item", class: "addItem", id: "addItem" %>
</div>
<div class="existingtopic" style="display:none;" >
<label for="initem">Select Topic To Add</label>
<%= select_tag "initem", options_from_collection_for_select(Item.order("name ASC").visibleToUser(user, nil).delete_if{|item| @map.items.include?(item)}, "id", "name") %>
<%= form.submit "Add Item", class: "addItem", id: "addItem" %>
</div>
<% end %>
</div>

View file

@ -4,6 +4,8 @@
<%= form.text_field :name %>
<label for="map_desc">Description</label>
<%= form.text_area :desc, class: "description", :rows => 5 %>
<label for="outitems">Remove Topics From Map</label>
<%= select_tag "outitems", options_from_collection_for_select(@outitems, "id", "name"), { :multiple => true } %>
<label for="map_perm">Permission</label>
<%= form.select :permission, options_for_select(['commons', 'public', 'private'], @map.permission) %>
<%= form.submit "Update", class: "update" %>