| 1 |
define(["dojo/_base/array"], function(arr){ |
| 2 |
var constraints = []; |
| 3 |
return { |
| 4 |
getSelectedChild: function(view, constraint){ |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
var type = typeof(constraint); |
| 16 |
var hash = (type == "string" || type == "number") ? constraint : constraint.__hash; |
| 17 |
return (view && view.selectedChildren && view.selectedChildren[hash]) ? |
| 18 |
view.selectedChildren[hash] : null; |
| 19 |
}, |
| 20 |
|
| 21 |
setSelectedChild: function(view, constraint, child){ |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
var type = typeof(constraint); |
| 32 |
var hash = (type == "string" || type == "number") ? constraint : constraint.__hash; |
| 33 |
view.selectedChildren[hash] = child; |
| 34 |
}, |
| 35 |
|
| 36 |
|
| 37 |
getAllSelectedChildren: function(view, selChildren){ |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
selChildren = selChildren || []; |
| 51 |
if(view && view.selectedChildren){ |
| 52 |
for(var hash in view.selectedChildren){ |
| 53 |
if(view.selectedChildren[hash]){ |
| 54 |
var subChild = view.selectedChildren[hash]; |
| 55 |
selChildren.push(subChild); |
| 56 |
this.getAllSelectedChildren(subChild, selChildren); |
| 57 |
} |
| 58 |
} |
| 59 |
} |
| 60 |
return selChildren; |
| 61 |
}, |
| 62 |
|
| 63 |
register: function(constraint){ |
| 64 |
|
| 65 |
var type = typeof(constraint); |
| 66 |
if(!constraint.__hash && type != "string" && type != "number"){ |
| 67 |
var match = null; |
| 68 |
arr.some(constraints, function(item){ |
| 69 |
var ok = true; |
| 70 |
for(var prop in item){ |
| 71 |
if(prop.charAt(0) !== "_"){ |
| 72 |
if(item[prop] != constraint[prop]){ |
| 73 |
ok = false; |
| 74 |
break; |
| 75 |
} |
| 76 |
} |
| 77 |
} |
| 78 |
if(ok == true){ |
| 79 |
match = item; |
| 80 |
} |
| 81 |
return ok; |
| 82 |
}); |
| 83 |
if(match){ |
| 84 |
constraint.__hash = match.__hash; |
| 85 |
}else{ |
| 86 |
|
| 87 |
var hash = ""; |
| 88 |
for(var prop in constraint){ |
| 89 |
if(prop.charAt(0) !== "_"){ |
| 90 |
hash += constraint[prop]; |
| 91 |
} |
| 92 |
} |
| 93 |
constraint.__hash = hash; |
| 94 |
constraints.push(constraint); |
| 95 |
} |
| 96 |
} |
| 97 |
} |
| 98 |
}; |
| 99 |
}); |