siteace.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. Websites = new Mongo.Collection("websites");
  2. if (Meteor.isClient) {
  3. /////
  4. // template helpers
  5. /////
  6. // helper function that returns all available websites
  7. Template.website_list.helpers({
  8. websites:function(){
  9. return Websites.find({});
  10. }
  11. });
  12. /////
  13. // template events
  14. /////
  15. Template.website_item.events({
  16. "click .js-upvote":function(event){
  17. // example of how you can access the id for the website in the database
  18. // (this is the data context for the template)
  19. var website_id = this._id;
  20. console.log("Up voting website with id "+website_id);
  21. // put the code in here to add a vote to a website!
  22. return false;// prevent the button from reloading the page
  23. },
  24. "click .js-downvote":function(event){
  25. // example of how you can access the id for the website in the database
  26. // (this is the data context for the template)
  27. var website_id = this._id;
  28. console.log("Down voting website with id "+website_id);
  29. // put the code in here to remove a vote from a website!
  30. return false;// prevent the button from reloading the page
  31. }
  32. })
  33. Template.website_form.events({
  34. "click .js-toggle-website-form":function(event){
  35. $("#website_form").toggle('slow');
  36. },
  37. "submit .js-save-website-form":function(event){
  38. // here is an example of how to get the url out of the form:
  39. var url = event.target.url.value;
  40. console.log("The url they entered is: "+url);
  41. // put your website saving code in here!
  42. return false;// stop the form submit from reloading the page
  43. }
  44. });
  45. }
  46. if (Meteor.isServer) {
  47. // start up function that creates entries in the Websites databases.
  48. Meteor.startup(function () {
  49. // code to run on server at startup
  50. if (!Websites.findOne()){
  51. console.log("No websites yet. Creating starter data.");
  52. Websites.insert({
  53. title:"Goldsmiths Computing Department",
  54. url:"http://www.gold.ac.uk/computing/",
  55. description:"This is where this course was developed.",
  56. createdOn:new Date()
  57. });
  58. Websites.insert({
  59. title:"University of London",
  60. url:"http://www.londoninternational.ac.uk/courses/undergraduate/goldsmiths/bsc-creative-computing-bsc-diploma-work-entry-route",
  61. description:"University of London International Programme.",
  62. createdOn:new Date()
  63. });
  64. Websites.insert({
  65. title:"Coursera",
  66. url:"http://www.coursera.org",
  67. description:"Universal access to the world’s best education.",
  68. createdOn:new Date()
  69. });
  70. Websites.insert({
  71. title:"Google",
  72. url:"http://www.google.com",
  73. description:"Popular search engine.",
  74. createdOn:new Date()
  75. });
  76. }
  77. });
  78. }