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.

187 lines
7.9 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. Ext.onReady(function() {
  16. var store = new Ext.data.ArrayStore({
  17. proxy : new Ext.data.MemoryProxy(),
  18. fields : ['hasEmail', 'hasCamera', 'id', 'name', 'price', 'screen', 'camera', 'color', 'type', 'reviews', 'screen-size'],
  19. sortInfo: {
  20. field : 'name',
  21. direction: 'ASC'
  22. }
  23. });
  24. store.loadData([
  25. [true, false, 1, "LG KS360", 70, "240 x 320 pixels", 2, "Pink", "Slider", 359, 2.400000],
  26. [true, true, 2, "Sony Ericsson C510a Cyber-shot", 180, "320 x 240 pixels", 3.2, "Future black", "Candy bar", 11, 0.000000],
  27. [true, true, 3, "LG PRADA KE850", 155, "240 x 400 pixels", 2, "Black", "Candy bar", 113, 0.000000],
  28. [true, true, 4, "Nokia N900 Smartphone 32 GB", 499, "800 x 480 pixels", 5, "Black", "Slider", 320, 3.500000],
  29. [true, false, 5, "Motorola RAZR V3", 65, "96 x 80 pixels", 0.3, "Silver", "Folder type phone", 5, 2.200000],
  30. [true, true, 6, "LG KC910 Renoir", 180, "240 x 400 pixels", 8, "Black", "Candy bar", 79, 0.000000],
  31. [true, true, 7, "BlackBerry Curve 8520 BlackBerry", 135, "320 x 240 pixels", 2, "Frost", "Candy bar", 320, 2.640000],
  32. [true, true, 8, "Sony Ericsson W580i Walkman", 70, "240 x 320 pixels", 2, "Urban gray", "Slider", 1, 0.000000],
  33. [true, true, 9, "Nokia E63 Smartphone 110 MB", 170, "320 x 240 pixels", 2, "Ultramarine blue", "Candy bar", 319, 2.360000],
  34. [true, true, 10, "Sony Ericsson W705a Walkman", 274, "320 x 240 pixels", 3.2, "Luxury silver", "Slider", 5, 0.000000],
  35. [false, false, 11, "Nokia 5310 XpressMusic", 170, "320 x 240 pixels", 2, "Blue", "Candy bar", 344, 2.000000],
  36. [false, true, 12, "Motorola SLVR L6i", 50, "128 x 160 pixels", 2, "Black", "Candy bar", 38, 0.000000],
  37. [false, true, 13, "T-Mobile Sidekick 3 Smartphone 64 MB", 170, "240 x 160 pixels", 1.3, "Green", "Sidekick", 115, 0.000000],
  38. [false, true, 14, "Audiovox CDM8600", 50, "240 x 160 pixels", 2, "Blue", "Folder type phone", 1, 0.000000],
  39. [false, true, 15, "Nokia N85", 70, "320 x 240 pixels", 5, "Copper", "Dual slider", 143, 2.600000],
  40. [false, true, 16, "Sony Ericsson XPERIA X1", 180, "800 x 480 pixels", 3.2, "Solid black", "Slider", 14, 0.000000],
  41. [false, true, 17, "Motorola W377", 135, "128 x 160 pixels", 0.3, "Black", "Folder type phone", 35, 0.000000],
  42. [true, true, 18, "LG Xenon GR500", 50, "240 x 400 pixels", 2, "Red", "Slider", 658, 2.800000],
  43. [true, false, 19, "BlackBerry Curve 8900 BlackBerry", 135, "480 x 360 pixels", 3.2, "Silver", "Candy bar", 21, 2.440000],
  44. [true, false, 20, "Samsung SGH U600 Ultra Edition 10.9", 135, "240 x 320 pixels", 3.2, "Rainbow", "Slider", 169, 2.200000]
  45. ]);
  46. var dataview = new Ext.DataView({
  47. store: store,
  48. tpl : new Ext.XTemplate(
  49. '<ul>',
  50. '<tpl for=".">',
  51. '<li class="phone">',
  52. '<img width="64" height="64" src="images/phones/{[values.name.replace(/ /g, "-")]}.png" />',
  53. '<strong>{name}</strong>',
  54. '<span>{price:usMoney} ({camera} MP)</span>',
  55. '</li>',
  56. '</tpl>',
  57. '</ul>'
  58. ),
  59. plugins : [
  60. new Ext.ux.DataViewTransition({
  61. duration : 550,
  62. idProperty: 'id'
  63. })
  64. ],
  65. id: 'phones',
  66. itemSelector: 'li.phone',
  67. overClass : 'phone-hover',
  68. singleSelect: true,
  69. multiSelect : true,
  70. autoScroll : true
  71. });
  72. var tbar = new Ext.Toolbar({
  73. items : ['Sort on these fields:', ''],
  74. plugins: [new Ext.ux.ToolbarReorderer()],
  75. listeners: {
  76. scope : this,
  77. reordered: function(button) {
  78. changeSortDirection(button, false);
  79. }
  80. }
  81. });
  82. new Ext.Panel({
  83. title: 'Animated DataView',
  84. layout: 'fit',
  85. items : dataview,
  86. height: 615,
  87. width : 800,
  88. tbar : tbar,
  89. renderTo: 'docbody'
  90. });
  91. tbar.add(createSorterButton({
  92. text: 'Megapixels',
  93. sortData: {
  94. field: 'camera',
  95. direction: 'DESC'
  96. }
  97. }));
  98. tbar.add(createSorterButton({
  99. text: 'Price',
  100. sortData: {
  101. field: 'price',
  102. direction: 'DESC'
  103. }
  104. }));
  105. //perform an initial sort
  106. doSort();
  107. //The following functions are used to get the sorting data from the toolbar and apply it to the store
  108. /**
  109. * Tells the store to sort itself according to our sort data
  110. */
  111. function doSort() {
  112. store.sort(getSorters(), "ASC");
  113. };
  114. /**
  115. * Callback handler used when a sorter button is clicked or reordered
  116. * @param {Ext.Button} button The button that was clicked
  117. * @param {Boolean} changeDirection True to change direction (default). Set to false for reorder
  118. * operations as we wish to preserve ordering there
  119. */
  120. function changeSortDirection(button, changeDirection) {
  121. var sortData = button.sortData,
  122. iconCls = button.iconCls;
  123. if (sortData != undefined) {
  124. if (changeDirection !== false) {
  125. button.sortData.direction = button.sortData.direction.toggle("ASC", "DESC");
  126. button.setIconClass(iconCls.toggle("sort-asc", "sort-desc"));
  127. }
  128. store.clearFilter();
  129. doSort();
  130. }
  131. };
  132. /**
  133. * Returns an array of sortData from the sorter buttons
  134. * @return {Array} Ordered sort data from each of the sorter buttons
  135. */
  136. function getSorters() {
  137. var sorters = [];
  138. Ext.each(tbar.findByType('button'), function(button) {
  139. sorters.push(button.sortData);
  140. }, this);
  141. return sorters;
  142. }
  143. /**
  144. * Convenience function for creating Toolbar Buttons that are tied to sorters
  145. * @param {Object} config Optional config object
  146. * @return {Ext.Button} The new Button object
  147. */
  148. function createSorterButton(config) {
  149. config = config || {};
  150. Ext.applyIf(config, {
  151. listeners: {
  152. click: function(button, e) {
  153. changeSortDirection(button, true);
  154. }
  155. },
  156. iconCls: 'sort-' + config.sortData.direction.toLowerCase(),
  157. reorderable: true
  158. });
  159. return new Ext.Button(config);
  160. };
  161. });