1 | define(["dojo/_base/kernel", "dojo/query" , "dojo/_base/array", "dijit", "dojo/_base/json"], function(dojo, query, array, dijit, djson){ |
---|
2 | return function(/*Array of widgets*/widgets, /*Object*/ models){ |
---|
3 | array.forEach(widgets, function(item){ |
---|
4 | //TODO need to find a better way to get all bindable widgets |
---|
5 | var bindWidgets = query("div[dojoType^=\"dojox.mvc\"],div[data-dojo-type^=\"dojox.mvc\"]", item.domNode); |
---|
6 | //set ref for each dojox.mvc widgets. |
---|
7 | array.forEach(bindWidgets, function(widget){ |
---|
8 | //TODO need to find a better way to know which model the widget is bound to |
---|
9 | //currently, the ref attribute in dojox.mvc.Group cannot be empty, leave |
---|
10 | //explicit string with single quote in ref attribute. |
---|
11 | var ref = widget.getAttribute("ref"); |
---|
12 | |
---|
13 | if(ref === null){ |
---|
14 | var refProps = widget.getAttribute("data-dojo-props"); |
---|
15 | if(refProps){ |
---|
16 | try{ |
---|
17 | refProps = djson.fromJson("{" + refProps + "}"); |
---|
18 | }catch(e){ |
---|
19 | // give the user a pointer to their invalid parameters. FIXME: can we kill this in production? |
---|
20 | throw new Error(e.toString() + " in data-dojo-props='" + extra + "'"); |
---|
21 | } |
---|
22 | ref = refProps.ref.replace(/^\s*rel\s*:\s*/, ""); |
---|
23 | } |
---|
24 | } |
---|
25 | |
---|
26 | if (ref) { |
---|
27 | if(ref[0] === "'"){ |
---|
28 | ref = ref.substring(1, ref.length-1); |
---|
29 | } |
---|
30 | var model = dojo.getObject(ref, false, models); |
---|
31 | if (model){ |
---|
32 | dijit.byNode(widget).set("ref", model); |
---|
33 | } |
---|
34 | } |
---|
35 | }, this); |
---|
36 | }, this); |
---|
37 | |
---|
38 | } |
---|
39 | }); |
---|