initial attempt at focussing input field when entering multiple topics

This commit is contained in:
Devin Howard 2016-09-21 14:27:49 +08:00
parent 49084b98dd
commit 1efd78ad7b
5 changed files with 48 additions and 55 deletions

View file

@ -63,7 +63,7 @@ Metamaps.Backbone.Map = Backbone.Model.extend({
authorizeToEdit: function (mapper) {
if (mapper && (
this.get('permission') === 'commons' ||
this.get('collaborator_ids').includes(mapper.get('id')) ||
(this.get('collaborator_ids') || []).includes(mapper.get('id')) ||
this.get('user_id') === mapper.get('id'))) {
return true
} else {
@ -350,9 +350,9 @@ Metamaps.Backbone.init = function () {
},
authorizeToEdit: function (mapper) {
if (mapper &&
(this.get('calculated_permission') === 'commons' ||
this.get('collaborator_ids').includes(mapper.get('id')) ||
this.get('user_id') === mapper.get('id'))) {
(this.get('user_id') === mapper.get('id') ||
this.get('calculated_permission') === 'commons' ||
this.get('collaborator_ids').includes(mapper.get('id')))) {
return true
} else {
return false

View file

@ -254,7 +254,7 @@ Metamaps.Import = {
},
createTopicWithParameters: function (name, metacode_name, permission, desc,
link, xloc, yloc, import_id) {
link, xloc, yloc, import_id, opts) {
var self = Metamaps.Import
$(document).trigger(Metamaps.Map.events.editedByActiveMapper)
var metacode = Metamaps.Metacodes.where({name: metacode_name})[0] || null
@ -271,7 +271,8 @@ Metamaps.Import = {
permission: topic_permission,
defer_to_map_id: defer_to_map_id,
desc: desc || "",
link: link || ""
link: link || "",
calculated_permission: Metamaps.Active.Map.get('permission')
})
Metamaps.Topics.add(topic)
@ -288,7 +289,9 @@ Metamaps.Import = {
Metamaps.Mappings.add(mapping)
// this function also includes the creation of the topic in the database
Metamaps.Topic.renderTopic(mapping, topic, true, true)
Metamaps.Topic.renderTopic(mapping, topic, true, true, {
success: opts.success
})
Metamaps.GlobalUI.hideDiv('#instructions')
},

View file

@ -80,43 +80,24 @@ Metamaps.PasteInput = {
var import_id = null // don't store a cidMapping
var permission = null // use default
// try {
// // fetch title in 150ms or less
// Promise.race([
// new Promise(function(resolve, reject) {
// fetch(text).then(function(response) {
// return response.text()
// }).then(function(html) {
// title = html.replace(/[\s\S]*<title>(.*)<\/title>[\s\S]*/m, '$1')
// resolve()
// })
// }), new Promise(function(resolve, reject) {
// window.setTimeout(function() {
// resolve()
// }, 150)
// })
// ]).then(function() {
// finish()
// }).catch(function(error) {
// throw error
// })
// } catch (err) {
// console.warn("Your browser can't fetch the title") // TODO move to webpack to avoid this error
// }
finish()
function finish() {
Metamaps.Import.createTopicWithParameters(
title,
'Reference', // metacode - todo fix
permission,
text, // desc - todo load from url?
text, // link - todo fix because this isn't being POSTed
coords.x,
coords.y,
import_id
)
}
Metamaps.Import.createTopicWithParameters(
title,
'Reference', // metacode - todo fix
permission,
text, // desc - todo load from url?
text, // link - todo fix because this isn't being POSTed
coords.x,
coords.y,
import_id,
{
success: function(topic) {
Metamaps.TopicCard.showCard(topic.get('node'), function() {
$('#showcard #titleActivator').click()
.find('textarea, input').focus()
})
}
}
)
},
handleJSON: function (text) {

View file

@ -186,11 +186,10 @@ Metamaps.Topic = {
error: function () {}
})
},
/*
*
*
*/
renderTopic: function (mapping, topic, createNewInDB, permitCreateSynapseAfter) {
// opts is additional options in a hash
// TODO: move createNewInDB and permitCerateSYnapseAfter into opts
renderTopic: function (mapping, topic, createNewInDB, permitCreateSynapseAfter, opts) {
var self = Metamaps.Topic
var nodeOnViz, tempPos
@ -265,18 +264,24 @@ Metamaps.Topic = {
})
}
var mappingSuccessCallback = function (mappingModel, response) {
var mappingSuccessCallback = function (mappingModel, response, topicModel) {
var newTopicData = {
mappingid: mappingModel.id,
mappableid: mappingModel.get('mappable_id')
}
$(document).trigger(Metamaps.JIT.events.newTopic, [newTopicData])
// call a success callback if provided
if (opts.success) {
opts.success(topicModel)
}
}
var topicSuccessCallback = function (topicModel, response) {
if (Metamaps.Active.Map) {
mapping.save({ mappable_id: topicModel.id }, {
success: mappingSuccessCallback,
success: function (model, response) {
mappingSuccessCallback(model, response, topicModel)
},
error: function (model, response) {
console.log('error saving mapping to database')
}

View file

@ -37,7 +37,7 @@ Metamaps.TopicCard = {
* Will open the Topic Card for the node that it's passed
* @param {$jit.Graph.Node} node
*/
showCard: function (node) {
showCard: function (node, opts) {
var self = Metamaps.TopicCard
var topic = node.getData('topic')
@ -46,7 +46,11 @@ Metamaps.TopicCard = {
self.authorizedToEdit = topic.authorizeToEdit(Metamaps.Active.Mapper)
// populate the card that's about to show with the right topics data
self.populateShowCard(topic)
$('.showcard').fadeIn('fast')
return $('.showcard').fadeIn('fast', function() {
if (opts.complete) {
opts.complete()
}
})
},
hideCard: function () {
var self = Metamaps.TopicCard
@ -413,8 +417,8 @@ Metamaps.TopicCard = {
nodeValues.attachments = ''
}
var inmapsAr = topic.get('inmaps')
var inmapsLinks = topic.get('inmapsLinks')
var inmapsAr = topic.get('inmaps') || []
var inmapsLinks = topic.get('inmapsLinks') || []
nodeValues.inmaps = ''
if (inmapsAr.length < 6) {
for (i = 0; i < inmapsAr.length; i++) {