| author | rougeronj |
| Wed, 11 Feb 2015 12:33:19 +0100 | |
| changeset 384 | 6a7930a0d4d1 |
| parent 331 | 0628ed75e8d3 |
| child 385 | 29dcaa4c1748 |
| 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 |
/* NodeEditor Begin */ |
|
8 |
//var NodeEditor = Renderer.NodeEditor = Utils.inherit(Renderer._BaseEditor); |
|
9 |
var NodeEditor = Utils.inherit(BaseEditor); |
|
10 |
||
11 |
_(NodeEditor.prototype).extend({ |
|
12 |
template: _.template( |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
13 |
'<h2><span class="Rk-CloseX">×</span><%-renkan.translate("Edit Node")%></span></h2>' + |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
14 |
'<p><label><%-renkan.translate("Title:")%></label><input class="Rk-Edit-Title" type="text" value="<%-node.title%>"/></p>' + |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
15 |
'<% if (options.show_node_editor_uri) { %><p><label><%-renkan.translate("URI:")%></label><input class="Rk-Edit-URI" type="text" value="<%-node.uri%>"/><a class="Rk-Edit-Goto" href="<%-node.uri%>" target="_blank"></a></p><% } %>' + |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
16 |
'<% if (options.show_node_editor_description) { %><p><label><%-renkan.translate("Description:")%></label><textarea class="Rk-Edit-Description"><%-node.description%></textarea></p><% } %>' + |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
17 |
'<% if (options.show_node_editor_size) { %><p><span class="Rk-Editor-Label"><%-renkan.translate("Size:")%></span><a href="#" class="Rk-Edit-Size-Down">-</a><span class="Rk-Edit-Size-Value"><%-node.size%></span><a href="#" class="Rk-Edit-Size-Up">+</a></p><% } %>' + |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
18 |
'<% if (options.show_node_editor_color) { %><div class="Rk-Editor-p"><span class="Rk-Editor-Label"><%-renkan.translate("Node color:")%></span><div class="Rk-Edit-ColorPicker-Wrapper"><span class="Rk-Edit-Color" style="background:<%-node.color%>;"><span class="Rk-Edit-ColorTip"></span></span>' + |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
19 |
'<%= renkan.colorPicker %><span class="Rk-Edit-ColorPicker-Text"><%- renkan.translate("Choose color") %></span></div></div><% } %>' + |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
20 |
'<% if (options.show_node_editor_image) { %><div class="Rk-Edit-ImgWrap"><div class="Rk-Edit-ImgPreview"><img src="<%-node.image || node.image_placeholder%>" />' + |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
21 |
'<% if (node.clip_path) { %><svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewbox="0 0 1 1" preserveAspectRatio="none"><path style="stroke-width: .02; stroke:red; fill-opacity:.3; fill:red;" d="<%- node.clip_path %>"/></svg><% }%>' + |
|
384
6a7930a0d4d1
Close #60 - Add a trash icon to delete the image URL
rougeronj
parents:
331
diff
changeset
|
22 |
'</div></div><p><label><%-renkan.translate("Image URL:")%></label><div><a class="Rk-Edit-Image-Del" href="#"></a><input class="Rk-Edit-Image" type="text" value="<%-node.image%>"/></div></p>' + |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
23 |
'<p><label><%-renkan.translate("Choose Image File:")%></label><input class="Rk-Edit-Image-File" type="file" accept="image/*"/></p><% } %>' + |
| 330 | 24 |
'<% if (options.show_node_editor_creator && node.has_creator) { %><p><span class="Rk-Editor-Label"><%-renkan.translate("Created by:")%></span> <span class="Rk-UserColor" style="background:<%-node.created_by_color%>;"></span><%- shortenText(node.created_by_title, 25) %></p><% } %>' + |
| 331 | 25 |
'<% if (options.change_shapes) { %><p><label><%-renkan.translate("Shapes available")%>:</label> <select class="Rk-Edit-Shape">' + |
| 330 | 26 |
'<option class="Rk-Edit-Vocabulary-Property" value="circle"<% if (node.shape === "circle") { %> selected<% } %>><%- renkan.translate("Circle") %></option>' + |
27 |
'<option class="Rk-Edit-Vocabulary-Property" value="rectangle"<% if (node.shape === "rectangle") { %> selected<% } %>><%- renkan.translate("Square") %></option>' + |
|
28 |
'<option class="Rk-Edit-Vocabulary-Property" value="diamond"<% if (node.shape === "diamond") { %> selected<% } %>><%- renkan.translate("Diamond") %></option>' + |
|
29 |
'<option class="Rk-Edit-Vocabulary-Property" value="polygon"<% if (node.shape === "polygon") { %> selected<% } %>><%- renkan.translate("Hexagone") %></option>' + |
|
30 |
'<option class="Rk-Edit-Vocabulary-Property" value="ellipse"<% if (node.shape === "ellipse") { %> selected<% } %>><%- renkan.translate("Ellipse") %></option>' + |
|
31 |
'<option class="Rk-Edit-Vocabulary-Property" value="star"<% if (node.shape === "star") { %> selected<% } %>><%- renkan.translate("Star") %></option>' + |
|
32 |
'</select></p><% } %>' |
|
| 284 | 33 |
), |
34 |
readOnlyTemplate: _.template( |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
35 |
'<h2><span class="Rk-CloseX">×</span><% if (options.show_node_tooltip_color) { %><span class="Rk-UserColor" style="background:<%-node.color%>;"></span><% } %>' + |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
36 |
'<span class="Rk-Display-Title"><% if (node.uri) { %><a href="<%-node.uri%>" target="_blank"><% } %><%-node.title%><% if (node.uri) { %></a><% } %></span></h2>' + |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
37 |
'<% if (node.uri && options.show_node_tooltip_uri) { %><p class="Rk-Display-URI"><a href="<%-node.uri%>" target="_blank"><%-node.short_uri%></a></p><% } %>' + |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
38 |
'<% if (options.show_node_tooltip_description) { %><p class="Rk-Display-Description"><%-node.description%></p><% } %>' + |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
39 |
'<% if (node.image && options.show_node_tooltip_image) { %><img class="Rk-Display-ImgPreview" src="<%-node.image%>" /><% } %>' + |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
40 |
'<% if (node.has_creator && options.show_node_tooltip_creator) { %><p><span class="Rk-Editor-Label"><%-renkan.translate("Created by:")%></span><span class="Rk-UserColor" style="background:<%-node.created_by_color%>;"></span><%- shortenText(node.created_by_title, 25) %></p><% } %>' |
| 284 | 41 |
), |
42 |
draw: function() { |
|
43 |
var _model = this.source_representation.model, |
|
44 |
_created_by = _model.get("created_by") || Utils._USER_PLACEHOLDER(this.renkan), |
|
45 |
_template = (this.renderer.isEditable() ? this.template : this.readOnlyTemplate ), |
|
46 |
_image_placeholder = this.options.static_url + "img/image-placeholder.png", |
|
47 |
_size = (_model.get("size") || 0); |
|
48 |
this.editor_$ |
|
49 |
.html(_template({ |
|
50 |
node: { |
|
51 |
has_creator: !!_model.get("created_by"), |
|
52 |
title: _model.get("title"), |
|
53 |
uri: _model.get("uri"), |
|
54 |
short_uri: Utils.shortenText((_model.get("uri") || "").replace(/^(https?:\/\/)?(www\.)?/,'').replace(/\/$/,''),40), |
|
55 |
description: _model.get("description"), |
|
56 |
image: _model.get("image") || "", |
|
57 |
image_placeholder: _image_placeholder, |
|
58 |
color: _model.get("color") || _created_by.get("color"), |
|
59 |
clip_path: _model.get("clip_path") || false, |
|
60 |
created_by_color: _created_by.get("color"), |
|
61 |
created_by_title: _created_by.get("title"), |
|
| 330 | 62 |
size: (_size > 0 ? "+" : "") + _size, |
63 |
shape: _model.get("shape") || "circle" |
|
| 284 | 64 |
}, |
65 |
renkan: this.renkan, |
|
66 |
options: this.options, |
|
67 |
shortenText: Utils.shortenText |
|
68 |
})); |
|
69 |
this.redraw(); |
|
70 |
var _this = this, |
|
71 |
closeEditor = function() { |
|
72 |
_this.renderer.removeRepresentation(_this); |
|
73 |
paper.view.draw(); |
|
74 |
}; |
|
75 |
||
76 |
this.editor_$.find(".Rk-CloseX").click(closeEditor); |
|
77 |
||
78 |
this.editor_$.find(".Rk-Edit-Goto").click(function() { |
|
79 |
if (!_model.get("uri")) { |
|
80 |
return false; |
|
81 |
} |
|
82 |
}); |
|
83 |
||
84 |
if (this.renderer.isEditable()) { |
|
85 |
||
86 |
var onFieldChange = _(function() { |
|
87 |
_(function() { |
|
88 |
if (_this.renderer.isEditable()) { |
|
89 |
var _data = { |
|
| 330 | 90 |
title: _this.editor_$.find(".Rk-Edit-Title").val() |
| 284 | 91 |
}; |
92 |
if (_this.options.show_node_editor_uri) { |
|
93 |
_data.uri = _this.editor_$.find(".Rk-Edit-URI").val(); |
|
94 |
_this.editor_$.find(".Rk-Edit-Goto").attr("href",_data.uri || "#"); |
|
95 |
} |
|
96 |
if (_this.options.show_node_editor_image) { |
|
97 |
_data.image = _this.editor_$.find(".Rk-Edit-Image").val(); |
|
98 |
_this.editor_$.find(".Rk-Edit-ImgPreview").attr("src", _data.image || _image_placeholder); |
|
99 |
} |
|
100 |
if (_this.options.show_node_editor_description) { |
|
101 |
_data.description = _this.editor_$.find(".Rk-Edit-Description").val(); |
|
102 |
} |
|
| 330 | 103 |
if (_this.options.change_shapes) { |
| 331 | 104 |
if(_model.get("shape")!==_this.editor_$.find(".Rk-Edit-Shape").val()){ |
105 |
_data.shape = _this.editor_$.find(".Rk-Edit-Shape").val(); |
|
106 |
_data.shape_changed = true; |
|
107 |
} |
|
| 330 | 108 |
} |
| 284 | 109 |
_model.set(_data); |
110 |
_this.redraw(); |
|
| 331 | 111 |
// For an unknown reason, we have to set data twice when we change shape, otherwise the image disappears. |
112 |
if(_data.shape_changed===true){ |
|
113 |
_model.set(_data); |
|
114 |
} |
|
| 284 | 115 |
} else { |
116 |
closeEditor(); |
|
117 |
} |
|
118 |
}).defer(); |
|
119 |
}).throttle(500); |
|
| 331 | 120 |
|
| 284 | 121 |
this.editor_$.on("keyup", function(_e) { |
122 |
if (_e.keyCode === 27) { |
|
123 |
closeEditor(); |
|
124 |
} |
|
125 |
}); |
|
126 |
||
| 330 | 127 |
this.editor_$.find("input, textarea, select").on("change keyup paste", onFieldChange); |
| 284 | 128 |
|
129 |
this.editor_$.find(".Rk-Edit-Image-File").change(function() { |
|
130 |
if (this.files.length) { |
|
131 |
var f = this.files[0], |
|
132 |
fr = new FileReader(); |
|
133 |
if (f.type.substr(0,5) !== "image") { |
|
134 |
alert(_this.renkan.translate("This file is not an image")); |
|
135 |
return; |
|
136 |
} |
|
137 |
if (f.size > (_this.options.uploaded_image_max_kb * 1024)) { |
|
138 |
alert(_this.renkan.translate("Image size must be under ") + _this.options.uploaded_image_max_kb + _this.renkan.translate("KB")); |
|
139 |
return; |
|
140 |
} |
|
141 |
fr.onload = function(e) { |
|
142 |
_this.editor_$.find(".Rk-Edit-Image").val(e.target.result); |
|
143 |
onFieldChange(); |
|
144 |
}; |
|
145 |
fr.readAsDataURL(f); |
|
146 |
} |
|
147 |
}); |
|
148 |
this.editor_$.find(".Rk-Edit-Title")[0].focus(); |
|
149 |
||
150 |
var _picker = _this.editor_$.find(".Rk-Edit-ColorPicker"); |
|
151 |
||
152 |
this.editor_$.find(".Rk-Edit-ColorPicker-Wrapper").hover( |
|
153 |
function(_e) { |
|
154 |
_e.preventDefault(); |
|
155 |
_picker.show(); |
|
156 |
}, |
|
157 |
function(_e) { |
|
158 |
_e.preventDefault(); |
|
159 |
_picker.hide(); |
|
160 |
} |
|
161 |
); |
|
162 |
||
163 |
_picker.find("li").hover( |
|
164 |
function(_e) { |
|
165 |
_e.preventDefault(); |
|
166 |
_this.editor_$.find(".Rk-Edit-Color").css("background", $(this).attr("data-color")); |
|
167 |
}, |
|
168 |
function(_e) { |
|
169 |
_e.preventDefault(); |
|
170 |
_this.editor_$.find(".Rk-Edit-Color").css("background", _model.get("color") || (_model.get("created_by") || Utils._USER_PLACEHOLDER(_this.renkan)).get("color")); |
|
171 |
} |
|
172 |
).click(function(_e) { |
|
173 |
_e.preventDefault(); |
|
174 |
if (_this.renderer.isEditable()) { |
|
175 |
_model.set("color", $(this).attr("data-color")); |
|
176 |
_picker.hide(); |
|
177 |
paper.view.draw(); |
|
178 |
} else { |
|
179 |
closeEditor(); |
|
180 |
} |
|
181 |
}); |
|
182 |
||
183 |
var shiftSize = function(n) { |
|
184 |
if (_this.renderer.isEditable()) { |
|
185 |
var _newsize = n+(_model.get("size") || 0); |
|
186 |
_this.editor_$.find(".Rk-Edit-Size-Value").text((_newsize > 0 ? "+" : "") + _newsize); |
|
187 |
_model.set("size", _newsize); |
|
188 |
paper.view.draw(); |
|
189 |
} else { |
|
190 |
closeEditor(); |
|
191 |
} |
|
192 |
}; |
|
193 |
||
194 |
this.editor_$.find(".Rk-Edit-Size-Down").click(function() { |
|
195 |
shiftSize(-1); |
|
196 |
return false; |
|
197 |
}); |
|
198 |
this.editor_$.find(".Rk-Edit-Size-Up").click(function() { |
|
199 |
shiftSize(1); |
|
200 |
return false; |
|
201 |
}); |
|
|
384
6a7930a0d4d1
Close #60 - Add a trash icon to delete the image URL
rougeronj
parents:
331
diff
changeset
|
202 |
|
|
6a7930a0d4d1
Close #60 - Add a trash icon to delete the image URL
rougeronj
parents:
331
diff
changeset
|
203 |
this.editor_$.find(".Rk-Edit-Image-Del").click(function() { |
|
6a7930a0d4d1
Close #60 - Add a trash icon to delete the image URL
rougeronj
parents:
331
diff
changeset
|
204 |
_this.editor_$.find(".Rk-Edit-Image").val(''); |
|
6a7930a0d4d1
Close #60 - Add a trash icon to delete the image URL
rougeronj
parents:
331
diff
changeset
|
205 |
onFieldChange(); |
|
6a7930a0d4d1
Close #60 - Add a trash icon to delete the image URL
rougeronj
parents:
331
diff
changeset
|
206 |
return false; |
|
6a7930a0d4d1
Close #60 - Add a trash icon to delete the image URL
rougeronj
parents:
331
diff
changeset
|
207 |
}); |
| 284 | 208 |
} else { |
209 |
if (typeof this.source_representation.highlighted === "object") { |
|
210 |
var titlehtml = this.source_representation.highlighted.replace(_(_model.get("title")).escape(),'<span class="Rk-Highlighted">$1</span>'); |
|
211 |
this.editor_$.find(".Rk-Display-Title" + (_model.get("uri") ? " a" : "")).html(titlehtml); |
|
212 |
if (this.options.show_node_tooltip_description) { |
|
213 |
this.editor_$.find(".Rk-Display-Description").html(this.source_representation.highlighted.replace(_(_model.get("description")).escape(),'<span class="Rk-Highlighted">$1</span>')); |
|
214 |
} |
|
215 |
} |
|
216 |
} |
|
217 |
this.editor_$.find("img").load(function() { |
|
218 |
_this.redraw(); |
|
219 |
}); |
|
220 |
}, |
|
221 |
redraw: function() { |
|
222 |
var _coords = this.source_representation.paper_coords; |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
223 |
Utils.drawEditBox(this.options, _coords, this.editor_block, this.source_representation.circle_radius * 0.75, this.editor_$); |
| 284 | 224 |
this.editor_$.show(); |
225 |
paper.view.draw(); |
|
226 |
} |
|
227 |
}); |
|
228 |
||
229 |
/* NodeEditor End */ |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
230 |
|
| 284 | 231 |
return NodeEditor; |
232 |
||
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
233 |
}); |