Web Interface For Lite Argus Control modules
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.5 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*!
  2. * Ext JS Library 3.3.1
  3. * Copyright(c) 2006-2010 Sencha Inc.
  4. * licensing@sencha.com
  5. * http://www.sencha.com/license
  6. */
  7. Ext.test.session.addTest( 'Ext', new Y.Test.Case({
  8. name: 'XTemplate',
  9. planned: 3,
  10. // 3
  11. test_apply: function() {
  12. var data = {
  13. hello: 'Hello',
  14. world: 'World',
  15. items1: [
  16. 'test1',
  17. 'test2',
  18. 'test3'
  19. ],
  20. items2: [
  21. { name: 'test1' },
  22. { name: 'test2' },
  23. { name: 'test3' }
  24. ],
  25. kids: [{
  26. name: 'Sara Grace',
  27. gender: 'f',
  28. age:3
  29. },{
  30. name: 'Zachary',
  31. gender: 'm',
  32. age:2
  33. },{
  34. name: 'John James',
  35. gender: 'm',
  36. age:.5
  37. }]
  38. };
  39. var tpl1 = new Ext.XTemplate( '{hello} {world}. <tpl for="items1">{.}{[ xindex === xcount ? "" : ":" ]}</tpl>', { compiled: true });
  40. Y.Assert.areEqual( 'Hello World. test1:test2:test3', tpl1.apply( data ), 'Test apply with an object with an array' );
  41. var tpl2 = new Ext.XTemplate( '<tpl for="items2">{name}{[ xindex === xcount ? "" : ":" ]}</tpl>', { compiled: true });
  42. Y.Assert.areEqual( 'test1:test2:test3', tpl2.apply( data ), 'Test apply with an object with an array of hashes' );
  43. var tpl3 = new Ext.XTemplate(
  44. '<ul><tpl for="kids">',
  45. '<tpl if="this.isGirl(gender)">',
  46. '<li>Girl: {name} - {age}</li>',
  47. '</tpl>',
  48. '<tpl if="!this.isGirl(gender)">',
  49. '<tpl if="age &lt; 1">',
  50. '<li>Baby Boy: {name} - {age*12} months</li>',
  51. '</tpl>',
  52. '<tpl if="age &gt;= 1">',
  53. '<li>Boy: {name} - {age}</li>',
  54. '</tpl>',
  55. '</tpl>',
  56. '</tpl></ul>',
  57. {
  58. compiled: true,
  59. disableFormats: true,
  60. isGirl: function(gender){
  61. return gender == 'f';
  62. }
  63. }
  64. );
  65. Y.Assert.areEqual( '<ul><li>Girl: Sara Grace - 3</li><li>Boy: Zachary - 2</li><li>Baby Boy: John James - 6 months</li></ul>',
  66. tpl3.apply( data ), 'Test apply with template member functions, basic comparison operators, and math' );
  67. }
  68. // apply is an alias for applyTemplate
  69. }));