data-view.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  3. *
  4. * http://extjs.com/license
  5. */
  6. Ext.onReady(function() {
  7. var xd = Ext.data;
  8. var store = new Ext.data.JsonStore({
  9. url : 'get-images.php',
  10. root : 'images',
  11. fields : ['name', 'url', {
  12. name : 'size',
  13. type : 'float'
  14. }, {
  15. name : 'lastmod',
  16. type : 'date',
  17. dateFormat : 'timestamp'
  18. }]
  19. });
  20. store.load();
  21. var tpl = new Ext.XTemplate('<tpl for=".">',
  22. '<div class="thumb-wrap" id="{name}">',
  23. '<div class="thumb"><img src="{url}" title="{name}"></div>',
  24. '<span class="x-editable">{shortName}</span></div>', '</tpl>',
  25. '<div class="x-clear"></div>');
  26. var panel = new Ext.Panel({
  27. id : 'images-view',
  28. frame : true,
  29. width : 535,
  30. autoHeight : true,
  31. collapsible : true,
  32. layout : 'fit',
  33. title : 'Simple DataView with editable labels, multi and drag selection',
  34. items : new Ext.DataView({
  35. store : store,
  36. tpl : tpl,
  37. autoHeight : true,
  38. multiSelect : true,
  39. overClass : 'x-view-over',
  40. itemSelector : 'div.thumb-wrap',
  41. emptyText : 'No images to display',
  42. plugins : [new Ext.DataView.DragSelector(),
  43. new Ext.DataView.LabelEditor({
  44. dataIndex : 'name'
  45. })],
  46. prepareData : function(data) {
  47. data.shortName = Ext.util.Format
  48. .ellipsis(data.name, 15);
  49. data.sizeString = Ext.util.Format.fileSize(data.size);
  50. data.dateString = data.lastmod.format("m/d/Y g:i a");
  51. return data;
  52. }
  53. })
  54. });
  55. panel.render(document.body);
  56. });