From f817ce772ce34e3e37642fd2f5ab7104ee0031ee Mon Sep 17 00:00:00 2001 From: Connor Turland Date: Tue, 29 Jul 2014 23:18:43 -0400 Subject: [PATCH] changed approach to map creation. reorganized code to suit that. --- app/assets/javascripts/application.js | 17 +- app/assets/javascripts/compileMapPages.js | 9 +- .../{ => librariesForAllPages}/bip.js | 0 .../{ => librariesForAllPages}/hogan-2.0.0.js | 0 .../jquery-ui-1.8.23.custom.min.js | 0 .../jquery.lettering.js | 0 .../jquery.mCustomScrollbar.min.js | 0 .../jquery.mousewheel.min.js | 0 .../{ => librariesForAllPages}/jquery.purr.js | 0 .../jquery.roundabout.min.js | 0 .../jquery.textillate.js | 0 .../jquery.typing-0.2.0.min.js | 0 .../mCSB_buttons.png | Bin .../{ => librariesForAllPages}/typeahead.js | 0 .../WebSocketMain.swf | Bin .../WebSocketMainInsecure.swf | Bin .../cloudcarousel.js} | 0 .../{ => librariesForMapPages}/socket.io.js | 0 .../javascripts/metamaps/Metamaps.Backbone.js | 34 + .../javascripts/metamaps/Metamaps.GlobalUI.js | 152 ++++- .../javascripts/metamaps/Metamaps.JIT.js | 2 +- app/assets/javascripts/metamaps/metamaps.js | 643 ++++++++---------- .../{ => orderedLibraries}/backbone.js | 0 .../{ => orderedLibraries}/underscore.js | 0 app/assets/stylesheets/application.css | 2 +- app/controllers/maps_controller.rb | 41 +- app/views/maps/_fork.html.erb | 8 +- app/views/maps/_new.html.erb | 5 +- app/views/maps/create.js.erb | 41 -- app/views/maps/destroy.js.erb | 5 - app/views/maps/realtime.js.erb | 94 --- app/views/maps/savelayout.js.erb | 6 - codeguide.txt | 71 ++ 33 files changed, 558 insertions(+), 572 deletions(-) rename app/assets/javascripts/{ => librariesForAllPages}/bip.js (100%) rename app/assets/javascripts/{ => librariesForAllPages}/hogan-2.0.0.js (100%) rename app/assets/javascripts/{scroll => librariesForAllPages}/jquery-ui-1.8.23.custom.min.js (100%) rename app/assets/javascripts/{ => librariesForAllPages}/jquery.lettering.js (100%) rename app/assets/javascripts/{scroll => librariesForAllPages}/jquery.mCustomScrollbar.min.js (100%) rename app/assets/javascripts/{scroll => librariesForAllPages}/jquery.mousewheel.min.js (100%) rename app/assets/javascripts/{ => librariesForAllPages}/jquery.purr.js (100%) rename app/assets/javascripts/{ => librariesForAllPages}/jquery.roundabout.min.js (100%) rename app/assets/javascripts/{ => librariesForAllPages}/jquery.textillate.js (100%) rename app/assets/javascripts/{typing => librariesForAllPages}/jquery.typing-0.2.0.min.js (100%) rename app/assets/javascripts/{scroll => librariesForAllPages}/mCSB_buttons.png (100%) rename app/assets/javascripts/{ => librariesForAllPages}/typeahead.js (100%) rename app/assets/javascripts/{ => librariesForMapPages}/WebSocketMain.swf (100%) rename app/assets/javascripts/{ => librariesForMapPages}/WebSocketMainInsecure.swf (100%) rename app/assets/javascripts/{carousel/cloud-carousel.1.0.5.js => librariesForMapPages/cloudcarousel.js} (100%) rename app/assets/javascripts/{ => librariesForMapPages}/socket.io.js (100%) create mode 100644 app/assets/javascripts/metamaps/Metamaps.Backbone.js rename app/assets/javascripts/{ => orderedLibraries}/backbone.js (100%) rename app/assets/javascripts/{ => orderedLibraries}/underscore.js (100%) delete mode 100644 app/views/maps/create.js.erb delete mode 100644 app/views/maps/destroy.js.erb delete mode 100644 app/views/maps/realtime.js.erb delete mode 100644 app/views/maps/savelayout.js.erb create mode 100644 codeguide.txt diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 521bc782..b35dfc1e 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -10,18 +10,11 @@ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD // GO AFTER THE REQUIRES BELOW. // -// require autocomplete-rails-uncompressed -// //= require jquery //= require jquery-ui -//= require jquery.purr -//= require jquery.lettering -//= require jquery.textillate -//= require jquery.roundabout.min -//= require bip //= require jquery_ujs -//= require typeahead -//= require hogan-2.0.0 -//= require_directory ./scroll -//= require_directory ./typing -//= require ./metamaps/Metamaps.GlobalUI \ No newline at end of file +//= require ./orderedLibraries/underscore +//= require ./orderedLibraries/backbone +//= require_directory ./librariesForAllPages +//= require ./metamaps/Metamaps.GlobalUI +//= require ./metamaps/Metamaps.Backbone \ No newline at end of file diff --git a/app/assets/javascripts/compileMapPages.js b/app/assets/javascripts/compileMapPages.js index 0d793858..24a98f84 100644 --- a/app/assets/javascripts/compileMapPages.js +++ b/app/assets/javascripts/compileMapPages.js @@ -10,10 +10,11 @@ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD // GO AFTER THE REQUIRES BELOW. // -//= require socket.io -//= require underscore -//= require backbone -//= require_directory ./carousel +// +// can't use require directory because underscore needs to come before backbone +// +//= require ./librariesForMapPages/cloudcarousel +//= require ./librariesForMapPages/socket.io //= require ./metamaps/JIT //= require ./metamaps/Metamaps //= require ./metamaps/Metamaps.JIT \ No newline at end of file diff --git a/app/assets/javascripts/bip.js b/app/assets/javascripts/librariesForAllPages/bip.js similarity index 100% rename from app/assets/javascripts/bip.js rename to app/assets/javascripts/librariesForAllPages/bip.js diff --git a/app/assets/javascripts/hogan-2.0.0.js b/app/assets/javascripts/librariesForAllPages/hogan-2.0.0.js similarity index 100% rename from app/assets/javascripts/hogan-2.0.0.js rename to app/assets/javascripts/librariesForAllPages/hogan-2.0.0.js diff --git a/app/assets/javascripts/scroll/jquery-ui-1.8.23.custom.min.js b/app/assets/javascripts/librariesForAllPages/jquery-ui-1.8.23.custom.min.js similarity index 100% rename from app/assets/javascripts/scroll/jquery-ui-1.8.23.custom.min.js rename to app/assets/javascripts/librariesForAllPages/jquery-ui-1.8.23.custom.min.js diff --git a/app/assets/javascripts/jquery.lettering.js b/app/assets/javascripts/librariesForAllPages/jquery.lettering.js similarity index 100% rename from app/assets/javascripts/jquery.lettering.js rename to app/assets/javascripts/librariesForAllPages/jquery.lettering.js diff --git a/app/assets/javascripts/scroll/jquery.mCustomScrollbar.min.js b/app/assets/javascripts/librariesForAllPages/jquery.mCustomScrollbar.min.js similarity index 100% rename from app/assets/javascripts/scroll/jquery.mCustomScrollbar.min.js rename to app/assets/javascripts/librariesForAllPages/jquery.mCustomScrollbar.min.js diff --git a/app/assets/javascripts/scroll/jquery.mousewheel.min.js b/app/assets/javascripts/librariesForAllPages/jquery.mousewheel.min.js similarity index 100% rename from app/assets/javascripts/scroll/jquery.mousewheel.min.js rename to app/assets/javascripts/librariesForAllPages/jquery.mousewheel.min.js diff --git a/app/assets/javascripts/jquery.purr.js b/app/assets/javascripts/librariesForAllPages/jquery.purr.js similarity index 100% rename from app/assets/javascripts/jquery.purr.js rename to app/assets/javascripts/librariesForAllPages/jquery.purr.js diff --git a/app/assets/javascripts/jquery.roundabout.min.js b/app/assets/javascripts/librariesForAllPages/jquery.roundabout.min.js similarity index 100% rename from app/assets/javascripts/jquery.roundabout.min.js rename to app/assets/javascripts/librariesForAllPages/jquery.roundabout.min.js diff --git a/app/assets/javascripts/jquery.textillate.js b/app/assets/javascripts/librariesForAllPages/jquery.textillate.js similarity index 100% rename from app/assets/javascripts/jquery.textillate.js rename to app/assets/javascripts/librariesForAllPages/jquery.textillate.js diff --git a/app/assets/javascripts/typing/jquery.typing-0.2.0.min.js b/app/assets/javascripts/librariesForAllPages/jquery.typing-0.2.0.min.js similarity index 100% rename from app/assets/javascripts/typing/jquery.typing-0.2.0.min.js rename to app/assets/javascripts/librariesForAllPages/jquery.typing-0.2.0.min.js diff --git a/app/assets/javascripts/scroll/mCSB_buttons.png b/app/assets/javascripts/librariesForAllPages/mCSB_buttons.png similarity index 100% rename from app/assets/javascripts/scroll/mCSB_buttons.png rename to app/assets/javascripts/librariesForAllPages/mCSB_buttons.png diff --git a/app/assets/javascripts/typeahead.js b/app/assets/javascripts/librariesForAllPages/typeahead.js similarity index 100% rename from app/assets/javascripts/typeahead.js rename to app/assets/javascripts/librariesForAllPages/typeahead.js diff --git a/app/assets/javascripts/WebSocketMain.swf b/app/assets/javascripts/librariesForMapPages/WebSocketMain.swf similarity index 100% rename from app/assets/javascripts/WebSocketMain.swf rename to app/assets/javascripts/librariesForMapPages/WebSocketMain.swf diff --git a/app/assets/javascripts/WebSocketMainInsecure.swf b/app/assets/javascripts/librariesForMapPages/WebSocketMainInsecure.swf similarity index 100% rename from app/assets/javascripts/WebSocketMainInsecure.swf rename to app/assets/javascripts/librariesForMapPages/WebSocketMainInsecure.swf diff --git a/app/assets/javascripts/carousel/cloud-carousel.1.0.5.js b/app/assets/javascripts/librariesForMapPages/cloudcarousel.js similarity index 100% rename from app/assets/javascripts/carousel/cloud-carousel.1.0.5.js rename to app/assets/javascripts/librariesForMapPages/cloudcarousel.js diff --git a/app/assets/javascripts/socket.io.js b/app/assets/javascripts/librariesForMapPages/socket.io.js similarity index 100% rename from app/assets/javascripts/socket.io.js rename to app/assets/javascripts/librariesForMapPages/socket.io.js diff --git a/app/assets/javascripts/metamaps/Metamaps.Backbone.js b/app/assets/javascripts/metamaps/Metamaps.Backbone.js new file mode 100644 index 00000000..b36e77a9 --- /dev/null +++ b/app/assets/javascripts/metamaps/Metamaps.Backbone.js @@ -0,0 +1,34 @@ +Metamaps.Backbone = {}; +Metamaps.Backbone.Map = Backbone.Model.extend({ + urlRoot: '/maps', + blacklist: ['created_at', 'updated_at'], + toJSON: function (options) { + return _.omit(this.attributes, this.blacklist); + }, + authorizeToEdit: function (mapper) { + if (mapper && (this.get('permission') === "commons" || this.get('user_id') === mapper.get('id'))) return true; + else return false; + } +}); +Metamaps.Backbone.MapsCollection = Backbone.Collection.extend({ + model: Metamaps.Backbone.Map, + url: '/maps' +}); + +Metamaps.Backbone.Mapper = Backbone.Model.extend({ + urlRoot: '/users', + blacklist: ['created_at', 'updated_at'], + toJSON: function (options) { + return _.omit(this.attributes, this.blacklist); + }, +}); +Metamaps.Backbone.MapperCollection = Backbone.Collection.extend({ + model: Metamaps.Backbone.Mapper, + url: '/users' +}); +Metamaps.Active.Mapper = new Metamaps.Backbone.Mapper({ + id: userid, + name: username +}); +Metamaps.Mappers = new Metamaps.Backbone.MapperCollection([Metamaps.Active.Mapper]); +Metamaps.Maps = new Metamaps.Backbone.MapsCollection(); \ No newline at end of file diff --git a/app/assets/javascripts/metamaps/Metamaps.GlobalUI.js b/app/assets/javascripts/metamaps/Metamaps.GlobalUI.js index 1c577c6d..0dff8295 100644 --- a/app/assets/javascripts/metamaps/Metamaps.GlobalUI.js +++ b/app/assets/javascripts/metamaps/Metamaps.GlobalUI.js @@ -2,22 +2,22 @@ var Metamaps = {}; // this variable declaration defines a Javascript object that /* * unless you are on a page with the Javascript InfoVis Toolkit (Topic or Map) the only section in the metamaps -* object will be this one +* object will be these GlobalUI +Active +Maps +Mappers +Backbone * all these get added when you are on a page with the Javascript Infovis Toolkit Settings Touch Mouse -Active Selected -Maps -Mappers Metacodes Topics Synapses Mappings -Backbone Create TopicCard SynapseCard @@ -28,18 +28,25 @@ Control Filter Listeners Organize -Topic -Synapse Map Mapper +Topic +Synapse JIT */ +Metamaps.Active = { + Map: null, + Topic: null, + Mapper: null +}; +Metamaps.Maps = {}; // will be initialized in Metamaps.Backbone.js as a MapCollection +Metamaps.Mappers = {}; // will be initialized in Metamaps.Backbone.js as a MapperCollection $(document).ready(function () { for (var prop in Metamaps) { - + // this runs the init function within each sub-object on the Metamaps one if (Metamaps.hasOwnProperty(prop) && Metamaps[prop].hasOwnProperty('init') && @@ -49,13 +56,11 @@ $(document).ready(function () { } } - //Metamaps.Visualize.type = "ForceDirected3D"; - // this line could maybe go at the end of the Metamaps.JIT init function - if (Metamaps.JIT) Metamaps.JIT.prepareVizData(); }); Metamaps.GlobalUI = { notifyTimeout: null, + lightbox: null, init: function () { var self = Metamaps.GlobalUI; @@ -76,8 +81,12 @@ Metamaps.GlobalUI = { $('.alert.metamaps').delay(10000).fadeOut('fast'); }, openLightbox: function (which) { + var self = Metamaps.GlobalUI; + $('.lightboxContent').hide(); $('#' + which).show(); + + self.lightbox = which; $('#lightbox_overlay').show(); $('#lightbox_main').css('margin-top', '-' + ($('#lightbox_main').height() / 2) + 'px'); @@ -97,16 +106,20 @@ Metamaps.GlobalUI = { }, closeLightbox: function () { + var self = Metamaps.GlobalUI; + $('#lightbox_overlay').hide(); - Metamaps.GlobalUI.CreateMap.reset('fork_map'); - Metamaps.GlobalUI.CreateMap.reset('new_map'); + + if (self.lightbox === 'forkmap') Metamaps.GlobalUI.CreateMap.reset('fork_map'); + if (self.lightbox === 'newmap') Metamaps.GlobalUI.CreateMap.reset('new_map'); if (Metamaps.Create && Metamaps.Create.isSwitchingSet) { Metamaps.Create.cancelMetacodeSetSwitch(); } + self.lightbox = null; }, notifyUser: function (message) { var self = Metamaps.GlobalUI; - + if ($('.notice.metamaps').length == 0) { $('body').prepend('
'); } @@ -186,33 +199,102 @@ Metamaps.GlobalUI.MainMenu = { Metamaps.GlobalUI.CreateMap = { + newMap: null, + emptyMapForm: "", + emptyForkMapForm: "", + topicsToMap: [], + synapsesToMap: [], init: function () { + var self = Metamaps.GlobalUI.CreateMap; + + self.newMap = new Metamaps.Backbone.Map({ permission: 'commons' }); + + self.bindFormEvents(); + + self.emptyMapForm = $('#new_map').html(); + + }, + bindFormEvents: function () { + var self = Metamaps.GlobalUI.CreateMap; + + $('.new_map button.cancel').unbind().bind('click', function (event) { + event.preventDefault(); + Metamaps.GlobalUI.closeLightbox(); + }); + $('.new_map button.submitMap').unbind().bind('click', self.submit); // bind permission changer events on the createMap form - $('.permIcon').click(function () { - $(this).siblings('#map_permission').val($(this).attr('data-permission')); - $(this).siblings('.permIcon').find('.mapPermIcon').removeClass('selected'); - $(this).find('.mapPermIcon').addClass('selected'); - }); - + $('.permIcon').unbind().bind('click', self.switchPermission); }, - reset: function (id) { + generateSuccessMessage: function (id) { + var stringStart = "Success! Do you want to
Go to your new map?"; + stringStart += "
or
Stay on this "; + var page = Metamaps.Active.Map ? 'map' : 'page'; + var stringEnd = "?"; + return stringStart + page + stringEnd; + }, + switchPermission: function () { + var self = Metamaps.GlobalUI.CreateMap; + + self.newMap.set('permission', $(this).attr('data-permission')); + $(this).siblings('.permIcon').find('.mapPermIcon').removeClass('selected'); + $(this).find('.mapPermIcon').addClass('selected'); + }, + submit: function (event) { + event.preventDefault(); + + var self = Metamaps.GlobalUI.CreateMap; - var form = $('#' + id); - - form.find('#map_name').val(''); - form.find('#map_desc').val(''); - form.find('#map_permission').val('commons'); - - if (id == "fork_map") { - form.find('#map_topicsToMap').val('0'); - form.find('#map_synapsesToMap').val('0'); + if (Metamaps.GlobalUI.lightbox === 'forkmap') { + self.newMap.set('topicsToMap', self.topicsToMap); + self.newMap.set('synapsesToMap', self.synapsesToMap); } - // remove a selected state from all three of them - form.find('.mapPermIcon').removeClass('selected'); - // add a selected state back to commons permission, the default - form.find('.mapCommonsIcon').addClass('selected'); + var formId = Metamaps.GlobalUI.lightbox === 'forkmap' ? '#fork_map' : '#new_map'; + var form = $(formId); + + self.newMap.set('name', form.find('#map_name').val()); + self.newMap.set('desc', form.find('#map_desc').val()); + + // TODO validate map attributes + + self.newMap.save(null, { + success: self.success + // TODO add error message + }); + + if (Metamaps.GlobalUI.lightbox === 'forkmap') { + form.html('Working...'); + } + }, + success: function (model) { + var self = Metamaps.GlobalUI.CreateMap; + + var formId = Metamaps.GlobalUI.lightbox === 'forkmap' ? '#fork_map' : '#new_map'; + var form = $(formId); + + form.html(self.generateSuccessMessage(model.id)); + + $('#lightbox_main').css('margin-top', '-' + ($('#lightbox_main').height() / 2) + 'px'); + }, + reset: function (id) { + var self = Metamaps.GlobalUI.CreateMap; + + var form = $('#' + id); + + if (id === "fork_map") { + self.topicsToMap = []; + self.synapsesToMap = []; + form.html(self.emptyForkMapForm); + } + else { + form.html(self.emptyMapForm); + } + + self.bindFormEvents(); + self.newMap = new Metamaps.Backbone.Map({ permission: 'commons' }); return false; }, @@ -300,7 +382,7 @@ Metamaps.GlobalUI.Search = { break; //console.log(e.which); } }); - + self.startTypeahead(); }, open: function () { diff --git a/app/assets/javascripts/metamaps/Metamaps.JIT.js b/app/assets/javascripts/metamaps/Metamaps.JIT.js index 5534d9e0..08a2b906 100644 --- a/app/assets/javascripts/metamaps/Metamaps.JIT.js +++ b/app/assets/javascripts/metamaps/Metamaps.JIT.js @@ -7,7 +7,7 @@ Metamaps.JIT = { init: function () { var self = Metamaps.JIT; - + self.prepareVizData(); }, /** * convert our topic JSON into something JIT can use diff --git a/app/assets/javascripts/metamaps/metamaps.js b/app/assets/javascripts/metamaps/metamaps.js index 358c945e..6b7be77e 100644 --- a/app/assets/javascripts/metamaps/metamaps.js +++ b/app/assets/javascripts/metamaps/metamaps.js @@ -59,19 +59,11 @@ Metamaps.Mouse = { DOUBLE_CLICK_TOLERANCE: 300 }; -Metamaps.Active = { - Map: null, - Topic: null, - Mapper: null -}; - Metamaps.Selected = { Nodes: [], Edges: [] }; -Metamaps.Maps = {}; // will be initialized in Metamaps.Backbone.init as a MapCollection -Metamaps.Mappers = {}; // will be initialized in Metamaps.Backbone.init as a MapperCollection Metamaps.Metacodes = {}; // will be initialized in Metamaps.Backbone.init as a MetacodeCollection Metamaps.Topics = {}; // will be initialized in Metamaps.Backbone.init as a TopicCollection Metamaps.Synapses = {}; // will be initialized in Metamaps.Backbone.init as a SynapseCollection @@ -79,270 +71,242 @@ Metamaps.Mappings = {}; // will be initialized in Metamaps.Backbone.init as a Ma /* -* -* BACKBONE -* -*/ -Metamaps.Backbone = { - init: function () { - var self = Metamaps.Backbone; + * + * BACKBONE + * + */ +Metamaps.Backbone.init = function () { + var self = Metamaps.Backbone; - self.Metacode = Backbone.Model.extend({}); - self.MetacodeCollection = Backbone.Collection.extend({ - model: this.Metacode, - url: '/metacodes' - }); + self.Metacode = Backbone.Model.extend({}); + self.MetacodeCollection = Backbone.Collection.extend({ + model: this.Metacode, + url: '/metacodes' + }); - self.Topic = Backbone.Model.extend({ - urlRoot: '/topics', - blacklist: ['node', 'created_at', 'updated_at'], - toJSON: function (options) { - return _.omit(this.attributes, this.blacklist); - }, - initialize: function () { - if (this.isNew()) { - this.set({ - "user_id": Metamaps.Active.Mapper.id, - "desc": '', - "link": '', - "permission": Metamaps.Active.Map ? Metamaps.Active.Map.get('permission') : 'commons' - }); - } - }, - authorizeToEdit: function (mapper) { - if (mapper && (this.get('permission') === "commons" || this.get('user_id') === mapper.get('id'))) return true; - else return false; - }, - authorizePermissionChange: function (mapper) { - if (mapper && this.get('user_id') === mapper.get('id')) return true; - else return false; - }, - getDate: function () { - - }, - getUser: function () { - return Metamaps.Mapper.get(this.get('user_id')); - }, - getMetacode: function () { - return Metamaps.Metacodes.get(this.get('metacode_id')); - }, - getMapping: function () { - return Metamaps.Mappings.findWhere({ - map_id: Metamaps.Active.Map.id, - topic_id: this.isNew() ? this.cid : this.id + self.Topic = Backbone.Model.extend({ + urlRoot: '/topics', + blacklist: ['node', 'created_at', 'updated_at'], + toJSON: function (options) { + return _.omit(this.attributes, this.blacklist); + }, + initialize: function () { + if (this.isNew()) { + this.set({ + "user_id": Metamaps.Active.Mapper.id, + "desc": '', + "link": '', + "permission": Metamaps.Active.Map ? Metamaps.Active.Map.get('permission') : 'commons' }); - }, - updateMapping: function () { - var mapping = this.getMapping(); - - if (mapping) { - mapping.set('topic_id', this.id); - } - }, - createNode: function () { - var mapping = this.getMapping(); - var node = { - adjacencies: [], - data: { - $mapping: null, - $mappingID: mapping ? mapping.id : null - }, - id: this.isNew() ? this.cid : this.id, - name: this.get('name') - }; - return node; - }, - updateNode: function () { - var mapping = this.getMapping(); - var node = this.get('node'); - node.setData('topic', this); - node.setData('mapping', mapping); - node.id = this.isNew() ? this.cid : this.id; - return node; - }, - }); - - self.TopicCollection = Backbone.Collection.extend({ - model: self.Topic, - url: '/topics', - comparator: function (a, b) { - a = a.get('name').toLowerCase(); - b = b.get('name').toLowerCase(); - return a > b ? 1 : a < b ? -1 : 0; } - }); + }, + authorizeToEdit: function (mapper) { + if (mapper && (this.get('permission') === "commons" || this.get('user_id') === mapper.get('id'))) return true; + else return false; + }, + authorizePermissionChange: function (mapper) { + if (mapper && this.get('user_id') === mapper.get('id')) return true; + else return false; + }, + getDate: function () { - self.Synapse = Backbone.Model.extend({ - urlRoot: '/synapses', - blacklist: ['edge', 'created_at', 'updated_at'], - toJSON: function (options) { - return _.omit(this.attributes, this.blacklist); - }, - initialize: function () { - if (this.isNew()) { - this.set({ - "user_id": Metamaps.Active.Mapper.id, - "permission": Metamaps.Active.Map.get('permission'), - "category": "from-to" - }); - } - }, - authorizeToEdit: function (mapper) { - if (mapper && (this.get('permission') === "commons" || this.get('user_id') === mapper.get('id'))) return true; - else return false; - }, - authorizePermissionChange: function (mapper) { - if (mapper && this.get('user_id') === mapper.get('id')) return true; - else return false; - }, - getUser: function () { - return Metamaps.Mapper.get(this.get('user_id')); - }, - getTopic1: function () { - return Metamaps.Topic.get(this.get('node1_id')); - }, - getTopic2: function () { - return Metamaps.Topic.get(this.get('node2_id')); - }, - getDirection: function () { - return [ + }, + getUser: function () { + return Metamaps.Mapper.get(this.get('user_id')); + }, + getMetacode: function () { + return Metamaps.Metacodes.get(this.get('metacode_id')); + }, + getMapping: function () { + return Metamaps.Mappings.findWhere({ + map_id: Metamaps.Active.Map.id, + topic_id: this.isNew() ? this.cid : this.id + }); + }, + updateMapping: function () { + var mapping = this.getMapping(); + + if (mapping) { + mapping.set('topic_id', this.id); + } + }, + createNode: function () { + var mapping = this.getMapping(); + var node = { + adjacencies: [], + data: { + $mapping: null, + $mappingID: mapping ? mapping.id : null + }, + id: this.isNew() ? this.cid : this.id, + name: this.get('name') + }; + return node; + }, + updateNode: function () { + var mapping = this.getMapping(); + var node = this.get('node'); + node.setData('topic', this); + node.setData('mapping', mapping); + node.id = this.isNew() ? this.cid : this.id; + return node; + }, + }); + + self.TopicCollection = Backbone.Collection.extend({ + model: self.Topic, + url: '/topics', + comparator: function (a, b) { + a = a.get('name').toLowerCase(); + b = b.get('name').toLowerCase(); + return a > b ? 1 : a < b ? -1 : 0; + } + }); + + self.Synapse = Backbone.Model.extend({ + urlRoot: '/synapses', + blacklist: ['edge', 'created_at', 'updated_at'], + toJSON: function (options) { + return _.omit(this.attributes, this.blacklist); + }, + initialize: function () { + if (this.isNew()) { + this.set({ + "user_id": Metamaps.Active.Mapper.id, + "permission": Metamaps.Active.Map.get('permission'), + "category": "from-to" + }); + } + }, + authorizeToEdit: function (mapper) { + if (mapper && (this.get('permission') === "commons" || this.get('user_id') === mapper.get('id'))) return true; + else return false; + }, + authorizePermissionChange: function (mapper) { + if (mapper && this.get('user_id') === mapper.get('id')) return true; + else return false; + }, + getUser: function () { + return Metamaps.Mapper.get(this.get('user_id')); + }, + getTopic1: function () { + return Metamaps.Topic.get(this.get('node1_id')); + }, + getTopic2: function () { + return Metamaps.Topic.get(this.get('node2_id')); + }, + getDirection: function () { + return [ this.get('node1_id'), this.get('node2_id') ]; - }, - getMapping: function () { - return Metamaps.Mappings.findWhere({ - map_id: Metamaps.Active.Map.id, - synapse_id: this.isNew() ? this.cid : this.id + }, + getMapping: function () { + return Metamaps.Mappings.findWhere({ + map_id: Metamaps.Active.Map.id, + synapse_id: this.isNew() ? this.cid : this.id + }); + }, + updateMapping: function () { + var mapping = this.getMapping(); + + if (mapping) { + mapping.set('synapse_id', this.id); + } + }, + createEdge: function () { + var mapping = this.getMapping(); + var mappingID = mapping.isNew() ? mapping.cid : mapping.id; + var synapseID = this.isNew() ? this.cid : this.id; + + var edge = { + nodeFrom: this.get('node1_id'), + nodeTo: this.get('node2_id'), + data: { + $mappings: [], + $mappingIDs: [mappingID], + $synapses: [], + $synapseIDs: [synapseID], + } + }; + return edge; + }, + updateEdge: function () { + var mapping = this.getMapping(); + var edge = this.get('edge'); + edge.getData('mappings').push(mapping); + edge.getData('synapses').push(this); + return edge; + }, + }); + + self.SynapseCollection = Backbone.Collection.extend({ + model: self.Synapse, + url: '/synapses' + }); + + self.Mapping = Backbone.Model.extend({ + urlRoot: '/mappings', + blacklist: ['created_at', 'updated_at'], + toJSON: function (options) { + return _.omit(this.attributes, this.blacklist); + }, + initialize: function () { + if (this.isNew()) { + this.set({ + "user_id": Metamaps.Active.Mapper.id, + "map_id": Metamaps.Active.Map ? Metamaps.Active.Map.id : null }); - }, - updateMapping: function () { - var mapping = this.getMapping(); - - if (mapping) { - mapping.set('synapse_id', this.id); - } - }, - createEdge: function () { - var mapping = this.getMapping(); - var mappingID = mapping.isNew() ? mapping.cid : mapping.id; - var synapseID = this.isNew() ? this.cid : this.id; - - var edge = { - nodeFrom: this.get('node1_id'), - nodeTo: this.get('node2_id'), - data: { - $mappings: [], - $mappingIDs: [mappingID], - $synapses: [], - $synapseIDs: [synapseID], - } - }; - return edge; - }, - updateEdge: function () { - var mapping = this.getMapping(); - var edge = this.get('edge'); - edge.getData('mappings').push(mapping); - edge.getData('synapses').push(this); - return edge; - }, - }); - - self.SynapseCollection = Backbone.Collection.extend({ - model: self.Synapse, - url: '/synapses' - }); - - self.Mapping = Backbone.Model.extend({ - urlRoot: '/mappings', - blacklist: ['created_at', 'updated_at'], - toJSON: function (options) { - return _.omit(this.attributes, this.blacklist); - }, - initialize: function () { - if (this.isNew()) { - this.set({ - "user_id": Metamaps.Active.Mapper.id, - "map_id": Metamaps.Active.Map ? Metamaps.Active.Map.id : null - }); - } - }, - getUser: function () { - return Metamaps.Mapper.get(this.get('user_id')); - }, - getMap: function () { - return Metamaps.Map.get(this.get('map_id')); - }, - getTopic: function () { - if (this.get('category') === 'Topic') return Metamaps.Topic.get(this.get('topic_id')); - else return false; - }, - getSynapse: function () { - if (this.get('category') === 'Synapse') return Metamaps.Synapse.get(this.get('synapse_id')); - else return false; } - }); + }, + getUser: function () { + return Metamaps.Mapper.get(this.get('user_id')); + }, + getMap: function () { + return Metamaps.Map.get(this.get('map_id')); + }, + getTopic: function () { + if (this.get('category') === 'Topic') return Metamaps.Topic.get(this.get('topic_id')); + else return false; + }, + getSynapse: function () { + if (this.get('category') === 'Synapse') return Metamaps.Synapse.get(this.get('synapse_id')); + else return false; + } + }); - self.MappingCollection = Backbone.Collection.extend({ - model: self.Mapping, - url: '/mappings' - }); + self.MappingCollection = Backbone.Collection.extend({ + model: self.Mapping, + url: '/mappings' + }); - self.Map = Backbone.Model.extend({ - urlRoot: '/maps', - blacklist: ['created_at', 'updated_at'], - toJSON: function (options) { - return _.omit(this.attributes, this.blacklist); - }, - authorizeToEdit: function (mapper) { - if (mapper && (this.get('permission') === "commons" || this.get('user_id') === mapper.get('id'))) return true; - else return false; - } - }); - self.MapsCollection = Backbone.Collection.extend({ - model: self.Map, - url: '/maps' - }); + Metamaps.Metacodes = new self.MetacodeCollection(Metamaps.Metacodes); - self.Mapper = Backbone.Model.extend({ - urlRoot: '/users', - blacklist: ['created_at', 'updated_at'], - toJSON: function (options) { - return _.omit(this.attributes, this.blacklist); - }, - }); - self.MapperCollection = Backbone.Collection.extend({ - model: self.Mapper, - url: '/users' - }); + Metamaps.Topics = new self.TopicCollection(Metamaps.Topics); - Metamaps.Metacodes = new self.MetacodeCollection(Metamaps.Metacodes); + Metamaps.Synapses = new self.SynapseCollection(Metamaps.Synapses); - Metamaps.Active.Mapper = new self.Mapper({ - id: userid, - name: username - }); - Metamaps.Mappers = new self.MapperCollection([Metamaps.Active.Mapper]); + Metamaps.Mappings = new self.MappingCollection(Metamaps.Mappings); - Metamaps.Topics = new self.TopicCollection(Metamaps.Topics); - - Metamaps.Synapses = new self.SynapseCollection(Metamaps.Synapses); - - Metamaps.Mappings = new self.MappingCollection(Metamaps.Mappings); - - Metamaps.Active.Map = new self.Map(Metamaps.Active.Map); - Metamaps.Maps = new self.MapsCollection([Metamaps.Active.Map]); - } -}; // end Metamaps.Backbone + Metamaps.Active.Map = new self.Map(Metamaps.Active.Map); + Metamaps.Maps.add(Metamaps.Active.Map); +}; // end Metamaps.Backbone.init /* -* -* CREATE -* -*/ + * + * CREATE + * + */ Metamaps.Create = { + isSwitchingSet: false, // indicates whether the metacode set switch lightbox is open + metacodeScrollerInit: false, // indicates whether the scrollbar in the custom metacode set space has been init + selectedMetacodeSet: null, + selectedMetacodeSetIndex: null, + selectedMetacodeNames: [], + newSelectedMetacodeNames: [], + selectedMetacodes: [], + newSelectedMetacodes: [], init: function () { var self = Metamaps.Create; self.newTopic.init(); @@ -356,28 +320,23 @@ Metamaps.Create = { selected: self.selectedMetacodeSetIndex }).addClass("ui-tabs-vertical ui-helper-clearfix"); $("#metacodeSwitchTabs .ui-tabs-nav li").removeClass("ui-corner-top").addClass("ui-corner-left"); - $('.customMetacodeList li').click(function () { - if ($(this).attr('class') != 'toggledOff') { - $(this).addClass('toggledOff'); - var value_to_remove = $(this).attr('id'); - var name_to_remove = $(this).attr('data-name'); - self.newSelectedMetacodes.splice(self.newSelectedMetacodes.indexOf(value_to_remove), 1); - self.newSelectedMetacodeNames.splice(self.newSelectedMetacodeNames.indexOf(name_to_remove), 1); - } else if ($(this).attr('class') == 'toggledOff') { - $(this).removeClass('toggledOff'); - self.newSelectedMetacodes.push($(this).attr('id')); - self.newSelectedMetacodeNames.push($(this).attr('data-name')); - } - }); + $('.customMetacodeList li').click(self.toggleMetacodeSelected); // within the custom metacode set tab + }, + toggleMetacodeSelected: function () { + var self = Metamaps.Create; + + if ($(this).attr('class') != 'toggledOff') { + $(this).addClass('toggledOff'); + var value_to_remove = $(this).attr('id'); + var name_to_remove = $(this).attr('data-name'); + self.newSelectedMetacodes.splice(self.newSelectedMetacodes.indexOf(value_to_remove), 1); + self.newSelectedMetacodeNames.splice(self.newSelectedMetacodeNames.indexOf(name_to_remove), 1); + } else if ($(this).attr('class') == 'toggledOff') { + $(this).removeClass('toggledOff'); + self.newSelectedMetacodes.push($(this).attr('id')); + self.newSelectedMetacodeNames.push($(this).attr('data-name')); + } }, - isSwitchingSet: false, // indicates whether the metacode set switch lightbox is open - metacodeScrollerInit: false, // indicates whether the scrollbar in the custom metacode set space has been init - selectedMetacodeSet: null, - selectedMetacodeSetIndex: null, - selectedMetacodeNames: [], - newSelectedMetacodeNames: [], - selectedMetacodes: [], - newSelectedMetacodes: [], updateMetacodeSet: function (set, index, custom) { if (custom && Metamaps.Create.newSelectedMetacodes.length == 0) { @@ -606,10 +565,10 @@ Metamaps.Create = { /* -* -* TOPICCARD -* -*/ + * + * TOPICCARD + * + */ Metamaps.TopicCard = { openTopicCard: null, //stores the JIT local ID of the topic with the topic card open init: function () { @@ -864,10 +823,10 @@ Metamaps.TopicCard = { /* -* -* SYNAPSECARD -* -*/ + * + * SYNAPSECARD + * + */ Metamaps.SynapseCard = { openSynapseCard: null, showCard: function (edge, e) { @@ -1080,10 +1039,10 @@ Metamaps.SynapseCard = { /* -* -* VISUALIZE -* -*/ + * + * VISUALIZE + * + */ Metamaps.Visualize = { mGraph: {}, // a reference to the graph object. cameraPosition: null, // stores the camera position when using a 3D visualization @@ -1219,10 +1178,10 @@ Metamaps.Visualize = { /* -* -* UTIL -* -*/ + * + * UTIL + * + */ Metamaps.Util = { // helper function to determine how many lines are needed // Line Splitter Function @@ -1271,10 +1230,10 @@ Metamaps.Util = { /* -* -* REALTIME -* -*/ + * + * REALTIME + * + */ Metamaps.Realtime = { // this is for the heroku staging environment //Metamaps.Realtime.socket = io.connect('http://gentle-savannah-1303.herokuapp.com'); @@ -1524,7 +1483,7 @@ Metamaps.Realtime = { } }, addTopicToMap: function (topic) { - + // TODO var newPos, tempForT; Metamaps.Visualize.mGraph.graph.addNode(topic); @@ -1540,7 +1499,7 @@ Metamaps.Realtime = { Metamaps.Visualize.mGraph.fx.plotNode(tempForT, Metamaps.Visualize.mGraph.canvas); }, updateTopicOnMap: function (topic) { - + // TODO var newPos, tempForT; tempForT = Metamaps.Visualize.mGraph.graph.getNode(topic.id); @@ -1562,7 +1521,7 @@ Metamaps.Realtime = { }); }, addSynapseToMap: function (synapse) { - + // TODO var Node1, Node2, tempForS; Node1 = Metamaps.Visualize.mGraph.graph.getNode(synapse.data.$direction[0]); @@ -1584,7 +1543,7 @@ Metamaps.Realtime = { }); }, updateSynapseOnMap: function (synapse) { - + // TODO var k, tempForS, v, wasShowDesc, _ref; tempForS = Metamaps.Visualize.mGraph.graph.getAdjacence(synapse.data.$direction[0], synapse.data.$direction[1]); @@ -1600,14 +1559,14 @@ Metamaps.Realtime = { } return Metamaps.Visualize.mGraph.plot(); } -}; // end Metamaps.Realtime +}; // end Metamaps.Realtime /* -* -* CONTROL -* -*/ + * + * CONTROL + * + */ Metamaps.Control = { init: function () { @@ -1874,10 +1833,10 @@ Metamaps.Control = { /* -* -* FILTER -* -*/ + * + * FILTER + * + */ Metamaps.Filter = { filters: { name: "", @@ -2008,10 +1967,10 @@ Metamaps.Filter = { /* -* -* LISTENERS -* -*/ + * + * LISTENERS + * + */ Metamaps.Listeners = { init: function () { @@ -2038,10 +1997,10 @@ Metamaps.Listeners = { /* -* -* ORGANIZE -* -*/ + * + * ORGANIZE + * + */ Metamaps.Organize = { init: function () { @@ -2167,10 +2126,10 @@ Metamaps.Organize = { /* -* -* TOPIC -* -*/ + * + * TOPIC + * + */ Metamaps.Topic = { // this function is to retrieve a topic JSON object from the database // @param id = the id of the topic to retrieve @@ -2347,10 +2306,10 @@ Metamaps.Topic = { /* -* -* SYNAPSE -* -*/ + * + * SYNAPSE + * + */ Metamaps.Synapse = { // this function is to retrieve a synapse JSON object from the database // @param id = the id of the synapse to retrieve @@ -2486,10 +2445,10 @@ Metamaps.Synapse = { /* -* -* MAP -* -*/ + * + * MAP + * + */ Metamaps.Map = { init: function () { var self = Metamaps.Map; @@ -2503,6 +2462,8 @@ Metamaps.Map = { self.fork(); }); + Metamaps.GlobalUI.CreateMap.emptyForkMapForm = $('#fork_map').html(); + self.InfoBox.init(); self.CheatSheet.init(); }, @@ -2570,17 +2531,17 @@ Metamaps.Map = { synapses_data = synapses_array.join(); nodes_data = nodes_data.slice(0, -1); - $('#map_topicsToMap').val(nodes_data); - $('#map_synapsesToMap').val(synapses_data); + Metamaps.GlobalUI.CreateMap.topicsToMap = nodes_data; + Metamaps.GlobalUI.CreateMap.synapsesToMap = synapses_data; } }; /* -* -* CHEATSHEET -* -*/ + * + * CHEATSHEET + * + */ Metamaps.Map.CheatSheet = { init: function () { // tab the cheatsheet @@ -2591,10 +2552,10 @@ Metamaps.Map.CheatSheet = { /* -* -* INFOBOX -* -*/ + * + * INFOBOX + * + */ Metamaps.Map.InfoBox = { isOpen: false, timeOut: null, @@ -2675,10 +2636,10 @@ Metamaps.Map.InfoBox = { /* -* -* MAPPER -* -*/ + * + * MAPPER + * + */ Metamaps.Mapper = { // this function is to retrieve a mapper JSON object from the database // @param id = the id of the mapper to retrieve @@ -2709,4 +2670,4 @@ Metamaps.Mapper = { } } }, -}; // end Metamaps.Mapper \ No newline at end of file +}; // end Metamaps.Mapper \ No newline at end of file diff --git a/app/assets/javascripts/backbone.js b/app/assets/javascripts/orderedLibraries/backbone.js similarity index 100% rename from app/assets/javascripts/backbone.js rename to app/assets/javascripts/orderedLibraries/backbone.js diff --git a/app/assets/javascripts/underscore.js b/app/assets/javascripts/orderedLibraries/underscore.js similarity index 100% rename from app/assets/javascripts/underscore.js rename to app/assets/javascripts/orderedLibraries/underscore.js diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index c7e84755..73671bf0 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -2011,7 +2011,7 @@ div.mapInfoStat { margin: 10px 0 0 131px; width: 254px; } -.onConsole .new_map button { +.onConsole .new_map button.cancel { margin-right: 20px; } .onConsole .new_map button, diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb index cdc403f8..37d9fdc3 100644 --- a/app/controllers/maps_controller.rb +++ b/app/controllers/maps_controller.rb @@ -98,18 +98,15 @@ class MapsController < ApplicationController @user = current_user @map = Map.new() - @map.name = params[:map][:name] - @map.desc = params[:map][:desc] - @map.permission = params[:map][:permission] + @map.name = params[:name] + @map.desc = params[:desc] + @map.permission = params[:permission] @map.user = @user - @map.arranged = false - @map.save - - #this variable specifies to the js file whether it's a brand new map or a forked one - @forked = false + @map.arranged = false + @map.save - if params[:map][:topicsToMap] - @all = params[:map][:topicsToMap] + if params[:topicsToMap] + @all = params[:topicsToMap] @all = @all.split(',') @all.each do |topic| topic = topic.split('/') @@ -123,8 +120,8 @@ class MapsController < ApplicationController @mapping.save end - if params[:map][:synapsesToMap] - @synAll = params[:map][:synapsesToMap] + if params[:synapsesToMap] + @synAll = params[:synapsesToMap] @synAll = @synAll.split(',') @synAll.each do |synapse_id| @mapping = Mapping.new() @@ -137,13 +134,11 @@ class MapsController < ApplicationController end @map.arranged = true - @map.save - - @forked = true + @map.save end respond_to do |format| - format.js { respond_with(@map, @forked) } + format.json { render :json => @map } end end @@ -153,15 +148,15 @@ class MapsController < ApplicationController @map = Map.find(params[:id]).authorize_to_edit(@current) if @map - if params[:map] - @map.name = params[:map][:name] if params[:map][:name] - @map.desc = params[:map][:desc] if params[:map][:desc] - @map.permission = params[:map][:permission] if params[:map][:permission] - end + @map.name = params[:name] if params[:name] + @map.desc = params[:desc] if params[:desc] + @map.permission = params[:permission] if params[:permission] @map.save - end + end - respond_with @map + respond_to do |format| + format.json { render :json => @map } + end end # DELETE maps/:id diff --git a/app/views/maps/_fork.html.erb b/app/views/maps/_fork.html.erb index 15cd12c8..3b3b4d7f 100644 --- a/app/views/maps/_fork.html.erb +++ b/app/views/maps/_fork.html.erb @@ -51,19 +51,15 @@

