← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2500: add paser for table sorter, sort by dhis period

 

------------------------------------------------------------
revno: 2500
committer: Tri <Tri@Tri-Laptop>
branch nick: dhis2
timestamp: Mon 2011-01-10 13:17:21 +0700
message:
  add paser for table sorter, sort by dhis period
modified:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/jQuery/jquery.ext.js
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm
  dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/searchResult.vm


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js	2011-01-06 09:03:29 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/commons.js	2011-01-10 06:17:21 +0000
@@ -914,7 +914,7 @@
 {
 	if(sortList==undefined) sortList = [[0,0]];
 	
-	jQuery("#" + tableId ).tablesorter(); 
+	jQuery("#" + tableId ).tablesorter({dateFormat:dateFormat}); 
 	
 	if($("#" + tableId ).find("tbody").children().size() > 0 )
 	{

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/jQuery/jquery.ext.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/jQuery/jquery.ext.js	2010-09-08 10:40:26 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/jQuery/jquery.ext.js	2011-01-10 06:17:21 +0000
@@ -2,4 +2,25 @@
 	postJSON: function( url, data, callback ) {
 		return jQuery.post(url, data, callback, "json");
 	}
+});
+
+$.tablesorter.addParser({
+	id: "period",
+	is: function (s) {
+		return /\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}/.test(s);
+	}, format: function (s, table, cell) {
+		var v = $(cell).attr('value');
+		var c = table.config;
+		v = v.replace(/\-/g, "/");
+		if (c.dateFormat == "us") {
+			// reformat the string in ISO format
+			v = v.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/, "$3/$1/$2");
+		} else if (c.dateFormat == "uk") {
+			// reformat the string in ISO format
+			v = v.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/, "$3/$2/$1");
+		} else if (c.dateFormat == "dd/mm/yy" || c.dateFormat == "dd-mm-yy") {
+			v = v.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{2})/, "$1/$2/$3");
+		}
+		return $.tablesorter.formatFloat(new Date(v).getTime());
+	}, type: "numeric"
 });
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm	2010-12-26 15:38:45 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm	2011-01-10 06:17:21 +0000
@@ -20,8 +20,7 @@
     <script type="text/javascript">
 		var dateFormat = '$encoder.jsEscape($i18n.getString( 'format.date.label.jquery' ) , "'")';
 	</script>    
-    <script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/jquery.min.js"></script>
-    <script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/jquery.ext.js"></script>
+    <script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/jquery.min.js"></script>    
     <script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/ui/jquery-ui.min.js"></script>
 	<script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/jquery.metadata.js"></script>	
 	<script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/jquery.tablesorter.min.js"></script>		
@@ -31,6 +30,7 @@
 	<script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/jquery.validate.js"></script>
 	<script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/jquery.validate.ext.js"></script>
 	<script type="text/javascript" src="../dhis-web-commons/i18nJavaScriptSupport.action"></script>
+	<script type="text/javascript" src="../dhis-web-commons/javascripts/jQuery/jquery.ext.js"></script>
     <script type="text/javascript" src="../dhis-web-commons/javascripts/commons.js"></script>
     <script type="text/javascript" src="../dhis-web-commons/javascripts/commons.ajax.js"></script>
     <script type="text/javascript" src="../dhis-web-commons/javascripts/lists.js"></script>

=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/searchResult.vm'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/searchResult.vm	2011-01-07 03:46:17 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/searchResult.vm	2011-01-10 06:17:21 +0000
@@ -16,7 +16,7 @@
 	<tr>
 		<th>$i18n.getString( "data_element" )</th>
 		<th>$i18n.getString( "organisation_unit" )</th>
-		<th>$i18n.getString( "period" )</th>
+		<th class="{sorter: 'period'}">$i18n.getString( "period" )</th>
 		<th style="text-align:center">$i18n.getString( "min" )</th>
 		<th style="width: 100px; text-align:center" class="{sorter: false}">$i18n.getString( "value" )</th>
 		<th style="text-align:center">$i18n.getString( "max" )</th>
@@ -32,7 +32,7 @@
 		
 		<td>$value.sourceName</td>
 		
-		<td>$format.formatPeriod( $value.period )</td>
+		<td value="$format.formatDate($value.period.startDate)">$format.formatPeriod( $value.period )</td>
 		
 		<td style="text-align:center">$value.min</td>