dojo.require("dojox.grid.Grid");
dojo.require("dojo.data.ItemFileReadStore");


dojo.addOnLoad(function(){
    var memberstore = new dojo.data.ItemFileReadStore({
        url: '/community/@@community-store.json'});
    var model = new dojox.grid.data.DojoData(null, null, {
          store: memberstore,
	  query: {username: '*'},
	  rowsPerPage: 20,
	  clientSort: true
      });

    formatDate = function(inDatum){
      return dojo.date.locale.format(new Date(inDatum),
				     this.constraint);
    };

    var view1 = {
    cells: [[
      {name: 'Name',
       field: 'link',
       width: 'auto',
       styles: 'text-align:left;'},
      {name: 'Videos',
       field: 'videos',
       width: 'auto',
       styles: 'text-align:center;'},
      {name: 'Last login',
       formatter: formatDate,
       field: 'last_visit',
       width: 'auto',
       constraint: {formatLength: 'long', selector: "date"},
       styles: 'text-align:center;'},
      {name: 'Joined',
       formatter: formatDate,
       field: 'created',
       width: 'auto',
       constraint: {formatLength: 'long', selector: "date"},
       styles: 'text-align:center;'}
      ]]
    };
    var layout = [ view1 ];
    var memgrid = new dojox.grid.Grid({
	  id: 'member-grid',
	  model: model,
	  structure: layout,
	  style: 'width:582px;height:320px;'
      });
    dojo.byId('member-container').appendChild(memgrid.domNode);
    memgrid.render();
  });

