initial attempt at focussing input field when entering multiple topics
This commit is contained in:
parent
49084b98dd
commit
1efd78ad7b
5 changed files with 48 additions and 55 deletions
|
@ -63,7 +63,7 @@ Metamaps.Backbone.Map = Backbone.Model.extend({
|
||||||
authorizeToEdit: function (mapper) {
|
authorizeToEdit: function (mapper) {
|
||||||
if (mapper && (
|
if (mapper && (
|
||||||
this.get('permission') === 'commons' ||
|
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'))) {
|
this.get('user_id') === mapper.get('id'))) {
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
|
@ -350,9 +350,9 @@ Metamaps.Backbone.init = function () {
|
||||||
},
|
},
|
||||||
authorizeToEdit: function (mapper) {
|
authorizeToEdit: function (mapper) {
|
||||||
if (mapper &&
|
if (mapper &&
|
||||||
(this.get('calculated_permission') === 'commons' ||
|
(this.get('user_id') === mapper.get('id') ||
|
||||||
this.get('collaborator_ids').includes(mapper.get('id')) ||
|
this.get('calculated_permission') === 'commons' ||
|
||||||
this.get('user_id') === mapper.get('id'))) {
|
this.get('collaborator_ids').includes(mapper.get('id')))) {
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -254,7 +254,7 @@ Metamaps.Import = {
|
||||||
},
|
},
|
||||||
|
|
||||||
createTopicWithParameters: function (name, metacode_name, permission, desc,
|
createTopicWithParameters: function (name, metacode_name, permission, desc,
|
||||||
link, xloc, yloc, import_id) {
|
link, xloc, yloc, import_id, opts) {
|
||||||
var self = Metamaps.Import
|
var self = Metamaps.Import
|
||||||
$(document).trigger(Metamaps.Map.events.editedByActiveMapper)
|
$(document).trigger(Metamaps.Map.events.editedByActiveMapper)
|
||||||
var metacode = Metamaps.Metacodes.where({name: metacode_name})[0] || null
|
var metacode = Metamaps.Metacodes.where({name: metacode_name})[0] || null
|
||||||
|
@ -271,7 +271,8 @@ Metamaps.Import = {
|
||||||
permission: topic_permission,
|
permission: topic_permission,
|
||||||
defer_to_map_id: defer_to_map_id,
|
defer_to_map_id: defer_to_map_id,
|
||||||
desc: desc || "",
|
desc: desc || "",
|
||||||
link: link || ""
|
link: link || "",
|
||||||
|
calculated_permission: Metamaps.Active.Map.get('permission')
|
||||||
})
|
})
|
||||||
Metamaps.Topics.add(topic)
|
Metamaps.Topics.add(topic)
|
||||||
|
|
||||||
|
@ -288,7 +289,9 @@ Metamaps.Import = {
|
||||||
Metamaps.Mappings.add(mapping)
|
Metamaps.Mappings.add(mapping)
|
||||||
|
|
||||||
// this function also includes the creation of the topic in the database
|
// 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')
|
Metamaps.GlobalUI.hideDiv('#instructions')
|
||||||
},
|
},
|
||||||
|
|
|
@ -80,43 +80,24 @@ Metamaps.PasteInput = {
|
||||||
var import_id = null // don't store a cidMapping
|
var import_id = null // don't store a cidMapping
|
||||||
var permission = null // use default
|
var permission = null // use default
|
||||||
|
|
||||||
// try {
|
Metamaps.Import.createTopicWithParameters(
|
||||||
// // fetch title in 150ms or less
|
title,
|
||||||
// Promise.race([
|
'Reference', // metacode - todo fix
|
||||||
// new Promise(function(resolve, reject) {
|
permission,
|
||||||
// fetch(text).then(function(response) {
|
text, // desc - todo load from url?
|
||||||
// return response.text()
|
text, // link - todo fix because this isn't being POSTed
|
||||||
// }).then(function(html) {
|
coords.x,
|
||||||
// title = html.replace(/[\s\S]*<title>(.*)<\/title>[\s\S]*/m, '$1')
|
coords.y,
|
||||||
// resolve()
|
import_id,
|
||||||
// })
|
{
|
||||||
// }), new Promise(function(resolve, reject) {
|
success: function(topic) {
|
||||||
// window.setTimeout(function() {
|
Metamaps.TopicCard.showCard(topic.get('node'), function() {
|
||||||
// resolve()
|
$('#showcard #titleActivator').click()
|
||||||
// }, 150)
|
.find('textarea, input').focus()
|
||||||
// })
|
})
|
||||||
// ]).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
|
|
||||||
)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
handleJSON: function (text) {
|
handleJSON: function (text) {
|
||||||
|
|
|
@ -186,11 +186,10 @@ Metamaps.Topic = {
|
||||||
error: function () {}
|
error: function () {}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
/*
|
|
||||||
*
|
// opts is additional options in a hash
|
||||||
*
|
// TODO: move createNewInDB and permitCerateSYnapseAfter into opts
|
||||||
*/
|
renderTopic: function (mapping, topic, createNewInDB, permitCreateSynapseAfter, opts) {
|
||||||
renderTopic: function (mapping, topic, createNewInDB, permitCreateSynapseAfter) {
|
|
||||||
var self = Metamaps.Topic
|
var self = Metamaps.Topic
|
||||||
|
|
||||||
var nodeOnViz, tempPos
|
var nodeOnViz, tempPos
|
||||||
|
@ -265,18 +264,24 @@ Metamaps.Topic = {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var mappingSuccessCallback = function (mappingModel, response) {
|
var mappingSuccessCallback = function (mappingModel, response, topicModel) {
|
||||||
var newTopicData = {
|
var newTopicData = {
|
||||||
mappingid: mappingModel.id,
|
mappingid: mappingModel.id,
|
||||||
mappableid: mappingModel.get('mappable_id')
|
mappableid: mappingModel.get('mappable_id')
|
||||||
}
|
}
|
||||||
|
|
||||||
$(document).trigger(Metamaps.JIT.events.newTopic, [newTopicData])
|
$(document).trigger(Metamaps.JIT.events.newTopic, [newTopicData])
|
||||||
|
// call a success callback if provided
|
||||||
|
if (opts.success) {
|
||||||
|
opts.success(topicModel)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
var topicSuccessCallback = function (topicModel, response) {
|
var topicSuccessCallback = function (topicModel, response) {
|
||||||
if (Metamaps.Active.Map) {
|
if (Metamaps.Active.Map) {
|
||||||
mapping.save({ mappable_id: topicModel.id }, {
|
mapping.save({ mappable_id: topicModel.id }, {
|
||||||
success: mappingSuccessCallback,
|
success: function (model, response) {
|
||||||
|
mappingSuccessCallback(model, response, topicModel)
|
||||||
|
},
|
||||||
error: function (model, response) {
|
error: function (model, response) {
|
||||||
console.log('error saving mapping to database')
|
console.log('error saving mapping to database')
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ Metamaps.TopicCard = {
|
||||||
* Will open the Topic Card for the node that it's passed
|
* Will open the Topic Card for the node that it's passed
|
||||||
* @param {$jit.Graph.Node} node
|
* @param {$jit.Graph.Node} node
|
||||||
*/
|
*/
|
||||||
showCard: function (node) {
|
showCard: function (node, opts) {
|
||||||
var self = Metamaps.TopicCard
|
var self = Metamaps.TopicCard
|
||||||
|
|
||||||
var topic = node.getData('topic')
|
var topic = node.getData('topic')
|
||||||
|
@ -46,7 +46,11 @@ Metamaps.TopicCard = {
|
||||||
self.authorizedToEdit = topic.authorizeToEdit(Metamaps.Active.Mapper)
|
self.authorizedToEdit = topic.authorizeToEdit(Metamaps.Active.Mapper)
|
||||||
// populate the card that's about to show with the right topics data
|
// populate the card that's about to show with the right topics data
|
||||||
self.populateShowCard(topic)
|
self.populateShowCard(topic)
|
||||||
$('.showcard').fadeIn('fast')
|
return $('.showcard').fadeIn('fast', function() {
|
||||||
|
if (opts.complete) {
|
||||||
|
opts.complete()
|
||||||
|
}
|
||||||
|
})
|
||||||
},
|
},
|
||||||
hideCard: function () {
|
hideCard: function () {
|
||||||
var self = Metamaps.TopicCard
|
var self = Metamaps.TopicCard
|
||||||
|
@ -413,8 +417,8 @@ Metamaps.TopicCard = {
|
||||||
nodeValues.attachments = ''
|
nodeValues.attachments = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
var inmapsAr = topic.get('inmaps')
|
var inmapsAr = topic.get('inmaps') || []
|
||||||
var inmapsLinks = topic.get('inmapsLinks')
|
var inmapsLinks = topic.get('inmapsLinks') || []
|
||||||
nodeValues.inmaps = ''
|
nodeValues.inmaps = ''
|
||||||
if (inmapsAr.length < 6) {
|
if (inmapsAr.length < 6) {
|
||||||
for (i = 0; i < inmapsAr.length; i++) {
|
for (i = 0; i < inmapsAr.length; i++) {
|
||||||
|
|
Loading…
Reference in a new issue