PageRenderTime 37ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/Hangman/Content/js/Collections.js

https://bitbucket.org/farmas/hangman
JavaScript | 31 lines | 28 code | 3 blank | 0 comment | 2 complexity | 673fcc060fc922e8312723e70549c6c3 MD5 | raw file
  1. (function (ns, undefined) {
  2. ns.Challenges = Backbone.Collection.extend({
  3. model: ns.Challenge,
  4. url: ns.Server.getContextPath() + "Game/Challenges",
  5. comparator: function (challenge) {
  6. return -challenge.id;
  7. },
  8. getFirstUnsolved: function () {
  9. var unsolved = _.find(this.models, function (c) { return c.get('answered') == false });
  10. return unsolved != undefined ? unsolved : this.models[0];
  11. },
  12. addChallenge: function (word) {
  13. this.create({ word: word, correct: true, answered: true, results: [], isCreator: true });
  14. },
  15. deselectAll: function () {
  16. this.each(function (c) { c.set({ active:false }); });
  17. }
  18. });
  19. ns.ChallengeResults = Backbone.Collection.extend({
  20. model: ns.ChallengeResult,
  21. setChallengeId: function (challengeId) {
  22. this.challengeId = challengeId;
  23. },
  24. url: function () {
  25. return ns.Server.getContextPath() + "Game/ChallengeResults/" + this.challengeId;
  26. }
  27. });
  28. })(Hangman);