From 23f7db2e1ced3fd5aa5bd539b61ff5407a4a0bdd Mon Sep 17 00:00:00 2001 From: Connor Turland Date: Sun, 21 Oct 2012 14:32:17 -0400 Subject: [PATCH] fixed bugs for adding new topic on any page --- app/assets/javascripts/application.js | 5 +++-- app/assets/stylesheets/application.css | 10 ++++++---- app/models/item.rb | 2 -- app/views/items/_new.html.erb | 5 ++++- app/views/items/create.js.erb | 25 ++++++++++++++++++------- app/views/items/index.html.erb | 2 +- app/views/items/new.html.erb | 4 +++- app/views/main/home.html.erb | 2 +- app/views/main/userobjects.html.erb | 2 +- 9 files changed, 37 insertions(+), 20 deletions(-) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index f9a37481..e87dda69 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -21,12 +21,13 @@ $('.nodemargin').css('padding-top',$('.focus').css('height')); $('#newtopic').click(function(event){ - obj = $('#new_item'); + obj = document.getElementById('new_item'); if (obj != null) { $('#new_item').fadeIn('fast'); - return false; + event.preventDefault(); } }); + }); diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 7f9141cb..75c53243 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -19,7 +19,7 @@ html, body, div, h1, h2, h3, h4, h5, h6, ul, ol, dl, li, dt, dd, p, blockquote, pre, form, fieldset, table, th, td, legend { margin: 0; padding: 0; } img {border:0; padding:0; margin:0; display:block; text-indent:-9999px;} -html, body, .main, .wrapper, .home { height: 100%; } +html, body, .main, .wrapper, #container { height: 100%; } html { } body { background:#031924 url(background2.jpg) repeat 0 0; font-family:Arial, Helvetica, sans-serif; background-attachment:fixed; color:#FFF; } @@ -30,9 +30,10 @@ h2 {display:block; text-align:center; background: #333; font-size:24px;} a {color:#2d6a5d; text-decoration:none;} .clearfloat {clear:both;} -.new_session, .new_synapse, .edit_item, .edit_synapse { display: block; width: 350px; margin: 0 auto; background: #D1D1D1; padding: 20px; border-radius: 15px; color: #000; } +.new_session, .new_user, .new_item, .new_synapse, .edit_item, .edit_synapse { display: block; width: 350px; margin: 0 auto; background: #D1D1D1; padding: 20px; border-radius: 15px; color: #000; border:2px solid #000; } -.new_item { display: none; position:absolute; left:50%; top:50%; margin:-175px 0 0 -195px; width: 350px; background: #D1D1D1; padding: 20px; border-radius: 15px; color: #000; border:2px solid #000; } +.anypage .new_item { display: none; position:absolute; left:50%; top:50%; margin:-175px 0 0 -195px; border:2px solid #000; } +#closenewtopic { position:absolute; top: 3px; right:3px; } label, select, input, textarea { display:block; } @@ -46,13 +47,14 @@ input[type="submit"] { margin-top:5px; } .contentarea ul {margin:0 0 0 1em; } .contentarea ol {margin:0 0 0 1.3em; } -.main { overflow:hidden; } +.main { overflow-x:hidden; } .headertop { display:block; position:fixed; top:0; left:0; z-index:10; height:38px; width:100%; min-width:622px; background: url(topbg2.png) repeat-x top left; } #mainTitle { float: left; } #mainTitle a { color:#FFF; } .headertop ul { display:block; float: right; } .headertop ul li {display:block; float:right; margin:10px 5px 0 5px; } +.headertop ul li a { color:#FFF; } .wrapper {display:block; height:100%; margin:50px 0; } diff --git a/app/models/item.rb b/app/models/item.rb index 06550adc..71c1053a 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -34,8 +34,6 @@ belongs_to :item_category #build a json object of everything connected to a specified node def map_as_json Jbuilder.encode do |json| - @single = Array.new - @single.push(self) @items = network(self,nil) json.array!(@items) do |item| diff --git a/app/views/items/_new.html.erb b/app/views/items/_new.html.erb index 51dcd046..76b4fd87 100644 --- a/app/views/items/_new.html.erb +++ b/app/views/items/_new.html.erb @@ -1,4 +1,6 @@ +
<%= form_for Item.new, url: items_path, remote: true do |form| %> +

Add Item

<%= select_tag "category", options_from_collection_for_select(ItemCategory.all, "id", "name") %> @@ -9,4 +11,5 @@ <%= form.text_field :link, class: "link" %> <%= form.submit "Add Item", class: "addItem", id: "addItem" %> -<% end %> \ No newline at end of file +<% end %> +
\ No newline at end of file diff --git a/app/views/items/create.js.erb b/app/views/items/create.js.erb index 85ef9f9a..f3e3ea50 100644 --- a/app/views/items/create.js.erb +++ b/app/views/items/create.js.erb @@ -1,11 +1,22 @@ $('#new_item').fadeOut('fast'); $('#new_item')[0].reset() -var newnode = <%= @item.self_as_json.html_safe %>; -fd.graph.addNode(newnode); -var temp = fd.graph.getNode('<%= @item.id %>'); -temp.setData('dim', 1, 'start'); -temp.setData('dim', 40, 'end'); -fd.fx.animate({ + +// if there's a map, add the node to that, if its in card view add card +obj = document.getElementById('container'); + + +if (obj != null) { + var newnode = <%= @item.self_as_json.html_safe %>; + fd.graph.addNode(newnode); + var temp = fd.graph.getNode('<%= @item.id %>'); + temp.setData('dim', 1, 'start'); + temp.setData('dim', 40, 'end'); + fd.fx.animate({ modes: ['node-property:dim'], duration: 400 - }); \ No newline at end of file + }); +} +else { + $('#cards').prepend('<%= escape_javascript(render(@item)) %>'); +} + diff --git a/app/views/items/index.html.erb b/app/views/items/index.html.erb index 0c0797b3..86591f4f 100644 --- a/app/views/items/index.html.erb +++ b/app/views/items/index.html.erb @@ -1,6 +1,6 @@

All Topics

-
+
<% @items.each do |item| %> <%= render item %> <% end %> diff --git a/app/views/items/new.html.erb b/app/views/items/new.html.erb index 86e51d70..416eecb9 100644 --- a/app/views/items/new.html.erb +++ b/app/views/items/new.html.erb @@ -1,3 +1,4 @@ +
<%= form_for @item || Item.new, url: items_path do |form| %>

Add Item

@@ -9,4 +10,5 @@ <%= form.text_field :link, class: "link" %> <%= form.submit "Add Item", class: "add" %> -<% end %> \ No newline at end of file +<% end %> +
\ No newline at end of file diff --git a/app/views/main/home.html.erb b/app/views/main/home.html.erb index 09609957..790602f1 100644 --- a/app/views/main/home.html.erb +++ b/app/views/main/home.html.erb @@ -1,5 +1,5 @@ <% unless @item.nil? %> -
+
diff --git a/app/views/main/userobjects.html.erb b/app/views/main/userobjects.html.erb index c84f308e..db2effa2 100644 --- a/app/views/main/userobjects.html.erb +++ b/app/views/main/userobjects.html.erb @@ -1,4 +1,4 @@ -
+
<% @all.each do |object| %> <%= render object %> <% end %>