realizeTree: function(treeSpec) { var deferred = Util.Promise.defer(); var self = this; if ((treeSpec.url !== null) && (typeof treeSpec.url == "string") && (treeSpec.url.indexOf("alias(") == 0) && (treeSpec.url[treeSpec.url.length - 1] == ")")) { var alias = treeSpec.url.substring(6, treeSpec.url.length - 1); if (typeof self.trees[alias] != 'undefined') { self.trees[treeSpec.name] = self.trees[alias]; if (treeSpec.receiveEvents) { // XXX: Potential bug here, depending on intent. The aliased tree is // the same tree! That means we might intend one to receive and the // other not to, but in reality they'll both be in lockstep. self.trees[treeSpec.name].toggleReceiveRelationEvents(true); } deferred.resolve(self.trees[alias]); } else { deferred.reject("Trying to alias undefined tree"); } } else if (typeof treeSpec.url == "string") { treeSpec.url = Util.Net.fixRelativeUrl(treeSpec.url, treeSpec.loadedFrom); self.factory.Tree(treeSpec, this).then( function(tree) { self.trees[treeSpec.name] = tree; // tree.registerInlineRelationSpecs(); deferred.resolve(tree); self.trigger('realized-tree', {name: treeSpec.name, kind: tree.kind, tree: tree}); }, function(reason) { deferred.reject(reason); } ).done(); } else { // it's a jquery node self.factory.Tree(treeSpec, this).then( function(tree) { self.trees[treeSpec.name] = tree; // tree.registerInlineRelationSpecs(); deferred.resolve(tree); self.trigger('realized-tree', {name: treeSpec.name, kind: tree.kind, tree: tree}); }, function(reason) { deferred.reject(reason); } ).done(); } return deferred; },
var promises = Util._.map(links, function(block) { var deferred = Util.Promise.defer(); if (block.type == 'link') { Util.Net.fetchString(block).then( function(content) { var url = block.url; self.parseAndAddSpec(content, block.format, url).then( function() { deferred.resolve(); }, function(reason) { Util.Log.Error("Could not parse and add spec", content, block); deferred.resolve(); } ).done(); }, function(reason) { Util.Log.Error("Could not fetch CTS link:", block); deferred.resolve(); }); } else if (block.type == 'block') { var url = window.location; self.parseAndAddSpec(block.content, block.format, url).then( function() { deferred.resolve(); }, function(reason) { Util.Log.Error("Could not parse and add spec", content, block); deferred.resolve(); } ).done(); } else { Util.Log.Error("Could not load CTS: did not understand block type", block.block, block); deferred.resolve(); } return deferred.promise; });