PageRenderTime 52ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/resources/js/repo.js

https://bitbucket.org/rmanalan/hipchat-for-fecru
JavaScript | 49 lines | 44 code | 5 blank | 0 comment | 2 complexity | 3e21eade581cdf584d52ed10d1117328 MD5 | raw file
Possible License(s): Apache-2.0
  1. AJS.$(function ($) {
  2. var Room, Rooms, rooms, PageView, pageView, RoomListView;
  3. Room = Backbone.Model.extend({});
  4. Rooms = Backbone.Collection.extend({
  5. model:Room,
  6. initialize:function (rooms) {
  7. var checkedRooms = hcRoomIds.split(","),
  8. sortedRooms = _.sortBy(rooms, function (room) {
  9. return room.name.toLowerCase();
  10. });
  11. return _.map(sortedRooms, function (room) {
  12. if (_.indexOf(checkedRooms, String(room.room_id)) > -1) {
  13. room.checked = 'checked="checked"';
  14. } else {
  15. room.checked = "";
  16. }
  17. return room;
  18. });
  19. },
  20. toObject:function () {
  21. return this.models.map(function (room) {
  22. return room.attributes
  23. })
  24. }
  25. });
  26. rooms = new Rooms(_.filter(hcRooms.rooms, function (room) { return !room.is_archived; }));
  27. RoomListView = Backbone.View.extend({
  28. el:$('#room-list'),
  29. template:_.template($('#rooms-tmpl').html()),
  30. initialize:function () {
  31. this.render();
  32. },
  33. render:function () {
  34. this.$el.html(this.template({rooms:rooms.toObject()}));
  35. }
  36. });
  37. PageView = Backbone.View.extend({
  38. el:$('#hipchat-form'),
  39. initialize:function () {
  40. var roomListView = new RoomListView;
  41. }
  42. });
  43. pageView = new PageView;
  44. })