2012-02-10 04:36:21 +04:00
|
|
|
/* Redmine - project management software
|
|
|
|
Copyright (C) 2006-2012 Jean-Philippe Lang */
|
2008-02-10 16:17:41 +03:00
|
|
|
|
2007-04-04 22:20:45 +04:00
|
|
|
function checkAll (id, checked) {
|
2012-02-10 04:35:58 +04:00
|
|
|
var els = Element.descendants(id);
|
|
|
|
for (var i = 0; i < els.length; i++) {
|
2008-05-14 21:23:40 +04:00
|
|
|
if (els[i].disabled==false) {
|
|
|
|
els[i].checked = checked;
|
2007-04-04 22:20:45 +04:00
|
|
|
}
|
2012-02-10 04:35:58 +04:00
|
|
|
}
|
2007-04-04 22:20:45 +04:00
|
|
|
}
|
|
|
|
|
2008-08-26 20:05:02 +04:00
|
|
|
function toggleCheckboxesBySelector(selector) {
|
2012-02-10 04:35:58 +04:00
|
|
|
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; }
|
2008-08-26 20:05:02 +04:00
|
|
|
}
|
|
|
|
|
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) {
|
2012-02-10 04:35:58 +04:00
|
|
|
Element.show(id);
|
|
|
|
if (focus!=null) { Form.Element.focus(focus); }
|
|
|
|
Element.scrollTo(id);
|
2008-06-29 23:50:07 +04:00
|
|
|
}
|
|
|
|
|
2009-05-04 22:04:09 +04:00
|
|
|
function toggleRowGroup(el) {
|
2012-02-10 04:35:58 +04:00
|
|
|
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);
|
|
|
|
}
|
2009-05-04 22:04:09 +04:00
|
|
|
}
|
|
|
|
|
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) {
|
2012-02-10 04:35:58 +04:00
|
|
|
var tr = Element.up(el, 'tr');
|
2011-03-20 19:01:25 +03:00
|
|
|
if (tr.hasClassName('open')) {
|
|
|
|
collapseAllRowGroups(el);
|
|
|
|
} else {
|
|
|
|
expandAllRowGroups(el);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-20 11:24:16 +04:00
|
|
|
function toggleFieldset(el) {
|
2012-02-10 04:35:58 +04:00
|
|
|
var fieldset = Element.up(el, 'fieldset');
|
|
|
|
fieldset.toggleClassName('collapsed');
|
|
|
|
Effect.toggle(fieldset.down('div'), 'slide', {duration:0.2});
|
2009-09-20 11:24:16 +04:00
|
|
|
}
|
|
|
|
|
2011-02-20 18:38:07 +03:00
|
|
|
function hideFieldset(el) {
|
2012-02-10 04:35:58 +04:00
|
|
|
var fieldset = Element.up(el, 'fieldset');
|
|
|
|
fieldset.toggleClassName('collapsed');
|
|
|
|
fieldset.down('div').hide();
|
2011-02-20 18:38:07 +03:00
|
|
|
}
|
|
|
|
|
2012-01-24 22:02:22 +04:00
|
|
|
function add_filter() {
|
|
|
|
select = $('add_filter_select');
|
|
|
|
field = select.value
|
|
|
|
Element.show('tr_' + field);
|
|
|
|
check_box = $('cb_' + field);
|
|
|
|
check_box.checked = true;
|
|
|
|
toggle_filter(field);
|
|
|
|
select.selectedIndex = 0;
|
|
|
|
|
|
|
|
for (i=0; i<select.options.length; i++) {
|
|
|
|
if (select.options[i].value == field) {
|
|
|
|
select.options[i].disabled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggle_filter(field) {
|
|
|
|
check_box = $('cb_' + field);
|
|
|
|
if (check_box.checked) {
|
|
|
|
Element.show("operators_" + field);
|
|
|
|
Form.Element.enable("operators_" + field);
|
|
|
|
toggle_operator(field);
|
|
|
|
} else {
|
|
|
|
Element.hide("operators_" + field);
|
|
|
|
Form.Element.disable("operators_" + field);
|
|
|
|
enableValues(field, []);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function enableValues(field, indexes) {
|
|
|
|
var f = $$(".values_" + field);
|
|
|
|
for(var i=0;i<f.length;i++) {
|
|
|
|
if (indexes.include(i)) {
|
|
|
|
Form.Element.enable(f[i]);
|
|
|
|
f[i].up('span').show();
|
|
|
|
} else {
|
|
|
|
f[i].value = '';
|
|
|
|
Form.Element.disable(f[i]);
|
|
|
|
f[i].up('span').hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (indexes.length > 0) {
|
|
|
|
Element.show("div_values_" + field);
|
|
|
|
} else {
|
|
|
|
Element.hide("div_values_" + field);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggle_operator(field) {
|
|
|
|
operator = $("operators_" + field);
|
|
|
|
switch (operator.value) {
|
|
|
|
case "!*":
|
|
|
|
case "*":
|
|
|
|
case "t":
|
|
|
|
case "w":
|
|
|
|
case "o":
|
|
|
|
case "c":
|
|
|
|
enableValues(field, []);
|
|
|
|
break;
|
|
|
|
case "><":
|
|
|
|
enableValues(field, [0,1]);
|
|
|
|
break;
|
|
|
|
case "<t+":
|
|
|
|
case ">t+":
|
|
|
|
case "t+":
|
|
|
|
case ">t-":
|
|
|
|
case "<t-":
|
|
|
|
case "t-":
|
|
|
|
enableValues(field, [2]);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
enableValues(field, [0]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggle_multi_select(el) {
|
|
|
|
var select = $(el);
|
|
|
|
if (select.multiple == true) {
|
|
|
|
select.multiple = false;
|
|
|
|
} else {
|
|
|
|
select.multiple = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function submit_query_form(id) {
|
|
|
|
selectAllOptions("selected_columns");
|
|
|
|
$(id).submit();
|
|
|
|
}
|
|
|
|
|
|
|
|
function apply_filters_observer() {
|
|
|
|
$$("#query_form input[type=text]").invoke("observe", "keypress", function(e){
|
|
|
|
if(e.keyCode == Event.KEY_RETURN) {
|
|
|
|
submit_query_form("query_form");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2008-02-29 22:46:58 +03:00
|
|
|
var fileFieldCount = 1;
|
|
|
|
|
2007-04-04 22:20:45 +04:00
|
|
|
function addFileField() {
|
2011-07-09 23:55:44 +04:00
|
|
|
var fields = $('attachments_fields');
|
2011-07-10 00:11:18 +04:00
|
|
|
if (fields.childElements().length >= 10) return false;
|
|
|
|
fileFieldCount++;
|
2012-02-05 15:54:38 +04:00
|
|
|
var s = new Element('span');
|
2011-07-09 23:55:44 +04:00
|
|
|
s.update(fields.down('span').innerHTML);
|
|
|
|
s.down('input.file').name = "attachments[" + fileFieldCount + "][file]";
|
|
|
|
s.down('input.description').name = "attachments[" + fileFieldCount + "][description]";
|
|
|
|
fields.appendChild(s);
|
2007-04-04 22:20:45 +04:00
|
|
|
}
|
|
|
|
|
2011-07-10 00:11:18 +04:00
|
|
|
function removeFileField(el) {
|
|
|
|
var fields = $('attachments_fields');
|
2012-02-10 04:35:58 +04:00
|
|
|
var s = Element.up(el, 'span');
|
|
|
|
if (fields.childElements().length > 1) {
|
|
|
|
s.remove();
|
|
|
|
} else {
|
|
|
|
s.update(s.innerHTML);
|
|
|
|
}
|
2011-07-10 00:11:18 +04:00
|
|
|
}
|
|
|
|
|
2011-11-26 02:32:07 +04:00
|
|
|
function checkFileSize(el, maxSize, message) {
|
|
|
|
var files = el.files;
|
|
|
|
if (files) {
|
|
|
|
for (var i=0; i<files.length; i++) {
|
|
|
|
if (files[i].size > maxSize) {
|
|
|
|
alert(message);
|
|
|
|
el.value = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-04 22:20:45 +04:00
|
|
|
function showTab(name) {
|
2012-02-10 04:35:58 +04:00
|
|
|
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) {
|
2012-02-10 04:35:58 +04:00
|
|
|
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();
|
2009-12-14 23:13:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function moveTabLeft(el) {
|
2012-02-10 04:35:58 +04:00
|
|
|
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();
|
|
|
|
}
|
2009-12-14 23:13:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function displayTabsButtons() {
|
2012-02-10 04:35:58 +04:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
});
|
2009-12-14 23:13:29 +03:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-20 17:23:20 +04:00
|
|
|
function showModal(id, width) {
|
|
|
|
el = $(id);
|
2012-02-10 04:35:58 +04:00
|
|
|
if (el == undefined || el.visible()) {return;}
|
2011-11-20 17:23:20 +04:00
|
|
|
var h = $$('body')[0].getHeight();
|
|
|
|
var d = document.createElement("div");
|
|
|
|
d.id = 'modalbg';
|
|
|
|
$('main').appendChild(d);
|
|
|
|
$('modalbg').setStyle({ width: '100%', height: h + 'px' });
|
|
|
|
$('modalbg').show();
|
|
|
|
|
|
|
|
var pageWidth = document.viewport.getWidth();
|
2012-02-10 04:35:58 +04:00
|
|
|
if (width) {
|
|
|
|
el.setStyle({'width': width});
|
2012-01-09 22:48:36 +04:00
|
|
|
}
|
2012-02-10 04:35:58 +04:00
|
|
|
el.setStyle({'left': (((pageWidth - el.getWidth())/2 *100) / pageWidth) + '%'});
|
2011-11-20 17:23:20 +04:00
|
|
|
el.addClassName('modal');
|
2012-02-10 04:35:58 +04:00
|
|
|
el.show();
|
2011-11-20 17:23:20 +04:00
|
|
|
|
2012-02-14 19:28:30 +04:00
|
|
|
if (el.down("input[type=text]")) {
|
|
|
|
el.down("input[type=text]").focus();
|
|
|
|
} else if (el.down("input[type=submit]")) {
|
|
|
|
el.down("input[type=submit]").focus();
|
|
|
|
}
|
2011-11-20 17:23:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function hideModal(el) {
|
2012-02-11 17:05:41 +04:00
|
|
|
var modal;
|
|
|
|
if (el) {
|
|
|
|
modal = Element.up(el, 'div.modal');
|
|
|
|
} else {
|
|
|
|
modal = $('ajax-modal');
|
|
|
|
}
|
2012-02-10 04:35:58 +04:00
|
|
|
if (modal) {
|
|
|
|
modal.hide();
|
|
|
|
}
|
|
|
|
var bg = $('modalbg');
|
|
|
|
if (bg) {
|
|
|
|
bg.remove();
|
2011-11-20 17:23:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-22 23:34:21 +04:00
|
|
|
function collapseScmEntry(id) {
|
2012-02-10 04:35:58 +04:00
|
|
|
var els = document.getElementsByClassName(id, 'browser');
|
|
|
|
for (var i = 0; i < els.length; i++) {
|
|
|
|
if (els[i].hasClassName('open')) {
|
|
|
|
collapseScmEntry(els[i].id);
|
|
|
|
}
|
|
|
|
Element.hide(els[i]);
|
|
|
|
}
|
|
|
|
$(id).removeClassName('open');
|
2007-10-22 23:34:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function expandScmEntry(id) {
|
|
|
|
var els = document.getElementsByClassName(id, 'browser');
|
2012-02-10 04:35:58 +04:00
|
|
|
for (var i = 0; i < els.length; i++) {
|
2007-10-22 23:34:21 +04:00
|
|
|
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) {
|
2012-02-10 04:35:58 +04:00
|
|
|
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;
|
2008-06-25 23:25:28 +04:00
|
|
|
}
|
|
|
|
|
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',
|
2011-12-09 00:03:27 +04:00
|
|
|
method: 'get',
|
2010-03-13 17:56:49 +03:00
|
|
|
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',
|
2011-12-09 00:03:27 +04:00
|
|
|
method: 'get',
|
2010-12-12 19:04:28 +03:00
|
|
|
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);
|
|
|
|
};
|
2012-02-10 04:36:21 +04:00
|
|
|
|
2011-01-07 00:02:19 +03:00
|
|
|
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({
|
2012-02-10 04:35:58 +04:00
|
|
|
observedForms: false,
|
|
|
|
observedElements: false,
|
|
|
|
changedForms: false,
|
|
|
|
message: null,
|
2012-02-10 04:36:21 +04:00
|
|
|
|
2012-02-10 04:35:58 +04:00
|
|
|
initialize: function(message){
|
|
|
|
this.observedForms = $$('form');
|
|
|
|
this.observedElements = $$('textarea');
|
|
|
|
this.message = message;
|
2012-02-10 04:36:21 +04:00
|
|
|
|
2012-02-10 04:35:58 +04:00
|
|
|
this.observedElements.each(this.observeChange.bind(this));
|
|
|
|
this.observedForms.each(this.submitAction.bind(this));
|
2012-02-10 04:36:21 +04:00
|
|
|
|
2012-02-10 04:35:58 +04:00
|
|
|
window.onbeforeunload = this.unload.bind(this);
|
|
|
|
},
|
2012-02-10 04:36:21 +04:00
|
|
|
|
2012-02-10 04:35:58 +04:00
|
|
|
unload: function(){
|
|
|
|
this.observedElements.each(function(el) {el.blur();})
|
|
|
|
if(this.changedForms)
|
2011-02-21 12:53:29 +03:00
|
|
|
return this.message;
|
2012-02-10 04:35:58 +04:00
|
|
|
},
|
2012-02-10 04:36:21 +04:00
|
|
|
|
2012-02-10 04:35:58 +04:00
|
|
|
setChanged: function(){
|
2011-02-21 12:53:29 +03:00
|
|
|
this.changedForms = true;
|
2012-02-10 04:35:58 +04:00
|
|
|
},
|
2012-02-10 04:36:21 +04:00
|
|
|
|
2012-02-10 04:35:58 +04:00
|
|
|
setUnchanged: function(){
|
2011-02-21 12:53:29 +03:00
|
|
|
this.changedForms = false;
|
2012-02-10 04:35:58 +04:00
|
|
|
},
|
2012-02-10 04:36:21 +04:00
|
|
|
|
2012-02-10 04:35:58 +04:00
|
|
|
observeChange: function(element){
|
2011-02-21 12:53:29 +03:00
|
|
|
element.observe('change',this.setChanged.bindAsEventListener(this));
|
2012-02-10 04:35:58 +04:00
|
|
|
},
|
2012-02-10 04:36:21 +04:00
|
|
|
|
2012-02-10 04:35:58 +04:00
|
|
|
submitAction: function(element){
|
2011-02-21 12:53:29 +03:00
|
|
|
element.observe('submit',this.setUnchanged.bindAsEventListener(this));
|
2012-02-10 04:35:58 +04:00
|
|
|
}
|
2011-02-21 12:53:29 +03:00
|
|
|
});
|
2011-01-07 00:02:19 +03:00
|
|
|
|
2012-02-10 04:36:21 +04:00
|
|
|
/*
|
2011-03-15 00:31:02 +03:00
|
|
|
* 1 - registers a callback which copies the csrf token into the
|
2012-02-10 04:36:21 +04:00
|
|
|
* X-CSRF-Token header with each ajax request. Necessary to
|
2011-03-15 00:31:02 +03:00
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
2012-02-14 19:34:27 +04:00
|
|
|
if ($('ajax-indicator') && Ajax.activeRequestCount > 0 && $$('input.ajax-loading').size() == 0) {
|
2007-04-27 23:32:57 +04:00
|
|
|
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) {
|
2012-02-10 04:35:58 +04:00
|
|
|
el.hide();
|
|
|
|
});
|
2010-06-19 23:51:43 +04:00
|
|
|
}
|
|
|
|
|
2012-04-14 08:58:46 +04:00
|
|
|
function addFormObserversForDoubleSubmit() {
|
|
|
|
$$('form[method=post]').each(function(el) {
|
|
|
|
Event.observe(el, 'submit', function(e) {
|
|
|
|
var form = Event.element(e);
|
|
|
|
form.select('input[type=submit]').each(function(btn) {
|
|
|
|
btn.disable();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2010-06-19 23:51:43 +04:00
|
|
|
Event.observe(window, 'load', hideOnLoad);
|
2012-04-14 08:58:46 +04:00
|
|
|
Event.observe(window, 'load', addFormObserversForDoubleSubmit);
|