Newer
Older
Jean-Philippe Lang
committed
/* redMine - project management software
Copyright (C) 2006-2008 Jean-Philippe Lang */
function checkAll (id, checked) {
var els = Element.descendants(id);
for (var i = 0; i < els.length; i++) {
if (els[i].disabled==false) {
els[i].checked = checked;
function toggleCheckboxesBySelector(selector) {
boxes = $$(selector);
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++) { boxes[i].checked = !all_checked; }
}
function showAndScrollTo(id, focus) {
Element.show(id);
if (focus!=null) { Form.Element.focus(focus); }
Element.scrollTo(id);
}
function toggleRowGroup(el) {
var tr = Element.up(el, 'tr');
var n = Element.next(tr);
tr.toggleClassName('open');
while (n != undefined && !n.hasClassName('group')) {
Element.toggle(n);
n = Element.next(n);
}
}
function toggleFieldset(el) {
var fieldset = Element.up(el, 'fieldset');
fieldset.toggleClassName('collapsed');
Effect.toggle(fieldset.down('div'), 'slide', {duration:0.2});
}
var fileFieldCount = 1;
function addFileField() {
if (fileFieldCount >= 10) return false
fileFieldCount++;
var f = document.createElement("input");
f.type = "file";
f.name = "attachments[" + fileFieldCount + "][file]";
var d = document.createElement("input");
d.type = "text";
d.name = "attachments[" + fileFieldCount + "][description]";
d.size = 60;
var dLabel = document.createElement("label");
dLabel.addClassName('inline');
// Pulls the languge value used for Optional Description
dLabel.update($('attachment_description_label_content').innerHTML)
p = document.getElementById("attachments_fields");
p.appendChild(document.createElement("br"));
p.appendChild(f);
p.appendChild(dLabel);
dLabel.appendChild(d);
}
function showTab(name) {
var f = $$('div#content .tab-content');
for(var i=0; i<f.length; i++){
Element.hide(f[i]);
}
var f = $$('div.tabs a');
for(var i=0; i<f.length; i++){
Element.removeClassName(f[i], "selected");
}
Element.show('tab-content-' + name);
Element.addClassName('tab-' + name, "selected");
return false;
Jean-Philippe Lang
committed
}
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
function moveTabRight(el) {
var lis = Element.up(el, 'div.tabs').down('ul').childElements();
var tabsWidth = 0;
var i;
for (i=0; i<lis.length; i++) {
if (lis[i].visible()) {
tabsWidth += lis[i].getWidth() + 6;
}
}
if (tabsWidth < Element.up(el, 'div.tabs').getWidth() - 60) {
return;
}
i=0;
while (i<lis.length && !lis[i].visible()) {
i++;
}
lis[i].hide();
}
function moveTabLeft(el) {
var lis = Element.up(el, 'div.tabs').down('ul').childElements();
var i = 0;
while (i<lis.length && !lis[i].visible()) {
i++;
}
if (i>0) {
lis[i-1].show();
}
}
function displayTabsButtons() {
var lis;
var tabsWidth = 0;
var i;
$$('div.tabs').each(function(el) {
lis = el.down('ul').childElements();
for (i=0; i<lis.length; i++) {
if (lis[i].visible()) {
tabsWidth += lis[i].getWidth() + 6;
}
}
if ((tabsWidth < el.getWidth() - 60) && (lis[0].visible())) {
el.down('div.tabs-buttons').hide();
} else {
el.down('div.tabs-buttons').show();
}
});
}
Jean-Philippe Lang
committed
function setPredecessorFieldsVisibility() {
relationType = $('relation_relation_type');
if (relationType && (relationType.value == "precedes" || relationType.value == "follows")) {
Jean-Philippe Lang
committed
Element.show('predecessor_fields');
} else {
Element.hide('predecessor_fields');
}
}
function promptToRemote(text, param, url) {
value = prompt(text + ':');
if (value) {
Jean-Philippe Lang
committed
new Ajax.Request(url + '?' + param + '=' + encodeURIComponent(value), {asynchronous:true, evalScripts:true});
return false;
}
}
Jean-Philippe Lang
committed
function collapseScmEntry(id) {
var els = document.getElementsByClassName(id, 'browser');
for (var i = 0; i < els.length; i++) {
if (els[i].hasClassName('open')) {
collapseScmEntry(els[i].id);
}
Jean-Philippe Lang
committed
Element.hide(els[i]);
}
$(id).removeClassName('open');
}
function expandScmEntry(id) {
var els = document.getElementsByClassName(id, 'browser');
for (var i = 0; i < els.length; i++) {
Element.show(els[i]);
if (els[i].hasClassName('loaded') && !els[i].hasClassName('collapsed')) {
expandScmEntry(els[i].id);
}
Jean-Philippe Lang
committed
}
$(id).addClassName('open');
}
function scmEntryClick(id) {
el = $(id);
if (el.hasClassName('open')) {
collapseScmEntry(id);
Jean-Philippe Lang
committed
return false;
} else if (el.hasClassName('loaded')) {
expandScmEntry(id);
Jean-Philippe Lang
committed
return false;
}
if (el.hasClassName('loading')) {
return false;
}
el.addClassName('loading');
Jean-Philippe Lang
committed
return true;
}
function scmEntryLoaded(id) {
Element.addClassName(id, 'open');
Element.addClassName(id, 'loaded');
Jean-Philippe Lang
committed
}
Jean-Philippe Lang
committed
function randomKey(size) {
var chars = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
var key = '';
for (i = 0; i < size; i++) {
key += chars[Math.floor(Math.random() * chars.length)];
}
return key;
}
function observeParentIssueField(url) {
new Ajax.Autocompleter('issue_parent_issue_id',
'parent_issue_candidates',
url,
{ minChars: 3,
frequency: 0.5,
paramName: 'q',
updateElement: function(value) {
document.getElementById('issue_parent_issue_id').value = value.id;
}});
}
Jean-Philippe Lang
committed
/* shows and hides ajax indicator */
Ajax.Responders.register({
onCreate: function(){
if ($('ajax-indicator') && Ajax.activeRequestCount > 0) {
Element.show('ajax-indicator');
}
},
onComplete: function(){
if ($('ajax-indicator') && Ajax.activeRequestCount == 0) {
Element.hide('ajax-indicator');
}
}
});
Jean-Philippe Lang
committed
Event.observe(window, 'load', function() {
$$('.hol').each(function(el) {
el.hide();
});
});