AlbumsPanel.js
上传用户:shuoshiled
上传日期:2018-01-28
资源大小:10124k
文件大小:3k
源码类别:

中间件编程

开发平台:

JavaScript

  1. /*!
  2.  * Ext JS Library 3.0.0
  3.  * Copyright(c) 2006-2009 Ext JS, LLC
  4.  * licensing@extjs.com
  5.  * http://www.extjs.com/license
  6.  */
  7. Imgorg.AlbumsPanel = Ext.extend(Ext.Panel,{
  8.     initComponent: function() {
  9.         Ext.apply(this, {
  10.             layout: 'column',
  11.             defaults: {
  12.                 border: false
  13.             },
  14.             autoScroll: true,
  15.             defaultType: 'img-album',
  16.             items: [{
  17.                 columnWidth: 0.33
  18.             },{
  19.                 columnWidth: 0.33
  20.             },{
  21.                 columnWidth: 0.34
  22.             }]
  23.         });
  24.         Imgorg.AlbumsPanel.superclass.initComponent.call(this);
  25.         this.loadAlbums();
  26.         this.on('activate', this.loadAlbums, this);
  27.     },
  28.     
  29.     afterRender: function() {
  30.         Imgorg.AlbumsPanel.superclass.afterRender.call(this);
  31.         this.body.on('click', this.onClick, this, {delegate: 'div.album-wrap'});
  32.     },
  33.     
  34.     loadAlbums: function() {
  35.         Imgorg.ss.Albums.getAllInfo({}, this.setupAlbums, this);
  36.     },
  37.     
  38.     setupAlbums: function(data, resp) {
  39.         var cols = [[],[],[]];
  40.         var idx = 0;
  41.         for (var i = 0;i < data.length;i++) {
  42.             var a = data[i];
  43.             cols[idx].push(a);
  44.             if (++idx >= 3) {
  45.                 idx = 0;
  46.             }
  47.         }
  48.         for (var i = 0; i < 3; i++) {
  49.             this.items.get(i).generateAlbums(cols[i]);
  50.         }
  51.     },
  52.     
  53.     onClick: function(e, n) {
  54.         var album = n.attributes.album_id.value;
  55.         var album_name = n.attributes.album_name.value;
  56.         this.fireEvent('openalbum', this, album, album_name);
  57.     }
  58. });
  59. Ext.reg('img-albumspanel', Imgorg.AlbumsPanel);
  60. Imgorg.Album = Ext.extend(Ext.Panel,{
  61.     maxWidth: 150,
  62.     maxHeight: 100,
  63.     tpl: new Ext.XTemplate(
  64.         '<tpl for=".">',
  65.             '<div class="album-wrap" album_id="{id}" album_name="{text}">',
  66.                 '<div class="album-wrap-inner">',
  67.                     '{filename:this.imageFormat}',
  68.                     '<h3>Album: {text}</h3>',
  69.                     '<div class="album-details">',
  70.                         '<p>Date: {date}</p>',
  71.                         '<p>Size: {size} images</p>',
  72.                     '</div>',
  73.                 '</div>',
  74.             '</div>',
  75.         '</tpl>',{
  76.             imageFormat: function(filename, data) {
  77.                 if (filename) {
  78.                     return String.format('<img src="images/thumbs/{0}" height="{1}" width="{2}" />',filename, data.height, data.width);
  79.                 } else {
  80.                     return '<p>No Images in Album</p>';
  81.                 }
  82.             }
  83.         }
  84.     ),
  85.     generateAlbums: function(albums) {
  86.         for(var i = 0; i < albums.length;i++) {
  87.             if (albums[i].exif) {
  88.                 albums[i].height = Math.min(this.maxHeight, albums[i].exif.COMPUTED.Height);
  89.                 albums[i].width = Math.min(this.maxWidth, albums[i].exif.COMPUTED.Width);
  90.             }
  91.         }
  92.         this.tpl.overwrite(this.body, albums);
  93.     }
  94. });
  95. Ext.reg('img-album', Imgorg.Album);