1 |
1e2b2c27
|
Tomáš Šimandl
|
|
2 |
|
|
/**
|
3 |
|
|
*
|
4 |
|
|
* Group rename dialog.
|
5 |
|
|
*/
|
6 |
|
|
var Dialog = {
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Set up the dialog - settings and such.
|
10 |
|
|
*/
|
11 |
|
|
setDialog : function() {
|
12 |
|
|
|
13 |
|
|
$("#dialog").dialog({
|
14 |
|
|
dialogClass : "no-close",
|
15 |
|
|
buttons : [ {
|
16 |
|
|
text : "OK",
|
17 |
|
|
|
18 |
|
|
click : function(e) {
|
19 |
|
|
Dialog.saveDialogValue(this);
|
20 |
|
|
}
|
21 |
|
|
}, {
|
22 |
|
|
text : "Cancel",
|
23 |
|
|
click : function() {
|
24 |
|
|
$(this).dialog("close");
|
25 |
|
|
}
|
26 |
|
|
} ],
|
27 |
|
|
closeOnEscape : true,
|
28 |
|
|
draggable : false,
|
29 |
|
|
modal : true,
|
30 |
|
|
autoOpen : false
|
31 |
|
|
});
|
32 |
|
|
|
33 |
|
|
// setup clearing button
|
34 |
|
|
$("#clearNameButton").click(function() { $("#groupNameTextarea").val(""); });
|
35 |
|
|
|
36 |
|
|
// when focused
|
37 |
|
|
$("#dialog").on("dialogfocus", function(event, ui) {
|
38 |
|
|
// set Enter as dialog completion accelerator
|
39 |
|
|
$(this).keypress(function(e) {
|
40 |
|
|
if(e.which == 13) {
|
41 |
|
|
Dialog.saveDialogValue($("#dialog").dialog());
|
42 |
|
|
}
|
43 |
|
|
});
|
44 |
|
|
|
45 |
|
|
// get the group object and set the input field value
|
46 |
|
|
var group = $("#dialog").dialog().data('group');
|
47 |
|
|
$("#groupNameTextarea").val(group.label);
|
48 |
|
|
} );
|
49 |
|
|
},
|
50 |
|
|
|
51 |
|
|
/**
|
52 |
|
|
* Save the values in dialog textarea to the group.
|
53 |
|
|
*
|
54 |
|
|
* @param callingParent parent
|
55 |
|
|
*
|
56 |
|
|
* group - group object itself
|
57 |
|
|
* groupLabel - group label element
|
58 |
|
|
* isSvgElement - if SVG element then true, false otherwise
|
59 |
|
|
*/
|
60 |
|
|
saveDialogValue : function(callingParent) {
|
61 |
|
|
var MAX_CHARS = 15;
|
62 |
|
|
|
63 |
|
|
var newName = $("#groupNameTextarea").val();
|
64 |
|
|
var group = $(callingParent).data('group');
|
65 |
|
|
var groupLabel = $(callingParent).data('groupLabel');
|
66 |
|
|
var isSVG = $(callingParent).data('isSvgElement');
|
67 |
|
|
|
68 |
|
|
if (newName.replace(/ /g, '').length === 0) {
|
69 |
|
|
// default name
|
70 |
|
|
newName = 'Group';
|
71 |
|
|
} else {
|
72 |
|
|
if (newName.length > MAX_CHARS) {
|
73 |
|
|
newName = newName.substring(0, MAX_CHARS);
|
74 |
|
|
newName += "..";
|
75 |
|
|
}
|
76 |
|
|
}
|
77 |
|
|
|
78 |
|
|
if(isSVG) {
|
79 |
|
|
var test = document.getElementById('labelTextElement' + group.idGroup);
|
80 |
|
|
test.textContent = newName;
|
81 |
|
|
}else {
|
82 |
|
|
groupLabel.html(newName);
|
83 |
|
|
}
|
84 |
|
|
|
85 |
|
|
// set new group label
|
86 |
|
|
group.label = newName;
|
87 |
|
|
|
88 |
|
|
// makes the label visible if newName isn't Group and adjusts position and size of the icon
|
89 |
|
|
if (newName != 'Group') {
|
90 |
|
|
$('#labelTextElement' + group.idGroup).attr('display', '');
|
91 |
|
|
|
92 |
|
|
$('#symbol' + group.idGroup).attr('class', 'group-symbol');
|
93 |
|
|
$('#symbol' + group.idGroup).attr('x', '20');
|
94 |
|
|
$('#symbol' + group.idGroup).attr('y', '11');
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
|
98 |
|
|
|
99 |
|
|
$(callingParent).dialog("close");
|
100 |
|
|
}
|
101 |
|
|
};
|