Skip to content

Commit

Permalink
Merge pull request #429 from NateWr/i2708_js_constants
Browse files Browse the repository at this point in the history
pkp/pkp-lib#2708 Pass constants with JS handler configuration
  • Loading branch information
NateWr authored Aug 28, 2017
2 parents 12e07c2 + dd265a9 commit 563d46e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
31 changes: 16 additions & 15 deletions js/controllers/list/submissions/CatalogSubmissionsListPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ export default {
},
data: function() {
return {
constants: {},
catalogSortBy: '',
catalogSortDir: '',
};
},
computed: {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
},
/**
Expand Down Expand Up @@ -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;
}
},
Expand Down
1 change: 1 addition & 0 deletions js/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ window.pkp = {
'SelectSubmissionsListPanel': SelectSubmissionsListPanel,
'CatalogSubmissionsListPanel': CatalogSubmissionsListPanel,
},
const: {},
/**
* Helper function to determine if the current user has a role
*
Expand Down

0 comments on commit 563d46e

Please sign in to comment.