From 056ef2b5b64b9a95a6cb3fa8a075cf7181ecdab9 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Thu, 11 Feb 2016 14:54:00 +0800 Subject: [PATCH] smoother synapse creation with clicks/tabs --- app/assets/javascripts/src/Metamaps.js.erb | 16 +++++++++++----- app/controllers/synapses_controller.rb | 4 ++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/src/Metamaps.js.erb b/app/assets/javascripts/src/Metamaps.js.erb index 3f0e0ae3..fb636f11 100644 --- a/app/assets/javascripts/src/Metamaps.js.erb +++ b/app/assets/javascripts/src/Metamaps.js.erb @@ -736,10 +736,6 @@ Metamaps.Create = { init: function () { var self = Metamaps.Create.newSynapse; - $('#synapse_desc').keyup(function () { - Metamaps.Create.newSynapse.description = $(this).val(); - }); - var synapseBloodhound = new Bloodhound({ datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'), queryTokenizer: Bloodhound.tokenizers.whitespace, @@ -795,6 +791,16 @@ Metamaps.Create = { }] ); + $('#synapse_desc').keyup(function () { + Metamaps.Create.newSynapse.description = $(this).val(); + }); + + $('#synapse_desc').focusout(function() { + // Metamaps.Create.newSynapse.description = $(this).val(); + Metamaps.Synapse.createSynapseLocally(); + }); + + $('#synapse_desc').bind('typeahead:select', function (event, datum, dataset) { if (datum.id) { // if they clicked on an existing synapse get it Metamaps.Synapse.getSynapseFromAutocomplete(datum.id); @@ -811,7 +817,7 @@ Metamaps.Create = { topic2id: null, newSynapseId: null, open: function () { - $('#new_synapse').fadeIn('fast', function () { + $('#new_synapse').fadeIn(100, function () { $('#synapse_desc').focus(); }); Metamaps.Create.newSynapse.beingCreated = true; diff --git a/app/controllers/synapses_controller.rb b/app/controllers/synapses_controller.rb index 2c3c08d0..f19dc053 100644 --- a/app/controllers/synapses_controller.rb +++ b/app/controllers/synapses_controller.rb @@ -22,7 +22,7 @@ class SynapsesController < ApplicationController # POST /synapses.json def create @synapse = Synapse.new(synapse_params) - @synapse.update_attribute :desc, "" if @synapse.desc.nil? + @synapse.desc = "" if @synapse.desc.nil? respond_to do |format| if @synapse.save @@ -37,7 +37,7 @@ class SynapsesController < ApplicationController # PUT /synapses/1.json def update @synapse = Synapse.find(params[:id]) - @synapse.update_attribute :desc, "" if @synapse.desc.nil? + @synapse.desc = "" if @synapse.desc.nil? respond_to do |format| if @synapse.update_attributes(synapse_params)