PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/pollapli/ui/static/pollapli/views/events_view.js

https://bitbucket.org/kaosat_dev/pollapli
JavaScript | 88 lines | 81 code | 7 blank | 0 comment | 7 complexity | 9d79f211d8b6940dd0c5ee5b2f3d1b59 MD5 | raw file
  1. function get_type(thing)
  2. {
  3. if(thing===null)return "[object Null]"; // special case
  4. return Object.prototype.toString.call(thing);
  5. }
  6. var EventsView= Backbone.View.extend
  7. (
  8. {
  9. events: {
  10. "click #new-zone-button": "add"
  11. },
  12. initialize: function()
  13. {
  14. this.template=this.options.template;
  15. if (this.template==null)
  16. {
  17. this.template=pollapli.ui.templates["events_tmpl"];
  18. }
  19. _.bindAll(this, "render","add");
  20. if (this.collection!=null)
  21. {
  22. this.collection.bind("all", this.render,this);
  23. }
  24. },
  25. render: function()
  26. {
  27. if (this.collection!=null)
  28. {
  29. var latestFirst = this.collection.sortBy(function(event)
  30. {
  31. return -event.get("time");
  32. });
  33. latestFirst=jQuery.parseJSON(JSON.stringify(latestFirst) );
  34. $(this.el).jqotesub(this.template, latestFirst);
  35. }
  36. return this;
  37. },
  38. add: function ()
  39. {
  40. $("#new-zone-form-dialog").dialog("open");
  41. }
  42. }
  43. );
  44. var EventsHeaderView= Backbone.View.extend
  45. (
  46. {
  47. events: {
  48. "click #new-zone-button": "add"
  49. },
  50. initialize: function()
  51. {
  52. this.template=this.options.template;
  53. if (this.template==null)
  54. {
  55. this.template=pollapli.ui.templates["events_tmpl"];
  56. }
  57. _.bindAll(this, "render","add");
  58. if (this.collection!=null)
  59. {
  60. this.collection.bind("all", this.render,this);
  61. }
  62. },
  63. render: function()
  64. {
  65. if (this.collection!=null)
  66. {
  67. var latestFirst = this.collection.sortBy(function(event)
  68. {
  69. return -event.get("time");
  70. });
  71. latestFirst=jQuery.parseJSON(JSON.stringify(latestFirst) );
  72. $(this.el).jqotesub(this.template, latestFirst);
  73. }
  74. return this;
  75. },
  76. add: function ()
  77. {
  78. $("#new-zone-form-dialog").dialog("open");
  79. }
  80. }
  81. );