forked from yui/yui3-gallery
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gallery-2011.08.24-22-36 eamonb gallery-user-patch-2529920-2529921
- Loading branch information
YUI Builder
committed
Aug 24, 2011
1 parent
81a364b
commit ec6cb9e
Showing
4 changed files
with
188 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
builddir=../../../../builder/componentbuild | ||
|
||
component=gallery-user-patch-2529920-2529921 | ||
component.jsfiles=datatable-patch-2529920-2529921.js | ||
component.skinnable=false | ||
component.requires=datatable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project name="gallery-user-patch-2529920-2529921" default="local"> | ||
<description>gallery-user-patch-2529920-2529921</description> | ||
<property file="build.properties" /> | ||
<import file="${builddir}/3.x/bootstrap.xml" description="Default Build Properties and Targets" /> | ||
|
||
<!-- This target added to force NetBeans to recognise the module as a valid target --> | ||
<target name="module" depends="all"></target> | ||
</project> |
64 changes: 64 additions & 0 deletions
64
src/gallery-user-patch-2529920-2529921/js/datatable-patch-2529920-2529921.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* This patch addresses YUI tickets #2529920, #2529921 | ||
* | ||
* #2529920 - Documentation refers to the cell formatter function having access to the TD element, but the TD reference is not passed. | ||
* http://yuilibrary.com/projects/yui3/ticket/2529920 | ||
* | ||
* #2529921 - {value} template is shown when the record data is null or undefined | ||
* http://yuilibrary.com/projects/yui3/ticket/2529921 | ||
* | ||
* The {value} token remains because Y.substitute does not delete invalid tokens, in case that they | ||
* are later used for recursive substitutions. One possible fix could be to have substitute delete tokens | ||
* if the recursive option is not set. | ||
* | ||
* @module gallery-user-patch-2529920-2529921 | ||
* @requires datatable | ||
*/ | ||
|
||
// Default: '<td headers="{headers}"><div class="'+CLASS_LINER+'">{value}</div></td>' | ||
// Changed in this fix because the value is not supplied at the Ysubstitute stage, it is appended to the liner. | ||
var YgetClassName = Y.ClassNameManager.getClassName, | ||
DATATABLE = "datatable", | ||
CLASS_LINER = YgetClassName(DATATABLE, "liner"), | ||
TD_TEMPLATE = '<td headers="{headers}" class="{classnames}"><div class="'+CLASS_LINER+'"></div></td>'; | ||
|
||
Y.DataTable.Base.prototype._createTbodyTdNode = function(o) { | ||
var column = o.column, | ||
formatvalue = null; | ||
|
||
//TODO: attributes? or methods? | ||
o.headers = column.headers; | ||
o.classnames = column.get("classnames"); | ||
o.td = Y.Node.create(Y.substitute(TD_TEMPLATE, o)); | ||
o.liner = o.td.one('div'); | ||
|
||
formatvalue = this.formatDataCell(o); | ||
|
||
// Formatters should return a string value to be appended, lack of a string here indicates that the formatter has utilised | ||
// the o.td reference to populate the cell. | ||
if (Y.Lang.isString(formatvalue)) { | ||
o.value = formatvalue; | ||
o.liner.append(formatvalue); | ||
} | ||
|
||
return o.td; | ||
}; | ||
|
||
// Use a custom function in the substitution to omit null results | ||
// Realistically, Y.sub should have an option to remove and not preserve tokens. | ||
Y.DataTable.Base.prototype.formatDataCell = function(o) { | ||
var record = o.record, | ||
column = o.column, | ||
formatter = column.get("formatter"), | ||
fnSubstituteNulls = function(key, v, meta) { | ||
return Y.Lang.isNull(v) || Y.Lang.isUndefined(v) ? "" : v; | ||
}; | ||
|
||
o.data = record.get("data"); | ||
o.value = record.getValue(column.get("field")); | ||
return Y.Lang.isString(formatter) ? | ||
Y.substitute(formatter, o, fnSubstituteNulls) : // Custom template | ||
Y.Lang.isFunction(formatter) ? | ||
formatter.call(this, o) : // Custom function | ||
Y.substitute(this.get("tdValueTemplate"), o, fnSubstituteNulls); // Default template | ||
}; |
109 changes: 109 additions & 0 deletions
109
src/gallery-user-patch-2529920-2529921/tests/ticket-2529920-2529921.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>#2529920, #2529921 defect test suite</title> | ||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | ||
<script src="http://yui.yahooapis.com/3.3.0/build/yui/yui-min.js" | ||
charset="utf-8"></script> | ||
<style type="text/css" media="screen"> | ||
body { font: 14px Gotham, "Helvetica Neue", sans-serif; } | ||
</style> | ||
</head> | ||
<body class="yui3-skin-sam"> | ||
<h2>#2529920, #2529921 defect test suite</h2> | ||
<p>1. The DataTable cell formatter is not given a reference to the TD node, but the documentation states so.</p> | ||
<p>2. The DataTable will produce template tokens if the record does not contain any value for that token.</p> | ||
<p> | ||
<input type="button" value="Run Tests (Patched)" id="btnRun" onClick="testFn('gallery-user-patch-2529920-2529921')();"> | ||
<input type="button" value="Run Tests (Unpatched)" id="btnRun" onClick="testFn(null)();"> | ||
</p> | ||
<div id="testsubject"></div> | ||
<script type="text/javascript"> | ||
var testFn = function(patchname) { | ||
return function() { | ||
YUI({ | ||
filter: (window.location.search.match(/[?&]filter=([^&]+)/) || [])[1] || 'min', | ||
allowRollup: false, | ||
modules : { | ||
'gallery-user-patch-2529920-2529921' : { | ||
'fullpath' : '../../../build/gallery-user-patch-2529920-2529921/gallery-user-patch-2529920-2529921.js', | ||
'requires' : ['datatable'] | ||
} | ||
} | ||
}).use("console", "test", "dump", "datatable", patchname, function(Y) { | ||
var myConsole = new Y.Console().render(), | ||
testBasic = new Y.Test.Case({ | ||
name: "Patch Ticket 2529920-2529921 Test", | ||
|
||
setUp: function() { | ||
|
||
this.mockresponse = { | ||
response: { | ||
results: [ | ||
{ "id" : "1", "name" : "Joe" }, | ||
{ "id" : "2", "name" : null }, | ||
{ "id" : "3", "name" : "Andrew" } | ||
] | ||
} | ||
}; | ||
|
||
this.testDataTable = new Y.DataTable.Base({ | ||
columnset : [ | ||
{ key:"id", sortable: true }, | ||
{ key:"name", sortable: true } | ||
], | ||
summary : "User patched DataTable Instance", | ||
recordset : this.mockresponse.response.results | ||
}); | ||
}, | ||
|
||
tearDown: function() { | ||
this.testDataTable.destroy(); | ||
|
||
delete this.testDataTable; | ||
}, | ||
|
||
"test formatter receives a td node reference" : function() { | ||
|
||
var testFormatter = function(o) { | ||
Y.Assert.isNotUndefined(o.td, "test o.td is a valid object"); | ||
|
||
return o.value; | ||
}; | ||
|
||
var columnSet = [ | ||
{ key:"id", sortable: true, formatter: testFormatter }, | ||
{ key:"name", sortable: true } | ||
]; | ||
|
||
this.testDataTable.set('caption', 'test formatter receives a td node reference'); | ||
this.testDataTable.set('columnset', columnSet); | ||
this.testDataTable.render('#testsubject'); | ||
}, | ||
|
||
"test null value in recordset does not produce a template token" : function() { | ||
this.testDataTable.set('caption', 'test null value in recordset does not produce a template token'); | ||
this.testDataTable.render('#testsubject'); | ||
|
||
var tbodyNode = Y.one('.yui3-datatable-data'), | ||
trNodes = tbodyNode.all('tr'), | ||
nameNull = trNodes.item(1).all('.yui3-datatable-liner').item(1), | ||
templateMatch = nameNull.get('innerHTML').match( /\{value\}/ ); | ||
|
||
Y.Assert.areNotEqual(templateMatch, '{value}'); | ||
} | ||
|
||
}), | ||
suite = new Y.Test.Suite({name:"Patch Ticket 2529920-2529921 Test Suite"}); | ||
|
||
suite.add(testBasic); | ||
|
||
Y.Test.Runner.setName("Test Runner"); | ||
Y.Test.Runner.add(suite); | ||
Y.Test.Runner.run(); | ||
}); | ||
}; | ||
}; | ||
</script> | ||
</body> | ||
</html> |