| author | ymh <ymh.work@gmail.com> |
| Tue, 02 Jun 2015 00:39:47 +0200 | |
| changeset 458 | 423bdf56d103 |
| parent 434 | 0d5998b32a7c |
| child 459 | 98cae534083d |
| 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" : "", |
| 284 | 34 |
from_title: _from_model.get("title"), |
35 |
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
|
36 |
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
|
37 |
to_color: (_to_model.has("style") && _to_model.get("style").color) || (_to_model.get("created_by") || Utils._USER_PLACEHOLDER(this.renkan)).get("color"), |
| 284 | 38 |
created_by_color: _created_by.get("color"), |
39 |
created_by_title: _created_by.get("title") |
|
40 |
}, |
|
41 |
renkan: this.renkan, |
|
42 |
shortenText: Utils.shortenText, |
|
43 |
options: this.options |
|
44 |
})); |
|
45 |
this.redraw(); |
|
46 |
var _this = this, |
|
47 |
closeEditor = function() { |
|
48 |
_this.renderer.removeRepresentation(_this); |
|
49 |
paper.view.draw(); |
|
50 |
}; |
|
51 |
this.editor_$.find(".Rk-CloseX").click(closeEditor); |
|
52 |
this.editor_$.find(".Rk-Edit-Goto").click(function() { |
|
53 |
if (!_model.get("uri")) { |
|
54 |
return false; |
|
55 |
} |
|
56 |
}); |
|
57 |
||
58 |
if (this.renderer.isEditable()) { |
|
59 |
||
| 433 | 60 |
var onFieldChange = _.throttle(function() { |
|
434
0d5998b32a7c
clean, and finalize lodash migration
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
61 |
_.defer(function() { |
|
0d5998b32a7c
clean, and finalize lodash migration
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
62 |
if (_this.renderer.isEditable()) { |
|
0d5998b32a7c
clean, and finalize lodash migration
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
63 |
var _data = { |
| 433 | 64 |
title: _this.editor_$.find(".Rk-Edit-Title").val() |
|
434
0d5998b32a7c
clean, and finalize lodash migration
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
65 |
}; |
|
0d5998b32a7c
clean, and finalize lodash migration
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
66 |
if (_this.options.show_edge_editor_uri) { |
|
0d5998b32a7c
clean, and finalize lodash migration
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
67 |
_data.uri = _this.editor_$.find(".Rk-Edit-URI").val(); |
|
0d5998b32a7c
clean, and finalize lodash migration
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
68 |
} |
|
458
423bdf56d103
migrated to style, added dash style to client + small refactoring for shapes + triangle
ymh <ymh.work@gmail.com>
parents:
434
diff
changeset
|
69 |
if (_this.options.show_node_editor_style) { |
|
423bdf56d103
migrated to style, added dash style to client + small refactoring for shapes + triangle
ymh <ymh.work@gmail.com>
parents:
434
diff
changeset
|
70 |
var dash = _this.editor_$.find(".Rk-Edit-Dash").is(':checked'); |
|
423bdf56d103
migrated to style, added dash style to client + small refactoring for shapes + triangle
ymh <ymh.work@gmail.com>
parents:
434
diff
changeset
|
71 |
_data.style = _.assign( ((_model.has("style") && _.clone(_model.get("style"))) || {}), {dash: dash}); |
|
423bdf56d103
migrated to style, added dash style to client + small refactoring for shapes + triangle
ymh <ymh.work@gmail.com>
parents:
434
diff
changeset
|
72 |
} |
|
434
0d5998b32a7c
clean, and finalize lodash migration
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
73 |
_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
|
74 |
_model.set(_data); |
|
0d5998b32a7c
clean, and finalize lodash migration
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
75 |
paper.view.draw(); |
|
0d5998b32a7c
clean, and finalize lodash migration
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
76 |
} else { |
|
0d5998b32a7c
clean, and finalize lodash migration
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
77 |
closeEditor(); |
| 284 | 78 |
} |
|
434
0d5998b32a7c
clean, and finalize lodash migration
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
79 |
}); |
| 433 | 80 |
},500); |
| 284 | 81 |
|
82 |
this.editor_$.on("keyup", function(_e) { |
|
83 |
if (_e.keyCode === 27) { |
|
84 |
closeEditor(); |
|
85 |
} |
|
86 |
}); |
|
87 |
||
88 |
this.editor_$.find("input").on("keyup change paste", onFieldChange); |
|
89 |
||
90 |
this.editor_$.find(".Rk-Edit-Vocabulary").change(function() { |
|
91 |
var e = $(this), |
|
92 |
v = e.val(); |
|
93 |
if (v) { |
|
94 |
_this.editor_$.find(".Rk-Edit-Title").val(e.find(":selected").text()); |
|
95 |
_this.editor_$.find(".Rk-Edit-URI").val(v); |
|
96 |
onFieldChange(); |
|
97 |
} |
|
98 |
}); |
|
99 |
this.editor_$.find(".Rk-Edit-Direction").click(function() { |
|
100 |
if (_this.renderer.isEditable()) { |
|
101 |
_model.set({ |
|
102 |
from: _model.get("to"), |
|
103 |
to: _model.get("from") |
|
104 |
}); |
|
105 |
_this.draw(); |
|
106 |
} else { |
|
107 |
closeEditor(); |
|
108 |
} |
|
109 |
}); |
|
110 |
||
111 |
var _picker = _this.editor_$.find(".Rk-Edit-ColorPicker"); |
|
112 |
||
113 |
this.editor_$.find(".Rk-Edit-ColorPicker-Wrapper").hover( |
|
114 |
function(_e) { |
|
115 |
_e.preventDefault(); |
|
116 |
_picker.show(); |
|
117 |
}, |
|
118 |
function(_e) { |
|
119 |
_e.preventDefault(); |
|
120 |
_picker.hide(); |
|
121 |
} |
|
122 |
); |
|
123 |
||
124 |
_picker.find("li").hover( |
|
125 |
function(_e) { |
|
126 |
_e.preventDefault(); |
|
127 |
_this.editor_$.find(".Rk-Edit-Color").css("background", $(this).attr("data-color")); |
|
128 |
}, |
|
129 |
function(_e) { |
|
130 |
_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
|
131 |
_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 | 132 |
} |
133 |
).click(function(_e) { |
|
134 |
_e.preventDefault(); |
|
135 |
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
|
136 |
_model.set("style", _.assign( ((_model.has("style") && _.clone(_model.get("style"))) || {}), {color: $(this).attr("data-color")})); |
| 284 | 137 |
_picker.hide(); |
138 |
paper.view.draw(); |
|
139 |
} else { |
|
140 |
closeEditor(); |
|
141 |
} |
|
142 |
}); |
|
143 |
} |
|
144 |
}, |
|
145 |
redraw: function() { |
|
146 |
var _coords = this.source_representation.paper_coords; |
|
147 |
Utils.drawEditBox(this.options, _coords, this.editor_block, 5, this.editor_$); |
|
148 |
this.editor_$.show(); |
|
149 |
paper.view.draw(); |
|
150 |
} |
|
| 433 | 151 |
}).value(); |
| 284 | 152 |
|
153 |
/* EdgeEditor End */ |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
154 |
|
| 284 | 155 |
return EdgeEditor; |
156 |
||
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
157 |
}); |