PRIVATE

- <%= form.hidden_field :permission, :value => "commons" %>

*new topics and synapses take on the same permission as the map they are created on

- - <%= form.submit "Create!", class: "add" %> + +
- - <%= form.hidden_field :topicsToMap, :value => 0 %> - <%= form.hidden_field :synapsesToMap, :value => 0 %>
<% end %> diff --git a/app/views/maps/_new.html.erb b/app/views/maps/_new.html.erb index 06c0c459..6d72ec20 100644 --- a/app/views/maps/_new.html.erb +++ b/app/views/maps/_new.html.erb @@ -46,15 +46,14 @@

PRIVATE

- <%= form.hidden_field :permission, :value => "commons" %>

*new topics and synapses take on the same permission as the map they are created on

- - <%= form.submit "Create!", class: "add" %> + +
diff --git a/app/views/maps/create.js.erb b/app/views/maps/create.js.erb deleted file mode 100644 index dc8a1937..00000000 --- a/app/views/maps/create.js.erb +++ /dev/null @@ -1,41 +0,0 @@ -/* - * @file - * Javascript run on creation of a new map - */ - - -$('#map_name').val(''); -$('#map_desc').val(''); -$('#map_permission').val('commons'); - -<% if @forked %> - $('#map_topicsToMap').val('0'); - $('#map_synapsesToMap').val('0'); - - var form = $('#fork_map'); -<% else %> - var form = $('#new_map'); -<% end %> -form.find('.mapPermIcon').removeClass('selected'); -form.find('.mapCommonsIcon').addClass('selected'); - - -var tempForm = form.html(); -if (mapid == null) { - form.html("Success! Do you want to
' + "'>Go to your new map?
or
Stay on this page?"); -} -else if (mapid != null) { - form.html("Success! Do you want to
' + "'>Go to your new map?
or
Stay on this map?"); -} -$('#lightbox_main').css('margin-top', '-' + ($('#lightbox_main').height() / 2) + 'px' ); - -function closeIt() { - $('#lightbox_overlay').hide(); - form.html(tempForm); - // bind permission changer events - form.find('.permIcon').click(function() { - $(this).siblings('#map_permission').val( $(this).attr('data-permission') ); - $(this).siblings('.permIcon').find('.mapPermIcon').removeClass('selected'); - $(this).find('.mapPermIcon').addClass('selected'); - }); -} diff --git a/app/views/maps/destroy.js.erb b/app/views/maps/destroy.js.erb deleted file mode 100644 index 851efd3a..00000000 --- a/app/views/maps/destroy.js.erb +++ /dev/null @@ -1,5 +0,0 @@ -/* - * @file - * Javascript run on destruction of a map. Fades it out from map index. - */ -$('#<%= dom_id(@map) %>').fadeOut('slow'); diff --git a/app/views/maps/realtime.js.erb b/app/views/maps/realtime.js.erb deleted file mode 100644 index 588faa8e..00000000 --- a/app/views/maps/realtime.js.erb +++ /dev/null @@ -1,94 +0,0 @@ -/* - * @file - * Javascript code for realtime callbacks - * TODO: Connor, could you explain this code sometime? - */ -var tempForT, tempForS, tempForM; - -<% @topics.each do |topic| %> - var topic = <%= topic.selfonmap_as_json(@map.id).html_safe %>; - tempForT = Mconsole.graph.getNode(topic.id); - if (tempForT === undefined) { - Mconsole.graph.addNode(topic); - var tempForT = Mconsole.graph.getNode(topic.id); - tempForT.setData('dim', 1, 'start'); - tempForT.setData('dim', 25, 'end'); - var newPos = new $jit.Complex(); - newPos.x = tempForT.data.$xloc; - newPos.y = tempForT.data.$yloc; - tempForT.setPos(newPos, 'start'); - tempForT.setPos(newPos, 'current'); - tempForT.setPos(newPos, 'end'); - Mconsole.fx.plotNode(tempForT, Mconsole.canvas); - Mconsole.labels.plotLabel(Mconsole.canvas, tempForT, Mconsole.config); - } - else { - var label = Mconsole.labels.getLabel(topic.id); - tempForT.setData('dim', 25, 'start'); - tempForT.setData('dim', 25, 'current'); - tempForT.setData('dim', 25, 'end'); - if (tempForT.name != topic.name) { - tempForT.name = topic.name; - $(label).find('.best_in_place_name').html(topic.name); - $(label).find('.label').html(topic.name); - } - if (tempForT.data.$metacode != topic.data.$metacode) { - $(label).find('.best_in_place_metacode').html(topic.data.$metacode); - $(label).find('img.icon').attr('alt', topic.data.$metacode); - $(label).find('img.icon').attr('src', imgArray[topic.data.$metacode].src); - } - if (tempForT.data.$desc != topic.data.$desc) { - $(label).find('.best_in_place_desc').html(topic.data.$desc); - } - if (tempForT.data.$link != topic.data.$link) { - $(label).find('.best_in_place_link').html(topic.data.$link); - $(label).find('.link').attr('href',topic.data.$link); - } - tempForT.data = topic.data; - } -<% end %> - -<% @synapses.each do |synapse| %> - var Node1 = Mconsole.graph.getNode(<%= synapse.topic1.id %>); - var Node2 = Mconsole.graph.getNode(<%= synapse.topic2.id %>); - Mconsole.graph.addAdjacence(Node1, Node2, {}); - tempForS = Mconsole.graph.getAdjacence(Node1.id, Node2.id); - tempForS.setDataset('start', { - lineWidth: 0.4 - }); - tempForS.setDataset('end', { - lineWidth: 2 - }); - var d = new Array(<%= synapse.node1_id.to_s() %>, <%= synapse.node2_id.to_s() %>); - tempForS.setDataset('current', { - desc: '<%= synapse.desc %>', - showDesc: false, - category: '<%= synapse.category %>', - id: '<%= synapse.id %>', - userid: '<%= synapse.user.id %>', - username: '<%= synapse.user.name %>' - }); - tempForS.data.$direction = d; - Mconsole.fx.plotLine(tempForS, Mconsole.canvas); -<% end %> - -<% @mappings.each do |mapping| %> - tempForM = Mconsole.graph.getNode(<%= mapping.topic_id %>); - tempForM.data.$xloc = <%= mapping.xloc %>; - tempForM.data.$yloc = <%= mapping.yloc %>; - var newPos = new $jit.Complex(); - newPos.x = tempForM.data.$xloc; - newPos.y = tempForM.data.$yloc; - tempForM.setPos(newPos, 'start'); - tempForM.setPos(newPos, 'current'); - tempForM.setPos(newPos, 'end'); -<% end %> - -<% if @topics.length > 0 || @synapses.length > 0 || @mappings.length > 0 %> - $('#map_time').val(Math.round((new Date()).getTime() / 1000)); - Mconsole.fx.animate({ - modes: ['linear','node-property:dim','edge-property:lineWidth'], - transition: $jit.Trans.Quad.easeInOut, - duration: 500 - }); -<% end %> diff --git a/app/views/maps/savelayout.js.erb b/app/views/maps/savelayout.js.erb deleted file mode 100644 index 3372a417..00000000 --- a/app/views/maps/savelayout.js.erb +++ /dev/null @@ -1,6 +0,0 @@ -/* - * @file - * Javascript executed when you save the layout of a map. - */ -$('.sidebarSave .tip').html('Saved!'); -setTimeout(function(){ $('.sidebarSave .tip').html('Save Layout') },1500); diff --git a/codeguide.txt b/codeguide.txt new file mode 100644 index 00000000..d10d088e --- /dev/null +++ b/codeguide.txt @@ -0,0 +1,71 @@ +FILE /app/views/layouts/application.html.erb + + ... + <%= javascript_include_tag "application" %> + <% if (controller_name == "maps" || controller_name == "topics") && action_name == "show" %> + <%= javascript_include_tag "compileMapPages" %> + <% end %> + ... + + +WHAT DOES IT MEAN? + + +____________________________________________________________________ + +FILE /app/assets/javascripts/application.js +... +//= require jquery +//= require jquery-ui +//= require jquery_ujs +//= require ./orderedLibraries/underscore +//= require ./orderedLibraries/backbone +//= require_directory ./librariesForAllPages +//= require ./metamaps/Metamaps.GlobalUI +//= require ./metamaps/Metamaps.Backbone + +WHAT DOES IT MEAN? + + +____________________________________________________________________ + +FILE /app/assets/javascripts/compileMapPages.js +... +//= require ./librariesForMapPages/cloudcarousel +//= require ./librariesForMapPages/socket.io +//= require ./metamaps/JIT +//= require ./metamaps/Metamaps +//= require ./metamaps/Metamaps.JIT + +WHAT DOES IT MEAN? + + + +____________________________________________________________________ + +FILE /app/assets/javascripts/metamaps/Metamaps.GlobalUI.js + +var Metamaps = {}; +... +$(document).ready(function () { + for (var prop in Metamaps) { + + // this runs the init function within each sub-object on the Metamaps one + if (Metamaps.hasOwnProperty(prop) && + Metamaps[prop].hasOwnProperty('init') && + typeof (Metamaps[prop].init) == 'function' + ) { + Metamaps[prop].init(); + } + } +}); +Metamaps.GlobalUI = { +... +}; + +WHAT DOES IT MEAN? + + + +____________________________________________________________________ +