summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/consts.js7
-rw-r--r--scripts/history.js53
-rw-r--r--scripts/rhizicore.js19
-rw-r--r--scripts/textanalysis.ui.js14
4 files changed, 38 insertions, 55 deletions
diff --git a/scripts/consts.js b/scripts/consts.js
index 927a30d3..d1e3dca4 100644
--- a/scripts/consts.js
+++ b/scripts/consts.js
@@ -1,5 +1,10 @@
define('consts', function() {
+ // TODO: enums, sometime
return {
- RECORD_LINKS: 'record_links',
+ APPLIED_GRAPH_DIFF: 'graph_diff',
+ KEYSTROKES: 'keystrokes',
+ KEYSTROKE_WHERE_EDIT_NODE: 'keystroke_where_edit_node',
+ KEYSTROKE_WHERE_DOCUMENT: 'keystroke_where_document',
+ KEYSTROKE_WHERE_TEXTANALYSIS: 'keystroke_where_textanalysis',
};
});
diff --git a/scripts/history.js b/scripts/history.js
index e99cbb08..5cc77eec 100644
--- a/scripts/history.js
+++ b/scripts/history.js
@@ -22,15 +22,16 @@ function History(user) {
var that = this;
this.records = [];
this.user = user;
- signal.slot(consts.RECORD_LINKS, function(obj) {
- return that.record_links(obj)
+ signal.slot(consts.APPLIED_GRAPH_DIFF, function(obj) {
+ return that.record_graph_diff(obj)
+ });
+ signal.slot(consts.KEYSTROKES, function(obj) {
+ return that.record_keystrokes(obj);
});
}
var ACTION_KEYSTROKES = 'ACTION_KEYSTROKES';
-var ACTION_MOUSE = 'ACTION_MOUSE';
-var ACTION_GRAPH_ADD = 'ACTION_GRAPH_ADD';
-var ACTION_GRAPH_DELETE = 'ACTION_GRAPH_DELETE';
+var ACTION_GRAPH_DIFF = 'ACTION_GRAPH_DIFF';
var KEYSTROKE_WHERE_TEXTANALYSIS = 'KEYSTROKE_WHERE_TEXTANALYSIS';
var KEYSTROKE_WHERE_DOCUMENT = 'KEYSTROKE_WHERE_DOCUMENT';
@@ -58,47 +59,31 @@ History.prototype.clear_history = function()
this.records = [];
}
-History.prototype.record_nodes_removal = function(ids)
-{
- this.record({
- 'action': ACTION_GRAPH_DELETE,
- 'node_ids': ids
- });
-}
-
-History.prototype.record_links = function(links)
+History.prototype.record_graph_diff = function(obj)
{
- if (links === undefined || links.length === undefined || links.length <= 0) {
- throw "Invalid arguments"
- }
this.record({
- 'action': ACTION_GRAPH_ADD,
- 'nodes': [],
- 'links': links
- });
+ action: ACTION_GRAPH_DIFF,
+ nodes: {add: obj.nodes && obj.nodes.add, remove: obj.nodes && obj.nodes.remove,
+ change: obj.nodes && obj.nodes.change},
+ links: {add: obj.links && obj.links.add, remove: obj.links && obj.links.remove,
+ change: obj.links && obj.links.change},
+ });
}
-History.prototype.record_nodes = function(nodes)
+History.prototype.record_keystrokes = function(obj)
{
- if (nodes === undefined || nodes.length === undefined || nodes.length <= 0) {
- throw "Invalid arguments"
- }
- this.record({'action': ACTION_GRAPH_ADD,
- 'nodes': nodes,
- 'links': []
- });
-}
+ var where = obj.where,
+ keys = obj.keys;
-History.prototype.record_keystrokes = function(where, keys)
-{
- if (keys === undefined || keys.length === undefined || keys.length <= 0) {
+ if (where === undefined || keys === undefined || keys.length === undefined ||
+ keys.length <= 0) {
throw "Invalid arguments";
}
keys = keys.filter(function(k) { return k !== undefined; });
if (keys.length == 0) {
return;
}
- this.record({'action': ACTION_KEYSTROKES,
+ this.record({action: ACTION_KEYSTROKES,
'keys': keys,
'where': where
});
diff --git a/scripts/rhizicore.js b/scripts/rhizicore.js
index 1b4bcbb3..de823882 100644
--- a/scripts/rhizicore.js
+++ b/scripts/rhizicore.js
@@ -40,8 +40,9 @@ function myGraph(el) {
start:0,
end:0,
status:"unknown"});
- if (new_node && this.history !== undefined) {
- this.history.record_nodes([new_node]);
+ if (new_node) {
+ signal.signal(consts.APPLIED_GRAPH_DIFF, [{
+ nodes: {add: [new_node]}}]);
}
}
@@ -79,9 +80,7 @@ function myGraph(el) {
if (index !== undefined) {
nodes.splice(index, 1);
}
- if (this.history != undefined) {
- this.history.record_nodes_removal([id]);
- }
+ signal.signal(consts.APPLIED_GRAPH_DIFF, [{nodes: {removed: [id]}}]);
}
this.removeNodes = function(state) {
@@ -99,8 +98,8 @@ function myGraph(el) {
nodes.splice(index, 1);
}
}
- if (ns.length > 0 && this.history !== undefined) {
- this.history.record_nodes_removal(ns.map(function(n) { return n.id; }));
+ if (ns.length > 0) {
+ signal.signal(consts.APPLIED_GRAPH_DIFF, [{nodes: {removed: ns.map(function(n) { return n.id; })}}]);
}
}
@@ -260,7 +259,7 @@ function myGraph(el) {
"state": state
};
links.push(link);
- signal.signal(consts.RECORD_LINKS, [[link]]);
+ signal.signal(consts.APPLIED_GRAPH_DIFF, [{links: {add: [link]}}]);
} else {
found.name = name;
found.state = state;
@@ -1043,9 +1042,7 @@ function AddedUnique(newnode) {
$('#editform').keypress(function(e) {
- if (graph.history !== undefined) {
- graph.history.record_keystrokes(history.KEYSTROKE_WHERE_EDIT_NODE, [e.which]);
- }
+ signal.signal(consts.KEYSTROKES, [{where: consts.KEYSTROKE_WHERE_EDIT_NODE, keys: [e.which]}]);
if (e.which == 13) {
$('.editinfo').css('top', -100);
$('.editinfo').css('left', 0);
diff --git a/scripts/textanalysis.ui.js b/scripts/textanalysis.ui.js
index bafc5134..4881d83c 100644
--- a/scripts/textanalysis.ui.js
+++ b/scripts/textanalysis.ui.js
@@ -1,4 +1,5 @@
-define('textanalysis.ui', ['autocomplete', 'rhizicore', 'textanalysis', 'history'], function(autocomplete, RZ, textanalysis, history) {
+define('textanalysis.ui', ['autocomplete', 'rhizicore', 'textanalysis', 'signal', 'consts'],
+ function(autocomplete, RZ, textanalysis, signal, consts) {
var text = ""; // Last text of sentence
var element_name = '#textanalyser';
var element = $(element_name);
@@ -74,10 +75,7 @@ return {
});
$(document).keydown(function(e) {
-
- if (RZ.graph.history !== undefined) {
- RZ.graph.history.record_keystrokes(history.KEYSTROKE_WHERE_DOCUMENT, [e.KeyCode]);
- }
+ signal.signal(consts.KEYSTROKES, [{where: consts.KEYSTROKE_WHERE_DOCUMENT, keys: [e.keyCode]}]);
if (e.keyCode == 9) {//TAB
e.preventDefault();
changeType(e.shiftKey ? "up" : "down", textanalysis.lastnode());
@@ -104,10 +102,8 @@ return {
});
element.keypress(function(e) {
- if (RZ.graph.history !== undefined) {
- RZ.graph.history.record_keystrokes(history.KEYSTROKE_WHERE_TEXTANALYSIS, [e.which]);
- }
- if (e.which == 13) {
+ signal.signal(consts.KEYSTROKES, [{where: consts.KEYSTROKE_WHERE_TEXTANALYSIS, keys:[e.which]}]);
+ if (e.which == 13) {
if(!suggestionChange) {
text = element.val();
element.val("");