From aeb464ddd50f008757f3a5b80cfec82da793edac Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Sat, 30 Apr 2011 17:54:52 +0000 Subject: [PATCH] Delete files that were moved to minsrc git-svn-id: svn://svn.code.sf.net/p/openrico/code/trunk/rico3@75 53df2df2-7ab5-4331-af62-ea79255fa4e2 --- ricoClient/js/ricoCalendar.js | 569 ------ ricoClient/js/ricoColorPicker.js | 112 -- ricoClient/js/ricoDragDrop.js | 578 ------ ricoClient/js/ricoGridCommon.js | 989 ---------- ricoClient/js/ricoLiveGrid.js | 2433 ------------------------- ricoClient/js/ricoLiveGridAjax.js | 576 ------ ricoClient/js/ricoLiveGridControls.js | 424 ----- ricoClient/js/ricoLiveGridForms.js | 1129 ------------ ricoClient/js/ricoLiveGridMenu.js | 141 -- ricoClient/js/ricoSearch.js | 135 -- ricoClient/js/ricoSimpleGrid.js | 403 ---- ricoClient/js/ricoTree.js | 326 ---- ricoClient/js/ricoUI.js | 1389 -------------- 13 files changed, 9204 deletions(-) delete mode 100644 ricoClient/js/ricoCalendar.js delete mode 100644 ricoClient/js/ricoColorPicker.js delete mode 100644 ricoClient/js/ricoDragDrop.js delete mode 100644 ricoClient/js/ricoGridCommon.js delete mode 100644 ricoClient/js/ricoLiveGrid.js delete mode 100644 ricoClient/js/ricoLiveGridAjax.js delete mode 100644 ricoClient/js/ricoLiveGridControls.js delete mode 100644 ricoClient/js/ricoLiveGridForms.js delete mode 100644 ricoClient/js/ricoLiveGridMenu.js delete mode 100644 ricoClient/js/ricoSearch.js delete mode 100644 ricoClient/js/ricoSimpleGrid.js delete mode 100644 ricoClient/js/ricoTree.js delete mode 100644 ricoClient/js/ricoUI.js diff --git a/ricoClient/js/ricoCalendar.js b/ricoClient/js/ricoCalendar.js deleted file mode 100644 index c0d5721..0000000 --- a/ricoClient/js/ricoCalendar.js +++ /dev/null @@ -1,569 +0,0 @@ -/* - * (c) 2005-2009 Richard Cowin (http://openrico.org) - * (c) 2005-2009 Matt Brown (http://dowdybrown.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this - * file except in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the - * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions - * and limitations under the License. - */ - -// Inspired by code originally written by Tan Ling Wee on 2 Dec 2001 -// Requires prototype.js and ricoCommon.js - -Rico.CalendarControl = function(id,options) { - this.initialize(id,options); -}; - -Rico.CalendarControl.prototype = { -/** - * @class Implements a pop-up Gregorian calendar. - * Dates of adoption of the Gregorian calendar vary by country - accurate as a US & British calendar from 14 Sept 1752 to present. - * Mark special dates with calls to addHoliday() - * @extends Rico.Popup - * @constructs - * @param id unique identifier - * @param options object may contain any of the following:
- *
startAt
week starts with 0=sunday, 1=monday? default=0
- *
showWeekNumber
show week number in first column? default=0
- *
showToday
show "Today is..." in footer? default=1
- *
repeatInterval
when left/right arrow is pressed, repeat action every x milliseconds, default=100
- *
dateFmt
date format for return value (one of values accepted by {@link Date#formatDate}), default=ISO8601
- *
minDate
earliest selectable date? default=today-50 years
- *
maxDate
last selectable date? default=today+50 years
- *
- */ - initialize: function(id,options) { - this.id=id; - var today=new Date(); - Rico.extend(this, new Rico.Popup()); - Rico.extend(this.options, { - ignoreClicks:true, - startAt : 0, - showWeekNumber : 0, - showToday : 1, - repeatInterval : 100, - dateFmt : 'ISO8601', - minDate : new Date(today.getFullYear()-50,0,1), - maxDate : new Date(today.getFullYear()+50,11,31) - }); - Rico.extend(this.options, options || {}); - /** - * alias for closePopup - * @function - */ - this.close=this.closePopup; - this.bPageLoaded=false; - this.img=[]; - this.Holidays={}; - this.weekString=Rico.getPhraseById("calWeekHdg"); - this.re=/^\s*(\w+)(\W)(\w+)(\W)(\w+)/i; - this.setDateFmt(this.options.dateFmt); - }, - - - setDateFmt: function(fmt) { - this.dateFmt=(fmt=='rico') ? Rico.dateFmt : fmt; - Rico.log(this.id+' date format set to '+this.dateFmt); - this.dateParts={}; - if (this.re.exec(this.dateFmt)) { - this.dateParts[RegExp.$1]=0; - this.dateParts[RegExp.$3]=1; - this.dateParts[RegExp.$5]=2; - } - }, - -/** - * Call before displaying calendar to highlight special days - * @param d day (1-31) - * @param m month (1-12) - * @param y year (0 implies a repeating holiday) - * @param desc description - * @param bgColor background color for cell displaying this day (CSS value, defaults to '#DDF') - * @param txtColor text color for cell displaying this day (CSS value), if not specified it is displayed with the same color as other days - */ - addHoliday : function(d, m, y, desc, bgColor, txtColor) { - this.Holidays[this.holidayKey(y,m-1,d)]={desc:desc, txtColor:txtColor, bgColor:bgColor || '#DDF'}; - }, - -/** @private */ - holidayKey : function(y,m,d) { - return 'h'+Rico.zFill(y,4)+Rico.zFill(m,2)+Rico.zFill(d,2); - }, - - atLoad : function() { - Rico.log('Calendar#atLoad: '+this.id); - this.createContainer(); - this.container.id=this.id; - //this.container.style.width="auto"; - this.content.className=Rico.theme.calendar || 'ricoCalContainer'; - - this.maintab=document.createElement("table"); - this.maintab.cellSpacing=2; - this.maintab.cellPadding=0; - this.maintab.border=0; - this.maintab.style.borderCollapse='separate'; - this.maintab.className='ricoCalTab'; - if (Rico.theme.calendarTable) Rico.addClass(this.maintab,Rico.theme.calendarTable) - this.tbody=Rico.getTBody(this.maintab); - - var r,c,d,i,j,img,dow,a,s,tab; - this.colStart=this.options.showWeekNumber ? 1 : 0; - for (i=0; i<7; i++) { - r=this.tbody.insertRow(-1); - r.className='row'+i; - for (c=0; c<7+this.colStart; c++) { - r.insertCell(-1); - } - } - r=this.tbody.rows[0]; - r.className='ricoCalDayNames'; - if (this.options.showWeekNumber) { - r.cells[0].innerHTML=this.weekString; - for (i=0; i<7; i++) { - this.tbody.rows[i].cells[0].className='ricoCalWeekNum'; - } - } - this.styles=[]; - for (i=0; i<7; i++) { - dow=(i+this.options.startAt) % 7; - r.cells[i+this.colStart].innerHTML=Rico.dayAbbr(dow); - this.styles[i]='ricoCal'+dow; - } - - // table header (navigation controls) - this.thead=this.maintab.createTHead(); - r=this.thead.insertRow(-1); - c=r.appendChild(document.createElement("th")); - c.colSpan=7+this.colStart; - d=c.appendChild(document.createElement("div")); - //d.style.padding='3px'; - d.className=Rico.theme.calendarHeading || 'RicoCalHeading'; - - d.appendChild(this._createTitleSection('Month')); - d.appendChild(this._createTitleSection('Year')); - new Rico.HoverSet(d.getElementsByTagName('a')); - new Rico.HoverSet(this.tbody.getElementsByTagName('td'),{ hoverNodes: function(e) { return e.innerHTML.match(/^\d+$/) ? [e] : []; } }); - d.appendChild(Rico.closeButton(Rico.eventHandle(this,'close'))); - - // table footer (today) - if (this.options.showToday) { - this.tfoot=this.maintab.createTFoot(); - r=this.tfoot.insertRow(-1); - this.todayCell=r.insertCell(-1); - this.todayCell.colSpan=7+this.colStart; - if (Rico.theme.calendarFooter) Rico.addClass(this.todayCell,Rico.theme.calendarFooter); - Rico.eventBind(this.todayCell,"click", Rico.eventHandle(this,'selectNow'), false); - } - this.content.appendChild(this.maintab); - var ie6=Rico.isIE && Rico.ieVersion < 7; - var selectOptions={shadow: !ie6}; - - // month selector - this.monthPopup=new Rico.Popup(document.createElement("div"),selectOptions); - this.monthPopup.closePopup(); - tab=document.createElement("table"); - tab.className='ricoCalMenu'; - if (Rico.theme.calendarPopdown) Rico.addClass(tab,Rico.theme.calendarPopdown); - tab.cellPadding=2; - tab.cellSpacing=0; - tab.border=0; - tab.style.borderCollapse='separate'; - tab.style.margin='0px'; - for (i=0; i<4; i++) { - r=tab.insertRow(-1); - for (j=0; j<3; j++) { - c=r.insertCell(-1); - a=document.createElement("a"); - a.innerHTML=Rico.monthAbbr(i*3+j); - a.name=i*3+j; - if (Rico.theme.calendarDay) Rico.addClass(a,Rico.theme.calendarDay); - c.appendChild(a); - Rico.eventBind(a,"click", Rico.eventHandle(this,'selectMonth'), false); - } - } - new Rico.HoverSet(tab.getElementsByTagName('a')); - this.monthPopup.content.appendChild(tab); - this.content.appendChild(this.monthPopup.container); - - // year selector - this.yearPopup=new Rico.Popup(document.createElement("div"),selectOptions); - this.yearPopup.closePopup(); - this.yearPopup.content.className='ricoCalYearPrompt'; - if (Rico.theme.calendarPopdown) Rico.addClass(this.yearPopup.content,Rico.theme.calendarPopdown); - var tab=document.createElement("table"); - tab.cellPadding=2; - tab.cellSpacing=0; - tab.border=0; - tab.style.borderCollapse='separate'; - tab.style.margin='0px'; - r=tab.insertRow(-1); - this.yearLabel=r.insertCell(-1); - this.yearLabel.colSpan=3; - r=tab.insertRow(-1); - c=r.insertCell(-1); - this.yearInput=c.appendChild(document.createElement("input")); - this.yearInput.maxlength=4; - this.yearInput.size=4; - Rico.eventBind(this.yearInput,"keypress", Rico.eventHandle(this,'yearKey'), false); - c=r.insertCell(-1); - c.appendChild(Rico.floatButton('Checkmark', Rico.eventHandle(this,'processPopUpYear'))); - c=r.insertCell(-1); - c.appendChild(Rico.floatButton('Cancel', Rico.eventHandle(this,'popDownYear'))); - this.yearPopup.content.appendChild(tab); - this.content.appendChild(this.yearPopup.container); - - //this.yearLabel.className='ricoCalYearPromptText'; - - // fix anchors so they work in IE6 - a=this.content.getElementsByTagName('a'); - for (i=0; i this.options.maxDate.getFullYear()) return false; - if (yr == this.options.maxDate.getFullYear() && mo > this.options.maxDate.getMonth()) return false; - return true; - }, - - incMonth : function() { - var newMonth=this.monthSelected+1; - var newYear=this.yearSelected; - if (newMonth>11) { - newMonth=0; - newYear++; - } - if (!this.isValidMonth(newYear,newMonth)) return; - this.monthSelected=newMonth; - this.yearSelected=newYear; - this.constructCalendar(); - }, - - decMonth : function() { - var newMonth=this.monthSelected-1; - var newYear=this.yearSelected; - if (newMonth<0) { - newMonth=11; - newYear--; - } - if (!this.isValidMonth(newYear,newMonth)) return; - this.monthSelected=newMonth; - this.yearSelected=newYear; - this.constructCalendar(); - }, - -/** @private */ - selectMonth : function(e) { - var el=Rico.eventElement(e); - this.monthSelected=parseInt(el.name,10); - this.constructCalendar(); - Rico.eventStop(e); - }, - - popUpMonth : function() { - if (this.monthPopup.visible()) { - this.popDownMonth(); - return; - } - this.popDownYear(); - this.monthPopup.openPopup(this.titleMonth.parentNode.offsetLeft, this.thead.offsetHeight+2); - }, - - popDownMonth : function() { - this.monthPopup.closePopup(); - }, - - popDownYear : function() { - this.yearPopup.closePopup(); - this.yearInput.disabled=true; // make sure this does not get submitted - }, - -/** - * Prompt for year - */ - popUpYear : function() { - if (this.yearPopup.visible()) { - this.popDownYear(); - return; - } - this.popDownMonth(); - this.yearPopup.openPopup(90, this.thead.offsetHeight+2); - this.yearLabel.innerHTML=Rico.getPhraseById("calYearRange",this.options.minDate.getFullYear(),this.options.maxDate.getFullYear()); - this.yearInput.disabled=false; - this.yearInput.value=''; // this.yearSelected - this.yearInput.focus(); - }, - - yearKey : function(e) { - switch (Rico.eventKey(e)) { - case 27: this.popDownYear(); Rico.eventStop(e); return false; - case 13: this.processPopUpYear(); Rico.eventStop(e); return false; - } - return true; - }, - - processPopUpYear : function() { - var newYear=this.yearInput.value; - newYear=parseInt(newYear,10); - if (isNaN(newYear) || newYearthis.options.maxDate.getFullYear()) { - alert(Rico.getPhraseById("calInvalidYear")); - } else { - this.yearSelected=newYear; - this.popDownYear(); - this.constructCalendar(); - } - }, - - incYear : function() { - if (this.yearSelected>=this.options.maxDate.getFullYear()) return; - this.yearSelected++; - this.constructCalendar(); - }, - - decYear : function() { - if (this.yearSelected<=this.options.minDate.getFullYear()) return; - this.yearSelected--; - this.constructCalendar(); - }, - - // tried a number of different week number functions posted on the net - // this is the only one that produced consistent results when comparing week numbers for December and the following January - WeekNbr : function(year,month,day) { - var when = new Date(year,month,day); - var newYear = new Date(year,0,1); - var offset = 7 + 1 - newYear.getDay(); - if (offset == 8) offset = 1; - var daynum = ((Date.UTC(year,when.getMonth(),when.getDate(),0,0,0) - Date.UTC(year,0,1,0,0,0)) /1000/60/60/24) + 1; - var weeknum = Math.floor((daynum-offset+7)/7); - if (weeknum == 0) { - year--; - var prevNewYear = new Date(year,0,1); - var prevOffset = 7 + 1 - prevNewYear.getDay(); - weeknum = (prevOffset == 2 || prevOffset == 8) ? 53 : 52; - } - return weeknum; - }, - - constructCalendar : function() { - var aNumDays = [31,0,31,30,31,30,31,31,30,31,30,31]; - var startDate = new Date (this.yearSelected,this.monthSelected,1); - var endDate,numDaysInMonth,i,colnum; - - if (typeof this.monthSelected!='number' || this.monthSelected>=12 || this.monthSelected<0) { - alert('ERROR in calendar: monthSelected='+this.monthSelected); - return; - } - - if (this.monthSelected==1) { - endDate = new Date (this.yearSelected,this.monthSelected+1,1); - endDate = new Date (endDate - (24*60*60*1000)); - numDaysInMonth = endDate.getDate(); - } else { - numDaysInMonth = aNumDays[this.monthSelected]; - } - var dayPointer = startDate.getDay() - this.options.startAt; - if (dayPointer<0) dayPointer+=7; - this.popDownMonth(); - this.popDownYear(); - - //this.bgcolor=Rico.getStyle(this.tbody,'background-color'); - //this.bgcolor=this.bgcolor.replace(/\"/g,''); - if (this.options.showWeekNumber) { - for (i=1; i<7; i++) { - this.tbody.rows[i].cells[0].innerHTML=' '; - } - } - for ( i=0; i maxyr) this.oyearSelected-=100; - } - } else { - if (curval) { - alert('ERROR: invalid date passed to calendar ('+curval+')'); - } - } - if (this.oyearSelected > 0) { - this.dateSelected=this.odateSelected; - this.monthSelected=this.omonthSelected; - this.yearSelected=this.oyearSelected; - } else { - this.dateSelected=this.dateNow; - this.monthSelected=this.monthNow; - this.yearSelected=this.yearNow; - } - this.constructCalendar(); - this.openPopup(); - } -}; - -Rico.includeLoaded('ricoCalendar.js'); diff --git a/ricoClient/js/ricoColorPicker.js b/ricoClient/js/ricoColorPicker.js deleted file mode 100644 index a1e64c3..0000000 --- a/ricoClient/js/ricoColorPicker.js +++ /dev/null @@ -1,112 +0,0 @@ -/* - * (c) 2005-2009 Richard Cowin (http://openrico.org) - * (c) 2005-2009 Matt Brown (http://dowdybrown.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this - * file except in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the - * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions - * and limitations under the License. - */ - -// =================================================================== -// Adapted to Rico by Matt Brown from code -// published by Matt Kruse http://www.mattkruse.com/ -// =================================================================== - -Rico.ColorPicker = function(id,options) { - this.initialize(id,options); -}; - -Rico.ColorPicker.prototype = { -/** - * @class Implements a pop-up color picker control. - * @extends Rico.Popup - * @constructs - * @param id unique identifier - * @param options object may contain any of the following:
- *
showColorCode
show hex color code as user hovers over color grid? default=false
- *
cellsPerRow
number of colors per row in the grid? default=18
- *
palette
array of 6 digit hex values, default=216 "web safe" colors
- *
- */ - initialize: function(id,options) { - this.id=id; - this.currentValue = "#FFFFFF"; - Rico.extend(this, new Rico.Popup()); - Rico.extend(this.options, { - showColorCode : false, - cellsPerRow : 18, - palette : [] - }); - var hexvals=['00','33','66','99','CC','FF']; - for (var g=0; g '; - if ( ((i+1)>=this.options.palette.length) || (((i+1) % width) == 0)) { - cp_contents += ""; - } - } - var halfwidth = Math.floor(width/2); - if (this.options.showColorCode) { - cp_contents += " #FFFFFF"; - } else { - cp_contents += " "; - } - cp_contents += ""; - this.content.innerHTML=cp_contents; - /** - * alias for openPopup - * @function - */ - this.open=this.openPopup; - /** - * alias for closePopup - * @function - */ - this.close=this.closePopup; - Rico.eventBind(this.container,"mouseover", Rico.eventHandle(this,'highlightColor'), false); - Rico.eventBind(this.container,"click", Rico.eventHandle(this,'selectColor'), false); - this.close(); - }, - -/** @private */ - selectColor: function(e) { - Rico.eventStop(e); - if (this.returnValue) this.returnValue(this.currentValue); - this.close(); - }, - -/* This function runs when you move your mouse over a color block */ -/** @private */ - highlightColor: function(e) { - var elem = Rico.eventElement(e); - if (!elem.tagName || elem.tagName.toLowerCase() != 'td') return; - var c=Rico.Color.createColorFromBackground(elem).toString(); - this.currentValue = c; - Rico.setStyle('colorPickerSelectedColor', {backgroundColor:c}); - var d = Rico.$("colorPickerSelectedColorValue"); - if (d) d.innerHTML = c; - } -}; - -Rico.includeLoaded('ricoColorPicker.js'); diff --git a/ricoClient/js/ricoDragDrop.js b/ricoClient/js/ricoDragDrop.js deleted file mode 100644 index e0f8bc6..0000000 --- a/ricoClient/js/ricoDragDrop.js +++ /dev/null @@ -1,578 +0,0 @@ -/* - * (c) 2005-2009 Richard Cowin (http://openrico.org) - * (c) 2005-2009 Matt Brown (http://dowdybrown.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this - * file except in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the - * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions - * and limitations under the License. - */ - -Rico.dndMgrList = []; - -Rico.registerDraggable = function(aDraggable, mgrIdx) { - if (typeof mgrIdx != 'number') mgrIdx=0; - if (typeof Rico.dndMgrList[mgrIdx] != 'object') - Rico.dndMgrList[mgrIdx] = new Rico.dndMgr(); - Rico.dndMgrList[mgrIdx].registerDraggable(aDraggable); -}; - -Rico.registerDropZone = function(aDropZone, mgrIdx) { - if (typeof mgrIdx != 'number') mgrIdx=0; - if (typeof Rico.dndMgrList[mgrIdx] != 'object') - Rico.dndMgrList[mgrIdx] = new Rico.dndMgr(); - Rico.dndMgrList[mgrIdx].registerDropZone(aDropZone); -}; - -Rico.dndMgr = function() { - this.initialize(); -}; - -Rico.dndMgr.prototype = { -/** - * @class Implements drag-n-drop manager -- a group of linked draggables and drop zones - * @constructs - */ - initialize: function() { - this.dropZones = []; - this.draggables = []; - this.currentDragObjects = []; - this.dragElement = null; - this.lastSelectedDraggable = null; - this.currentDragObjectVisible = false; - this.interestedInMotionEvents = false; - this._mouseDown = Rico.eventHandle(this,'_mouseDownHandler'); - this._mouseMove = Rico.eventHandle(this,'_mouseMoveHandler'); - this._mouseUp = Rico.eventHandle(this,'_mouseUpHandler'); - }, - - registerDropZone: function(aDropZone) { - this.dropZones[ this.dropZones.length ] = aDropZone; - }, - - deregisterDropZone: function(aDropZone) { - var newDropZones = new Array(); - var j = 0; - for ( var i = 0 ; i < this.dropZones.length ; i++ ) { - if ( this.dropZones[i] != aDropZone ) - newDropZones[j++] = this.dropZones[i]; - } - - this.dropZones = newDropZones; - }, - - clearDropZones: function() { - this.dropZones = new Array(); - }, - - registerDraggable: function( aDraggable ) { - this.draggables[ this.draggables.length ] = aDraggable; - var htmlElement = aDraggable.getMouseDownHTMLElement(); - if ( htmlElement != null ) { - htmlElement.ricoDraggable = aDraggable; - Rico.eventBind(htmlElement, "mousedown", Rico.eventHandle(this,'_attachEvents')); - Rico.eventBind(htmlElement, "mousedown", this._mouseDown); - } - }, - - clearSelection: function() { - for ( var i = 0 ; i < this.currentDragObjects.length ; i++ ) - this.currentDragObjects[i].deselect(); - this.currentDragObjects = new Array(); - this.lastSelectedDraggable = null; - }, - - hasSelection: function() { - return this.currentDragObjects.length > 0; - }, - - setStartDragFromElement: function( e, mouseDownElement ) { - this.origPos = Rico.cumulativeOffset(mouseDownElement); - var coord=Rico.eventClient(e); - this.startx = coord.x - this.origPos.left; - this.starty = coord.y - this.origPos.top; - - this.interestedInMotionEvents = this.hasSelection(); - Rico.eventStop(e); - }, - - updateSelection: function( draggable, extendSelection ) { - if ( ! extendSelection ) - this.clearSelection(); - - if ( draggable.isSelected() ) { - this.currentDragObjects=this.currentDragObjects.without(draggable); - draggable.deselect(); - if ( draggable == this.lastSelectedDraggable ) - this.lastSelectedDraggable = null; - } - else { - draggable.select(); - if ( draggable.isSelected() ) { - this.currentDragObjects.push(draggable); - this.lastSelectedDraggable = draggable; - } - } - }, - - _mouseDownHandler: function(e) { - // if not button 1 ignore it... - if (!Rico.eventLeftClick(e)) return; - - var eventTarget = Rico.eventElement(e); - var draggableObject = eventTarget.ricoDraggable; - - var candidate = eventTarget; - while (draggableObject == null && candidate.parentNode) { - candidate = candidate.parentNode; - draggableObject = candidate.ricoDraggable; - } - - if ( draggableObject == null ) return; - - this.updateSelection( draggableObject, e.ctrlKey ); - - // clear the drop zones postion cache... - if ( this.hasSelection() ) { - for ( var i = 0 ; i < this.dropZones.length ; i++ ) - this.dropZones[i].clearPositionCache(); - } - this.setStartDragFromElement( e, draggableObject.getMouseDownHTMLElement() ); - }, - - - _mouseMoveHandler: function(e) { - if ( !this.interestedInMotionEvents ) { - return; - } - - if ( ! this.hasSelection() ) - return; - - if ( ! this.currentDragObjectVisible ) - this._startDrag(e); - - if ( !this.activatedDropZones ) - this._activateRegisteredDropZones(); - - this._updateDraggableLocation(e); - this._updateDropZonesHover(e); - - Rico.eventStop(e); - }, - - _makeDraggableObjectVisible: function(e) { - if ( !this.hasSelection() ) - return; - - var dragElement; - if ( this.currentDragObjects.length > 1 ) - dragElement = this.currentDragObjects[0].getMultiObjectDragGUI(this.currentDragObjects); - else - dragElement = this.currentDragObjects[0].getSingleObjectDragGUI(); - - // go ahead and absolute position it... - this.dragElemPosition=Rico.getStyle(dragElement, "position"); - if (this.dragElemPosition != "absolute") - dragElement.style.position = "absolute"; - - // need to parent him into the document... - if ( dragElement.parentNode == null || dragElement.parentNode.nodeType == 11 ) - document.body.appendChild(dragElement); - - this.dragElement = dragElement; - this._updateDraggableLocation(e); - - this.currentDragObjectVisible = true; - }, - - _leftOffset: function(e) { - return e.offsetX ? document.body.scrollLeft : 0; - }, - - _topOffset: function(e) { - return e.offsetY ? document.body.scrollTop : 0; - }, - - - _updateDraggableLocation: function(e) { - var dragObjectStyle = this.dragElement.style; - var coord=Rico.eventClient(e); - dragObjectStyle.left = (coord.x + this._leftOffset(e) - this.startx) + "px"; - dragObjectStyle.top = (coord.y + this._topOffset(e) - this.starty) + "px"; - }, - - _updateDropZonesHover: function(e) { - var i,n = this.dropZones.length; - for ( i = 0 ; i < n ; i++ ) { - if ( ! this._mousePointInDropZone( e, this.dropZones[i] ) ) - this.dropZones[i].hideHover(); - } - - for ( i = 0 ; i < n ; i++ ) { - if ( this._mousePointInDropZone( e, this.dropZones[i] ) ) { - if ( this.dropZones[i].canAccept(this.currentDragObjects) ) - this.dropZones[i].showHover(); - } - } - }, - - _startDrag: function(e) { - for ( var i = 0 ; i < this.currentDragObjects.length ; i++ ) - this.currentDragObjects[i].startDrag(); - this._makeDraggableObjectVisible(e); - }, - - _mouseUpHandler: function(e) { - if ( ! this.hasSelection() ) return; - if (!Rico.eventLeftClick(e)) return; - - this.interestedInMotionEvents = false; - - if ( this._placeDraggableInDropZone(e) ) - this._completeDropOperation(e); - else if (this.dragElement != null) { - Rico.eventStop(e); - Rico.animate(this.dragElement, - {duration: 300, onEnd:Rico.bind(this,'_doCancelDragProcessing')}, - {left:this.origPos.left, top:this.origPos.top}); - } - - Rico.eventUnbind(document.body, "mousemove", this._mouseMove); - Rico.eventUnbind(document.body, "mouseup", this._mouseUp); - }, - - _retTrue: function () { - return true; - }, - - _completeDropOperation: function(e) { - if ( this.dragElement != this.currentDragObjects[0].getMouseDownHTMLElement() ) { - if ( this.dragElement.parentNode != null ) - this.dragElement.parentNode.removeChild(this.dragElement); - } - - this._deactivateRegisteredDropZones(); - this._endDrag(); - this.clearSelection(); - this.dragElement = null; - this.currentDragObjectVisible = false; - Rico.eventStop(e); - }, - - _doCancelDragProcessing: function() { - this._cancelDrag(); - if ( this.dragElement == this.currentDragObjects[0].getMouseDownHTMLElement() ) { - this.dragElement.style.position=this.dragElemPosition; - } else { - if ( this.dragElement && this.dragElement.parentNode != null ) - this.dragElement.parentNode.removeChild(this.dragElement); - } - this._deactivateRegisteredDropZones(); - this.dragElement = null; - this.currentDragObjectVisible = false; - }, - - _placeDraggableInDropZone: function(e) { - var foundDropZone = false; - var n = this.dropZones.length; - for ( var i = 0 ; i < n ; i++ ) { - if ( this._mousePointInDropZone( e, this.dropZones[i] ) ) { - if ( this.dropZones[i].canAccept(this.currentDragObjects) ) { - this.dropZones[i].hideHover(); - this.dropZones[i].accept(this.currentDragObjects); - foundDropZone = true; - break; - } - } - } - - return foundDropZone; - }, - - _cancelDrag: function() { - for ( var i = 0 ; i < this.currentDragObjects.length ; i++ ) - this.currentDragObjects[i].cancelDrag(); - }, - - _endDrag: function() { - for ( var i = 0 ; i < this.currentDragObjects.length ; i++ ) - this.currentDragObjects[i].endDrag(); - }, - - _mousePointInDropZone: function( e, dropZone ) { - - var absoluteRect = dropZone.getAbsoluteRect(); - var coord=Rico.eventClient(e); - - return coord.x > absoluteRect.left + this._leftOffset(e) && - coord.x < absoluteRect.right + this._leftOffset(e) && - coord.y > absoluteRect.top + this._topOffset(e) && - coord.y < absoluteRect.bottom + this._topOffset(e); - }, - - _activateRegisteredDropZones: function() { - var n = this.dropZones.length; - for ( var i = 0 ; i < n ; i++ ) { - var dropZone = this.dropZones[i]; - if ( dropZone.canAccept(this.currentDragObjects) ) - dropZone.activate(); - } - - this.activatedDropZones = true; - }, - - _deactivateRegisteredDropZones: function() { - var n = this.dropZones.length; - for ( var i = 0 ; i < n ; i++ ) - this.dropZones[i].deactivate(); - this.activatedDropZones = false; - }, - - _attachEvents: function () { - Rico.eventBind(document.body, "mousemove", this._mouseMove); - Rico.eventBind(document.body, "mouseup", this._mouseUp); - } - -}; - - -Rico.Draggable = function(type, htmlElement) { - this.initialize(type, htmlElement); -}; - -Rico.Draggable.prototype = { -/** - * @class Implements behavior for a draggable element - * @constructs - */ - initialize: function( type, htmlElement ) { - this.type = type; - this.htmlElement = Rico.$(htmlElement); - this.selected = false; - }, - - /** - * Returns the HTML element that should have a mouse down event - * added to it in order to initiate a drag operation - **/ - getMouseDownHTMLElement: function() { - return this.htmlElement; - }, - - select: function() { - this._select(); - }, - - _select: function() { - this.selected = true; - if (this.showingSelected) return; - this.showingSelected = true; - - var htmlElement = this.getMouseDownHTMLElement(); - var color = Rico.Color.createColorFromBackground(htmlElement); - color.isBright() ? color.darken(0.033) : color.brighten(0.033); - this.saveBackground = Rico.getStyle(htmlElement, "backgroundColor", "background-color"); - htmlElement.style.backgroundColor = color.asHex(); - }, - - deselect: function() { - this.selected = false; - if (!this.showingSelected) return; - var htmlElement = this.getMouseDownHTMLElement(); - htmlElement.style.backgroundColor = this.saveBackground; - this.showingSelected = false; - }, - - isSelected: function() { - return this.selected; - }, - - startDrag: function() { - }, - - cancelDrag: function() { - }, - - endDrag: function() { - }, - - getSingleObjectDragGUI: function() { - return this.htmlElement; - }, - - getMultiObjectDragGUI: function( draggables ) { - return this.htmlElement; - }, - - getDroppedGUI: function() { - return this.htmlElement; - }, - - toString: function() { - return this.type + ":" + this.htmlElement + ":"; - } - -}; - - -Rico.LiveGridDraggable = function(grid, rownum, colnum) { - this.initialize(grid, rownum, colnum); -}; - -Rico.LiveGridDraggable.prototype = Rico.extend(new Rico.Draggable(), { -/** - * @class Enables draggable behavior for LiveGrid cells. - * Called by LiveGrid#appendBlankRow for columns where canDrag is true. - * @extends Rico.Draggable - * @constructs - */ - initialize: function( grid, rownum, colnum) { - this.type = 'RicoCell'; - this.htmlElement = grid.cell(rownum,colnum); - this.liveGrid = grid; - this.dragRow = rownum; - this.dragCol = colnum; - }, - - select: function() { - if (this.dragRow >= this.liveGrid.buffer.totalRows) return; - this.selected = true; - this.showingSelected = true; - }, - - deselect: function() { - this.selected = false; - this.showingSelected = false; - }, - - getSingleObjectDragGUI: function() { - var div = document.createElement("div"); - div.className = 'LiveGridDraggable'; - div.style.width = (this.htmlElement.offsetWidth - 10) + "px"; - div.innerHTML=this.htmlElement.innerHTML; - return div; - } -}); - - -Rico.Dropzone = function(htmlElement) { - this.initialize(htmlElement); -}; - -Rico.Dropzone.prototype = { -/** - * @class Implements behavior for a drop zone - * @constructs - */ - initialize: function( htmlElement ) { - this.htmlElement = Rico.$(htmlElement); - this.absoluteRect = null; - }, - - getHTMLElement: function() { - return this.htmlElement; - }, - - clearPositionCache: function() { - this.absoluteRect = null; - }, - - getAbsoluteRect: function() { - if ( this.absoluteRect == null ) { - var htmlElement = this.getHTMLElement(); - var pos = Rico.viewportOffset(htmlElement); - - this.absoluteRect = { - top: pos.top, - left: pos.left, - bottom: pos.top + htmlElement.offsetHeight, - right: pos.left + htmlElement.offsetWidth - }; - } - return this.absoluteRect; - }, - - activate: function() { - var htmlElement = this.getHTMLElement(); - if (htmlElement == null || this.showingActive) - return; - - this.showingActive = true; - this.saveBackgroundColor = htmlElement.style.backgroundColor; - - var fallbackColor = "#ffea84"; - var currentColor = Rico.Color.createColorFromBackground(htmlElement); - if ( currentColor == null ) - htmlElement.style.backgroundColor = fallbackColor; - else { - currentColor.isBright() ? currentColor.darken(0.2) : currentColor.brighten(0.2); - htmlElement.style.backgroundColor = currentColor.asHex(); - } - }, - - deactivate: function() { - var htmlElement = this.getHTMLElement(); - if (htmlElement == null || !this.showingActive) - return; - - htmlElement.style.backgroundColor = this.saveBackgroundColor; - this.showingActive = false; - this.saveBackgroundColor = null; - }, - - showHover: function() { - var htmlElement = this.getHTMLElement(); - if ( htmlElement == null || this.showingHover ) - return; - - this.saveBorderWidth = htmlElement.style.borderWidth; - this.saveBorderStyle = htmlElement.style.borderStyle; - this.saveBorderColor = htmlElement.style.borderColor; - - this.showingHover = true; - htmlElement.style.borderWidth = "1px"; - htmlElement.style.borderStyle = "solid"; - //htmlElement.style.borderColor = "#ff9900"; - htmlElement.style.borderColor = "#ffff00"; - }, - - hideHover: function() { - var htmlElement = this.getHTMLElement(); - if ( htmlElement == null || !this.showingHover ) - return; - - htmlElement.style.borderWidth = this.saveBorderWidth; - htmlElement.style.borderStyle = this.saveBorderStyle; - htmlElement.style.borderColor = this.saveBorderColor; - this.showingHover = false; - }, - - canAccept: function(draggableObjects) { - return true; - }, - - accept: function(draggableObjects) { - var htmlElement = this.getHTMLElement(); - if ( htmlElement == null ) - return; - - var n = draggableObjects.length; - for ( var i = 0 ; i < n ; i++ ) { - var theGUI = draggableObjects[i].getDroppedGUI(); - if ( Rico.getStyle( theGUI, "position" ) == "absolute" ) { - theGUI.style.position = "static"; - theGUI.style.top = ""; - theGUI.style.top = ""; - } - htmlElement.appendChild(theGUI); - } - } -}; - -Rico.includeLoaded('ricoDragDrop.js'); diff --git a/ricoClient/js/ricoGridCommon.js b/ricoClient/js/ricoGridCommon.js deleted file mode 100644 index b665b47..0000000 --- a/ricoClient/js/ricoGridCommon.js +++ /dev/null @@ -1,989 +0,0 @@ -/* - * (c) 2005-2009 Richard Cowin (http://openrico.org) - * (c) 2005-2009 Matt Brown (http://dowdybrown.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this - * file except in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the - * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions - * and limitations under the License. - */ - -if(typeof Rico=='undefined') throw("GridCommon requires the Rico JavaScript framework"); - -/** - * Define methods that are common to both SimpleGrid and LiveGrid - */ -Rico.GridCommon = { - - baseInit: function() { - this.options = { - resizeBackground : 'resize.gif', - saveColumnInfo : {width:true, filter:false, sort:false}, // save info in cookies? - cookiePrefix : 'RicoGrid.', - allowColResize : true, // allow user to resize columns - windowResize : true, // Resize grid on window.resize event? Set to false when embedded in an accordian. - click : null, - dblclick : null, - contextmenu : null, - menuEvent : 'dblclick', // event that triggers menus - click, dblclick, contextmenu, or none (no menus) - defaultWidth : -1, // if -1, then use unformatted column width - scrollBarWidth : 19, // this is the value used in positioning calculations, it does not actually change the width of the scrollbar - minScrollWidth : 100, // min scroll area width when width of frozen columns exceeds window width - frozenColumns : 0, - exportWindow : "height=400,width=500,scrollbars=1,menubar=1,resizable=1", - exportStyleList : ['background-color','color','text-align','font-weight','font-size','font-family'], - exportImgTags : false, // applies to grid header and to SimpleGrid cells (not LiveGrid cells) - exportFormFields : true, - FilterLocation : null, // heading row number to place filters. -1=add a new heading row. - FilterAllToken : '___ALL___', // select box value to use to indicate ALL - columnSpecs : [] - }; - this.colWidths = []; - this.hdrCells=[]; - this.headerColCnt=0; - this.headerRowIdx=0; // row in header which gets resizers (no colspan's in this row) - this.tabs=new Array(2); - this.thead=new Array(2); - this.tbody=new Array(2); - }, - - attachMenuEvents: function() { - var i; - if (!this.options.menuEvent || this.options.menuEvent=='none') return; - this.hideScroll=navigator.userAgent.match(/Macintosh\b.*\b(Firefox|Camino)\b/i) || (Rico.isOpera && parseFloat(window.opera.version())<9.5); - this.options[this.options.menuEvent]=Rico.eventHandle(this,'handleMenuClick'); - if (this.highlightDiv) { - switch (this.options.highlightElem) { - case 'cursorRow': - this.attachMenu(this.highlightDiv[0]); - break; - case 'cursorCell': - for (i=0; i<2; i++) { - this.attachMenu(this.highlightDiv[i]); - } - break; - } - } - for (i=0; i<2; i++) { - this.attachMenu(this.tbody[i]); - } - }, - - attachMenu: function(elem) { - if (this.options.click) - Rico.eventBind(elem, 'click', this.options.click, false); - if (this.options.dblclick) { - if (Rico.isWebKit || Rico.isOpera) - Rico.eventBind(elem, 'click', Rico.eventHandle(this,'handleDblClick'), false); - else - Rico.eventBind(elem, 'dblclick', this.options.dblclick, false); - } - if (this.options.contextmenu) { - if (Rico.isOpera || Rico.isKonqueror) - Rico.eventBind(elem, 'click', Rico.eventHandle(this,'handleContextMenu'), false); - else - Rico.eventBind(elem, 'contextmenu', this.options.contextmenu, false); - } - }, - -/** - * implement double-click for browsers that don't support a double-click event (e.g. Safari) - */ - handleDblClick: function(e) { - var elem=Rico.eventElement(e); - if (this.dblClickElem == elem) { - this.options.dblclick(e); - } else { - this.dblClickElem = elem; - this.safariTimer=Rico.runLater(300,this,'clearDblClick'); - } - }, - - clearDblClick: function() { - this.dblClickElem=null; - }, - -/** - * implement right-click for browsers that don't support contextmenu event (e.g. Opera, Konqueror) - * use control-click instead - */ - handleContextMenu: function(e) { - var b; - if( typeof( e.which ) == 'number' ) - b = e.which; //Netscape compatible - else if( typeof( e.button ) == 'number' ) - b = e.button; //DOM - else - return; - if (b==1 && e.ctrlKey) { - this.options.contextmenu(e); - } - }, - - cancelMenu: function() { - if (this.menu) this.menu.cancelmenu(); - }, - -/** - * gather info from original headings - */ - getColumnInfo: function(hdrSrc) { - Rico.log('getColumnInfo: len='+hdrSrc.length); - if (hdrSrc.length == 0) return 0; - this.headerRowCnt=hdrSrc.length; - var r,c,colcnt; - for (r=0; r= this.hdrCells.length) this.hdrCells[r]=[]; - for (c=0; c 0) - wiLimit=Math.min(this.outerDiv.parentNode.clientWidth, wiLimit); - var overage=this.frzWi+this.scrWi-wiLimit; - Rico.log('baseSizeDivs '+this.tableId+': scrWi='+this.scrWi+' wiLimit='+wiLimit+' overage='+overage+' clientWidth='+this.outerDiv.parentNode.clientWidth); - if (overage > 0 && this.options.frozenColumns < this.columns.length) - this.scrWi=Math.max(this.scrWi-overage, this.options.minScrollWidth); - this.scrollDiv.style.width=this.scrWi+'px'; - //this.scrollDiv.style.top=this.hdrHt+'px'; - //this.frozenTabs.style.width=this.scrollDiv.style[this.align[0]]=this.innerDiv.style[this.align[0]]=this.frzWi+'px'; - this.frozenTabs.style.width=this.frzWi+'px'; - this.outerDiv.style.width=(this.frzWi+this.scrWi)+'px'; - }, - -/** - * Returns the sum of the left & right border widths of an element - */ - borderWidth: function(elem) { - var l=Rico.nan2zero(Rico.getStyle(elem,'borderLeftWidth')); - var r=Rico.nan2zero(Rico.getStyle(elem,'borderRightWidth')); - Rico.log((elem.id || elem.tagName)+' borderWidth: L='+l+', R='+r); - return l + r; -// return Rico.nan2zero(Rico.getStyle(elem,'borderLeftWidth')) + Rico.nan2zero(Rico.getStyle(elem,'borderRightWidth')); - }, - - setOtherHdrCellWidths: function() { - var c,i,j,r,w,hdrcell,cell,origSpan,newSpan,divs; - for (r=0; r'; - }, - -/** - * Returns a div for the cell at the specified row and column index. - * In SimpleGrid, r can refer to any row in the grid. - * In LiveGrid, r refers to a visible row (row 0 is the first visible row). - */ - cell: function(r,c) { - return (0<=c && c=0) ? this.columns[c].cell(r) : null; - }, - -/** - * Returns the screen height available for a grid - */ - availHt: function() { - var divPos=Rico.cumulativeOffset(this.outerDiv); - return Rico.windowHeight()-divPos.top-2*this.options.scrollBarWidth-15; // allow for scrollbar and some margin - }, - - setHorizontalScroll: function() { - var newLeft=(-this.scrollDiv.scrollLeft)+'px'; - this.hdrTabs[1].style.marginLeft=newLeft; - }, - - pluginScroll: function() { - if (this.scrollPluggedIn) return; - Rico.eventBind(this.scrollDiv,"scroll",this.scrollEventFunc, false); - this.scrollPluggedIn=true; - }, - - unplugScroll: function() { - Rico.eventUnbind(this.scrollDiv,"scroll", this.scrollEventFunc , false); - this.scrollPluggedIn=false; - }, - - hideMsg: function() { - this.messagePopup.closePopup(); - }, - - showMsg: function(msg) { - this.messagePopup.setContent(msg); - this.messagePopup.centerPopup(); - Rico.log("showMsg: "+msg); - }, - -/** - * @return array of column objects which have invisible status - */ - listInvisible: function(attr) { - var hiddenColumns=[]; - for (var x=0;x"; - } - this.exportText+=""; - if (this.exportHeader) this.exportText+=this.exportHeader; - for (r=0; r 0) { - divs=Rico.select('.ricoLG_cell',hdrcell.cell); - cell=divs && divs.length>0 ? divs[0] : hdrcell.cell; - this.exportText+=" 1) this.exportText+=" colspan='"+newSpan+"'"; - this.exportText+=">"+Rico.getInnerText(cell,!this.options.exportImgTags, !this.options.exportFormFields, 'NoExport')+""; - } - } - this.exportText+=""; - } - this.exportText+=""; - }, - -/** - * Support function for printVisible(). - * exportType is optional and defaults 'plain'; 'owc' can be used for IE users with Office Web Components. - */ - exportFinish: function(exportType) { - if (this.hideMsg) this.hideMsg(); - window.status=Rico.getPhraseById('exportComplete'); - if (this.exportRows.length > 0) this.exportText+=''+this.exportRows.join('')+''; - if (this.exportFooter) this.exportText+=this.exportFooter; - this.exportText+=""; - this.exportDiv.innerHTML=this.exportText; - this.exportText=undefined; - this.exportRows=undefined; - if (this.cancelMenu) this.cancelMenu(); - var w=window.open(Rico.htmDir+'export-'+(exportType || 'plain')+'.html?'+this.exportDiv.id,'',this.options.exportWindow); - if (w == null) alert(Rico.getPhraseById('disableBlocker')); - }, - -/** - * Support function for printVisible() - */ - exportStyle: function(elem,styleList) { - for (var i=0,s=''; i < styleList.length; i++) { - try { - var curstyle=Rico.getStyle(elem,styleList[i]); - if (curstyle) s+=styleList[i]+':'+curstyle+';'; - } catch(e) {}; - } - return s; - }, - -/** - * Gets the value of the grid cookie and interprets the contents. - * All information for a particular grid is stored in a single cookie. - * This may include column widths, column hide/show status, current sort, and any column filters. - */ - getCookie: function() { - var c=Rico.getCookie(this.options.cookiePrefix+this.tableId); - if (!c) return; - var cookieVals=c.split(','); - for (var i=0; i= this.columns.length) continue; - var col=this.columns[colnum]; - switch (v[0].charAt(0)) { - case 'w': - col.setColWidth(v[1]); - col.customWidth=true; - break; - case 'h': - if (v[1].toLowerCase()=='true') - col.hideshow(true,true); - else - col.hideshow(false,true); - break; - case 's': - if (!this.options.saveColumnInfo.sort || !col.sortable) break; - col.setSorted(v[1]); - break; - case 'f': - if (!this.options.saveColumnInfo.filter || !col.filterable) break; - var filterTemp=v[1].split('~'); - col.filterOp=filterTemp.shift(); - col.filterValues = []; - col.filterType = Rico.ColumnConst.USERFILTER; - for (var j=0; j 0) - return anchors[0].innerHTML; - else - return Rico.stripTags(el.innerHTML); - }, - - _clear: function(gridCell) { - gridCell.innerHTML=' '; - }, - - clearCell: function(rowIndex) { - var gridCell=this.cell(rowIndex); - this._clear(gridCell,rowIndex); - if (!this.liveGrid.buffer) return; - var acceptAttr=this.liveGrid.buffer.options.acceptAttr; - for (var k=0; k0) this.edge+=Rico.nan2zero(this.liveGrid.tabs[0].offsetWidth); - } - this.liveGrid.resizeDiv.style.left=this.edge+"px"; - this.liveGrid.resizeDiv.style.display=""; - this.liveGrid.outerDiv.style.cursor='e-resize'; - this.tmpHighlight=this.liveGrid.highlightEnabled; - this.liveGrid.highlightEnabled=false; - this.pluginMouseEvents(); - Rico.eventStop(e); - }, - - handleMouseMove: function(e) { - var delta=Rico.eventClient(e).x-this.resizeStart; - var newWidth=(this.liveGrid.direction=='rtl') ? this.origWidth-delta : this.origWidth+delta; - if (newWidth < Rico.ColumnConst.MINWIDTH) return; - this.liveGrid.resizeDiv.style.left=(this.edge+delta)+"px"; - this.colWidth=newWidth; - Rico.eventStop(e); - }, - - handleMouseUp: function(e) { - this.unplugMouseEvents(); - Rico.log('handleMouseUp '+this.liveGrid.tableId); - this.liveGrid.outerDiv.style.cursor=''; - this.liveGrid.resizeDiv.style.display="none"; - this.setColWidth(this.colWidth); - this.customWidth=true; - this.liveGrid.setCookie(); - this.liveGrid.highlightEnabled=this.tmpHighlight; - this.liveGrid.sizeDivs(); - Rico.eventStop(e); - }, - - handleMouseOut: function(e) { - var reltg = Rico.eventRelatedTarget(e) || e.toElement; - while (reltg != null && reltg.nodeName.toLowerCase() != 'body') - reltg=reltg.parentNode; - if (reltg!=null && reltg.nodeName.toLowerCase() == 'body') return true; - this.handleMouseUp(e); - return true; - }, - - setDisplay: function(d) { - this.hdrCell.style.display=d; - this.hdrColDiv.style.display=d; - this.dataCell.style.display=d; - this.dataColDiv.style.display=d; - }, - - hideshow: function(visible,noresize) { - this.setDisplay(visible ? '' : 'none'); - this.liveGrid.cancelMenu(); - this.visible=visible; - this.customVisible=true; - if (noresize) return; - this.liveGrid.setCookie(); - this.liveGrid.sizeDivs(); - }, - - hideColumn: function() { - Rico.log('hideColumn '+this.liveGrid.tableId); - this.hideshow(false,false); - }, - - showColumn: function() { - Rico.log('showColumn '+this.liveGrid.tableId); - this.hideshow(true,false); - }, - - chooseColumn: function(e) { - var elem=Rico.eventElement(e); - this.hideshow(elem.checked,false); - }, - - setImage: function() { - if ( this.currentSort == Rico.ColumnConst.SORT_ASC ) { - this.imgSort.style.display='inline-block'; - this.imgSort.className=Rico.theme.sortAsc || 'ricoLG_sortAsc'; - } else if ( this.currentSort == Rico.ColumnConst.SORT_DESC ) { - this.imgSort.style.display='inline-block'; - this.imgSort.className=Rico.theme.sortDesc || 'ricoLG_sortDesc'; - } else { - this.imgSort.style.display='none'; - } - if (this.filterType == Rico.ColumnConst.USERFILTER) { - this.imgFilter.style.display=''; - this.imgFilter.title=this.getFilterText(); - } else { - this.imgFilter.style.display='none'; - } - }, - - canHideShow: function() { - return this.hideable; - } - -}; - -Rico.includeLoaded('ricoGridCommon.js'); diff --git a/ricoClient/js/ricoLiveGrid.js b/ricoClient/js/ricoLiveGrid.js deleted file mode 100644 index 15a08ad..0000000 --- a/ricoClient/js/ricoLiveGrid.js +++ /dev/null @@ -1,2433 +0,0 @@ -/* - * (c) 2005-2009 Richard Cowin (http://openrico.org) - * (c) 2005-2009 Matt Brown (http://dowdybrown.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this - * file except in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the - * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions - * and limitations under the License. - */ - -if(typeof Rico=='undefined') throw("LiveGrid requires the Rico JavaScript framework"); - - -/** @namespace */ -if (!Rico.Buffer) Rico.Buffer = {}; - -Rico.Buffer.Base = function(dataTable, options) { - this.initialize(dataTable, options); -} -/** @lends Rico.Buffer.Base# */ -Rico.Buffer.Base.prototype = { -/** - * @class Defines the static buffer class (no AJAX). - * Loads buffer with data that already exists in the document as an HTML table or passed via javascript. - * Also serves as a base class for AJAX-enabled buffers. - * @constructs - */ - initialize: function(dataTable, options) { - this.clear(); - this.updateInProgress = false; - this.lastOffset = 0; - this.rcvdRowCount = false; // true if an eof element was included in the last xml response - this.foundRowCount = false; // true if an xml response is ever received with eof true - this.totalRows = 0; - this.rowcntContent = ""; - this.rcvdOffset = -1; - this.options = { - fixedHdrRows : 0, - canFilter : true, // does buffer object support filtering? - isEncoded : true, // is the data received via ajax html encoded? - acceptAttr : [] // attributes that can be copied from original/ajax data (e.g. className, style, id) - }; - Rico.extend(this.options, options || {}); - if (dataTable) { - this.loadRowsFromTable(dataTable,this.options.fixedHdrRows); - } else { - this.clear(); - } - }, - - registerGrid: function(liveGrid) { - this.liveGrid = liveGrid; - }, - - setTotalRows: function( newTotalRows ) { - if (typeof(newTotalRows)!='number') newTotalRows=this.size; - if (this.totalRows == newTotalRows) return; - this.totalRows = newTotalRows; - if (!this.liveGrid) return; - Rico.log("setTotalRows, newTotalRows="+newTotalRows); - switch (this.liveGrid.sizeTo) { - case 'data': - this.liveGrid.resizeWindow(); - break; - case 'datamax': - this.liveGrid.setPageSize(newTotalRows); - break; - default: - this.liveGrid.updateHeightDiv(); - break; - } - }, - - loadRowsFromTable: function(tableElement,firstRow) { - var newRows = new Array(); - var trs = tableElement.getElementsByTagName("tr"); - for ( var i=firstRow || 0; i < trs.length; i++ ) { - var row = new Array(); - var cells = trs[i].getElementsByTagName("td"); - for ( var j=0; j < cells.length ; j++ ) - row[j]=cells[j].innerHTML; - newRows.push( row ); - } - this.loadRows(newRows); - }, - - loadRowsFromArray: function(array2D) { - for ( var i=0; i < array2D.length; i++ ) { - for ( var j=0; j < array2D[i].length ; j++ ) { - array2D[i][j]=array2D[i][j].toString(); - } - } - this.loadRows(array2D); - }, - - loadRows: function(jstable) { - this.baseRows = jstable; - this.startPos = 0; - this.size = this.baseRows.length; - }, - - dom2jstable: function(rowsElement) { - Rico.log('dom2jstable: encoded='+this.options.isEncoded); - var newRows = new Array(); - var trs = rowsElement.getElementsByTagName("tr"); - for ( var i=0; i < trs.length; i++ ) { - var row = new Array(); - var cells = trs[i].getElementsByTagName("td"); - for ( var j=0; j < cells.length ; j++ ) - row[j]=Rico.getContentAsString(cells[j],this.options.isEncoded); - newRows.push( row ); - } - return newRows; - }, - - dom2jstableAttr: function(rowsElement,firstRow) { - var acceptAttr=this.options.acceptAttr; - Rico.log("dom2jstableAttr start, # attr="+acceptAttr.length); - var newRows = new Array(); - var trs = rowsElement.getElementsByTagName("tr"); - for ( var i=firstRow || 0; i < trs.length; i++ ) { - var row = new Array(); - var cells = trs[i].getElementsByTagName("td"); - for ( var j=0; j < cells.length ; j++ ) { - row[j]={}; - for (var k=0; k= this.startPos) && (lastRow <= this.endPos()); // && (this.size != 0); - }, - - endPos: function() { - return this.startPos + this.rows.length; - }, - - fetch: function(offset) { - Rico.log('fetch '+this.liveGrid.tableId+': offset='+offset); - this.applyFilters(); - this.setTotalRows(); - this.rcvdRowCount = true; - this.foundRowCount = true; - if (offset < 0) offset=0; - this.liveGrid.refreshContents(offset); - return; - }, - -/** - * @return a 2D array of buffer data representing the rows that are currently visible on the grid - */ - visibleRows: function() { - return this.rows.slice(this.windowStart,this.windowEnd); - }, - - setWindow: function(startrow, endrow) { - this.windowStart = startrow - this.startPos; // position in the buffer of first visible row - Rico.log('setWindow '+this.liveGrid.tableId+': '+startrow+', '+endrow+', newstart='+this.windowStart); - this.windowEnd = Math.min(endrow,this.size); // position in the buffer of last visible row containing data+1 - this.windowPos = startrow; // position in the dataset of first visible row - }, - -/** - * @return true if bufRow is currently visible in the grid - */ - isVisible: function(bufRow) { - return bufRow < this.rows.length && bufRow >= this.windowStart && bufRow < this.windowEnd; - }, - -/** - * takes a window row index and returns the corresponding buffer row index - */ - bufferRow: function(windowRow) { - return this.windowStart+windowRow; - }, - -/** - * @return buffer cell at the specified visible row/col index - */ - getWindowCell: function(windowRow,col) { - var bufrow=this.bufferRow(windowRow); - return this.isVisible(bufrow) && col < this.rows[bufrow].length ? this.rows[bufrow][col] : null; - }, - - getWindowAttr: function(windowRow,col) { - var bufrow=this.bufferRow(windowRow); - return this.attr && this.isVisible(bufrow) && col < this.attr[bufrow].length ? this.attr[bufrow][col] : null; - }, - - getWindowValue: function(windowRow,col) { - return this.getWindowCell(windowRow,col); - }, - - setWindowValue: function(windowRow,col,newval) { - var bufrow=this.bufferRow(windowRow); - if (bufrow >= this.windowEnd) return false; - return this.setValue(bufrow,col,newval); - }, - - getCell: function(bufRow,col) { - return bufRow < this.size ? this.rows[bufRow][col] : null; - }, - - getValue: function(bufRow,col) { - return this.getCell(bufRow,col); - }, - - setValue: function(bufRow,col,newval,newstyle) { - if (bufRow>=this.size) return false; - if (!this.rows[bufRow][col]) this.rows[bufRow][col]={}; - this.rows[bufRow][col]=newval; - if (typeof newstyle=='string') this.rows[bufRow][col]._style=newstyle; - this.rows[bufRow][col].modified=true; - return true; - }, - - getRows: function(start, count) { - var begPos = start - this.startPos; - var endPos = Math.min(begPos + count,this.size); - var results = new Array(); - for ( var i=begPos; i < endPos; i++ ) { - results.push(this.rows[i]); - } - return results; - }, - - applyFilters: function() { - var newRows=[],re=[]; - var r,c,n,i,showRow,filtercnt; - var cols=this.liveGrid.columns; - for (n=0,filtercnt=0; n=this.nan2zero(c.filterValues[0]); - else - showRow=this.baseRows[r][n]>=c.filterValues[0]; - break; - case 'NULL': - showRow=this.baseRows[r][n]==''; - break; - case 'NOTNULL': - showRow=this.baseRows[r][n]!=''; - break; - } - } - if (showRow) newRows.push(this.baseRows[r]); - } - this.rows = newRows; - } - this.rowcntContent = this.size = this.rows.length; - }, - - printAll: function(exportType) { - this.liveGrid.showMsg(Rico.getPhraseById('exportInProgress')); - Rico.runLater(10,this,'_printAll',exportType); // allow message to paint - }, - -/** - * Support function for printAll() - */ - _printAll: function(exportType) { - this.liveGrid.exportStart(); - this.exportBuffer(this.getRows(0,this.totalRows)); - this.liveGrid.exportFinish(exportType); - }, - -/** - * Copies visible rows to a new window as a simple html table. - */ - printVisible: function(exportType) { - this.liveGrid.showMsg(Rico.getPhraseById('exportInProgress')); - Rico.runLater(10,this,'_printVisible',exportType); // allow message to paint - }, - - _printVisible: function(exportType) { - this.liveGrid.exportStart(); - this.exportBuffer(this.visibleRows()); - this.liveGrid.exportFinish(exportType); - }, - -/** - * Send all rows to print/export window - */ - exportBuffer: function(rows,startPos) { - var r,c,v,col,exportText; - Rico.log("exportBuffer: "+rows.length+" rows"); - var exportStyles=this.liveGrid.getExportStyles(this.liveGrid.tbody[0]); - var tdstyle=[]; - var totalcnt=startPos || 0; - var cols=this.liveGrid.columns; - for (c=0; c"+v+""; - } - this.liveGrid.exportRows.push(exportText); - totalcnt++; - if (totalcnt % 10 == 0) window.status=Rico.getPhraseById('exportStatus',totalcnt); - } - } - -}; - - -// Rico.LiveGrid ----------------------------------------------------- - -Rico.LiveGrid = function(tableId, buffer, options) { - this.initialize(tableId, buffer, options); -} - -/** - * @lends Rico.LiveGrid# - * @property tableId id string for this grid - * @property options the options object passed to the constructor extended with defaults - * @property buffer the buffer object containing the data for this grid - * @property columns array of {@link Rico.LiveGridColumn} objects - */ -Rico.LiveGrid.prototype = { -/** - * @class Buffered LiveGrid component - * @extends Rico.GridCommon - * @constructs - */ - initialize: function( tableId, buffer, options ) { - Rico.extend(this, Rico.GridCommon); - Rico.extend(this, Rico.LiveGridMethods); - this.baseInit(); - this.tableId = tableId; - this.buffer = buffer; - this.actionId='_action_'+tableId; - Rico.setDebugArea(tableId+"_debugmsgs"); // if used, this should be a textarea - - Rico.extend(this.options, { - visibleRows : -3, // -1 or 'window'=size grid to client window; -2 or 'data'=size grid to min(window,data); -3 or 'body'=size so body does not have a scrollbar; -4 or 'parent'=size to parent element (e.g. if grid is inside a div) - frozenColumns : 0, - offset : 0, // first row to be displayed - prefetchBuffer : true, // load table on page load? - minPageRows : 2, - maxPageRows : 50, - canSortDefault : true, // can be overridden in the column specs - canFilterDefault : buffer.options.canFilter, // can be overridden in the column specs - canHideDefault : true, // can be overridden in the column specs - - // highlight & selection parameters - highlightElem : 'none',// what gets highlighted/selected (cursorRow, cursorCell, menuRow, menuCell, selection, or none) - highlightSection : 3, // which section gets highlighted (frozen=1, scrolling=2, all=3, none=0) - highlightMethod : 'class', // outline, class, both (outline is less CPU intensive on the client) - highlightClass : Rico.theme.gridHighlightClass || 'ricoLG_selection', - - // export/print parameters - maxPrint : 5000, // max # of rows that can be printed/exported, 0=disable print/export feature - - // heading parameters - headingSort : 'link', // link: make headings a link that will sort column, hover: make headings a hoverset, none: events on headings are disabled - hdrIconsFirst : true, // true: put sort & filter icons before header text, false: after - filterImg : 'filtercol.gif' - }); - // other options: - // sortCol: initial sort column - - this.options.sortHandler = Rico.bind(this,'sortHandler'); - this.options.filterHandler = Rico.bind(this,'filterHandler'); - this.options.onRefreshComplete = Rico.bind(this,'bookmarkHandler'); - this.options.rowOverHandler = Rico.eventHandle(this,'rowMouseOver'); - this.options.mouseDownHandler = Rico.eventHandle(this,'selectMouseDown'); - this.options.mouseOverHandler = Rico.eventHandle(this,'selectMouseOver'); - this.options.mouseUpHandler = Rico.eventHandle(this,'selectMouseUp'); - Rico.extend(this.options, options || {}); - - switch (typeof this.options.visibleRows) { - case 'string': - this.sizeTo=this.options.visibleRows; - switch (this.options.visibleRows) { - case 'data': this.options.visibleRows=-2; break; - case 'body': this.options.visibleRows=-3; break; - case 'parent': this.options.visibleRows=-4; break; - case 'datamax':this.options.visibleRows=-5; break; - default: this.options.visibleRows=-1; break; - } - break; - case 'number': - switch (this.options.visibleRows) { - case -1: this.sizeTo='window'; break; - case -2: this.sizeTo='data'; break; - case -3: this.sizeTo='body'; break; - case -4: this.sizeTo='parent'; break; - case -5: this.sizeTo='datamax'; break; - default: this.sizeTo='fixed'; break; - } - break; - default: - this.sizeTo='body'; - this.options.visibleRows=-3; - break; - } - this.highlightEnabled=this.options.highlightSection>0; - this.pageSize=0; - this.createTables(); - if (this.headerColCnt==0) { - alert('ERROR: no columns found in "'+this.tableId+'"'); - return; - } - this.createColumnArray('LiveGridColumn'); - if (this.options.headingSort=='hover') - this.createHoverSet(); - - this.bookmark=document.getElementById(this.tableId+"_bookmark"); - this.sizeDivs(); - var filterUIrow=this.buffer.options.canFilter ? this.options.FilterLocation : false; - if (typeof(filterUIrow)=='number' && filterUIrow<0) - filterUIrow=this.addHeadingRow('ricoLG_FilterRow'); - this.createDataCells(this.options.visibleRows); - if (this.pageSize == 0) return; - this.buffer.registerGrid(this); - if (this.buffer.setBufferSize) this.buffer.setBufferSize(this.pageSize); - this.scrollTimeout = null; - this.lastScrollPos = 0; - this.attachMenuEvents(); - - // preload the images... - new Image().src = Rico.imgDir+this.options.filterImg; - Rico.log("images preloaded"); - - this.setSortUI( this.options.sortCol, this.options.sortDir ); - this.setImages(); - if (this.listInvisible().length==this.columns.length) - this.columns[0].showColumn(); - this.sizeDivs(); - this.scrollDiv.style.display=""; - if (this.buffer.totalRows>0) - this.updateHeightDiv(); - if (this.options.prefetchBuffer) { - if (this.bookmark) this.bookmark.innerHTML = Rico.getPhraseById('bookmarkLoading'); - if (this.options.canFilterDefault && this.options.getQueryParms) - this.checkForFilterParms(); - this.scrollToRow(this.options.offset); - this.buffer.fetch(this.options.offset); - } - if (typeof(filterUIrow)=='number') - this.createFilters(filterUIrow); - this.scrollEventFunc=Rico.eventHandle(this,'handleScroll'); - this.wheelEventFunc=Rico.eventHandle(this,'handleWheel'); - this.wheelEvent=(Rico.isIE || Rico.isOpera || Rico.isWebKit) ? 'mousewheel' : 'DOMMouseScroll'; - if (this.options.offset && this.options.offset < this.buffer.totalRows) - Rico.runLater(50,this,'scrollToRow',this.options.offset); // Safari requires a delay - this.pluginScroll(); - this.setHorizontalScroll(); - Rico.log("setHorizontalScroll done"); - if (this.options.windowResize) - Rico.runLater(100,this,'pluginWindowResize'); - Rico.log("initialize complete for "+this.tableId); - } -}; - - -Rico.LiveGridMethods = { -/** @lends Rico.LiveGrid# */ - - createHoverSet: function() { - var hdrs=[]; - for( var c=0; c < this.headerColCnt; c++ ) { - if (this.columns[c].sortable) { - hdrs.push(this.columns[c].hdrCellDiv); - } - } - this.hoverSet = new Rico.HoverSet(hdrs); - }, - - checkForFilterParms: function() { - var s=window.location.search; - if (s.charAt(0)=='?') s=s.substring(1); - var pairs = s.split('&'); - for (var i=0; i= this.buffer.totalRows) return -1 - this.unhighlight(); - this.menuIdx=idx; // ensures selection gets cleared when menu is displayed - this.highlight(idx); - var drillValue=this.buffer.getWindowCell(idx.row,masterColNum); - for (var i=3; i 0) { - Rico.log("Data provider returned an error:\n"+Rico.getContentAsString(error[0],this.buffer.isEncoded)); - alert(Rico.getPhraseById("requestError",Rico.getContentAsString(error[0],this.buffer.isEncoded))); - return false; - } - response=response.getElementsByTagName('response')[0]; - var rowsElement = response.getElementsByTagName('rows')[0]; - var col=this.columns[parseInt(colnum,10)]; - var rows = this.buffer.dom2jstable(rowsElement); - var c,opt,v; - if (col.filterType==Rico.ColumnConst.USERFILTER && col.filterOp=='EQ') v=col.filterValues[0]; - Rico.log('filterValuesUpdate: col='+colnum+' rows='+rows.length); - switch (col.format.filterUI.charAt(0)) { - case 'm': - // multi-select - col.mFilter = document.body.appendChild(document.createElement("div")); - col.mFilter.className = 'ricoLG_mFilter' - Rico.hide(col.mFilter); - var contentDiv = col.mFilter.appendChild(document.createElement("div")); - contentDiv.className = 'ricoLG_mFilter_content' - var buttonDiv = col.mFilter.appendChild(document.createElement("div")); - buttonDiv.className = 'ricoLG_mFilter_button' - col.mFilterButton=buttonDiv.appendChild(document.createElement("button")); - col.mFilterButton.innerHTML=Rico.getPhraseById("ok"); - var eventName=Rico.isWebKit ? 'mousedown' : 'click'; - Rico.eventBind(col.filterField,eventName,Rico.eventHandle(col,'mFilterSelectClick')); - Rico.eventBind(col.mFilterButton,'click',Rico.eventHandle(col,'mFilterFinish')); - //col.filterField.options[0].text=$('AllLabel').innerHTML; - tab = contentDiv.appendChild(document.createElement("table")); - tab.border=0; - tab.cellPadding=2; - tab.cellSpacing=0; - //tbody=(tab.tBodies.length==0) ? tab.appendChild(document.createElement("tbody")) : tab.tBodies[0]; - var baseId=this.filterId(colnum)+'_'; - this.createMFilterItem(tab,this.options.FilterAllToken,Rico.getPhraseById("filterAll"),baseId+'all',Rico.eventHandle(col,'mFilterAllClick')); - var handle=Rico.eventHandle(col,'mFilterOtherClick') - for (var i=0; i0) { - c=rows[i][0]; - this.createMFilterItem(tab,c,c || Rico.getPhraseById("filterBlank"),baseId+i,handle); - } - } - col.mFilterInputs=contentDiv.getElementsByTagName('input'); - col.mFilterLabels=contentDiv.getElementsByTagName('label'); - col.mFilterFocus=col.mFilterInputs.length ? col.mFilterInputs[0] : col.mFilterButton; - break; - - case 's': - // drop-down select - for (var i=0; i0) { - c=rows[i][0]; - opt=Rico.addSelectOption(col.filterField,c,c || Rico.getPhraseById("filterBlank")); - if (col.filterType==Rico.ColumnConst.USERFILTER && c==v) opt.selected=true; - } - } - Rico.eventBind(col.filterField,'change',Rico.eventHandle(col,'filterChange')); - break; - } - return true; - }, - - createMFilterItem: function(table,code,description,id,eventHandle) { - var tr=table.insertRow(-1); - tr.vAlign='top'; - if (tr.rowIndex % 2 == 1) tr.className='ricoLG_mFilter_oddrow'; - var td1=tr.insertCell(-1) - var td2=tr.insertCell(-1) - var field=Rico.createFormField(td1,'input','checkbox',id); - field.value=code; - field.checked=true; - var label = td2.appendChild(document.createElement("label")); - label.htmlFor = id; - label.innerHTML=description; - Rico.eventBind(field,'click',eventHandle); - }, - - unplugHighlightEvents: function() { - var s=this.options.highlightSection; - if (s & 1) this.detachHighlightEvents(this.tbody[0]); - if (s & 2) this.detachHighlightEvents(this.tbody[1]); - }, - -/** - * place panel names on first row of grid header (used by LiveGridForms) - */ - insertPanelNames: function(r,start,limit,cellClass) { - Rico.log('insertPanelNames: start='+start+' limit='+limit); - r.className='ricoLG_hdg'; - var lastIdx=-1, span, newCell=null, spanIdx=0; - for( var c=start; c < limit; c++ ) { - if (lastIdx == this.options.columnSpecs[c].panelIdx) { - span++; - } else { - if (newCell) newCell.colSpan=span; - newCell = r.insertCell(-1); - if (cellClass) newCell.className=cellClass; - span=1; - lastIdx=this.options.columnSpecs[c].panelIdx; - newCell.innerHTML=this.options.panels[lastIdx]; - } - } - if (newCell) newCell.colSpan=span; - }, - -/** - * create grid header for table i (if none was provided) - */ - createHdr: function(i,start,limit) { - Rico.log('createHdr: i='+i+' start='+start+' limit='+limit); - var mainRow = this.thead[i].insertRow(-1); - mainRow.id=this.tableId+'_tab'+i+'h_main'; - mainRow.className='ricoLG_hdg'; - for( var c=start; c < limit; c++ ) { - var newCell = mainRow.insertCell(-1); - newCell.innerHTML=this.options.columnSpecs[c].Hdg; - } - }, - -/** - * move header cells in original table to grid - */ - loadHdrSrc: function(hdrSrc) { - var i,h,c,r,newrow,cells; - Rico.log('loadHdrSrc start'); - for (i=0; i<2; i++) { - for (r=0; r 0; c++) - this.thead[c 0; c++) { - if (cells[0].className=='ricoFrozen') { - if (r==this.headerRowIdx) this.options.frozenColumns=c+1; - } else { - h=1; - } - this.thead[h].rows[r].appendChild(cells[0]); - } - } - } - Rico.log('loadHdrSrc end'); - }, - -/** - * Size div elements - */ - sizeDivs: function() { - Rico.log('sizeDivs: '+this.tableId); - //this.cancelMenu(); - this.unhighlight(); - this.baseSizeDivs(); - var firstVisible=this.firstVisible(); - if (this.pageSize == 0 || firstVisible < 0) return; - var totRowHt=this.columns[firstVisible].dataColDiv.offsetHeight; - this.rowHeight = Math.round(totRowHt/this.pageSize); - var scrHt=this.dataHt; - if (this.scrTabWi0 == this.scrTabWi) { - // no scrolling columns - horizontal scroll bar not needed - this.innerDiv.style.height=(this.hdrHt+1)+'px'; - this.scrollDiv.style.overflowX='hidden'; - } else { - this.scrollDiv.style.overflowX='scroll'; - scrHt+=this.options.scrollBarWidth; - } - this.scrollDiv.style.height=scrHt+'px'; - this.innerDiv.style.width=(this.scrWi)+'px'; - this.scrollTab.style.width=(this.scrWi-this.options.scrollBarWidth)+'px'; - //this.resizeDiv.style.height=this.frozenTabs.style.height=this.innerDiv.style.height=(this.hdrHt+this.dataHt+1)+'px'; - this.resizeDiv.style.height=(this.hdrHt+this.dataHt+1)+'px'; - Rico.log('sizeDivs scrHt='+scrHt+' innerHt='+this.innerDiv.style.height+' rowHt='+this.rowHeight+' pageSize='+this.pageSize); - var pad=(this.scrWi-this.scrTabWi < this.options.scrollBarWidth) ? 2 : 0; - this.shadowDiv.style.width=(this.scrTabWi+pad)+'px'; - this.outerDiv.style.height=(this.hdrHt+scrHt)+'px'; - this.setHorizontalScroll(); - }, - - setHorizontalScroll: function() { - var newLeft=(-this.scrollDiv.scrollLeft)+'px'; - this.tabs[1].style.marginLeft=newLeft; - this.tabs[2].style.marginLeft=newLeft; - }, - - remainingHt: function() { - var tabHt; - var winHt=Rico.windowHeight(); - var margin=Rico.isIE ? 15 : 10; - // if there is a horizontal scrollbar take it into account - if (!Rico.isIE && window.frameElement && window.frameElement.scrolling=='yes' && this.sizeTo!='parent') margin+=this.options.scrollBarWidth; - switch (this.sizeTo) { - case 'window': - var divTop=Rico.cumulativeOffset(this.outerDiv).top; - tabHt=Math.max(this.tabs[0].offsetHeight,this.tabs[1].offsetHeight); - Rico.log("remainingHt, winHt="+winHt+' tabHt='+tabHt+' gridY='+divTop); - return winHt-divTop-tabHt-this.options.scrollBarWidth-margin; // allow for scrollbar and some margin - case 'parent': - var offset=this.offsetFromParent(this.outerDiv); - tabHt=Math.max(this.tabs[0].offsetHeight,this.tabs[1].offsetHeight); - if (Rico.isIE) Rico.hide(this.outerDiv); - var parentHt=this.outerDiv.parentNode.offsetHeight; - if (Rico.isIE) Rico.show(this.outerDiv); - Rico.log("remainingHt, parentHt="+parentHt+' gridY='+offset+' winHt='+winHt+' tabHt='+tabHt); - return parentHt - tabHt - offset - this.options.scrollBarWidth; - case 'data': - case 'body': - var bodyHt=Rico.isIE ? document.body.scrollHeight : document.body.offsetHeight; - //alert("remainingHt\n document.height="+document.height+"\n body.offsetHeight="+document.body.offsetHeight+"\n body.scrollHeight="+document.body.scrollHeight+"\n documentElement.scrollHeight="+document.documentElement.scrollHeight); - var remHt=winHt-bodyHt-margin; - if (!Rico.isWebKit) remHt-=this.options.scrollBarWidth; - Rico.log("remainingHt, winHt="+winHt+' pageHt='+bodyHt+' remHt='+remHt); - return remHt; - default: - tabHt=Math.max(this.tabs[0].offsetHeight,this.tabs[1].offsetHeight); - Rico.log("remainingHt, winHt="+winHt+' tabHt='+tabHt); - if (this.sizeTo.slice(-1)=='%') winHt*=parseFloat(this.sizeTo)/100.0; - else if (this.sizeTo.slice(-2)=='px') winHt=parseInt(this.sizeTo,10); - return winHt-tabHt-this.options.scrollBarWidth-margin; // allow for scrollbar and some margin - } - }, - - offsetFromParent: function(element) { - var valueT = 0; - var elParent=element.parentNode; - do { - //Rico.log("offsetFromParent: "+element.tagName+' id='+element.id+' otop='+element.offsetTop); - valueT += element.offsetTop || 0; - element = element.offsetParent; - if (!element || element==null) break; - var p = Rico.getStyle(element, 'position'); - if (element.tagName=='BODY' || element.tagName=='HTML' || p=='absolute') return valueT-elParent.offsetTop; - } while (element != elParent); - return valueT; - }, - - adjustPageSize: function() { - var remHt=this.remainingHt(); - Rico.log('adjustPageSize remHt='+remHt+' lastRow='+this.lastRowPos); - if (remHt > this.rowHeight) - this.autoAppendRows(remHt); - else if (remHt < 0 || this.sizeTo=='data') - this.autoRemoveRows(-remHt); - }, - - setPageSize: function(newRowCount) { - newRowCount=Math.min(newRowCount,this.options.maxPageRows); - newRowCount=Math.max(newRowCount,this.options.minPageRows); - this.sizeTo='fixed'; - var oldSize=this.pageSize; - while (this.pageSize > newRowCount) { - this.removeRow(); - } - while (this.pageSize < newRowCount) { - this.appendBlankRow(); - } - this.finishResize(oldSize); - }, - - pluginWindowResize: function() { - Rico.log("pluginWindowResize"); - this.resizeWindowHandler=Rico.eventHandle(this,'resizeWindow'); - Rico.eventBind(window, "resize", this.resizeWindowHandler, false); - }, - - unplugWindowResize: function() { - if (!this.resizeWindowHandler) return; - Rico.eventUnbind(window,"resize", this.resizeWindowHandler, false); - this.resizeWindowHandler=null; - }, - - resizeWindow: function() { - Rico.log('resizeWindow '+this.tableId+' lastRow='+this.lastRowPos); - if (this.resizeState=='finish') { - Rico.log('resizeWindow postponed'); - this.resizeState='resize'; - return; - } - if (!this.sizeTo || this.sizeTo=='fixed') { - this.sizeDivs(); - return; - } - if (this.sizeTo=='parent' && Rico.getStyle(this.outerDiv.parentNode,'display') == 'none') return; - var oldSize=this.pageSize; - this.adjustPageSize(); - this.finishResize(oldSize); - }, - - finishResize: function(oldSize) { - if (this.pageSize > oldSize && this.buffer.totalRows>0) { - this.isPartialBlank=true; - var adjStart=this.adjustRow(this.lastRowPos); - this.buffer.fetch(adjStart); - } else if (this.pageSize < oldSize) { - if (this.options.onRefreshComplete) this.options.onRefreshComplete(this.contentStartPos,this.contentStartPos+this.pageSize-1); // update bookmark - } - this.resizeState='finish'; - Rico.runLater(20,this,'finishResize2'); - Rico.log('Resize '+this.tableId+' complete. old size='+oldSize+' new size='+this.pageSize); - }, - - finishResize2: function() { - this.sizeDivs(); - this.updateHeightDiv(); - if (this.resizeState=='resize') { - this.resizeWindow(); - } else { - this.resizeState=''; - } - }, - - topOfLastPage: function() { - return Math.max(this.buffer.totalRows-this.pageSize,0); - }, - - updateHeightDiv: function() { - var notdisp=this.topOfLastPage(); - var ht = notdisp ? this.scrollDiv.clientHeight + Math.floor(this.rowHeight * (notdisp + 0.4)) : 1; - Rico.log("updateHeightDiv, ht="+ht+' scrollDiv.clientHeight='+this.scrollDiv.clientHeight+' rowsNotDisplayed='+notdisp); - this.shadowDiv.style.height=ht+'px'; - }, - - autoRemoveRows: function(overage) { - if (!this.rowHeight) return; - var removeCnt=Math.ceil(overage / this.rowHeight); - if (this.sizeTo=='data') - removeCnt=Math.max(removeCnt,this.pageSize-this.buffer.totalRows); - Rico.log("autoRemoveRows overage="+overage+" removeCnt="+removeCnt); - for (var i=0; i= this.buffer.endPos()); - return idx; - }, - - attachHighlightEvents: function(tBody) { - switch (this.options.highlightElem) { - case 'selection': - Rico.eventBind(tBody,"mousedown", this.options.mouseDownHandler, false); - /** @ignore */ - tBody.ondrag = function () { return false; }; - /** @ignore */ - tBody.onselectstart = function () { return false; }; - break; - case 'cursorRow': - case 'cursorCell': - Rico.eventBind(tBody,"mouseover", this.options.rowOverHandler, false); - break; - } - }, - - detachHighlightEvents: function(tBody) { - switch (this.options.highlightElem) { - case 'selection': - Rico.eventUnbind(tBody,"mousedown", this.options.mouseDownHandler, false); - tBody.ondrag = null; - tBody.onselectstart = null; - break; - case 'cursorRow': - case 'cursorCell': - Rico.eventUnbind(tBody,"mouseover", this.options.rowOverHandler, false); - break; - } - }, - -/** - * @return array of objects containing row/col indexes (index values are relative to the start of the window) - */ - getVisibleSelection: function() { - var cellList=[]; - if (this.SelectIdxStart && this.SelectIdxEnd) { - var r1=Math.max(Math.min(this.SelectIdxEnd.row,this.SelectIdxStart.row)-this.buffer.startPos,this.buffer.windowStart); - var r2=Math.min(Math.max(this.SelectIdxEnd.row,this.SelectIdxStart.row)-this.buffer.startPos,this.buffer.windowEnd-1); - var c1=Math.min(this.SelectIdxEnd.column,this.SelectIdxStart.column); - var c2=Math.max(this.SelectIdxEnd.column,this.SelectIdxStart.column); - //Rico.log("getVisibleSelection "+r1+','+c1+' to '+r2+','+c2+' ('+this.SelectIdxStart.row+',startPos='+this.buffer.startPos+',windowPos='+this.buffer.windowPos+',windowEnd='+this.buffer.windowEnd+')'); - for (var r=r1; r<=r2; r++) { - for (var c=c1; c<=c2; c++) - cellList.push({row:r-this.buffer.windowStart,column:c}); - } - } - if (this.SelectCtrl) { - for (var i=0; i=this.buffer.windowStart && this.SelectCtrl[i].row r2) { - this.HideSelection(); - return; - } - var c1=Math.min(this.SelectIdxEnd.column,this.SelectIdxStart.column); - var c2=Math.max(this.SelectIdxEnd.column,this.SelectIdxStart.column); - var top1=this.columns[c1].cell(r1-this.buffer.windowStart).offsetTop; - var cell2=this.columns[c1].cell(r2-this.buffer.windowStart); - var bottom2=cell2.offsetTop+cell2.offsetHeight; - var left1=this.columns[c1].dataCell.offsetLeft; - var left2=this.columns[c2].dataCell.offsetLeft; - var right2=left2+this.columns[c2].dataCell.offsetWidth; - //window.status='updateSelectOutline: '+r1+' '+r2+' top='+top1+' bot='+bottom2; - this.highlightDiv[0].style.top=this.highlightDiv[3].style.top=this.highlightDiv[1].style.top=(this.hdrHt+top1-1) + 'px'; - this.highlightDiv[2].style.top=(this.hdrHt+bottom2-1)+'px'; - this.highlightDiv[3].style.left=(left1-2)+'px'; - this.highlightDiv[0].style.left=this.highlightDiv[2].style.left=(left1-1)+'px'; - this.highlightDiv[1].style.left=(right2-1)+'px'; - this.highlightDiv[0].style.width=this.highlightDiv[2].style.width=(right2-left1-1) + 'px'; - this.highlightDiv[1].style.height=this.highlightDiv[3].style.height=(bottom2-top1) + 'px'; - //this.highlightDiv[0].style.right=this.highlightDiv[2].style.right=this.highlightDiv[1].style.right=()+'px'; - //this.highlightDiv[2].style.bottom=this.highlightDiv[3].style.bottom=this.highlightDiv[1].style.bottom=(this.hdrHt+bottom2) + 'px'; - for (var i=0; i<4; i++) - this.highlightDiv[i].style.display=''; - }, - - HideSelection: function() { - var i; - if (this.options.highlightMethod!='class') { - for (i=0; i r2) return false; - var c1=Math.min(this.SelectIdxEnd.column,this.SelectIdxStart.column); - var c2=Math.max(this.SelectIdxEnd.column,this.SelectIdxStart.column); - var curIdx=this.datasetIndex(cell); - return (r1<=curIdx.row && curIdx.row<=r2 && c1<=curIdx.column && curIdx.column<=c2); - }, - - highlightCell: function(cell) { - Rico.addClass(cell,this.options.highlightClass); - }, - - unhighlightCell: function(cell) { - if (cell==null) return; - Rico.removeClass(cell,this.options.highlightClass); - }, - - selectRow: function(r) { - for (var c=0; c= 0) { - sortDirection=this.columns[colnum].getSortDirection(); - } else { - if (typeof sortDirection!='string') { - sortDirection=Rico.ColumnConst.SORT_ASC; - } else { - sortDirection=sortDirection.toUpperCase(); - if (sortDirection != Rico.ColumnConst.SORT_DESC) sortDirection=Rico.ColumnConst.SORT_ASC; - } - switch (typeof columnNameOrNum) { - case 'string': - colnum=this.findColumnName(columnNameOrNum); - break; - case 'number': - colnum=columnNameOrNum; - break; - } - } - if (typeof(colnum)!='number' || colnum < 0) return; - this.clearSort(); - this.columns[colnum].setSorted(sortDirection); - this.buffer.sortBuffer(colnum); - }, - -/** - * clear sort flag on all columns - */ - clearSort: function() { - for (var x=0;x startPos; - var contentStartPos = viewPrecedesBuffer ? this.buffer.startPos: startPos; - this.contentStartPos = contentStartPos+1; - var contentEndPos = Math.min(this.buffer.startPos + this.buffer.size, startPos + this.pageSize); - this.buffer.setWindow(contentStartPos, contentEndPos); - Rico.log('refreshContents2 '+this.tableId+': cStartPos='+contentStartPos+' cEndPos='+contentEndPos+' vPrecedesBuf='+viewPrecedesBuffer+' b.startPos='+this.buffer.startPos); - if (startPos == this.lastRowPos && !this.isPartialBlank && !this.isBlank) return; - this.isBlank = false; - var onRefreshComplete = this.options.onRefreshComplete; - - if ((startPos + this.pageSize < this.buffer.startPos) || - (this.buffer.startPos + this.buffer.size < startPos) || - (this.buffer.size == 0)) { - this.clearRows(); - if (onRefreshComplete) onRefreshComplete(this.contentStartPos,contentEndPos); // update bookmark - return; - } - - Rico.log('refreshContents: contentStartPos='+contentStartPos+' contentEndPos='+contentEndPos+' viewPrecedesBuffer='+viewPrecedesBuffer); - var rowSize = contentEndPos - contentStartPos; - var blankSize = this.pageSize - rowSize; - var blankOffset = viewPrecedesBuffer ? 0: rowSize; - var contentOffset = viewPrecedesBuffer ? blankSize: 0; - - for (var r=0; r < rowSize; r++) { //initialize what we have - for (var c=0; c < this.columns.length; c++) - this.columns[c].displayValue(r + contentOffset); - } - for (var i=0; i < blankSize; i++) // blank out the rest - this.blankRow(i + blankOffset); - if (this.options.highlightElem=='selection') this.ShowSelection(); - this.isPartialBlank = blankSize > 0; - this.lastRowPos = startPos; - Rico.log("refreshContents complete, startPos="+startPos); - if (onRefreshComplete) onRefreshComplete(this.contentStartPos,contentEndPos); // update bookmark - }, - - scrollToRow: function(rowOffset) { - var p=this.rowToPixel(rowOffset); - Rico.log("scrollToRow, rowOffset="+rowOffset+" pixel="+p); - this.scrollDiv.scrollTop = p; // this causes a scroll event - if ( this.options.onscroll ) - this.options.onscroll( this, rowOffset ); - }, - - scrollUp: function() { - this.moveRelative(-1); - }, - - scrollDown: function() { - this.moveRelative(1); - }, - - pageUp: function() { - this.moveRelative(-this.pageSize); - }, - - pageDown: function() { - this.moveRelative(this.pageSize); - }, - - adjustRow: function(rowOffset) { - var notdisp=this.topOfLastPage(); - if (notdisp == 0 || !rowOffset) return 0; - return Math.min(notdisp,rowOffset); - }, - - rowToPixel: function(rowOffset) { - return this.adjustRow(rowOffset) * this.rowHeight; - }, - -/** - * @returns row to display at top of scroll div - */ - pixeltorow: function(p) { - var notdisp=this.topOfLastPage(); - if (notdisp == 0) return 0; - var prow=parseInt(p/this.rowHeight,10); - return Math.min(notdisp,prow); - }, - - moveRelative: function(relOffset) { - var newoffset=Math.max(this.scrollDiv.scrollTop+relOffset*this.rowHeight,0); - newoffset=Math.min(newoffset,this.scrollDiv.scrollHeight); - //Rico.log("moveRelative, newoffset="+newoffset); - this.scrollDiv.scrollTop=newoffset; - }, - - pluginScroll: function() { - if (this.scrollPluggedIn) return; - Rico.log("pluginScroll: wheelEvent="+this.wheelEvent); - Rico.eventBind(this.scrollDiv,"scroll",this.scrollEventFunc, false); - for (var t=0; t<2; t++) - Rico.eventBind(this.tabs[t],this.wheelEvent,this.wheelEventFunc, false); - this.scrollPluggedIn=true; - }, - - unplugScroll: function() { - if (!this.scrollPluggedIn) return; - Rico.log("unplugScroll"); - Rico.eventUnbind(this.scrollDiv,"scroll", this.scrollEventFunc , false); - for (var t=0; t<2; t++) - Rico.eventUnbind(this.tabs[t],this.wheelEvent,this.wheelEventFunc, false); - this.scrollPluggedIn=false; - }, - - handleWheel: function(e) { - var delta = 0; - if (e.wheelDelta) { - if (Rico.isOpera) - delta = e.wheelDelta/120; - else if (Rico.isWebKit) - delta = -e.wheelDelta/12; - else - delta = -e.wheelDelta/120; - } else if (e.detail) { - delta = e.detail/3; /* Mozilla/Gecko */ - } - if (delta) this.moveRelative(delta); - Rico.eventStop(e); - return false; - }, - - handleScroll: function(e) { - if ( this.scrollTimeout ) - clearTimeout( this.scrollTimeout ); - this.setHorizontalScroll(); - var scrtop=this.scrollDiv.scrollTop; - var vscrollDiff = this.lastScrollPos-scrtop; - if (vscrollDiff == 0.00) return; - var newrow=this.pixeltorow(scrtop); - if (newrow == this.lastRowPos && !this.isPartialBlank && !this.isBlank) return; - var stamp1 = new Date(); - Rico.log("handleScroll, newrow="+newrow+" scrtop="+scrtop); - if (this.options.highlightElem=='selection') this.HideSelection(); - this.buffer.fetch(newrow); - if (this.options.onscroll) this.options.onscroll(this, newrow); - this.scrollTimeout = Rico.runLater(1200,this,'scrollIdle'); - this.lastScrollPos = this.scrollDiv.scrollTop; - var stamp2 = new Date(); - //Rico.log("handleScroll, time="+(stamp2.getTime()-stamp1.getTime())); - }, - - scrollIdle: function() { - if ( this.options.onscrollidle ) - this.options.onscrollidle(); - } - -}; - - -Rico.LiveGridColumn = function(grid,colIdx,hdrInfo,tabIdx) { - this.initialize(grid,colIdx,hdrInfo,tabIdx); -}; - -Rico.LiveGridColumn.prototype = -/** @lends Rico.LiveGridColumn# */ -{ -/** - * Implements a LiveGrid column. Also contains static properties used by SimpleGrid columns. - * @extends Rico.TableColumnBase - * @constructs - */ -initialize: function(liveGrid,colIdx,hdrInfo,tabIdx) { - Rico.extend(this, new Rico.TableColumnBase()); - this.baseInit(liveGrid,colIdx,hdrInfo,tabIdx); - this.buffer=liveGrid.buffer; - if (typeof(this.format.type)!='string' || this.format.EntryType=='tinyMCE') this.format.type='raw'; - if (typeof this.isNullable!='boolean') this.isNullable = /number|date/.test(this.format.type); - this.isText = /raw|text|showTags/.test(this.format.type); - Rico.log(" sortable="+this.sortable+" filterable="+this.filterable+" hideable="+this.hideable+" isNullable="+this.isNullable+' isText='+this.isText); - this.fixHeaders(this.liveGrid.tableId, this.options.hdrIconsFirst); - if (this['format_'+this.format.type]) { - this._format=this['format_'+this.format.type]; - //this._format=Rico.bind(this,'format_'+this.format.type); - } - if (this.format.control) { - // copy all properties/methods that start with '_' - if (typeof this.format.control=='string') { - this.format.control=eval(this.format.control); - } - for (var property in this.format.control) { - if (property.charAt(0)=='_') { - Rico.log("Copying control property "+property+ ' to ' + this); - this[property] = this.format.control[property]; - } - } - } -}, - -/** - * Sorts the column in ascending order - */ -sortAsc: function() { - this.setColumnSort(Rico.ColumnConst.SORT_ASC); -}, - -/** - * Sorts the column in descending order - */ -sortDesc: function() { - this.setColumnSort(Rico.ColumnConst.SORT_DESC); -}, - -/** - * Sorts the column in the specified direction - * @param direction must be one of Rico.ColumnConst.UNSORTED, .SORT_ASC, or .SORT_DESC - */ -setColumnSort: function(direction) { - this.liveGrid.clearSort(); - this.setSorted(direction); - if (this.liveGrid.options.saveColumnInfo.sort) - this.liveGrid.setCookie(); - if (this.options.sortHandler) - this.options.sortHandler(); -}, - -/** - * @returns true if this column is allowed to be sorted - */ -isSortable: function() { - return this.sortable; -}, - -/** - * @returns true if this column is currently sorted - */ -isSorted: function() { - return this.currentSort != Rico.ColumnConst.UNSORTED; -}, - -/** - * @returns Rico.ColumnConst.UNSORTED, .SORT_ASC, or .SORT_DESC - */ -getSortDirection: function() { - return this.currentSort; -}, - -/** - * toggle the sort sequence for this column - */ -toggleSort: function() { - if (this.buffer && this.buffer.totalRows==0) return; - if (this.currentSort == Rico.ColumnConst.SORT_ASC) - this.sortDesc(); - else - this.sortAsc(); -}, - -/** - * Flags that this column is not sorted - */ -setUnsorted: function() { - this.setSorted(Rico.ColumnConst.UNSORTED); -}, - -/** - * Flags that this column is sorted, but doesn't actually carry out the sort - * @param direction must be one of Rico.ColumnConst.UNSORTED, .SORT_ASC, or .SORT_DESC - */ -setSorted: function(direction) { - this.currentSort = direction; -}, - -/** - * @returns true if this column is allowed to be filtered - */ -canFilter: function() { - return this.filterable; -}, - -/** - * @returns a textual representation of how this column is filtered - */ -getFilterText: function() { - var vals=[]; - for (var i=0; i= '+vals[0]; - case 'LIKE': return Rico.getPhraseById('filterLike',vals[0]); - case 'NULL': return Rico.getPhraseById('filterEmpty'); - case 'NOTNULL': return Rico.getPhraseById('filterNotEmpty'); - } - return '?'; -}, - -/** - * @returns returns the query string representation of the filter - */ -getFilterQueryParm: function() { - if (this.filterType == Rico.ColumnConst.UNFILTERED) return ''; - var retval='&f['+this.index+'][op]='+this.filterOp; - retval+='&f['+this.index+'][len]='+this.filterValues.length; - for (var i=0; i 0) { - var newText=newLabels.join(', '); - this.filterField.options[0].text=newText; - this.filterField.title=newText; - Rico.hide(this.mFilter); - this.mFilterChange=false; - this.setFilter('EQ',newValues,Rico.ColumnConst.USERFILTER,Rico.bind(this,'mFilterReset')); - } else { - alert('Please select at least one value'); - } -}, - -mFilterReset: function() { - var newText=this.mFilterLabels[0].innerHTML; // all - this.filterField.options[0].text=newText; - this.filterField.title=newText; -}, - -mFilterAllClick: function(e) { - var allChecked=this.mFilterInputs[0].checked; - for (var i=1; i/g,'>'); -}, - -format_number: function(v) { - if (typeof v=='undefined' || v=='' || v==null) - return ' '; - else - return Rico.formatNumber(v,this.format); -}, - -format_datetime: function(v) { - if (typeof v=='undefined' || v=='' || v==null) - return ' '; - else { - var d=Rico.setISO8601(v); - if (!d) return v; - return (this.format.prefix || '')+Rico.formatDate(d,this.format.dateFmt || 'translateDateTime')+(this.format.suffix || ''); - } -}, - -// converts GMT/UTC to local time -format_UTCasLocalTime: function(v) { - if (typeof v=='undefined' || v=='' || v==null) - return ' '; - else { - var tz=new Date(); - var d=Rico.setISO8601(v,-tz.getTimezoneOffset()); - if (!d) return v; - return (this.format.prefix || '')+Rico.formatDate(d,this.format.dateFmt || 'translateDateTime')+(this.format.suffix || ''); - } -}, - -format_date: function(v) { - if (typeof v=='undefined' || v==null || v=='') - return ' '; - else { - var d=Rico.setISO8601(v); - if (!d) return v; - return (this.format.prefix || '')+Rico.formatDate(d,this.format.dateFmt || 'translateDate')+(this.format.suffix || ''); - } -}, - -fixHeaders: function(prefix, iconsfirst) { - if (this.sortable) { - var handler=Rico.eventHandle(this,'toggleSort'); - switch (this.options.headingSort) { - case 'link': - var a=Rico.wrapChildren(this.hdrCellDiv,'ricoSort',undefined,'a'); - a.href = "javascript:void(0)"; - Rico.eventBind(a,"click", handler); - break; - case 'hover': - Rico.eventBind(this.hdrCellDiv,"click", handler); - break; - } - } - this.imgFilter = document.createElement('img'); - this.imgFilter.style.display='none'; - this.imgFilter.src=Rico.imgDir+this.options.filterImg; - this.imgFilter.className='ricoLG_HdrIcon'; - this.imgSort = document.createElement('span'); - this.imgSort.style.display='none'; - if (iconsfirst) { - this.hdrCellDiv.insertBefore(this.imgSort,this.hdrCellDiv.firstChild); - this.hdrCellDiv.insertBefore(this.imgFilter,this.hdrCellDiv.firstChild); - } else { - this.hdrCellDiv.appendChild(this.imgFilter); - this.hdrCellDiv.appendChild(this.imgSort); - } - if (!this.format.filterUI) { - Rico.eventBind(this.imgFilter, 'click', Rico.eventHandle(this,'filterClick'), false); - } -}, - -filterClick: function(e) { - if (this.filterType==Rico.ColumnConst.USERFILTER && this.filterOp=='LIKE') { - this.liveGrid.openKeyword(this.index); - } -}, - -getValue: function(windowRow) { - return this.buffer.getWindowCell(windowRow,this.index); -}, - -getBufferAttr: function(windowRow) { - return this.buffer.getWindowAttr(windowRow,this.index); -}, - -setValue: function(windowRow,newval) { - this.buffer.setWindowValue(windowRow,this.index,newval); -}, - -_format: function(v) { - return v; -}, - -_display: function(v,gridCell) { - gridCell.innerHTML=this._format(v); -}, - -_export: function(v) { - return this._format(v); -}, - -exportBuffer: function(bufRow) { - return this._export(this.buffer.getValue(bufRow,this.index)); -}, - -displayValue: function(windowRow) { - var bufval=this.getValue(windowRow); - if (bufval==null) { - this.clearCell(windowRow); - return; - } - var gridCell=this.cell(windowRow); - this._display(bufval,gridCell,windowRow); - var acceptAttr=this.buffer.options.acceptAttr; - if (acceptAttr.length==0) return; - var bufAttr=this.getBufferAttr(windowRow); - if (bufAttr==null) return; - for (var k=0; k=-1) { - var offset=this.pendingRequest; - Rico.log("ajaxUpdate: found pending request for offset="+offset); - this.pendingRequest=-2; - this.fetch(offset); - } - }, - - // used by both XML and SQL buffers - processResponseXML: function(startPos,request) { - // The response text may contain META DATA for debugging if client side debugging is enabled in VS - var xmlDoc = request.responseXML; - if (request.responseText.substring(0, 4) == ""); - if (nEnd == -1) { - this.liveGrid.showMsg('Web server error - client side debugging may be enabled'); - return false; - } - xmlDoc = Rico.createXmlDocument(); - xmlDoc.loadXML(request.responseText.substring(nEnd+3)); - } - - if (!xmlDoc) { - alert("Data provider returned an invalid XML response"); - Rico.log("Data provider returned an invalid XML response"); - return false; - } - - // process children of - var response = xmlDoc.getElementsByTagName("ajax-response"); - if (response == null || response.length != 1) return false; - this.rcvdRows = 0; - this.rcvdRowCount = false; - var ajaxResponse=response[0]; - var debugtags = ajaxResponse.getElementsByTagName('debug'); - for (var i=0; i 0) { - var msg=Rico.getContentAsString(error[0],this.options.isEncoded); - alert("Data provider returned an error:\n"+msg); - Rico.log("Data provider returned an error:\n"+msg); - return false; - } - var rowsElement = ajaxResponse.getElementsByTagName('rows')[0]; - if (!rowsElement) { - Rico.log("ajaxUpdate: invalid response"); - this.liveGrid.showMsg(Rico.getPhraseById("invalidResponse")); - return false; - } - var rowcnttags = ajaxResponse.getElementsByTagName('rowcount'); - if (rowcnttags && rowcnttags.length==1) { - this.rowcntContent = Rico.getContentAsString(rowcnttags[0],this.options.isEncoded); - this.rcvdRowCount = true; - this.foundRowCount = true; - Rico.log("ajaxUpdate: found RowCount="+this.rowcntContent); - } - - // process - this.updateUI = rowsElement.getAttribute("update_ui") == "true"; - this.rcvdOffset = rowsElement.getAttribute("offset"); - Rico.log("ajaxUpdate: rcvdOffset="+this.rcvdOffset); - var newRows = this.dom2jstable(rowsElement); - var newAttr = (this.options.acceptAttr.length > 0) ? this.dom2jstableAttr(rowsElement) : false; - this.rcvdRows = newRows.length; - this.updateBuffer(startPos, newRows, newAttr); - return true; - }, - - processResponseJSON: function(startPos,request) { - var json = Rico.getJSON(request); - if (!json || json == null) { - alert("Data provider returned an invalid JSON response"); - Rico.log("Data provider returned an invalid JSON response"); - return false; - } - - if (json.debug) { - for (var i=0; i this.sessionEndTime) { - this.displaySessionTimer(Rico.getPhraseById("sessionExpired")); - this.timerMsg.style.backgroundColor="red"; - this.sessionExpired=true; - } else { - var timeRemaining=Math.ceil((this.sessionEndTime - now) / 60000); - this.displaySessionTimer(timeRemaining); - this.sessionTimer=Rico.runLater(10000,this,'updateSessionTimer'); - } - }, - - displaySessionTimer: function(msg) { - this.timerMsg.innerHTML=' '+msg+' '; - }, - - /** - * Update the grid with fresh data from the database, maintaining scroll position. - * @param resetRowCount indicates whether the total row count should be refreshed as well - */ - refresh: function(resetRowCount) { - var lastGridPos=this.liveGrid.lastRowPos; - this.clear(); - if (resetRowCount) { - this.setTotalRows(0); - this.foundRowCount = false; - } - this.liveGrid.clearBookmark(); - this.liveGrid.clearRows(); - this.fetch(lastGridPos); - }, - - /** - * Fetch data from database. - * @param offset position (row) within the dataset (-1=clear existing buffer before issuing request) - */ - fetch: function(offset) { - Rico.log("AjaxSQL fetch: offset="+offset+', lastOffset='+this.lastOffset); - if (this.processingRequest) { - Rico.log("AjaxSQL fetch: queue request"); - this.pendingRequest=offset; - return; - } - if (offset < 0) { - this.clear(); - this.setTotalRows(0); - this.foundRowCount = false; - offset=0; - } - var lastOffset = this.lastOffset; - this.lastOffset = offset; - if (this.isInRange(offset)) { - Rico.log("AjaxSQL fetch: in buffer"); - this.liveGrid.refreshContents(offset); - if (offset > lastOffset) { - if (offset+this.liveGrid.pageSize < this.endPos()-this.nearLimit) return; - if (this.endPos()==this.totalRows && this.foundRowCount) return; - } else if (offset < lastOffset) { - if (offset > this.startPos+this.nearLimit) return; - if (this.startPos==0) return; - } else return; - } - if (offset >= this.totalRows && this.foundRowCount) return; - - this.processingRequest=true; - Rico.log("AjaxSQL fetch: processing offset="+offset); - var bufferStartPos = this.getFetchOffset(offset); - var fetchSize = this.getFetchSize(bufferStartPos); - var partialLoaded = false; - - this.liveGrid.showMsg(this.options.waitMsg); - this.timeoutHandler = Rico.runLater(this.options.bufferTimeout, this, 'handleTimedOut'); - this.ajaxOptions.parameters = this.formQueryHashSQL(bufferStartPos,fetchSize,this.options.fmt); - this.requestCount++; - Rico.log('sending req #'+this.requestCount); - if (typeof this.dataSource=='string') { - this.ajaxOptions.onComplete = Rico.bind(this,'ajaxUpdate',bufferStartPos); - new Rico.ajaxRequest(this.dataSource, this.ajaxOptions); - } else { - this.ajaxOptions.onComplete = Rico.bind(this,'jsUpdate',bufferStartPos); - this.dataSource(this.ajaxOptions); - } - }, - - formQueryHashSQL: function(startPos,fetchSize,fmt) { - var queryHash=this.formQueryHashXML(startPos,fetchSize); - queryHash[this.liveGrid.actionId]="query"; - if (fmt) queryHash._fmt=fmt; - - // sort - Rico.extend(queryHash,this.sortParm); - - // filters - for (var n=0; n= this.startPos) { //appending - var endFetchOffset = this.maxFetchSize + adjustedOffset; - adjustedSize = endFetchOffset - adjustedOffset; - if(adjustedOffset == 0 && adjustedSize < this.maxFetchSize) - adjustedSize = this.maxFetchSize; - Rico.log("getFetchSize/append, adjustedSize="+adjustedSize+" adjustedOffset="+adjustedOffset+' endFetchOffset='+endFetchOffset); - } else { //prepending - adjustedSize = Math.min(this.startPos - adjustedOffset,this.maxFetchSize); - } - return adjustedSize; - }, - - getFetchOffset: function(offset) { - var adjustedOffset = offset; - if (offset > this.startPos) - adjustedOffset = Math.max(offset, this.endPos()); //appending - else if (offset + this.maxFetchSize >= this.startPos) - adjustedOffset = Math.max(this.startPos - this.maxFetchSize, 0); //prepending - return adjustedOffset; - }, - - updateBuffer: function(start, newRows, newAttr) { - Rico.log("updateBuffer: start="+start+", # of rows="+this.rcvdRows); - if (this.rows.length == 0) { // initial load - this.rows = newRows; - this.attr = newAttr; - this.startPos = start; - } else if (start > this.startPos) { //appending - if (this.startPos + this.rows.length < start) { - this.rows = newRows; - this.attr = newAttr; - this.startPos = start; - } else { - this.rows = this.rows.concat( newRows.slice(0, newRows.length)); - if (this.attr) this.attr = this.attr.concat( newAttr.slice(0, newAttr.length)); - if (this.rows.length > this.maxBufferSize) { - var fullSize = this.rows.length; - this.rows = this.rows.slice(this.rows.length - this.maxBufferSize, this.rows.length); - if (this.attr) this.attr = this.attr.slice(this.attr.length - this.maxBufferSize, this.attr.length); - this.startPos = this.startPos + (fullSize - this.rows.length); - } - } - } else { //prepending - if (start + newRows.length < this.startPos) { - this.rows = newRows; - } else { - this.rows = newRows.slice(0, this.startPos).concat(this.rows); - if (this.maxBufferSize && this.rows.length > this.maxBufferSize) - this.rows = this.rows.slice(0, this.maxBufferSize); - } - this.startPos = start; - } - this.size = this.rows.length; - }, - - sortBuffer: function(colnum) { - this.sortParm={}; - var col=this.liveGrid.columns[colnum]; - if (this.options.sortParmFmt) { - this.sortParm['sort_col']=col[this.options.sortParmFmt]; - this.sortParm['sort_dir']=col.getSortDirection(); - } else { - this.sortParm['s'+colnum]=col.getSortDirection(); - } - this.clear(); - }, - - printAllSQL: function(exportType) { - var parms=this.formQueryHashSQL(0,this.liveGrid.options.maxPrint,exportType); - parms.hidden=this.liveGrid.listInvisible('index').join(','); - var url=this.dataSource+'?'+Rico.toQueryString(parms); - window.open(url,'',this.liveGrid.options.exportWindow); - }, - - printVisibleSQL: function(exportType) { - var parms=this.formQueryHashSQL(this.liveGrid.contentStartPos-1, this.liveGrid.pageSize, exportType); - parms.hidden=this.liveGrid.listInvisible('index').join(','); - var url=this.dataSource+'?'+Rico.toQueryString(parms); - window.open(url,'',this.liveGrid.options.exportWindow); - }, - - // for datasource that is a javascript function - _printAll: function(exportType) { - this.liveGrid.exportStart(); - this.ajaxOptions.parameters = this.formQueryHashSQL(0,this.liveGrid.options.maxPrint); - this.ajaxOptions.onComplete = Rico.bind(this,'_jsExport',exportType); - this.dataSource(this.ajaxOptions); - }, - - _jsExport: function(exportType, newRows, newAttr, totalRows, errMsg) { - Rico.log("_jsExport: "+arguments.length); - if (errMsg) { - Rico.log("_jsExport: received error="+errMsg); - this.liveGrid.showMsg(Rico.getPhraseById("requestError",errMsg)); - return; - } - this.exportBuffer(newRows,0); - this.liveGrid.exportFinish(exportType); - } - -}; - -Rico.includeLoaded('ricoLiveGridAjax.js'); diff --git a/ricoClient/js/ricoLiveGridControls.js b/ricoClient/js/ricoLiveGridControls.js deleted file mode 100644 index 6299a48..0000000 --- a/ricoClient/js/ricoLiveGridControls.js +++ /dev/null @@ -1,424 +0,0 @@ -/* - * (c) 2005-2009 Richard Cowin (http://openrico.org) - * (c) 2005-2009 Matt Brown (http://dowdybrown.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this - * file except in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the - * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions - * and limitations under the License. - */ - -// ----------------------------------------------------- -// -// Custom formatting for LiveGrid columns -// -// columnSpecs Usage: { type:'control', control:new Rico.TableColumn.CONTROLNAME() } -// -// ----------------------------------------------------- - -Rico.TableColumn = {}; - -Rico.TableColumn.checkboxKey = function(showKey) { - this.initialize(showKey); -} - -Rico.TableColumn.checkboxKey.prototype = { -/** - * @class Custom formatting for a LiveGrid column. - * Display unique key column as: <checkbox> <key value> - * and keep track of which keys the user selects - * Key values should not contain <, >, or & - * @constructs - */ - initialize: function(showKey) { - this._checkboxes=[]; - this._spans=[]; - this._KeyHash={}; - this._showKey=showKey; - }, - - _create: function(gridCell,windowRow) { - this._checkboxes[windowRow]=Rico.createFormField(gridCell,'input','checkbox',this.liveGrid.tableId+'_chkbox_'+this.index+'_'+windowRow); - this._spans[windowRow]=Rico.createFormField(gridCell,'span',null,this.liveGrid.tableId+'_desc_'+this.index+'_'+windowRow); - this._clear(gridCell,windowRow); - Rico.eventBind(this._checkboxes[windowRow], 'click', Rico.eventHandle(this,'_onclick')); - }, - - _onclick: function(e) { - var elem=Event.element(e); - var windowRow=parseInt(elem.id.substr((elem.id.lastIndexOf('_',elem.id.length)+1))); //faster than split - var v=this.getValue(windowRow); - if (elem.checked) - this._addChecked(v); - else - this._remChecked(v); - }, - - _clear: function(gridCell,windowRow) { - var box=this._checkboxes[windowRow]; - box.checked=false; - box.style.display='none'; - this._spans[windowRow].innerHTML=''; - }, - - _display: function(v,gridCell,windowRow) { - var box=this._checkboxes[windowRow]; - box.style.display=''; - box.checked=this._KeyHash[v]; - if (this._showKey) this._spans[windowRow].innerHTML=v; - }, - - _SelectedKeys: function() { - return Rico.keys(this._KeyHash); - }, - - _addChecked: function(k){ - this._KeyHash[k]=1; - }, - - _remChecked: function(k){ - delete this._KeyHash[k]; - } -} - - -Rico.TableColumn.checkbox = function(checkedValue, uncheckedValue, defaultValue, readOnly) -{ - this.initialize(checkedValue, uncheckedValue, defaultValue, readOnly); -} - -Rico.TableColumn.checkbox.prototype = { -/** - * @class display checkboxes for two-valued column (e.g. yes/no) - * @constructs - */ - initialize: function(checkedValue, uncheckedValue, defaultValue, readOnly) { - this._checkedValue=checkedValue; - this._uncheckedValue=uncheckedValue; - this._defaultValue=defaultValue || false; - this._readOnly=readOnly || false; - this._checkboxes=[]; - }, - - _create: function(gridCell,windowRow) { - this._checkboxes[windowRow]=Rico.createFormField(gridCell,'input','checkbox',this.liveGrid.tableId+'_chkbox_'+this.index+'_'+windowRow); - this._clear(gridCell,windowRow); - if (this._readOnly) - this._checkboxes[windowRow].disabled=true; - else - Rico.eventBind(this._checkboxes[windowRow], 'click', Rico.eventHandle(this,'_onclick')); - }, - - _onclick: function(e) { - var elem=Event.element(e); - var windowRow=parseInt(elem.id.substr((elem.id.lastIndexOf('_',elem.id.length)+1))); //faster than split - var newval=elem.checked ? this._checkedValue : this._uncheckedValue; - this.setValue(windowRow,newval); - }, - - _clear: function(gridCell,windowRow) { - var box=this._checkboxes[windowRow]; - box.checked=this._defaultValue; - box.style.display='none'; - }, - - _display: function(v,gridCell,windowRow) { - var box=this._checkboxes[windowRow]; - box.style.display=''; - box.checked=(v==this._checkedValue); - } - -} - - -Rico.TableColumn.textbox = function(boxSize, boxMaxLen, readOnly) { - this.initialize(boxSize, boxMaxLen, readOnly); -} - -Rico.TableColumn.textbox.prototype = { -/** - * @class display value in a text box - * @constructs - */ - initialize: function(boxSize, boxMaxLen, readOnly) { - this._boxSize=boxSize; - this._boxMaxLen=boxMaxLen; - this._readOnly=readOnly || false; - this._textboxes=[]; - }, - - _create: function(gridCell,windowRow) { - var box=Rico.createFormField(gridCell,'input','text',this.liveGrid.tableId+'_txtbox_'+this.index+'_'+windowRow); - box.size=this._boxSize; - box.maxLength=this._boxMaxLen; - this._textboxes[windowRow]=box; - this._clear(gridCell,windowRow); - if (this._readOnly) - box.disabled=true; - else - Rico.eventBind(box, 'change', Rico.eventHandle(this,'_onchange')); - }, - - _onchange: function(e) { - var elem=Event.element(e); - var windowRow=parseInt(elem.id.substr((elem.id.lastIndexOf('_',elem.id.length)+1))); //faster than split - this.setValue(windowRow,elem.value); - }, - - _clear: function(gridCell,windowRow) { - var box=this._textboxes[windowRow]; - box.value=''; - box.style.display='none'; - }, - - _display: function(v,gridCell,windowRow) { - var box=this._textboxes[windowRow]; - box.style.display=''; - box.value=v; - } - -} - - -Rico.TableColumn.HighlightCell = function(chkcol,chkval,highlightColor,highlightBackground,chkop) { - this.initialize(chkcol,chkval,highlightColor,highlightBackground,chkop); -} - -Rico.TableColumn.HighlightCell.prototype = { -/** - * @class highlight a grid cell when a particular value is present in the specified column - * @constructs - */ - initialize: function(chkcol,chkval,highlightColor,highlightBackground,chkop) { - this._chkcol=chkcol; - this._chkval=chkval; - this._chkop=chkop; - this._highlightColor=highlightColor; - this._highlightBackground=highlightBackground; - }, - - _clear: function(gridCell,windowRow) { - gridCell.style.color=''; - gridCell.style.backgroundColor=''; - gridCell.innerHTML=' '; - }, - - _display: function(v,gridCell,windowRow) { - var gridval=this.liveGrid.buffer.getWindowValue(windowRow,this._chkcol); - var match; - switch(this._chkop){ - case '!=': - match=(gridval!=this._chkval); - break; - case '>': - match=(gridval>this._chkval); - break; - case '<': - match=(gridval=': - match=(gridval>=this._chkval); - break; - case '<=': - match=(gridval<=this._chkval); - break; - case 'abs>': - match=(Math.abs(gridval)>this._chkval); - break; - case 'abs<': - match=(Math.abs(gridval)=': - match=(Math.abs(gridval)>=this._chkval); - break; - case 'abs<=': - match=(Math.abs(gridval)<=this._chkval); - break; - default: - match=(gridval==this._chkval); - break; - } - gridCell.style.color=match ? this._highlightColor : ''; - gridCell.style.backgroundColor=match ? this._highlightBackground : ''; - gridCell.innerHTML=this._format(v); - } -} - - -Rico.TableColumn.bgColor = function() { -} - -Rico.TableColumn.bgColor.prototype = { -/** - * @class database value contains a css color name/value - */ - - _clear: function(gridCell,windowRow) { - gridCell.style.backgroundColor=''; - }, - - _display: function(v,gridCell,windowRow) { - gridCell.style.backgroundColor=v; - } - -} - - -Rico.TableColumn.link = function(href,target,linktext) { - this.initialize(href,target,linktext); -} - -Rico.TableColumn.link.prototype = { -/** - * @class database value contains a url to another page - * @constructs - */ - initialize: function(href,target,linktext) { - this._href=href; - this._target=target; - this._linktext=linktext; - this._anchors=[]; - }, - - _create: function(gridCell,windowRow) { - this._anchors[windowRow]=Rico.createFormField(gridCell,'a',null,this.liveGrid.tableId+'_a_'+this.index+'_'+windowRow); - if (this._target) this._anchors[windowRow].target=this._target; - this._clear(gridCell,windowRow); - }, - - _clear: function(gridCell,windowRow) { - this._anchors[windowRow].href=''; - this._anchors[windowRow].innerHTML=''; - }, - - _display: function(v,gridCell,windowRow) { - var getWindowValue=Rico.bind(this.liveGrid.buffer,'getWindowValue'); - var href=this._href=='self' ? v : this._href.replace(/\{\d+\}/g, - function ($1) { - var colIdx=parseInt($1.substr(1),10); - return encodeURIComponent(getWindowValue(windowRow,colIdx)); - } - ); - var desc=this._linktext || v; - if (href && desc) { - this._anchors[windowRow].href=href; - this._anchors[windowRow].innerHTML=desc; - } else { - this._clear(gridCell,windowRow); - } - } - -}; - - -Rico.TableColumn.image = function(prefix,suffix) { - this.initialize(prefix,suffix); -}; - -Rico.TableColumn.image.prototype = { -/** - * @class database value contains a url to an image - * @constructs - */ - initialize: function(prefix,suffix) { - this._img=[]; - this._prefix=prefix || ''; - this._suffix=suffix || ''; - }, - - _create: function(gridCell,windowRow) { - this._img[windowRow]=Rico.createFormField(gridCell,'img',null,this.liveGrid.tableId+'_img_'+this.index+'_'+windowRow); - this._clear(gridCell,windowRow); - }, - - _clear: function(gridCell,windowRow) { - var img=this._img[windowRow]; - img.style.display='none'; - img.src=''; - }, - - _display: function(v,gridCell,windowRow) { - var img=this._img[windowRow]; - this._img[windowRow].src=this._prefix+v+this._suffix; - img.style.display=''; - } - -}; - - -Rico.TableColumn.lookup = function(map, defaultCode, defaultDesc) { - this.initialize(map, defaultCode, defaultDesc); -}; - -Rico.TableColumn.lookup.prototype = { -/** - * @class map a database value to a display value - * @constructs - */ - initialize: function(map, defaultCode, defaultDesc) { - this._map=map; - this._defaultCode=defaultCode || ''; - this._defaultDesc=defaultDesc || ' '; - this._sortfunc=Rico.bind(this,'_sortvalue'); - this._codes=[]; - this._descriptions=[]; - }, - - _create: function(gridCell,windowRow) { - this._descriptions[windowRow]=Rico.createFormField(gridCell,'span',null,this.liveGrid.tableId+'_desc_'+this.index+'_'+windowRow); - this._codes[windowRow]=Rico.createFormField(gridCell,'input','hidden',this.liveGrid.tableId+'_code_'+this.index+'_'+windowRow); - this._clear(gridCell,windowRow); - }, - - _clear: function(gridCell,windowRow) { - this._codes[windowRow].value=this._defaultCode; - this._descriptions[windowRow].innerHTML=this._defaultDesc; - }, - - _sortvalue: function(v) { - return this._getdesc(v).replace(/&/g, '&').replace(/</g,'<').replace(/>/g,'>').replace(/ /g,' '); - }, - - _getdesc: function(v) { - var desc=this._map[v]; - return (typeof desc=='string') ? desc : this._defaultDesc; - }, - - _export: function(v) { - return this._getdesc(v); - }, - - _display: function(v,gridCell,windowRow) { - this._codes[windowRow].value=v; - this._descriptions[windowRow].innerHTML=this._getdesc(v); - } - -}; - - - -Rico.TableColumn.MultiLine = function() { -}; - -Rico.TableColumn.MultiLine.prototype = { -/** - * @class Fix issues with multiline content in IE - */ - _display: function(v,gridCell,windowRow) { - var newdiv = document.createElement("div"); - newdiv.innerHTML = this._format(v); - newdiv.style.height='100%'; - if (gridCell.firstChild) - gridCell.replaceChild(newdiv, gridCell.firstChild); - else - gridCell.appendChild(newdiv); - } - -}; - -Rico.includeLoaded('ricoLiveGridControls.js'); diff --git a/ricoClient/js/ricoLiveGridForms.js b/ricoClient/js/ricoLiveGridForms.js deleted file mode 100644 index c675913..0000000 --- a/ricoClient/js/ricoLiveGridForms.js +++ /dev/null @@ -1,1129 +0,0 @@ -/* - * (c) 2005-2009 Richard Cowin (http://openrico.org) - * (c) 2005-2009 Matt Brown (http://dowdybrown.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this - * file except in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the - * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions - * and limitations under the License. - */ - -if(typeof Rico=='undefined') throw("LiveGridForms requires the Rico JavaScript framework"); - - -Rico.TableEdit = function(liveGrid) { - this.initialize(liveGrid); -} - -Rico.TableEdit.prototype = { -/** - * @class Supports editing LiveGrid data. - * @constructs - */ - initialize: function(liveGrid) { - Rico.log('Rico.TableEdit initialize: '+liveGrid.tableId); - this.grid=liveGrid; - this.options = { - maxDisplayLen : 20, // max displayed text field length - panelHeight : 200, // size of tabbed panels - panelWidth : 500, - compact : false, // compact corners - RecordName : Rico.getPhraseById("record"), - updateURL : window.location.href, // default is that updates post back to the generating page - showSaveMsg : 'errors' // disposition of database update responses (full - show full response, errors - show full response for errors and short response otherwise) - }; - Rico.extend(this.options, liveGrid.options); - this.hasWF2=(document.implementation && document.implementation.hasFeature && document.implementation.hasFeature('WebForms', '2.0')); - this.menu=liveGrid.menu; - this.menu.options.dataMenuHandler=Rico.bind(this,'editMenu'); - this.menu.ignoreClicks(); - this.editText=Rico.getPhraseById("editRecord",this.options.RecordName); - this.cloneText=Rico.getPhraseById("cloneRecord",this.options.RecordName); - this.delText=Rico.getPhraseById("deleteRecord",this.options.RecordName); - this.addText=Rico.getPhraseById("addRecord",this.options.RecordName); - this.buttonHover=new Rico.HoverSet(); - this.dateRegExp=/^\s*(\w+)(\W)(\w+)(\W)(\w+)/i; - Rico.EditControls.atLoad(); - this.createKeyArray(); - this.createEditDiv(); - this.saveMsg=Rico.$(liveGrid.tableId+'_savemsg'); - Rico.eventBind(document,"click", Rico.eventHandle(this,'clearSaveMsg')); - this.extraMenuItems=[]; - this.responseHandler=Rico.bind(this,'processResponse'); - Rico.log("Rico.TableEdit.initialize complete, hasWF2="+this.hasWF2); - }, - - createKeyArray: function() { - this.keys=[]; - for (var i=0; i0) return; - var wi=parseInt(this.options.panelWidth,10); - if (this.form) { - //this.form.style.width=(wi+10)+'px'; - if (Rico.isWebKit) this.formPopup.container.style.display='block'; // this causes display to flash briefly - this.options.bgColor = Rico.Color.createColorFromBackground(this.form).toString(); - } - this.formPopup.container.style.display='none'; - //this.options.panelHdrWidth=(Math.floor(wi / this.options.panels.length)-20)+'px'; - this.formPanels=new Rico.TabbedPanel(this.panelGroup, this.options); - }, - - notEmpty: function(v) { - return typeof(v)!='undefined'; - }, - - startForm: function() { - this.form = document.createElement('form'); - /** @ignore */ - this.form.onsubmit=function() {return false;}; - this.form.autocomplete="off"; // seems to fix "Permission denied..." errors in FF - this.formPopup.contentDiv.appendChild(this.form); - - var tab = document.createElement('div'); - tab.className='ButtonBar'; - var button=tab.appendChild(this.createButton(Rico.getPhraseById("saveRecord",this.options.RecordName))); - Rico.eventBind(button,"click", Rico.eventHandle(this,'TESubmit'), false); - button=tab.appendChild(this.createButton(Rico.getPhraseById("cancel"))); - Rico.eventBind(button,"click", Rico.eventHandle(this,'cancelEdit'), false); - this.form.appendChild(tab); - - // hidden fields - this.hiddenFields = document.createElement('div'); - this.hiddenFields.style.display='none'; - this.action = this.appendHiddenField(this.grid.actionId,''); - var i,fldSpec; - for (i=0; i=0; i--) { - tables[i]=this.createPanel(i); - } - } else { - for (i=0; i 0 ? table.rows[table.rows.length-1] : table.insertRow(-1); - var hdr = row.insertCell(-1); - column.formLabel=hdr; - if (hdr.noWrap) hdr.noWrap=true; - var entry = row.insertCell(-1); - if (entry.noWrap) entry.noWrap=true; - hdr.id='lbl_'+fmt.FieldName; - var field, name=fmt.FieldName; - switch (fmt.EntryType) { - case 'TA': - case 'tinyMCE': - field=Rico.createFormField(entry,'textarea',null,name); - field.cols=fmt.TxtAreaCols; - field.rows=fmt.TxtAreaRows; - field.innerHTML=fmt.ColData; - hdr.style.verticalAlign='top'; - break; - case 'R': - case 'RL': - field=Rico.createFormField(entry,'div',null,name); - if (fmt.DescriptionField) field.RicoUpdate=fmt.DescriptionField; - if (fmt.MultiSelect) Rico.addClass(field, 'MultiSelect'); - if (fmt.isNullable && !fmt.MultiSelect) this.addSelectNone(field); - this.selectValuesRequest(field,column); - break; - case 'N': - field=Rico.createFormField(entry,'select',null,name); - if (fmt.isNullable) this.addSelectNone(field); - Rico.eventBind(field,"change", Rico.eventHandle(this,'checkSelectNew')); - this.selectValuesRequest(field,column); - field=document.createElement('span'); - field.className='ricoEditLabel'; - field.id='labelnew__'+fmt.FieldName; - field.innerHTML='   '+Rico.getPhraseById('formNewValue').replace(' ',' '); - entry.appendChild(field); - name='textnew__'+fmt.FieldName; - field=Rico.createFormField(entry,'input','text',name,name); - break; - case 'S': - case 'SL': - if (fmt.ReadOnly) { - field=Rico.createFormField(entry,'input','text',name,name); - this.initField(field,fmt); - } else { - field=Rico.createFormField(entry,'select',null,name); - if (fmt.MultiSelect) field.multiple=true; - if (fmt.SelectRows) field.size=parseInt(fmt.SelectRows,10); - if (fmt.isNullable && !fmt.MultiSelect) this.addSelectNone(field); - if (fmt.DescriptionField) { - field.RicoUpdate=fmt.DescriptionField; - Rico.eventBind(field,"change", Rico.eventHandle(this,'selectClick'), false); - } - this.selectValuesRequest(field,column); - } - break; - case 'D': - if (!fmt.isNullable) fmt.required=true; - if (!fmt.dateFmt) fmt.dateFmt=Rico.dateFmt; - if (!fmt.Help) fmt.Help=fmt.dateFmt; - if (typeof fmt.min=='string') fmt.min=Rico.setISO8601(fmt.min) || new Date(fmt.min); - if (typeof fmt.max=='string') fmt.max=Rico.setISO8601(fmt.max) || new Date(fmt.max); - if (this.hasWF2) { - field=Rico.createFormField(entry,'input','date',name,name); - field.required=fmt.required; - if (fmt.min) field.min=Rico.toISO8601String(fmt.min,3); - if (fmt.max) field.max=Rico.toISO8601String(fmt.max,3); - field.required=fmt.required; - fmt.SelectCtl=null; // use the WebForms calendar instead of the Rico calendar - } else { - field=Rico.createFormField(entry,'input','text',name,name); - } - this.initField(field,fmt); - break; - case 'I': - if (!fmt.isNullable) fmt.required=true; - if (!fmt.pattern) fmt.pattern='int-signed'; - if (this.hasWF2) { - field=Rico.createFormField(entry,'input','number',name,name); - field.required=fmt.required; - field.min=fmt.min; - field.max=fmt.max; - field.step=1; - } else { - field=Rico.createFormField(entry,'input','text',name,name); - } - if (typeof fmt.min=='string') fmt.min=parseInt(fmt.min,10); - if (typeof fmt.max=='string') fmt.max=parseInt(fmt.max,10); - this.initField(field,fmt); - break; - case 'F': - if (!fmt.isNullable) fmt.required=true; - if (!fmt.pattern) fmt.pattern='float-signed'; - field=Rico.createFormField(entry,'input','text',name,name); - this.initField(field,fmt); - if (typeof fmt.min=='string') fmt.min=parseFloat(fmt.min); - if (typeof fmt.max=='string') fmt.max=parseFloat(fmt.max); - break; - default: - field=Rico.createFormField(entry,'input','text',name,name); - if (!fmt.isNullable && fmt.EntryType!='T') fmt.required=true; - this.initField(field,fmt); - break; - } - if (field) { - if (fmt.SelectCtl) - Rico.EditControls.applyTo(column,field); - } - var hdrSuffix=''; - hdr.className='ricoEditLabel'; - if (fmt.Help) { - hdr.title=fmt.Help; - hdrSuffix=" "; - Rico.addClass(hdr,'ricoHelp'); - } - var hdrText=fmt.EntryType.length>1 && fmt.EntryType.charAt(1)=='L' ? column.next.displayName : column.displayName; - hdr.innerHTML=hdrText+hdrSuffix; - }, - - addSelectNone: function(field) { - this.addSelectOption(field,this.options.TableSelectNone,Rico.getPhraseById("selectNone")); - }, - - initField: function(field,fmt) { - if (fmt.Length) { - field.maxLength=fmt.Length; - field.size=Math.min(fmt.Length, this.options.maxDisplayLen); - } - field.value=fmt.ColData; - }, - - selectClick: function(e) { - var SelObj=Rico.eventElement(e); - if (SelObj.readOnly) { - Rico.eventStop(e); - return false; - } - if (SelObj.RicoUpdate) { - var opt=SelObj.options[SelObj.selectedIndex]; - Rico.$(SelObj.RicoUpdate).value=opt.innerHTML; - } - }, - - radioClick: function(e) { - var ChkBoxObj=Rico.eventElement(e); - if (ChkBoxObj.readOnly) { - Rico.eventStop(e); - return false; - } - var container=Rico.getParentByTagName(ChkBoxObj,'div'); - if (container.RicoUpdate) { - Rico.$(container.RicoUpdate).value=ChkBoxObj.nextSibling.innerHTML; - } - }, - - checkSelectNew: function(e) { - this.updateSelectNew(Rico.eventElement(e)); - }, - - updateSelectNew: function(SelObj) { - var vis=(SelObj.value==this.options.TableSelectNew) ? "" : "hidden"; - Rico.$("labelnew__" + SelObj.id).style.visibility=vis; - Rico.$("textnew__" + SelObj.id).style.visibility=vis; - }, - - selectValuesRequest: function(elem,column) { - var fldSpec=column.format; - if (fldSpec.SelectValues) { - var valueList=fldSpec.SelectValues.split(','); - for (var i=0; i 0) { - var errmsg=Rico.getContentAsString(error[0],this.grid.buffer.isEncoded); - Rico.log("Data provider returned an error:\n"+errmsg); - alert(Rico.getPhraseById("requestError",errmsg)); - return null; - } - response=response.getElementsByTagName('response')[0]; - var rowsElement = response.getElementsByTagName('rows')[0]; - var rows = this.grid.buffer.dom2jstable(rowsElement); - Rico.log("selectValuesUpdate: id="+elem.id+' rows='+rows.length); - for (var i=0; i0) { - var c0=rows[i][0]; - var c1=(rows[i].length>1) ? rows[i][1] : c0; - this.addSelectOption(elem,c0,c1,i); - } - } - if (Rico.$('textnew__'+elem.id)) - this.addSelectOption(elem,this.options.TableSelectNew,Rico.getPhraseById("selectNewVal")); - if (this.panelGroup) - Rico.runLater(50,this,'initPanelGroup'); - }, - - addSelectOption: function(elem,value,text,idx) { - switch (elem.tagName.toLowerCase()) { - case 'div': - var opt=Rico.createFormField(elem,'input', Rico.hasClass(elem, 'MultiSelect') ? 'checkbox' : 'radio', elem.id+'_'+idx, elem.id); - opt.value=value; - var lbl=document.createElement('label'); - lbl.innerHTML=text; - lbl.htmlFor=opt.id; - elem.appendChild(lbl); - Rico.eventBind(opt,"click", Rico.eventHandle(this,'radioClick'), false); - break; - case 'select': - Rico.addSelectOption(elem,value,text); - break; - } - }, - - clearSaveMsg: function() { - if (this.saveMsg) this.saveMsg.innerHTML=""; - }, - - addMenuItem: function(menuText,menuAction,enabled) { - this.extraMenuItems.push({menuText:menuText,menuAction:menuAction,enabled:enabled}); - }, - - editMenu: function(grid,r,c,onBlankRow) { - this.clearSaveMsg(); - if (this.grid.buffer.sessionExpired==true || this.grid.buffer.startPos<0) return false; - this.rowIdx=r; - var elemTitle=Rico.$('pageTitle'); - var pageTitle=elemTitle ? elemTitle.innerHTML : document.title; - this.menu.addMenuHeading(pageTitle); - if (onBlankRow==false) { - for (var i=0; i=0; i--) { - if (ch[i].nodeType==1 && ch[i].nodeName!='P' && ch[i].nodeName!='DIV' && ch[i].nodeName!='BR') - this.responseDiv.removeChild(ch[i]); - } - responseText=Rico.stripTags(this.responseDiv.innerHTML); - success=(responseText.toLowerCase().indexOf('error')==-1); - } - if (success && this.options.showSaveMsg!='full') { - this.hideResponse(''); - this.grid.resetContents(); - this.grid.buffer.foundRowCount = false; - this.grid.buffer.fetch(this.grid.lastRowPos || 0); - if (this.saveMsg) this.saveMsg.innerHTML=' '+responseText+' '; - } - this.processCallback(this.options.onSubmitResponse); - Rico.log('Processing response completed'); - }, - - processCallback: function(callback) { - switch (typeof callback) { - case 'string': return eval(callback); - case 'function': return callback(); - } - }, - - // called when ok pressed on error response message - ackResponse: function(e) { - this.hideResponse(''); - this.grid.highlightEnabled=true; - }, - - cloneRecord: function() { - this.formPopup.setTitle(this.cloneText); - this.displayEditForm("ins"); - }, - - editRecord: function() { - this.formPopup.setTitle(this.editText); - this.displayEditForm("upd"); - }, - - displayEditForm: function(action) { - this.grid.highlightEnabled=false; - this.menu.cancelmenu(); - this.hideResponse(Rico.getPhraseById('saving')); - this.grid.outerDiv.style.cursor = 'auto'; - this.action.value=action; - for (var i=0; i1 && c.format.EntryType.charAt(1)=='L') - v=this.grid.columns[i+1].getValue(this.rowIdx); - v=c._format(v); - if (v==='') v=' '; - c.format.selectDesc.innerHTML=v; - } - if (c.format.SelectCtl) - Rico.EditControls.displayClrImg(c, !c.format.InsertOnly); - } - } - this.setReadOnly(action); - for (var k=0; k winWi ? (winWi-editWi)+'px' : (odOffset.left+1)+'px'; - - // set top position - var scrTop=Rico.docScrollTop(); - var editHt=this.formPopup.container.offsetHeight; - var newTop=odOffset.top+this.grid.hdrHt+scrTop; - var bottom=Rico.windowHeight()+scrTop; - if (row >= 0) { - newTop+=(row+1)*this.grid.rowHeight; - if (newTop+editHt>bottom) newTop-=(this.formPopup.contentCell.offsetHeight+this.grid.rowHeight); - } else { - if (newTop+editHt>bottom) newTop=bottom-editHt-2; - } - - if (this.processCallback(this.options.formOpen) === false) return; - this.formPopup.openPopup(null,Math.max(newTop,scrTop)); - this.formPopup.container.style.visibility='visible'; - Rico.EditControls.setZ(Rico.getStyle(this.formPopup.container,'zIndex')); - if (this.initialized) return; - - var i, spec; - for (i = 0; i < this.grid.columns.length; i++) { - spec=this.grid.columns[i].format; - if (!spec || !spec.EntryType || !spec.FieldName) continue; - switch (spec.EntryType) { - case 'tinyMCE': - if (typeof tinyMCE!='undefined') tinyMCE.execCommand('mceAddControl', true, spec.FieldName); - break; - } - } - this.initialized=true; - }, - - makeFormInvisible: function() { - this.formPopup.container.style.visibility='hidden'; - this.formPopup.closePopup(); - this.processCallback(this.options.formClose); - }, - - getConfirmDesc: function(rowIdx) { - return Rico.stripTags(this.grid.cell(rowIdx,this.options.ConfirmDeleteCol).innerHTML).replace(' ',' '); //.unescapeHTML(); - }, - - deleteRecord: function() { - this.menu.cancelmenu(); - var desc; - switch(this.options.ConfirmDeleteCol){ - case -1 : - desc=Rico.getPhraseById("thisRecord",this.options.RecordName); - break; - case -2 : // Use key/column header to identify the row - for (var k=0; k1 && fmt.EntryType.charAt(1)=='L') i++; - var value=Rico.stripTags(this.grid.cell(rowIdx,i).innerHTML).replace(/ /g,' '); - if (desc) desc+=', '; - desc+=this.grid.columns[i].displayName+" "+value; - } - break; - default : - desc='\"' + Rico.truncate(this.getConfirmDesc(this.rowIdx),50) + '\"'; - break; - } - if (!this.options.ConfirmDelete.valueOf || confirm(Rico.getPhraseById("confirmDelete",desc))) { - this.hideResponse(Rico.getPhraseById('deleting')); - this.showResponse(); - var parms={}; - parms[this.grid.actionId]="del"; - for (var k=0; k31) return NaN; - var mm=parseInt(aDate[dateParts.mm], 10) - 1; - if (mm > 11) return NaN; - var yy=parseInt(aDate[dateParts.yyyy], 10); - if (yy < 100) { - // apply a century to 2-digit years - yy+=curyr - (curyr % 100); - } - d.setFullYear(yy,mm,dd); - return d; - }, - - TESubmit: function(e) { - var i,ro,lbl,spec,elem,n,dateValues=[]; - - Rico.eventStop(e); - Rico.log('Event: TESubmit called to validate input'); - - // check fields that are supposed to be non-blank - - for (i = 0; i < this.grid.columns.length; i++) { - spec=this.grid.columns[i].format; - if (!spec || !spec.EntryType || !spec.FieldName) continue; - elem=Rico.$(spec.FieldName); - if (!this.isTextInput(elem)) continue; - switch (this.action.value) { - case 'ins': ro=!spec.Writeable || spec.ReadOnly || spec.UpdateOnly; break; - case 'upd': ro=!spec.Writeable || spec.ReadOnly || spec.InsertOnly; break; - default: ro=false; break; - } - if (ro) continue; // readonly, so don't validate - Rico.log(' Validating field #'+i+' EntryType='+spec.EntryType+' ('+spec.FieldName+')'); - - // check for blanks - if (elem.value.length == 0) { - if (spec.required) - return this.validationMsg(elem,i,"formPleaseEnter"); - else - continue; - } - - // check pattern - if (elem.value.length > 0 && spec.regexp && !spec.regexp.test(elem.value)) - return this.validationMsg(elem,i,"formInvalidFmt"); - - // check min/max and date values - switch (spec.EntryType.charAt(0)) { - case 'I': n=parseInt(elem.value,10); break; - case 'F': n=parseFloat(elem.value); break; - case 'D': - n=this.parseDate(elem.value,spec.dateFmt); - if (isNaN(n)) return this.validationMsg(elem,i,"formInvalidFmt"); - dateValues.push({e:elem,v:n}); - break; - default: n=NaN; break; - } - if (typeof spec.min!='undefined' && !isNaN(n) && n < spec.min) - return this.validationMsg(elem,i,"formOutOfRange"); - if (typeof spec.max!='undefined' && !isNaN(n) && n > spec.max) - return this.validationMsg(elem,i,"formOutOfRange"); - } - if (this.processCallback(this.options.formSubmit) === false) return false; - - // update drop-down for any columns with entry type of N - - for (i = 0; i < this.grid.columns.length; i++) { - spec=this.grid.columns[i].format; - if (!spec || !spec.EntryType || !spec.FieldName) continue; - if (spec.EntryType.charAt(0) != 'N') continue; - var SelObj=Rico.$(spec.FieldName); - if (!SelObj || SelObj.value!=this.options.TableSelectNew) continue; - var newtext=Rico.$("textnew__" + SelObj.id).value; - this.addSelectOption(SelObj,newtext,newtext); - } - - // set date values to ISO format - for (i = 0; i < dateValues.length; i++) { - dateValues[i].e.value = Rico.formatDate(dateValues[i].v,'yyyy-mm-dd'); - } - - if (typeof tinyMCE!='undefined') tinyMCE.triggerSave(); - this.makeFormInvisible(); - this.sendForm(); - this.menu.cancelmenu(); - return false; - }, - - sendForm: function() { - this.setReadOnly("reset"); // reset disabled flag so that all fields are sent to server - this.showResponse(); - Rico.log("sendForm: "+this.grid.tableId); - Rico.ajaxSubmit(this.form, this.options.updateURL, {method:'post',onComplete:this.responseHandler}); - } -}; - - -/** - * @namespace Registers custom popup widgets to fill in a text box (e.g. ricoCalendar and ricoTree) - *
- * Custom widget must implement:
- *   open() method (make control visible)
- *   close() method (hide control)
- *   container property (div element that contains the control)
- *   id property (uniquely identifies the widget class)
- *
- * widget calls returnValue method to return a value to the caller
- *
- * this object handles clicks on the control's icon and positions the control appropriately.
- * 
- */ -Rico.EditControls = { - widgetList : {}, - elemList : {}, - zIndex : 0, - - register: function(widget, imgsrc) { - this.widgetList[widget.id] = {imgsrc:imgsrc, widget:widget, currentEl:''}; - widget.returnValue=Rico.bind(this,'setValue',widget); - Rico.log("Rico.EditControls.register:"+widget.id); - }, - - setZ: function(z) { - this.zIndex=Math.max(this.zIndex,z+10); - }, - - atLoad: function() { - for (var id in this.widgetList) { - var widget=this.widgetList[id].widget; - if (widget.atLoad && !widget.atLoadComplete) { - Rico.log("Rico.EditControls.atLoad: "+id); - widget.atLoad(); - widget.atLoadComplete=true; - } - } - }, - - applyTo: function(column,inputCtl) { - var wInfo=this.widgetList[column.format.SelectCtl]; - if (!wInfo) return; - Rico.log('Rico.EditControls.applyTo: '+column.displayName+' : '+column.format.SelectCtl); - var descSpan = document.createElement('span'); - var newimg = document.createElement('img'); - newimg.style.paddingLeft='4px'; - newimg.style.cursor='pointer'; - newimg.align='top'; - newimg.src=wInfo.imgsrc; - newimg.id=this.imgId(column.format.FieldName); - Rico.eventBind(newimg,"click", Rico.eventHandle(this,'processClick')); - inputCtl.parentNode.appendChild(descSpan); - inputCtl.parentNode.appendChild(newimg); - inputCtl.style.display='none'; // comment out this line for debugging - var clr; - if (column.format.isNullable) { - clr=Rico.clearButton(Rico.eventHandle(this,'processClear')); - clr.id=newimg.id+'_clear'; - inputCtl.parentNode.appendChild(clr); - } - this.elemList[newimg.id] = {descSpan:descSpan, inputCtl:inputCtl, widget:wInfo.widget, listObj:wInfo, column:column, clrimg:clr}; - column.format.selectIcon=newimg; - column.format.selectDesc=descSpan; - }, - - displayClrImg: function(column,bShow) { - var el=this.elemList[this.imgId(column.format.FieldName)]; - //alert(column.format.FieldName+': '+bShow+' '+typeof(el.clrimg)); - if (el && el.clrimg) el.clrimg.style.display=bShow ? 'inline-block' : 'none'; - }, - - processClear: function(e) { - var elem=Rico.eventElement(e); - var el=this.elemList[elem.id.slice(0,-6)]; - if (!el) return; - el.inputCtl.value=''; - el.descSpan.innerHTML=el.column._format(''); - }, - - processClick: function(e) { - var elem=Rico.eventElement(e); - var el=this.elemList[elem.id]; - if (!el) return; - if (el.listObj.currentEl==elem.id && el.widget.container.style.display!='none') { - el.widget.close(); - el.listObj.currentEl=''; - } else { - el.listObj.currentEl=elem.id; - Rico.log('Rico.EditControls.processClick: '+el.widget.id+' : '+el.inputCtl.value); - el.widget.container.style.zIndex=this.zIndex; - el.widget.open(el.inputCtl.value,el.column); // this may change the size of the widget - Rico.positionCtlOverIcon(el.widget.container,elem); - } - }, - - imgId: function(fieldname) { - return 'icon_'+fieldname; - }, - - resetValue: function(column) { - var el=this.elemList[this.imgId(column.format.FieldName)]; - if (!el) return; - el.inputCtl.value=column.format.ColData; - var v=column._format(column.format.ColData); - if (v==='') v=' '; - el.descSpan.innerHTML=v; - }, - - setValue: function(widget,newVal,newDesc) { - var wInfo=this.widgetList[widget.id]; - if (!wInfo) return null; - var id=wInfo.currentEl; - if (!id) return null; - var el=this.elemList[id]; - if (!el) return null; - el.inputCtl.value=newVal; - if (!newDesc) newDesc=el.column._format(newVal); - el.descSpan.innerHTML=newDesc; - if (el.column.format.DescriptionField) - Rico.$(el.column.format.DescriptionField).value = newDesc; - //alert(widget.id+':'+id+':'+el.inputCtl.id+':'+el.inputCtl.value+':'+newDesc); - }, - - close: function(id) { - var wInfo=this.widgetList[id]; - if (!wInfo) return; - if (wInfo.widget.container.style.display!='none') - wInfo.widget.close(); - } -}; - -Rico.includeLoaded('ricoLiveGridForms.js'); diff --git a/ricoClient/js/ricoLiveGridMenu.js b/ricoClient/js/ricoLiveGridMenu.js deleted file mode 100644 index 7ca9385..0000000 --- a/ricoClient/js/ricoLiveGridMenu.js +++ /dev/null @@ -1,141 +0,0 @@ -/* - * (c) 2005-2009 Richard Cowin (http://openrico.org) - * (c) 2005-2009 Matt Brown (http://dowdybrown.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this - * file except in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the - * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions - * and limitations under the License. - */ - - if(typeof Rico=='undefined') - throw("GridMenu requires the Rico JavaScript framework"); - -/** - * Standard menu for LiveGrid - */ -Rico.GridMenu = function(options) { - this.initialize(options); -}; - -Rico.GridMenu.prototype = { - -initialize: function(options) { - this.options = { - width : '18em', - dataMenuHandler : null // put custom items on the menu - }; - Rico.extend(this.options, options || {}); - Rico.extend(this, new Rico.Menu(this.options)); - this.sortmenu = new Rico.Menu({ width: '15em' }); - this.filtermenu = new Rico.Menu({ width: '22em' }); - this.exportmenu = new Rico.Menu({ width: '24em' }); - this.hideshowmenu = new Rico.Menu({ width: '22em' }); - this.createDiv(); - this.sortmenu.createDiv(); - this.filtermenu.createDiv(); - this.exportmenu.createDiv(); - this.hideshowmenu.createDiv(); -}, - -// Build context menu for grid -buildGridMenu: function(r,c) { - this.clearMenu(); - var totrows=this.liveGrid.buffer.totalRows; - var onBlankRow=r >= totrows; - var column=this.liveGrid.columns[c]; - if (this.options.dataMenuHandler) { - var showDefaultMenu=this.options.dataMenuHandler(this.liveGrid,r,c,onBlankRow); - if (!showDefaultMenu) return (this.itemCount > 0); - } - - // menu items for sorting - if (column.sortable && totrows>0) { - this.sortmenu.clearMenu(); - this.addSubMenuItem(Rico.getPhraseById("gridmenuSortBy",column.displayName), this.sortmenu, false); - this.sortmenu.addMenuItemId("gridmenuSortAsc", Rico.bind(column,'sortAsc'), true); - this.sortmenu.addMenuItemId("gridmenuSortDesc", Rico.bind(column,'sortDesc'), true); - } - - // menu items for filtering - this.filtermenu.clearMenu(); - if (column.canFilter() && !column.format.filterUI && (!onBlankRow || column.filterType == Rico.ColumnConst.USERFILTER)) { - this.addSubMenuItem(Rico.getPhraseById("gridmenuFilterBy",column.displayName), this.filtermenu, false); - column.userFilter=column.getValue(r); - if (column.filterType == Rico.ColumnConst.USERFILTER) { - this.filtermenu.addMenuItemId("gridmenuRemoveFilter", Rico.bind(column,'setUnfiltered',false), true); - if (column.filterOp=='LIKE') - this.filtermenu.addMenuItemId("gridmenuChgKeyword", Rico.bind(this.liveGrid,'openKeyword',c), true); - if (column.filterOp=='NE' && !onBlankRow) - this.filtermenu.addMenuItemId("gridmenuExcludeAlso", Rico.bind(column,'addFilterNE'), true); - } else if (!onBlankRow) { - this.filtermenu.addMenuItemId("gridmenuInclude", Rico.bind(column,'setFilterEQ'), true); - this.filtermenu.addMenuItemId("gridmenuGreaterThan", Rico.bind(column,'setFilterGE'), column.userFilter!=''); - this.filtermenu.addMenuItemId("gridmenuLessThan", Rico.bind(column,'setFilterLE'), column.userFilter!=''); - if (column.isText) - this.filtermenu.addMenuItemId("gridmenuContains", Rico.bind(this.liveGrid,'openKeyword',c), true); - this.filtermenu.addMenuItemId("gridmenuExclude", Rico.bind(column,'setFilterNE'), true); - } - if (this.liveGrid.filterCount() > 0) { - this.filtermenu.addMenuItemId("gridmenuRefresh", Rico.bind(this.liveGrid,'filterHandler'), true); - this.filtermenu.addMenuItemId("gridmenuRemoveAll", Rico.bind(this.liveGrid,'clearFilters'), true); - } - } else if (this.liveGrid.filterCount() > 0) { - this.addSubMenuItem(Rico.getPhraseById("gridmenuFilterBy",column.displayName), this.filtermenu, false); - this.filtermenu.addMenuItemId("gridmenuRemoveAll", Rico.bind(this.liveGrid,'clearFilters'), true); - } - - // menu items for Print/Export - this.exportmenu.clearMenu(); - if (this.liveGrid.buffer.printVisibleSQL && typeof(this.liveGrid.buffer.dataSource)=='string') { - // SQL buffer - this.addSubMenuItem(Rico.getPhraseById('gridmenuExport'),this.exportmenu,false); - this.exportmenu.addMenuItemId("gridmenuExportVis2Web", Rico.bind(this.liveGrid.buffer,'printVisibleSQL','html')); - this.exportmenu.addMenuItemId("gridmenuExportAll2Web", Rico.bind(this.liveGrid.buffer,'printAllSQL','html'), this.liveGrid.buffer.totalRows <= this.liveGrid.options.maxPrint); - this.exportmenu.addMenuBreak(); - this.exportmenu.addMenuItemId("gridmenuExportVis2SS", Rico.bind(this.liveGrid.buffer,'printVisibleSQL','xl')); - this.exportmenu.addMenuItemId("gridmenuExportAll2SS", Rico.bind(this.liveGrid.buffer,'printAllSQL','xl'), this.liveGrid.buffer.totalRows <= this.liveGrid.options.maxPrint); - } else if (this.liveGrid.options.maxPrint > 0 && totrows>0) { - // any other buffer - this.addSubMenuItem(Rico.getPhraseById('gridmenuExport'),this.exportmenu,false); - this.exportmenu.addMenuItemId("gridmenuExportVis2Web", Rico.bind(this.liveGrid.buffer,'printVisible','plain')); - this.exportmenu.addMenuItemId("gridmenuExportAll2Web", Rico.bind(this.liveGrid.buffer,'printAll','plain'), this.liveGrid.buffer.totalRows <= this.liveGrid.options.maxPrint); - if (Rico.isIE) { - this.exportmenu.addMenuBreak(); - this.exportmenu.addMenuItemId("gridmenuExportVis2SS", Rico.bind(this.liveGrid.buffer,'printVisible','owc')); - this.exportmenu.addMenuItemId("gridmenuExportAll2SS", Rico.bind(this.liveGrid.buffer,'printAll','owc'), this.liveGrid.buffer.totalRows <= this.liveGrid.options.maxPrint); - } - } - - // menu items for hide/unhide - var hiddenCols=this.liveGrid.listInvisible(); - for (var showableCnt=0,x=0; x 0 || column.canHideShow()) { - this.hideshowmenu.clearMenu(); - this.addSubMenuItem(Rico.getPhraseById('gridmenuHideShow'),this.hideshowmenu,false); - this.hideshowmenu.addMenuItemId('gridmenuChooseCols', Rico.bind(this.liveGrid,'chooseColumns'),true,false); - var visibleCnt=this.liveGrid.columns.length-hiddenCols.length; - var enabled=(visibleCnt>1 && column.visible && column.canHideShow()); - this.hideshowmenu.addMenuItem(Rico.getPhraseById('gridmenuHide',column.displayName), Rico.bind(column,'hideColumn'), enabled); - for (var cnt=0,x=0; x 1) - this.hideshowmenu.addMenuItemId('gridmenuShowAll', Rico.bind(this.liveGrid,'showAll')); - } - return true; -} - -} - -Rico.includeLoaded('ricoLiveGridMenu.js'); diff --git a/ricoClient/js/ricoSearch.js b/ricoClient/js/ricoSearch.js deleted file mode 100644 index 3e90dd7..0000000 --- a/ricoClient/js/ricoSearch.js +++ /dev/null @@ -1,135 +0,0 @@ -/* - * (c) 2005-2009 Richard Cowin (http://openrico.org) - * (c) 2005-2009 Matt Brown (http://dowdybrown.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this - * file except in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the - * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions - * and limitations under the License. - */ - -Rico.KeywordSearch = function(id,options) { - this.initialize(id,options); -}; - -Rico.KeywordSearch.prototype = { -/** - * @class Implements a pop-up keyword search control. - * @extends Rico.Popup - * @constructs - * @param id unique identifier - * @param options object may contain any of the following:
- *
showColorCode
show hex color code as user hovers over color grid? default=false
- *
cellsPerRow
number of colors per row in the grid? default=18
- *
palette
array of 6 digit hex values, default=216 "web safe" colors
- *
- */ - initialize: function(id,options) { - this.id=id; - Rico.extend(this, new Rico.Window(Rico.getPhraseById("keywordTitle"),options)); - this.contentCell.className='ricoKeywordSearch'; - Rico.extend(this.options, { - listLength : 10, - maxSuggest : 20, - width: '12em' - }); - }, - - atLoad : function() { - this.searchField=Rico.createFormField(this.contentDiv,'input','text',this.id+'_search'); - this.searchField.style.display="block"; - this.searchField.style.width=this.options.width; - Rico.eventBind(this.searchField,'keyup',Rico.eventHandle(this,'filterKeypress'),false); - this.selectList=Rico.createFormField(this.contentDiv,'select',null,this.id+'_list'); - this.selectList.size=this.options.listLength; - this.selectList.style.display="block"; - this.selectList.style.width=this.options.width; - Rico.eventBind(this.selectList,'change',Rico.eventHandle(this,'listClick'),false); - /** - * alias for closePopup - * @function - */ - this.close=this.closePopup; - this.close(); - }, - - open: function(currentVal,column) { - this.column=column; - this.grid=this.column.liveGrid; - this.searchField.value=''; - this.selectList.options.length=0; - this.openPopup(); - this.searchField.focus(); - this.selectValuesRequest(''); - }, - - selectValuesRequest: function(filter) { - var colnum=this.column.index; - var options={}; - Rico.extend(options, this.grid.buffer.ajaxOptions); - options.parameters = {id: this.grid.tableId, offset: '0', page_size: this.options.maxSuggest, edit: colnum}; - options.parameters[this.grid.actionId]="query"; - if (filter!='' && filter!='*') { - if (filter.indexOf('*')==-1) filter='*'+filter+'*'; - options.parameters['f[1][op]']="LIKE"; - options.parameters['f[1][len]']=1; - options.parameters['f[1][0]']=filter; - } - options.onComplete = Rico.bind(this,'selectValuesUpdate'); - new Rico.ajaxRequest(this.grid.buffer.dataSource, options); - }, - - selectValuesUpdate: function(request) { - var response = request.responseXML.getElementsByTagName("ajax-response"); - Rico.log("selectValuesUpdate: "+request.status); - if (response == null || response.length != 1) return; - response=response[0]; - var error = response.getElementsByTagName('error'); - if (error.length > 0) { - var errmsg=Rico.getContentAsString(error[0],this.grid.buffer.isEncoded); - Rico.log("Data provider returned an error:\n"+errmsg); - alert(Rico.getPhraseById("requestError",errmsg)); - return null; - } - this.selectList.options.length=0; - response=response.getElementsByTagName('response')[0]; - var rowsElement = response.getElementsByTagName('rows')[0]; - var rows = this.grid.buffer.dom2jstable(rowsElement); - Rico.log("selectValuesUpdate: id="+this.selectList.id+' rows='+rows.length); - for (var i=0; i0) { - var c0=rows[i][0]; - var c1=(rows[i].length>1) ? rows[i][1] : c0; - Rico.addSelectOption(this.selectList,c0,c1); - } - } - }, - - filterKeypress: function(e) { - var txtbox=Rico.eventElement(e); - if (typeof this.lastKeyFilter != 'string') this.lastKeyFilter=''; - if (this.lastKeyFilter==txtbox.value) return; - var v=txtbox.value; - Rico.log("filterKeypress: "+this.index+' '+v); - this.lastKeyFilter=v; - this.selectValuesRequest(v); - }, - - listClick: function(e) { - var elem=Rico.eventElement(e); - if (elem.tagName.toLowerCase() != 'select') return; - if (this.returnValue) { - var opt=elem.options[elem.selectedIndex]; - this.returnValue(opt.value,opt.innerHTML); - } - this.close(); - } - -}; - -Rico.includeLoaded('ricoSearch.js'); diff --git a/ricoClient/js/ricoSimpleGrid.js b/ricoClient/js/ricoSimpleGrid.js deleted file mode 100644 index 5c16afd..0000000 --- a/ricoClient/js/ricoSimpleGrid.js +++ /dev/null @@ -1,403 +0,0 @@ -/* - * (c) 2005-2009 Richard Cowin (http://openrico.org) - * (c) 2005-2009 Matt Brown (http://dowdybrown.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this - * file except in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the - * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions - * and limitations under the License. - */ - -if(typeof Rico=='undefined') throw("SimpleGrid requires the Rico JavaScript framework"); - -Rico.SimpleGrid = function(tableId, options) { - this.initialize(tableId, options); -} - -Rico.SimpleGrid.prototype = { -/** - * @class Create & manage an unbuffered grid. - * Supports: frozen columns & headings, resizable columns. - * @extends Rico.GridCommon - * @constructs - */ - initialize: function( tableId, options ) { - Rico.extend(this, Rico.GridCommon); - this.baseInit(); - Rico.setDebugArea(tableId+"_debugmsgs"); // if used, this should be a textarea - Rico.extend(this.options, options || {}); - this.tableId = tableId; - Rico.log("SimpleGrid initialize start: "+tableId); - this.createDivs(); - this.hdrTabs=new Array(2); - this.simpleGridInit(); - Rico.log("SimpleGrid initialize end: "+tableId); - }, - - simpleGridInit: function() { - var i; - for (i=0; i<2; i++) { - Rico.log("simpleGridInit "+i); - this.tabs[i]=document.getElementById(this.tableId+'_tab'+i); - if (!this.tabs[i]) return; - this.hdrTabs[i]=document.getElementById(this.tableId+'_tab'+i+'h'); - if (!this.hdrTabs[i]) return; - //if (i==0) this.tabs[i].style.position='absolute'; - //if (i==0) this.tabs[i].style.left='0px'; - //this.hdrTabs[i].style.position='absolute'; - //this.hdrTabs[i].style.top='0px'; - //this.hdrTabs[i].style.zIndex=1; - this.thead[i]=this.hdrTabs[i]; - this.tbody[i]=this.tabs[i]; - this.headerColCnt = this.getColumnInfo(this.hdrTabs[i].rows); - if (i==0) this.options.frozenColumns=this.headerColCnt; - if (Rico.theme.gridheader) Rico.addClass(this.thead[i],Rico.theme.gridheader); - if (Rico.theme.gridcontent) Rico.addClass(this.tbody[i],Rico.theme.gridcontent); - } - if (this.headerColCnt==0) { - alert('ERROR: no columns found in "'+this.tableId+'"'); - return; - } - //this.hdrHt=Math.max(Rico.nan2zero(this.hdrTabs[0].offsetHeight),this.hdrTabs[1].offsetHeight); - //for (i=0; i<2; i++) { - // if (i==0) this.tabs[i].style.top=this.hdrHt+'px'; - //} - this.createColumnArray('SimpleGridColumn'); - this.pageSize=this.columns[0].dataColDiv.childNodes.length; - this.sizeDivs(); - if (typeof(this.options.FilterLocation)=='number') - this.createFilters(this.options.FilterLocation); - this.attachMenuEvents(); - this.scrollEventFunc=Rico.eventHandle(this,'handleScroll'); - this.pluginScroll(); - if (this.options.windowResize) - Rico.eventBind(window,"resize", Rico.eventHandle(this,'sizeDivs'), false); - }, - - // return id string for a filter element - filterId: function(colnum) { - return 'RicoFilter_'+this.tableId+'_'+colnum; - }, - - // create filter elements on heading row r - createFilters: function(r) { - if (r < 0) { - r=this.addHeadingRow(); - this.sizeDivs(); - } - for( var c=0; c < this.headerColCnt; c++ ) { - var col=this.columns[c]; - var fmt=col.format; - if (typeof fmt.filterUI!='string') continue; - var cell=this.hdrCells[r][c].cell; - var field,name=this.filterId(c); - var divs=cell.getElementsByTagName('div'); - switch (fmt.filterUI.charAt(0)) { - case 't': - field=Rico.createFormField(divs[1],'input','text',name,name); - var size=fmt.filterUI.match(/\d+/); - field.maxLength=fmt.Length || 50; - field.size=size ? parseInt(size,10) : 10; - Rico.eventBind(field,'keyup',Rico.eventHandle(col,'filterKeypress'),false); - break; - case 's': - field=Rico.createFormField(divs[1],'select',null,name); - Rico.addSelectOption(field,this.options.FilterAllToken,Rico.getPhraseById("filterAll")); - this.getFilterValues(col); - var keys=Rico.keys(col.filterHash); - keys.sort(); - for (var i=0; i"+v+""; - } - } - this.exportRows.push(exportText); - } - this.exportFinish(exportType); - }, - - /** - * Hide a row in the grid. - * sizeDivs() should be called after this function has completed. - */ - hideRow: function(rownum) { - if (this.columns[0].cell(rownum).style.display=='none') return; - for (var i=0; i this.width) newLeft-=this.width; - } else { - if (newLeft+this.width+this.options.margin > this.scrollDiv.clientWidth) newLeft-=this.width; - } - popupobj.divPopup.style.visibility="hidden"; - popupobj.divPopup.style.display="block"; - var contentHt=popupobj.divPopup.offsetHeight; - var newTop=Math.floor(elem.offsetTop-this.scrollDiv.scrollTop+elem.offsetHeight/2); - if (newTop+contentHt+popupobj.options.margin > this.scrollDiv.clientHeight) - newTop=Math.max(newTop-contentHt,0); - popupobj.openPopup(this.frzWi+newLeft,this.hdrHt+newTop); - popupobj.divPopup.style.visibility ="visible"; - return elem; - } - -} - -if (Rico.Menu) { -Rico.extend(Rico.Menu.prototype, { - -showSimpleMenu: function(e,hideFunc) { - Rico.eventStop(e); - this.hideFunc=hideFunc; - if (this.div.childNodes.length==0) { - this.cancelmenu(); - return false; - } - var elem=Rico.eventElement(e); - this.grid.openPopup(elem,this); - return elem; -}, - -showSimpleSubMenu: function(a,submenu) { - if (this.openSubMenu) this.hideSubMenu(); - this.openSubMenu=submenu; - this.openMenuAnchor=a; - if (a.className=='ricoSubMenu') a.className='ricoSubMenuOpen'; - var top=parseInt(this.div.style.top,10); - var left=parseInt(this.div.style.left,10); - submenu.openPopup(left+a.offsetWidth,top+a.offsetTop); - submenu.div.style.visibility ="visible"; -} - -}); -} - - -Rico.SimpleGridColumn = function(grid,colIdx,hdrInfo,tabIdx) { - this.initialize(grid,colIdx,hdrInfo,tabIdx); -} - -Rico.SimpleGridColumn.prototype = { -/** - * @class Implements a SimpleGrid column - * @extends Rico.TableColumnBase - * @constructs - */ -initialize: function(grid,colIdx,hdrInfo,tabIdx) { - Rico.extend(this, new Rico.TableColumnBase()); - this.baseInit(grid,colIdx,hdrInfo,tabIdx); -}, - -setUnfiltered: function() { - this.filterRows=null; -}, - -filterChange: function(e) { - var selbox=Rico.eventElement(e); - if (selbox.value==this.liveGrid.options.FilterAllToken) - this.setUnfiltered(); - else - this.filterRows=this.filterHash[selbox.value]; - this.liveGrid.applyFilters(); -}, - -filterKeypress: function(e) { - var txtbox=Rico.eventElement(e); - if (typeof this.lastKeyFilter != 'string') this.lastKeyFilter=''; - if (this.lastKeyFilter==txtbox.value) return; - var v=txtbox.value; - Rico.log("filterKeypress: "+this.index+' '+v); - this.lastKeyFilter=v; - if (v) { - v=v.replace('\\','\\\\'); - v=v.replace('(','\\(').replace(')','\\)'); - v=v.replace('.','\\.'); - if (this.format.filterUI.indexOf('^') > 0) v='^'+v; - var re=new RegExp(v,'i'); - this.filterRows=[]; - var n=this.numRows(); - for (var i=0; inot selectable, 1->selectable (use default action), otherwise the node is selectable and cells[4] contains the action -// cells[5]=leafIcon (optional) - - -Rico.TreeControl = function(id,url,options) { - this.initialize(id,url,options); -}; - -Rico.TreeControl.prototype = { -/** - * @class Implements a pop-up tree control. - * @extends Rico.Popup - * @constructs - * @param id unique identifier - * @param url data source - * @param options object may contain any of the following:
- *
nodeIdDisplay
first, last, tooltip, or none? default=none
- *
showCheckBox
show checkbox next to each item? default=false
- *
showFolders
show folder icons? default=false
- *
showPlusMinus
show +/- icons to open/close branches? default=true
- *
showLines
show vertical lines connecting each level? default=true
- *
defaultAction
Rico event handle to call when user clicks on an item, default is to call returnValue method
- *
height
control height? default=300px
- *
width
control width? default=300px
- *
leafIcon
url to img, default=doc.gif ('none'=no leaf icon)
- *
- */ - initialize: function(id,url,options) { - Rico.extend(this, new Rico.Popup()); - Rico.extend(this.options, { - ignoreClicks:true, - nodeIdDisplay:'none', - showCheckBox: false, - showFolders: false, - showPlusMinus: true, - showLines: true, - defaultAction: Rico.eventHandle(this,'nodeClick'), - height: '300px', - width: '300px', - leafIcon: Rico.imgDir+'doc.gif' - }); - Rico.extend(this.options, options || {}); - this.id=id; - this.dataSource=url; - this.close=this.closePopup; - this.hoverSet = new Rico.HoverSet([]); - }, - - atLoad : function() { - var imgsrc = ["node.gif","nodelast.gif","folderopen.gif","folderclosed.gif"]; - // preload images - for (var i=0;i1) { - var tdParent=parentNode.getElementsByTagName('td'); - for (var i=0; i0) { - var suffix=isLast && this.options.showLines ? 'last' : ''; - var prefix=this.options.showLines ? 'node' : ''; - if (this.options.showPlusMinus && isContainer) { - var img = document.createElement("img"); - img.name=nodeId; - img.style.cursor='pointer'; - Rico.eventBind(img, 'click', Rico.eventHandle(this,'clickBranch')); - img.src=Rico.imgDir+prefix+"p"+suffix+".gif"; - row.insertCell(-1).appendChild(img); - } else if (this.options.showLines) { - var img = document.createElement("img"); - img.src=Rico.imgDir+"node"+suffix+".gif"; - row.insertCell(-1).appendChild(img); - } - if (this.options.showFolders && (isContainer || (leafIcon && leafIcon!='none'))) { - var img = document.createElement("img"); - if (!isContainer) { - img.src=leafIcon; - } else { - img.name=nodeId; - img.style.cursor='pointer'; - Rico.eventBind(img, 'click', Rico.eventHandle(this,'clickBranch')); - img.src=Rico.imgDir+"folderclosed.gif"; - } - row.insertCell(-1).appendChild(img); - } - } - if (isSelectable && this.options.showCheckBox) { - var chkbx=document.createElement("input"); - chkbx.type="checkbox"; - chkbx.value=nodeId; - row.insertCell(-1).appendChild(chkbx); - } - - if (isSelectable && !this.options.showCheckBox) { - var span=document.createElement('a'); - if (typeof isSelectable=='string') { - span.href=isSelectable; - } else { - span.href='javascript:void(0)'; - Rico.eventBind(span, 'click', this.options.defaultAction); - } - this.hoverSet.add(span); - } else { - var span=document.createElement('p'); - } - span.id=this.domID(nodeId,'Desc'); - span.className='ricoTreeLevel'+level; - switch (this.options.nodeIdDisplay) { - case 'last': nodeDesc+=' ('+nodeId+')'; break; - case 'first': nodeDesc=nodeId+' - '+nodeDesc; break; - case 'tooltip': span.title=nodeId; break; - } - span.appendChild(document.createTextNode(nodeDesc)); - row.insertCell(-1).appendChild(span); - - var parent=parentChildren || this.treeDiv; - parent.appendChild(tab); - parent.appendChild(div); - }, - - nodeClick: function(e) { - var node=Rico.eventElement(e); - if (this.returnValue) { - var t=this.domID('','Desc'); - this.returnValue(node.id.substr(t.length),node.innerHTML); - } - this.close(); - }, - - saveSelection: function(e) { - if (this.returnValue) { - this.returnValue(this.getCheckedItems()); - } - this.close(); - }, - - getCheckedItems: function() { - var inp=this.treeDiv.getElementsByTagName('input'); - var vals=[]; - for (var i=0; i
"; - } - } - if (elem && elem.parentNode) { - elem.parentNode.replaceChild(tab, elem); - c0.appendChild(elem); - } - return tab; -}; - -Rico.Popup = function(containerDiv,options) { - this.initialize(containerDiv,options); -}; - -Rico.Popup.prototype = { -/** - * @class Class to manage pop-up div windows. - * @constructs - * @param options object may contain any of the following:
- *
hideOnEscape
hide popup when escape key is pressed? default=true
- *
hideOnClick
hide popup when mouse button is clicked? default=true
- *
ignoreClicks
if true, mouse clicks within the popup are not allowed to bubble up to parent elements
- *
position
defaults to absolute, use "auto" to auto-detect
- *
shadow
display shadow with popup? default=true
- *
zIndex
which layer? default=1
- *
canDrag
boolean value (or function that returns a boolean) indicating if it is ok to drag/reposition popup, default=false
- *
onClose
function to call when the popup is closed
- *
- * @param containerDiv if supplied, then setDiv() is called at the end of initialization - */ - initialize: function(containerDiv,options) { - this.options = { - hideOnEscape : true, - hideOnClick : true, - ignoreClicks : false, - position : 'absolute', - shadow : true, - zIndex : 2, - canDrag : false, - dragElement : false, - closeFunc : false - }; - if (containerDiv) this.setDiv(containerDiv,options); - }, - - createContainer: function(options) { - this.setDiv(document.createElement('div'), options); - if (options && options.parent) { - options.parent.appendChild(this.container); - } else { - document.getElementsByTagName("body")[0].appendChild(this.container); - } - }, - -/** - * Apply popup behavior to a div that already exists in the DOM - * @param containerDiv div element (or element id) in the DOM. If null, then the div is created automatically. - */ - setDiv: function(containerDiv,options) { - Rico.extend(this.options, options || {}); - this.container=Rico.$(containerDiv); - if (this.options.position == 'auto') { - this.position=Rico.getStyle(this.container,'position').toLowerCase(); - } else { - this.position=this.container.style.position=this.options.position; - } - if (this.position != 'absolute') { - this.content=this.container; - return; - } - if (this.options.zIndex >= 0) this.container.style.zIndex=this.options.zIndex; - this.closeFunc=this.options.closeFunc || Rico.bind(this,'closePopup'); - //this.container.style.overflow='hidden'; - this.container.style.top='0px'; - this.container.style.left='0px'; - this.container.style.display='none'; - - var tab=Rico.applyShadow(null,this.options.shadow); - tab.style.position='relative'; - this.contentCell=tab.rows[0].cells[0]; - - if (Rico.isIE && Rico.ieVersion < 7) { - // create iframe shim - this.ifr = document.createElement('iframe'); - this.ifr.style.position="absolute"; - this.ifr.style.top = '0px'; - this.ifr.style.left = '0px'; - this.ifr.style.width = '2000px'; - this.ifr.style.height = '2000px'; - this.ifr.style.zIndex = -1; - this.ifr.frameBorder = 0; - this.ifr.src="javascript:false;"; - this.contentCell.appendChild(this.ifr); - } - this.content=this.contentCell.appendChild(document.createElement('div')); - this.content.className='RicoPopupContent'; - this.content.style.position='relative'; - - while (this.container.firstChild) { - this.content.appendChild(this.container.firstChild); - } - this.container.appendChild(tab); - - if (this.options.hideOnClick) - Rico.eventBind(document,"click", Rico.eventHandle(this,'_docClick')); - if (this.options.hideOnEscape) - Rico.eventBind(document,"keyup", Rico.eventHandle(this,'_checkKey')); - this.dragEnabled=false; - this.mousedownHandler = Rico.eventHandle(this,'_startDrag'); - this.dragHandler = Rico.eventHandle(this,'_drag'); - this.dropHandler = Rico.eventHandle(this,'_endDrag'); - if (this.options.canDrag) this.enableDragging(); - if (this.options.ignoreClicks || this.options.canDrag) this.ignoreClicks(); - }, - - clearContent: function() { - this.content.innerHTML=""; - }, - - setContent: function(content) { - this.content.innerHTML=content; - }, - - enableDragging: function() { - if (!this.dragEnabled && this.options.dragElement) { - Rico.eventBind(this.options.dragElement, "mousedown", this.mousedownHandler); - this.dragEnabled=true; - } - return this.dragEnabled; - }, - - disableDragging: function() { - if (!this.dragEnabled) return; - Rico.eventUnbind(this.options.dragElement, "mousedown", this.mousedownHandler); - this.dragEnabled=false; - }, - - setZ: function(zIndex) { - this.container.style.zIndex=zIndex; - }, - -/** @private */ - ignoreClicks: function() { - Rico.eventBind(this.container,"click", Rico.eventHandle(this,'_ignoreClick')); - }, - - _ignoreClick: function(e) { - if (e.stopPropagation) - e.stopPropagation(); - else - e.cancelBubble = true; - return true; - }, - - // event handler to process keyup events (hide menu on escape key) - _checkKey: function(e) { - if (Rico.eventKey(e)!=27 || !this.visible()) return true; - //alert('closing popup: '+this.container.className); - Rico.eventStop(e); - this.closeFunc(); - return false; - }, - - _docClick: function(e) { - this.closeFunc(); - return true; - }, - -/** - * Move popup to specified position - */ - move: function(left,top) { - if (typeof left=='number') this.container.style.left=left+'px'; - if (typeof top=='number') this.container.style.top=top+'px'; - }, - - _startDrag : function(event){ - var elem=Rico.eventElement(event); - this.container.style.cursor='move'; - this.lastMouse = Rico.eventClient(event); - Rico.eventBind(document, "mousemove", this.dragHandler); - Rico.eventBind(document, "mouseup", this.dropHandler); - Rico.eventStop(event); - }, - - _drag : function(event){ - var newMouse = Rico.eventClient(event); - var newLeft = parseInt(this.container.style.left,10) + newMouse.x - this.lastMouse.x; - var newTop = parseInt(this.container.style.top,10) + newMouse.y - this.lastMouse.y; - this.move(newLeft, newTop); - this.lastMouse = newMouse; - Rico.eventStop(event); - }, - - _endDrag : function(){ - this.container.style.cursor=''; - Rico.eventUnbind(document, "mousemove", this.dragHandler); - Rico.eventUnbind(document, "mouseup", this.dropHandler); - }, - -/** - * Display popup at specified position - */ - openPopup: function(left,top) { - this.container.style.display=this.position=='absolute' ? "block" : Rico.isIE && Rico.ieVersion<8 ? "inline" : "inline-block"; - if (typeof left=='number') this.container.style.left=left+'px'; - if (typeof top=='number') this.container.style.top=top+'px'; - if (this.container.id) Rico.log('openPopup '+this.container.id+' at '+left+','+top); - }, - - centerPopup: function() { - this.openPopup(); - var msgWidth=this.container.offsetWidth; - var msgHeight=this.container.offsetHeight; - var divwi=this.container.parentNode.offsetWidth; - var divht=this.container.parentNode.offsetHeight; - this.move(parseInt(Math.max((divwi-msgWidth)/2,0),10), parseInt(Math.max((divht-msgHeight)/2,0),10)); - }, - - visible: function() { - return Rico.visible(this.container); - }, - -/** - * Hide popup - */ - closePopup: function() { - if (!Rico.visible(this.container)) return; - if (this.container.id) Rico.log('closePopup '+this.container.id); - if (this.dragEnabled) this._endDrag(); - this.container.style.display="none"; - if (this.options.onClose) this.options.onClose(); - } - -}; - -Rico.closeButton = function(handle) { - var a = document.createElement('a'); - a.className='RicoCloseAnchor'; - if (Rico.theme.closeAnchor) Rico.addClass(a,Rico.theme.closeAnchor); - var span = a.appendChild(document.createElement('span')); - span.title=Rico.getPhraseById('close'); - new Rico.HoverSet([a]); - Rico.addClass(span,Rico.theme.close || 'RicoClose'); - Rico.eventBind(a,"click", handle); - return a; -}; - -Rico.floatButton = function(buttonName, handle, title) { - var a=document.createElement("a"); - a.className='RicoButtonAnchor' - Rico.addClass(a,Rico.theme.buttonAnchor || 'RicoButtonAnchorNative'); - var span=a.appendChild(document.createElement("span")); - if (title) span.title=title; - span.className=Rico.theme[buttonName.toLowerCase()] || 'Rico'+buttonName; - Rico.eventBind(a,"click", handle, false); - new Rico.HoverSet([a]); - return a -} - -Rico.clearButton = function(handle) { - var span=document.createElement("span"); - span.title=Rico.getPhraseById('clear'); - span.className='ricoClear'; - Rico.addClass(span, Rico.theme.clear || 'ricoClearNative'); - span.style.display='inline-block'; - span.style.cursor='pointer'; - Rico.eventBind(span,"click", handle); - return span; -} - -Rico.Window = function(title, options, contentParam) { - this.initialize(title, options, contentParam); -}; - -Rico.Window.prototype = { - -/** - * Create popup div with a title bar. - */ - initialize: function(title, options, contentParam) { - options=options || {overflow:'auto'}; - Rico.extend(this, new Rico.Popup()); - - this.titleDiv = document.createElement('div'); - this.options.canDrag=true; - this.options.dragElement=this.titleDiv; - this.options.hideOnClick=false; - this.createContainer(options); - this.content.appendChild(this.titleDiv); - contentParam=Rico.$(contentParam); - this.contentDiv=contentParam || document.createElement('div'); - this.content.appendChild(this.contentDiv); - - // create title area - this.titleDiv.className='ricoTitle'; - if (Rico.theme.dialogTitle) Rico.addClass(this.titleDiv,Rico.theme.dialogTitle); - this.titleDiv.style.position='relative'; - this.titleContent = document.createElement('span'); - this.titleContent.className='ricoTitleSpan'; - this.titleDiv.appendChild(this.titleContent); - this.titleDiv.appendChild(Rico.closeButton(Rico.eventHandle(this,'closePopup'))); - if (!title && contentParam) { - title=contentParam.title; - contentParam.title=''; - } - this.setTitle(title || ' '); - - // create content area - this.contentDiv.className='ricoContent'; - if (Rico.theme.dialogContent) Rico.addClass(this.contentDiv,Rico.theme.dialogContent); - this.contentDiv.style.position='relative'; - if (options.height) this.contentDiv.style.height=options.height; - if (options.width) this.contentDiv.style.width=options.width; - if (options.overflow) this.contentDiv.style.overflow=options.overflow; - Rico.addClass(this.content,'ricoWindow'); - if (Rico.theme.dialog) Rico.addClass(this.content,Rico.theme.dialog); - if (Rico.isIE) { - // fix float'ed content in IE - this.titleDiv.style.zoom=1; - this.contentDiv.style.zoom=1; - } - - this.content=this.contentDiv; - }, - - setTitle: function(title) { - this.titleContent.innerHTML=title; - } - -} - - -Rico.Menu = function(options) { - this.initialize(options); -} - -Rico.Menu.prototype = { -/** - * @class Implements popup menus and submenus - * @extends Rico.Popup - * @constructs - */ - initialize: function(options) { - Rico.extend(this, new Rico.Popup()); - Rico.extend(this.options, { - width : "15em", - showDisabled : false - }); - if (typeof options=='string') - this.options.width=options; - else - Rico.extend(this.options, options || {}); - this.hideFunc=null; - this.highlightElem=null; - new Image().src = Rico.imgDir+'left_b.gif'; - new Image().src = Rico.imgDir+'right_b.gif'; - }, - - createDiv: function(parentNode) { - if (this.container) return; - var options={closeFunc:Rico.bind(this,'cancelmenu')}; - if (parentNode) options.parent=parentNode; - this.createContainer(options); - this.content.className = Rico.isWebKit ? 'ricoMenuSafari' : 'ricoMenu'; - this.content.style.width=this.options.width; - this.direction=Rico.getStyle(this.container,'direction') || 'ltr'; - this.direction=this.direction.toLowerCase(); // ltr or rtl - this.hidemenu(); - this.itemCount=0; - }, - - showmenu: function(e,hideFunc){ - Rico.eventStop(e); - this.hideFunc=hideFunc; - if (this.content.childNodes.length==0) { - this.cancelmenu(); - return false; - } - var mousePos = Rico.eventClient(e); - this.openmenu(mousePos.x,mousePos.y,0,0); - }, - - openmenu: function(x,y,clickItemWi,clickItemHt,noOffset) { - var newLeft=x + (noOffset ? 0 : Rico.docScrollLeft()); - this.container.style.visibility="hidden"; - this.container.style.display="block"; - var w=this.container.offsetWidth; - var cw=this.contentCell.offsetWidth; - //window.status='openmenu: newLeft='+newLeft+' width='+w+' clickItemWi='+clickItemWi+' windowWi='+Rico.windowWidth(); - if (this.direction == 'rtl') { - if (newLeft > w+clickItemWi) newLeft-=cw+clickItemWi; - } else { - if (x+w > Rico.windowWidth()) newLeft-=cw+clickItemWi-2; - } - var scrTop=Rico.docScrollTop(); - var newTop=y + (noOffset ? 0 : scrTop); - if (y+this.container.offsetHeight-scrTop > Rico.windowHeight()) - newTop=Math.max(newTop-this.contentCell.offsetHeight+clickItemHt,0); - this.openPopup(newLeft,newTop); - this.container.style.visibility ="visible"; - return false; - }, - - clearMenu: function() { - this.clearContent(); - this.defaultAction=null; - this.itemCount=0; - }, - - addMenuHeading: function(hdg) { - var el=document.createElement('div'); - el.innerHTML=hdg; - el.className='ricoMenuHeading'; - this.content.appendChild(el); - }, - - addMenuBreak: function() { - var brk=document.createElement('div'); - brk.className="ricoMenuBreak"; - this.content.appendChild(brk); - }, - - addSubMenuItem: function(menutext, submenu, translate) { - var dir=this.direction=='rtl' ? 'left' : 'right'; - var a=this.addMenuItem(menutext,null,true,null,translate); - a.className='ricoSubMenu'; - a.style.backgroundImage='url('+Rico.imgDir+dir+'_b.gif)'; - a.style.backgroundRepeat='no-repeat'; - a.style.backgroundPosition=dir; - a.RicoSubmenu=submenu; - Rico.eventBind(a,"mouseover", Rico.eventHandle(this,'showSubMenu')); - Rico.eventBind(a,"mouseout", Rico.eventHandle(this,'subMenuOut')); - }, - - showSubMenu: function(e) { - if (this.openSubMenu) this.hideSubMenu(); - var a=Rico.eventElement(e); - this.openSubMenu=a.RicoSubmenu; - this.openMenuAnchor=a; - if (a.className=='ricoSubMenu') a.className='ricoSubMenuOpen'; - a.RicoSubmenu.openmenu(parseInt(this.container.style.left)+a.offsetWidth, parseInt(this.container.style.top)+a.offsetTop, a.offsetWidth-2, a.offsetHeight+2,true); - }, - - subMenuOut: function(e) { - if (!this.openSubMenu) return; - Rico.eventStop(e); - var elem=Rico.eventElement(e); - var reltg = Rico.eventRelatedTarget(e) || e.toElement; - try { - while (reltg != null && reltg != this.openSubMenu.div) - reltg=reltg.parentNode; - } catch(err) {} - if (reltg == this.openSubMenu.div) return; - this.hideSubMenu(); - }, - - hideSubMenu: function() { - if (this.openMenuAnchor) { - this.openMenuAnchor.className='ricoSubMenu'; - this.openMenuAnchor=null; - } - if (this.openSubMenu) { - this.openSubMenu.hidemenu(); - this.openSubMenu=null; - } - }, - - addMenuItemId: function(phraseId,action,enabled,title,target) { - if ( arguments.length < 3 ) enabled=true; - this.addMenuItem(Rico.getPhraseById(phraseId),action,enabled,title,target); - }, - -// if action is a string, then it is assumed to be a URL and the target parm can be used indicate which window gets the content -// action can also be a function (optionally wrapped using Rico.bind), -// action can also be a Rico.eventHandle, but set target='event' in this case - addMenuItem: function(menutext,action,enabled,title,target) { - if (arguments.length >= 3 && !enabled && !this.options.showDisabled) return null; - this.itemCount++; - var a = document.createElement(typeof action=='string' ? 'a' : 'div'); - if ( arguments.length < 3 || enabled ) { - if (typeof action=='string') { - a.href = action; - if (target) a.target = target; - } else if (target=='event') { - Rico.eventBind(a,"click", action); - } else { - a.onclick=action; - } - a.className = 'enabled'; - if (this.defaultAction==null) this.defaultAction=action; - } else { - a.disabled = true; - a.className = 'disabled'; - } - a.innerHTML = menutext; - if (typeof title=='string') - a.title = title; - a=this.content.appendChild(a); - Rico.eventBind(a,"mouseover", Rico.eventHandle(this,'mouseOver')); - Rico.eventBind(a,"mouseout", Rico.eventHandle(this,'mouseOut')); - return a; - }, - - mouseOver: function(e) { - if (this.highlightElem && this.highlightElem.className=='enabled-hover') { - // required for Safari - this.highlightElem.className='enabled'; - this.highlightElem=null; - } - var elem=Rico.eventElement(e); - if (this.openMenuAnchor && this.openMenuAnchor!=elem) - this.hideSubMenu(); - if (elem.className=='enabled') { - elem.className='enabled-hover'; - this.highlightElem=elem; - } - }, - - mouseOut: function(e) { - var elem=Rico.eventElement(e); - if (elem.className=='enabled-hover') elem.className='enabled'; - if (this.highlightElem==elem) this.highlightElem=null; - }, - - cancelmenu: function() { - if (!this.visible()) return; - if (this.hideFunc) this.hideFunc(); - this.hideFunc=null; - this.hidemenu(); - }, - - hidemenu: function() { - if (this.openSubMenu) this.openSubMenu.hidemenu(); - this.closePopup(); - } - -} - - -Rico.SelectionSet = function(selectionSet, options) { - this.initialize(selectionSet, options); -} - -Rico.SelectionSet.prototype = { -/** - * @class - * @constructs - * @param selectionSet collection of DOM elements (or a CSS selection string) - * @param options object may contain any of the following:
- *
selectedClass
class name to add when element is selected, default is "selected"
- *
selectNode
optional function that returns the element to be selected
- *
onSelect
optional function that gets called when element is selected
- *
onFirstSelect
optional function that gets called the first time element is selected
- *
noDefault
when true, no element in the set is initially selected, default is false
- *
selectedIndex
index of the element that should be initially selected, default is 0
- *
cookieName
optional name of cookie to use to remember selected element. If specified, and the cookie exists, then the cookie value overrides selectedIndex.
- *
cookieDays
specifies how long cookie should persist (in days). If unspecified, then the cookie persists for the current session.
- *
cookiePath
optional cookie path
- *
cookieDomain
optional cookie domain
- *
- */ - initialize: function(selectionSet, options){ - Rico.log('SelectionSet#initialize'); - this.options = options || {}; - if (typeof selectionSet == 'string') - selectionSet = Rico.select(selectionSet); - this.previouslySelected = []; - this.selectionSet = []; - this.selectedClassName = this.options.selectedClass || Rico.theme.selected || "selected"; - this.selectNode = this.options.selectNode || function(e){return e;}; - this.onSelect = this.options.onSelect; - this.onFirstSelect = this.options.onFirstSelect; - this.clickHandler = Rico.bind(this,'selectIndex'); - this.selectedIndex=-1; - for (var i=0; i= 0) this.selectIndex(i); - }, - _notifySelected: function(index){ - if (index < 0) return; - var element = this.selectionSet[index]; - if (this.options.cookieName) - Rico.setCookie(this.options.cookieName, index, this.options.cookieDays, this.options.cookiePath, this.options.cookieDomain); - if (this.onFirstSelect && !this.previouslySelected[index]){ - this.onFirstSelect(element, index); - this.previouslySelected[index] = true; - } - if (this.onSelect) - try{ - this.onSelect(index); - } catch (e) {}; - }, - selectIndex: function(index){ - if (this.selectedIndex == index || index >= this.selectionSet.length) return; - this.clearSelected(); - this._notifySelected(index); - this.selectedIndex = index; - this.selected=this.selectionSet[index].element; - Rico.addClass(this.selectNode(this.selected), this.selectedClassName); - }, - nextSelectIndex: function(){ - return (this.selectedIndex + 1) % this.selectionSet.length; - }, - nextSelectItem: function(){ - return this.selectionSet[this.nextSelectIndex()]; - }, - selectNext: function(){ - this.selectIndex(this.nextSelectIndex()); - }, - add: function(item){ - var index=this.selectionSet.length; - this.selectionSet[index] = new Rico._SelectionItem(item,index,this.clickHandler); - }, - remove: function(item){ - if (item==this.selected) this.clearSelected(); - var i=this.getIndex(item); - if (i < 0) return; - this.selectionSet[i].remove(); - this.selectionSet.splice(i,1); - }, - removeAll: function(){ - this.clearSelected(); - while (this.selectionSet.length > 0) { - this.selectionSet.pop().remove(); - } - } -}; - - -Rico._SelectionItem=function(element,index,callback) { - this.add(element,index,callback); -}; - -Rico._SelectionItem.prototype = { - add: function(element,index,callback) { - this.element=element; - this.index=index; - this.callback=callback; - this.handle=Rico.eventHandle(this,'click'); - Rico.eventBind(element, "click", this.handle); - }, - - click: function(ev) { - this.callback(this.index); - }, - - remove: function() { - Rico.eventUnbind(this.element, "click", this.handle); - } -}; - - -Rico.HoverSet = function(hoverSet, options) { - this.initialize(hoverSet, options); -}; - -Rico.HoverSet.prototype = { -/** - * @class - * @constructs - * @param hoverSet collection of DOM elements - * @param options object may contain any of the following:
- *
hoverClass
class name to add when mouse is over element, default is "hover"
- *
hoverNodes
optional function to select/filter which nodes are in the set
- *
- */ - initialize: function(hoverSet, options){ - Rico.log('HoverSet#initialize'); - options = options || {}; - this.hoverClass = options.hoverClass || Rico.theme.hover || "hover"; - this.hoverFunc = options.hoverNodes || function(e){return [e];}; - this.hoverSet=[]; - if (!hoverSet) return; - for (var i=0; i 0) { - this.hoverSet.pop().remove(); - } - } -}; - - -Rico._HoverItem=function(element,selectFunc,hoverClass) { - this.add(element,selectFunc,hoverClass); -}; - -Rico._HoverItem.prototype = { - add: function(element,selectFunc,hoverClass) { - this.element=element; - this.selectFunc=selectFunc; - this.hoverClass=hoverClass; - this.movehandle=Rico.eventHandle(this,'move'); - this.outhandle=Rico.eventHandle(this,'mouseout'); - Rico.eventBind(element, "mousemove", this.movehandle); - Rico.eventBind(element, "mouseout", this.outhandle); - }, - - move: function(ev) { - var elems=this.selectFunc(this.element); - for (var i=0; i=2) { - items[0].className=options.titleClass || Rico.theme.accTitle || "Rico_accTitle"; - items[1].className=options.contentClass || Rico.theme.accContent || "Rico_accContent"; - titles.push(items[0]); - contents.push(items[1]); - var a=Rico.wrapChildren(items[0],'','','a'); - a.href="javascript:void(0)"; - } - } - Rico.log('creating Rico.Accordion for '+element.id+' with '+titles.length+' panels'); - this.initBase(titles, contents, options); - this.selected.style.height = this.options.panelHeight + "px"; - this.totSteps=(typeof options.duration =='number' ? options.duration : 200)/25; - }, - transition: function(p){ - if (!this.options.noAnimate) { - this.closing=this.selected; - this.opening=p; - this.curStep=0; - this.timer=setInterval(Rico.bind(this,'step'),25); - } else { - p.style.height = this.options.panelHeight + "px"; - if (this.selected) Rico.hide(this.selected); - p.style.display='block'; - } - }, - step: function() { - this.curStep++; - var oheight=Math.round(this.curStep/this.totSteps*this.options.panelHeight); - this.opening.style.height=oheight+'px'; - this.closing.style.height=(this.options.panelHeight - oheight)+'px'; - if (this.curStep==1) { - this.opening.style.paddingTop=this.opening.style.paddingBottom='0px'; - this.opening.style.display='block'; - } - if (this.curStep==this.totSteps) { - clearInterval(this.timer); - this.opening.style.paddingTop=this.opening.style.paddingBottom=''; - Rico.hide(this.closing); - } - }, - setPanelHeight: function(h) { - this.options.panelHeight = h; - this.selected.style.height = this.options.panelHeight + "px"; - } -}); - - -/** - * @class Implements tabbed panel effect - * @see Rico.ContentTransitionBase#initialize for construction parameters - * @extends Rico.ContentTransitionBase - */ -Rico.TabbedPanel = function(element, options) { - this.initialize(element, options); -}; - -Rico.TabbedPanel.prototype = Rico.extend(new Rico.ContentTransitionBase(), -{ - initialize: function(element, options) { - element=Rico.$(element); - options=options || {}; - if (typeof options.panelWidth=='number') options.panelWidth+="px"; - if (typeof options.panelHeight=='number') options.panelHeight+="px"; - element.className=options.tabClass || Rico.theme.tabPanel || "Rico_tabPanel"; - if (options.panelWidth) element.style.width = options.panelWidth; - var items = []; - var allKids = element.childNodes; - for( var i = 0 ; i < allKids.length ; i++ ) { - if (allKids[i] && allKids[i].tagName && allKids[i].tagName.match(/^div|ul$/i)) - items.push(allKids[i]); - } - if (items.length < 2) return; - var childTag=items[0].tagName.toLowerCase()=='ul' ? 'li' : 'div'; - items[0].className=options.navContainerClass || Rico.theme.tabNavContainer || "Rico_tabNavContainer"; - items[0].style.listStyle='none'; - items[1].className=options.contentContainerClass || Rico.theme.tabContentContainer || "Rico_tabContentContainer"; - var titles=Rico.getDirectChildrenByTag(items[0], childTag); - var contents=Rico.getDirectChildrenByTag(items[1],'div'); - if (!options.corners) options.corners='top'; - for (var i=0; i= 0) return true; - } - return false; - } - -}; - -Rico.toColorPart = function(c) { - return Rico.zFill(c, 2, 16); -}; - - -Rico.Color = function(red, green, blue) { - this.initialize(red, green, blue); -}; - -Rico.Color.prototype = { -/** - * @class Methods to manipulate color values. - * @constructs - * @param red integer (0-255) - * @param green integer (0-255) - * @param blue integer (0-255) - */ - initialize: function(red, green, blue) { - this.rgb = { r: red, g : green, b : blue }; - }, - - setRed: function(r) { - this.rgb.r = r; - }, - - setGreen: function(g) { - this.rgb.g = g; - }, - - setBlue: function(b) { - this.rgb.b = b; - }, - - setHue: function(h) { - - // get an HSB model, and set the new hue... - var hsb = this.asHSB(); - hsb.h = h; - - // convert back to RGB... - this.rgb = Rico.Color.HSBtoRGB(hsb.h, hsb.s, hsb.b); - }, - - setSaturation: function(s) { - // get an HSB model, and set the new hue... - var hsb = this.asHSB(); - hsb.s = s; - - // convert back to RGB and set values... - this.rgb = Rico.Color.HSBtoRGB(hsb.h, hsb.s, hsb.b); - }, - - setBrightness: function(b) { - // get an HSB model, and set the new hue... - var hsb = this.asHSB(); - hsb.b = b; - - // convert back to RGB and set values... - this.rgb = Rico.Color.HSBtoRGB( hsb.h, hsb.s, hsb.b ); - }, - - darken: function(percent) { - var hsb = this.asHSB(); - this.rgb = Rico.Color.HSBtoRGB(hsb.h, hsb.s, Math.max(hsb.b - percent,0)); - }, - - brighten: function(percent) { - var hsb = this.asHSB(); - this.rgb = Rico.Color.HSBtoRGB(hsb.h, hsb.s, Math.min(hsb.b + percent,1)); - }, - - blend: function(other) { - this.rgb.r = Math.floor((this.rgb.r + other.rgb.r)/2); - this.rgb.g = Math.floor((this.rgb.g + other.rgb.g)/2); - this.rgb.b = Math.floor((this.rgb.b + other.rgb.b)/2); - }, - - isBright: function() { - var hsb = this.asHSB(); - return this.asHSB().b > 0.5; - }, - - isDark: function() { - return ! this.isBright(); - }, - - asRGB: function() { - return "rgb(" + this.rgb.r + "," + this.rgb.g + "," + this.rgb.b + ")"; - }, - - asHex: function() { - return "#" + Rico.toColorPart(this.rgb.r) + Rico.toColorPart(this.rgb.g) + Rico.toColorPart(this.rgb.b); - }, - - asHSB: function() { - return Rico.Color.RGBtoHSB(this.rgb.r, this.rgb.g, this.rgb.b); - }, - - toString: function() { - return this.asHex(); - } - -}; - -/** - * Factory method for creating a color from an RGB string - * @param hexCode a 3 or 6 digit hex string, optionally preceded by a # symbol - * @returns a Rico.Color object - */ -Rico.Color.createFromHex = function(hexCode) { - if(hexCode.length==4) { - var shortHexCode = hexCode; - hexCode = '#'; - for(var i=1;i<4;i++) - hexCode += (shortHexCode.charAt(i) + shortHexCode.charAt(i)); - } - if ( hexCode.indexOf('#') == 0 ) - hexCode = hexCode.substring(1); - if (!hexCode.match(/^[0-9A-Fa-f]{6}$/)) return null; - var red = hexCode.substring(0,2); - var green = hexCode.substring(2,4); - var blue = hexCode.substring(4,6); - return new Rico.Color( parseInt(red,16), parseInt(green,16), parseInt(blue,16) ); -}; - -/** - * Retrieves the background color of an HTML element - * @param elem the DOM element whose background color should be retreived - * @returns a Rico.Color object - */ -Rico.Color.createColorFromBackground = function(elem) { - - if (!elem.style) return new Rico.Color(255,255,255); - var actualColor = Rico.getStyle(elem, "background-color"); - - // if color is tranparent, check parent - // Safari returns "rgba(0, 0, 0, 0)", which means transparent - if ( actualColor.match(/^(transparent|rgba\(0,\s*0,\s*0,\s*0\))$/i) && elem.parentNode ) - return Rico.Color.createColorFromBackground(elem.parentNode); - - if (actualColor == null) return new Rico.Color(255,255,255); - - if ( actualColor.indexOf("rgb(") == 0 ) { - var colors = actualColor.substring(4, actualColor.length - 1 ); - var colorArray = colors.split(","); - return new Rico.Color( parseInt( colorArray[0],10 ), - parseInt( colorArray[1],10 ), - parseInt( colorArray[2],10 ) ); - - } - else if ( actualColor.indexOf("#") == 0 ) { - return Rico.Color.createFromHex(actualColor); - } - else - return new Rico.Color(255,255,255); -}; - -/** - * Converts hue/saturation/brightness to RGB - * @returns a 3-element object: r=red, g=green, b=blue. - */ -Rico.Color.HSBtoRGB = function(hue, saturation, brightness) { - - var red = 0; - var green = 0; - var blue = 0; - - if (saturation == 0) { - red = parseInt(brightness * 255.0 + 0.5,10); - green = red; - blue = red; - } - else { - var h = (hue - Math.floor(hue)) * 6.0; - var f = h - Math.floor(h); - var p = brightness * (1.0 - saturation); - var q = brightness * (1.0 - saturation * f); - var t = brightness * (1.0 - (saturation * (1.0 - f))); - - switch (parseInt(h,10)) { - case 0: - red = (brightness * 255.0 + 0.5); - green = (t * 255.0 + 0.5); - blue = (p * 255.0 + 0.5); - break; - case 1: - red = (q * 255.0 + 0.5); - green = (brightness * 255.0 + 0.5); - blue = (p * 255.0 + 0.5); - break; - case 2: - red = (p * 255.0 + 0.5); - green = (brightness * 255.0 + 0.5); - blue = (t * 255.0 + 0.5); - break; - case 3: - red = (p * 255.0 + 0.5); - green = (q * 255.0 + 0.5); - blue = (brightness * 255.0 + 0.5); - break; - case 4: - red = (t * 255.0 + 0.5); - green = (p * 255.0 + 0.5); - blue = (brightness * 255.0 + 0.5); - break; - case 5: - red = (brightness * 255.0 + 0.5); - green = (p * 255.0 + 0.5); - blue = (q * 255.0 + 0.5); - break; - } - } - - return { r : parseInt(red,10), g : parseInt(green,10) , b : parseInt(blue,10) }; -}; - -/** - * Converts RGB value to hue/saturation/brightness - * @param r integer (0-255) - * @param g integer (0-255) - * @param b integer (0-255) - * @returns a 3-element object: h=hue, s=saturation, b=brightness. - * (unlike some HSB documentation which states hue should be a value 0-360, this routine returns hue values from 0 to 1.0) - */ -Rico.Color.RGBtoHSB = function(r, g, b) { - - var hue; - var saturation; - var brightness; - - var cmax = (r > g) ? r : g; - if (b > cmax) - cmax = b; - - var cmin = (r < g) ? r : g; - if (b < cmin) - cmin = b; - - brightness = cmax / 255.0; - if (cmax != 0) - saturation = (cmax - cmin)/cmax; - else - saturation = 0; - - if (saturation == 0) - hue = 0; - else { - var redc = (cmax - r)/(cmax - cmin); - var greenc = (cmax - g)/(cmax - cmin); - var bluec = (cmax - b)/(cmax - cmin); - - if (r == cmax) - hue = bluec - greenc; - else if (g == cmax) - hue = 2.0 + redc - bluec; - else - hue = 4.0 + greenc - redc; - - hue = hue / 6.0; - if (hue < 0) - hue = hue + 1.0; - } - - return { h : hue, s : saturation, b : brightness }; -}; - -/** - * Returns a new XML document object - */ -Rico.createXmlDocument = function() { - if (document.implementation && document.implementation.createDocument) { - var doc = document.implementation.createDocument("", "", null); - // some older versions of Moz did not support the readyState property - // and the onreadystate event so we patch it! - if (doc.readyState == null) { - doc.readyState = 1; - doc.addEventListener("load", function () { - doc.readyState = 4; - if (typeof doc.onreadystatechange == "function") { - doc.onreadystatechange(); - } - }, false); - } - return doc; - } - - if (window.ActiveXObject) - return Rico.tryFunctions( - function() { return new ActiveXObject('MSXML2.DomDocument'); }, - function() { return new ActiveXObject('Microsoft.DomDocument');}, - function() { return new ActiveXObject('MSXML.DomDocument'); }, - function() { return new ActiveXObject('MSXML3.DomDocument'); } - ) || false; - return null; -} - -Rico.includeLoaded('ricoUI.js'); -- 2.20.1