I recently started a new site with Apostrophe CMS, and one of the features in the project will be extending apostrophe-events to have a list of "registered" users who are associated with each event. I was able to add a new joinByArray column to the apostrophe-events module, and it works correctly when editing events.
Now, I'm trying to add a Register button to the apostrophe-events-pages module, so that users can register for the event from each event's page. I currently have a working API endpoint available, which I created using this code:
(In file lib/modules/apostrophe-events-pages/index.js)
module.exports = {
construct: function(self, options) {
self.route('get', 'register', function(req, res) {
// Validate things with the launder module
var name = self.apos.launder.string(req.body.name);
// Deliver a JSON response
return res.send({ status: 'ok', moreInfo: 'something' });
});
}
};
That endpoint works as expected, but I'm stuck on adding a button with a link to the correct action on the front end. I created a button that looks correct in the show.html overwrite that I created, with the following code:
(In lib/modules/apostrophe-events-pages/views/show.html)
{{ buttons.minor('Register for Field Trip', { action: 'register' }) }}
I'm not sure how I can add a link to the register action. I tried adding this code to the same index.js file as above:
(In lib/modules/apostrophe-events-pages/index.js)
self.registerEvent = function() {
var res;
self.api('register', {}, function(result) {
res = results;
});
};
var superBeforeShow = self.beforeShow;
self.beforeShow = function(callback) {
self.link('register', self.registerEvent);
return superBeforeShow(callback);
};
But when I access the event page, an error happens that says self.link is not a function. Should I be putting the link code elsewhere?
Thanks!