From 1cceaceb067c4513acee82f57c79a65daab8c09b Mon Sep 17 00:00:00 2001 From: Connor Turland Date: Thu, 16 Oct 2014 21:03:11 -0400 Subject: [PATCH] cannow handle multiple metacodes with same names --- app/assets/javascripts/lib/cloudcarousel.js | 4 +-- app/assets/javascripts/src/Metamaps.js | 40 ++++++++++----------- app/assets/stylesheets/application.css | 4 ++- app/views/maps/_newtopic.html.erb | 2 +- app/views/shared/_metacodeBgColors.html.erb | 2 +- app/views/shared/_switchmetacodes.html.erb | 2 +- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/app/assets/javascripts/lib/cloudcarousel.js b/app/assets/javascripts/lib/cloudcarousel.js index 31a9aa7a..db7633c7 100644 --- a/app/assets/javascripts/lib/cloudcarousel.js +++ b/app/assets/javascripts/lib/cloudcarousel.js @@ -208,7 +208,7 @@ jQuery.browser = browser; { $(options.titleBox).html( ($(event.target).attr('title') )); // METAMAPS CODE - Metamaps.Create.newTopic.metacode = $(event.target).attr('title'); + Metamaps.Create.newTopic.metacode = $(event.target).attr('data-id'); // NOT METAMAPS CODE var idx = $(event.target).data('itemIndex'); var frontIndex = event.data.frontIndex; @@ -246,7 +246,7 @@ jQuery.browser = browser; { if ( items[this.frontIndex] === undefined ) { return; } // Images might not have loaded yet. // METAMAPS CODE - Metamaps.Create.newTopic.metacode = $(items[this.frontIndex].image).attr('title'); + Metamaps.Create.newTopic.metacode = $(items[this.frontIndex].image).attr('data-id'); //$('img.cloudcarousel').css({"background":"none", "width":"","height":""}); //$(items[this.frontIndex].image).css({"width":"45px","height":"45px"}); // NOT METAMAPS CODE diff --git a/app/assets/javascripts/src/Metamaps.js b/app/assets/javascripts/src/Metamaps.js index 5c4bd5da..88059d31 100644 --- a/app/assets/javascripts/src/Metamaps.js +++ b/app/assets/javascripts/src/Metamaps.js @@ -410,37 +410,39 @@ Metamaps.Create = { return false; } - var codesToSwitchTo; + var codesToSwitchToIds; + var metacodeModels = new Metamaps.Backbone.MetacodeCollection(); Metamaps.Create.selectedMetacodeSetIndex = index; Metamaps.Create.selectedMetacodeSet = "metacodeset-" + set; if (!custom) { - codesToSwitchTo = $('#metacodeSwitchTabs' + set).attr('data-metacodes').split(','); + codesToSwitchToIds = $('#metacodeSwitchTabs' + set).attr('data-metacodes').split(','); $('.customMetacodeList li').addClass('toggledOff'); Metamaps.Create.selectedMetacodes = []; Metamaps.Create.selectedMetacodeNames = []; Metamaps.Create.newSelectedMetacodes = []; Metamaps.Create.newSelectedMetacodeNames = []; } - if (custom) { + else if (custom) { // uses .slice to avoid setting the two arrays to the same actual array Metamaps.Create.selectedMetacodes = Metamaps.Create.newSelectedMetacodes.slice(0); Metamaps.Create.selectedMetacodeNames = Metamaps.Create.newSelectedMetacodeNames.slice(0); - codesToSwitchTo = Metamaps.Create.selectedMetacodeNames.slice(0); + codesToSwitchToIds = Metamaps.Create.selectedMetacodes.slice(0); } // sort by name - codesToSwitchTo.sort(); - codesToSwitchTo.reverse(); + for (var i = 0; i < codesToSwitchToIds.length; i++) { + metacodeModels.add( Metamaps.Metacodes.get(codesToSwitchToIds[i]) ); + }; + metacodeModels.sort(); $('#metacodeImg, #metacodeImgTitle').empty(); $('#metacodeImg').removeData('cloudcarousel'); var newMetacodes = ""; - var metacode; - for (var i = 0; i < codesToSwitchTo.length; i++) { - metacode = Metamaps.Metacodes.findWhere({ name: codesToSwitchTo[i] }); - newMetacodes += '' + metacode.get('name') + ''; - }; + metacodeModels.each(function(metacode){ + newMetacodes += '' + metacode.get('name') + ''; + }); + $('#metacodeImg').empty().append(newMetacodes).CloudCarousel({ titleBox: $('#metacodeImgTitle'), yRadius: 40, @@ -772,13 +774,11 @@ Metamaps.TopicCard = { var metacodeLiClick = function () { selectingMetacode = false; - var metacodeName = $(this).find('.mSelectName').text(); - var metacode = Metamaps.Metacodes.findWhere({ - name: metacodeName - }); - $('.CardOnGraph').find('.metacodeTitle').html(metacodeName) + var metacodeId = parseInt($(this).attr('data-id')); + var metacode = Metamaps.Metacodes.get(metacodeId); + $('.CardOnGraph').find('.metacodeTitle').html(metacode.get('name')) .append('
') - .attr('class', 'metacodeTitle mbg' + metacodeName.replace(/\s/g, '')); + .attr('class', 'metacodeTitle mbg' + metacode.id); $('.CardOnGraph').find('.metacodeImage').css('background-image', 'url(' + metacode.get('icon') + ')'); topic.save({ metacode_id: metacode.id @@ -993,7 +993,7 @@ Metamaps.TopicCard = { nodeValues.synapse_count = topic.get("synapse_count").toString(); nodeValues.id = topic.isNew() ? topic.cid : topic.id; nodeValues.metacode = topic.getMetacode().get("name"); - nodeValues.metacode_class = 'mbg' + topic.getMetacode().get("name").replace(/\s/g, ''); + nodeValues.metacode_class = 'mbg' + topic.get('metacode_id'); nodeValues.imgsrc = topic.getMetacode().get("icon"); nodeValues.name = topic.get("name"); nodeValues.userid = topic.get("user_id"); @@ -3285,9 +3285,7 @@ Metamaps.Topic = { $(document).trigger(Metamaps.Map.events.editedByActiveMapper); - var metacode = Metamaps.Metacodes.findWhere({ - name: Metamaps.Create.newTopic.metacode - }); + var metacode = Metamaps.Metacodes.get(Metamaps.Create.newTopic.metacode); var topic = new Metamaps.Backbone.Topic({ name: Metamaps.Create.newTopic.name, diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 9c7268df..c6002195 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -1669,8 +1669,10 @@ float: left; background-position: 0 0; } /* only display share button if 'public' or 'commons' */ +/* we're currently disabling this, as we're not ready for it +and it won't be important on password protected instances */ .shareable .mapInfoShare { - display: block; + display: none; } .mapInfoDelete { background-image: url(delete_mapinfo.png); diff --git a/app/views/maps/_newtopic.html.erb b/app/views/maps/_newtopic.html.erb index 048f453f..f22920bb 100644 --- a/app/views/maps/_newtopic.html.erb +++ b/app/views/maps/_newtopic.html.erb @@ -13,7 +13,7 @@ <% end %> <% @metacodes.sort! {|m1,m2| m2.name.downcase <=> m1.name.downcase }.rotate!(-1) %> <% @metacodes.each do |metacode| %> - <%= metacode.name %> + <%= metacode.name %> <% end %> <%= form.text_field :name, :maxlength => 140, :placeholder => "title..." %> diff --git a/app/views/shared/_metacodeBgColors.html.erb b/app/views/shared/_metacodeBgColors.html.erb index a1aa030c..09396a3b 100644 --- a/app/views/shared/_metacodeBgColors.html.erb +++ b/app/views/shared/_metacodeBgColors.html.erb @@ -1,7 +1,7 @@