diff options
| author | Xavier Morel <xmo@openerp.com> | 2013-09-13 17:13:16 +0200 |
|---|---|---|
| committer | Xavier Morel <xmo@openerp.com> | 2013-09-13 17:13:16 +0200 |
| commit | 243a9c559b7c603ee1cffb9a186401771e35c871 (patch) | |
| tree | 3c2add5fad5ecefca821aae60ebd4d49d2ecdda0 /addons/website/static/src/js/website.editor.js | |
| parent | 1adb76aad079a3cebf66fa2f50558f93bacbc52e (diff) | |
[ADD] paginated images
bzr revid: xmo@openerp.com-20130913151316-rzr3rcg1w7h3gw10
Diffstat (limited to 'addons/website/static/src/js/website.editor.js')
| -rw-r--r-- | addons/website/static/src/js/website.editor.js | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/addons/website/static/src/js/website.editor.js b/addons/website/static/src/js/website.editor.js index 6c14b29e3a9..c7e5155fcc9 100644 --- a/addons/website/static/src/js/website.editor.js +++ b/addons/website/static/src/js/website.editor.js @@ -666,13 +666,25 @@ }, }); + var IMAGES_PER_ROW = 3; + var IMAGES_ROWS = 3; website.editor.ExistingImageDialog = website.editor.Dialog.extend({ template: 'website.editor.dialog.image.existing', events: _.extend({}, website.editor.Dialog.prototype.events, { 'click .existing-attachments a': 'select_existing', + 'click .pager > li': function (e) { + e.preventDefault(); + var $target = $(e.currentTarget); + if ($target.hasClass('disabled')) { + return; + } + this.page += $target.hasClass('previous') ? -1 : 1; + this.display_attachments(); + }, }), init: function (parent) { this.image = null; + this.page = 0; this.parent = parent; this._super(parent.editor); }, @@ -684,7 +696,6 @@ }, fetch_existing: function () { - // FIXME: lazy load attachments? return openerp.jsonRpc('/web/dataset/call_kw', 'call', { model: 'ir.attachment', method: 'search_read', @@ -698,14 +709,29 @@ }); }, fetched_existing: function (records) { + this.records = records; + this.display_attachments(); + }, + display_attachments: function () { + var per_screen = IMAGES_PER_ROW * IMAGES_ROWS; + + var from = this.page * per_screen; + var records = this.records; + // Create rows of 3 records var rows = _(records).chain() - .groupBy(function (_, index) { return Math.floor(index / 3); }) + .slice(from, from + per_screen) + .groupBy(function (_, index) { return Math.floor(index / IMAGES_PER_ROW); }) .values() .value(); + this.$('.existing-attachments').replaceWith( openerp.qweb.render( 'website.editor.dialog.image.existing.content', {rows: rows})); + this.$('.pager') + .find('li.previous').toggleClass('disabled', (from === 0)).end() + .find('li.next').toggleClass('disabled', (from + per_screen >= records.length)); + }, select_existing: function (e) { e.preventDefault(); |
