r13670 - in Products.AddRemoveWidget/trunk: Products/AddRemoveWidget Products/AddRemoveWidget/skins/AddRemoveWidget docs

"Vitaliy Podoba" <[email protected]> Mon, 06 Jun 2011 07:43:47 +0000
Newsgroups gmane.comp.web.zope.plone.archetypes.cvs
Message-ID <[email protected]>
Author: piv
Date: Mon Jun  6 07:43:46 2011
New Revision: 13670

Modified:
   Products.AddRemoveWidget/trunk/Products/AddRemoveWidget/AddRemoveWidget.py
   Products.AddRemoveWidget/trunk/Products/AddRemoveWidget/skins/AddRemoveWidget/widget_addremove.js
   Products.AddRemoveWidget/trunk/Products/AddRemoveWidget/skins/AddRemoveWidget/widget_addremove.pt
   Products.AddRemoveWidget/trunk/Products/AddRemoveWidget/skins/AddRemoveWidget/widget_addremove_vars.js.dtml
   Products.AddRemoveWidget/trunk/Products/AddRemoveWidget/version.txt
   Products.AddRemoveWidget/trunk/docs/HISTORY.txt
Log:
add items ordering support as an optional feature and prepare to tag 1.4.5 version

Modified: Products.AddRemoveWidget/trunk/Products/AddRemoveWidget/AddRemoveWidget.py
==============================================================================
--- Products.AddRemoveWidget/trunk/Products/AddRemoveWidget/AddRemoveWidget.py	(original)
+++ Products.AddRemoveWidget/trunk/Products/AddRemoveWidget/AddRemoveWidget.py	Mon Jun  6 07:43:46 2011
@@ -53,6 +53,9 @@
          'size': '7',
          'width': '10em',
          'width_absolute': 0,
+
+         # Should items be ordered?
+         'ordered': False,
          },
         )
 

Modified: Products.AddRemoveWidget/trunk/Products/AddRemoveWidget/skins/AddRemoveWidget/widget_addremove.js
==============================================================================
--- Products.AddRemoveWidget/trunk/Products/AddRemoveWidget/skins/AddRemoveWidget/widget_addremove.js	(original)
+++ Products.AddRemoveWidget/trunk/Products/AddRemoveWidget/skins/AddRemoveWidget/widget_addremove.js	Mon Jun  6 07:43:46 2011
@@ -4,12 +4,12 @@
  
 
 // add input from an inputbox
