X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=js%2Finserts.js;h=0dd141650f64203d2f864004ae8fd926f0d11728;hb=9451db1760036985de791ba24c442801e37f37de;hp=a639b2cc3ed623b6f968b856a4a97bc87a42b16d;hpb=73f7e2f83657966f999078917cf9404ec5d65fc3;p=fa-stable.git
diff --git a/js/inserts.js b/js/inserts.js
index a639b2cc..0dd14165 100644
--- a/js/inserts.js
+++ b/js/inserts.js
@@ -1,348 +1,623 @@
-//ajax transfer progress indicator
-var starttabs = new Array();
-var autoload = new Array();
-var onload_script = ""
-var loadstatustext=" Requesting content..."
-var loadedobjects=""
-
-function Querystring(qs) { // optionally pass a querystring to parse
- this.params = new Object()
- this.get=Querystring_get
- this.set=Querystring_set
- this.href=window.location.pathname
- this.url=Querystring_url
-
- if (qs == null)
- qs=location.search.substring(1,location.search.length)
-
- if (qs.length == 0) return
-
-// Turn back to
-// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
- qs = qs.replace(/\+/g, ' ')
- var args = qs.split('&') // parse out name/value pairs separated via &
-
-// split out each name=value pair
- for (var i=0;i.
+***********************************************************************/
+var _focus;
+var _hotkeys = {
+ 'alt': false, // whether is the Alt key pressed
+ 'list': false, // list of all elements with hotkey used recently
+ 'focus': -1 // currently selected list element
+};
- if (pair.length == 2)
- value = unescape(pair[1])
- else
- value = name
-
- this.params[name] = value
+function validate(e) {
+ if (e.name && (typeof _validate[e.name] == 'function'))
+ return _validate[e.name](e);
+ else {
+ var n = e.name.indexOf('[');
+ if(n!=-1) {
+ var key = e.name.substring(n+1, e.name.length-1);
+ if (key.length>1 && _validate[e.name.substring(0,n)])
+ return _validate[e.name.substring(0,n)][key](e);
+ }
}
-
- this.page = this.params.page
- delete this.params.page
+ return true;
}
-function Querystring_get(key, default_) {
- // This silly looking line changes UNDEFINED to NULL
- if (default_ == null) default_ = null;
-
- var value=this.params[key]
- if (value==null) value=default_;
-
- return value
+function save_focus(e) {
+ _focus = e.name||e.id;
+ var h = document.getElementById('hints');
+ if (h) {
+ h.style.display = e.title && e.title.length ? 'inline' : 'none';
+ h.innerHTML = e.title ? e.title : '';
+ }
}
-function Querystring_set(key, value) {
- this.params[key] = value;
-}
+function _expand(tabobj) {
-function Querystring_url() {
- var url = this.href + '?page='+ this.page
- for( key in this.params) {
- url += '&'+ key + '='+ this.params[key]
- }
- return url
+ var ul = tabobj.parentNode.parentNode;
+ var alltabs=ul.getElementsByTagName("button");
+ var frm = tabobj.form;
+
+ if (ul.getAttribute("rel")){
+ for (var i=0; i=0) {
+ var len = select.length;
+ var byid = string_contains(this.className, 'combo') || string_contains(this.className, 'combo3');
+ var ac = this.value.toUpperCase();
+ select.options[select.selectedIndex].selected = false;
+ for (i = 0; i < len; i++) {
+ var txt = byid ? select.options[i].value : select.options[i].text;
+ if (string_contains(this.className, 'combo3')) {
+ if(txt.toUpperCase().indexOf(ac) == 0) {
+ select.options[i].selected = true;
+ break;
+ }
+ } else {
+ if(txt.toUpperCase().indexOf(ac) >= 0) {
+ select.options[i].selected = true;
+ break;
+ }
+ }
+ }
+ }
+ };
+ e.onkeydown = function(ev) {
+ ev = ev||window.event;
+ key = ev.keyCode||ev.which;
+ if(key == 13) {
+ this.blur();
+ return false;
+ }
}
- debug(url)
- container.innerHTML=loadstatustext
- ajaxCaller.postForPlainText(url,vars,callback)
}
-function loadobjs(revattribute){
-if (revattribute!=null && revattribute!=""){ //if "rev" attribute is defined (load external .js or .css files)
-var objectlist=revattribute.split(/\s*,\s*/) //split the files and store as array
-for (var i=0; i=0) {
+ var opt = s.options[s.selectedIndex];
+ if(box) {
+ var old = box.value;
+ box.value = byid ? opt.value : opt.text;
+ box.setAttribute('_last', box.value);
+ return old != box.value
+ }
+ }
}
-function _expand(tabobj) {
-var alltabs=tabobj.parentNode.parentNode.getElementsByTagName("a")
-
-if (tabobj.getAttribute("rel")){
-for (var i=0; i=0) {
+ var sname = '_'+s.name+'_update';
+ var update = document.getElementsByName(sname)[0];
+ if(update) {
+ JsHttpRequest.request(update);
+ }
+ }
+ return true;
+ }
+ e.onkeydown = function(event) {
+ event = event||window.event;
+ key = event.keyCode||event.which;
+ var box = document.getElementsByName(this.getAttribute('rel'))[0];
+ if(key == 8 || (key==37 && event.altKey)) {
+ event.returnValue = false;
+ return false;
+ }
+ if (box && (key == 32) && (string_contains(this.className, 'combo2'))) {
+ this.style.display = 'none';
+ box.style.display = 'inline';
+ box.value='';
+ setFocus(box);
+ return false;
+ } else {
+ if (key == 13 && !e.length) // prevent chrome issue (blocked cursor after CR on empty selector)
+ return false;
+ }
+ }
}
-function expandtab(tabcontentid, tabnumber){ //interface for selecting a tab (plus expand corresponding content)
-var alltabs=document.getElementById(tabcontentid).getElementsByTagName("a")
-var thetab=alltabs[tabnumber]
-//debug(tabcontentid+' '+tabnumber)
-if (thetab.getAttribute("rel")){
- for (var i=0; i-1) {
- ajaxloader(url,vars, table.getAttribute('rel'))
- } else { // this is external 'select' handler
- window.location = url;
- }
-
+ },
+ '.searchbox': // emulated onchange event handling for text inputs
+ function(e) {
+ e.setAttribute('_last_val', e.value);
+ e.setAttribute('autocomplete', 'off'); //must be off when calling onblur
+ e.onblur = function() {
+ var val = this.getAttribute('_last_val');
+ if (val != this.value) {
+ this.setAttribute('_last_val', this.value);
+ JsHttpRequest.request('_'+this.name+'_changed', this.form);
+ }
+ }
+ },
+ '.date':
+ function(e) {
+ e.setAttribute('_last_val', e.value);
+ e.setAttribute('autocomplete', 'off');
+ e.onblur = function() {
+ var val = this.getAttribute('_last_val');
+ if (val != this.value) {
+ this.value = fix_date(this.value, val);
+ this.setAttribute('_last_val', this.value);
+ if (e.className.match(/\bactive\b/))
+ JsHttpRequest.request('_'+this.name+'_changed', this.form);
+ }
+ }
+ },
+ 'button[aspect*selector], button[aspect*abort], input[aspect*selector]': function(e) {
+ e.onclick = function() {
+ passBack(this.getAttribute('rel'));
+ return false;
}
- }
},
- 'table.ajaxgrid th': function(element) {
- element.onclick=function(){
- var table = this.parentNode.parentNode.parentNode
- var url = table.getAttribute('href')
- var vars = {}
- url+='&ajax='+table.id+'&action=sort&id='+ this.id
-// debug(url)
-
- ajaxloader(url, {}, table.getAttribute("rel"))
-// loadobjs(this.getAttribute("href"))
- return false
- }
+ 'button[aspect=popup]': function(e) {
+ e.onclick = function() {
+ if(_w) _w.close(); // this is really necessary to have window on top in FF2 :/
+ var left = (screen.width - 800)/2;
+ var top = (screen.height - 600)/2;
+ _w = open(document.location+'popup=1',
+ "edit","Scrollbars=0,resizable=0,width=800,height=600, top="+top+",left="+left+",screenX="+left+",screenY="+top);
+ if (_w.opener == null)
+ _w.opener = self;
+ // editors._call = key; // store call point for passBack
+// _w.moveTo(50, 50);
+ _w.focus();
+ return false;
+ }
},
- 'a.ajaxgrid-navi': function(element) {
- if(element.onclick==undefined)
- if (element.getAttribute("rel")){
- var modifiedurl=element.getAttribute("href").replace(/^http:\/\/[^\/]+\//i, "http://"+window.location.hostname+"/")
- element.setAttribute("href", modifiedurl) //replace URL's root domain with dynamic root domain, for ajax security sake
- if( modifiedurl.indexOf('ajax=')>-1) {
- element.onclick=function(){ // set ajax handler
-// debug(this.getAttribute("href"))
- ajaxloader(this.getAttribute("href"), {}, this.getAttribute("rel"))
- loadobjs(this.getAttribute("href"))
- return false
- }
- }
- }
+ 'select': function(e) {
+ if(e.onfocus==undefined) {
+ e.onfocus = function() {
+ save_focus(this);
+ };
+ }
+ var c = e.className;
+ if (string_contains(c, 'combo') || string_contains(c, 'combo2') || string_contains(c, 'combo3'))
+ _set_combo_select(e);
+ else {
+ e.onkeydown = function(ev) { // block unintentional page escape with 'history back' key pressed on buttons
+ ev = ev||window.event;
+ key = ev.keyCode||ev.which;
+ if(key == 8 || (key=37 && ev.altKey)) {
+ ev.returnValue = false;
+ return false;
+ }
+ }
+ }
},
- 'a.ajaxgrid-select': function(element) {
- if(element.onclick==undefined) {
- var modifiedurl=element.getAttribute("href").replace(/^http:\/\/[^\/]+\//i, "http://"+window.location.hostname+"/")
- element.setAttribute("href", modifiedurl) //replace URL's root domain with dynamic root domain, for ajax security sake
- element.onclick=function(){
- var row = this.parentNode.parentNode
- var table = row.parentNode.parentNode
-
- var url = this.getAttribute('href')
- var vars = {}
-
- hideddrivetip()
-
-// url += '&ajax='+table.id
- url += _TableRowSelector(table,row)
-// alert( this.getAttribute('rel'))
- ajaxloader(url,vars, this.getAttribute('rel'))
- return false
+ 'a.printlink': function(l) {
+ l.onclick = function() {
+ save_focus(this);
+ JsHttpRequest.request(this, null, 60000);
+ return false;
}
- element.tooltip = element.getAttribute('title') // save tooltip
- element.removeAttribute('title') // native tooltip off
- element.onmouseover=function() {
- ddrivetip(this.tooltip)
+ },
+ 'a.repopts_link': function(l) {
+ l.onclick = function() {
+ save_focus(this);
+ var replinks = document.getElementsBySelector('a.repopts_link');
+ for(var i in replinks)
+ replinks[i].style.fontWeight = replinks[i]==this ? 'bold' : 'normal';
+ JsHttpRequest.request(this, null);
+ return false;
}
- element.onmouseout=function() {
- hideddrivetip()
+ },
+ 'a': function(e) { // traverse menu
+ e.onkeydown = function(ev) {
+ ev = ev||window.event;
+ key = ev.keyCode||ev.which;
+ if(key==37 || key==38 || key==39 || key==40) {
+ move_focus(key, e, document.links);
+ ev.returnValue = false;
+ return false;
+ }
}
- }
+ // prevent unneeded transaction entry abortion
+ if (e.className == 'shortcut'
+ || e.className == 'menu_option'
+ || e.className == 'menu_tab'
+ || e.className == 'selected')
+ e.onclick = function(ev) {
+ if (_validate._processing
+ && _validate._modified
+ && !confirm(_validate._processing)) {
+ ev.returnValue = false;
+ return false;
+ }
+ if (_hotkeys.alt) // ommit Chrome accesskeys
+ return false;
+ window.location = e.href;
+ }
},
- '.amount': function(element) {
- if(element.onblur==undefined) {
- var dec = element.getAttribute("dec");
- element.onblur = function() {
- price_format(this.name, get_amount(this.name), dec);
- };
+ 'ul.ajaxtabs': function(ul) {
+ var ulist=ul.getElementsByTagName("li");
+ for (var x=0; x47 && key<58) || (key>64 && key<91))) {
+ key = String.fromCharCode(key);
+ var n = _hotkeys.focus;
+ var l = document.getElementsBySelector('[accesskey='+key+']');
+ var cnt = l.length;
+ _hotkeys.list = l;
+ for (var i=0; i= 0) {
+ var link = _hotkeys.list[_hotkeys.focus];
+ if(link.onclick)
+ link.onclick();
+ else
+ if (link.target=='_blank') {
+ window.open(link.href,'','toolbar=no,scrollbar=no,resizable=yes,menubar=no,width=900,height=500');
+ openWindow(link.href,'_blank');
+ } else
+ window.location = link.href;
+ }
+ return stopEv(ev);
+ }
+ }
+ return true;
+ }
}
-);
+
+Behaviour.register(inserts);
+
+Behaviour.addLoadEvent(setFocus);
+Behaviour.addLoadEvent(setHotKeys);