PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/app/assets/javascripts/views/project_view.js

https://bitbucket.org/sqctest01/fulcrum
JavaScript | 95 lines | 68 code | 18 blank | 9 comment | 4 complexity | 14f072257f56cce44739693cd8ad7193 MD5 | raw file
  1. if (typeof Fulcrum == 'undefined') {
  2. Fulcrum = {};
  3. }
  4. Fulcrum.ProjectView = Backbone.View.extend({
  5. initialize: function() {
  6. this.columns = {};
  7. _.bindAll(this, 'addStory', 'addAll', 'render');
  8. this.model.stories.bind('add', this.addStory);
  9. this.model.stories.bind('reset', this.addAll);
  10. this.model.stories.bind('all', this.render);
  11. this.model.bind('change:userVelocity', this.addAll);
  12. this.model.stories.fetch();
  13. },
  14. // Triggered when the 'Add Story' button is clicked
  15. newStory: function() {
  16. this.model.stories.add([{
  17. events: [], editing: true
  18. }]);
  19. },
  20. addStory: function(story, column) {
  21. // If column is blank determine it from the story. When the add event
  22. // is bound on a collection, the callback sends the collection as the
  23. // second argument, so also check that column is a string and not an
  24. // object for those cases.
  25. if (typeof column === 'undefined' || typeof column !== 'string') {
  26. column = story.column;
  27. }
  28. var view = new Fulcrum.StoryView({model: story}).render();
  29. this.appendViewToColumn(view, column);
  30. view.setFocus();
  31. },
  32. appendViewToColumn: function(view, columnName) {
  33. $(columnName).append(view.el);
  34. },
  35. addIteration: function(iteration) {
  36. var that = this;
  37. var column = iteration.get('column');
  38. var view = new Fulcrum.IterationView({model: iteration}).render();
  39. this.appendViewToColumn(view, column);
  40. _.each(iteration.stories(), function(story) {
  41. that.addStory(story, column);
  42. });
  43. },
  44. addAll: function() {
  45. $(".loading_screen").show();
  46. var that = this;
  47. $('#done').html("");
  48. $('#in_progress').html("");
  49. $('#backlog').html("");
  50. $('#chilly_bin').html("");
  51. this.model.rebuildIterations();
  52. // Render each iteration
  53. _.each(this.model.iterations, function(iteration) {
  54. var column = iteration.get('column');
  55. that.addIteration(iteration);
  56. });
  57. // Render the chilly bin. This needs to be rendered separately because
  58. // the stories don't belong to an iteration.
  59. _.each(this.model.stories.column('#chilly_bin'), function(story) {
  60. that.addStory(story);
  61. });
  62. $(".loading_screen").hide();
  63. },
  64. scaleToViewport: function() {
  65. var storyTableTop = $('table.stories tbody').offset().top;
  66. // Extra for the bottom padding and the
  67. var extra = 100;
  68. var height = $(window).height() - (storyTableTop + extra);
  69. $('.storycolumn').css('height', height + 'px');
  70. },
  71. notice: function(message) {
  72. $.gritter.add(message);
  73. },
  74. addColumnView: function(id, view) {
  75. this.columns[id] = view;
  76. }
  77. });