/static/scripts/model/tools.js
JavaScript | 127 lines | 74 code | 12 blank | 41 comment | 7 complexity | 994a50c6197581a3fa77aeb998e08fac MD5 | raw file
- /**
- * Model classes for Galaxy tools and tool panel.
- */
-
- var Tool = Backbone.Model.extend({
- // Default attributes.
- defaults: {
- name: null,
- description: null,
- id: null,
- params: []
- }
- });
- var ToolPanelSection = Backbone.Model.extend({
- defaults: {
- id: null,
- name: null,
- elems: []
- },
-
- });
- var ToolPanelLabel = Backbone.Model.extend({
- defaults: {
- id: null,
- name: null
- }
- });
- var ToolPanel = Backbone.Collection.extend({
- url: "/api/tools/panel",
- parse: function(response) {
- // Recursive function to parse tool panel elements.
- var parse_elt = function(elt_dict) {
- var type = elt_dict.type;
- if (type === 'tool') {
- return new Tool(elt_dict);
- }
- else if (type === 'section') {
- // Parse elements.
- var elems = _.map(elt_dict.elems, parse_elt);
- elt_dict.elems = elems;
- return new ToolPanelSection(elt_dict);
- }
- else if (type === 'label') {
- return new ToolPanelLabel(elt_dict);
- }
- };
-
- return _.map(response, parse_elt);
- }
- });
- /**
- * View classes for Galaxy tools.
- */
-
- var ToolView = Backbone.View.extend({
- tagName: 'a',
- template: Handlebars.compile( $("#tool_template").html() ),
- render: function() {
- this.$el = ( Handlebars.compile( $("#tool_template").html() )(this.model.toJSON()) );
- return this;
- }
- });
- var ToolPanelView = Backbone.View.extend({
- tagName: 'div',
- className: 'toolMenu',
-
- initialize: function() {
- _.bindAll(this, 'render');
- var self = this;
- this.collection.bind("reset", function() { self.render(); });
- },
-
- render: function() {
- var this_el = this.$el;
- this_el.append( $("<h1/>").text("Tool Menu") );
- this.collection.each(function(panel_elt) {
- if (panel_elt instanceof ToolPanelSection) {
- _.each(panel_elt.get("elems"), function(elt) {
- if (elt instanceof Tool) {
- var tool_view = new ToolView({model: elt});
- tool_view.render();
- this_el.append(tool_view.$el);
- }
- });
- }
- });
- return this;
- }
- });
- /*
- var buildToolboxView = function(toolboxModel, toolboxController) {
- var container = $("<div/>"),
- toolbox_elt = $("<div/>");
- container.append(toolbox_elt);
- var render = function() {
- // TODO: need template for toolbox.
- //photoEl.innerHTML = _.template('photoTemplate', {src: photoModel.getSrc()});
- };
- toolboxModel.addSubscriber(render);
- toolbox.addEventListener('click', function() {
- toolboxController.handleEvent('click', toolboxModel);
- });
- var show = function() {
- toolbox_elt.style.display = '';
- };
- var hide = function() {
- toolbox_elt.style.display = 'none';
- };
- return {
- showView: show,
- hideView: hide
- };
- };
- */