summaryrefslogtreecommitdiff
path: root/src/client/messages.js
blob: 655b0d29a6f6140282c6b726847d12e532e11625 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
    This file is part of rhizi, a collaborative knowledge graph editor.
    Copyright (C) 2014-2015  Rhizi

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published
    by the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

define( ['underscore', 'util', 'model/graph'],
function (_,            util,         graph) {



function delete_nodes_links_message(nodes, links) {
    util.assert(nodes && links && nodes.length && links.length && nodes.length + links.length > 0);

    return delete_nodes_links_message_by_name(nodes, links);
}

function delete_nodes_links_message_by_name(nodes, links)
{
    var middle,
        node_names = _.map(_.map(nodes, 'name'), quoted),
        link_names = _.map(_.map(links, 'name'), quoted);

    if (nodes.length > 0 && links.length > 0) {
        middle = english_conjunction(node_names) + ', and ' + english_conjunction(link_names) + ' connections';
    } else if (nodes.length > 0) {
        middle = english_conjunction(node_names);
    } else {
        middle = english_conjunction(link_names);
    }
    return 'Delete ' + middle + '?';
}

function quoted(name)
{
    if (name.indexOf(' ') == -1) {
        return name;
    }
    return '"' + name + '"'
}

function english_conjunction(names)
{
    if (names.length == 1) {
        return names[0];
    }
    return names.slice(0, names.length - 1).join(', ') + ' and ' + names[names.length - 1];
}

function delete_nodes_links_message_by_number(type, nodes, links) {
    var count_nodes = nodes.length,
        count_links = links.length,
        make_descriptor = function (type, count) { return count > 1 ? '' + count + ' ' + type + 's' : 'a ' + type; },
        descriptor = make_descriptor('node', count_nodes) +
            (count_links > 0 && count_nodes > 0 ? ' and ' : '') + make_descriptor('link', count_links);

    return 'You are about to delete ' + descriptor + ', are you sure you want to do that?' ;
}

return {
    delete_nodes_links_message: delete_nodes_links_message,
};
});