Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vitmalina committed Sep 27, 2011
1 parent 1c6b92a commit 9514abb
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 65 deletions.
129 changes: 112 additions & 17 deletions libs/jsControls2.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,34 +53,34 @@ var jsControls2 = {
// -- insert div for calendar
var div = document.createElement('DIV');
div.id = cnt.id + '_calendar';
div.style.cssText += 'position: absolute; z-index: 1000; display: none;';
div.style.cssText += 'position: absolute; z-index: 1000; display: none; '+
'top: '+ (parseInt(cnt.offsetTop) + parseInt(cnt.offsetHeight)) +'px; left: '+ parseInt(cnt.offsetLeft) +'px;';
div.className = 'w20-calendar';
//div.innerHTML = this.getCalendar(cnt.value, (param ? param : {}));

cnt.parentNode.appendChild(div, cnt);
cnt._controls = this;
cnt._param = param;
cnt.calendar = div;
window._calendar_el = cnt;
cnt.parentNode.appendChild(div);
cnt._controls = this;
cnt._param = param;
cnt._calendar_div = div;

// -- cross browser multiple events
if (cnt.onfocus) cnt._onfocus = cnt.onfocus;
cnt.onfocus = function (event) {
if (this.calendar.style.display == '') return;
this.calendar.innerHTML = this._controls.getCalendar(cnt.value, (this._param ? this._param : {}));
this.calendar.style.display = '';
window.jsUtils.dropShadow(this.calendar);
window._tmp_el = this;
if (this._calendar_div.style.display == '') return;
this._calendar_div.innerHTML = this._controls.getCalendar(cnt.value, (this._param ? this._param : {}));
this._calendar_div.style.display = '';
if (cnt._onfocus) cnt._onfocus();
}
if (cnt.onkeyup) cnt._onkeyup = cnt.onkeyup;
cnt.onkeyup = function (event) {
this.calendar.innerHTML = this._controls.getCalendar(cnt.value, (this._param ? this._param : {}));
this._calendar_div.innerHTML = this._controls.getCalendar(cnt.value, (this._param ? this._param : {}));
if (cnt._onkeyup) cnt._onkeyup();
}
if (cnt.onblur) cnt._onblur = cnt.onblur;
cnt.onblur = function (event) {
window._tmp_el = this;
window._tmp_timeout = setTimeout("window._tmp_el.calendar.style.display = 'none'; window.jsUtils.clearShadow(window._tmp_el.calendar);", 300);
window._tmp_timeout = setTimeout("document.getElementById('"+ cnt.id +"')._calendar_div.style.display = 'none';", 300);
if (cnt._onblur) cnt._onblur();
}
break;
Expand All @@ -94,10 +94,66 @@ var jsControls2 = {
case 'LIST':
break;

case 'LOOKUP':
case 'AUTOCOMPLETE':
// -- insert div for items
var div = document.createElement('DIV');
div.id = cnt.id + '_items';
div.style.cssText += 'position: absolute; z-index: 1000; display: none; -moz-box-sizing: border-box; -webkit-box-sizing: border-box;'+
'width: '+ parseInt(cnt.offsetWidth) +'px; height: 200px; overflow: auto;'+
'top: '+ (parseInt(cnt.offsetTop) + parseInt(cnt.offsetHeight)) +'px; left: '+ parseInt(cnt.offsetLeft) +'px;';
div.className = 'w20-items';

cnt.parentNode.appendChild(div);
cnt._controls = this;
cnt._param = param;
cnt._items_div = div;
if (param && param['items']) {
cnt._items = param['items'];
this.populate(cnt);
} else {
cnt._items = [];
}
cnt.hideItems = function (delay) {
if (String(delay) == 'undefined') delay = 300;
this._timeout = setTimeout("document.getElementById('"+ this.id +"')._items_div.style.display = 'none';", delay);
}
cnt.showItems = function () {
this._items_div.style.display = '';
setTimeout("document.getElementById('"+ this.id +"')._items_div.scrollTop = '0px';", 1);
}
// if items clicked
div.onmousedown = new Function("setTimeout('var el = document.getElementById(\""+ cnt.id +"\"); clearTimeout(el._timeout); el.focus();', 200)");

// -- cross browser multiple events
if (cnt.onclick) cnt._onclick = cnt.onclick;
cnt.onclick = function (event) {
// check minChars
var minChars = 1;
if (this._param && this._param['minChars']) minChars = parseInt(this._param['minChars']);
if (String(this.value).length < minChars) { return; }
// show
if (this._items.length > 0 && this._param && this._param['showOnClick'] == true) this.showItems();
if (this._onclick) this._onclick();
}
if (cnt.onkeyup) cnt._onkeyup = cnt.onkeyup;
cnt.onkeyup = function (event) {
// check minChars
var minChars = 1;
if (this._param && this._param['minChars']) minChars = parseInt(this._param['minChars']);
if (String(this.value).length < minChars) { return; }
// show
this._controls.populate(this);
if (this._items_div.style.display != '') this.showItems();
if (this._onkeyup) this._onkeyup();
}
if (cnt.onblur) cnt._onblur = cnt.onblur;
cnt.onblur = function (event) {
this.hideItems();
if (this._onblur) this._onblur();
}
break;

case 'LOOKUP-SOFT':
case 'LOOKUP':
break;

case 'HTMLAREA':
Expand All @@ -109,12 +165,51 @@ var jsControls2 = {
case 'RADIO-YESNO':
break;

case 'MASK':
break;

case 'UPLOAD':
break;
}
},

populate: function(cnt, param) {
populate: function(cnt) { // used for autocomplete
var items = cnt._items;
var minChars = 1;
if (cnt._param && cnt._param['minChars']) minChars = parseInt(cnt._param['minChars']);

if (cnt._param && cnt._param['url'] && (items.length == 0 // not items
|| (String(cnt.value).length == minChars && cnt._param['lastSearch'] != cnt.value) // min chars is reached
|| (String(cnt.value).length > minChars && cnt._param['lastSearch'] != cnt.value && cnt._param['cacheMax'] == cnt._count) // > min chars and max = cacheMax
)) {
cnt._param['lastSearch'] = cnt.value;
window.jsUtils.get(cnt._param['url'], { s: cnt.value, tmp: new Date().getTime() },
new Function('data', "var t = String(data).split('\\n'); var tmp = []; var i = 0; " +
"for (var a in t) { i++; tmp[a] = t[a]; if (i >= '"+ cnt._param['cacheMax'] +"') break; }" +
"document.getElementById('"+ cnt.id +"')._items = tmp; "+
"document.getElementById('"+ cnt.id +"')._controls.populate(document.getElementById('"+ cnt.id +"')); ") );
cnt._items_div.innerHTML = 'Loading...';
} else {
var html = '<ul>';
var i = 0;
for (var a in items) {
if (items[a] == '') continue;
var row = String(items[a]).split('|');
if (parseInt(cnt._param['showMax']) > i || !cnt._param) {
html += '<li class="'+ (i % 2 ? 'even' : 'odd')+ '"' +
' onclick="var el = document.getElementById(\''+ cnt.id +'\'); el.value = '+
(cnt._param && cnt._param['onSelect'] ? "el._param['onSelect'](String(el._items['"+ a +"']).split('|'), '"+ a +"')" : "el._items['"+ a +"']") +';'+
'el.hideItems(0);">'+
(cnt._param && cnt._param['onFormat'] ? cnt._param['onFormat'](row) : row[0]) +
'</li>';
}
i++;
}
html += '</ul>';
cnt._items_div.innerHTML = html;
cnt._count = i;
setTimeout("document.getElementById('"+ cnt.id +"')._items_div.scrollTop = '0px';", 1);
}
},

getCalendar: function (date, param) {
Expand Down Expand Up @@ -162,7 +257,7 @@ var jsControls2 = {
var weekDay = td.getDay();

var html =
'<table cellpadding="3" onclick = "window.clearTimeout(window._tmp_timeout); window._calendar_el.focus();" cellspacing="0">'+
'<table cellpadding="3" onclick = "window.clearTimeout(window._tmp_timeout); window._tmp_el.focus();" cellspacing="0">'+
' <tr><td colspan="7" align="center" class="title"> '+
' <b>'+ months[month-1] +', '+ year +'</b> </td></tr>'+
' <tr><td class="week_day">M</td> <td class="week_day">T</td> <td class="week_day">W</td>'+
Expand Down Expand Up @@ -205,7 +300,7 @@ var jsControls2 = {
noSelect = true;
}
if (noSelect === false) {
html += 'onclick = "window._calendar_el.value = \''+ dt +'\'; if(window._calendar_el.onchange) window._calendar_el.onchange();'+
html += 'onclick = "window._tmp_el.value = \''+ dt +'\'; if(window._tmp_el.onchange) window._tmp_el.onchange();'+
' event.stopPropagation(); return false;"'+
'onmouseover = "this._bgColor = this.style.backgroundColor; this.className = \''+ className +' day_hover\';"'+
'onmouseout = "this.style.backgroundColor = this._bgColor; this.className = \''+ className +'\';"';
Expand Down
14 changes: 9 additions & 5 deletions libs/jsEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ function jsEdit(name, box, recid) {
if (this.tabs[i].width == null) this.tabs[i].width = 100;
tabs_html += '<td style="width: '+ (parseInt(this.tabs[i].width)+3) +'px; padding: 0px; margin: 0px; font-weight: normal;">'+
' <div style="position: relative; top: -'+ (top.jsUtils.engine == 'WebKit' ? '10' : '11') +'px; padding: 0px; margin: 0px;">'+
' <div id="'+ this.name + '_tab'+ i +'" class="tab '+ (this.tabs[i].active ? 'tab_selected' : '') +'" style="position: absolute; margin: 0px; height: 20px; '+
' <div id="'+ this.name + '_tab'+ i +'" class="tab '+ (this.tabs[i].active ? 'tab_selected' : '') +'" style="position: absolute; margin: 0px; height: 25px; '+
' width: '+ parseInt(this.tabs[i].width) +'px; cursor: default;" '+
' onclick="top.elements[\''+ this.name +'\'].showTab('+ i +');">'+
this.tabs[i].caption+ '</div>'+
Expand Down Expand Up @@ -894,10 +894,14 @@ function jsEdit(name, box, recid) {
param[t[0]] = t[1];
}
}

if (this.srvFile.indexOf('?') > -1) { cchar = '&'; } else { cchar = '?'; }
req.src = this.srvFile + cchar + 'cmd=' + top.jsUtils.serialize(param) + '&' + Math.random();
this.box.ownerDocument.body.appendChild(req);
// populate data
if (typeof(this.srvFile) == 'function') {
this.srvFile(cmd, param);
} else {
if (this.srvFile.indexOf('?') > -1) { cchar = '&'; } else { cchar = '?'; }
req.src = this.srvFile + cchar + 'cmd=' + top.jsUtils.serialize(param) + '&' + Math.random();
this.box.ownerDocument.body.appendChild(req);
}
}

function jsEdit_validate() {
Expand Down
49 changes: 25 additions & 24 deletions libs/jsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,18 +553,16 @@ function jsList(name, box) {

// -- height of the _body
if (height > 0 && el) {
var newHeight = height
var newHeight = height - 2
- (this.showHeader ? 28 : 0)
- (this.showFooter ? 24 : 0)
- (this.showToolbar ? 30 : -2) // compensating for toolbar border
- (top.jsUtils.inArray(top.jsUtils.engine, ['IE5']) ? 2 : 7);
- (this.showToolbar ? 32 : 0)
- (this.showFooter ? 24 : 0);
if (newHeight < 0 ) newHeight = 0;
if (this.fixedSize) el.style.height = newHeight + 'px';
}
// -- width of the _body
if (width > 0 && el) {
var newWidth = width
- (top.jsUtils.inArray(top.jsUtils.engine, ['IE5']) ? 2 : 4);
var newWidth = width - 2
if (newWidth < 0) newWidth = 0;
// in FF4 - if width is set - it goes beyond borders
el.style.width = newWidth + 'px';
Expand All @@ -578,11 +576,11 @@ function jsList(name, box) {
if (elm) {
elm.style.display = 'block';
elm.style.overflow = 'auto';
var newHeight = height - 23
- (this.showHeader ? 28 : 0)
- (this.showFooter ? 24 : 0)
- (this.showToolbar ? 30 : -2) // compensating for toolbar border
- (top.jsUtils.inArray(top.jsUtils.engine, ['IE5']) ? 2 : 4);
var newHeight = height - 2
- (this.showHeader ? 28 : 0)
- (this.showToolbar ? 32 : 0)
- (this.showRecHeader ? 24 : 0)
- (this.showFooter ? 24 : 0)
elm.style.height = newHeight + 'px';
}
if (els) els.style.display = '';
Expand All @@ -597,23 +595,22 @@ function jsList(name, box) {
// -- Calculate Column size in PX
var dbody = this.box.ownerDocument.getElementById('body_'+ this.name);
if (dbody) {
var width_max = parseInt(dbody.clientWidth) - (this.columns.length + 1) * 7
- (bodyOverFlow ? 14 : -3)
- (top.jsUtils.engine == 'WebKit' ? -1 : 0)
- (this.showRecNumber ? 24 : 0);
var width_max = parseInt(dbody.clientWidth)
- (bodyOverFlow ? 17 : 0)
- (this.showRecNumber ? 23 : 0);
// assign PX columns
for (var i=0; i<this.columns.length; i++) {
var col = this.columns[i];
if (String(col.size).substr(String(col.size).length-2).toLowerCase() == 'px') {
width_max -= parseInt(col.size);
width_max -= parseInt(col.size) + 1; // count in cell border
this.columns[i].calculatedSize = col.size;
}
}
// calculate % columns
for (var i=0; i<this.columns.length; i++) {
var col = this.columns[i];
if (String(col.size).substr(String(col.size).length-2).toLowerCase() != 'px') {
this.columns[i].calculatedSize = (width_max * parseInt(col.size) / 100) + 'px';
this.columns[i].calculatedSize = (width_max * parseInt(col.size) / 100 - 1) + 'px'; // count in cell border
}
}
}
Expand Down Expand Up @@ -741,7 +738,7 @@ function jsList(name, box) {
'</div>\n';
}
if (this.showToolbar) {
html += '<div id="toolbar_'+ this.name +'" class="list_toolbar" style="height: 30px;"></div>';
html += '<div id="toolbar_'+ this.name +'" class="list_toolbar" style="height: 32px;"></div>';
}
html += '<div style="position: relative">'+
' <div style="margin-left: 22px; position: absolute; overflow: hidden; z-index: 100;">'+
Expand Down Expand Up @@ -1173,11 +1170,11 @@ function jsList(name, box) {
}
html += '<td id="'+ this.name +'_cell_header_'+ i +'" class="head" '+
' onclick="top.elements[\''+ this.name +'\'].columnClick('+ i +', event);" '+
' style="'+ sortStyle +'">'+
' style="'+ sortStyle +'; '+ (i == this.columns.length -1 ? 'border-right: 1px solid transparent;' : '') +'">'+
'<div style="cursor: default; width: '+ col.calculatedSize +'; overflow: hidden;">'+ col.caption +'<div></td>';
}
html += '<td id="hcell_'+ this.name +'" class="head" style="border-right: 0px; display: none;">'+
' <div style="width: 16px; overflow: hidden;">&nbsp;</div></td>';
' <div style="width: 2000px; overflow: hidden;">&nbsp;</div></td>';
html += '</tr>';
}
break;
Expand Down Expand Up @@ -1603,10 +1600,14 @@ function jsList(name, box) {
}
}
}
// generate and append SCRIPT tag
var req = this.box.ownerDocument.createElement('SCRIPT');
req.src = this.srvFile + (this.srvFile.indexOf('?') > -1 ? '&' : '?') + 'cmd=' + top.jsUtils.serialize(param) + '&rnd=' + Math.random();
this.box.ownerDocument.body.appendChild(req);
// populate data
if (typeof(this.srvFile) == 'function') {
this.srvFile(cmd, param);
} else {
var req = this.box.ownerDocument.createElement('SCRIPT');
req.src = this.srvFile + (this.srvFile.indexOf('?') > -1 ? '&' : '?') + 'cmd=' + top.jsUtils.serialize(param) + '&rnd=' + Math.random();
this.box.ownerDocument.body.appendChild(req);
}
}

function jsList_saveData() {
Expand Down
Loading

0 comments on commit 9514abb

Please sign in to comment.