smoother synapse creation with clicks/tabs

This commit is contained in:
Devin Howard 2016-02-11 14:54:00 +08:00
parent 48863ce246
commit 056ef2b5b6
2 changed files with 13 additions and 7 deletions

View file

@ -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;

View file

@ -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)