PageRenderTime 26ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Nancy/Diagnostics/Resources/Modules/tracing/sessions.js

http://github.com/NancyFx/Nancy
JavaScript | 60 lines | 44 code | 16 blank | 0 comment | 0 complexity | da8a3c9b6eda97e9d2d193e5da7d0f4c MD5 | raw file
Possible License(s): CC-BY-SA-3.0, LGPL-3.0, Apache-2.0, MPL-2.0-no-copyleft-exception, LGPL-2.0, BSD-3-Clause
  1. (function (Session) {
  2. var app = diagnostics.app;
  3. Session.Model = Backbone.Model.extend({});
  4. Session.Collection = Backbone.Collection.extend({
  5. model: Session.Model,
  6. url: function () {
  7. return Nancy.config.basePath + "trace/sessions/";
  8. }
  9. });
  10. Session.Views.List = Backbone.View.extend({
  11. el: '#main',
  12. initialize: function () {
  13. this.template = $("#sessionList").html();
  14. },
  15. render: function () {
  16. var sessions = this.model.toJSON();
  17. var html = Handlebars.compile(this.template)({ collection: sessions });
  18. $(this.el).html(html);
  19. _.each(sessions, this.renderItem, this);
  20. },
  21. renderItem: function (model) {
  22. var itemView = new Session.Views.Item({ model: model });
  23. $(this.el).append(itemView.el);
  24. }
  25. });
  26. Session.Views.Item = Backbone.View.extend({
  27. className: "item-list",
  28. events: {
  29. 'click': 'showSession'
  30. },
  31. initialize: function () {
  32. this.router = app.router;
  33. this.template = $("#session").html();
  34. this.render();
  35. },
  36. render: function () {
  37. var html = Handlebars.compile(this.template)({ model: this.model });
  38. $(this.el).append(html);
  39. },
  40. showSession: function () {
  41. this.router.navigate(this.model.id, true);
  42. }
  43. });
  44. })(diagnostics.module("session"))