diff --git a/app/assets/javascripts/Jit/Map/metamapMAP.js b/app/assets/javascripts/Jit/Map/metamapMAP.js
index 42a7c046..81e3f359 100644
--- a/app/assets/javascripts/Jit/Map/metamapMAP.js
+++ b/app/assets/javascripts/Jit/Map/metamapMAP.js
@@ -320,18 +320,6 @@ function initMAP(){
});
$(document).ready(function() {
- var coor = "";
- $("#saveLayout").click(function(event) {
- event.preventDefault();
- coor = "";
- map.graph.eachNode(function(n) {
- coor = coor + n.data.$mappingid + '/' + n.pos.x + '/' + n.pos.y + ',';
- });
- coor = coor.slice(0, -1);
- $('#map_coordinates').val(coor);
- $('#saveMapLayout').submit();
- });
-
map.animate({
modes: ['linear'],
transition: $jit.Trans.Quad.easeInOut,
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index c792ca07..b2cc195c 100644
--- a/app/assets/javascripts/application.js
+++ b/app/assets/javascripts/application.js
@@ -219,6 +219,26 @@
}
}
});
+
+ // this is to save the layout of maps
+ var coor = "";
+ $("#saveLayout").click(function(event) {
+ event.preventDefault();
+ coor = "";
+ if (map != null) {
+ map.graph.eachNode(function(n) {
+ coor = coor + n.data.$mappingid + '/' + n.pos.x + '/' + n.pos.y + ',';
+ });
+ }
+ else if (fd != null) {
+ fd.graph.eachNode(function(n) {
+ coor = coor + n.data.$mappingid + '/' + n.pos.x + '/' + n.pos.y + ',';
+ });
+ }
+ coor = coor.slice(0, -1);
+ $('#map_coordinates').val(coor);
+ $('#saveMapLayout').submit();
+ });
});
diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb
index 61aab663..01471d24 100644
--- a/app/controllers/maps_controller.rb
+++ b/app/controllers/maps_controller.rb
@@ -47,7 +47,7 @@ class MapsController < ApplicationController
@user = current_user
@map = Map.create(params[:map])
@map.user = @user
-
+ @map.arranged = false
@map.save
respond_to do |format|
@@ -110,6 +110,8 @@ class MapsController < ApplicationController
@mapping.yloc = item[2]
@mapping.save
end
+ @map.arranged = true
+ @map.save
end
end
@@ -127,7 +129,8 @@ class MapsController < ApplicationController
@map.delete
- respond_with(location: user_maps_path(@user)) do |format|
+ respond_to do |format|
+ format.js
end
end
diff --git a/app/views/items/create.js.erb b/app/views/items/create.js.erb
index e5af4392..d333cfcd 100644
--- a/app/views/items/create.js.erb
+++ b/app/views/items/create.js.erb
@@ -6,13 +6,18 @@ map2 = document.getElementById('container');
if (map2 != null) {
var newnode = <%= @item.self_as_json.html_safe %>;
- console.log(newnode);
+
if (fd != null) {
fd.graph.addNode(newnode);
var temp = fd.graph.getNode('<%= @item.id %>');
temp.setData('dim', 1, 'start');
temp.setData('dim', 40, 'end');
+ <% unless (@mapping.nil?) %>
+ temp.setData('xloc',0);
+ temp.setData('yloc',0);
+ temp.setData('mappingid', '<%= @mapping.id %>');
+ <% end %>
temp.setPos(new $jit.Complex(0, 0), 'current');
temp.setPos(new $jit.Complex(0, 0), 'start');
temp.setPos(new $jit.Complex(0, 0), 'end');
@@ -36,7 +41,7 @@ if (map2 != null) {
duration: 400
});
}
- if (map != null) {
+ else if (map != null) {
map.graph.addNode(newnode);
var temp = map.graph.getNode('<%= @item.id %>');
temp.setData('dim', 1, 'start');
@@ -57,7 +62,8 @@ if (map2 != null) {
json = newnode;
initFD();
}
- // add the new node to the synapse select list
+ console.log(temp);
+ // add the new node to the synapse select lists
$("#node1_id").prepend("");
$("#node2_id").prepend("");
diff --git a/app/views/maps/destroy.js.erb b/app/views/maps/destroy.js.erb
index fa847ae6..b48cbd79 100644
--- a/app/views/maps/destroy.js.erb
+++ b/app/views/maps/destroy.js.erb
@@ -1 +1 @@
-$('#<%= dom_id(@item) %>').fadeOut('slow');
\ No newline at end of file
+$('#<%= dom_id(@map) %>').fadeOut('slow');
\ No newline at end of file
diff --git a/app/views/maps/show.html.erb b/app/views/maps/show.html.erb
index f3a29e92..bdca326f 100644
--- a/app/views/maps/show.html.erb
+++ b/app/views/maps/show.html.erb
@@ -34,7 +34,11 @@
json = <%= @mapjson %>;
if (json.length > 0) {
$(document).ready(function() {
- initMAP();
+ <% if (@map.arranged) %>
+ initMAP();
+ <% else %>
+ initFD();
+ <% end %>
});
}
diff --git a/db/migrate/20121023231434_create_maps.rb b/db/migrate/20121023231434_create_maps.rb
index 2266067a..f28c31e4 100644
--- a/db/migrate/20121023231434_create_maps.rb
+++ b/db/migrate/20121023231434_create_maps.rb
@@ -2,6 +2,7 @@ class CreateMaps < ActiveRecord::Migration
def change
create_table :maps do |t|
t.text :name
+ t.boolean :arranged
t.text :desc
t.text :permission
t.integer :user_id
diff --git a/db/migrate/20121203225613_add_arranged_to_map.rb b/db/migrate/20121203225613_add_arranged_to_map.rb
new file mode 100644
index 00000000..f5a88665
--- /dev/null
+++ b/db/migrate/20121203225613_add_arranged_to_map.rb
@@ -0,0 +1,6 @@
+class AddArrangedToMap < ActiveRecord::Migration
+ def change
+ add_column :maps, :arranged, :boolean
+ Map.update_all ["arranged = ?", false]
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 4d849f05..c4f01152 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20121026000731) do
+ActiveRecord::Schema.define(:version => 20121203225613) do
create_table "item_categories", :force => true do |t|
t.text "name"
@@ -50,6 +50,7 @@ ActiveRecord::Schema.define(:version => 20121026000731) do
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
+ t.boolean "arranged"
end
create_table "synapses", :force => true do |t|