You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ha...@apache.org on 2008/06/15 01:59:09 UTC

svn commit: r667900 - in /myfaces/tomahawk/trunk/core/src/main/resources/org/apache/myfaces/custom/picklist: ./ resource/ resource/picklist.js

Author: hazems
Date: Sat Jun 14 16:59:09 2008
New Revision: 667900

URL: http://svn.apache.org/viewvc?rev=667900&view=rev
Log:
Promoting the selectManyPicklist component.

Added:
    myfaces/tomahawk/trunk/core/src/main/resources/org/apache/myfaces/custom/picklist/
    myfaces/tomahawk/trunk/core/src/main/resources/org/apache/myfaces/custom/picklist/resource/
    myfaces/tomahawk/trunk/core/src/main/resources/org/apache/myfaces/custom/picklist/resource/picklist.js

Added: myfaces/tomahawk/trunk/core/src/main/resources/org/apache/myfaces/custom/picklist/resource/picklist.js
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/resources/org/apache/myfaces/custom/picklist/resource/picklist.js?rev=667900&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/resources/org/apache/myfaces/custom/picklist/resource/picklist.js (added)
+++ myfaces/tomahawk/trunk/core/src/main/resources/org/apache/myfaces/custom/picklist/resource/picklist.js Sat Jun 14 16:59:09 2008
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+ 
+ /**
+ * @author Bruno Aranda (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+ 
+// moves an item to the selected list
+function myfaces_picklist_addToSelected(availableListId, selectedListId, hiddenId)
+{
+	var availableList = document.getElementById(availableListId);
+    var selectedList = document.getElementById(selectedListId);
+
+	myfaces_picklist_move(availableList, selectedList, hiddenId);
+	myfaces_picklist_updateHidden(selectedList, hiddenId);
+}
+
+// removes an item from the selected list
+function myfaces_picklist_removeFromSelected(availableListId, selectedListId, hiddenId)
+{
+    var availableList = document.getElementById(availableListId);
+    var selectedList = document.getElementById(selectedListId);
+
+	myfaces_picklist_move(selectedList, availableList, hiddenId);
+	myfaces_picklist_updateHidden(selectedList, hiddenId);
+}
+
+function myfaces_picklist_move(fromList, toList, hiddenId) {
+	// Return, if no items selected
+	var selectedIndex = fromList.selectedIndex;
+	if(selectedIndex < 0) { return; }
+
+	// Decremental loop, so the index is not affected in the moves
+	for(var i = fromList.length - 1; i >= 0; i--) {
+		if(fromList.options.item(i).selected) {
+			toList.appendChild(fromList.options.item(i));
+		}
+	}
+
+}
+
+// Selection - invoked on submit
+function myfaces_picklist_updateHidden(selectedList, hiddenId) {
+	var hiddenField = document.getElementById(hiddenId);
+	
+	var arrValues = new Array(selectedList.options.length);
+	for (var i = 0; i<selectedList.options.length; i++) {
+	    arrValues[i] = selectedList.options[i].value;
+	}
+	
+	hiddenField.value = arrValues.join();
+}
\ No newline at end of file