-
Notifications
You must be signed in to change notification settings - Fork 199
/
modEncodeTrackMetadata.js
110 lines (95 loc) · 2.89 KB
/
modEncodeTrackMetadata.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
define( [
'dojo/_base/declare',
'dojo/data/util/simpleFetch'
],
function( declare, simpleFetch ) {
var M = declare( null,
/**
* @lends JBrowse.Model.modEncodeTrackMetadata.prototype
*/
{
/**
* Track metadata datasource that understands the format of the
* modencode.js track metadata JSON currently (May 2012) used at
* data.modencode.org.
* @constructor
* @param args.url {String} URL to fetch the metadata JSON from
*/
constructor: function( args ) {
this.url = args.url;
},
// dojo.data.api.Read support
getValue: function( i, attr, defaultValue ) {
var v = i[attr];
return typeof v == 'undefined' ? defaultValue : v;
},
getValues: function( i, attr ) {
var a = [ i[attr] ];
return typeof a[0] == 'undefined' ? [] : a;
},
getAttributes: function(item) {
return dojof.keys( item );
},
hasAttribute: function(item,attr) {
return item.hasOwnProperty(attr);
},
containsValue: function(item, attribute, value) {
return item[attribute] == value;
},
isItem: function(item) {
return typeof item == 'object' && typeof item.label == 'string';
},
isItemLoaded: function() {
return true;
},
loadItem: function( args ) {
},
// used by the dojo.data.util.simpleFetch mixin to implement fetch()
_fetchItems: function( keywordArgs, findCallback, errorCallback ) {
dojo.xhrGet({
url: this.url,
handleAs: 'json',
load: dojo.hitch(this, function( data ) {
var items = [];
dojo.forEach( data.items || [], function(i) {
if( dojo.isArray( i.Tracks ) )
dojo.forEach( i.Tracks, function(trackName) {
var item = dojo.clone(i);
item.key = item.label;
item.label = trackName;
delete item.Tracks;
items.push( item );
},this);
},this);
findCallback( items, keywordArgs );
}),
error: function(e) { errorCallback(e,keywordArgs); }
});
},
getFeatures: function() {
return {
'dojo.data.api.Read': true,
'dojo.data.api.Identity': true
};
},
close: function() {},
getLabel: function(i) {
return this.getValue(i,'key',undefined);
},
getLabelAttributes: function(i) {
return ['key'];
},
// dojo.data.api.Identity support
getIdentityAttributes: function() {
return ['label'];
},
getIdentity: function(i) {
return this.getValue(i, 'label', undefined);
},
fetchItemByIdentity: function(id) {
return this.identIndex[id];
}
});
dojo.extend( M, simpleFetch );
return M;
});