Files
galaxy/static/scripts/mvc/tools/tools-tree.js
T

135 lines
3.8 KiB
JavaScript

// dependencies
define([], function() {
// tool form tree
return Backbone.Model.extend({
// initialize
initialize: function(app) {
// link app
this.app = app;
},
// creates tree structure
refresh: function() {
// check if section is available
if (!this.app.section) {
return {};
}
// create dictionary
this.dict = {};
// create xml object
this.xml = $('<div/>');
// fill dictionary
this._iterate(this.app.section.$el, this.dict, this.xml);
},
// iterate
_iterate: function(parent, dict, xml) {
// get child nodes
var self = this;
var children = $(parent).children();
children.each(function() {
// get child element
var child = this;
// get id
var id = $(child).attr('id');
// create new branch
if ($(child).hasClass('form-row') || $(child).hasClass('tab-pane')) {
// create sub dictionary
dict[id] = {};
// add input element if it exists
var input = self.app.inputs_sequential[id];
if (input) {
dict[id] = {
input : input
}
}
// create xml element
var $el = $('<div id="' + id + '"/>');
// append xml
xml.append($el);
// fill sub dictionary
self._iterate(child, dict[id], $el);
} else {
self._iterate(child, dict, xml);
}
});
},
// find referenced elements
findReferences: function(identifier) {
// referenced elements
var referenced = [];
// link this
var self = this;
// iterate
function search (name, parent) {
// get child nodes
var children = $(parent).children();
// create sublist
var list = [];
// verify that hierachy level is referenced to identifier
children.each(function() {
// get child element
var child = this;
// get id
var id = $(child).attr('id');
// skip
if (id !== identifier) {
// get input element
var input = self.app.inputs_sequential[id];
if (input) {
// check for new reference definition
if (input.name == name) {
// stop iteration
return;
}
// check for referenced element
if (input.data_ref == name) {
list.push(id);
}
}
}
});
// merge temporary list with result
referenced = referenced.concat(list);
// continue iteration
children.each(function() {
search(identifier, this);
});
}
// get initial node
var node = this.xml.find('#' + identifier);
if (node.length > 0) {
// get parent input element
var input = self.app.inputs_sequential[identifier];
if (input) {
search(input.name, node.parent());
}
}
// return
return referenced;
}
});
});