From dcd50306ed8546798992f81120a2774cdb917876 Mon Sep 17 00:00:00 2001 From: Nate Wright Date: Mon, 14 Aug 2017 15:44:42 +0100 Subject: [PATCH 1/2] pkp/pkp-lib#2708 Use new global pattern for passing constants to JS handlers --- .../CatalogSubmissionsListHandler.inc.php | 14 ++++----- .../CatalogSubmissionsListPanel.vue | 31 ++++++++++--------- js/load.js | 1 + 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/controllers/list/submissions/CatalogSubmissionsListHandler.inc.php b/controllers/list/submissions/CatalogSubmissionsListHandler.inc.php index 64847259573..f4e05f8be5a 100644 --- a/controllers/list/submissions/CatalogSubmissionsListHandler.inc.php +++ b/controllers/list/submissions/CatalogSubmissionsListHandler.inc.php @@ -29,6 +29,8 @@ public function getConfig() { list($catalogSortBy, $catalogSortDir) = explode('-', $context->getSetting('catalogSortOption')); $catalogSortBy = empty($catalogSortBy) ? ORDERBY_DATE_PUBLISHED : $catalogSortBy; $catalogSortDir = $catalogSortDir == SORT_DIRECTION_ASC ? 'ASC' : 'DESC'; + $config['catalogSortBy'] = $catalogSortBy; + $config['catalogSortDir'] = $catalogSortDir; $this->_getParams = array_merge( $this->_getParams, @@ -129,14 +131,10 @@ public function getConfig() { } } - $config['constants'] = array( - 'assocTypes' => array( - 'press' => ASSOC_TYPE_PRESS, - 'category' => ASSOC_TYPE_CATEGORY, - 'series' => ASSOC_TYPE_SERIES, - ), - 'catalogSortBy' => $catalogSortBy, - 'catalogSortDir' => $catalogSortDir, + $config['_constants'] = array( + 'ASSOC_TYPE_PRESS' => ASSOC_TYPE_PRESS, + 'ASSOC_TYPE_CATEGORY' => ASSOC_TYPE_CATEGORY, + 'ASSOC_TYPE_SERIES' => ASSOC_TYPE_SERIES, ); return $config; diff --git a/js/controllers/list/submissions/CatalogSubmissionsListPanel.vue b/js/controllers/list/submissions/CatalogSubmissionsListPanel.vue index 653907df479..1d9c92a8a6b 100644 --- a/js/controllers/list/submissions/CatalogSubmissionsListPanel.vue +++ b/js/controllers/list/submissions/CatalogSubmissionsListPanel.vue @@ -108,7 +108,8 @@ export default { }, data: function() { return { - constants: {}, + catalogSortBy: '', + catalogSortDir: '', }; }, computed: { @@ -138,9 +139,9 @@ export default { * if we're looking at a filtered view */ featuredLabel: function() { - if (this.filterAssocType === this.constants.assocTypes.category) { + if (this.filterAssocType === pkp.const.ASSOC_TYPE_CATEGORY) { return this.i18n.featuredCategory; - } else if (this.filterAssocType === this.constants.assocTypes.series) { + } else if (this.filterAssocType === pkp.const.ASSOC_TYPE_SERIES) { return this.i18n.featuredSeries; } return this.i18n.featured; @@ -151,9 +152,9 @@ export default { * if we're looking at a filtered view */ newReleaseLabel: function() { - if (this.filterAssocType === this.constants.assocTypes.category) { + if (this.filterAssocType === pkp.const.ASSOC_TYPE_CATEGORY) { return this.i18n.newReleaseCategory; - } else if (this.filterAssocType === this.constants.assocTypes.series) { + } else if (this.filterAssocType === pkp.const.ASSOC_TYPE_SERIES) { return this.i18n.newReleaseSeries; } return this.i18n.newRelease; @@ -164,9 +165,9 @@ export default { * if we're looking at a filtered view */ featuredNotice: function() { - if (this.filterAssocType === this.constants.assocTypes.category) { + if (this.filterAssocType === pkp.const.ASSOC_TYPE_CATEGORY) { return this.__('orderingFeaturesSection', {title: _.findWhere(this.filters.categoryIds.filters, {val: this.filterAssocId}).title}); - } else if (this.filterAssocType === this.constants.assocTypes.series) { + } else if (this.filterAssocType === pkp.const.ASSOC_TYPE_SERIES) { return this.__('orderingFeaturesSection', {title: _.findWhere(this.filters.seriesIds.filters, {val: this.filterAssocId}).title}); } return this.i18n.orderingFeatures; @@ -182,11 +183,11 @@ export default { */ filterAssocType: function() { if (_.has(this.filterParams, 'categoryIds')) { - return this.constants.assocTypes.category; + return pkp.const.ASSOC_TYPE_CATEGORY; } else if (_.has(this.filterParams, 'seriesIds')) { - return this.constants.assocTypes.series; + return pkp.const.ASSOC_TYPE_SERIES; } - return this.constants.assocTypes.press; + return pkp.const.ASSOC_TYPE_PRESS; }, /** @@ -240,14 +241,14 @@ export default { if (typeof this.filterParams.categoryIds !== 'undefined') { var cat = _.findWhere(this.filters.categoryIds.filters, {val: this.filterParams.categoryIds[0]}); this.getParams.orderBy = cat.sortBy; - this.getParams.orderDirection = cat.sortDir || this.constants.catalogSortDir; + this.getParams.orderDirection = cat.sortDir || this.catalogSortDir; } else if (typeof this.filterParams.seriesIds !== 'undefined') { var series = _.findWhere(this.filters.seriesIds.filters, {val: this.filterParams.seriesIds[0]}); - this.getParams.orderBy = series.sortBy || this.constants.catalogSortBy; - this.getParams.orderDirection = series.sortDir || this.constants.catalogSortDir; + this.getParams.orderBy = series.sortBy || this.catalogSortBy; + this.getParams.orderDirection = series.sortDir || this.catalogSortDir; } else { - this.getParams.orderBy = this.constants.catalogSortBy; - this.getParams.orderDirection = this.constants.catalogSortDir; + this.getParams.orderBy = this.catalogSortBy; + this.getParams.orderDirection = this.catalogSortDir; } }, diff --git a/js/load.js b/js/load.js index f5d1dbe4561..bce48d54281 100644 --- a/js/load.js +++ b/js/load.js @@ -21,6 +21,7 @@ window.pkp = { 'SelectSubmissionsListPanel': SelectSubmissionsListPanel, 'CatalogSubmissionsListPanel': CatalogSubmissionsListPanel, }, + const: {}, /** * Helper function to determine if the current user has a role * From dd265a9fc085c6f86aa3f8851d839ee6774a863d Mon Sep 17 00:00:00 2001 From: Nate Wright Date: Mon, 28 Aug 2017 13:57:02 +0100 Subject: [PATCH 2/2] Submodule update ##NateWr/i2708_js_constants## --- lib/pkp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pkp b/lib/pkp index 3b9e79b946a..b4bd85b2932 160000 --- a/lib/pkp +++ b/lib/pkp @@ -1 +1 @@ -Subproject commit 3b9e79b946a81077c7ae1954a94fccf6fe1b061e +Subproject commit b4bd85b2932c5e235cdf5a4d0d3649cc7e354af3