comparison public/javascripts/.svn/text-base/application.js.svn-base @ 0:513646585e45

* Import Redmine trunk SVN rev 3859
author Chris Cannam
date Fri, 23 Jul 2010 15:52:44 +0100
parents
children cca12e1c1fd4
comparison
equal deleted inserted replaced
-1:000000000000 0:513646585e45
1 /* redMine - project management software
2 Copyright (C) 2006-2008 Jean-Philippe Lang */
3
4 function checkAll (id, checked) {
5 var els = Element.descendants(id);
6 for (var i = 0; i < els.length; i++) {
7 if (els[i].disabled==false) {
8 els[i].checked = checked;
9 }
10 }
11 }
12
13 function toggleCheckboxesBySelector(selector) {
14 boxes = $$(selector);
15 var all_checked = true;
16 for (i = 0; i < boxes.length; i++) { if (boxes[i].checked == false) { all_checked = false; } }
17 for (i = 0; i < boxes.length; i++) { boxes[i].checked = !all_checked; }
18 }
19
20 function showAndScrollTo(id, focus) {
21 Element.show(id);
22 if (focus!=null) { Form.Element.focus(focus); }
23 Element.scrollTo(id);
24 }
25
26 function toggleRowGroup(el) {
27 var tr = Element.up(el, 'tr');
28 var n = Element.next(tr);
29 tr.toggleClassName('open');
30 while (n != undefined && !n.hasClassName('group')) {
31 Element.toggle(n);
32 n = Element.next(n);
33 }
34 }
35
36 function toggleFieldset(el) {
37 var fieldset = Element.up(el, 'fieldset');
38 fieldset.toggleClassName('collapsed');
39 Effect.toggle(fieldset.down('div'), 'slide', {duration:0.2});
40 }
41
42 var fileFieldCount = 1;
43
44 function addFileField() {
45 if (fileFieldCount >= 10) return false
46 fileFieldCount++;
47 var f = document.createElement("input");
48 f.type = "file";
49 f.name = "attachments[" + fileFieldCount + "][file]";
50 f.size = 30;
51 var d = document.createElement("input");
52 d.type = "text";
53 d.name = "attachments[" + fileFieldCount + "][description]";
54 d.size = 60;
55 var dLabel = document.createElement("label");
56 dLabel.addClassName('inline');
57 // Pulls the languge value used for Optional Description
58 dLabel.update($('attachment_description_label_content').innerHTML)
59
60 p = document.getElementById("attachments_fields");
61 p.appendChild(document.createElement("br"));
62 p.appendChild(f);
63 p.appendChild(dLabel);
64 dLabel.appendChild(d);
65
66 }
67
68 function showTab(name) {
69 var f = $$('div#content .tab-content');
70 for(var i=0; i<f.length; i++){
71 Element.hide(f[i]);
72 }
73 var f = $$('div.tabs a');
74 for(var i=0; i<f.length; i++){
75 Element.removeClassName(f[i], "selected");
76 }
77 Element.show('tab-content-' + name);
78 Element.addClassName('tab-' + name, "selected");
79 return false;
80 }
81
82 function moveTabRight(el) {
83 var lis = Element.up(el, 'div.tabs').down('ul').childElements();
84 var tabsWidth = 0;
85 var i;
86 for (i=0; i<lis.length; i++) {
87 if (lis[i].visible()) {
88 tabsWidth += lis[i].getWidth() + 6;
89 }
90 }
91 if (tabsWidth < Element.up(el, 'div.tabs').getWidth() - 60) {
92 return;
93 }
94 i=0;
95 while (i<lis.length && !lis[i].visible()) {
96 i++;
97 }
98 lis[i].hide();
99 }
100
101 function moveTabLeft(el) {
102 var lis = Element.up(el, 'div.tabs').down('ul').childElements();
103 var i = 0;
104 while (i<lis.length && !lis[i].visible()) {
105 i++;
106 }
107 if (i>0) {
108 lis[i-1].show();
109 }
110 }
111
112 function displayTabsButtons() {
113 var lis;
114 var tabsWidth = 0;
115 var i;
116 $$('div.tabs').each(function(el) {
117 lis = el.down('ul').childElements();
118 for (i=0; i<lis.length; i++) {
119 if (lis[i].visible()) {
120 tabsWidth += lis[i].getWidth() + 6;
121 }
122 }
123 if ((tabsWidth < el.getWidth() - 60) && (lis[0].visible())) {
124 el.down('div.tabs-buttons').hide();
125 } else {
126 el.down('div.tabs-buttons').show();
127 }
128 });
129 }
130
131 function setPredecessorFieldsVisibility() {
132 relationType = $('relation_relation_type');
133 if (relationType && (relationType.value == "precedes" || relationType.value == "follows")) {
134 Element.show('predecessor_fields');
135 } else {
136 Element.hide('predecessor_fields');
137 }
138 }
139
140 function promptToRemote(text, param, url) {
141 value = prompt(text + ':');
142 if (value) {
143 new Ajax.Request(url + '?' + param + '=' + encodeURIComponent(value), {asynchronous:true, evalScripts:true});
144 return false;
145 }
146 }
147
148 function collapseScmEntry(id) {
149 var els = document.getElementsByClassName(id, 'browser');
150 for (var i = 0; i < els.length; i++) {
151 if (els[i].hasClassName('open')) {
152 collapseScmEntry(els[i].id);
153 }
154 Element.hide(els[i]);
155 }
156 $(id).removeClassName('open');
157 }
158
159 function expandScmEntry(id) {
160 var els = document.getElementsByClassName(id, 'browser');
161 for (var i = 0; i < els.length; i++) {
162 Element.show(els[i]);
163 if (els[i].hasClassName('loaded') && !els[i].hasClassName('collapsed')) {
164 expandScmEntry(els[i].id);
165 }
166 }
167 $(id).addClassName('open');
168 }
169
170 function scmEntryClick(id) {
171 el = $(id);
172 if (el.hasClassName('open')) {
173 collapseScmEntry(id);
174 el.addClassName('collapsed');
175 return false;
176 } else if (el.hasClassName('loaded')) {
177 expandScmEntry(id);
178 el.removeClassName('collapsed');
179 return false;
180 }
181 if (el.hasClassName('loading')) {
182 return false;
183 }
184 el.addClassName('loading');
185 return true;
186 }
187
188 function scmEntryLoaded(id) {
189 Element.addClassName(id, 'open');
190 Element.addClassName(id, 'loaded');
191 Element.removeClassName(id, 'loading');
192 }
193
194 function randomKey(size) {
195 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');
196 var key = '';
197 for (i = 0; i < size; i++) {
198 key += chars[Math.floor(Math.random() * chars.length)];
199 }
200 return key;
201 }
202
203 function observeParentIssueField(url) {
204 new Ajax.Autocompleter('issue_parent_issue_id',
205 'parent_issue_candidates',
206 url,
207 { minChars: 3,
208 frequency: 0.5,
209 paramName: 'q',
210 updateElement: function(value) {
211 document.getElementById('issue_parent_issue_id').value = value.id;
212 }});
213 }
214
215 /* shows and hides ajax indicator */
216 Ajax.Responders.register({
217 onCreate: function(){
218 if ($('ajax-indicator') && Ajax.activeRequestCount > 0) {
219 Element.show('ajax-indicator');
220 }
221 },
222 onComplete: function(){
223 if ($('ajax-indicator') && Ajax.activeRequestCount == 0) {
224 Element.hide('ajax-indicator');
225 }
226 }
227 });
228
229 function hideOnLoad() {
230 $$('.hol').each(function(el) {
231 el.hide();
232 });
233 }
234
235 Event.observe(window, 'load', hideOnLoad);