| author | ymh <ymh.work@gmail.com> |
| Tue, 02 Jun 2015 00:39:47 +0200 | |
| changeset 458 | 423bdf56d103 |
| parent 435 | e529b633c339 |
| child 459 | 98cae534083d |
| permissions | -rw-r--r-- |
| 284 | 1 |
|
|
458
423bdf56d103
migrated to style, added dash style to client + small refactoring for shapes + triangle
ymh <ymh.work@gmail.com>
parents:
435
diff
changeset
|
2 |
define(['jquery', 'underscore', 'requtils', 'renderer/baseeditor', 'renderer/shapebuilder'], function ($, _, requtils, BaseEditor, ShapeBuilder) { |
|
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({ |
|
|
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
|
12 |
_init: function() { |
|
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
|
13 |
BaseEditor.prototype._init.apply(this); |
|
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
|
14 |
this.template = this.options.templates['templates/nodeeditor.html']; |
|
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
|
15 |
this.readOnlyTemplate = this.options.templates['templates/nodeeditor_readonly.html']; |
|
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
|
16 |
}, |
| 284 | 17 |
draw: function() { |
18 |
var _model = this.source_representation.model, |
|
19 |
_created_by = _model.get("created_by") || Utils._USER_PLACEHOLDER(this.renkan), |
|
20 |
_template = (this.renderer.isEditable() ? this.template : this.readOnlyTemplate ), |
|
21 |
_image_placeholder = this.options.static_url + "img/image-placeholder.png", |
|
22 |
_size = (_model.get("size") || 0); |
|
23 |
this.editor_$ |
|
24 |
.html(_template({ |
|
25 |
node: { |
|
26 |
has_creator: !!_model.get("created_by"), |
|
27 |
title: _model.get("title"), |
|
28 |
uri: _model.get("uri"), |
|
29 |
short_uri: Utils.shortenText((_model.get("uri") || "").replace(/^(https?:\/\/)?(www\.)?/,'').replace(/\/$/,''),40), |
|
30 |
description: _model.get("description"), |
|
31 |
image: _model.get("image") || "", |
|
32 |
image_placeholder: _image_placeholder, |
|
|
458
423bdf56d103
migrated to style, added dash style to client + small refactoring for shapes + triangle
ymh <ymh.work@gmail.com>
parents:
435
diff
changeset
|
33 |
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:
435
diff
changeset
|
34 |
dash: _model.has("style") && _model.get("style").dash ? "checked" : "", |
| 284 | 35 |
clip_path: _model.get("clip_path") || false, |
36 |
created_by_color: _created_by.get("color"), |
|
37 |
created_by_title: _created_by.get("title"), |
|
| 330 | 38 |
size: (_size > 0 ? "+" : "") + _size, |
39 |
shape: _model.get("shape") || "circle" |
|
| 284 | 40 |
}, |
41 |
renkan: this.renkan, |
|
42 |
options: this.options, |
|
|
458
423bdf56d103
migrated to style, added dash style to client + small refactoring for shapes + triangle
ymh <ymh.work@gmail.com>
parents:
435
diff
changeset
|
43 |
shortenText: Utils.shortenText, |
|
423bdf56d103
migrated to style, added dash style to client + small refactoring for shapes + triangle
ymh <ymh.work@gmail.com>
parents:
435
diff
changeset
|
44 |
shapes : _(ShapeBuilder.builders).omit('svg').keys().value(), |
| 284 | 45 |
})); |
46 |
this.redraw(); |
|
47 |
var _this = this, |
|
48 |
closeEditor = function() { |
|
|
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
|
49 |
_this.editor_$.off("keyup"); |
|
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
|
50 |
_this.editor_$.find("input, textarea, select").off("change keyup paste"); |
|
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
|
51 |
_this.editor_$.find(".Rk-Edit-Image-File").off('change'); |
|
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
|
52 |
_this.editor_$.find(".Rk-Edit-ColorPicker-Wrapper").off('hover'); |
|
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
|
53 |
_this.editor_$.find(".Rk-Edit-Size-Down").off('click'); |
|
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
|
54 |
_this.editor_$.find(".Rk-Edit-Size-Up").off('click'); |
|
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
|
55 |
_this.editor_$.find(".Rk-Edit-Image-Del").off('click'); |
|
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
|
56 |
_this.editor_$.find(".Rk-Edit-ColorPicker").find("li").off('hover click'); |
|
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
|
57 |
_this.editor_$.find(".Rk-CloseX").off('click'); |
|
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
|
58 |
_this.editor_$.find(".Rk-Edit-Goto").off('click'); |
|
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
|
59 |
|
| 284 | 60 |
_this.renderer.removeRepresentation(_this); |
61 |
paper.view.draw(); |
|
62 |
}; |
|
63 |
||
64 |
this.editor_$.find(".Rk-CloseX").click(closeEditor); |
|
65 |
||
66 |
this.editor_$.find(".Rk-Edit-Goto").click(function() { |
|
67 |
if (!_model.get("uri")) { |
|
68 |
return false; |
|
69 |
} |
|
70 |
}); |
|
71 |
||
72 |
if (this.renderer.isEditable()) { |
|
73 |
||
| 433 | 74 |
var onFieldChange = _.throttle(function() { |
75 |
_.defer(function() { |
|
76 |
if (_this.renderer.isEditable()) { |
|
77 |
var _data = { |
|
78 |
title: _this.editor_$.find(".Rk-Edit-Title").val() |
|
79 |
}; |
|
80 |
if (_this.options.show_node_editor_uri) { |
|
81 |
_data.uri = _this.editor_$.find(".Rk-Edit-URI").val(); |
|
82 |
_this.editor_$.find(".Rk-Edit-Goto").attr("href",_data.uri || "#"); |
|
83 |
} |
|
84 |
if (_this.options.show_node_editor_image) { |
|
85 |
_data.image = _this.editor_$.find(".Rk-Edit-Image").val(); |
|
86 |
_this.editor_$.find(".Rk-Edit-ImgPreview").attr("src", _data.image || _image_placeholder); |
|
87 |
} |
|
88 |
if (_this.options.show_node_editor_description) { |
|
89 |
_data.description = _this.editor_$.find(".Rk-Edit-Description").val(); |
|
90 |
} |
|
|
458
423bdf56d103
migrated to style, added dash style to client + small refactoring for shapes + triangle
ymh <ymh.work@gmail.com>
parents:
435
diff
changeset
|
91 |
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:
435
diff
changeset
|
92 |
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:
435
diff
changeset
|
93 |
_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:
435
diff
changeset
|
94 |
} |
| 433 | 95 |
if (_this.options.change_shapes) { |
96 |
if(_model.get("shape")!==_this.editor_$.find(".Rk-Edit-Shape").val()){ |
|
97 |
_data.shape = _this.editor_$.find(".Rk-Edit-Shape").val(); |
|
| 284 | 98 |
} |
| 433 | 99 |
} |
100 |
_model.set(_data); |
|
101 |
_this.redraw(); |
|
102 |
} else { |
|
103 |
closeEditor(); |
|
104 |
} |
|
105 |
}); |
|
106 |
}, 500); |
|
107 |
||
| 284 | 108 |
this.editor_$.on("keyup", function(_e) { |
109 |
if (_e.keyCode === 27) { |
|
110 |
closeEditor(); |
|
111 |
} |
|
112 |
}); |
|
113 |
||
| 330 | 114 |
this.editor_$.find("input, textarea, select").on("change keyup paste", onFieldChange); |
| 284 | 115 |
|
| 385 | 116 |
if(_this.options.allow_image_upload) { |
117 |
this.editor_$.find(".Rk-Edit-Image-File").change(function() { |
|
118 |
if (this.files.length) { |
|
119 |
var f = this.files[0], |
|
120 |
fr = new FileReader(); |
|
121 |
if (f.type.substr(0,5) !== "image") { |
|
122 |
alert(_this.renkan.translate("This file is not an image")); |
|
123 |
return; |
|
124 |
} |
|
125 |
if (f.size > (_this.options.uploaded_image_max_kb * 1024)) { |
|
126 |
alert(_this.renkan.translate("Image size must be under ") + _this.options.uploaded_image_max_kb + _this.renkan.translate("KB")); |
|
127 |
return; |
|
128 |
} |
|
129 |
fr.onload = function(e) { |
|
130 |
_this.editor_$.find(".Rk-Edit-Image").val(e.target.result); |
|
131 |
onFieldChange(); |
|
132 |
}; |
|
133 |
fr.readAsDataURL(f); |
|
| 284 | 134 |
} |
| 385 | 135 |
}); |
136 |
} |
|
| 284 | 137 |
this.editor_$.find(".Rk-Edit-Title")[0].focus(); |
138 |
||
139 |
var _picker = _this.editor_$.find(".Rk-Edit-ColorPicker"); |
|
140 |
||
141 |
this.editor_$.find(".Rk-Edit-ColorPicker-Wrapper").hover( |
|
142 |
function(_e) { |
|
143 |
_e.preventDefault(); |
|
144 |
_picker.show(); |
|
145 |
}, |
|
146 |
function(_e) { |
|
147 |
_e.preventDefault(); |
|
148 |
_picker.hide(); |
|
149 |
} |
|
150 |
); |
|
151 |
||
152 |
_picker.find("li").hover( |
|
153 |
function(_e) { |
|
154 |
_e.preventDefault(); |
|
155 |
_this.editor_$.find(".Rk-Edit-Color").css("background", $(this).attr("data-color")); |
|
156 |
}, |
|
157 |
function(_e) { |
|
158 |
_e.preventDefault(); |
|
|
458
423bdf56d103
migrated to style, added dash style to client + small refactoring for shapes + triangle
ymh <ymh.work@gmail.com>
parents:
435
diff
changeset
|
159 |
_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 | 160 |
} |
161 |
).click(function(_e) { |
|
162 |
_e.preventDefault(); |
|
163 |
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:
435
diff
changeset
|
164 |
_model.set("style", _.assign( ((_model.has("style") && _.clone(_model.get("style"))) || {}), {color: $(this).attr("data-color")})); |
| 284 | 165 |
_picker.hide(); |
166 |
paper.view.draw(); |
|
167 |
} else { |
|
168 |
closeEditor(); |
|
169 |
} |
|
170 |
}); |
|
171 |
||
172 |
var shiftSize = function(n) { |
|
173 |
if (_this.renderer.isEditable()) { |
|
174 |
var _newsize = n+(_model.get("size") || 0); |
|
175 |
_this.editor_$.find(".Rk-Edit-Size-Value").text((_newsize > 0 ? "+" : "") + _newsize); |
|
176 |
_model.set("size", _newsize); |
|
177 |
paper.view.draw(); |
|
178 |
} else { |
|
179 |
closeEditor(); |
|
180 |
} |
|
181 |
}; |
|
182 |
||
183 |
this.editor_$.find(".Rk-Edit-Size-Down").click(function() { |
|
184 |
shiftSize(-1); |
|
185 |
return false; |
|
186 |
}); |
|
187 |
this.editor_$.find(".Rk-Edit-Size-Up").click(function() { |
|
188 |
shiftSize(1); |
|
189 |
return false; |
|
190 |
}); |
|
| 433 | 191 |
|
|
384
6a7930a0d4d1
Close #60 - Add a trash icon to delete the image URL
rougeronj
parents:
331
diff
changeset
|
192 |
this.editor_$.find(".Rk-Edit-Image-Del").click(function() { |
|
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
|
193 |
_this.editor_$.find(".Rk-Edit-Image").val(''); |
|
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
|
194 |
onFieldChange(); |
|
384
6a7930a0d4d1
Close #60 - Add a trash icon to delete the image URL
rougeronj
parents:
331
diff
changeset
|
195 |
return false; |
|
6a7930a0d4d1
Close #60 - Add a trash icon to delete the image URL
rougeronj
parents:
331
diff
changeset
|
196 |
}); |
| 284 | 197 |
} else { |
198 |
if (typeof this.source_representation.highlighted === "object") { |
|
199 |
var titlehtml = this.source_representation.highlighted.replace(_(_model.get("title")).escape(),'<span class="Rk-Highlighted">$1</span>'); |
|
200 |
this.editor_$.find(".Rk-Display-Title" + (_model.get("uri") ? " a" : "")).html(titlehtml); |
|
201 |
if (this.options.show_node_tooltip_description) { |
|
202 |
this.editor_$.find(".Rk-Display-Description").html(this.source_representation.highlighted.replace(_(_model.get("description")).escape(),'<span class="Rk-Highlighted">$1</span>')); |
|
203 |
} |
|
204 |
} |
|
205 |
} |
|
206 |
this.editor_$.find("img").load(function() { |
|
207 |
_this.redraw(); |
|
208 |
}); |
|
209 |
}, |
|
210 |
redraw: function() { |
|
211 |
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
|
212 |
Utils.drawEditBox(this.options, _coords, this.editor_block, this.source_representation.circle_radius * 0.75, this.editor_$); |
| 284 | 213 |
this.editor_$.show(); |
214 |
paper.view.draw(); |
|
215 |
} |
|
| 433 | 216 |
}).value(); |
|
434
0d5998b32a7c
clean, and finalize lodash migration
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
217 |
|
| 284 | 218 |
/* NodeEditor End */ |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
219 |
|
| 284 | 220 |
return NodeEditor; |
221 |
||
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
222 |
}); |