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