show/hide add a topic instructions more consistently

This commit is contained in:
Devin Howard 2016-09-25 22:27:11 +08:00
parent 17870e7a4c
commit c20e503785
5 changed files with 31 additions and 15 deletions

View file

@ -98,7 +98,6 @@ _Backbone.Map = Backbone.Model.extend({
$.ajax({
url: '/maps/' + this.id + '/contains.json',
success: start,
error: errorFunc,
async: false
})
},

View file

@ -1,6 +1,7 @@
/* global Metamaps, $ */
import _ from 'lodash'
import outdent from 'outdent'
import Active from './Active'
import Filter from './Filter'
@ -52,9 +53,8 @@ const Control = {
var n = Selected.Nodes.length
var e = Selected.Edges.length
var ntext = n == 1 ? '1 topic' : n + ' topics'
var etext = e == 1 ? '1 synapse' : e + ' synapses'
var text = 'You have ' + ntext + ' and ' + etext + ' selected. '
var ntext = n === 1 ? '1 topic' : n + ' topics'
var etext = e === 1 ? '1 synapse' : e + ' synapses'
var authorized = Active.Map.authorizeToEdit(Active.Mapper)
@ -63,11 +63,18 @@ const Control = {
return
}
var r = confirm(text + 'Are you sure you want to permanently delete them all? This will remove them from all maps they appear on.')
if (r == true) {
var r = confirm(outdent`
You have ${ntext} and ${etext} selected. Are you sure you want
to permanently delete them all? This will remove them from all
maps they appear on.`)
if (r) {
Control.deleteSelectedEdges()
Control.deleteSelectedNodes()
}
if (Metamaps.Topics.length === 0) {
GlobalUI.showDiv('#instructions')
}
},
deleteSelectedNodes: function () { // refers to deleting topics permanently
if (!Active.Map) return
@ -191,7 +198,7 @@ const Control = {
duration: 500
})
setTimeout(function () {
if (nodeid == Visualize.mGraph.root) { // && Visualize.type === "RGraph"
if (nodeid === Visualize.mGraph.root) { // && Visualize.type === "RGraph"
var newroot = _.find(graph.graph.nodes, function (n) { return n.id !== nodeid; })
graph.root = newroot ? newroot.id : null
}
@ -231,7 +238,7 @@ const Control = {
color: Settings.colors.synapses.normal
})
if (Mouse.edgeHoveringOver == edge) {
if (Mouse.edgeHoveringOver === edge) {
edge.setDataset('current', {
showDesc: true,
lineWidth: 4
@ -414,8 +421,8 @@ const Control = {
}
}
var nString = nCount == 1 ? (nCount.toString() + ' topic and ') : (nCount.toString() + ' topics and ')
var sString = sCount == 1 ? (sCount.toString() + ' synapse') : (sCount.toString() + ' synapses')
var nString = nCount === 1 ? (nCount.toString() + ' topic and ') : (nCount.toString() + ' topics and ')
var sString = sCount === 1 ? (sCount.toString() + ' synapse') : (sCount.toString() + ' synapses')
var message = nString + sString + ' you created updated to ' + permission
GlobalUI.notifyUser(message)
@ -444,7 +451,7 @@ const Control = {
}
}
var nString = nCount == 1 ? (nCount.toString() + ' topic') : (nCount.toString() + ' topics')
var nString = nCount === 1 ? (nCount.toString() + ' topic') : (nCount.toString() + ' topics')
var message = nString + ' you can edit updated to ' + metacode.get('name')
GlobalUI.notifyUser(message)

View file

@ -13,6 +13,7 @@ import GlobalUI from './GlobalUI'
* Dependencies:
* - Metamaps.Backbone
* - Metamaps.Metacodes
* - Metamaps.Topics
*/
const Create = {
@ -223,8 +224,10 @@ const Create = {
})
Create.newTopic.beingCreated = true
Create.newTopic.name = ''
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
@ -234,6 +237,9 @@ const Create = {
Create.newTopic.pinned = false
}
$('#topic_name').typeahead('val', '')
if (Metamaps.Topics.length === 0) {
GlobalUI.showDiv('#instructions')
}
}
},
newSynapse: {

View file

@ -148,11 +148,14 @@ const JIT = {
if (Metamaps.Mappings) Metamaps.Mappings.remove(mapping)
})
// set up addTopic instructions in case they delete all the topics
// i.e. if there are 0 topics at any time, it should have instructions again
$('#instructions div').hide()
if (Metamaps.Active.Map.authorizeToEdit(Active.Mapper)) {
$('#instructions div.addTopic').show()
}
if (self.vizData.length == 0) {
$('#instructions div').hide()
if (Metamaps.Active.Map.authorizeToEdit(Active.Mapper)) {
$('#instructions div.addTopic').show()
}
GlobalUI.showDiv('#instructions')
Visualize.loadLater = true
} else {

View file

@ -29,6 +29,7 @@
"csv-parse": "1.1.7",
"lodash": "4.16.1",
"node-uuid": "1.4.7",
"outdent": "0.2.1",
"react": "15.3.2",
"react-dom": "15.3.2",
"socket.io": "0.9.12",