2008-02-10 16:17:41 +03:00
|
|
|
/* redMine - project management software
|
|
|
|
Copyright (C) 2006-2008 Jean-Philippe Lang */
|
|
|
|
|
2007-04-04 22:20:45 +04:00
|
|
|
function checkAll (id, checked) {
|
2008-05-14 21:23:40 +04:00
|
|
|
var els = Element.descendants(id);
|
|
|
|
for (var i = 0; i < els.length; i++) {
|
|
|
|
if (els[i].disabled==false) {
|
|
|
|
els[i].checked = checked;
|
2007-04-04 22:20:45 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-26 20:05:02 +04:00
|
|
|
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; }
|
|
|
|
}
|
|
|
|
|
2010-09-29 01:09:06 +04:00
|
|
|
function setCheckboxesBySelector(checked, selector) {
|
|
|
|
var boxes = $$(selector);
|
|
|
|
boxes.each(function(ele) {
|
|
|
|
ele.checked = checked;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2008-06-29 23:50:07 +04:00
|
|
|
function showAndScrollTo(id, focus) {
|
|
|
|
Element.show(id);
|
|
|
|
if (focus!=null) { Form.Element.focus(focus); }
|
|
|
|
Element.scrollTo(id);
|
|
|
|
}
|
|
|
|
|
2009-05-04 22:04:09 +04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-20 19:01:25 +03:00
|
|
|
function collapseAllRowGroups(el) {
|
|
|
|
var tbody = Element.up(el, 'tbody');
|
|
|
|
tbody.childElements('tr').each(function(tr) {
|
|
|
|
if (tr.hasClassName('group')) {
|
|
|
|
tr.removeClassName('open');
|
|
|
|
} else {
|
|
|
|
tr.hide();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function expandAllRowGroups(el) {
|
|
|
|
var tbody = Element.up(el, 'tbody');
|
|
|
|
tbody.childElements('tr').each(function(tr) {
|
|
|
|
if (tr.hasClassName('group')) {
|
|
|
|
tr.addClassName('open');
|
|
|
|
} else {
|
|
|
|
tr.show();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleAllRowGroups(el) {
|
|
|
|
var tr = Element.up(el, 'tr');
|
|
|
|
if (tr.hasClassName('open')) {
|
|
|
|
collapseAllRowGroups(el);
|
|
|
|
} else {
|
|
|
|
expandAllRowGroups(el);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-20 11:24:16 +04:00
|
|
|
function toggleFieldset(el) {
|
|
|
|
var fieldset = Element.up(el, 'fieldset');
|
|
|
|
fieldset.toggleClassName('collapsed');
|
|
|
|
Effect.toggle(fieldset.down('div'), 'slide', {duration:0.2});
|
|
|
|
}
|
|
|
|
|
2011-02-20 18:38:07 +03:00
|
|
|
function hideFieldset(el) {
|
|
|
|
var fieldset = Element.up(el, 'fieldset');
|
|
|
|
fieldset.toggleClassName('collapsed');
|
|
|
|
fieldset.down('div').hide();
|
|
|
|
}
|
|
|
|
|
2008-02-29 22:46:58 +03:00
|
|
|
var fileFieldCount = 1;
|
|
|
|
|
2007-04-04 22:20:45 +04:00
|
|
|
function addFileField() {
|
2008-02-29 22:46:58 +03:00
|
|
|
if (fileFieldCount >= 10) return false
|
|
|
|
fileFieldCount++;
|
2007-04-04 22:20:45 +04:00
|
|
|
var f = document.createElement("input");
|
|
|
|
f.type = "file";
|
2008-02-29 22:46:58 +03:00
|
|
|
f.name = "attachments[" + fileFieldCount + "][file]";
|
2007-04-04 22:20:45 +04:00
|
|
|
f.size = 30;
|
2008-02-29 22:46:58 +03:00
|
|
|
var d = document.createElement("input");
|
|
|
|
d.type = "text";
|
|
|
|
d.name = "attachments[" + fileFieldCount + "][description]";
|
|
|
|
d.size = 60;
|
2010-07-25 14:34:55 +04:00
|
|
|
var dLabel = new Element('label');
|
2010-05-25 04:11:58 +04:00
|
|
|
dLabel.addClassName('inline');
|
|
|
|
// Pulls the languge value used for Optional Description
|
|
|
|
dLabel.update($('attachment_description_label_content').innerHTML)
|
2008-02-29 22:46:58 +03:00
|
|
|
p = document.getElementById("attachments_fields");
|
2007-04-04 22:20:45 +04:00
|
|
|
p.appendChild(document.createElement("br"));
|
|
|
|
p.appendChild(f);
|
2010-05-25 04:11:58 +04:00
|
|
|
p.appendChild(dLabel);
|
|
|
|
dLabel.appendChild(d);
|
|
|
|
|
2007-04-04 22:20:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2007-04-27 23:32:57 +04:00
|
|
|
}
|
|
|
|
|
2009-12-14 23:13:29 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2009-12-17 21:23:00 +03:00
|
|
|
if ((tabsWidth < el.getWidth() - 60) && (lis[0].visible())) {
|
2009-12-14 23:13:29 +03:00
|
|
|
el.down('div.tabs-buttons').hide();
|
|
|
|
} else {
|
|
|
|
el.down('div.tabs-buttons').show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2007-05-05 17:22:27 +04:00
|
|
|
function setPredecessorFieldsVisibility() {
|
|
|
|
relationType = $('relation_relation_type');
|
2009-12-18 23:35:16 +03:00
|
|
|
if (relationType && (relationType.value == "precedes" || relationType.value == "follows")) {
|
2007-05-05 17:22:27 +04:00
|
|
|
Element.show('predecessor_fields');
|
|
|
|
} else {
|
|
|
|
Element.hide('predecessor_fields');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-16 20:45:06 +04:00
|
|
|
function promptToRemote(text, param, url) {
|
|
|
|
value = prompt(text + ':');
|
|
|
|
if (value) {
|
2008-05-22 21:02:29 +04:00
|
|
|
new Ajax.Request(url + '?' + param + '=' + encodeURIComponent(value), {asynchronous:true, evalScripts:true});
|
2007-08-16 20:45:06 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-22 23:34:21 +04:00
|
|
|
function collapseScmEntry(id) {
|
|
|
|
var els = document.getElementsByClassName(id, 'browser');
|
|
|
|
for (var i = 0; i < els.length; i++) {
|
2007-10-23 23:07:59 +04:00
|
|
|
if (els[i].hasClassName('open')) {
|
|
|
|
collapseScmEntry(els[i].id);
|
|
|
|
}
|
2007-10-22 23:34:21 +04:00
|
|
|
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]);
|
2007-10-24 00:42:15 +04:00
|
|
|
if (els[i].hasClassName('loaded') && !els[i].hasClassName('collapsed')) {
|
|
|
|
expandScmEntry(els[i].id);
|
|
|
|
}
|
2007-10-22 23:34:21 +04:00
|
|
|
}
|
|
|
|
$(id).addClassName('open');
|
|
|
|
}
|
|
|
|
|
|
|
|
function scmEntryClick(id) {
|
|
|
|
el = $(id);
|
|
|
|
if (el.hasClassName('open')) {
|
|
|
|
collapseScmEntry(id);
|
2007-10-24 00:42:15 +04:00
|
|
|
el.addClassName('collapsed');
|
2007-10-22 23:34:21 +04:00
|
|
|
return false;
|
|
|
|
} else if (el.hasClassName('loaded')) {
|
|
|
|
expandScmEntry(id);
|
2007-10-24 00:42:15 +04:00
|
|
|
el.removeClassName('collapsed');
|
2007-10-22 23:34:21 +04:00
|
|
|
return false;
|
|
|
|
}
|
2007-10-24 00:42:15 +04:00
|
|
|
if (el.hasClassName('loading')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
el.addClassName('loading');
|
2007-10-22 23:34:21 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function scmEntryLoaded(id) {
|
|
|
|
Element.addClassName(id, 'open');
|
|
|
|
Element.addClassName(id, 'loaded');
|
2007-10-24 00:42:15 +04:00
|
|
|
Element.removeClassName(id, 'loading');
|
2007-10-22 23:34:21 +04:00
|
|
|
}
|
|
|
|
|
2008-06-25 23:25:28 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-03-13 17:56:49 +03:00
|
|
|
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;
|
|
|
|
}});
|
|
|
|
}
|
|
|
|
|
2010-12-12 19:04:28 +03:00
|
|
|
function observeRelatedIssueField(url) {
|
|
|
|
new Ajax.Autocompleter('relation_issue_to_id',
|
|
|
|
'related_issue_candidates',
|
|
|
|
url,
|
|
|
|
{ minChars: 3,
|
|
|
|
frequency: 0.5,
|
|
|
|
paramName: 'q',
|
|
|
|
updateElement: function(value) {
|
|
|
|
document.getElementById('relation_issue_to_id').value = value.id;
|
|
|
|
},
|
|
|
|
parameters: 'scope=all'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-01-07 00:02:19 +03:00
|
|
|
function setVisible(id, visible) {
|
|
|
|
var el = $(id);
|
|
|
|
if (el) {if (visible) {el.show();} else {el.hide();}}
|
|
|
|
}
|
|
|
|
|
|
|
|
function observeProjectModules() {
|
|
|
|
var f = function() {
|
|
|
|
/* Hides trackers and issues custom fields on the new project form when issue_tracking module is disabled */
|
|
|
|
var c = ($('project_enabled_module_names_issue_tracking').checked == true);
|
|
|
|
setVisible('project_trackers', c);
|
|
|
|
setVisible('project_issue_custom_fields', c);
|
|
|
|
};
|
|
|
|
|
|
|
|
Event.observe(window, 'load', f);
|
|
|
|
Event.observe('project_enabled_module_names_issue_tracking', 'change', f);
|
|
|
|
}
|
|
|
|
|
2011-02-21 12:53:29 +03:00
|
|
|
/*
|
|
|
|
* Class used to warn user when leaving a page with unsaved textarea
|
|
|
|
* Author: mathias.fischer@berlinonline.de
|
|
|
|
*/
|
|
|
|
|
|
|
|
var WarnLeavingUnsaved = Class.create({
|
|
|
|
observedForms: false,
|
|
|
|
observedElements: false,
|
|
|
|
changedForms: false,
|
|
|
|
message: null,
|
|
|
|
|
|
|
|
initialize: function(message){
|
|
|
|
this.observedForms = $$('form');
|
|
|
|
this.observedElements = $$('textarea');
|
|
|
|
this.message = message;
|
|
|
|
|
|
|
|
this.observedElements.each(this.observeChange.bind(this));
|
|
|
|
this.observedForms.each(this.submitAction.bind(this));
|
|
|
|
|
|
|
|
window.onbeforeunload = this.unload.bind(this);
|
|
|
|
},
|
|
|
|
|
|
|
|
unload: function(){
|
2011-05-31 01:19:25 +04:00
|
|
|
this.observedElements.each(function(el) {el.blur();})
|
2011-02-21 12:53:29 +03:00
|
|
|
if(this.changedForms)
|
|
|
|
return this.message;
|
|
|
|
},
|
|
|
|
|
|
|
|
setChanged: function(){
|
|
|
|
this.changedForms = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
setUnchanged: function(){
|
|
|
|
this.changedForms = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
observeChange: function(element){
|
|
|
|
element.observe('change',this.setChanged.bindAsEventListener(this));
|
|
|
|
},
|
|
|
|
|
|
|
|
submitAction: function(element){
|
|
|
|
element.observe('submit',this.setUnchanged.bindAsEventListener(this));
|
|
|
|
}
|
|
|
|
});
|
2011-01-07 00:02:19 +03:00
|
|
|
|
2011-03-15 00:31:02 +03:00
|
|
|
/*
|
|
|
|
* 1 - registers a callback which copies the csrf token into the
|
|
|
|
* X-CSRF-Token header with each ajax request. Necessary to
|
|
|
|
* work with rails applications which have fixed
|
|
|
|
* CVE-2011-0447
|
|
|
|
* 2 - shows and hides ajax indicator
|
|
|
|
*/
|
2007-04-27 23:32:57 +04:00
|
|
|
Ajax.Responders.register({
|
2011-03-15 00:31:02 +03:00
|
|
|
onCreate: function(request){
|
|
|
|
var csrf_meta_tag = $$('meta[name=csrf-token]')[0];
|
|
|
|
|
|
|
|
if (csrf_meta_tag) {
|
|
|
|
var header = 'X-CSRF-Token',
|
|
|
|
token = csrf_meta_tag.readAttribute('content');
|
|
|
|
|
|
|
|
if (!request.options.requestHeaders) {
|
|
|
|
request.options.requestHeaders = {};
|
|
|
|
}
|
|
|
|
request.options.requestHeaders[header] = token;
|
|
|
|
}
|
|
|
|
|
2007-04-27 23:32:57 +04:00
|
|
|
if ($('ajax-indicator') && Ajax.activeRequestCount > 0) {
|
|
|
|
Element.show('ajax-indicator');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onComplete: function(){
|
|
|
|
if ($('ajax-indicator') && Ajax.activeRequestCount == 0) {
|
|
|
|
Element.hide('ajax-indicator');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2010-02-25 00:23:20 +03:00
|
|
|
|
2010-06-19 23:51:43 +04:00
|
|
|
function hideOnLoad() {
|
2010-02-25 00:23:20 +03:00
|
|
|
$$('.hol').each(function(el) {
|
|
|
|
el.hide();
|
|
|
|
});
|
2010-06-19 23:51:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Event.observe(window, 'load', hideOnLoad);
|