浏览代码

Added the ability to reload a selection fro a paginated list.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@1524 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 13 年之前
父节点
当前提交
2ef2fbed8e
共有 1 个文件被更改,包括 65 次插入49 次删除
  1. 65 49
      js/jquery.tablesorter.pager.js

+ 65 - 49
js/jquery.tablesorter.pager.js

@@ -105,7 +105,7 @@ function sprintf(format, etc) {
 				$(':input[name^=storedSelection]', pager).remove();
 			}
 			
-			function updateSelection(table, pager, id, value)
+			function storeSelection(table, pager, id, value)
 			{
 				var valueToStore = value;
 				if (table.config.selectionMode == 'negative')
@@ -133,6 +133,12 @@ function sprintf(format, etc) {
 				updateCounter(table, pager);
 			}
 			
+			function loadSelection(table, pager)
+			{
+				table.config.selectionMode = $(pager).find(':input[name=selectionMode]').val();
+				updateCounter(table, pager);
+			}
+			
 			function updateCounter(table, pager)
 			{
 				var ex = $(':input[name^=storedSelection]', pager).length;
@@ -205,53 +211,7 @@ function sprintf(format, etc) {
 							}
 							
 							fixPosition(table,tableBody);
-							if (c.selectionMode == 'negative')
-							{
-								$(table).find(':checkbox[name^=selectObj]').attr('checked', true);
-							}
-							
-							if (table.config.select_mode == 'multiple')
-							{
-								$(table).find(':checkbox[name^=selectObj]').each(function() {
-									var id = parseInt(this.value, 10);
-									if ($('#'+id, table.config.container).length > 0)
-									{
-										if (c.selectionMode == 'positive')
-										{
-											$(this).attr('checked', true);
-										}
-										else
-										{
-											$(this).attr('checked', false);
-										}
-									}
-								});
-	
-								$(table).find(':checkbox[name^=selectObj]').change(function() {
-									updateSelection(table, table.config.container, this.value, this.checked);
-								});
-							}
-							else if (table.config.select_mode == 'single')
-							{
-								$(table).find('input[name^=selectObject]:radio').each(function() {
-									var id = parseInt(this.value, 10);
-									if ($('#'+id, table.config.container).length > 0)
-									{
-										if (c.selectionMode == 'positive')
-										{
-											$(this).attr('checked', true);
-										}
-										else
-										{
-											$(this).attr('checked', false);
-										}
-									}
-								});
-	
-								$(table).find('input[name^=selectObject]:radio').change(function() {
-									updateSelection(table, table.config.container, this.value, this.checked);
-								});
-							}
+							applySelection(table);
 							
 							$(table).trigger("applyWidgets");
 							
@@ -267,6 +227,58 @@ function sprintf(format, etc) {
 					   });
 			}
 			
+			function applySelection(table)
+			{
+				var c = table.config;
+				if (c.selectionMode == 'negative')
+				{
+					$(table).find(':checkbox[name^=selectObj]').attr('checked', true);
+				}
+				
+				if (table.config.select_mode == 'multiple')
+				{
+					$(table).find(':checkbox[name^=selectObj]').each(function() {
+						var id = parseInt(this.value, 10);
+						if ($('#'+id, table.config.container).length > 0)
+						{
+							if (c.selectionMode == 'positive')
+							{
+								$(this).attr('checked', true);
+							}
+							else
+							{
+								$(this).attr('checked', false);
+							}
+						}
+					});
+
+					$(table).find(':checkbox[name^=selectObj]').change(function() {
+						storeSelection(table, table.config.container, this.value, this.checked);
+					});
+				}
+				else if (table.config.select_mode == 'single')
+				{
+					$(table).find('input[name^=selectObject]:radio').each(function() {
+						var id = parseInt(this.value, 10);
+						if ($('#'+id, table.config.container).length > 0)
+						{
+							if (c.selectionMode == 'positive')
+							{
+								$(this).attr('checked', true);
+							}
+							else
+							{
+								$(this).attr('checked', false);
+							}
+						}
+					});
+
+					$(table).find('input[name^=selectObject]:radio').change(function() {
+						storeSelection(table, table.config.container, this.value, this.checked);
+					});
+				}
+			}
+			
 			function renderPager(table, pager)
 			{
 				var c = table.config;
@@ -400,9 +412,13 @@ function sprintf(format, etc) {
 					$(table).find(':checkbox.checkAll').removeAttr('onclick').click(function() {
 						return checkAll(table, pager, this.checked);
 					});
+
+					$(table).bind('load_selection', function() {
+						loadSelection(table, pager);
+						applySelection(table);
+					});
 				});
 			};
-			
 		}
 	});
 	// extend plugin scope