##// END OF EJS Templates
Merged r9389 from trunk....
Merged r9389 from trunk. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/1.4-stable@9402 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r8770:a8f98bb74903
r9268:baa4ebd05f39
Show More
context_menu.js
236 lines | 7.0 KiB | application/javascript | JavascriptLexer
Toshi MARUYAMA
remove trailing white-spaces from public/javascripts/context_menu.js...
r8770 /* Redmine - project management software
Copyright (C) 2006-2012 Jean-Philippe Lang */
Jean-Philippe Lang
Issue list now supports bulk edit/move/delete (#563, #607). For now, issues from different projects can not be bulk edited/moved/deleted at once....
r1116
var observingContextMenuClick;
Jean-Philippe Lang
Added AJAX based context menu on the project issue list that provide shortcuts for editing, re-assigning, changing the status or the priority, moving or deleting an issue....
r859 ContextMenu = Class.create();
ContextMenu.prototype = {
Toshi MARUYAMA
replace tabs to spaces and fix indents public/javascripts/context_menu.js...
r8769 initialize: function (url) {
this.url = url;
this.createMenu();
Jean-Philippe Lang
Issue list now supports bulk edit/move/delete (#563, #607). For now, issues from different projects can not be bulk edited/moved/deleted at once....
r1116
Toshi MARUYAMA
replace tabs to spaces and fix indents public/javascripts/context_menu.js...
r8769 if (!observingContextMenuClick) {
Event.observe(document, 'click', this.Click.bindAsEventListener(this));
Event.observe(document, 'contextmenu', this.RightClick.bindAsEventListener(this));
observingContextMenuClick = true;
}
Toshi MARUYAMA
remove trailing white-spaces from public/javascripts/context_menu.js...
r8770
Toshi MARUYAMA
replace tabs to spaces and fix indents public/javascripts/context_menu.js...
r8769 this.unselectAll();
this.lastSelected = null;
},
Toshi MARUYAMA
remove trailing white-spaces from public/javascripts/context_menu.js...
r8770
Toshi MARUYAMA
replace tabs to spaces and fix indents public/javascripts/context_menu.js...
r8769 RightClick: function(e) {
this.hideMenu();
// do not show the context menu on links
if (Event.element(e).tagName == 'A') { return; }
var tr = Event.findElement(e, 'tr');
if (tr == document || tr == undefined || !tr.hasClassName('hascontextmenu')) { return; }
Event.stop(e);
if (!this.isSelected(tr)) {
this.unselectAll();
this.addSelection(tr);
this.lastSelected = tr;
}
this.showMenu(e);
},
Jean-Philippe Lang
Issue list now supports bulk edit/move/delete (#563, #607). For now, issues from different projects can not be bulk edited/moved/deleted at once....
r1116
Click: function(e) {
Toshi MARUYAMA
replace tabs to spaces and fix indents public/javascripts/context_menu.js...
r8769 if (Event.element(e).tagName == 'A' && Event.element(e).hasClassName('submenu')) {
Event.stop(e)
return;
}
this.hideMenu();
if (Event.element(e).tagName == 'A' || Event.element(e).tagName == 'IMG') { return; }
Toshi MARUYAMA
remove trailing white-spaces from public/javascripts/context_menu.js...
r8770 if (Event.isLeftClick(e) || (navigator.appVersion.match(/\bMSIE\b/))) {
Jean-Philippe Lang
Issue list now supports bulk edit/move/delete (#563, #607). For now, issues from different projects can not be bulk edited/moved/deleted at once....
r1116 var tr = Event.findElement(e, 'tr');
Jean-Philippe Lang
Fixes a JS error on context_menu with IE (#2390)....
r2176 if (tr!=null && tr!=document && tr.hasClassName('hascontextmenu')) {
Jean-Philippe Lang
Issue list now supports bulk edit/move/delete (#563, #607). For now, issues from different projects can not be bulk edited/moved/deleted at once....
r1116 // a row was clicked, check if the click was on checkbox
var box = Event.findElement(e, 'input');
Jean-Philippe Lang
Upgraded to Prototype 1.6.0.1....
r1580 if (box!=document && box!=undefined) {
Jean-Philippe Lang
Issue list now supports bulk edit/move/delete (#563, #607). For now, issues from different projects can not be bulk edited/moved/deleted at once....
r1116 // a checkbox may be clicked
if (box.checked) {
tr.addClassName('context-menu-selection');
} else {
tr.removeClassName('context-menu-selection');
}
} else {
Jean-Philippe Lang
Adds support for Mac metaKey in issues selection (#5148)....
r5097 if (e.ctrlKey || e.metaKey) {
Jean-Philippe Lang
Issue list now supports bulk edit/move/delete (#563, #607). For now, issues from different projects can not be bulk edited/moved/deleted at once....
r1116 this.toggleSelection(tr);
} 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) {
this.addSelection(rows[i]);
}
if (rows[i]==tr || rows[i]==this.lastSelected) {
toggling = !toggling;
}
}
} else {
this.addSelection(tr);
}
} else {
this.unselectAll();
this.addSelection(tr);
}
this.lastSelected = tr;
}
} else {
// click is outside the rows
var t = Event.findElement(e, 'a');
Jean-Philippe Lang
Unselect issues when clicking outside of the list....
r3430 if (t == document || t == undefined) {
this.unselectAll();
} else {
if (Element.hasClassName(t, 'disabled') || Element.hasClassName(t, 'submenu')) {
Event.stop(e);
}
Jean-Philippe Lang
Issue list now supports bulk edit/move/delete (#563, #607). For now, issues from different projects can not be bulk edited/moved/deleted at once....
r1116 }
}
}
},
Toshi MARUYAMA
remove trailing white-spaces from public/javascripts/context_menu.js...
r8770
Jean-Philippe Lang
Adds an helper for creating the context menu....
r3428 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);
}
},
Toshi MARUYAMA
remove trailing white-spaces from public/javascripts/context_menu.js...
r8770
Jean-Philippe Lang
Issue list now supports bulk edit/move/delete (#563, #607). For now, issues from different projects can not be bulk edited/moved/deleted at once....
r1116 showMenu: function(e) {
Jean-Philippe Lang
Display the context menu above and/or to the left of the click if needed (patch by Mike Duchene, closes #960)....
r1308 var mouse_x = Event.pointerX(e);
var mouse_y = Event.pointerY(e);
var render_x = mouse_x;
var render_y = mouse_y;
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');
Toshi MARUYAMA
remove trailing white-spaces from public/javascripts/context_menu.js...
r8770 $('context-menu').style['top'] = (render_y + 'px');
Jean-Philippe Lang
Display the context menu above and/or to the left of the click if needed (patch by Mike Duchene, closes #960)....
r1308 Element.update('context-menu', '');
Toshi MARUYAMA
remove trailing white-spaces from public/javascripts/context_menu.js...
r8770 new Ajax.Updater({success:'context-menu'}, this.url,
Jean-Philippe Lang
Issue list now supports bulk edit/move/delete (#563, #607). For now, issues from different projects can not be bulk edited/moved/deleted at once....
r1116 {asynchronous:true,
Jean-Philippe Lang
Use GET instead of POST to retrieve context menu (#6762)....
r4390 method: 'get',
Jean-Philippe Lang
Issue list now supports bulk edit/move/delete (#563, #607). For now, issues from different projects can not be bulk edited/moved/deleted at once....
r1116 evalScripts:true,
parameters:Form.serialize(Event.findElement(e, 'form')),
onComplete:function(request){
Toshi MARUYAMA
replace tabs to spaces and fix indents public/javascripts/context_menu.js...
r8769 dims = $('context-menu').getDimensions();
menu_width = dims.width;
menu_height = dims.height;
max_width = mouse_x + 2*menu_width;
max_height = mouse_y + menu_height;
Toshi MARUYAMA
remove trailing white-spaces from public/javascripts/context_menu.js...
r8770
Toshi MARUYAMA
replace tabs to spaces and fix indents public/javascripts/context_menu.js...
r8769 var ws = window_size();
window_width = ws.width;
window_height = ws.height;
Toshi MARUYAMA
remove trailing white-spaces from public/javascripts/context_menu.js...
r8770
Toshi MARUYAMA
replace tabs to spaces and fix indents public/javascripts/context_menu.js...
r8769 /* 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');
Toshi MARUYAMA
remove trailing white-spaces from public/javascripts/context_menu.js...
r8770
Jean-Philippe Lang
Issue list now supports bulk edit/move/delete (#563, #607). For now, issues from different projects can not be bulk edited/moved/deleted at once....
r1116 Effect.Appear('context-menu', {duration: 0.20});
if (window.parseStylesheets) { window.parseStylesheets(); } // IE
}})
},
Toshi MARUYAMA
remove trailing white-spaces from public/javascripts/context_menu.js...
r8770
Jean-Philippe Lang
Issue list now supports bulk edit/move/delete (#563, #607). For now, issues from different projects can not be bulk edited/moved/deleted at once....
r1116 hideMenu: function() {
Element.hide('context-menu');
},
Toshi MARUYAMA
remove trailing white-spaces from public/javascripts/context_menu.js...
r8770
Jean-Philippe Lang
Issue list now supports bulk edit/move/delete (#563, #607). For now, issues from different projects can not be bulk edited/moved/deleted at once....
r1116 addSelection: function(tr) {
tr.addClassName('context-menu-selection');
this.checkSelectionBox(tr, true);
Jean-Philippe Lang
Do not disable text selection in the issue list....
r3429 this.clearDocumentSelection();
Jean-Philippe Lang
Issue list now supports bulk edit/move/delete (#563, #607). For now, issues from different projects can not be bulk edited/moved/deleted at once....
r1116 },
Toshi MARUYAMA
remove trailing white-spaces from public/javascripts/context_menu.js...
r8770
Jean-Philippe Lang
Issue list now supports bulk edit/move/delete (#563, #607). For now, issues from different projects can not be bulk edited/moved/deleted at once....
r1116 toggleSelection: function(tr) {
if (this.isSelected(tr)) {
this.removeSelection(tr);
} else {
this.addSelection(tr);
}
},
Toshi MARUYAMA
remove trailing white-spaces from public/javascripts/context_menu.js...
r8770
Jean-Philippe Lang
Issue list now supports bulk edit/move/delete (#563, #607). For now, issues from different projects can not be bulk edited/moved/deleted at once....
r1116 removeSelection: function(tr) {
tr.removeClassName('context-menu-selection');
this.checkSelectionBox(tr, false);
},
Toshi MARUYAMA
remove trailing white-spaces from public/javascripts/context_menu.js...
r8770
Jean-Philippe Lang
Issue list now supports bulk edit/move/delete (#563, #607). For now, issues from different projects can not be bulk edited/moved/deleted at once....
r1116 unselectAll: function() {
var rows = $$('.hascontextmenu');
for (i=0; i<rows.length; i++) {
this.removeSelection(rows[i]);
}
},
Toshi MARUYAMA
remove trailing white-spaces from public/javascripts/context_menu.js...
r8770
Jean-Philippe Lang
Issue list now supports bulk edit/move/delete (#563, #607). For now, issues from different projects can not be bulk edited/moved/deleted at once....
r1116 checkSelectionBox: function(tr, checked) {
Toshi MARUYAMA
replace tabs to spaces and fix indents public/javascripts/context_menu.js...
r8769 var inputs = Element.getElementsBySelector(tr, 'input');
if (inputs.length > 0) { inputs[0].checked = checked; }
Jean-Philippe Lang
Issue list now supports bulk edit/move/delete (#563, #607). For now, issues from different projects can not be bulk edited/moved/deleted at once....
r1116 },
Toshi MARUYAMA
remove trailing white-spaces from public/javascripts/context_menu.js...
r8770
Jean-Philippe Lang
Issue list now supports bulk edit/move/delete (#563, #607). For now, issues from different projects can not be bulk edited/moved/deleted at once....
r1116 isSelected: function(tr) {
return Element.hasClassName(tr, 'context-menu-selection');
Jean-Philippe Lang
Do not disable text selection in the issue list....
r3429 },
Toshi MARUYAMA
remove trailing white-spaces from public/javascripts/context_menu.js...
r8770
Jean-Philippe Lang
Do not disable text selection in the issue list....
r3429 clearDocumentSelection: function() {
if (document.selection) {
document.selection.clear(); // IE
} else {
window.getSelection().removeAllRanges();
}
Jean-Philippe Lang
Issue list now supports bulk edit/move/delete (#563, #607). For now, issues from different projects can not be bulk edited/moved/deleted at once....
r1116 }
}
Jean-Philippe Lang
Added AJAX based context menu on the project issue list that provide shortcuts for editing, re-assigning, changing the status or the priority, moving or deleting an issue....
r859
Jean-Philippe Lang
Issue list now supports bulk edit/move/delete (#563, #607). For now, issues from different projects can not be bulk edited/moved/deleted at once....
r1116 function toggleIssuesSelection(el) {
Toshi MARUYAMA
replace tabs to spaces and fix indents public/javascripts/context_menu.js...
r8769 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');
}
}
Jean-Philippe Lang
Added AJAX based context menu on the project issue list that provide shortcuts for editing, re-assigning, changing the status or the priority, moving or deleting an issue....
r859 }
Jean-Philippe Lang
Display the context menu above and/or to the left of the click if needed (patch by Mike Duchene, closes #960)....
r1308
function window_size() {
Toshi MARUYAMA
replace tabs to spaces and fix indents public/javascripts/context_menu.js...
r8769 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};
Jean-Philippe Lang
Display the context menu above and/or to the left of the click if needed (patch by Mike Duchene, closes #960)....
r1308 }