~jonas-drange/online-services-common-js/navbar-autocomplete

« back to all changes in this revision

Viewing changes to src/photos/js/views/album-pager.js

  • Committer: Stephen Stewart
  • Date: 2014-02-22 23:57:25 UTC
  • mfrom: (18.1.2 trunk)
  • Revision ID: stephen.stewart@canonical.com-20140222235725-iw6f15t9umws19xd
mergeĀ lp:~stephen-stewart/online-services-common-js/remove-u1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
    Represents the pager in an album
3
 
*/
4
 
var AlbumPagerView = Y.Base.create('albumPagerView', Y.View, [], {
5
 
 
6
 
    initializer: function () {
7
 
 
8
 
        this.pagerNodes = Y.all(this.get('containers'));
9
 
        this.photoList = this.get('photoList');
10
 
    },
11
 
 
12
 
    buildURLTemplate: function (currentQueryString) {
13
 
        var pageParameterRegex = /page\=\d+/,
14
 
            pageParameterSubstitute = 'page={page}',
15
 
            ret;
16
 
 
17
 
        // found page parameter
18
 
        if(pageParameterRegex.test(currentQueryString)) {
19
 
            ret = currentQueryString.replace(pageParameterRegex, pageParameterSubstitute);
20
 
        }
21
 
        // append page parameter
22
 
        else {
23
 
            ret = currentQueryString + '&' + pageParameterSubstitute;
24
 
        }
25
 
        return '?' + ret;
26
 
    },
27
 
 
28
 
    render: function (app) {
29
 
 
30
 
        var total = this.photoList.get('total'),
31
 
            pagesize = this.photoList.get('pagesize'),
32
 
            page = this.photoList.get('page');
33
 
 
34
 
        if(total > pagesize) {
35
 
            // create one or two new Pages object, which then will replace the pager
36
 
            // Y.Pages does strict comparison, so make sure they're all Numbers
37
 
            this.pagerNodes.each(function (node) {
38
 
                new Y.Pages({
39
 
                    page: page,
40
 
                    pageSize: pagesize,
41
 
                    srcNode: node,
42
 
                    totalItems: total,
43
 
                    URLTemplate: this.buildURLTemplate(app.getQueryString())
44
 
                });
45
 
            }, this);
46
 
        }
47
 
    }
48
 
 
49
 
}, {
50
 
    ATTRS: {
51
 
        // note containerS, since this view will serve both
52
 
        // it could be one view pr pager
53
 
        containers: {
54
 
            value: '.paging'
55
 
        }
56
 
    }
57
 
});
58
 
 
59
 
Y.namespace('Photos').AlbumPagerView = AlbumPagerView;