") + 1, pos2); jsHtml = jsHtml.substring(pos2 + 9); eval(jsCode); } if(WOSSelector.createIdCalc != null) { var portletHide = WebOS_popup.Client.getField(WOSSelector.idField).topics[0]; portletHide = portletHide.substring(0, portletHide.lastIndexOf("__")); if(getTag(portletHide)) { getTag(portletHide).style.display = "none"; } /*html = '<' + 'script>WebOS_popup.Client.registerFieldDependency( "' + newtoid + '", "sel_new__snvZ01__' + WOSSelector.idField + '", "' + WOSSelector.idField + '", "' + WOSSelector.idField + '", "' + WOSSelector.idField + '", [ ] , "" );' + 'script>' + '' + html;*/ } } } function ve_sel_new_addRequiredField( id, name ) { ve_sel_new_requiredFields[ ve_sel_new_requiredFields.length ] = new RequiredField( id, name ); } function getPopupField( fieldName ) { var tag = getTag(WebOS_popup.Client.getField(fieldName).tname); return (tag ? ( tag.value == undefined ? tag.innerHTML : tag.value ) : null); } var WOSSelector = { urlPrefix: null, toid: null, uniID: null, folderName: null, isMultiple: false, idField: null, createIdCalc: null, searchString: null, searchParam: null, pageSize: 250, fields: {}, advancedCriteria: {}, advancedPopup: null, tabs: [], selection: [], buttons: { "Submit" : [ "Submit", null ], "Cancel" : [ "Cancel", null ], "Clear" : [ "Clear", null ] }, onOpen: function() { customSelectFetch( this.urlPrefix, this.uniID, this.folderName, null, null, this.getFieldProperty( this.topic, "ref" ) ); if( WOSSelector.isMultiple ) WOSSelector.syncSelectionList(); }, action_Submit: function() { var secondtab = document.getElementById('newFolderEntry' + this.uniID); if ( getStyle( secondtab.parentNode, 'display') != 'none' ) { // second tab if( ve_validateRequiredFields( true ) ) { tabChange( document.getElementById('selectorTabs' + this.uniID).getElementsByTagName('LI')[0] ); var newform = document.getElementById('newObject' + this.uniID); var searchStr; if(this.createIdCalc != null) { eval("searchStr = " + this.createIdCalc); getTag(WebOS_popup.Client.getField(WOSSelector.idField).tname).value = searchStr; getTag(WebOS_popup.Client.getField(WOSSelector.idField).tname).onchange(); } var newtoid = newform.getAttribute("toid") + "__" + this.idField; searchStr = ve_getStringValue( newtoid, newtoid ); this.select( secondtab.getAttribute('newoid'), searchStr ); newform.submit(); if ( this.isMultiple ) { this.search(); } } } else { // first tab var lis = document.getElementById('selectorList' + this.uniID).getElementsByTagName('LI'); var temp = document.getElementById('selectorList' + this.uniID).getAttribute('hnfieldid'); var hidden = document.getElementById( temp ); var display = document.getElementById( 'display_' + temp ); var ds = document.getElementById( 'ds_' + temp ); var soid = document.getElementById( 'soid_' + temp ); var hiddenstr = ''; var soidstr = ''; var displaystr = ''; var dsstr = ''; for ( var i = 0; i < lis.length; i++ ) { if ( lis[i].getAttribute('remove') != 'true' ) { displaystr += lis[i].innerHTML + ", "; dsstr += lis[i].innerHTML + "|"; hiddenstr += lis[i].getAttribute('oid') + ","; soidstr += lis[i].getAttribute('soid') + ","; lis[i].setAttribute('onclick', "customSelector.select(this)" ); } } // fix display hidden.value = hiddenstr.substring(0, hiddenstr.length - 1); hidden.name = hidden.id; soid.value = soidstr.substring(0, soidstr.length - 1); soid.name = soid.id; ds.value = dsstr.substring(0, dsstr.length - 1); display.innerHTML = displaystr.substring(0, displaystr.length - 2); /* if ( !this.isMultiple ) { hidden.value = hiddenstr.substring(0, hiddenstr.indexOf(",") ); hidden.name = hidden.id; soid.value = soidstr.substring(0, soidstr.indexOf(",") ); soid.name = soid.id; ds.value = displaystr.substring(0, displaystr.indexOf(",") ); display.innerHTML = displaystr.substring(0, displaystr.indexOf(",") ); } else { hidden.value = hiddenstr.substring(0, hiddenstr.length - 1); hidden.name = hidden.id; soid.value = soidstr.substring(0, soidstr.length - 1); soid.name = soid.id; ds.value = dsstr.substring(0, dsstr.length - 1); display.innerHTML = displaystr.substring(0, displaystr.length - 2); } */ WOSSelector.updateOrder(soid.id, this.toid + "__" + temp.replace(this.toid, "").substring(3) + "Order"); // update sort field displayDefault = document.getElementById( 'display_default_' + temp ); if( displayDefault && display.innerHTML == "" ) displayDefault.style.display = "block"; else if( displayDefault ) displayDefault.style.display = "none"; CustomPopup.close("selectorPopup" + this.uniID); getTopic( this.topic ).notify( temp, hidden.value ); } }, action_Cancel: function () { CustomPopup.close("selectorPopup" + this.uniID); }, action_Clear: function() { this.removeAll( ); if( !this.isMultiple ) this.action_Submit(); }, syncSelectionList: function() { //find out what was the original selection when the popup opened var ul = document.getElementById('selectorList' + this.uniID); var temp = ul.getAttribute('hnfieldid'); var hidden = document.getElementById( temp ); var originalSelection = []; if( hidden && hidden.value.length > 0 ) originalSelection = hidden.value.split(","); //clear the selector list li elements first var lis = ul.getElementsByTagName('LI'); while ( lis.length >= 1 ) { ul.removeChild(lis[0]); } this.selection = []; //set the selector list li elements to what they are supposed to be if( originalSelection.length > 0 ) { var temp = ul.getAttribute('hnfieldid'); var dsinput = document.getElementById( "ds_" + temp ); var soidinput = document.getElementById( "soid_" + temp ); var items = []; if( dsinput ) { items = dsinput.value.replace("'", "'").split( "|" ); } var soids = []; if( soidinput ) { soids = soidinput.value.split( "," ); } for ( var i = 0; i < originalSelection.length; i++ ) { this.select( originalSelection[ i ], items[ i ], soids[ i ] ); } } }, search: function ( search ) { this.searchString = search == "Full Keyword Search" ? "" : search; if( this.advancedPopup ) this.toggleAdvanced( this.advancedPopup ); customSelectFetch( this.urlPrefix, this.uniID, this.folderName, this.searchString ); }, next: function ( currentPage, pageSize, size ) { var nextOffset = currentPage * pageSize; if( nextOffset < size ) customSelectFetch( this.urlPrefix, this.uniID, this.folderName, this.searchString, nextOffset ); }, previous: function ( currentPage, pageSize ) { if( currentPage > 1 ) { var nextOffset = ( currentPage - 2 ) * pageSize; customSelectFetch( this.urlPrefix, this.uniID, this.folderName, this.searchString, nextOffset ); } }, goto: function( newPage, pageSize, size ) { var nextOffset = ( newPage - 1 ) * pageSize; if( nextOffset >= 0 && nextOffset < size ) customSelectFetch( this.urlPrefix, this.uniID, this.folderName, this.searchString, nextOffset ); }, select: function ( oid, item, soid ) { //if(soid) { // alert("soid=" + soid); //} //alert( "select: " + oid + "/" + item ); var name; if ( typeof( item ) == 'string' ) { name = item; // called from new object tab } else { var headers = item.parentNode.getElementsByTagName('TR')[0].getElementsByTagName('TD'); for( var i = 0; i < headers.length; i++ ) { if ( headers[i].getAttribute("wosField") == this.idField ) { name = item.getElementsByTagName('TD')[i].innerHTML; // called from search tab } } } var ul = document.getElementById('selectorList' + this.uniID); var lis = ul.getElementsByTagName('LI'); if( this.isMultiple && this.containsSelection( oid, name ) ) return; var elem = !this.isMultiple && lis.length == 1 ? lis[ 0 ] : document.createElement('li'); elem.innerHTML = name; ul.insertBefore( elem, null ); elem.setAttribute('oid', oid); elem.setAttribute('soid', soid); //elem.onclick = function () { customSelector.select(this); }; /* not sure why this fails after parent is set to display: none */ /*if( browser.isIE ) elem.setAttribute('onclick', function () { customSelector.select(this); } ); else elem.setAttribute('onclick', "customSelector.select(this)" );*/ elem.setAttribute('onclick','customSelector.select(this);'); // for FF elem.onclick = function() { customSelector.select(this); }; // for IE if ( this.isMultiple ) this.addSelection( oid, name ); //alert( this.selection ); if ( !this.isMultiple ) { this.action_Submit(); CustomPopup.close("selectorPopup" + this.uniID ); } }, open: function ( urlPrefix, toid, folderName, fieldName, multi, idField, topic ) { var fieldInfo = this.acquireField( topic ); if( fieldInfo.refLabel && !fieldInfo.ref ) { alert( "You must enter " + fieldInfo.refLabel + " first" ); return; } this.urlPrefix = urlPrefix; this.toid = toid; this.uniID = toid + fieldName; this.folderName = folderName; this.isMultiple = multi; this.idField = idField; this.topic = topic; this.clear( this.uniID ); //this.initSelection(); //this.selection = []; CustomPopup.open( "selectorPopup" + toid + fieldName, "60", true, true, fieldName, null, this ); }, keyPressed: function( field, event ) { event = event || window.event; var keyCode = document.all ? event.keyCode : event.which; if( keyCode == 13 ) { if( field.id == this.uniID + "_search" ) { this.search( field.value ); event.returnValue = false; event.cancelBubble = true; return false; } else { window.setTimeout( "WOSSelector.search( getTag( WOSSelector.uniID + '_search' ).value );", 200 ); field.blur(); } } return true; }, acquireField: function( topic ) { var field = this.fields[ topic ]; if( field == null ) this.fields[ topic ] = field = { "name" : topic }; return field; }, getFieldProperty: function( topic, property ) { var field = this.fields[ topic ]; return field == null ? null : field[ property ]; }, advancedChanged: function( fieldName, fieldValue ) { this.advancedCriteria[ fieldName ] = fieldValue; }, calcAdvancedCriteria: function() { var url = ""; for( var key in this.advancedCriteria ) { var value = this.advancedCriteria[ key ]; if( value ) url += "&_" + key + "=" + escape( value ); } return url; }, toggleAdvanced: function( div, ifOpen ) { if( div.className == "ref-selector-advanced-hide" && !ifOpen ) { div.className = "ref-selector-advanced-show"; this.advancedPopup = div; } else { div.className = "ref-selector-advanced-hide"; this.advancedPopup = null; } }, clear: function( uniId ) { getTag( uniId + "_search" ).value = "Full Keyword Search"; var div = getTag( uniId + "_advanced" ); this.searchString = null; if( div ) { this.toggleAdvanced( div, true ); this.clearAdvanced( div ); } }, clearAdvanced: function( div ) { this.advancedCriteria = {}; var inputs = div.getElementsByTagName( "input" ); for( var i = 0; i < inputs.length; i++ ) inputs[ i ].value = inputs[ i ].getAttribute( "noValue" ); inputs = div.getElementsByTagName( "select" ); for( var i = 0; i < inputs.length; i++ ) inputs[ i ].value = "--"; }, tabChange: function( li, tabId ) { tabChange( li ); var tab = tabId ? this.tabs[ tabId ] : null; if( tab && tab.onOpen ) tab.onOpen(); }, addSelection: function( oid, item ) { //this.selection[ this.selection.length ] = oid; var newSelection = new Object(); newSelection.oid = oid; newSelection.item = item; this.selection[ this.selection.length ] = newSelection; }, removeSelection: function( oid, pos ) { //alert( "pos: "+pos + "; oid: " + oid + "; this.selection[ pos ]=" + this.selection[ pos ] ); var selectedItem = this.selection[ pos ]; if( selectedItem != null && selectedItem.oid == oid ) this.selection[ pos ] = null; else for( var i = 0; i < this.selection.length; i++ ) if( this.selection[ i ] != null && this.selection[ i ].oid == oid ) this.selection[ i ] = null; this.selection = this.getSelections(); }, getSelections: function() { var selections = []; for( var i = 0; i < this.selection.length; i++ ) if( this.selection[ i ] != null ) selections[ selections.length ] = this.selection[ i ]; return selections; }, getSelectionOids: function() { var oids = []; for( var i = 0; i < this.getSelections().length; i++ ) oids[ i ] = this.selection[ i ].oid; return oids; }, moveSelection: function( oid, dir ) { //dir=0 means up, dir=1 means down var stop = false; var i = 0; var adjustment; while( stop == false && i< this.selection.length ) //for( var i = 0; i < this.selection.length; i++ ) { if( this.selection[ i ] != null && this.selection[ i ].oid == oid ) { if( dir == 0 ) adjustment = -1; else adjustment = 1; replacementIdx = i + adjustment; while( replacementIdx >= 0 && replacementIdx < this.selection.length && this.selection[ replacementIdx ] == null ) { replacementIdx = i + adjustment; } if( replacementIdx >= 0 && replacementIdx < this.selection.length ) { var tempSelection = this.selection[ replacementIdx ]; this.selection[ replacementIdx ] = this.selection[ i ]; this.selection[ i ] = tempSelection; //alert( i + ":" + this.selection[ i ].oid + "/" + replacementIdx + ":" + tempSelection.oid ); } stop = true; } i+=1; } }, containsSelection: function( oid, item ) { var result = false; for( var i = 0; i < this.selection.length; i++ ) { if( this.selection[ i ].item == item && this.selection[i].oid == oid ) { //alert( "i=" + i + "; this.selection[i].item=[" + this.selection[ i ].item + "], item=" + item + ", this.selection[i].oid=" + this.selection[i].oid + ", oid=" + oid ); result = true; } } return result; }, removeAll: function( ) { var ul = document.getElementById('selectorList' + this.uniID); if( ul ) { var lis = ul.getElementsByTagName('LI'); while ( lis.length >= 1 ) { ul.removeChild(lis[0]); } } }, updateOrder: function( soidSrc, soidTar ) { //WOSSelector.updateOrder(soid.id, this.uniID); //alert('soidSrc=' + soidSrc + ', soidTar=' + soidTar); var soidSrcItem = getTag(soidSrc); var soidTarItem = getTag(soidTar); if(soidSrcItem && soidTarItem) { soidTarItem.value = soidSrcItem.value; soidTarItem.onchange(); } } }; var customSelector = { select: function( item ) { if ( item.className == 'active' ) { item.className = ''; } else { var lis = item.parentNode.getElementsByTagName('LI'); for ( var i = 0; i < lis.length; i++ ) { lis[i].className = ''; } item.className = 'active'; } }, move: function( id, dir ) { var lis = document.getElementById(id).getElementsByTagName('LI'); for ( var i = 0; i < lis.length; i++ ) { if ( lis[i].className == 'active' ) { var item = lis[i]; var place = i; if ( i == lis.length-1 && dir == 1 ) { return 0; } else if ( i == 0 && dir == 0 ) { return 0; } } } if ( place != undefined ) { var text = item.innerHTML; var oid = item.getAttribute("oid"); var soid = item.getAttribute("soid"); item.parentNode.removeChild(item); lis = document.getElementById(id).getElementsByTagName('LI'); var elem = document.createElement('li'); elem.innerHTML = text; if ( dir == 0 ) { var before = lis[place-1]; document.getElementById(id).insertBefore(elem, before); } else if ( dir == 1 ) { var before = lis[place+1]; if ( place+1 >= lis.length ) { document.getElementById(id).appendChild(elem); } else { document.getElementById(id).insertBefore(elem, before); } } elem.className = 'active'; //elem.onclick = function () { customSelector.select(this); }; //elem.setAttribute('onclick', "customSelector.select(this)" ); if( browser.isIE ) elem.setAttribute('onclick', function () { customSelector.select(this); } ); else elem.setAttribute('onclick', "customSelector.select(this)" ); elem.setAttribute('oid', oid); elem.setAttribute('soid', soid); WOSSelector.moveSelection( oid, dir ); } }, remove: function( id ) { var lis = document.getElementById(id).getElementsByTagName('LI'); for ( var i = 0; i < lis.length; i++ ) { if ( lis[i].className == 'active' ) { var place = i; var item = lis[i]; } } if ( place != undefined ) { { WOSSelector.removeSelection( item.getAttribute( "oid" ) , place ); item.parentNode.removeChild(item); } } } };