From: Thyamad c. <th...@us...> - 2006-01-28 13:38:22
|
Update of /cvsroot/thyapi/thyapi/thywidgets In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13437/thywidgets Modified Files: thydropdownbox_ie.js thylistbox.js Added Files: thylistbox_ie.js Log Message: Commiting file additions and modification from SVN revision 2727 to 2728... Changes made by vinicius on 2006-01-28 15:45:02 +0100 (Sat, 28 Jan 2006) corresponding to SVN revision 2728 with message: Listbox with select multiple for IE --- NEW FILE: thylistbox_ie.js --- /***************************************************************************\ * ThyAPI - Thyamad Javascript API - Drop-Down Combo Box Element * * http://www.thyamad.com * * * * Copyright (C) 2005, 2006 - Raphael Derosso Pereira, Vinicius Cubas Brand * * Based on DynAPI v3.0b1 * * ------------------------------------------------------------------------- * * This library is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as published * * by the Free Software Foundation; either version 2.1 of the License, * * or any later version. * * This library is distributed in the hope that it will be useful, but * * WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * See the GNU Lesser General Public License for more details. * \***************************************************************************/ /** * Class: thyListBox * * This is the ListBox Element, that uses a selectbox multiple * */ function thyListBox(name,label) { this.thyLabelPanel = thyLabelPanel; this.thyLabelPanel(name,label); // Atributes this.containerWindow = null; //These selected* arguments are only used when this element has not been created this.selectedIndex = null; this.selectedValue = null; this.selectedContent = null; /* in thylistbox_ie */ this.popcontents = { }; this.addCSSClass('thyListBox'); this.contents.addCSSClass(this.name); this.onPreCreate(this.preInitThyListBox); this.onCreate(this.initThyListBox); this.addEventListener({ onparentchange: this._dropDownParentChange() }); /* Essa classe deve ter os eventos onselect e onchange */ } p = dynapi.setPrototype('thyListBox', 'thyLabelPanel'); /** * Method: initThyListBox * * Initialization Method * */ p.initThyListBox = function() { this.contents.elm.childNodes[0]._dynobj = this; } /** * Method: preInitThyListBox * * Initialization method executed right before element creation * */ p.preInitThyListBox = function() { this.contents.setRelativeness(false); this.setHTML(['<select multiple ', 'class="thyEditBox_input '+this.name+'_input" ', 'style="', 'width: 100%;', 'height: 100%;', 'left: 0px;', 'right: 0px;', 'background: inherit;', 'background-color: inherit;', 'text-align: inherit;', 'color: inherit;', 'border: 0px;', 'z-index: inherit" ', (this.readOnly ? 'readonly ': ''), (this.disabled ? 'disabled ': ''), '>', this._getHTMLContents(), '</select>' ].join('') ); } /** * Method: getContentByValue * * Returns the associated content with the specified value * * Parameter: * * value - The value associated with the needed content * */ p.getContentByValue = function (value) { var opt = this._getOptionByValue(value); if (opt) { return opt.text; } } /** * Method: setContentByValue * * Changes the content associated with the specified value * * Parameters: * * value - The value associated with the needed content * content - The new content * */ p.setContentByValue = function(value,content) { var opt = this._getOptionByValue(value); if (opt) { opt.text = content; } } p._thyLabelPanelAddChild = p.addChild; /** * Method: addChild * * Overloaded method that prevents the insertion of children in <thyListBox> * */ p.addChild = function () { throw({result: 'No meaning on adding child to thyListBox', location:'thyListBox.addChild'}); } p._thyLabelPanelRemoveChild = p.removeChild; /** * Method: removeChild * * Overloaded method that prevents the removal of children of <thyListBox> * */ p.removeChild = function () { throw({result: 'No meaning on adding child to thyListBox', location:'thyListBox.addChild'}); } p._thyLabelPanelSetName = p.setName; /** * Method: setName * * Overwritten method that sets the name of main, button and listbox * and refreshes CSS Classes * * Parameter: * * name - The new widget name * */ p.setName = function (name) { if (name == null || this.name == name) return; var old_name = this.name; this._thyLabelPanelSetName(name); this.contents.elm.childNodes[0].className += (this.name + '_input'); } /** * Method: reset * * Resets dropdown to defaultValue * */ p.reset = function () { var selopts = this.contents.elm.childNodes[0].options, i; for (i=0;i<selopts.length;i++) { selopts[i].selected = false; } } /** * Method: appendRow * * Method that garantees if the user sends just one field for each roll, * they will be assumed as contents and their values will be set to null * * viniciuscb: why null???? */ p.appendRow = function(row) { var nCells = row.getElementsCount(); if (!this._created) { if (!this.popcontents.rows) { this.popcontents.rows = []; } var insrow = [], i; for (i=0;i<nCells;i++) { insrow.push(row.getElementByIndex(i)); } this.popcontents.rows.push(insrow); return; } opt = document.createElement('option'); sel = this.contents.elm.childNodes[0]; if (nCells < 2) { opt.value = null; opt.text = row.i(0); } else { opt.value = row.i(0); opt.text = row.i(1); } sel.options.add(opt); } p.insertRow = p.appendRow; /** * Method: getSelectedValues * * Returns an array with the values of the selected rows * */ p.getSelectedValues = function() { var selarr = this._getSelectedArray(), selectedValues = [], i; for (i in selarr) { selectedValues.push(selarr[i].v); } return selectedValues; } /** * Method: getSelectedNames * * Returns an array with the names (captions) of the selected rows * */ p.getSelectedNames = function() { var selarr = this._getSelectedArray(), selectedNames = [], i; for (i in selarr) { selectedNames.push(selarr[i].n); } return selectedNames; } /** * Method: getSelectedIndexes * * Returns an array with the indexes of the selected rows * */ p.getSelectedIndexes = function() { var selarr = this._getSelectedArray(), selectedIndexes = [], i; for (i in selarr) { selectedIndexes.push(selarr[i].i); } return selectedIndexes; } /** * Method: getSelected * * Returns all selected informations * * See <thyGrid::getSelectedRows> for more information * */ p.getSelected = function() { var selarr = this._getSelectedArray(), i; var retcol = new thyCollection(), retrow; for (i in selarr) { retrow = new thyCollection(); retrow.add(selarr[i].v); retrow.add(selarr[i].n); retcol.add(retrow); } return retcol; } p.getSelectedRows = p.getSelected; /** * Method: removeSelected * * Removes all selected rows * * See <thyGrid::removeSelectedRows> for more information * */ p.removeSelected = function() { var selopt = this.contents.elm.childNodes[0].options, i; for (i=0; i< selopt.length; i++) { if (selopt[i].selected) { selopt[i] = null; } } return ret; } /** * Method: search * * Searches for a specified string inside values column * * Parameter: * * str - The string to be searched for * * Returns: the row index */ p.search = function (str) { var selopt = this.contents.elm.childNodes[0].options, i; for (i=0;i<selopt.length;i++) { if (selopt[i].value.indexOf(str) != -1) { return i; } } } /*************************************************************************\ * Group: Private Methods * \*************************************************************************/ p._addOption = function(value,content) { if (!value && !content) return; var sel = this.contents.elm.childNodes[0]; var opt = document.createElement('option'); opt.value = value; opt.text = content; sel.options.add(opt); } p._thyLabelPanel_destroy = p._destroy; /** * Method: _destroy * * Overloaded method that removes dropList from memory * */ p._destroy = function () { /* This avoids memory leak in IE */ this.contents.elm.childNodes[0]._dynobj = null; this._thyLabelPanel_destroy(); } /** * Method: cleanUp * * Cleans up all values from the component * */ p.cleanUp = function () { var sel = this.contents.elm.childNodes[0]; while (sel.firstChild) { sel.removeChild(sel.firstChild); } } p.removeAllRows = p.cleanUp; p._thyLabelPanel_setDisabled = p._setDisabled; /** * Method: _setDisabled * * Executed when non-private <thyPanel> setDisabled method is called * */ p._setDisabled = function () { this._thyLabelPanel_setDisabled(); if (!this._created) return; this.contents.elm.childNodes[0].setAttribute('disabled', ''); this.contents.elm.childNodes[0].disabled = this.disabled; } /** * Method: _populateContents * * Sets the contents of the <thyListBox>. This is the same populate as * <thyListBox>::populate, so pass correct formated data. * * Parameter: * * data - The <thyListBox> possible values * */ p._populateContents = function (data) {/* var i, j, row, cell; if (!data.selectedValues || data.rows) { var rows; if (data.rows) rows = data.rows; else rows = data; this.cleanUp(); for (i = 0; i<rows.length; i++) { if (typeof(rows[i]) != 'object') rows[i] = [rows[i]]; row = new thyCollection('Row'+i); for (j=0; j<rows[i].length; j++) { row.add(rows[i][j],'Cell'+i+j); } this.appendRow(row); } } if (data.selectedValues) { var values = data.selectedValues; var nValues = data.selectedValues.length; var nRows = this.getRowsCount(); for (i=0; i<nValues; i++) { for (j=0; j<nRows; j++) { if (this.getRowElement(j).getCellElement(0).sweepOut() == values[i]) this.getRowElement(j).select(); } } }*/ if (typeof(data) == 'number') { data = {index: data}; } if (typeof(data) == 'object') { this.popcontents = contents; this._updateDOMElement(); } } /** * Method: _sweepOutContents * * Gets the value that was selected by the user. * */ p._sweepOutContents = function () { var data = { selectedValues: this.getSelectedValues(), selectedIndexes: this.getSelectedIndexes() }; return data; } p._thyLabelPanel_addCSSClass = p._addCSSClass; /** * Method: _addCSSClass * * Overwritten method that adds the class to main, button and listbox * * Parameter: * * cssClass - The cssClass to be added * */ p._addCSSClass = function (cssClass) { this._thyLabelPanel_addCSSClass(cssClass); /* VINICIUS: mudar isto */ /* if (this.dropButton) { this.dropEdit._addCSSClass(cssClass+'_edit'); this.dropButton._addCSSClass(cssClass+'_button'); this.dropList._addCSSClass(cssClass+'_listBox'); }*/ } p._thyLabelPanel_removeCSSClass = p._removeCSSClass; /** * Method: _removeCSSClass * * Overwritten method that removes the specified CSS Class from main, * button and listbox * * Parameter: * * cssClass - The cssClass to be removed * */ p._removeCSSClass = function (cssClass) { this._thyLabelPanel_removeCSSClass(cssClass); /* VINICIUS: mudar isto */ /* if (this.dropButton) { this.dropEdit._removeCSSClass(cssClass+'_edit'); this.dropButton._removeCSSClass(cssClass+'_button'); this.dropList._removeCSSClass(cssClass+'_list'); }*/ } /** * Method: _getHTMLContents * * This class is used in the creation of the current component */ p._getHTMLContents = function() { var selected = false, str = [ ], contents = this.popcontents.rows, i, j = 0; for (i in contents) { if (j == this.selectedIndex || contents[i][1] == this.selectedValue) { str.push('<option value="'+contents[i][0]+'" SELECTED>'+contents[i][1]+'</option>'); } else { str.push('<option value="'+contents[i][0]+'">'+contents[i][1]+'</option>'); } j++; } return str.join(''); } /** * Method: _updateDOMElement * * Updates the DOM Element * * Actually, it erases all the select's contents and puts some new contents */ p._updateDOMElement = function() { if (!this._created) return; var cont = this.popcontents.rows; var selvalues = this.popcontents.selectedValues ; this.cleanUp(); var sel = this.contents.elm.childNodes[0], j = 0, optlist = { }; for (var i in cont) { var opt = this.parent.doc.createElement('option'); if (cont[i].length == 1) { opt.value = null; opt.text = cont[i][0]; } else { opt.value = cont[i][0]; opt.text = cont[i][1]; } sel.options.add(opt); optlist[opt.value] = cont[i][0]; } if (selvalues) { for (j in selvalues) { if (optlist[selvalues[j]]) { optlist[selvalues[j]].selected = true; } else { optlist[selvalues[j]].selected = false; } } } } /** * Method: _getSelectedArray * * Returns an array with the selected elements * * Format of the returned array: an array, where each element is an object * with the atributes 'i' (index), 'v' (value) and 'n' (name/caption) */ p._getSelectedArray = function() { var selopt = this.contents.elm.childNodes[0].options, ret = [ ], i, j=0; for (i=0; i<selopt.length; i++) { if (selopt[i].selected) { ret.push({ i: j, v: selopt[i].value, t: selopt[i].text}); } j++; } return ret; } /** * Method: _getElementWithValue * * Returns an OPTION element with the respective value given */ p._getOptionByValue = function(value) { var selopt = this.contents.elm.childNodes[0].options, i; for (i=0; i< selopt.length; i++) { if (selopt[i].value == value) { return selopt[i]; } } } /*************************************************************************\ * Group: Events Methods * \*************************************************************************/ /** VINICIUS: assignar os eventos desse objeto ao dropdown */ p._dropDownParentChange = function() { var self = this; return function() { if (self.parent && self.parent._attachWindowed) { self.parent._attachWindowed(self); } else { self.containerWindow = null; } } } /****************************************************************************\ * Group: Misc Operations * \****************************************************************************/ Index: thylistbox.js =================================================================== RCS file: /cvsroot/thyapi/thyapi/thywidgets/thylistbox.js,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** thylistbox.js 26 Jan 2006 16:25:36 -0000 1.8 --- thylistbox.js 28 Jan 2006 13:38:10 -0000 1.9 *************** *** 164,168 **** /** ! * Method: getSelectedValues * * Returns an array with the names (captions) of the selected rows --- 164,168 ---- /** ! * Method: getSelectedNames * * Returns an array with the names (captions) of the selected rows *************** *** 328,333 **** p._sweepOutContents = function () { - var selRows = this.getSelectedRows(); - var i,nRows = selRows.length(); var data = { selectedValues: this.getSelectedValues(), --- 328,331 ---- Index: thydropdownbox_ie.js =================================================================== RCS file: /cvsroot/thyapi/thyapi/thywidgets/thydropdownbox_ie.js,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** thydropdownbox_ie.js 27 Jan 2006 10:29:35 -0000 1.2 --- thydropdownbox_ie.js 28 Jan 2006 13:38:10 -0000 1.3 *************** *** 396,409 **** } - /** - * Method: hide - * - * Hides - */ - p.hide = function() - { - - } - /*************************************************************************\ --- 396,399 ---- |