| author | rougeronj |
| Wed, 03 Jun 2015 17:27:46 +0200 | |
| changeset 471 | e0c7be5dc02c |
| parent 450 | 88e8673aaeeb |
| child 461 | 48235ed6b07d |
| 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({ |
|
|
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']; |
| 450 | 15 |
//this.templates['default']= this.options.templates['templates/nodeeditor.html']; |
16 |
//fusionner avec this.options.node_editor_templates |
|
|
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
|
17 |
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
|
18 |
}, |
| 284 | 19 |
draw: function() { |
20 |
var _model = this.source_representation.model, |
|
21 |
_created_by = _model.get("created_by") || Utils._USER_PLACEHOLDER(this.renkan), |
|
22 |
_template = (this.renderer.isEditable() ? this.template : this.readOnlyTemplate ), |
|
23 |
_image_placeholder = this.options.static_url + "img/image-placeholder.png", |
|
24 |
_size = (_model.get("size") || 0); |
|
25 |
this.editor_$ |
|
26 |
.html(_template({ |
|
27 |
node: { |
|
28 |
has_creator: !!_model.get("created_by"), |
|
29 |
title: _model.get("title"), |
|
30 |
uri: _model.get("uri"), |
|
31 |
short_uri: Utils.shortenText((_model.get("uri") || "").replace(/^(https?:\/\/)?(www\.)?/,'').replace(/\/$/,''),40), |
|
32 |
description: _model.get("description"), |
|
33 |
image: _model.get("image") || "", |
|
34 |
image_placeholder: _image_placeholder, |
|
35 |
color: _model.get("color") || _created_by.get("color"), |
|
36 |
clip_path: _model.get("clip_path") || false, |
|
37 |
created_by_color: _created_by.get("color"), |
|
38 |
created_by_title: _created_by.get("title"), |
|
| 330 | 39 |
size: (_size > 0 ? "+" : "") + _size, |
40 |
shape: _model.get("shape") || "circle" |
|
| 284 | 41 |
}, |
42 |
renkan: this.renkan, |
|
43 |
options: this.options, |
|
44 |
shortenText: Utils.shortenText |
|
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 |
} |
|
91 |
if (_this.options.change_shapes) { |
|
92 |
if(_model.get("shape")!==_this.editor_$.find(".Rk-Edit-Shape").val()){ |
|
93 |
_data.shape = _this.editor_$.find(".Rk-Edit-Shape").val(); |
|
| 284 | 94 |
} |
| 433 | 95 |
} |
96 |
_model.set(_data); |
|
97 |
_this.redraw(); |
|
98 |
} else { |
|
99 |
closeEditor(); |
|
100 |
} |
|
101 |
}); |
|
102 |
}, 500); |
|
103 |
||
| 284 | 104 |
this.editor_$.on("keyup", function(_e) { |
105 |
if (_e.keyCode === 27) { |
|
106 |
closeEditor(); |
|
107 |
} |
|
108 |
}); |
|
109 |
||
| 330 | 110 |
this.editor_$.find("input, textarea, select").on("change keyup paste", onFieldChange); |
| 284 | 111 |
|
| 385 | 112 |
if(_this.options.allow_image_upload) { |
113 |
this.editor_$.find(".Rk-Edit-Image-File").change(function() { |
|
114 |
if (this.files.length) { |
|
115 |
var f = this.files[0], |
|
116 |
fr = new FileReader(); |
|
117 |
if (f.type.substr(0,5) !== "image") { |
|
118 |
alert(_this.renkan.translate("This file is not an image")); |
|
119 |
return; |
|
120 |
} |
|
121 |
if (f.size > (_this.options.uploaded_image_max_kb * 1024)) { |
|
122 |
alert(_this.renkan.translate("Image size must be under ") + _this.options.uploaded_image_max_kb + _this.renkan.translate("KB")); |
|
123 |
return; |
|
124 |
} |
|
125 |
fr.onload = function(e) { |
|
126 |
_this.editor_$.find(".Rk-Edit-Image").val(e.target.result); |
|
127 |
onFieldChange(); |
|
128 |
}; |
|
129 |
fr.readAsDataURL(f); |
|
| 284 | 130 |
} |
| 385 | 131 |
}); |
132 |
} |
|
| 284 | 133 |
this.editor_$.find(".Rk-Edit-Title")[0].focus(); |
134 |
||
135 |
var _picker = _this.editor_$.find(".Rk-Edit-ColorPicker"); |
|
136 |
||
137 |
this.editor_$.find(".Rk-Edit-ColorPicker-Wrapper").hover( |
|
138 |
function(_e) { |
|
139 |
_e.preventDefault(); |
|
140 |
_picker.show(); |
|
141 |
}, |
|
142 |
function(_e) { |
|
143 |
_e.preventDefault(); |
|
144 |
_picker.hide(); |
|
145 |
} |
|
146 |
); |
|
147 |
||
148 |
_picker.find("li").hover( |
|
149 |
function(_e) { |
|
150 |
_e.preventDefault(); |
|
151 |
_this.editor_$.find(".Rk-Edit-Color").css("background", $(this).attr("data-color")); |
|
152 |
}, |
|
153 |
function(_e) { |
|
154 |
_e.preventDefault(); |
|
155 |
_this.editor_$.find(".Rk-Edit-Color").css("background", _model.get("color") || (_model.get("created_by") || Utils._USER_PLACEHOLDER(_this.renkan)).get("color")); |
|
156 |
} |
|
157 |
).click(function(_e) { |
|
158 |
_e.preventDefault(); |
|
159 |
if (_this.renderer.isEditable()) { |
|
160 |
_model.set("color", $(this).attr("data-color")); |
|
161 |
_picker.hide(); |
|
162 |
paper.view.draw(); |
|
163 |
} else { |
|
164 |
closeEditor(); |
|
165 |
} |
|
166 |
}); |
|
167 |
||
168 |
var shiftSize = function(n) { |
|
169 |
if (_this.renderer.isEditable()) { |
|
170 |
var _newsize = n+(_model.get("size") || 0); |
|
171 |
_this.editor_$.find(".Rk-Edit-Size-Value").text((_newsize > 0 ? "+" : "") + _newsize); |
|
172 |
_model.set("size", _newsize); |
|
173 |
paper.view.draw(); |
|
174 |
} else { |
|
175 |
closeEditor(); |
|
176 |
} |
|
177 |
}; |
|
178 |
||
179 |
this.editor_$.find(".Rk-Edit-Size-Down").click(function() { |
|
180 |
shiftSize(-1); |
|
181 |
return false; |
|
182 |
}); |
|
183 |
this.editor_$.find(".Rk-Edit-Size-Up").click(function() { |
|
184 |
shiftSize(1); |
|
185 |
return false; |
|
186 |
}); |
|
| 433 | 187 |
|
|
384
6a7930a0d4d1
Close #60 - Add a trash icon to delete the image URL
rougeronj
parents:
331
diff
changeset
|
188 |
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
|
189 |
_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
|
190 |
onFieldChange(); |
|
384
6a7930a0d4d1
Close #60 - Add a trash icon to delete the image URL
rougeronj
parents:
331
diff
changeset
|
191 |
return false; |
|
6a7930a0d4d1
Close #60 - Add a trash icon to delete the image URL
rougeronj
parents:
331
diff
changeset
|
192 |
}); |
| 284 | 193 |
} else { |
194 |
if (typeof this.source_representation.highlighted === "object") { |
|
195 |
var titlehtml = this.source_representation.highlighted.replace(_(_model.get("title")).escape(),'<span class="Rk-Highlighted">$1</span>'); |
|
196 |
this.editor_$.find(".Rk-Display-Title" + (_model.get("uri") ? " a" : "")).html(titlehtml); |
|
197 |
if (this.options.show_node_tooltip_description) { |
|
198 |
this.editor_$.find(".Rk-Display-Description").html(this.source_representation.highlighted.replace(_(_model.get("description")).escape(),'<span class="Rk-Highlighted">$1</span>')); |
|
199 |
} |
|
200 |
} |
|
201 |
} |
|
202 |
this.editor_$.find("img").load(function() { |
|
203 |
_this.redraw(); |
|
204 |
}); |
|
205 |
}, |
|
206 |
redraw: function() { |
|
| 447 | 207 |
if (this.options.popup_editor){ |
208 |
var _coords = this.source_representation.paper_coords; |
|
209 |
Utils.drawEditBox(this.options, _coords, this.editor_block, this.source_representation.circle_radius * 0.75, this.editor_$); |
|
210 |
} |
|
| 284 | 211 |
this.editor_$.show(); |
212 |
paper.view.draw(); |
|
213 |
} |
|
| 433 | 214 |
}).value(); |
|
434
0d5998b32a7c
clean, and finalize lodash migration
ymh <ymh.work@gmail.com>
parents:
433
diff
changeset
|
215 |
|
| 284 | 216 |
/* NodeEditor End */ |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
217 |
|
| 284 | 218 |
return NodeEditor; |
219 |
||
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
220 |
}); |