| author | rougeronj |
| Fri, 02 Oct 2015 18:15:48 +0200 | |
| changeset 575 | 3e48b1672ace |
| parent 570 | 9698b3c8f31a |
| child 576 | 1e1791dfc9e4 |
| permissions | -rw-r--r-- |
| 284 | 1 |
|
| 555 | 2 |
define(['jquery', 'underscore', 'filesaver', 'requtils', 'renderer/miniframe', 'screenfull'], function ($, _, filesaver, requtils, MiniFrame, Screenfull) { |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
3 |
'use strict'; |
| 555 | 4 |
|
| 284 | 5 |
var Utils = requtils.getUtils(); |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
6 |
|
| 284 | 7 |
/* Scene Begin */ |
8 |
||
9 |
var Scene = function(_renkan) { |
|
10 |
this.renkan = _renkan; |
|
11 |
this.$ = $(".Rk-Render"); |
|
12 |
this.representations = []; |
|
|
419
4f458e6d32bd
export the templates of scene and edgeeditor to html files
rougeronj
parents:
414
diff
changeset
|
13 |
this.$.html(_renkan.options.templates['templates/scene.html'](_renkan)); |
| 284 | 14 |
this.onStatusChange(); |
15 |
this.canvas_$ = this.$.find(".Rk-Canvas"); |
|
16 |
this.labels_$ = this.$.find(".Rk-Labels"); |
|
|
445
705a2e9c6c9d
Add popup_editor and editor_panel option to allow the editor panel to bin in an external div
rougeronj
parents:
435
diff
changeset
|
17 |
if (!_renkan.options.popup_editor){ |
| 447 | 18 |
this.editor_$ = $("#" + _renkan.options.editor_panel); |
19 |
}else{ |
|
20 |
this.editor_$ = this.$.find(".Rk-Editor"); |
|
|
445
705a2e9c6c9d
Add popup_editor and editor_panel option to allow the editor panel to bin in an external div
rougeronj
parents:
435
diff
changeset
|
21 |
} |
| 284 | 22 |
this.notif_$ = this.$.find(".Rk-Notifications"); |
23 |
paper.setup(this.canvas_$[0]); |
|
24 |
this.totalScroll = 0; |
|
25 |
this.mouse_down = false; |
|
26 |
this.click_target = null; |
|
27 |
this.selected_target = null; |
|
28 |
this.edge_layer = new paper.Layer(); |
|
29 |
this.node_layer = new paper.Layer(); |
|
30 |
this.buttons_layer = new paper.Layer(); |
|
31 |
this.delete_list = []; |
|
|
543
5f7bebdcfc0d
Improve the way we init the view. The data loader send a "loaded" event, hooked by the scene.py and initializing the backbone.history and the view.
rougeronj
parents:
534
diff
changeset
|
32 |
this.redrawActive = false; |
|
434
0d5998b32a7c
clean, and finalize lodash migration
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
33 |
|
| 284 | 34 |
if (_renkan.options.show_minimap) { |
35 |
this.minimap = { |
|
36 |
background_layer: new paper.Layer(), |
|
37 |
edge_layer: new paper.Layer(), |
|
38 |
node_layer: new paper.Layer(), |
|
39 |
node_group: new paper.Group(), |
|
40 |
size: new paper.Size( _renkan.options.minimap_width, _renkan.options.minimap_height ) |
|
41 |
}; |
|
42 |
||
43 |
this.minimap.background_layer.activate(); |
|
44 |
this.minimap.topleft = paper.view.bounds.bottomRight.subtract(this.minimap.size); |
|
45 |
this.minimap.rectangle = new paper.Path.Rectangle(this.minimap.topleft.subtract([2,2]), this.minimap.size.add([4,4])); |
|
46 |
this.minimap.rectangle.fillColor = _renkan.options.minimap_background_color; |
|
47 |
this.minimap.rectangle.strokeColor = _renkan.options.minimap_border_color; |
|
48 |
this.minimap.rectangle.strokeWidth = 4; |
|
49 |
this.minimap.offset = new paper.Point(this.minimap.size.divide(2)); |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
50 |
this.minimap.scale = 0.1; |
| 284 | 51 |
|
52 |
this.minimap.node_layer.activate(); |
|
53 |
this.minimap.cliprectangle = new paper.Path.Rectangle(this.minimap.topleft, this.minimap.size); |
|
54 |
this.minimap.node_group.addChild(this.minimap.cliprectangle); |
|
55 |
this.minimap.node_group.clipped = true; |
|
56 |
this.minimap.miniframe = new paper.Path.Rectangle(this.minimap.topleft, this.minimap.size); |
|
57 |
this.minimap.node_group.addChild(this.minimap.miniframe); |
|
58 |
this.minimap.miniframe.fillColor = '#c0c0ff'; |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
59 |
this.minimap.miniframe.opacity = 0.3; |
| 284 | 60 |
this.minimap.miniframe.strokeColor = '#000080'; |
|
403
96781c1a8bbe
correct resizing problems especially in next firefox
ymh <ymh.work@gmail.com>
parents:
398
diff
changeset
|
61 |
this.minimap.miniframe.strokeWidth = 2; |
| 284 | 62 |
this.minimap.miniframe.__representation = new MiniFrame(this, null); |
63 |
} |
|
64 |
||
65 |
this.throttledPaperDraw = _(function() { |
|
66 |
paper.view.draw(); |
|
| 433 | 67 |
}).throttle(100).value(); |
| 284 | 68 |
|
69 |
this.bundles = []; |
|
70 |
this.click_mode = false; |
|
71 |
||
72 |
var _this = this, |
|
73 |
_allowScroll = true, |
|
74 |
_originalScale = 1, |
|
75 |
_zooming = false, |
|
76 |
_lastTapX = 0, |
|
|
534
c25e7c9e26a0
small bug fixed preventing touch to work on tablet - init _lastTap variable before using it
rougeronj
parents:
525
diff
changeset
|
77 |
_lastTapY = 0, |
|
c25e7c9e26a0
small bug fixed preventing touch to work on tablet - init _lastTap variable before using it
rougeronj
parents:
525
diff
changeset
|
78 |
_lastTap = 0; |
| 284 | 79 |
|
80 |
this.image_cache = {}; |
|
81 |
this.icon_cache = {}; |
|
82 |
||
| 453 | 83 |
['edit', 'remove', 'hide', 'show', 'link', 'enlarge', 'shrink', 'revert' ].forEach(function(imgname) { |
| 284 | 84 |
var img = new Image(); |
85 |
img.src = _renkan.options.static_url + 'img/' + imgname + '.png'; |
|
86 |
_this.icon_cache[imgname] = img; |
|
87 |
}); |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
88 |
|
| 284 | 89 |
var throttledMouseMove = _.throttle(function(_event, _isTouch) { |
90 |
_this.onMouseMove(_event, _isTouch); |
|
91 |
}, Utils._MOUSEMOVE_RATE); |
|
92 |
||
93 |
this.canvas_$.on({ |
|
94 |
mousedown: function(_event) { |
|
95 |
_event.preventDefault(); |
|
96 |
_this.onMouseDown(_event, false); |
|
97 |
}, |
|
98 |
mousemove: function(_event) { |
|
99 |
_event.preventDefault(); |
|
100 |
throttledMouseMove(_event, false); |
|
101 |
}, |
|
102 |
mouseup: function(_event) { |
|
103 |
_event.preventDefault(); |
|
104 |
_this.onMouseUp(_event, false); |
|
105 |
}, |
|
106 |
mousewheel: function(_event, _delta) { |
|
107 |
if(_renkan.options.zoom_on_scroll) { |
|
108 |
_event.preventDefault(); |
|
109 |
if (_allowScroll) { |
|
110 |
_this.onScroll(_event, _delta); |
|
111 |
} |
|
112 |
} |
|
113 |
}, |
|
114 |
touchstart: function(_event) { |
|
115 |
_event.preventDefault(); |
|
116 |
var _touches = _event.originalEvent.touches[0]; |
|
117 |
if ( |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
118 |
_renkan.options.allow_double_click && |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
119 |
new Date() - _lastTap < Utils._DOUBLETAP_DELAY && |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
120 |
( Math.pow(_lastTapX - _touches.pageX, 2) + Math.pow(_lastTapY - _touches.pageY, 2) < Utils._DOUBLETAP_DISTANCE ) |
| 284 | 121 |
) { |
122 |
_lastTap = 0; |
|
123 |
_this.onDoubleClick(_touches); |
|
124 |
} else { |
|
125 |
_lastTap = new Date(); |
|
126 |
_lastTapX = _touches.pageX; |
|
127 |
_lastTapY = _touches.pageY; |
|
| 508 | 128 |
_originalScale = _this.view.scale; |
| 284 | 129 |
_zooming = false; |
130 |
_this.onMouseDown(_touches, true); |
|
131 |
} |
|
132 |
}, |
|
133 |
touchmove: function(_event) { |
|
134 |
_event.preventDefault(); |
|
135 |
_lastTap = 0; |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
136 |
if (_event.originalEvent.touches.length === 1) { |
| 284 | 137 |
_this.onMouseMove(_event.originalEvent.touches[0], true); |
138 |
} else { |
|
139 |
if (!_zooming) { |
|
140 |
_this.onMouseUp(_event.originalEvent.touches[0], true); |
|
141 |
_this.click_target = null; |
|
142 |
_this.is_dragging = false; |
|
143 |
_zooming = true; |
|
144 |
} |
|
145 |
if (_event.originalEvent.scale === "undefined") { |
|
146 |
return; |
|
147 |
} |
|
148 |
var _newScale = _event.originalEvent.scale * _originalScale, |
|
| 508 | 149 |
_scaleRatio = _newScale / _this.view.scale, |
| 284 | 150 |
_newOffset = new paper.Point([ |
151 |
_this.canvas_$.width(), |
|
152 |
_this.canvas_$.height() |
|
| 508 | 153 |
]).multiply( 0.5 * ( 1 - _scaleRatio ) ).add(_this.view.offset.multiply( _scaleRatio )); |
154 |
_this.view.setScale(_newScale, _newOffset); |
|
| 284 | 155 |
} |
156 |
}, |
|
157 |
touchend: function(_event) { |
|
158 |
_event.preventDefault(); |
|
159 |
_this.onMouseUp(_event.originalEvent.changedTouches[0], true); |
|
160 |
}, |
|
161 |
dblclick: function(_event) { |
|
162 |
_event.preventDefault(); |
|
163 |
if (_renkan.options.allow_double_click) { |
|
164 |
_this.onDoubleClick(_event); |
|
165 |
} |
|
166 |
}, |
|
167 |
mouseleave: function(_event) { |
|
168 |
_event.preventDefault(); |
|
|
490
8b05c7322e93
correct grunt file for dist version
ymh <ymh.work@gmail.com>
parents:
487
diff
changeset
|
169 |
//_this.onMouseUp(_event, false); |
| 284 | 170 |
_this.click_target = null; |
171 |
_this.is_dragging = false; |
|
172 |
}, |
|
173 |
dragover: function(_event) { |
|
174 |
_event.preventDefault(); |
|
175 |
}, |
|
176 |
dragenter: function(_event) { |
|
177 |
_event.preventDefault(); |
|
178 |
_allowScroll = false; |
|
179 |
}, |
|
180 |
dragleave: function(_event) { |
|
181 |
_event.preventDefault(); |
|
182 |
_allowScroll = true; |
|
183 |
}, |
|
184 |
drop: function(_event) { |
|
185 |
_event.preventDefault(); |
|
186 |
_allowScroll = true; |
|
187 |
var res = {}; |
|
| 433 | 188 |
_.each(_event.originalEvent.dataTransfer.types, function(t) { |
| 284 | 189 |
try { |
190 |
res[t] = _event.originalEvent.dataTransfer.getData(t); |
|
191 |
} catch(e) {} |
|
192 |
}); |
|
193 |
var text = _event.originalEvent.dataTransfer.getData("Text"); |
|
194 |
if (typeof text === "string") { |
|
195 |
switch(text[0]) { |
|
196 |
case "{": |
|
197 |
case "[": |
|
198 |
try { |
|
199 |
var data = JSON.parse(text); |
|
| 433 | 200 |
_.extend(res,data); |
| 284 | 201 |
} |
202 |
catch(e) { |
|
203 |
if (!res["text/plain"]) { |
|
204 |
res["text/plain"] = text; |
|
205 |
} |
|
206 |
} |
|
207 |
break; |
|
208 |
case "<": |
|
209 |
if (!res["text/html"]) { |
|
210 |
res["text/html"] = text; |
|
211 |
} |
|
212 |
break; |
|
213 |
default: |
|
214 |
if (!res["text/plain"]) { |
|
215 |
res["text/plain"] = text; |
|
216 |
} |
|
217 |
} |
|
218 |
} |
|
219 |
var url = _event.originalEvent.dataTransfer.getData("URL"); |
|
220 |
if (url && !res["text/uri-list"]) { |
|
221 |
res["text/uri-list"] = url; |
|
222 |
} |
|
223 |
_this.dropData(res, _event.originalEvent); |
|
224 |
} |
|
225 |
}); |
|
226 |
||
227 |
var bindClick = function(selector, fname) { |
|
228 |
_this.$.find(selector).click(function(evt) { |
|
229 |
_this[fname](evt); |
|
230 |
return false; |
|
231 |
}); |
|
232 |
}; |
|
233 |
||
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
412
diff
changeset
|
234 |
if(this.renkan.project.get("views").length > 0 && this.renkan.options.save_view){ |
| 284 | 235 |
this.$.find(".Rk-ZoomSetSaved").show(); |
236 |
} |
|
237 |
this.$.find(".Rk-CurrentUser").mouseenter( |
|
238 |
function() { _this.$.find(".Rk-UserList").slideDown(); } |
|
239 |
); |
|
240 |
this.$.find(".Rk-Users").mouseleave( |
|
241 |
function() { _this.$.find(".Rk-UserList").slideUp(); } |
|
242 |
); |
|
| 555 | 243 |
|
244 |
if (Screenfull.enabled){ |
|
245 |
bindClick(".Rk-FullScreen-Button", "fullScreen"); |
|
| 575 | 246 |
|
247 |
document.addEventListener(Screenfull.raw.fullscreenchange, function () { |
|
248 |
var widthAft = _this.$.width(); |
|
249 |
var heightAft = _this.$.height(); |
|
250 |
|
|
251 |
if (_this.renkan.options.show_top_bar) { |
|
252 |
heightAft -= _this.$.find(".Rk-TopBar").height(); |
|
253 |
} |
|
254 |
if (_this.renkan.options.show_bins && (this.renkan.$.find(".Rk-Bins").position().left > 0)) { |
|
255 |
widthAft -= this.renkan.$.find(".Rk-Bins").width(); |
|
256 |
} |
|
257 |
|
|
258 |
paper.view.viewSize = new paper.Size([widthAft, heightAft]); |
|
259 |
|
|
260 |
_this.resize(_this.currentWidth, widthAft, _this.currentHeight, heightAft); |
|
261 |
|
|
262 |
_this.currentWidth = widthAft; |
|
263 |
_this.currentHeight = heightAft; |
|
264 |
|
|
265 |
paper.view.onResize = function(_event) { |
|
266 |
var newWidth = _event.size._width, |
|
267 |
newHeight = _event.size._height; |
|
268 |
var prevHeight = newHeight - _event.delta.height, |
|
269 |
prevWidth = newWidth - _event.delta.width; |
|
270 |
|
|
271 |
_this.resize(prevWidth, newWidth, prevHeight, newHeight); |
|
272 |
}; |
|
273 |
}); |
|
| 555 | 274 |
} else { |
275 |
this.$.find(".Rk-FullScreen-Button").addClass("disabled"); |
|
276 |
this.$.find(".Rk-FullScreen-Button .Rk-TopBar-Tooltip-Contents").html(this.renkan.translate("Fullscreen not supported by your browser")); |
|
277 |
} |
|
278 |
|
|
| 284 | 279 |
bindClick(".Rk-AddNode-Button", "addNodeBtn"); |
280 |
bindClick(".Rk-AddEdge-Button", "addEdgeBtn"); |
|
281 |
bindClick(".Rk-Save-Button", "save"); |
|
282 |
bindClick(".Rk-Open-Button", "open"); |
|
| 297 | 283 |
bindClick(".Rk-Export-Button", "exportProject"); |
| 284 | 284 |
this.$.find(".Rk-Bookmarklet-Button") |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
285 |
/*jshint scripturl:true */ |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
286 |
.attr("href","javascript:" + Utils._BOOKMARKLET_CODE(_renkan)) |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
287 |
.click(function(){ |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
288 |
_this.notif_$ |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
289 |
.text(_renkan.translate("Drag this button to your bookmark bar. When on a third-party website, click it to enable drag-and-drop from the website to Renkan.")) |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
290 |
.fadeIn() |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
291 |
.delay(5000) |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
292 |
.fadeOut(); |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
293 |
return false; |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
294 |
}); |
| 284 | 295 |
this.$.find(".Rk-TopBar-Button").mouseover(function() { |
296 |
$(this).find(".Rk-TopBar-Tooltip").show(); |
|
297 |
}).mouseout(function() { |
|
298 |
$(this).find(".Rk-TopBar-Tooltip").hide(); |
|
299 |
}); |
|
300 |
bindClick(".Rk-Fold-Bins", "foldBins"); |
|
301 |
||
| 575 | 302 |
paper.view.on("resize", function(_event) { |
303 |
var newWidth = _event.size._width, |
|
|
543
5f7bebdcfc0d
Improve the way we init the view. The data loader send a "loaded" event, hooked by the scene.py and initializing the backbone.history and the view.
rougeronj
parents:
534
diff
changeset
|
304 |
newHeight = _event.size._height; |
| 575 | 305 |
var prevHeight = newHeight - _event.delta.height, |
306 |
prevWidth = newWidth - _event.delta.width; |
|
|
543
5f7bebdcfc0d
Improve the way we init the view. The data loader send a "loaded" event, hooked by the scene.py and initializing the backbone.history and the view.
rougeronj
parents:
534
diff
changeset
|
307 |
|
| 575 | 308 |
_this.resize(prevWidth, newWidth, prevHeight, newHeight); |
309 |
}); |
|
| 284 | 310 |
|
311 |
var _thRedraw = _.throttle(function() { |
|
312 |
_this.redraw(); |
|
313 |
},50); |
|
|
537
88703fb5aaaf
correct view initisalization for java
ymh <ymh.work@gmail.com>
parents:
534
diff
changeset
|
314 |
|
| 284 | 315 |
this.addRepresentations("Node", this.renkan.project.get("nodes")); |
316 |
this.addRepresentations("Edge", this.renkan.project.get("edges")); |
|
317 |
this.renkan.project.on("change:title", function() { |
|
318 |
_this.$.find(".Rk-PadTitle").val(_renkan.project.get("title")); |
|
319 |
}); |
|
320 |
||
321 |
this.$.find(".Rk-PadTitle").on("keyup input paste", function() { |
|
322 |
_renkan.project.set({"title": $(this).val()}); |
|
323 |
}); |
|
324 |
||
325 |
var _thRedrawUsers = _.throttle(function() { |
|
326 |
_this.redrawUsers(); |
|
327 |
}, 100); |
|
328 |
||
329 |
_thRedrawUsers(); |
|
330 |
||
331 |
// register model events |
|
|
443
4c7ab16e5845
best coding convention for loadingstatus and savingstatus, rempve loadingatatus form export
ymh <ymh.work@gmail.com>
parents:
435
diff
changeset
|
332 |
this.renkan.project.on("change:saveStatus", function(){ |
|
4c7ab16e5845
best coding convention for loadingstatus and savingstatus, rempve loadingatatus form export
ymh <ymh.work@gmail.com>
parents:
435
diff
changeset
|
333 |
switch (_this.renkan.project.get("saveStatus")) { |
| 396 | 334 |
case 0: //clean |
335 |
_this.$.find(".Rk-Save-Button").removeClass("to-save"); |
|
336 |
_this.$.find(".Rk-Save-Button").removeClass("saving"); |
|
337 |
_this.$.find(".Rk-Save-Button").addClass("saved"); |
|
338 |
break; |
|
339 |
case 1: //dirty |
|
340 |
_this.$.find(".Rk-Save-Button").removeClass("saved"); |
|
341 |
_this.$.find(".Rk-Save-Button").removeClass("saving"); |
|
342 |
_this.$.find(".Rk-Save-Button").addClass("to-save"); |
|
343 |
break; |
|
344 |
case 2: //saving |
|
345 |
_this.$.find(".Rk-Save-Button").removeClass("saved"); |
|
346 |
_this.$.find(".Rk-Save-Button").removeClass("to-save"); |
|
347 |
_this.$.find(".Rk-Save-Button").addClass("saving"); |
|
348 |
break; |
|
349 |
} |
|
|
357
70e577b0cdc6
add save_status var to specify the status of the renkan (saved/to-save/saving)
rougeronj
parents:
340
diff
changeset
|
350 |
}); |
|
543
5f7bebdcfc0d
Improve the way we init the view. The data loader send a "loaded" event, hooked by the scene.py and initializing the backbone.history and the view.
rougeronj
parents:
534
diff
changeset
|
351 |
|
|
5f7bebdcfc0d
Improve the way we init the view. The data loader send a "loaded" event, hooked by the scene.py and initializing the backbone.history and the view.
rougeronj
parents:
534
diff
changeset
|
352 |
this.renkan.project.on("loaded", function(){ |
| 547 | 353 |
if (_this.renkan.options.url_parameters){ |
354 |
Backbone.history.start(); |
|
355 |
} else { |
|
356 |
_this.fixSize(); |
|
357 |
} |
|
|
543
5f7bebdcfc0d
Improve the way we init the view. The data loader send a "loaded" event, hooked by the scene.py and initializing the backbone.history and the view.
rougeronj
parents:
534
diff
changeset
|
358 |
_this.redrawActive = true; |
|
5f7bebdcfc0d
Improve the way we init the view. The data loader send a "loaded" event, hooked by the scene.py and initializing the backbone.history and the view.
rougeronj
parents:
534
diff
changeset
|
359 |
_thRedraw(); |
|
5f7bebdcfc0d
Improve the way we init the view. The data loader send a "loaded" event, hooked by the scene.py and initializing the backbone.history and the view.
rougeronj
parents:
534
diff
changeset
|
360 |
}); |
|
5f7bebdcfc0d
Improve the way we init the view. The data loader send a "loaded" event, hooked by the scene.py and initializing the backbone.history and the view.
rougeronj
parents:
534
diff
changeset
|
361 |
|
| 554 | 362 |
//register router events |
363 |
this.renkan.router.on("router", function(_params){ |
|
364 |
_this.setViewparameters(_params); |
|
365 |
}); |
|
366 |
|
|
|
443
4c7ab16e5845
best coding convention for loadingstatus and savingstatus, rempve loadingatatus form export
ymh <ymh.work@gmail.com>
parents:
435
diff
changeset
|
367 |
this.renkan.project.on("change:loadingStatus", function(){ |
|
4c7ab16e5845
best coding convention for loadingstatus and savingstatus, rempve loadingatatus form export
ymh <ymh.work@gmail.com>
parents:
435
diff
changeset
|
368 |
if (_this.renkan.project.get("loadingStatus")){ |
| 396 | 369 |
var animate = _this.$.find(".loader").addClass("run"); |
370 |
var timer = setTimeout(function(){ |
|
371 |
_this.$.find(".loader").hide(250); |
|
372 |
}, 3000); |
|
373 |
} |
|
|
368
3abc79964948
Close #33 - Add loading status var to set up a loading bar while the renkan is loading
rougeronj
parents:
364
diff
changeset
|
374 |
}); |
| 396 | 375 |
|
| 284 | 376 |
this.renkan.project.on("add:users remove:users", _thRedrawUsers); |
377 |
||
378 |
this.renkan.project.on("add:views remove:views", function(_node) { |
|
|
543
5f7bebdcfc0d
Improve the way we init the view. The data loader send a "loaded" event, hooked by the scene.py and initializing the backbone.history and the view.
rougeronj
parents:
534
diff
changeset
|
379 |
if(_this.renkan.project.get('views').length > 1) { |
| 284 | 380 |
_this.$.find(".Rk-ZoomSetSaved").show(); |
381 |
} |
|
382 |
else { |
|
383 |
_this.$.find(".Rk-ZoomSetSaved").hide(); |
|
384 |
} |
|
385 |
}); |
|
386 |
||
387 |
this.renkan.project.on("add:nodes", function(_node) { |
|
388 |
_this.addRepresentation("Node", _node); |
|
|
443
4c7ab16e5845
best coding convention for loadingstatus and savingstatus, rempve loadingatatus form export
ymh <ymh.work@gmail.com>
parents:
435
diff
changeset
|
389 |
if (!_this.renkan.project.get("loadingStatus")){ |
| 396 | 390 |
_thRedraw(); |
|
368
3abc79964948
Close #33 - Add loading status var to set up a loading bar while the renkan is loading
rougeronj
parents:
364
diff
changeset
|
391 |
} |
| 284 | 392 |
}); |
393 |
this.renkan.project.on("add:edges", function(_edge) { |
|
394 |
_this.addRepresentation("Edge", _edge); |
|
|
443
4c7ab16e5845
best coding convention for loadingstatus and savingstatus, rempve loadingatatus form export
ymh <ymh.work@gmail.com>
parents:
435
diff
changeset
|
395 |
if (!_this.renkan.project.get("loadingStatus")){ |
| 396 | 396 |
_thRedraw(); |
|
368
3abc79964948
Close #33 - Add loading status var to set up a loading bar while the renkan is loading
rougeronj
parents:
364
diff
changeset
|
397 |
} |
| 284 | 398 |
}); |
399 |
this.renkan.project.on("change:title", function(_model, _title) { |
|
400 |
var el = _this.$.find(".Rk-PadTitle"); |
|
401 |
if (el.is("input")) { |
|
402 |
if (el.val() !== _title) { |
|
403 |
el.val(_title); |
|
404 |
} |
|
405 |
} else { |
|
406 |
el.text(_title); |
|
407 |
} |
|
408 |
}); |
|
|
537
88703fb5aaaf
correct view initisalization for java
ymh <ymh.work@gmail.com>
parents:
534
diff
changeset
|
409 |
|
| 284 | 410 |
if (_renkan.options.size_bug_fix) { |
411 |
var _delay = ( |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
412 |
typeof _renkan.options.size_bug_fix === "number" ? |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
413 |
_renkan.options.size_bug_fix |
| 284 | 414 |
: 500 |
415 |
); |
|
416 |
window.setTimeout( |
|
417 |
function() { |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
412
diff
changeset
|
418 |
_this.fixSize(); |
| 284 | 419 |
}, |
420 |
_delay |
|
421 |
); |
|
422 |
} |
|
423 |
||
424 |
if (_renkan.options.force_resize) { |
|
425 |
$(window).resize(function() { |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
412
diff
changeset
|
426 |
_this.autoScale(); |
| 284 | 427 |
}); |
428 |
} |
|
429 |
||
430 |
if (_renkan.options.show_user_list && _renkan.options.user_color_editable) { |
|
431 |
var $cpwrapper = this.$.find(".Rk-Users .Rk-Edit-ColorPicker-Wrapper"), |
|
432 |
$cplist = this.$.find(".Rk-Users .Rk-Edit-ColorPicker"); |
|
433 |
||
434 |
$cpwrapper.hover( |
|
435 |
function(_e) { |
|
436 |
if (_this.isEditable()) { |
|
437 |
_e.preventDefault(); |
|
438 |
$cplist.show(); |
|
439 |
} |
|
440 |
}, |
|
441 |
function(_e) { |
|
442 |
_e.preventDefault(); |
|
443 |
$cplist.hide(); |
|
444 |
} |
|
445 |
); |
|
446 |
||
447 |
$cplist.find("li").mouseenter( |
|
448 |
function(_e) { |
|
449 |
if (_this.isEditable()) { |
|
450 |
_e.preventDefault(); |
|
451 |
_this.$.find(".Rk-CurrentUser-Color").css("background", $(this).attr("data-color")); |
|
452 |
} |
|
453 |
} |
|
454 |
); |
|
455 |
} |
|
456 |
||
457 |
if (_renkan.options.show_search_field) { |
|
458 |
||
459 |
var lastval = ''; |
|
460 |
||
461 |
this.$.find(".Rk-GraphSearch-Field").on("keyup change paste input", function() { |
|
462 |
var $this = $(this), |
|
463 |
val = $this.val(); |
|
464 |
if (val === lastval) { |
|
465 |
return; |
|
466 |
} |
|
467 |
lastval = val; |
|
468 |
if (val.length < 2) { |
|
469 |
_renkan.project.get("nodes").each(function(n) { |
|
470 |
_this.getRepresentationByModel(n).unhighlight(); |
|
471 |
}); |
|
472 |
} else { |
|
473 |
var rxs = Utils.regexpFromTextOrArray(val); |
|
474 |
_renkan.project.get("nodes").each(function(n) { |
|
475 |
if (rxs.test(n.get("title")) || rxs.test(n.get("description"))) { |
|
476 |
_this.getRepresentationByModel(n).highlight(rxs); |
|
477 |
} else { |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
478 |
_this.getRepresentationByModel(n).unhighlight(); |
| 284 | 479 |
} |
480 |
}); |
|
481 |
} |
|
482 |
}); |
|
483 |
} |
|
484 |
||
485 |
this.redraw(); |
|
486 |
||
487 |
window.setInterval(function() { |
|
488 |
var _now = new Date().valueOf(); |
|
489 |
_this.delete_list.forEach(function(d) { |
|
490 |
if (_now >= d.time) { |
|
491 |
var el = _renkan.project.get("nodes").findWhere({"delete_scheduled":d.id}); |
|
492 |
if (el) { |
|
493 |
project.removeNode(el); |
|
494 |
} |
|
495 |
el = _renkan.project.get("edges").findWhere({"delete_scheduled":d.id}); |
|
496 |
if (el) { |
|
497 |
project.removeEdge(el); |
|
498 |
} |
|
499 |
} |
|
500 |
}); |
|
501 |
_this.delete_list = _this.delete_list.filter(function(d) { |
|
502 |
return _renkan.project.get("nodes").findWhere({"delete_scheduled":d.id}) || _renkan.project.get("edges").findWhere({"delete_scheduled":d.id}); |
|
503 |
}); |
|
504 |
}, 500); |
|
505 |
||
506 |
if (this.minimap) { |
|
507 |
window.setInterval(function() { |
|
508 |
_this.rescaleMinimap(); |
|
509 |
}, 2000); |
|
510 |
} |
|
511 |
||
512 |
}; |
|
513 |
||
514 |
_(Scene.prototype).extend({ |
|
|
414
276042cb477c
correct fix size, improve control on view save button and related init state
ymh <ymh.work@gmail.com>
parents:
412
diff
changeset
|
515 |
fixSize: function() { |
|
519
b94a34c139c1
update parameters function to accept idView parameter
rougeronj
parents:
512
diff
changeset
|
516 |
if(typeof this.view === 'undefined') { |
| 554 | 517 |
this.view = this.addRepresentation("View", this.renkan.project.get("views").last()); |
|
519
b94a34c139c1
update parameters function to accept idView parameter
rougeronj
parents:
512
diff
changeset
|
518 |
} |
| 547 | 519 |
this.view.autoScale(); |
| 284 | 520 |
}, |
521 |
drawSector: function(_repr, _inR, _outR, _startAngle, _endAngle, _padding, _imgname, _caption) { |
|
522 |
var _options = this.renkan.options, |
|
|
398
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
523 |
_startRads = _startAngle * Math.PI / 180, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
524 |
_endRads = _endAngle * Math.PI / 180, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
525 |
_img = this.icon_cache[_imgname], |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
526 |
_startdx = - Math.sin(_startRads), |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
527 |
_startdy = Math.cos(_startRads), |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
528 |
_startXIn = Math.cos(_startRads) * _inR + _padding * _startdx, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
529 |
_startYIn = Math.sin(_startRads) * _inR + _padding * _startdy, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
530 |
_startXOut = Math.cos(_startRads) * _outR + _padding * _startdx, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
531 |
_startYOut = Math.sin(_startRads) * _outR + _padding * _startdy, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
532 |
_enddx = - Math.sin(_endRads), |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
533 |
_enddy = Math.cos(_endRads), |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
534 |
_endXIn = Math.cos(_endRads) * _inR - _padding * _enddx, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
535 |
_endYIn = Math.sin(_endRads) * _inR - _padding * _enddy, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
536 |
_endXOut = Math.cos(_endRads) * _outR - _padding * _enddx, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
537 |
_endYOut = Math.sin(_endRads) * _outR - _padding * _enddy, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
538 |
_centerR = (_inR + _outR) / 2, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
539 |
_centerRads = (_startRads + _endRads) / 2, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
540 |
_centerX = Math.cos(_centerRads) * _centerR, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
541 |
_centerY = Math.sin(_centerRads) * _centerR, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
542 |
_centerXIn = Math.cos(_centerRads) * _inR, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
543 |
_centerXOut = Math.cos(_centerRads) * _outR, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
544 |
_centerYIn = Math.sin(_centerRads) * _inR, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
545 |
_centerYOut = Math.sin(_centerRads) * _outR, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
546 |
_textX = Math.cos(_centerRads) * (_outR + 3), |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
547 |
_textY = Math.sin(_centerRads) * (_outR + _options.buttons_label_font_size) + _options.buttons_label_font_size / 2; |
| 284 | 548 |
this.buttons_layer.activate(); |
549 |
var _path = new paper.Path(); |
|
550 |
_path.add([_startXIn, _startYIn]); |
|
551 |
_path.arcTo([_centerXIn, _centerYIn], [_endXIn, _endYIn]); |
|
552 |
_path.lineTo([_endXOut, _endYOut]); |
|
553 |
_path.arcTo([_centerXOut, _centerYOut], [_startXOut, _startYOut]); |
|
554 |
_path.fillColor = _options.buttons_background; |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
555 |
_path.opacity = 0.5; |
| 284 | 556 |
_path.closed = true; |
557 |
_path.__representation = _repr; |
|
558 |
var _text = new paper.PointText(_textX,_textY); |
|
559 |
_text.characterStyle = { |
|
560 |
fontSize: _options.buttons_label_font_size, |
|
561 |
fillColor: _options.buttons_label_color |
|
562 |
}; |
|
563 |
if (_textX > 2) { |
|
564 |
_text.paragraphStyle.justification = 'left'; |
|
565 |
} else if (_textX < -2) { |
|
566 |
_text.paragraphStyle.justification = 'right'; |
|
567 |
} else { |
|
568 |
_text.paragraphStyle.justification = 'center'; |
|
569 |
} |
|
570 |
_text.visible = false; |
|
571 |
var _visible = false, |
|
|
398
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
572 |
_restPos = new paper.Point(-200, -200), |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
573 |
_grp = new paper.Group([_path, _text]), |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
574 |
//_grp = new paper.Group([_path]), |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
575 |
_delta = _grp.position, |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
576 |
_imgdelta = new paper.Point([_centerX, _centerY]), |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
577 |
_currentPos = new paper.Point(0,0); |
| 284 | 578 |
_text.content = _caption; |
|
398
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
579 |
// set group pivot to not depend on text visibility that changes the group bounding box. |
|
57f8d344fde9
Correct button shift on hover that appeared after paperjs v 0.9.15
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
580 |
_grp.pivot = _grp.bounds.center; |
| 284 | 581 |
_grp.visible = false; |
582 |
_grp.position = _restPos; |
|
583 |
var _res = { |
|
584 |
show: function() { |
|
585 |
_visible = true; |
|
586 |
_grp.position = _currentPos.add(_delta); |
|
587 |
_grp.visible = true; |
|
588 |
}, |
|
589 |
moveTo: function(_point) { |
|
590 |
_currentPos = _point; |
|
591 |
if (_visible) { |
|
592 |
_grp.position = _point.add(_delta); |
|
593 |
} |
|
594 |
}, |
|
595 |
hide: function() { |
|
596 |
_visible = false; |
|
597 |
_grp.visible = false; |
|
598 |
_grp.position = _restPos; |
|
599 |
}, |
|
600 |
select: function() { |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
601 |
_path.opacity = 0.8; |
| 284 | 602 |
_text.visible = true; |
603 |
}, |
|
604 |
unselect: function() { |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
605 |
_path.opacity = 0.5; |
| 284 | 606 |
_text.visible = false; |
607 |
}, |
|
608 |
destroy: function() { |
|
609 |
_grp.remove(); |
|
610 |
} |
|
611 |
}; |
|
612 |
var showImage = function() { |
|
613 |
var _raster = new paper.Raster(_img); |
|
614 |
_raster.position = _imgdelta.add(_grp.position).subtract(_delta); |
|
615 |
_raster.locked = true; // Disable mouse events on icon |
|
616 |
_grp.addChild(_raster); |
|
617 |
}; |
|
618 |
if (_img.width) { |
|
619 |
showImage(); |
|
620 |
} else { |
|
621 |
$(_img).on("load",showImage); |
|
622 |
} |
|
623 |
||
624 |
return _res; |
|
625 |
}, |
|
626 |
addToBundles: function(_edgeRepr) { |
|
627 |
var _bundle = _(this.bundles).find(function(_bundle) { |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
628 |
return ( |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
629 |
( _bundle.from === _edgeRepr.from_representation && _bundle.to === _edgeRepr.to_representation ) || |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
630 |
( _bundle.from === _edgeRepr.to_representation && _bundle.to === _edgeRepr.from_representation ) |
| 284 | 631 |
); |
632 |
}); |
|
633 |
if (typeof _bundle !== "undefined") { |
|
634 |
_bundle.edges.push(_edgeRepr); |
|
635 |
} else { |
|
636 |
_bundle = { |
|
637 |
from: _edgeRepr.from_representation, |
|
638 |
to: _edgeRepr.to_representation, |
|
639 |
edges: [ _edgeRepr ], |
|
640 |
getPosition: function(_er) { |
|
641 |
var _dir = (_er.from_representation === this.from) ? 1 : -1; |
|
642 |
return _dir * ( _(this.edges).indexOf(_er) - (this.edges.length - 1) / 2 ); |
|
643 |
} |
|
644 |
}; |
|
645 |
this.bundles.push(_bundle); |
|
646 |
} |
|
647 |
return _bundle; |
|
648 |
}, |
|
649 |
isEditable: function() { |
|
650 |
return (this.renkan.options.editor_mode && !this.renkan.read_only); |
|
651 |
}, |
|
652 |
onStatusChange: function() { |
|
653 |
var savebtn = this.$.find(".Rk-Save-Button"), |
|
654 |
tip = savebtn.find(".Rk-TopBar-Tooltip-Contents"); |
|
655 |
if (this.renkan.read_only) { |
|
656 |
savebtn.removeClass("disabled Rk-Save-Online").addClass("Rk-Save-ReadOnly"); |
|
657 |
tip.text(this.renkan.translate("Connection lost")); |
|
658 |
} else { |
|
| 322 | 659 |
if (this.renkan.options.manual_save) { |
| 284 | 660 |
savebtn.removeClass("Rk-Save-ReadOnly Rk-Save-Online"); |
661 |
tip.text(this.renkan.translate("Save Project")); |
|
662 |
} else { |
|
663 |
savebtn.removeClass("disabled Rk-Save-ReadOnly").addClass("Rk-Save-Online"); |
|
664 |
tip.text(this.renkan.translate("Auto-save enabled")); |
|
665 |
} |
|
666 |
} |
|
667 |
this.redrawUsers(); |
|
668 |
}, |
|
669 |
redrawMiniframe: function() { |
|
670 |
var topleft = this.toMinimapCoords(this.toModelCoords(new paper.Point([0,0]))), |
|
|
403
96781c1a8bbe
correct resizing problems especially in next firefox
ymh <ymh.work@gmail.com>
parents:
398
diff
changeset
|
671 |
bottomright = this.toMinimapCoords(this.toModelCoords(paper.view.bounds.bottomRight)); |
| 284 | 672 |
this.minimap.miniframe.fitBounds(topleft, bottomright); |
673 |
}, |
|
674 |
rescaleMinimap: function() { |
|
675 |
var nodes = this.renkan.project.get("nodes"); |
|
676 |
if (nodes.length > 1) { |
|
677 |
var _xx = nodes.map(function(_node) { return _node.get("position").x; }), |
|
|
403
96781c1a8bbe
correct resizing problems especially in next firefox
ymh <ymh.work@gmail.com>
parents:
398
diff
changeset
|
678 |
_yy = nodes.map(function(_node) { return _node.get("position").y; }), |
|
96781c1a8bbe
correct resizing problems especially in next firefox
ymh <ymh.work@gmail.com>
parents:
398
diff
changeset
|
679 |
_minx = Math.min.apply(Math, _xx), |
|
96781c1a8bbe
correct resizing problems especially in next firefox
ymh <ymh.work@gmail.com>
parents:
398
diff
changeset
|
680 |
_miny = Math.min.apply(Math, _yy), |
|
96781c1a8bbe
correct resizing problems especially in next firefox
ymh <ymh.work@gmail.com>
parents:
398
diff
changeset
|
681 |
_maxx = Math.max.apply(Math, _xx), |
|
96781c1a8bbe
correct resizing problems especially in next firefox
ymh <ymh.work@gmail.com>
parents:
398
diff
changeset
|
682 |
_maxy = Math.max.apply(Math, _yy); |
| 284 | 683 |
var _scale = Math.min( |
| 508 | 684 |
this.view.scale * 0.8 * this.renkan.options.minimap_width / paper.view.bounds.width, |
685 |
this.view.scale * 0.8 * this.renkan.options.minimap_height / paper.view.bounds.height, |
|
| 284 | 686 |
( this.renkan.options.minimap_width - 2 * this.renkan.options.minimap_padding ) / (_maxx - _minx), |
687 |
( this.renkan.options.minimap_height - 2 * this.renkan.options.minimap_padding ) / (_maxy - _miny) |
|
688 |
); |
|
689 |
this.minimap.offset = this.minimap.size.divide(2).subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(_scale)); |
|
690 |
this.minimap.scale = _scale; |
|
691 |
} |
|
692 |
if (nodes.length === 1) { |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
693 |
this.minimap.scale = 0.1; |
| 284 | 694 |
this.minimap.offset = this.minimap.size.divide(2).subtract(new paper.Point([nodes.at(0).get("position").x, nodes.at(0).get("position").y]).multiply(this.minimap.scale)); |
695 |
} |
|
696 |
this.redraw(); |
|
697 |
}, |
|
698 |
toPaperCoords: function(_point) { |
|
| 508 | 699 |
return _point.multiply(this.view.scale).add(this.view.offset); |
| 284 | 700 |
}, |
701 |
toMinimapCoords: function(_point) { |
|
702 |
return _point.multiply(this.minimap.scale).add(this.minimap.offset).add(this.minimap.topleft); |
|
703 |
}, |
|
704 |
toModelCoords: function(_point) { |
|
| 508 | 705 |
return _point.subtract(this.view.offset).divide(this.view.scale); |
| 284 | 706 |
}, |
707 |
addRepresentation: function(_type, _model) { |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
708 |
var RendererType = requtils.getRenderer()[_type]; |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
709 |
var _repr = new RendererType(this, _model); |
| 284 | 710 |
this.representations.push(_repr); |
|
537
88703fb5aaaf
correct view initisalization for java
ymh <ymh.work@gmail.com>
parents:
534
diff
changeset
|
711 |
return _repr; |
| 284 | 712 |
}, |
713 |
addRepresentations: function(_type, _collection) { |
|
714 |
var _this = this; |
|
715 |
_collection.forEach(function(_model) { |
|
716 |
_this.addRepresentation(_type, _model); |
|
717 |
}); |
|
718 |
}, |
|
719 |
userTemplate: _.template( |
|
720 |
'<li class="Rk-User"><span class="Rk-UserColor" style="background:<%=background%>;"></span><%=name%></li>' |
|
721 |
), |
|
722 |
redrawUsers: function() { |
|
723 |
if (!this.renkan.options.show_user_list) { |
|
724 |
return; |
|
725 |
} |
|
726 |
var allUsers = [].concat((this.renkan.project.current_user_list || {}).models || [], (this.renkan.project.get("users") || {}).models || []), |
|
727 |
ulistHtml = '', |
|
728 |
$userpanel = this.$.find(".Rk-Users"), |
|
729 |
$name = $userpanel.find(".Rk-CurrentUser-Name"), |
|
730 |
$cpitems = $userpanel.find(".Rk-Edit-ColorPicker li"), |
|
731 |
$colorsquare = $userpanel.find(".Rk-CurrentUser-Color"), |
|
732 |
_this = this; |
|
733 |
$name.off("click").text(this.renkan.translate("<unknown user>")); |
|
734 |
$cpitems.off("mouseleave click"); |
|
735 |
allUsers.forEach(function(_user) { |
|
736 |
if (_user.get("_id") === _this.renkan.current_user) { |
|
737 |
$name.text(_user.get("title")); |
|
738 |
$colorsquare.css("background", _user.get("color")); |
|
739 |
if (_this.isEditable()) { |
|
740 |
||
741 |
if (_this.renkan.options.user_name_editable) { |
|
742 |
$name.click(function() { |
|
743 |
var $this = $(this), |
|
744 |
$input = $('<input>').val(_user.get("title")).blur(function() { |
|
745 |
_user.set("title", $(this).val()); |
|
746 |
_this.redrawUsers(); |
|
747 |
_this.redraw(); |
|
748 |
}); |
|
749 |
$this.empty().html($input); |
|
750 |
$input.select(); |
|
751 |
}); |
|
752 |
} |
|
753 |
||
754 |
if (_this.renkan.options.user_color_editable) { |
|
755 |
$cpitems.click( |
|
756 |
function(_e) { |
|
757 |
_e.preventDefault(); |
|
758 |
if (_this.isEditable()) { |
|
759 |
_user.set("color", $(this).attr("data-color")); |
|
760 |
} |
|
761 |
$(this).parent().hide(); |
|
762 |
} |
|
763 |
).mouseleave(function() { |
|
764 |
$colorsquare.css("background", _user.get("color")); |
|
765 |
}); |
|
766 |
} |
|
767 |
} |
|
768 |
||
769 |
} else { |
|
770 |
ulistHtml += _this.userTemplate({ |
|
771 |
name: _user.get("title"), |
|
772 |
background: _user.get("color") |
|
773 |
}); |
|
774 |
} |
|
775 |
}); |
|
776 |
$userpanel.find(".Rk-UserList").html(ulistHtml); |
|
777 |
}, |
|
778 |
removeRepresentation: function(_representation) { |
|
779 |
_representation.destroy(); |
|
| 433 | 780 |
this.representations = _.reject(this.representations, |
781 |
function(_repr) { |
|
782 |
return _repr === _representation; |
|
783 |
} |
|
| 284 | 784 |
); |
785 |
}, |
|
786 |
getRepresentationByModel: function(_model) { |
|
787 |
if (!_model) { |
|
788 |
return undefined; |
|
789 |
} |
|
| 433 | 790 |
return _.find(this.representations, function(_repr) { |
| 284 | 791 |
return _repr.model === _model; |
792 |
}); |
|
793 |
}, |
|
794 |
removeRepresentationsOfType: function(_type) { |
|
| 433 | 795 |
var _representations = _.filter(this.representations,function(_repr) { |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
796 |
return _repr.type === _type; |
| 433 | 797 |
}), |
798 |
_this = this; |
|
799 |
_.each(_representations, function(_repr) { |
|
| 284 | 800 |
_this.removeRepresentation(_repr); |
801 |
}); |
|
802 |
}, |
|
803 |
highlightModel: function(_model) { |
|
804 |
var _repr = this.getRepresentationByModel(_model); |
|
805 |
if (_repr) { |
|
806 |
_repr.highlight(); |
|
807 |
} |
|
808 |
}, |
|
809 |
unhighlightAll: function(_model) { |
|
| 433 | 810 |
_.each(this.representations, function(_repr) { |
| 284 | 811 |
_repr.unhighlight(); |
812 |
}); |
|
813 |
}, |
|
814 |
unselectAll: function(_model) { |
|
| 433 | 815 |
_.each(this.representations, function(_repr) { |
| 284 | 816 |
_repr.unselect(); |
817 |
}); |
|
818 |
}, |
|
819 |
redraw: function() { |
|
| 450 | 820 |
var _this = this; |
| 307 | 821 |
if(! this.redrawActive ) { |
822 |
return; |
|
823 |
} |
|
| 433 | 824 |
_.each(this.representations, function(_representation) { |
|
435
e529b633c339
Add shape management, correction on shape manip[ulation on the client, correct 404 error on space creation, increment version
ymh <ymh.work@gmail.com>
parents:
434
diff
changeset
|
825 |
_representation.redraw({ dontRedrawEdges:true }); |
| 284 | 826 |
}); |
| 508 | 827 |
if (this.minimap && typeof this.view !== 'undefined') { |
| 284 | 828 |
this.redrawMiniframe(); |
829 |
} |
|
830 |
paper.view.draw(); |
|
831 |
}, |
|
| 575 | 832 |
resize: function(prevWidth, newWidth, prevHeight, newHeight){ |
833 |
var _ratio; |
|
834 |
|
|
835 |
if (this.minimap) { |
|
836 |
this.minimap.topleft = paper.view.bounds.bottomRight.subtract(this.minimap.size); |
|
837 |
this.minimap.rectangle.fitBounds(this.minimap.topleft.subtract([2,2]), this.minimap.size.add([4,4])); |
|
838 |
this.minimap.cliprectangle.fitBounds(this.minimap.topleft, this.minimap.size); |
|
839 |
} |
|
840 |
|
|
841 |
var ratioH = newHeight/prevHeight, |
|
842 |
ratioW = newWidth/prevWidth; |
|
843 |
if (newHeight < newWidth) { |
|
844 |
_ratio = ratioH; |
|
845 |
} else { |
|
846 |
_ratio = ratioW; |
|
847 |
} |
|
848 |
this.view.resizeZoom(newWidth - prevWidth, newHeight - prevHeight, _ratio); |
|
849 |
|
|
850 |
this.redraw(); |
|
851 |
}, |
|
| 284 | 852 |
addTempEdge: function(_from, _point) { |
853 |
var _tmpEdge = this.addRepresentation("TempEdge",null); |
|
854 |
_tmpEdge.end_pos = _point; |
|
855 |
_tmpEdge.from_representation = _from; |
|
856 |
_tmpEdge.redraw(); |
|
857 |
this.click_target = _tmpEdge; |
|
858 |
}, |
|
859 |
findTarget: function(_hitResult) { |
|
860 |
if (_hitResult && typeof _hitResult.item.__representation !== "undefined") { |
|
861 |
var _newTarget = _hitResult.item.__representation; |
|
862 |
if (this.selected_target !== _hitResult.item.__representation) { |
|
863 |
if (this.selected_target) { |
|
864 |
this.selected_target.unselect(_newTarget); |
|
865 |
} |
|
866 |
_newTarget.select(this.selected_target); |
|
867 |
this.selected_target = _newTarget; |
|
868 |
} |
|
869 |
} else { |
|
870 |
if (this.selected_target) { |
|
871 |
this.selected_target.unselect(); |
|
872 |
} |
|
873 |
this.selected_target = null; |
|
874 |
} |
|
875 |
}, |
|
876 |
onMouseMove: function(_event) { |
|
877 |
var _off = this.canvas_$.offset(), |
|
878 |
_point = new paper.Point([ |
|
879 |
_event.pageX - _off.left, |
|
880 |
_event.pageY - _off.top |
|
881 |
]), |
|
882 |
_delta = _point.subtract(this.last_point); |
|
883 |
this.last_point = _point; |
|
884 |
if (!this.is_dragging && this.mouse_down && _delta.length > Utils._MIN_DRAG_DISTANCE) { |
|
885 |
this.is_dragging = true; |
|
886 |
} |
|
887 |
var _hitResult = paper.project.hitTest(_point); |
|
888 |
if (this.is_dragging) { |
|
889 |
if (this.click_target && typeof this.click_target.paperShift === "function") { |
|
890 |
this.click_target.paperShift(_delta); |
|
891 |
} else { |
|
| 511 | 892 |
this.view.paperShift(_delta); |
| 284 | 893 |
} |
894 |
} else { |
|
895 |
this.findTarget(_hitResult); |
|
896 |
} |
|
897 |
paper.view.draw(); |
|
898 |
}, |
|
899 |
onMouseDown: function(_event, _isTouch) { |
|
900 |
var _off = this.canvas_$.offset(), |
|
901 |
_point = new paper.Point([ |
|
902 |
_event.pageX - _off.left, |
|
903 |
_event.pageY - _off.top |
|
904 |
]); |
|
905 |
this.last_point = _point; |
|
906 |
this.mouse_down = true; |
|
907 |
if (!this.click_target || this.click_target.type !== "Temp-edge") { |
|
908 |
this.removeRepresentationsOfType("editor"); |
|
909 |
this.is_dragging = false; |
|
910 |
var _hitResult = paper.project.hitTest(_point); |
|
911 |
if (_hitResult && typeof _hitResult.item.__representation !== "undefined") { |
|
912 |
this.click_target = _hitResult.item.__representation; |
|
913 |
this.click_target.mousedown(_event, _isTouch); |
|
914 |
} else { |
|
915 |
this.click_target = null; |
|
916 |
if (this.isEditable() && this.click_mode === Utils._CLICKMODE_ADDNODE) { |
|
917 |
var _coords = this.toModelCoords(_point), |
|
918 |
_data = { |
|
919 |
id: Utils.getUID('node'), |
|
920 |
created_by: this.renkan.current_user, |
|
921 |
position: { |
|
922 |
x: _coords.x, |
|
923 |
y: _coords.y |
|
924 |
} |
|
925 |
}; |
|
| 473 | 926 |
var _node = this.renkan.project.addNode(_data); |
| 284 | 927 |
this.getRepresentationByModel(_node).openEditor(); |
928 |
} |
|
929 |
} |
|
930 |
} |
|
931 |
if (this.click_mode) { |
|
932 |
if (this.isEditable() && this.click_mode === Utils._CLICKMODE_STARTEDGE && this.click_target && this.click_target.type === "Node") { |
|
933 |
this.removeRepresentationsOfType("editor"); |
|
934 |
this.addTempEdge(this.click_target, _point); |
|
935 |
this.click_mode = Utils._CLICKMODE_ENDEDGE; |
|
936 |
this.notif_$.fadeOut(function() { |
|
937 |
$(this).html(this.renkan.translate("Click on a second node to complete the edge")).fadeIn(); |
|
938 |
}); |
|
939 |
} else { |
|
940 |
this.notif_$.hide(); |
|
941 |
this.click_mode = false; |
|
942 |
} |
|
943 |
} |
|
944 |
paper.view.draw(); |
|
945 |
}, |
|
946 |
onMouseUp: function(_event, _isTouch) { |
|
947 |
this.mouse_down = false; |
|
948 |
if (this.click_target) { |
|
949 |
var _off = this.canvas_$.offset(); |
|
950 |
this.click_target.mouseup( |
|
951 |
{ |
|
952 |
point: new paper.Point([ |
|
953 |
_event.pageX - _off.left, |
|
954 |
_event.pageY - _off.top |
|
955 |
]) |
|
956 |
}, |
|
957 |
_isTouch |
|
958 |
); |
|
959 |
} else { |
|
960 |
this.click_target = null; |
|
961 |
this.is_dragging = false; |
|
962 |
if (_isTouch) { |
|
963 |
this.unselectAll(); |
|
964 |
} |
|
| 511 | 965 |
this.view.updateUrl(); |
| 284 | 966 |
} |
967 |
paper.view.draw(); |
|
968 |
}, |
|
969 |
onScroll: function(_event, _scrolldelta) { |
|
970 |
this.totalScroll += _scrolldelta; |
|
971 |
if (Math.abs(this.totalScroll) >= 1) { |
|
972 |
var _off = this.canvas_$.offset(), |
|
973 |
_delta = new paper.Point([ |
|
974 |
_event.pageX - _off.left, |
|
975 |
_event.pageY - _off.top |
|
| 508 | 976 |
]).subtract(this.view.offset).multiply( Math.SQRT2 - 1 ); |
| 284 | 977 |
if (this.totalScroll > 0) { |
| 508 | 978 |
this.view.setScale( this.view.scale * Math.SQRT2, this.view.offset.subtract(_delta) ); |
| 284 | 979 |
} else { |
| 508 | 980 |
this.view.setScale( this.view.scale * Math.SQRT1_2, this.view.offset.add(_delta.divide(Math.SQRT2))); |
| 284 | 981 |
} |
982 |
this.totalScroll = 0; |
|
983 |
} |
|
984 |
}, |
|
985 |
onDoubleClick: function(_event) { |
|
986 |
var _off = this.canvas_$.offset(), |
|
987 |
_point = new paper.Point([ |
|
988 |
_event.pageX - _off.left, |
|
989 |
_event.pageY - _off.top |
|
990 |
]); |
|
991 |
var _hitResult = paper.project.hitTest(_point); |
|
|
470
47308aa6ce94
correction for rich text editor. correct problem of empty description. make sure that the editor toolbr close
ymh <ymh.work@gmail.com>
parents:
463
diff
changeset
|
992 |
|
| 452 | 993 |
if (!this.isEditable()) { |
994 |
if (_hitResult && typeof _hitResult.item.__representation !== "undefined") { |
|
995 |
if (_hitResult.item.__representation.model.get('uri')){ |
|
996 |
window.open(_hitResult.item.__representation.model.get('uri'), '_blank'); |
|
997 |
} |
|
998 |
} |
|
999 |
return; |
|
1000 |
} |
|
| 284 | 1001 |
if (this.isEditable() && (!_hitResult || typeof _hitResult.item.__representation === "undefined")) { |
1002 |
var _coords = this.toModelCoords(_point), |
|
1003 |
_data = { |
|
1004 |
id: Utils.getUID('node'), |
|
1005 |
created_by: this.renkan.current_user, |
|
1006 |
position: { |
|
1007 |
x: _coords.x, |
|
1008 |
y: _coords.y |
|
1009 |
} |
|
1010 |
}, |
|
1011 |
_node = this.renkan.project.addNode(_data); |
|
1012 |
this.getRepresentationByModel(_node).openEditor(); |
|
1013 |
} |
|
1014 |
paper.view.draw(); |
|
1015 |
}, |
|
1016 |
defaultDropHandler: function(_data) { |
|
1017 |
var newNode = {}; |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
1018 |
var snippet = ""; |
| 284 | 1019 |
switch(_data["text/x-iri-specific-site"]) { |
| 286 | 1020 |
case "twitter": |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
1021 |
snippet = $('<div>').html(_data["text/x-iri-selected-html"]); |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
1022 |
var tweetdiv = snippet.find(".tweet"); |
| 286 | 1023 |
newNode.title = this.renkan.translate("Tweet by ") + tweetdiv.attr("data-name"); |
1024 |
newNode.uri = "http://twitter.com/" + tweetdiv.attr("data-screen-name") + "/status/" + tweetdiv.attr("data-tweet-id"); |
|
1025 |
newNode.image = tweetdiv.find(".avatar").attr("src"); |
|
1026 |
newNode.description = tweetdiv.find(".js-tweet-text:first").text(); |
|
1027 |
break; |
|
1028 |
case "google": |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
1029 |
snippet = $('<div>').html(_data["text/x-iri-selected-html"]); |
| 286 | 1030 |
newNode.title = snippet.find("h3:first").text().trim(); |
1031 |
newNode.uri = snippet.find("h3 a").attr("href"); |
|
1032 |
newNode.description = snippet.find(".st:first").text().trim(); |
|
1033 |
break; |
|
1034 |
default: |
|
1035 |
if (_data["text/x-iri-source-uri"]) { |
|
1036 |
newNode.uri = _data["text/x-iri-source-uri"]; |
|
1037 |
} |
|
1038 |
} |
|
| 284 | 1039 |
if (_data["text/plain"] || _data["text/x-iri-selected-text"]) { |
1040 |
newNode.description = (_data["text/plain"] || _data["text/x-iri-selected-text"]).replace(/[\s\n]+/gm,' ').trim(); |
|
1041 |
} |
|
1042 |
if (_data["text/html"] || _data["text/x-iri-selected-html"]) { |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
1043 |
snippet = $('<div>').html(_data["text/html"] || _data["text/x-iri-selected-html"]); |
| 284 | 1044 |
var _svgimgs = snippet.find("image"); |
1045 |
if (_svgimgs.length) { |
|
1046 |
newNode.image = _svgimgs.attr("xlink:href"); |
|
1047 |
} |
|
1048 |
var _svgpaths = snippet.find("path"); |
|
1049 |
if (_svgpaths.length) { |
|
1050 |
newNode.clipPath = _svgpaths.attr("d"); |
|
1051 |
} |
|
1052 |
var _imgs = snippet.find("img"); |
|
1053 |
if (_imgs.length) { |
|
1054 |
newNode.image = _imgs[0].src; |
|
1055 |
} |
|
1056 |
var _as = snippet.find("a"); |
|
1057 |
if (_as.length) { |
|
1058 |
newNode.uri = _as[0].href; |
|
1059 |
} |
|
1060 |
newNode.title = snippet.find("[title]").attr("title") || newNode.title; |
|
1061 |
newNode.description = snippet.text().replace(/[\s\n]+/gm,' ').trim(); |
|
1062 |
} |
|
1063 |
if (_data["text/uri-list"]) { |
|
1064 |
newNode.uri = _data["text/uri-list"]; |
|
1065 |
} |
|
1066 |
if (_data["text/x-moz-url"] && !newNode.title) { |
|
1067 |
newNode.title = (_data["text/x-moz-url"].split("\n")[1] || "").trim(); |
|
1068 |
if (newNode.title === newNode.uri) { |
|
1069 |
newNode.title = false; |
|
1070 |
} |
|
1071 |
} |
|
1072 |
if (_data["text/x-iri-source-title"] && !newNode.title) { |
|
1073 |
newNode.title = _data["text/x-iri-source-title"]; |
|
1074 |
} |
|
1075 |
if (_data["text/html"] || _data["text/x-iri-selected-html"]) { |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
1076 |
snippet = $('<div>').html(_data["text/html"] || _data["text/x-iri-selected-html"]); |
| 284 | 1077 |
newNode.image = snippet.find("[data-image]").attr("data-image") || newNode.image; |
1078 |
newNode.uri = snippet.find("[data-uri]").attr("data-uri") || newNode.uri; |
|
1079 |
newNode.title = snippet.find("[data-title]").attr("data-title") || newNode.title; |
|
1080 |
newNode.description = snippet.find("[data-description]").attr("data-description") || newNode.description; |
|
1081 |
newNode.clipPath = snippet.find("[data-clip-path]").attr("data-clip-path") || newNode.clipPath; |
|
1082 |
} |
|
| 286 | 1083 |
|
1084 |
if (!newNode.title) { |
|
1085 |
newNode.title = this.renkan.translate("Dragged resource"); |
|
| 284 | 1086 |
} |
| 286 | 1087 |
var fields = ["title", "description", "uri", "image"]; |
1088 |
for (var i = 0; i < fields.length; i++) { |
|
1089 |
var f = fields[i]; |
|
1090 |
if (_data["text/x-iri-" + f] || _data[f]) { |
|
1091 |
newNode[f] = _data["text/x-iri-" + f] || _data[f]; |
|
1092 |
} |
|
1093 |
if (newNode[f] === "none" || newNode[f] === "null") { |
|
1094 |
newNode[f] = undefined; |
|
1095 |
} |
|
1096 |
} |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
1097 |
|
| 284 | 1098 |
if(typeof this.renkan.options.drop_enhancer === "function"){ |
1099 |
newNode = this.renkan.options.drop_enhancer(newNode, _data); |
|
1100 |
} |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
1101 |
|
| 284 | 1102 |
return newNode; |
1103 |
||
1104 |
}, |
|
1105 |
dropData: function(_data, _event) { |
|
1106 |
if (!this.isEditable()) { |
|
1107 |
return; |
|
1108 |
} |
|
1109 |
if (_data["text/json"] || _data["application/json"]) { |
|
1110 |
try { |
|
1111 |
var jsondata = JSON.parse(_data["text/json"] || _data["application/json"]); |
|
| 433 | 1112 |
_.extend(_data,jsondata); |
| 284 | 1113 |
} |
1114 |
catch(e) {} |
|
1115 |
} |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
1116 |
|
| 284 | 1117 |
var newNode = (typeof this.renkan.options.drop_handler === "undefined")?this.defaultDropHandler(_data):this.renkan.options.drop_handler(_data); |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
1118 |
|
| 284 | 1119 |
var _off = this.canvas_$.offset(), |
1120 |
_point = new paper.Point([ |
|
1121 |
_event.pageX - _off.left, |
|
1122 |
_event.pageY - _off.top |
|
1123 |
]), |
|
1124 |
_coords = this.toModelCoords(_point), |
|
1125 |
_nodedata = { |
|
1126 |
id: Utils.getUID('node'), |
|
1127 |
created_by: this.renkan.current_user, |
|
1128 |
uri: newNode.uri || "", |
|
1129 |
title: newNode.title || "", |
|
1130 |
description: newNode.description || "", |
|
1131 |
image: newNode.image || "", |
|
1132 |
color: newNode.color || undefined, |
|
1133 |
clip_path: newNode.clipPath || undefined, |
|
1134 |
position: { |
|
1135 |
x: _coords.x, |
|
1136 |
y: _coords.y |
|
1137 |
} |
|
1138 |
}; |
|
1139 |
var _node = this.renkan.project.addNode(_nodedata), |
|
1140 |
_repr = this.getRepresentationByModel(_node); |
|
1141 |
if (_event.type === "drop") { |
|
1142 |
_repr.openEditor(); |
|
1143 |
} |
|
1144 |
}, |
|
1145 |
fullScreen: function() { |
|
| 575 | 1146 |
this.currentWidth = this.$.width(); |
1147 |
this.currentHeight = this.$.height(); |
|
| 555 | 1148 |
|
| 575 | 1149 |
var _el = this.renkan.$[0]; |
1150 |
paper.view.off("resize"); |
|
1151 |
Screenfull.toggle(_el); |
|
| 284 | 1152 |
}, |
1153 |
addNodeBtn: function() { |
|
1154 |
if (this.click_mode === Utils._CLICKMODE_ADDNODE) { |
|
1155 |
this.click_mode = false; |
|
1156 |
this.notif_$.hide(); |
|
1157 |
} else { |
|
1158 |
this.click_mode = Utils._CLICKMODE_ADDNODE; |
|
1159 |
this.notif_$.text(this.renkan.translate("Click on the background canvas to add a node")).fadeIn(); |
|
1160 |
} |
|
1161 |
return false; |
|
1162 |
}, |
|
1163 |
addEdgeBtn: function() { |
|
1164 |
if (this.click_mode === Utils._CLICKMODE_STARTEDGE || this.click_mode === Utils._CLICKMODE_ENDEDGE) { |
|
1165 |
this.click_mode = false; |
|
1166 |
this.notif_$.hide(); |
|
1167 |
} else { |
|
1168 |
this.click_mode = Utils._CLICKMODE_STARTEDGE; |
|
1169 |
this.notif_$.text(this.renkan.translate("Click on a first node to start the edge")).fadeIn(); |
|
1170 |
} |
|
1171 |
return false; |
|
1172 |
}, |
|
| 297 | 1173 |
exportProject: function() { |
1174 |
var projectJSON = this.renkan.project.toJSON(), |
|
1175 |
downloadLink = document.createElement("a"), |
|
1176 |
projectId = projectJSON.id, |
|
1177 |
fileNameToSaveAs = projectId + ".json"; |
|
1178 |
||
1179 |
// clean ids |
|
1180 |
delete projectJSON.id; |
|
| 298 | 1181 |
delete projectJSON._id; |
1182 |
delete projectJSON.space_id; |
|
1183 |
||
|
463
41325cc50574
make hidden nodes work on java + correct projects export
ymh <ymh.work@gmail.com>
parents:
455
diff
changeset
|
1184 |
var objId, |
|
41325cc50574
make hidden nodes work on java + correct projects export
ymh <ymh.work@gmail.com>
parents:
455
diff
changeset
|
1185 |
idsMap = {}, |
|
41325cc50574
make hidden nodes work on java + correct projects export
ymh <ymh.work@gmail.com>
parents:
455
diff
changeset
|
1186 |
hiddenNodes; |
| 298 | 1187 |
|
| 297 | 1188 |
_.each(projectJSON.nodes, function(e,i,l) { |
| 298 | 1189 |
objId = e.id || e._id; |
| 297 | 1190 |
delete e._id; |
1191 |
delete e.id; |
|
| 298 | 1192 |
idsMap[objId] = e['@id'] = Utils.getUUID4(); |
| 297 | 1193 |
}); |
1194 |
_.each(projectJSON.edges, function(e,i,l) { |
|
1195 |
delete e._id; |
|
1196 |
delete e.id; |
|
| 298 | 1197 |
e.to = idsMap[e.to]; |
1198 |
e.from = idsMap[e.from]; |
|
| 297 | 1199 |
}); |
1200 |
_.each(projectJSON.views, function(e,i,l) { |
|
1201 |
delete e._id; |
|
1202 |
delete e.id; |
|
|
470
47308aa6ce94
correction for rich text editor. correct problem of empty description. make sure that the editor toolbr close
ymh <ymh.work@gmail.com>
parents:
463
diff
changeset
|
1203 |
|
|
463
41325cc50574
make hidden nodes work on java + correct projects export
ymh <ymh.work@gmail.com>
parents:
455
diff
changeset
|
1204 |
if(e.hidden_nodes) { |
|
41325cc50574
make hidden nodes work on java + correct projects export
ymh <ymh.work@gmail.com>
parents:
455
diff
changeset
|
1205 |
hiddenNodes = e.hidden_nodes; |
|
41325cc50574
make hidden nodes work on java + correct projects export
ymh <ymh.work@gmail.com>
parents:
455
diff
changeset
|
1206 |
e.hidden_nodes = []; |
|
41325cc50574
make hidden nodes work on java + correct projects export
ymh <ymh.work@gmail.com>
parents:
455
diff
changeset
|
1207 |
_.each(hiddenNodes, function(h,j) { |
|
41325cc50574
make hidden nodes work on java + correct projects export
ymh <ymh.work@gmail.com>
parents:
455
diff
changeset
|
1208 |
e.hidden_nodes.push(idsMap[h]); |
|
41325cc50574
make hidden nodes work on java + correct projects export
ymh <ymh.work@gmail.com>
parents:
455
diff
changeset
|
1209 |
}); |
|
41325cc50574
make hidden nodes work on java + correct projects export
ymh <ymh.work@gmail.com>
parents:
455
diff
changeset
|
1210 |
} |
| 297 | 1211 |
}); |
1212 |
projectJSON.users = []; |
|
1213 |
||
1214 |
var projectJSONStr = JSON.stringify(projectJSON, null, 2); |
|
1215 |
var blob = new Blob([projectJSONStr], {type: "application/json;charset=utf-8"}); |
|
1216 |
filesaver(blob,fileNameToSaveAs); |
|
1217 |
||
1218 |
}, |
|
|
537
88703fb5aaaf
correct view initisalization for java
ymh <ymh.work@gmail.com>
parents:
534
diff
changeset
|
1219 |
setViewparameters: function(_params){ |
| 524 | 1220 |
this.removeRepresentationsOfType("View"); |
|
510
a8f02d66bf02
adapt the viewRepr to support a temp View (a representation without a model)
rougeronj
parents:
508
diff
changeset
|
1221 |
if ($.isEmptyObject(_params)){ |
| 524 | 1222 |
this.view = this.addRepresentation("View", this.renkan.project.get("views").at(this.validViewIndex(this.renkan.options.default_index_view))); |
|
510
a8f02d66bf02
adapt the viewRepr to support a temp View (a representation without a model)
rougeronj
parents:
508
diff
changeset
|
1223 |
return; |
|
a8f02d66bf02
adapt the viewRepr to support a temp View (a representation without a model)
rougeronj
parents:
508
diff
changeset
|
1224 |
} |
| 525 | 1225 |
if (typeof _params.viewIndex !== 'undefined'){ |
1226 |
this.view = this.addRepresentation("View", this.renkan.project.get("views").at(this.validViewIndex(_params.viewIndex))); |
|
| 554 | 1227 |
} else { |
1228 |
this.view = this.addRepresentation("View", this.renkan.project.get("views").at(this.validViewIndex(this.renkan.options.default_index_view))); |
|
|
519
b94a34c139c1
update parameters function to accept idView parameter
rougeronj
parents:
512
diff
changeset
|
1229 |
} |
|
b94a34c139c1
update parameters function to accept idView parameter
rougeronj
parents:
512
diff
changeset
|
1230 |
if (typeof _params.view !== 'undefined' && _params.view.split(",").length >= 3){ |
|
510
a8f02d66bf02
adapt the viewRepr to support a temp View (a representation without a model)
rougeronj
parents:
508
diff
changeset
|
1231 |
var viewParams = _params.view.split(","); |
|
519
b94a34c139c1
update parameters function to accept idView parameter
rougeronj
parents:
512
diff
changeset
|
1232 |
var params = { |
|
b94a34c139c1
update parameters function to accept idView parameter
rougeronj
parents:
512
diff
changeset
|
1233 |
"project": this.renkan.project, |
|
b94a34c139c1
update parameters function to accept idView parameter
rougeronj
parents:
512
diff
changeset
|
1234 |
"offset": { |
|
b94a34c139c1
update parameters function to accept idView parameter
rougeronj
parents:
512
diff
changeset
|
1235 |
"x": parseFloat(viewParams[0]), |
|
b94a34c139c1
update parameters function to accept idView parameter
rougeronj
parents:
512
diff
changeset
|
1236 |
"y": parseFloat(viewParams[1]) |
|
b94a34c139c1
update parameters function to accept idView parameter
rougeronj
parents:
512
diff
changeset
|
1237 |
}, |
|
b94a34c139c1
update parameters function to accept idView parameter
rougeronj
parents:
512
diff
changeset
|
1238 |
"zoom_level": parseFloat(viewParams[2]) |
|
b94a34c139c1
update parameters function to accept idView parameter
rougeronj
parents:
512
diff
changeset
|
1239 |
}; |
| 554 | 1240 |
this.view.setScale(params.zoom_level, new paper.Point(params.offset)); |
1241 |
} |
|
| 560 | 1242 |
//if view parameters = autoscale we apply a zoom fit on the view. |
| 554 | 1243 |
if ((typeof _params.view !== 'undefined' && _params.view === "autoscale")){ |
1244 |
this.view.autoScale(); |
|
1245 |
} |
|
| 560 | 1246 |
//if viewsNodes = false we show all the node by default. |
| 554 | 1247 |
if (typeof _params.viewsNodes !== 'undefined'){ |
1248 |
if (_params.viewsNodes === "true"){ |
|
1249 |
this.view.hiddenNodes = (this.view.params.hidden_nodes || []).concat(); |
|
1250 |
this.view.hideNodes(); |
|
1251 |
} else { |
|
1252 |
this.view.showNodes(false); |
|
|
510
a8f02d66bf02
adapt the viewRepr to support a temp View (a representation without a model)
rougeronj
parents:
508
diff
changeset
|
1253 |
} |
|
a8f02d66bf02
adapt the viewRepr to support a temp View (a representation without a model)
rougeronj
parents:
508
diff
changeset
|
1254 |
} |
| 511 | 1255 |
//other parameters must go after because most of them depends on a view that must be initialize before |
| 520 | 1256 |
this.unhighlightAll(); |
| 511 | 1257 |
if (typeof _params.idNode !== 'undefined'){ |
|
537
88703fb5aaaf
correct view initisalization for java
ymh <ymh.work@gmail.com>
parents:
534
diff
changeset
|
1258 |
this.highlightModel(this.renkan.project.get("nodes").get(_params.idNode)); |
| 511 | 1259 |
} |
| 473 | 1260 |
}, |
| 524 | 1261 |
validViewIndex: function(index){ |
1262 |
//check if the view index exist (negative index is from the end) and return the correct index or false if doesn't exist |
|
1263 |
var _index = parseInt(index); |
|
1264 |
var validIndex = 0; |
|
1265 |
if (_index < 0){ |
|
1266 |
validIndex = this.renkan.project.get("views").length + _index; |
|
1267 |
} else { |
|
|
537
88703fb5aaaf
correct view initisalization for java
ymh <ymh.work@gmail.com>
parents:
534
diff
changeset
|
1268 |
validIndex = _index; |
| 524 | 1269 |
} |
1270 |
if (typeof this.renkan.project.get("views").at(_index) === 'undefined'){ |
|
1271 |
validIndex = 0; |
|
1272 |
} |
|
1273 |
return validIndex; |
|
1274 |
}, |
|
| 284 | 1275 |
foldBins: function() { |
1276 |
var foldBinsButton = this.$.find(".Rk-Fold-Bins"), |
|
| 557 | 1277 |
bins = this.renkan.$.find(".Rk-Bins"), |
1278 |
_delta = 0; |
|
|
377
1d87c4342e5d
Close #36 and #25 - zoom while resizing and minimap disappearing when back from fullscreen
rougeronj
parents:
373
diff
changeset
|
1279 |
var _this = this, |
| 396 | 1280 |
sizeBef = _this.canvas_$.width(), |
1281 |
sizeAft; |
|
| 340 | 1282 |
if (bins.position().left < 0) { |
| 557 | 1283 |
_delta= new paper.Point([-bins.width()/2, 0]); |
| 284 | 1284 |
bins.animate({left: 0},250); |
1285 |
this.$.animate({left: 300},250,function() { |
|
1286 |
var w = _this.$.width(); |
|
1287 |
paper.view.viewSize = new paper.Size([w, _this.canvas_$.height()]); |
|
1288 |
}); |
|
|
379
81573f4331b5
minor correction to improve zooming while bins are closing
rougeronj
parents:
377
diff
changeset
|
1289 |
if ((sizeBef - bins.width()) < bins.height()){ |
| 396 | 1290 |
sizeAft = sizeBef; |
|
377
1d87c4342e5d
Close #36 and #25 - zoom while resizing and minimap disappearing when back from fullscreen
rougeronj
parents:
373
diff
changeset
|
1291 |
} else { |
| 396 | 1292 |
sizeAft = sizeBef - bins.width(); |
|
377
1d87c4342e5d
Close #36 and #25 - zoom while resizing and minimap disappearing when back from fullscreen
rougeronj
parents:
373
diff
changeset
|
1293 |
} |
| 284 | 1294 |
foldBinsButton.html("«"); |
1295 |
} else { |
|
| 557 | 1296 |
_delta= new paper.Point([bins.width()/2, 0]); |
| 284 | 1297 |
bins.animate({left: -300},250); |
1298 |
this.$.animate({left: 0},250,function() { |
|
1299 |
var w = _this.$.width(); |
|
1300 |
paper.view.viewSize = new paper.Size([w, _this.canvas_$.height()]); |
|
1301 |
}); |
|
|
377
1d87c4342e5d
Close #36 and #25 - zoom while resizing and minimap disappearing when back from fullscreen
rougeronj
parents:
373
diff
changeset
|
1302 |
sizeAft = sizeBef+300; |
| 284 | 1303 |
foldBinsButton.html("»"); |
1304 |
} |
|
| 557 | 1305 |
this.view.paperShift(_delta); |
| 284 | 1306 |
}, |
1307 |
save: function() { }, |
|
1308 |
open: function() { } |
|
| 433 | 1309 |
}).value(); |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
1310 |
|
| 284 | 1311 |
/* Scene End */ |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
1312 |
|
| 284 | 1313 |
return Scene; |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
286
diff
changeset
|
1314 |
|
| 284 | 1315 |
}); |