var listLoadTimeCheck = 1; var saveForm = ''; function showlist(){ this.column = new Array(); this.where = new Array(); this.limitStart = 0; this.checkCookie = 1; this.search = 1; this.idField = 'id'; this.limitNum = ''; this.showPaging = 1; this.multilang = 0; this.cellId = ''; this.table = ''; this.order = ''; this.currentPage = 1; this.orderType = 'ASC'; this.width = '700'; this.searchKey = ''; this.showCaption = 1; this.showOwnerInfo = 0; this.listLevel = 0; this.fexibleCol = 1; this.emptyText = "No records."; this.extraWhere = ''; this.runAfterLoad = ''; this.isIE = false; this.isNS = false; this.version = null; this.Browser = Browser; this.listItems = listItems; this.generateSQL = generateSQL; this.addColumn = addColumn; this.activateLangEdit = activateLangEdit; this.pagingMenu = pagingMenu; this.openChildren = openChildren; this.getFullLevel = getFullLevel; this.getOwnerInfo = getOwnerInfo; this.printownerInfo = printownerInfo; this.ordera2z = new Image(); this.ordera2z.src = '../images/a2z.gif'; this.orderz2a = new Image(); this.orderz2a.src = '../images/z2a.gif'; this.activeImg = new Image(); this.activeImg.src = '../images/active.gif'; this.inActiveImg = new Image(); this.inActiveImg.src = '../images/inactive.gif'; this.saveImg = new Image(); this.saveImg.src = '../images/save.gif'; this.editImg = new Image(); this.editImg.src = '../images/edit.gif'; this.delImg = new Image(); this.delImg.src = '../images/delete.gif'; this.emptyImg = new Image(); this.emptyImg.src = '../images/empty.gif'; } function addColumn(columnArr){ var newIndex = this.column.length; this.column[newIndex] = new Array(); for(key in columnArr){ this.column[newIndex][key] = columnArr[key]; } } function listItems(){ this.Browser(); if(listLoadTimeCheck) { var pageCookie = getCookie('cookie_' + this.table + '_page'); var limitCookie = getCookie('cookie_' + this.table + '_limitnum'); if(limitCookie){ this.limitNum = limitCookie; if(pageCookie){ var startCookie = (pageCookie - 1) * limitCookie; this.limitStart = startCookie; } } } showStatus(); this.search = (this.showPaging==1) ? this.search : 0; this.generateSQL(); } function generateSQL(){ var ajaxVar = new ajaxVars(); ajaxVar.vars['sql_type'] = "select"; ajaxVar.vars['sql_what'] = this.idField; for(var col=0; col= 0) { ajaxVar.vars['sql_where'] += ' and ' + wkey + '=' + this.where[wkey] + ' '; }else{ ajaxVar.vars['sql_where'] += ' and ' + wkey + '=' + "'" + this.where[wkey] + "'"; } } if(this.extraWhere != ''){ ajaxVar.vars['sql_where'] += ' ' + this.extraWhere + ' '; } if(this.searchKey != ''){ if(this.currentCell) { var cellInfoArr = colInfo(this.currentCell.id); ajaxVar.vars['sql_where'] += " having " + cellInfoArr['col'] + ' like "%' + this.searchKey + '%" '; } } ajaxVar.vars['sql_order'] = this.order + ' ' + this.orderType; if(this.showPaging){ ajaxVar.vars['sql_limit'] = 'limit ' + this.limitStart + ', ' + this.limitNum; } ajaxVar.vars['action'] = "db_fetch_array"; ajaxVar.gotoFunction = 'createList'; ajaxVar.fnVars = this; ajaxVar.AjaxPostSQL(); } function delConfirm(){ var cnf = confirm("You are about to delete a record. Continue?"); return cnf; } function postConfirm(event,cellId){ var cnf = confirm("You are about to change the post settings of this record. Continue?"); if (cnf) { changePost(event,cellId); }else { return false; } } function colInfo(cellId){ var colInfo = new Array(); colInfo['table'] = cellId.split(/_id_/g)[0]; colInfo['id'] = cellId.split(/_id_/g)[1].split(/_col_/g)[0]; colInfo['col'] = cellId.split(/_id_/g)[1].split(/_col_/g)[1]; return colInfo; } function getFullLevel(colObj, level) { var tableCell = colObj.parentNode.parentNode.parentNode.parentNode; if(tableCell) { var newLevel = parseInt(level,10) + parseInt(tableCell.cellIndex, 10); if(tableCell.cellIndex == 0){ this.listLevel = newLevel; }else{ this.getFullLevel(tableCell, newLevel); } } } function createList(dataArr, orgObj){ var bodyObj = document.getElementsByTagName('body')[0]; var draggerObj = document.getElementById('draggerdiv'); if(draggerObj){ }else{ var draggerObj = document.createElement('DIV'); draggerObj.id = 'draggerdiv'; draggerObj.style.position = 'absolute'; bodyObj.appendChild(draggerObj); } if(draggerObj){ draggerObj.style.visibility = 'hidden'; draggerObj.style.position = 'absolute'; draggerObj.listObj = orgObj; } var contObj = document.getElementById(orgObj.cellId); contObj.listObj = orgObj; contObj.innerHTML = ''; var listTable = document.createElement('TABLE'); listTable.onselectstart = function(e) { return false }; listTable.border = 0; listTable.id = 'listTable_' + orgObj.cellId; listTable.cellSpacing = 0; listTable.cellPadding = 0; var listTBody = document.createElement('TBODY'); listTable.appendChild(listTBody); contObj.appendChild(listTable); if(orgObj.showCaption) { var rowObj = listTBody.insertRow(listTBody.rows.length); for(var col=0; col1) { cellText = ""; } if(orgObj.column[col]['css']) colObj.className = orgObj.column[col]['css']; var newWidth = 0; if(col == listItem.fexibleCol) { newWidth = parseInt(orgObj.listLevel,0) * parseInt(orgObj.column[0]['width'], 0); if(i==0) { orgObj.width = orgObj.width - newWidth; listTable.width = orgObj.width; } } if(orgObj.column[col]['width']) colObj.width = orgObj.column[col]['width'] - newWidth; if(orgObj.column[col]['align']) colObj.align = orgObj.column[col]['align']; if(orgObj.column[col]['valign']) colObj.valign = orgObj.column[col]['valign']; if(orgObj.column[col]['height']) colObj.height = orgObj.column[col]['height']; if(orgObj.column[col]['search'] && orgObj.search){ colObj.listObj = orgObj; colObj.onclick = function(e){ showHideDiv('searchDv', 1); this.style.border = "1px dotted #555"; var fldObj = document.getElementById('searchtxt'); if(fldObj) { fldObj.focus(); fldObj.listObj = orgObj; fldObj.onkeydown = function(e){ var unicode=e.keyCode? e.keyCode : e.charCode; switch(unicode){ case 13: this.listObj.searchKey = this.value; this.listObj.limitStart = 0; this.listObj.listItems(); break; } } } if(this.listObj.currentCell) if(this.listObj.currentCell.id != this.id) { this.listObj.currentCell.style.border = "0px solid #FFF"; this.listObj.currentCell.style.borderBottom = "1px solid #FFF"; } this.listObj.currentCell = this; } } if(orgObj.column[col]['jsEvent']){ colObj.column = orgObj.column[col]; colObj.rowNum = i; colObj.isIE = orgObj.isIE; colObj[orgObj.column[col]['jsEvent']] = function(e){ if(this.column['jsFunc'] != 'delConfirm'){ if(this.isIE == true){ var e = true; } if(this.column['jsParam']) { eval(this.column['jsFunc'] + "(e, '" + this.id + "', '" + this.column['jsParam'] + "')"); }else{ eval(this.column['jsFunc'] + "(e, '" + this.id + "')"); } } }; } if(orgObj.column[col]['url'].length>1) { var aCell = document.createElement('A'); var url = orgObj.column[col]['url']; var fixJsVar = url.match(/({(.+?)})/g); if(fixJsVar) { for(h=0; h 0) { colObj.title = dataArr[orgObj.column[col]['orderField']][i]; } } } orgObj.openChildren(); if(orgObj.multilang){ orgObj.activateLangEdit(); } if(orgObj.showPaging){ orgObj.pagingMenu(dataArr); } if(orgObj.showOwnerInfo){ orgObj.getOwnerInfo(); } if(orgObj.runAfterLoad){ eval(orgObj.runAfterLoad); } }else{ contObj.className = 'listCell'; if(orgObj.emptyText) { contObj.innerHTML = "

  " + orgObj.emptyText + "

"; }else{ contObj.innerHTML = " "; } } listLoadTimeCheck = 0; hideStatus(); } function openChildren(){ var cookieVar = 'cookie_' + this.table + '_open'; var cookieVal = getCookie(cookieVar); if(cookieVal){ var cellArr = cookieVal.split('|'); for(i=0; i= 0){ var cellId = cellArr[i] + '_col_' + this.column[0]['txtIndex']; var cellObj = document.getElementById(cellId); if(cellObj) { execChild('',cellId); } } } } } function activateLangEdit(){ var ajaxVar = new ajaxVars(); ajaxVar.vars['sql_type'] = "select"; ajaxVar.vars['sql_what'] = "t.id, t.general_id, l.lang_code, t.active"; ajaxVar.vars['sql_from'] = this.table + ' as t left join languages as l on(t.lang_id=l.id)'; ajaxVar.vars['sql_where'] = '1 and t.general_id>0'; ajaxVar.vars['action'] = "db_fetch_array"; ajaxVar.gotoFunction = 'activateLangEditList'; ajaxVar.fnVars = this; showStatus(); ajaxVar.AjaxPostSQL(); } function activateLangEditList(dataArr, orgObj){ if(dataArr['id']) { for(var i=0; i dataArr[0][0]) ? dataArr[0][0] : StopRec; StartRec++; statusObj.innerHTML = 'Showing record from ' ; if(StartRec == StopRec) { statusObj.innerHTML += StartRec; }else { statusObj.innerHTML += StartRec + ' to ' + StopRec; } statusObj.innerHTML += ' of ' + dataArr[0][0]; var pageNum = parseInt(dataArr[0][0],10)/parseInt(this.limitNum,10); var currentPage = StartRec/parseInt(this.limitNum,10); this.currentPage = Math.ceil(currentPage); statusObj.innerHTML += ' | page ' + Math.ceil(currentPage) + ' of ' + Math.ceil(pageNum); var colObj = rowObj.insertCell(rowObj.cells.length); var pageSelObj = document.createElement('SELECT'); pageSelObj.style.textAlign = 'right'; pageSelObj.style.border = "1px solid #CCC"; pageSelObj.style.width = "100%"; for(var i=0; i this.totalNum){ alert("You are already on last page"); }else{ this.listObj.limitStart = tmplimitStart; this.listObj.listItems(); } } nextObj.appendChild(nbuttonObj); var lastObj = rowObj.insertCell(rowObj.cells.length); lastObj.width = '12%'; var lbuttonObj = document.createElement('input'); lbuttonObj.type = 'button'; // lbuttonObj.value = 'Last >|'; lbuttonObj.value = '>>|'; lbuttonObj.listObj = this; lbuttonObj.style.width = '100%'; lbuttonObj.className = 'last'; lbuttonObj.totalNum = dataArr[0][0]; lbuttonObj.onclick = function(e){ var remainder = this.totalNum % parseInt(this.listObj.limitNum,10); var newStart = lbuttonObj.totalNum - remainder; if((this.listObj.limitStart == newStart) || (newStart == this.totalNum)){ alert("You are already on last page"); }else{ this.listObj.limitStart = newStart; this.listObj.listItems(); } } lastObj.appendChild(lbuttonObj); cellObj.insertBefore(pagingTable,cellObj.firstChild); document.cookie = 'cookie_' + this.table + '_page='+this.currentPage+'; path=/'; document.cookie = 'cookie_' + this.table + '_limitnum='+this.limitNum+'; path=/'; var fldObj = document.getElementById('searchtxt'); fldObj.value = this.searchKey; showHideDiv('searchDv'); } function changeStatus(event, cellId){ showStatus(); var colArr = colInfo(cellId); var ajaxVar = new ajaxVars(); if(document.getElementById(cellId).innerHTML.indexOf('inactive.gif') > 1){ ajaxVar.vars['active'] = "1"; }else{ ajaxVar.vars['active'] = "0"; } ajaxVar.vars['id'] = colArr['id']; ajaxVar.vars['table'] = colArr['table']; ajaxVar.vars['action'] = "modify"; ajaxVar.gotoFunction = 'statusChanged'; ajaxVar.fnVars['cellid'] = cellId; ajaxVar.dbVars = "active"; ajaxVar.AjaxPostSQL(); } function changePost(event, cellId){ showStatus(); var colArr = colInfo(cellId); var ajaxVar = new ajaxVars(); if(document.getElementById(cellId).innerHTML.indexOf('icon_unposted.png') > 1){ ajaxVar.vars['post'] = "1"; }else{ ajaxVar.vars['post'] = "0"; } ajaxVar.vars['id'] = colArr['id']; ajaxVar.vars['table'] = colArr['table']; ajaxVar.vars['action'] = "modify"; ajaxVar.gotoFunction = 'postChanged'; ajaxVar.fnVars['cellid'] = cellId; ajaxVar.dbVars = "post"; ajaxVar.AjaxPostSQL(); } function applySaveBeforeGo(formName){ saveForm = formName; var aTags = document.getElementsByTagName('A'); for(var i=0; i 1) && (aTags[i].href.indexOf('#') < 0)) { if(aTags[i].onclick) { aTags[i].oldClick = aTags[i].onclick; aTags[i].onclick = function(e){ this.oldClick(); saveBeforeGo(this); }; }else{ aTags[i].onclick = function(e){ saveBeforeGo(this); }; } } } } function saveBeforeGo(aObj){ if(saveForm != '') { var tmpHref = aObj.href; if(tmpHref.indexOf('#') < 0) { var cnf = confirm('Click "OK" to save changes, or "Cancel" to exit without saving.'); if(cnf) { aObj.href = '#'; location.href = '#'; var formObj = eval('document.' + saveForm); var saveUrlObj = eval('document.' + saveForm + '.saveurl'); if(saveUrlObj){ saveUrlObj.value = tmpHref; } if(formObj){ formObj.submit(); } }else{ location.href = tmpHref; } } } } function statusChanged(dataArr, fnVars){ hideStatus(); var cellInner = document.getElementById(fnVars['cellid']).innerHTML; if(dataArr['active'][0] == 1){ cellInner = cellInner.replace(/inactive/g, 'active'); document.getElementById(fnVars['cellid']).innerHTML = cellInner; }else{ cellInner = cellInner.replace(/active/g, 'inactive'); document.getElementById(fnVars['cellid']).innerHTML = cellInner; } } function postChanged(dataArr, fnVars){ hideStatus(); var cellInner = document.getElementById(fnVars['cellid']).innerHTML; if(dataArr['post'][0] == 1){ cellInner = cellInner.replace(/icon_unposted/g, 'icon_posted'); document.getElementById(fnVars['cellid']).innerHTML = cellInner; }else{ cellInner = cellInner.replace(/icon_posted/g, 'icon_unposted'); document.getElementById(fnVars['cellid']).innerHTML = cellInner; } } function getOwnerInfo(){ var ajaxVar = new ajaxVars(); ajaxVar.vars['action'] = "runFunction"; ajaxVar.vars['func'] = "owner_info"; ajaxVar.vars['args'] = this.table + ',0, 1'; ajaxVar.gotoFunction = 'printownerInfo'; ajaxVar.fnVars = this; ajaxVar.AjaxPostSQL(); } function printownerInfo(data, orgObj){ var divObj = document.getElementById(orgObj.cellId); var ownerDivObj = document.createElement('DIV'); ownerDivObj.innerHTML = data; ownerDivObj.style.width = parseInt(divObj.offsetWidth - 30) + 'px'; ownerDivObj.style.verticalAlign = "bottom"; divObj.appendChild(ownerDivObj); } function test(){ listItem = new showlist(); listItem.column[0] = new Array(); listItem.column[0]['title'] = 'Language'; listItem.column[0]['width'] = '100%'; listItem.column[0]['sql'] = 'name'; listItem.column[0]['txtIndex'] = 'name'; listItem.column[0]['numIndex'] = '1'; listItem.column[0]['order'] = 1; listItem.column[0]['orderField'] = 'name'; listItem.column[0]['url'] = '#'; listItem.column[0]['target'] = '_blank'; listItem.column[0]['css'] = 'caption'; listItem.column[0]['image'] = ''; listItem.column[0]['jsEvent'] = ''; listItem.column[0]['jsFunc'] = ''; listItem.table = 'languages'; listItem.cellId = 'listlanguages'; // listItem.where['field'] = 'value'; listItem.order = 'name'; listItem.width = '100%'; listItem.orderType = 'ASC'; listItem.listItems(); }