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

/static/scripts/model/tools.js

https://bitbucket.org/dannon/galaxy-central-bb
JavaScript | 127 lines | 74 code | 12 blank | 41 comment | 7 complexity | 994a50c6197581a3fa77aeb998e08fac MD5 | raw file
  1. /**
  2. * Model classes for Galaxy tools and tool panel.
  3. */
  4. var Tool = Backbone.Model.extend({
  5. // Default attributes.
  6. defaults: {
  7. name: null,
  8. description: null,
  9. id: null,
  10. params: []
  11. }
  12. });
  13. var ToolPanelSection = Backbone.Model.extend({
  14. defaults: {
  15. id: null,
  16. name: null,
  17. elems: []
  18. },
  19. });
  20. var ToolPanelLabel = Backbone.Model.extend({
  21. defaults: {
  22. id: null,
  23. name: null
  24. }
  25. });
  26. var ToolPanel = Backbone.Collection.extend({
  27. url: "/api/tools/panel",
  28. parse: function(response) {
  29. // Recursive function to parse tool panel elements.
  30. var parse_elt = function(elt_dict) {
  31. var type = elt_dict.type;
  32. if (type === 'tool') {
  33. return new Tool(elt_dict);
  34. }
  35. else if (type === 'section') {
  36. // Parse elements.
  37. var elems = _.map(elt_dict.elems, parse_elt);
  38. elt_dict.elems = elems;
  39. return new ToolPanelSection(elt_dict);
  40. }
  41. else if (type === 'label') {
  42. return new ToolPanelLabel(elt_dict);
  43. }
  44. };
  45. return _.map(response, parse_elt);
  46. }
  47. });
  48. /**
  49. * View classes for Galaxy tools.
  50. */
  51. var ToolView = Backbone.View.extend({
  52. tagName: 'a',
  53. template: Handlebars.compile( $("#tool_template").html() ),
  54. render: function() {
  55. this.$el = ( Handlebars.compile( $("#tool_template").html() )(this.model.toJSON()) );
  56. return this;
  57. }
  58. });
  59. var ToolPanelView = Backbone.View.extend({
  60. tagName: 'div',
  61. className: 'toolMenu',
  62. initialize: function() {
  63. _.bindAll(this, 'render');
  64. var self = this;
  65. this.collection.bind("reset", function() { self.render(); });
  66. },
  67. render: function() {
  68. var this_el = this.$el;
  69. this_el.append( $("<h1/>").text("Tool Menu") );
  70. this.collection.each(function(panel_elt) {
  71. if (panel_elt instanceof ToolPanelSection) {
  72. _.each(panel_elt.get("elems"), function(elt) {
  73. if (elt instanceof Tool) {
  74. var tool_view = new ToolView({model: elt});
  75. tool_view.render();
  76. this_el.append(tool_view.$el);
  77. }
  78. });
  79. }
  80. });
  81. return this;
  82. }
  83. });
  84. /*
  85. var buildToolboxView = function(toolboxModel, toolboxController) {
  86. var container = $("<div/>"),
  87. toolbox_elt = $("<div/>");
  88. container.append(toolbox_elt);
  89. var render = function() {
  90. // TODO: need template for toolbox.
  91. //photoEl.innerHTML = _.template('photoTemplate', {src: photoModel.getSrc()});
  92. };
  93. toolboxModel.addSubscriber(render);
  94. toolbox.addEventListener('click', function() {
  95. toolboxController.handleEvent('click', toolboxModel);
  96. });
  97. var show = function() {
  98. toolbox_elt.style.display = '';
  99. };
  100. var hide = function() {
  101. toolbox_elt.style.display = 'none';
  102. };
  103. return {
  104. showView: show,
  105. hideView: hide
  106. };
  107. };
  108. */