diff --git a/App.js b/App.js index 111f227..5e29fe1 100644 --- a/App.js +++ b/App.js @@ -53,6 +53,7 @@ define([ } this.id = props.id; this.name = props.name; + this.siblings = props.siblings; this.logoName = props.logo_name; this.logoDetailPageName = props.logo_detail_page_name; this.version = props.version; diff --git a/AppCenterMetaCategory.js b/AppCenterMetaCategory.js index f54bbea..0b86864 100644 --- a/AppCenterMetaCategory.js +++ b/AppCenterMetaCategory.js @@ -100,11 +100,22 @@ define([ isContextAction: false, label: _('Open'), callback: lang.hitch(this, function(id, app) { + app.siblings = this._getCurrentSiblings(); this.onShowApp(app); }) }] }); + this._getCurrentSiblings = function() { + // to show prev or next app on the AppDetailsPage + // we need all ids of the current siblings + var siblings = this.grid.store.query(this.filterQuery); + var siblingIds = array.map(siblings, function(iapp) { + return iapp.id; + }); + return siblingIds; + }; + this.addChild(this._label); this.own(this._label); //this.addChild(this.button); diff --git a/AppDetailsPage.js b/AppDetailsPage.js index 34657c4..afff85f 100644 --- a/AppDetailsPage.js +++ b/AppDetailsPage.js @@ -110,14 +110,49 @@ define([ this.own(this._progressBar); this._grid = new AppCenterGallery({}); this.own(this._grid); + }, - this.headerButtons = [{ + getHeaderButtons: function() { + var buttons = [{ name: 'close', iconClass: this.isSubPage ? 'umcArrowLeftIconWhite' : 'umcCloseIconWhite', label: this.backLabel, align: 'left', callback: lang.hitch(this, 'onBack') }]; + + if (this.app.siblings && this.app.siblings.length) { + var idx = array.indexOf(this.app.siblings, this.app.id); + var prev_idx = idx - 1; + var next_idx = idx + 1; + var isPrevIdxValid = prev_idx >= 0; + var isNextIdxValid = next_idx < this.app.siblings.length; + var app = { + siblings: this.app.siblings + }; + buttons.push({ + name: 'prev', + iconClass: 'umcLeftIconWhite', + label: isPrevIdxValid ? _('Previous app') : '', + align: 'left', + disabled: !isPrevIdxValid, + callback: lang.hitch(this, 'loadApp', app, prev_idx) + }); + buttons.push({ + name: 'next', + iconClass: 'umcRightIconWhite', + label: isNextIdxValid ? _('Next app') : '', + align: 'left', + disabled: !isNextIdxValid, + callback: lang.hitch(this, 'loadApp', app, next_idx) + }); + } + return buttons; + }, + + loadApp: function(app, idx) { + app.id = this.app.siblings[idx]; + this.set('app', app); }, _setAppAttr: function(app) { @@ -131,6 +166,7 @@ define([ // we need to ask the server, // it is not yet known! appLoaded = tools.umcpCommand(this.getAppCommand, {'application': app.id}).then(function(data) { + data.result.siblings = app.siblings; return data.result; }); } @@ -382,6 +418,7 @@ define([ } this.set('navButtons', this.getButtons()); + this.set('headerButtons', this.getHeaderButtons()); this._navButtons.set('style', {'margin-left': '-0.2em', 'margin-top': '1em'}); this._navHeaderButtonContainer.addChild(this._navButtons);