kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
235 lines
6.8 KiB
235 lines
6.8 KiB
17 years ago
|
/* redMine - project management software
|
||
|
Copyright (C) 2006-2008 Jean-Philippe Lang */
|
||
|
|
||
|
var observingContextMenuClick;
|
||
|
|
||
17 years ago
|
ContextMenu = Class.create();
|
||
|
ContextMenu.prototype = {
|
||
17 years ago
|
initialize: function (url) {
|
||
|
this.url = url;
|
||
15 years ago
|
this.createMenu();
|
||
17 years ago
|
|
||
|
if (!observingContextMenuClick) {
|
||
|
Event.observe(document, 'click', this.Click.bindAsEventListener(this));
|
||
14 years ago
|
Event.observe(document, 'contextmenu', this.RightClick.bindAsEventListener(this));
|
||
17 years ago
|
observingContextMenuClick = true;
|
||
|
}
|
||
|
|
||
|
this.unselectAll();
|
||
|
this.lastSelected = null;
|
||
17 years ago
|
},
|
||
17 years ago
|
|
||
|
RightClick: function(e) {
|
||
|
this.hideMenu();
|
||
|
// do not show the context menu on links
|
||
16 years ago
|
if (Event.element(e).tagName == 'A') { return; }
|
||
17 years ago
|
var tr = Event.findElement(e, 'tr');
|
||
17 years ago
|
if (tr == document || tr == undefined || !tr.hasClassName('hascontextmenu')) { return; }
|
||
17 years ago
|
Event.stop(e);
|
||
17 years ago
|
if (!this.isSelected(tr)) {
|
||
|
this.unselectAll();
|
||
13 years ago
|
this.addSelection(tr, e);
|
||
17 years ago
|
this.lastSelected = tr;
|
||
17 years ago
|
}
|
||
17 years ago
|
this.showMenu(e);
|
||
|
},
|
||
|
|
||
|
Click: function(e) {
|
||
|
this.hideMenu();
|
||
16 years ago
|
if (Event.element(e).tagName == 'A') { return; }
|
||
14 years ago
|
if (!Event.isRightClick(e) || (navigator.appVersion.match(/\bMSIE\b/))) {
|
||
17 years ago
|
var tr = Event.findElement(e, 'tr');
|
||
16 years ago
|
if (tr!=null && tr!=document && tr.hasClassName('hascontextmenu')) {
|
||
17 years ago
|
// a row was clicked, check if the click was on checkbox
|
||
|
var box = Event.findElement(e, 'input');
|
||
17 years ago
|
if (box!=document && box!=undefined) {
|
||
17 years ago
|
// a checkbox may be clicked
|
||
|
if (box.checked) {
|
||
|
tr.addClassName('context-menu-selection');
|
||
|
} else {
|
||
|
tr.removeClassName('context-menu-selection');
|
||
|
}
|
||
|
} else {
|
||
14 years ago
|
if (e.ctrlKey || e.metaKey) {
|
||
13 years ago
|
this.toggleSelection(tr, e);
|
||
17 years ago
|
} else if (e.shiftKey) {
|
||
|
if (this.lastSelected != null) {
|
||
|
var toggling = false;
|
||
|
var rows = $$('.hascontextmenu');
|
||
|
for (i=0; i<rows.length; i++) {
|
||
|
if (toggling || rows[i]==tr) {
|
||
13 years ago
|
this.addSelection(rows[i], e);
|
||
17 years ago
|
}
|
||
|
if (rows[i]==tr || rows[i]==this.lastSelected) {
|
||
|
toggling = !toggling;
|
||
|
}
|
||
|
}
|
||
|
} else {
|
||
13 years ago
|
this.addSelection(tr, e);
|
||
17 years ago
|
}
|
||
|
} else {
|
||
|
this.unselectAll();
|
||
13 years ago
|
this.addSelection(tr, e);
|
||
17 years ago
|
}
|
||
|
this.lastSelected = tr;
|
||
|
}
|
||
|
} else {
|
||
|
// click is outside the rows
|
||
|
var t = Event.findElement(e, 'a');
|
||
15 years ago
|
if (t == document || t == undefined) {
|
||
|
this.unselectAll();
|
||
|
} else {
|
||
|
if (Element.hasClassName(t, 'disabled') || Element.hasClassName(t, 'submenu')) {
|
||
|
Event.stop(e);
|
||
|
}
|
||
17 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
|
||
15 years ago
|
createMenu: function() {
|
||
|
if (!$('context-menu')) {
|
||
|
var menu = document.createElement("div");
|
||
|
menu.setAttribute("id", "context-menu");
|
||
|
menu.setAttribute("style", "display:none;");
|
||
|
document.getElementById("content").appendChild(menu);
|
||
|
}
|
||
|
},
|
||
|
|
||
17 years ago
|
showMenu: function(e) {
|
||
17 years ago
|
var mouse_x = Event.pointerX(e);
|
||
|
var mouse_y = Event.pointerY(e);
|
||
|
var render_x = mouse_x;
|
||
13 years ago
|
var render_y = mouse_y - $('top-menu').getHeight();
|
||
17 years ago
|
var dims;
|
||
|
var menu_width;
|
||
|
var menu_height;
|
||
|
var window_width;
|
||
|
var window_height;
|
||
|
var max_width;
|
||
|
var max_height;
|
||
|
|
||
|
$('context-menu').style['left'] = (render_x + 'px');
|
||
|
$('context-menu').style['top'] = (render_y + 'px');
|
||
|
Element.update('context-menu', '');
|
||
|
|
||
|
new Ajax.Updater({success:'context-menu'}, this.url,
|
||
17 years ago
|
{asynchronous:true,
|
||
14 years ago
|
method: 'get',
|
||
17 years ago
|
evalScripts:true,
|
||
|
parameters:Form.serialize(Event.findElement(e, 'form')),
|
||
|
onComplete:function(request){
|
||
17 years ago
|
dims = $('context-menu').getDimensions();
|
||
|
menu_width = dims.width;
|
||
|
menu_height = dims.height;
|
||
13 years ago
|
max_width = render_x + 2*menu_width;
|
||
|
max_height = render_y + menu_height;
|
||
|
|
||
17 years ago
|
var ws = window_size();
|
||
|
window_width = ws.width;
|
||
|
window_height = ws.height;
|
||
|
|
||
|
/* display the menu above and/or to the left of the click if needed */
|
||
|
if (max_width > window_width) {
|
||
|
render_x -= menu_width;
|
||
|
$('context-menu').addClassName('reverse-x');
|
||
|
} else {
|
||
|
$('context-menu').removeClassName('reverse-x');
|
||
|
}
|
||
|
if (max_height > window_height) {
|
||
|
render_y -= menu_height;
|
||
|
$('context-menu').addClassName('reverse-y');
|
||
|
} else {
|
||
|
$('context-menu').removeClassName('reverse-y');
|
||
|
}
|
||
|
if (render_x <= 0) render_x = 1;
|
||
|
if (render_y <= 0) render_y = 1;
|
||
|
$('context-menu').style['left'] = (render_x + 'px');
|
||
|
$('context-menu').style['top'] = (render_y + 'px');
|
||
|
|
||
17 years ago
|
Effect.Appear('context-menu', {duration: 0.20});
|
||
|
if (window.parseStylesheets) { window.parseStylesheets(); } // IE
|
||
|
}})
|
||
|
},
|
||
|
|
||
|
hideMenu: function() {
|
||
|
Element.hide('context-menu');
|
||
|
},
|
||
13 years ago
|
|
||
|
addSelection: function(tr, e) {
|
||
17 years ago
|
tr.addClassName('context-menu-selection');
|
||
|
this.checkSelectionBox(tr, true);
|
||
13 years ago
|
this.clearDocumentSelection(e);
|
||
17 years ago
|
},
|
||
13 years ago
|
|
||
|
toggleSelection: function(tr,e) {
|
||
17 years ago
|
if (this.isSelected(tr)) {
|
||
|
this.removeSelection(tr);
|
||
|
} else {
|
||
13 years ago
|
this.addSelection(tr, e);
|
||
17 years ago
|
}
|
||
|
},
|
||
|
|
||
|
removeSelection: function(tr) {
|
||
|
tr.removeClassName('context-menu-selection');
|
||
|
this.checkSelectionBox(tr, false);
|
||
|
},
|
||
|
|
||
|
unselectAll: function() {
|
||
|
var rows = $$('.hascontextmenu');
|
||
|
for (i=0; i<rows.length; i++) {
|
||
|
this.removeSelection(rows[i]);
|
||
|
}
|
||
|
},
|
||
|
|
||
|
checkSelectionBox: function(tr, checked) {
|
||
|
var inputs = Element.getElementsBySelector(tr, 'input');
|
||
|
if (inputs.length > 0) { inputs[0].checked = checked; }
|
||
|
},
|
||
|
|
||
|
isSelected: function(tr) {
|
||
|
return Element.hasClassName(tr, 'context-menu-selection');
|
||
15 years ago
|
},
|
||
13 years ago
|
|
||
|
clearDocumentSelection: function(e) {
|
||
15 years ago
|
if (document.selection) {
|
||
13 years ago
|
if (document.selection.type == "Text" && e.shiftKey) {
|
||
|
document.selection.empty(); // IE
|
||
|
}
|
||
15 years ago
|
} else {
|
||
|
window.getSelection().removeAllRanges();
|
||
|
}
|
||
17 years ago
|
}
|
||
|
}
|
||
17 years ago
|
|
||
17 years ago
|
function toggleIssuesSelection(el) {
|
||
|
var boxes = el.getElementsBySelector('input[type=checkbox]');
|
||
|
var all_checked = true;
|
||
|
for (i = 0; i < boxes.length; i++) { if (boxes[i].checked == false) { all_checked = false; } }
|
||
|
for (i = 0; i < boxes.length; i++) {
|
||
|
if (all_checked) {
|
||
|
boxes[i].checked = false;
|
||
|
boxes[i].up('tr').removeClassName('context-menu-selection');
|
||
|
} else if (boxes[i].checked == false) {
|
||
|
boxes[i].checked = true;
|
||
|
boxes[i].up('tr').addClassName('context-menu-selection');
|
||
|
}
|
||
17 years ago
|
}
|
||
|
}
|
||
17 years ago
|
|
||
|
function window_size() {
|
||
|
var w;
|
||
|
var h;
|
||
|
if (window.innerWidth) {
|
||
|
w = window.innerWidth;
|
||
|
h = window.innerHeight;
|
||
|
} else if (document.documentElement) {
|
||
|
w = document.documentElement.clientWidth;
|
||
|
h = document.documentElement.clientHeight;
|
||
|
} else {
|
||
|
w = document.body.clientWidth;
|
||
|
h = document.body.clientHeight;
|
||
|
}
|
||
|
return {width: w, height: h};
|
||
|
}
|