fixes #720 double topic create when pinned (#732)

This commit is contained in:
Connor Turland 2016-10-06 10:37:01 -04:00 committed by GitHub
parent b52523e7be
commit 658f102a4e
2 changed files with 18 additions and 10 deletions

View file

@ -194,6 +194,7 @@ const Create = {
// tell the autocomplete to submit the form with the topic you clicked on if you pick from the autocomplete
$('#topic_name').bind('typeahead:select', function (event, datum, dataset) {
Create.newTopic.beingCreated = false
if (datum.rtype === 'topic') {
Topic.getTopicFromAutocomplete(datum.id)
} else if (datum.rtype === 'map') {
@ -235,19 +236,20 @@ const Create = {
GlobalUI.hideDiv('#instructions')
},
hide: function (force) {
if (Create.newTopic.beingCreated === false) return
if (force || !Create.newTopic.pinned) {
$('#new_topic').fadeOut('fast')
Create.newTopic.beingCreated = false
}
if (force) {
$('.pinCarousel').removeClass('isPinned')
Create.newTopic.pinned = false
}
$('#topic_name').typeahead('val', '')
if (Metamaps.Topics.length === 0) {
GlobalUI.showDiv('#instructions')
}
Create.newTopic.beingCreated = false
},
reset: function () {
$('#topic_name').typeahead('val', '')
}
},
newSynapse: {

View file

@ -330,16 +330,21 @@ const Topic = {
Metamaps.Mappings.add(mapping)
// these can't happen until the value is retrieved, which happens in the line above
Create.newTopic.hide()
if (!Create.newTopic.pinned) Create.newTopic.hide()
Create.newTopic.reset()
self.renderTopic(mapping, topic, true, true) // this function also includes the creation of the topic in the database
},
getTopicFromAutocomplete: function (id) {
var self = Topic
// hide the 'double-click to add a topic' message
GlobalUI.hideDiv('#instructions')
$(document).trigger(Map.events.editedByActiveMapper)
Create.newTopic.hide()
if (!Create.newTopic.pinned) Create.newTopic.hide()
Create.newTopic.reset()
self.get(id, (topic) => {
if (Create.newTopic.pinned) {
@ -354,18 +359,16 @@ const Topic = {
Metamaps.Mappings.add(mapping)
self.renderTopic(mapping, topic, true, true)
// this blocked the enterKeyHandler from creating a new topic as well
if (Create.newTopic.pinned) Create.newTopic.beingCreated = true
})
},
getMapFromAutocomplete: function (data) {
var self = Metamaps.Topic
// hide the 'double-click to add a topic' message
Metamaps.GlobalUI.hideDiv('#instructions')
$(document).trigger(Metamaps.Map.events.editedByActiveMapper)
var metacode = Metamaps.Metacodes.findWhere({ name: 'Metamap' })
var topic = new Metamaps.Backbone.Topic({
name: data.name,
metacode_id: metacode.id,
@ -383,9 +386,12 @@ const Topic = {
Metamaps.Mappings.add(mapping)
// these can't happen until the value is retrieved, which happens in the line above
Metamaps.Create.newTopic.hide()
if (!Create.newTopic.pinned) Create.newTopic.hide()
Create.newTopic.reset()
self.renderTopic(mapping, topic, true, true) // this function also includes the creation of the topic in the database
// this blocked the enterKeyHandler from creating a new topic as well
if (Create.newTopic.pinned) Create.newTopic.beingCreated = true
},
getTopicFromSearch: function (event, id) {
var self = Topic