1 /**********************************************************************
2 Copyright (C) FrontAccounting, LLC.
3 Released under the terms of the GNU General Public License, GPL,
4 as published by the Free Software Foundation, either version 3
5 of the License, or (at your option) any later version.
6 This program is distributed in the hope that it will be useful,
7 but WITHOUT ANY WARRANTY; without even the implied warranty of
8 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
10 ***********************************************************************/
13 'alt': false, // whether is the Alt key pressed
14 'focus': -1 // currently selected indeks of document.links
17 function save_focus(e) {
18 _focus = e.name||e.id;
19 var h = document.getElementById('hints');
21 h.style.display = e.title && e.title.length ? 'inline' : 'none';
22 h.innerHTML = e.title ? e.title : '';
26 function _expand(tabobj) {
28 var ul = tabobj.parentNode.parentNode;
29 var alltabs=ul.getElementsByTagName("input");
30 var frm = tabobj.form;
32 if (ul.getAttribute("rel")){
33 for (var i=0; i<alltabs.length; i++){
34 alltabs[i].className = "ajaxbutton" //deselect all tabs
36 tabobj.className = "current";
37 JsHttpRequest.request(tabobj)
41 //interface for selecting a tab (plus expand corresponding content)
42 function expandtab(tabcontentid, tabnumber) {
43 var tabs = document.getElementById(tabcontentid);
44 _expand(tabs.getElementsByTagName("input")[tabnumber]);
47 function _set_combo_input(e) {
48 e.setAttribute('_last', e.value);
50 var but_name = this.name.substring(0, this.name.length-4)+'button';
51 var button = document.getElementsByName(but_name)[0];
52 var select = document.getElementsByName(this.getAttribute('rel'))[0];
54 // submit request if there is submit_on_change option set and
55 // search field has changed.
56 if (button && (this.value != this.getAttribute('_last'))) {
57 JsHttpRequest.request(button);
58 } else if(this.className=='combo2') {
59 this.style.display = 'none';
60 select.style.display = 'inline';
65 e.onkeyup = function(ev) {
66 var select = document.getElementsByName(this.getAttribute('rel'))[0];
67 if(select && select.selectedIndex>=0) {
68 var len = select.length;
69 var byid = this.className=='combo';
70 var ac = this.value.toUpperCase();
71 select.options[select.selectedIndex].selected = false;
72 for (i = 0; i < len; i++) {
73 var txt = byid ? select.options[i].value : select.options[i].text;
74 if (txt.toUpperCase().indexOf(ac) >= 0) {
75 select.options[i].selected = true;
81 e.onkeydown = function(ev) {
82 ev = ev||window.event;
83 key = ev.keyCode||ev.which;
91 function _update_box(s) {
92 var byid = s.className=='combo';
93 var rel = s.getAttribute('rel');
94 var box = document.getElementsByName(rel)[0];
95 if(box && s.selectedIndex>=0) {
96 var opt = s.options[s.selectedIndex];
98 box.value = byid ? opt.value : opt.text;
99 box.setAttribute('_last', box.value);
104 function _set_combo_select(e) {
105 // When combo position is changed via js (eg from searchbox)
106 // no onchange event is generated. To ensure proper change
107 // signaling we must track selectedIndex in onblur handler.
108 e.setAttribute('_last', e.selectedIndex);
109 e.onblur = function() {
110 if(this.className=='combo')
112 if (this.selectedIndex != this.getAttribute('_last'))
115 e.onchange = function() {
117 this.setAttribute('_last', this.selectedIndex);
118 if(s.className=='combo')
120 if(s.selectedIndex>=0) {
121 var sname = '_'+s.name+'_update';
122 var update = document.getElementsByName(sname)[0];
124 JsHttpRequest.request(update);
129 e.onkeydown = function(event) {
130 event = event||window.event;
131 key = event.keyCode||event.which;
132 var box = document.getElementsByName(this.getAttribute('rel'))[0];
133 if (box && key == 32 && this.className == 'combo2') {
134 this.style.display = 'none';
135 box.style.display = 'inline';
140 if (this.getAttribute('aspect') == 'editable' && key==115) {
141 // F4: call related database editor - not available in non-js fallback mode
142 JsHttpRequest.request('_'+this.name+'_editor', this.form);
143 return false; // prevent default binding
144 // TODO: stopPropagation when needed
150 Behaviour definitions
153 'input': function(e) {
154 if(e.onfocus==undefined) {
155 e.onfocus = function() {
157 if (this.className == 'combo')
161 if (e.className == 'combo' || e.className == 'combo2') {
165 if(e.type == 'text' ) {
166 e.onkeydown = function(ev) {
167 ev = ev||window.event;
168 key = ev.keyCode||ev.which;
170 if(e.className == 'searchbox') e.onblur();
177 'input.combo2,input[aspect="fallback"]':
179 // this hides search button for js enabled browsers
180 e.style.display = 'none';
184 // this shows divs for js enabled browsers only
185 e.style.display = 'block';
187 // '.ajaxsubmit,.editbutton,.navibutton': // much slower on IE7
188 'button.ajaxsubmit,input.ajaxsubmit,input.editbutton,button.editbutton,button.navibutton':
190 e.onclick = function() {
192 if (e.getAttribute('aspect') == 'process')
193 JsHttpRequest.request(this, null, 30000);
195 JsHttpRequest.request(this);
199 /* 'button': function(e) {
201 var func = _validate[e.name];
204 if (typeof old != 'function') {
207 e.onclick = function() {
209 { old(); return true;}
217 */ '.amount': function(e) {
218 if(e.onblur==undefined) {
219 e.onblur = function() {
220 var dec = this.getAttribute("dec");
221 price_format(this.name, get_amount(this.name), dec);
225 '.searchbox': // emulated onchange event handling for text inputs
227 e.setAttribute('_last_val', e.value);
228 e.setAttribute('autocomplete', 'off'); //must be off when calling onblur
229 e.onblur = function() {
230 var val = this.getAttribute('_last_val');
231 if (val != this.value) {
232 this.setAttribute('_last_val', this.value);
233 JsHttpRequest.request('_'+this.name+'_changed', this.form);
237 'select': function(e) {
238 if(e.onfocus==undefined) {
239 e.onfocus = function() {
243 if (c == 'combo' || c == 'combo2')
244 _set_combo_select(e);
247 'textarea,a': function(e) {
248 if(e.onfocus==undefined) {
249 e.onfocus = function() {
252 e.onmouseover = function(e) {
258 'a.printlink': function(l) {
259 l.onclick = function() {
261 JsHttpRequest.request(this);
265 'a': function(e) { // traverse menu
266 e.onkeydown = function(ev) {
267 ev = ev||window.event;
268 key = ev.keyCode||ev.which;
269 if(key==37 || key==38 || key==39 || key==40) {
270 move_focus(key, e, document.links);
271 ev.returnValue = false;
276 'ul.ajaxtabs': function(ul) {
277 var ulist=ul.getElementsByTagName("li");
278 for (var x=0; x<ulist.length; x++){ //loop through each LI e
279 var ulistlink=ulist[x].getElementsByTagName("input")[0];
280 if(ulistlink.onclick==undefined) {
281 // ? var modifiedurl=ulistlink.getAttribute("href").replace(/^http:\/\/[^\/]+\//i, "http://"+window.location.hostname+"/")
282 var url = ulistlink.form.action
283 ulistlink.onclick=function(){
290 /* 'tr.editrow': function(e) {
291 e.onkeydown = function(ev) {
292 ev = ev||window.event;
293 key = ev.keyCode||ev.which;
295 // Find & click additem/update button
297 } else if(key == 27) {
303 *//* '#msgbox': function(e) {
304 // this is to avoid changing div height after ajax update in IE7
305 e.style.display = e.innerHTML.length ? 'block' : 'none';
308 'a.date_picker': function(e) {
309 // this un-hides data picker for js enabled browsers
310 e.href = date_picker(this.getAttribute('rel'));
311 e.style.display = '';
312 e.tabindex = -1; // skip in tabbing order
316 function stopEv(ev) {
317 ev.returnValue = false;
318 ev.cancelBubble = true;
319 if(ev.preventDefault) ev.preventDefault();
323 Modified accesskey system. While Alt key is pressed letter keys moves
324 focus to next marked link. Alt key release activates focused link.
326 function setHotKeys() {
327 document.onkeydown = function(ev) {
328 ev = ev||window.event;
329 key = ev.keyCode||ev.which;
330 if (key == 18 && !ev.ctrlKey) { // start selection, skip Win AltGr
335 else if (_hotkeys.alt && ((key>47 && key<58) || (key>64 && key<91))) {
336 var n = _hotkeys.focus;
337 var l = document.links;
339 key = String.fromCharCode(key);
340 for (var i=0; i<cnt; i++) {
342 // check also if the link is visible
343 if (l[n].accessKey==key && l[n].scrollWidth) {
345 // The timeout is needed to prevent unpredictable behaviour on IE.
346 var tmp = function() {document.links[_hotkeys.focus].focus();};
353 if((ev.ctrlKey && key == 13) || key == 27) {
354 _hotkeys.alt = false; // cancel link selection
356 ev.cancelBubble = true;
357 if(ev.stopPropagation) ev.stopPropagation();
358 // activate submit/escape form
359 for(var j=0; j<this.forms.length; j++) {
360 var form = this.forms[j];
361 for (var i=0; i<form.elements.length; i++){
362 var el = form.elements[i];
363 var asp = el.getAttribute('aspect');
364 if ((asp=='default' && key==13)||(asp=='cancel' && key==27)) {
365 JsHttpRequest.request(el);
366 ev.returnValue = false;
371 ev.returnValue = false;
376 document.onkeyup = function(ev) {
377 if (_hotkeys.alt==true) {
378 ev = ev||window.event;
379 key = ev.keyCode||ev.which;
382 _hotkeys.alt = false;
383 if (_hotkeys.focus>=0) {
384 var link = document.links[_hotkeys.focus];
388 if (link.target=='_blank') {
389 window.open(link.href,'','toolbar=no,scrollbar=no,resizable=yes,menubar=no,width=900,height=500');
390 openWindow(link.href,'_blank');
392 window.location = link.href;
401 Behaviour.register(inserts);
403 Behaviour.addLoadEvent(setFocus);
404 Behaviour.addLoadEvent(setHotKeys);