UNPKG

foam-framework

Version:
64 lines (58 loc) 1.98 kB
/** * @license * Copyright 2014 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ CLASS({ package: 'foam.graphics', name: 'DAOListCView', extends: 'foam.graphics.CView', properties: [ { model_: 'foam.core.types.DAOProperty', name: 'dao' }, { model_: 'IntProperty', name: 'scrollTop', preSet: function(_,t) { return Math.max(t, 0); }, postSet: function() { this.scroll(); } }, { name: 'rowRenderer' }, { name: 'objs', postSet: function() { this.view && this.view.paint(); }, factory: function() { return []; } } ], methods: { init: function(args) { this.SUPER(args); this.dao.listen(this.scroll); }, paintSelf: function() { var renderer = this.rowRenderer; var offset = -(this.scrollTop % renderer.height); this.canvas.save(); this.canvas.translate(0, offset); for ( var i = 0; i < this.objs.length; i++ ) { renderer.render(this.canvas, this.objs[i]); this.canvas.translate(0, renderer.height); } this.canvas.restore(); } }, listeners: [ { name: 'scroll', code: function() { var renderer = this.rowRenderer; var limit = Math.floor(this.height / renderer.height); var skip = Math.floor(this.scrollTop / renderer.height); var self = this; this.dao.skip(skip).limit(limit).select()(function(objs) { self.objs = objs; }); } } ] });