| author | ymh <ymh.work@gmail.com> |
| Wed, 29 Jun 2016 22:48:10 +0200 | |
| changeset 625 | 4d67ae41b9b3 |
| parent 466 | 884b35feb04b |
| child 648 | e388117572d8 |
| permissions | -rw-r--r-- |
| 284 | 1 |
|
2 |
define(['jquery', 'underscore', 'requtils', 'renderer/baseeditor'], function ($, _, requtils, BaseEditor) { |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
3 |
'use strict'; |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
4 |
|
| 284 | 5 |
var Utils = requtils.getUtils(); |
6 |
||
7 |
/* EdgeEditor Begin */ |
|
8 |
||
9 |
//var EdgeEditor = Renderer.EdgeEditor = Utils.inherit(Renderer._BaseEditor); |
|
10 |
var EdgeEditor = Utils.inherit(BaseEditor); |
|
11 |
||
12 |
_(EdgeEditor.prototype).extend({ |
|
|
434
0d5998b32a7c
clean, and finalize lodash migration
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
13 |
_init: function() { |
|
0d5998b32a7c
clean, and finalize lodash migration
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
14 |
BaseEditor.prototype._init.apply(this); |
|
0d5998b32a7c
clean, and finalize lodash migration
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
15 |
this.template = this.options.templates['templates/edgeeditor.html']; |
|
0d5998b32a7c
clean, and finalize lodash migration
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
16 |
this.readOnlyTemplate = this.options.templates['templates/edgeeditor_readonly.html']; |
|
0d5998b32a7c
clean, and finalize lodash migration
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
17 |
}, |
| 284 | 18 |
draw: function() { |
19 |
var _model = this.source_representation.model, |
|
20 |
_from_model = _model.get("from"), |
|
21 |
_to_model = _model.get("to"), |
|
22 |
_created_by = _model.get("created_by") || Utils._USER_PLACEHOLDER(this.renkan), |
|
23 |
_template = (this.renderer.isEditable() ? this.template : this.readOnlyTemplate); |
|
24 |
this.editor_$ |
|
| 433 | 25 |
.html(_template({ |
| 284 | 26 |
edge: { |
27 |
has_creator: !!_model.get("created_by"), |
|
28 |
title: _model.get("title"), |
|
29 |
uri: _model.get("uri"), |
|
30 |
short_uri: Utils.shortenText((_model.get("uri") || "").replace(/^(https?:\/\/)?(www\.)?/,'').replace(/\/$/,''),40), |
|
31 |
description: _model.get("description"), |
|
|
458
423bdf56d103
migrated to style, added dash style to client + small refactoring for shapes + triangle
ymh <ymh.work@gmail.com>
parents:
434
diff
changeset
|
32 |
color: (_model.has("style") && _model.get("style").color) || _created_by.get("color"), |
|
423bdf56d103
migrated to style, added dash style to client + small refactoring for shapes + triangle
ymh <ymh.work@gmail.com>
parents:
434
diff
changeset
|
33 |
dash: _model.has("style") && _model.get("style").dash ? "checked" : "", |
|
459
98cae534083d
add node and edge stroke width + adjust text + arrow placement + conrol arrow visibility
ymh <ymh.work@gmail.com>
parents:
458
diff
changeset
|
34 |
arrow: (_model.has("style") && _model.get("style").arrow) || !_model.has("style") || (typeof _model.get("style").arrow === 'undefined') ? "checked" : "", |
|
98cae534083d
add node and edge stroke width + adjust text + arrow placement + conrol arrow visibility
ymh <ymh.work@gmail.com>
parents:
458
diff
changeset
|
35 |
thickness: (_model.has("style") && _model.get("style").thickness) || 1, |
| 284 | 36 |
from_title: _from_model.get("title"), |
37 |
to_title: _to_model.get("title"), |
|
|
458
423bdf56d103
migrated to style, added dash style to client + small refactoring for shapes + triangle
ymh <ymh.work@gmail.com>
parents:
434
diff
changeset
|
38 |
from_color: (_from_model.has("style") && _from_model.get("style").color) || (_from_model.get("created_by") || Utils._USER_PLACEHOLDER(this.renkan)).get("color"), |
|
423bdf56d103
migrated to style, added dash style to client + small refactoring for shapes + triangle
ymh <ymh.work@gmail.com>
parents:
434
diff
changeset
|
39 |
to_color: (_to_model.has("style") && _to_model.get("style").color) || (_to_model.get("created_by") || Utils._USER_PLACEHOLDER(this.renkan)).get("color"), |
| 284 | 40 |
created_by_color: _created_by.get("color"), |
41 |
created_by_title: _created_by.get("title") |
|
42 |
}, |
|
43 |
renkan: this.renkan, |
|
44 |
shortenText: Utils.shortenText, |
|
45 |
options: this.options |
|
46 |
})); |
|
47 |
this.redraw(); |
|
48 |
var _this = this, |
|
49 |
closeEditor = function() { |
|
50 |
_this.renderer.removeRepresentation(_this); |
|
|
459
98cae534083d
add node and edge stroke width + adjust text + arrow placement + conrol arrow visibility
ymh <ymh.work@gmail.com>
parents:
458
diff
changeset
|
51 |
_this.editor_$.find(".Rk-Edit-Size-Btn").off('click'); |
| 284 | 52 |
paper.view.draw(); |
53 |
}; |
|
54 |
this.editor_$.find(".Rk-CloseX").click(closeEditor); |
|
55 |
this.editor_$.find(".Rk-Edit-Goto").click(function() { |
|
56 |
if (!_model.get("uri")) { |
|
57 |
return false; |
|
58 |
} |
|
59 |
}); |
|
60 |
||
61 |
if (this.renderer.isEditable()) { |
|
62 |
||
|
625
4d67ae41b9b3
debounce node and edge edition instead of throttle
ymh <ymh.work@gmail.com>
parents:
466
diff
changeset
|
63 |
var onFieldChange = _.debounce(function() { |
|
434
0d5998b32a7c
clean, and finalize lodash migration
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
64 |
_.defer(function() { |
|
0d5998b32a7c
clean, and finalize lodash migration
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
65 |
if (_this.renderer.isEditable()) { |
|
0d5998b32a7c
clean, and finalize lodash migration
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
66 |
var _data = { |
| 433 | 67 |
title: _this.editor_$.find(".Rk-Edit-Title").val() |
|
434
0d5998b32a7c
clean, and finalize lodash migration
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
68 |
}; |
|
0d5998b32a7c
clean, and finalize lodash migration
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
69 |
if (_this.options.show_edge_editor_uri) { |
|
0d5998b32a7c
clean, and finalize lodash migration
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
70 |
_data.uri = _this.editor_$.find(".Rk-Edit-URI").val(); |
|
0d5998b32a7c
clean, and finalize lodash migration
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
71 |
} |
|
458
423bdf56d103
migrated to style, added dash style to client + small refactoring for shapes + triangle
ymh <ymh.work@gmail.com>
parents:
434
diff
changeset
|
72 |
if (_this.options.show_node_editor_style) { |
|
466
884b35feb04b
correct dash for edge + change text for view saves
ymh <ymh.work@gmail.com>
parents:
461
diff
changeset
|
73 |
var dash = _this.editor_$.find(".Rk-Edit-Dash").is(':checked'), |
|
884b35feb04b
correct dash for edge + change text for view saves
ymh <ymh.work@gmail.com>
parents:
461
diff
changeset
|
74 |
arrow = _this.editor_$.find(".Rk-Edit-Arrow").is(':checked'); |
|
884b35feb04b
correct dash for edge + change text for view saves
ymh <ymh.work@gmail.com>
parents:
461
diff
changeset
|
75 |
_data.style = _.assign( ((_model.has("style") && _.clone(_model.get("style"))) || {}), {dash: dash, arrow: arrow}); |
|
458
423bdf56d103
migrated to style, added dash style to client + small refactoring for shapes + triangle
ymh <ymh.work@gmail.com>
parents:
434
diff
changeset
|
76 |
} |
|
434
0d5998b32a7c
clean, and finalize lodash migration
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
77 |
_this.editor_$.find(".Rk-Edit-Goto").attr("href",_data.uri || "#"); |
|
0d5998b32a7c
clean, and finalize lodash migration
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
78 |
_model.set(_data); |
|
0d5998b32a7c
clean, and finalize lodash migration
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
79 |
paper.view.draw(); |
|
0d5998b32a7c
clean, and finalize lodash migration
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
80 |
} else { |
|
0d5998b32a7c
clean, and finalize lodash migration
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
81 |
closeEditor(); |
| 284 | 82 |
} |
|
434
0d5998b32a7c
clean, and finalize lodash migration
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
83 |
}); |
|
625
4d67ae41b9b3
debounce node and edge edition instead of throttle
ymh <ymh.work@gmail.com>
parents:
466
diff
changeset
|
84 |
},1000); |
| 284 | 85 |
|
86 |
this.editor_$.on("keyup", function(_e) { |
|
87 |
if (_e.keyCode === 27) { |
|
88 |
closeEditor(); |
|
89 |
} |
|
90 |
}); |
|
91 |
||
92 |
this.editor_$.find("input").on("keyup change paste", onFieldChange); |
|
93 |
||
94 |
this.editor_$.find(".Rk-Edit-Vocabulary").change(function() { |
|
95 |
var e = $(this), |
|
96 |
v = e.val(); |
|
97 |
if (v) { |
|
98 |
_this.editor_$.find(".Rk-Edit-Title").val(e.find(":selected").text()); |
|
99 |
_this.editor_$.find(".Rk-Edit-URI").val(v); |
|
100 |
onFieldChange(); |
|
101 |
} |
|
102 |
}); |
|
103 |
this.editor_$.find(".Rk-Edit-Direction").click(function() { |
|
104 |
if (_this.renderer.isEditable()) { |
|
105 |
_model.set({ |
|
106 |
from: _model.get("to"), |
|
107 |
to: _model.get("from") |
|
108 |
}); |
|
109 |
_this.draw(); |
|
110 |
} else { |
|
111 |
closeEditor(); |
|
112 |
} |
|
113 |
}); |
|
114 |
||
115 |
var _picker = _this.editor_$.find(".Rk-Edit-ColorPicker"); |
|
116 |
||
117 |
this.editor_$.find(".Rk-Edit-ColorPicker-Wrapper").hover( |
|
118 |
function(_e) { |
|
119 |
_e.preventDefault(); |
|
120 |
_picker.show(); |
|
121 |
}, |
|
122 |
function(_e) { |
|
123 |
_e.preventDefault(); |
|
124 |
_picker.hide(); |
|
125 |
} |
|
126 |
); |
|
127 |
||
128 |
_picker.find("li").hover( |
|
129 |
function(_e) { |
|
130 |
_e.preventDefault(); |
|
131 |
_this.editor_$.find(".Rk-Edit-Color").css("background", $(this).attr("data-color")); |
|
132 |
}, |
|
133 |
function(_e) { |
|
134 |
_e.preventDefault(); |
|
|
458
423bdf56d103
migrated to style, added dash style to client + small refactoring for shapes + triangle
ymh <ymh.work@gmail.com>
parents:
434
diff
changeset
|
135 |
_this.editor_$.find(".Rk-Edit-Color").css("background", (_model.has("style") && _model.get("style").color)|| (_model.get("created_by") || Utils._USER_PLACEHOLDER(_this.renkan)).get("color")); |
| 284 | 136 |
} |
137 |
).click(function(_e) { |
|
138 |
_e.preventDefault(); |
|
139 |
if (_this.renderer.isEditable()) { |
|
|
458
423bdf56d103
migrated to style, added dash style to client + small refactoring for shapes + triangle
ymh <ymh.work@gmail.com>
parents:
434
diff
changeset
|
140 |
_model.set("style", _.assign( ((_model.has("style") && _.clone(_model.get("style"))) || {}), {color: $(this).attr("data-color")})); |
| 284 | 141 |
_picker.hide(); |
142 |
paper.view.draw(); |
|
143 |
} else { |
|
144 |
closeEditor(); |
|
145 |
} |
|
146 |
}); |
|
|
459
98cae534083d
add node and edge stroke width + adjust text + arrow placement + conrol arrow visibility
ymh <ymh.work@gmail.com>
parents:
458
diff
changeset
|
147 |
var shiftThickness = function(n) { |
|
98cae534083d
add node and edge stroke width + adjust text + arrow placement + conrol arrow visibility
ymh <ymh.work@gmail.com>
parents:
458
diff
changeset
|
148 |
if (_this.renderer.isEditable()) { |
|
98cae534083d
add node and edge stroke width + adjust text + arrow placement + conrol arrow visibility
ymh <ymh.work@gmail.com>
parents:
458
diff
changeset
|
149 |
var _oldThickness = ((_model.has('style') && _model.get('style').thickness) || 1), |
|
98cae534083d
add node and edge stroke width + adjust text + arrow placement + conrol arrow visibility
ymh <ymh.work@gmail.com>
parents:
458
diff
changeset
|
150 |
_newThickness = n + _oldThickness; |
|
98cae534083d
add node and edge stroke width + adjust text + arrow placement + conrol arrow visibility
ymh <ymh.work@gmail.com>
parents:
458
diff
changeset
|
151 |
if(_newThickness < 1 ) { |
|
98cae534083d
add node and edge stroke width + adjust text + arrow placement + conrol arrow visibility
ymh <ymh.work@gmail.com>
parents:
458
diff
changeset
|
152 |
_newThickness = 1; |
|
98cae534083d
add node and edge stroke width + adjust text + arrow placement + conrol arrow visibility
ymh <ymh.work@gmail.com>
parents:
458
diff
changeset
|
153 |
} |
|
98cae534083d
add node and edge stroke width + adjust text + arrow placement + conrol arrow visibility
ymh <ymh.work@gmail.com>
parents:
458
diff
changeset
|
154 |
else if (_newThickness > _this.options.node_stroke_witdh_scale) { |
|
98cae534083d
add node and edge stroke width + adjust text + arrow placement + conrol arrow visibility
ymh <ymh.work@gmail.com>
parents:
458
diff
changeset
|
155 |
_newThickness = _this.options.node_stroke_witdh_scale; |
|
98cae534083d
add node and edge stroke width + adjust text + arrow placement + conrol arrow visibility
ymh <ymh.work@gmail.com>
parents:
458
diff
changeset
|
156 |
} |
|
98cae534083d
add node and edge stroke width + adjust text + arrow placement + conrol arrow visibility
ymh <ymh.work@gmail.com>
parents:
458
diff
changeset
|
157 |
if (_newThickness !== _oldThickness) { |
|
98cae534083d
add node and edge stroke width + adjust text + arrow placement + conrol arrow visibility
ymh <ymh.work@gmail.com>
parents:
458
diff
changeset
|
158 |
_this.editor_$.find("#Rk-Edit-Thickness-Value").text(_newThickness); |
|
98cae534083d
add node and edge stroke width + adjust text + arrow placement + conrol arrow visibility
ymh <ymh.work@gmail.com>
parents:
458
diff
changeset
|
159 |
_model.set("style", _.assign( ((_model.has("style") && _.clone(_model.get("style"))) || {}), {thickness: _newThickness})); |
|
98cae534083d
add node and edge stroke width + adjust text + arrow placement + conrol arrow visibility
ymh <ymh.work@gmail.com>
parents:
458
diff
changeset
|
160 |
paper.view.draw(); |
|
98cae534083d
add node and edge stroke width + adjust text + arrow placement + conrol arrow visibility
ymh <ymh.work@gmail.com>
parents:
458
diff
changeset
|
161 |
} |
|
98cae534083d
add node and edge stroke width + adjust text + arrow placement + conrol arrow visibility
ymh <ymh.work@gmail.com>
parents:
458
diff
changeset
|
162 |
} |
|
98cae534083d
add node and edge stroke width + adjust text + arrow placement + conrol arrow visibility
ymh <ymh.work@gmail.com>
parents:
458
diff
changeset
|
163 |
else { |
|
98cae534083d
add node and edge stroke width + adjust text + arrow placement + conrol arrow visibility
ymh <ymh.work@gmail.com>
parents:
458
diff
changeset
|
164 |
closeEditor(); |
|
98cae534083d
add node and edge stroke width + adjust text + arrow placement + conrol arrow visibility
ymh <ymh.work@gmail.com>
parents:
458
diff
changeset
|
165 |
} |
|
98cae534083d
add node and edge stroke width + adjust text + arrow placement + conrol arrow visibility
ymh <ymh.work@gmail.com>
parents:
458
diff
changeset
|
166 |
}; |
|
98cae534083d
add node and edge stroke width + adjust text + arrow placement + conrol arrow visibility
ymh <ymh.work@gmail.com>
parents:
458
diff
changeset
|
167 |
|
|
98cae534083d
add node and edge stroke width + adjust text + arrow placement + conrol arrow visibility
ymh <ymh.work@gmail.com>
parents:
458
diff
changeset
|
168 |
this.editor_$.find("#Rk-Edit-Thickness-Down").click(function() { |
|
98cae534083d
add node and edge stroke width + adjust text + arrow placement + conrol arrow visibility
ymh <ymh.work@gmail.com>
parents:
458
diff
changeset
|
169 |
shiftThickness(-1); |
|
98cae534083d
add node and edge stroke width + adjust text + arrow placement + conrol arrow visibility
ymh <ymh.work@gmail.com>
parents:
458
diff
changeset
|
170 |
return false; |
|
98cae534083d
add node and edge stroke width + adjust text + arrow placement + conrol arrow visibility
ymh <ymh.work@gmail.com>
parents:
458
diff
changeset
|
171 |
}); |
|
98cae534083d
add node and edge stroke width + adjust text + arrow placement + conrol arrow visibility
ymh <ymh.work@gmail.com>
parents:
458
diff
changeset
|
172 |
this.editor_$.find("#Rk-Edit-Thickness-Up").click(function() { |
|
98cae534083d
add node and edge stroke width + adjust text + arrow placement + conrol arrow visibility
ymh <ymh.work@gmail.com>
parents:
458
diff
changeset
|
173 |
shiftThickness(1); |
|
98cae534083d
add node and edge stroke width + adjust text + arrow placement + conrol arrow visibility
ymh <ymh.work@gmail.com>
parents:
458
diff
changeset
|
174 |
return false; |
|
98cae534083d
add node and edge stroke width + adjust text + arrow placement + conrol arrow visibility
ymh <ymh.work@gmail.com>
parents:
458
diff
changeset
|
175 |
}); |
| 284 | 176 |
} |
177 |
}, |
|
178 |
redraw: function() { |
|
| 447 | 179 |
if (this.options.popup_editor){ |
180 |
var _coords = this.source_representation.paper_coords; |
|
181 |
Utils.drawEditBox(this.options, _coords, this.editor_block, 5, this.editor_$); |
|
182 |
} |
|
| 284 | 183 |
this.editor_$.show(); |
184 |
paper.view.draw(); |
|
185 |
} |
|
| 433 | 186 |
}).value(); |
| 284 | 187 |
|
188 |
/* EdgeEditor End */ |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
189 |
|
| 284 | 190 |
return EdgeEditor; |
191 |
||
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
192 |
}); |