| 1 |
define(["dojo/_base/declare","dojox/data/CssRuleStore"], |
| 2 |
function(declare, CssRuleStore) { |
| 3 |
|
| 4 |
return declare("dojox.data.CssClassStore", CssRuleStore, { |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
_labelAttribute: 'class', |
| 17 |
|
| 18 |
_idAttribute: 'class', |
| 19 |
_cName: "dojox.data.CssClassStore", |
| 20 |
|
| 21 |
getFeatures: function(){ |
| 22 |
|
| 23 |
|
| 24 |
return { |
| 25 |
"dojo.data.api.Read" : true, |
| 26 |
"dojo.data.api.Identity" : true |
| 27 |
}; |
| 28 |
}, |
| 29 |
|
| 30 |
getAttributes: function(item){ |
| 31 |
|
| 32 |
|
| 33 |
this._assertIsItem(item); |
| 34 |
return ['class', 'classSans']; |
| 35 |
}, |
| 36 |
|
| 37 |
getValue: function(item, attribute, defaultValue){ |
| 38 |
|
| 39 |
|
| 40 |
var values = this.getValues(item, attribute); |
| 41 |
if(values && values.length > 0){ |
| 42 |
return values[0]; |
| 43 |
} |
| 44 |
return defaultValue; |
| 45 |
}, |
| 46 |
|
| 47 |
getValues: function(item, attribute){ |
| 48 |
|
| 49 |
|
| 50 |
this._assertIsItem(item); |
| 51 |
this._assertIsAttribute(attribute); |
| 52 |
var value = []; |
| 53 |
if(attribute === "class"){ |
| 54 |
value = [item.className]; |
| 55 |
}else if(attribute === "classSans"){ |
| 56 |
value = [item.className.replace(/\./g,'')]; |
| 57 |
} |
| 58 |
return value; |
| 59 |
}, |
| 60 |
|
| 61 |
_handleRule: function(rule, styleSheet, href){ |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
var obj = {}; |
| 66 |
var s = rule['selectorText'].split(" "); |
| 67 |
for(var j=0; j<s.length; j++){ |
| 68 |
var tmp = s[j]; |
| 69 |
var first = tmp.indexOf('.'); |
| 70 |
if(tmp && tmp.length > 0 && first !== -1){ |
| 71 |
var last = tmp.indexOf(',') || tmp.indexOf('['); |
| 72 |
tmp = tmp.substring(first, ((last !== -1 && last > first)?last:tmp.length)); |
| 73 |
obj[tmp] = true; |
| 74 |
} |
| 75 |
} |
| 76 |
for(var key in obj){ |
| 77 |
if(!this._allItems[key]){ |
| 78 |
var item = {}; |
| 79 |
item.className = key; |
| 80 |
item[this._storeRef] = this; |
| 81 |
this._allItems[key] = item; |
| 82 |
} |
| 83 |
} |
| 84 |
}, |
| 85 |
|
| 86 |
_handleReturn: function(){ |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
var _inProgress = []; |
| 92 |
|
| 93 |
var items = {}; |
| 94 |
for(var i in this._allItems){ |
| 95 |
items[i] = this._allItems[i]; |
| 96 |
} |
| 97 |
var requestInfo; |
| 98 |
|
| 99 |
while(this._pending.length){ |
| 100 |
requestInfo = this._pending.pop(); |
| 101 |
requestInfo.request._items = items; |
| 102 |
_inProgress.push(requestInfo); |
| 103 |
} |
| 104 |
|
| 105 |
while(_inProgress.length){ |
| 106 |
requestInfo = _inProgress.pop(); |
| 107 |
if(requestInfo.fetch){ |
| 108 |
this._handleFetchReturn(requestInfo.request); |
| 109 |
}else{ |
| 110 |
this._handleFetchByIdentityReturn(requestInfo.request); |
| 111 |
} |
| 112 |
} |
| 113 |
}, |
| 114 |
|
| 115 |
_handleFetchByIdentityReturn: function(request){ |
| 116 |
|
| 117 |
|
| 118 |
var items = request._items; |
| 119 |
|
| 120 |
|
| 121 |
var item = items[request.identity]; |
| 122 |
if(!this.isItem(item)){ |
| 123 |
item = null; |
| 124 |
} |
| 125 |
if(request.onItem){ |
| 126 |
var scope = request.scope || dojo.global; |
| 127 |
request.onItem.call(scope, item); |
| 128 |
} |
| 129 |
}, |
| 130 |
|
| 131 |
|
| 132 |
getIdentity: function( item){ |
| 133 |
|
| 134 |
|
| 135 |
this._assertIsItem(item); |
| 136 |
return this.getValue(item, this._idAttribute); |
| 137 |
}, |
| 138 |
|
| 139 |
getIdentityAttributes: function( item){ |
| 140 |
|
| 141 |
|
| 142 |
this._assertIsItem(item); |
| 143 |
return [this._idAttribute]; |
| 144 |
}, |
| 145 |
|
| 146 |
fetchItemByIdentity: function( request){ |
| 147 |
|
| 148 |
|
| 149 |
request = request || {}; |
| 150 |
if(!request.store){ |
| 151 |
request.store = this; |
| 152 |
} |
| 153 |
if(this._pending && this._pending.length > 0){ |
| 154 |
this._pending.push({request: request}); |
| 155 |
}else{ |
| 156 |
this._pending = [{request: request}]; |
| 157 |
this._fetch(request); |
| 158 |
} |
| 159 |
return request; |
| 160 |
} |
| 161 |
}); |
| 162 |
|
| 163 |
}); |