-function addremove_addNewItem(field) {
+function addremove_addNewItem(field, sort) {
 
   	var inputBox   = document.getElementById(field + "_new");
   	var targetList = document.getElementById(field + "_selected");
   
- 	if(_addremove_addToList(targetList, inputBox.value, inputBox.value)) {
+ 	if(_addremove_addToList(targetList, inputBox.value, inputBox.value, sort)) {
   		_addremove_updateSubmitField(field);
 		inputBox.value = "";
 		return true;
@@ -19,14 +19,14 @@
 }
 
 // add the selected item from the "from" box to the "to" box
-function addremove_addItem(field) {
+function addremove_addItem(field, sort) {
 
 	var sourceList = document.getElementById(field + "_unselected");
 	var targetList = document.getElementById(field + "_selected");
 	
 	var idx = sourceList.selectedIndex;
 
-	if(_addremove_moveItem(sourceList, idx, targetList)) {
+	if(_addremove_moveItem(sourceList, idx, targetList, sort)) {
 		_addremove_updateSubmitField(field);
 		return true;
 	} else {
@@ -43,7 +43,7 @@
 	
 	var idx = sourceList.selectedIndex;
 
-	if(_addremove_moveItem(sourceList, idx, targetList)) {
+	if(_addremove_moveItem(sourceList, idx, targetList, 'true')) {
 		_addremove_updateSubmitField(field);
 		return true;
 	} else {
@@ -52,19 +52,65 @@
 
 }
 
+// move selected in "to" box item on one position up
+function addremove_upItem(field) {
+  var sourceList = document.getElementById(field + "_selected");
+  var idx = sourceList.selectedIndex;
+
+  if (idx == -1) {
+    alert(string_addremove_moveItem);
+    return false;
+  } else if (sourceList.options[0].selected) {
+    alert(string_addremove_upItem);
+    return false;
+  } else {
+    for (var i = 0; i < sourceList.length; i++) {
+      if (sourceList.options[i].selected) {
+        _swapFields(sourceList.options[i-1], sourceList.options[i]);
+      }
+    }
+  }
+  
+  _addremove_updateSubmitField(field);
+  return true;
+}
+
+// move selected in "to" box item on one position down
+function addremove_downItem(field) {
+  var sourceList = document.getElementById(field + "_selected");
+  var idx = sourceList.selectedIndex;
+
+  if (idx == -1) {
+    alert(string_addremove_moveItem);
+    return false;
+  } else if (sourceList.options[sourceList.length-1].selected) {
+    alert(string_addremove_downItem);
+    return false;
+  } else {
+    for (var i = sourceList.length-1; i >= 0; i--) {
+      if (sourceList.options[i].selected) {
+        _swapFields(sourceList.options[i+1], sourceList.options[i]);
+      }
+    }
+  }
+  
+  _addremove_updateSubmitField(field);
+  return true;
+}
+
 /*
  * Helper functions
  */
  
 // Move an item from one list to another
-function _addremove_moveItem(sourceList, idx, targetList) {
+function _addremove_moveItem(sourceList, idx, targetList, sort) {
 
   var success = false;
 
   if(idx >= 0) {
 	success = _addremove_addToList(targetList, 
 									sourceList[idx].text, 
-  								    sourceList[idx].value)
+  								    sourceList[idx].value, sort);
   	if(success)
 	  sourceList[idx] = null;
   } else {
@@ -75,7 +121,7 @@
 }
 
 // add a new item to the given list
-function _addremove_addToList(targetList, newText, newValue) {
+function _addremove_addToList(targetList, newText, newValue, sort) {
 
   	// ensure we don't have it already
   	for(var i = 0; i < targetList.length; ++i) {
@@ -89,7 +135,9 @@
   	targetList[newIdx]       = new Option(_trimString(newText));
   	targetList[newIdx].value = _trimString(newValue);
 	
-	_addremove_sortListBox(targetList);
+	if (sort) {
+	  _addremove_sortListBox(targetList);
+  }
 
   	return true;
 }
@@ -160,6 +208,24 @@
 	}
 }
 
+// Swapt select element options
+function _swapFields(a, b) {
+  // swap text
+  var temp = a.text;
+  a.text = b.text;
+  b.text = temp;
+  
+  // swap value
+  temp = a.value;
+  a.value = b.value;
+  b.value = temp;
+  
+  // swap selection
+  temp = a.selected;
+  a.selected = b.selected;
+  b.selected = temp;
+}
+
 function _printTree(node, str) {
     str += node.nodeName + ' -> ' + node.nodeValue + '\n'
     if (node.hasChildNodes()) {

Modified: Products.AddRemoveWidget/trunk/Products/AddRemoveWidget/skins/AddRemoveWidget/widget_addremove.pt
==============================================================================
--- Products.AddRemoveWidget/trunk/Products/AddRemoveWidget/skins/AddRemoveWidget/widget_addremove.pt	(original)
+++ Products.AddRemoveWidget/trunk/Products/AddRemoveWidget/skins/AddRemoveWidget/widget_addremove.pt	Mon Jun  6 07:43:46 2011
@@ -30,6 +30,7 @@
             width           - The width of the add boxes (default 10em)
             size            - The height of the add boxes (default 7)
             width_absolute  - Whether the width is absolute or min-width (default false)
+            ordered         - Whether items should be ordered
 
          and then include the macro add_remove_box. Be sure to include
          widget_addremove.js as well.
@@ -44,6 +45,8 @@
                             width          widget/width;
                             width_absolute widget/width_absolute;
                             size           widget/size;
+                            ordered        widget/ordered|nothing;
+                            js_auto_sort   python:ordered and 'false' or 'true';
 
                             vocab_source   python:getattr(widget,'vocab_source','portal_catalog');
                             isKWfield      python:widget.is_keyword_field(field,vocab_source) and not vocabulary;
@@ -88,7 +91,7 @@
                                         style       string:${widthSpec}:${width};
                                         tabindex    tabindex/next|nothing;
                                         size        size;
-                                        onDblClick  string:addremove_addItem('${fieldName}')">
+                                        onDblClick  string:addremove_addItem('${fieldName}', ${js_auto_sort})">
                   <tal:block repeat="item vocabulary/keys">
                     <option
                         value="#"
@@ -99,13 +102,13 @@
                 </select>
 
             </td>
-            <!-- Buttons -->
+            <!-- Add/Remove Buttons -->
             <td valign="middle" align="center">
                 <input type="button" value="Add &gt;"
                        style="width: 100%;" onClick=""
                        i18n:attributes="value button_add_item;"
                        tal:attributes="tabindex tabindex/next|nothing;
-                                    onClick  string:addremove_addItem('${fieldName}')"/><br/>
+                                    onClick  string:addremove_addItem('${fieldName}', ${js_auto_sort})"/><br/>
                 <input type="button" value="&lt; Remove"
                        style="width: 100%; margin: 0"
                        i18n:attributes="value button_remove_item;"
@@ -137,6 +140,21 @@
                 </select>
 
             </td>
+            <!-- Up/Down Buttons -->
+            <td valign="middle" align="center">
+                <tal:if condition="ordered"> 
+                <input type="button" value="Up"
+                       style="width: 100%;" onClick=""
+                       i18n:attributes="value button_up_item;"
+                       tal:attributes="tabindex tabindex/next|nothing;
+                                    onClick  string:addremove_upItem('${fieldName}')"/><br/>
+                <input type="button" value="Down"
+                       style="width: 100%;"
+                       i18n:attributes="value button_down_item;"
+                       tal:attributes="tabindex tabindex/next|nothing;
+                                       onClick  string:addremove_downItem('${fieldName}')"/>
+                </tal:if>
+            </td>
             </tr>
 
             <!-- Add button -->
@@ -148,14 +166,14 @@
                                tal:attributes="id addBox"/>
                 </div>
             </td>
-            <td align="center" valign="middle">
+            <td align="center" valign="middle" colspan="2">
                 <div style="margin-top: 1em">
                     <input type="button" value="&gt; Add New Value"
                            style="width: 100%; margin: 0"
                            onClick=""
                            i18n:attributes="value button_add_new_item;"
                            tal:attributes="tabindex tabindex/next|nothing;
-                                           onClick  string:addremove_addNewItem('${fieldName}')"/>
+                                           onClick  string:addremove_addNewItem('${fieldName}', ${js_auto_sort})"/>
                 </div>
             </td>
             </tr>

Modified: Products.AddRemoveWidget/trunk/Products/AddRemoveWidget/skins/AddRemoveWidget/widget_addremove_vars.js.dtml
==============================================================================
--- Products.AddRemoveWidget/trunk/Products/AddRemoveWidget/skins/AddRemoveWidget/widget_addremove_vars.js.dtml	(original)
+++ Products.AddRemoveWidget/trunk/Products/AddRemoveWidget/skins/AddRemoveWidget/widget_addremove_vars.js.dtml	Mon Jun  6 07:43:46 2011
@@ -2,3 +2,5 @@
 * Set Javascript variables for i18n usage
 */
 var string_addremove_moveItem = '<dtml-var "translate(msgid='alert_please_select_an_item', domain='AddRemoveWidget', default='Please select an item', escape_for_js=True)">';
+var string_addremove_upItem = '<dtml-var "translate(msgid='alert_cant_up', domain='AddRemoveWidget', default='Cannot move further up', escape_for_js=True)">';
+var string_addremove_downItem = '<dtml-var "translate(msgid='alert_cant_down', domain='AddRemoveWidget', default='Cannot move further down', escape_for_js=True)">';

Modified: Products.AddRemoveWidget/trunk/Products/AddRemoveWidget/version.txt
==============================================================================
--- Products.AddRemoveWidget/trunk/Products/AddRemoveWidget/version.txt	(original)
+++ Products.AddRemoveWidget/trunk/Products/AddRemoveWidget/version.txt	Mon Jun  6 07:43:46 2011
@@ -1 +1 @@
-1.4.5dev
+1.4.5

Modified: Products.AddRemoveWidget/trunk/docs/HISTORY.txt
==============================================================================
--- Products.AddRemoveWidget/trunk/docs/HISTORY.txt	(original)
+++ Products.AddRemoveWidget/trunk/docs/HISTORY.txt	Mon Jun  6 07:43:46 2011
@@ -1,11 +1,15 @@
 Changelog
 =========
 
-1.4.5 (unreleased)
+1.4.5 (2011-06-06)
 ------------------
 
+* Added ordering support as an optional feature.
+  [piv]
+
 * Removed 'unicodeTestIn' call. This fixes #14.
   [jaroel/maerteijn]
+
 * Add empty element to submitContainer when no items are selected. Fixes #13.
   [jaroel/maerteijn]
 

------------------------------------------------------------------------------
Simplify data backup and recovery for your virtual environment with vRanger.
Installation's a snap, and flexible recovery options mean your data is safe,
secure and there when you need it. Discover what all the cheering's about.
Get your free trial download today. 
http://p.sf.net/sfu/quest-dev2dev2