|
| 1 | +import _ from 'underscore'; |
| 2 | +import $ from 'jquery'; |
| 3 | +import context from 'context-utils'; |
| 4 | +import { Collection } from 'backbone'; |
| 5 | +import PageView from '../../lib/PageView'; |
| 6 | +import OsBarView from '../../lib/navigations/OsBarView'; |
| 7 | +import SwipeListView from './SwipeListView'; |
| 8 | +import ModelA from './models/ModelA'; |
| 9 | + |
| 10 | +export default class SwipeListViewPage extends PageView { |
| 11 | + |
| 12 | + addClass() { |
| 13 | + return 'swipe-list-view'; |
| 14 | + } |
| 15 | + |
| 16 | + constructor(options) { |
| 17 | + super(options); |
| 18 | + |
| 19 | + const state = this.getState(); |
| 20 | + const navigationBarView = new OsBarView({ |
| 21 | + state: state, |
| 22 | + addClass: 'back-bar', |
| 23 | + left: '<span>Back</span>', |
| 24 | + center: $('<span class="title"></span>').text('Swipe list view'), |
| 25 | + popViewOnBackButton: true |
| 26 | + }); |
| 27 | + this.addSubView('navigationBarView', navigationBarView); |
| 28 | + |
| 29 | + this.initCollection(); |
| 30 | + |
| 31 | + const listView = new SwipeListView(_.extend(this.options.listview || {}, { |
| 32 | + collection: this.collection, |
| 33 | + itemClass: 'ui-swipe-list-item' |
| 34 | + })); |
| 35 | + this.addSubView('listView', listView); |
| 36 | + |
| 37 | + this.listenTo(listView, 'swipe:left', (view) => { console.log(view) }); |
| 38 | + this.listenTo(listView, 'swipe:right', (view) => { console.log(view) }); |
| 39 | + |
| 40 | + // For debug |
| 41 | + window.__listView = listView; |
| 42 | + } |
| 43 | + |
| 44 | + getNavigationBar() { |
| 45 | + return this.getSubView('navigationBarView'); |
| 46 | + } |
| 47 | + |
| 48 | + onRender(rendered) { |
| 49 | + if (!rendered) { |
| 50 | + const listView = this.getSubView('listView'); |
| 51 | + this.$el.append(listView.el); |
| 52 | + listView.render(); |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + // |
| 57 | + // Utils |
| 58 | + // |
| 59 | + |
| 60 | + initCollection() { |
| 61 | + const models = []; |
| 62 | + let aModelClass; |
| 63 | + for (var i = 0; i < 30; i++) { |
| 64 | + models.push(new ModelA({ |
| 65 | + id: i |
| 66 | + })); |
| 67 | + } |
| 68 | + |
| 69 | + const collection = new Collection(models); |
| 70 | + this.collection = collection; |
| 71 | + } |
| 72 | + |
| 73 | +} |
0 commit comments