topic.js 942 B

12345678910111213141516171819202122232425262728293031
  1. var _ = require('underscore');
  2. var AppState = require('../app_state');
  3. var Backbone = require('backbone');
  4. var Topic = Backbone.Model.extend({
  5. idAttribute: 'name',
  6. constructor: function Topic() {
  7. Backbone.Model.prototype.constructor.apply(this, arguments);
  8. },
  9. url: function() {
  10. return AppState.apiPath('/topics/' + encodeURIComponent(this.get('name')));
  11. },
  12. parse: function(response) {
  13. response['nodes'] = _.map(response['nodes'] || [], function(node) {
  14. var nodeParts = node['node'].split(':');
  15. var port = nodeParts.pop();
  16. var address = nodeParts.join(':');
  17. var hostname = node['hostname'];
  18. node['show_broadcast_address'] = hostname.toLowerCase() !== address.toLowerCase();
  19. node['hostname_port'] = hostname + ':' + port;
  20. return node;
  21. });
  22. return response;
  23. }
  24. });
  25. module.exports = Topic;