Skip to content
Browse files

updated model.js which is called from main and view to create any nec…

…essary models based upon the models sections in the config. model will load and call utils/mvcModel for any models which have a modelType of dojox/application/utils/mvcModel. During render View will set the loadedModels on its widgetInTemplate to make the loadedModel available during the parse of the view. I also updated tests/modelApp and added a tests/simpleModelApplication
  • Loading branch information...
1 parent aab1dd7 commit 061f1a3c02a023996e37c5ff8478c0778fbf638f @edchat edchat committed Apr 12, 2012
View
35 main.js
@@ -113,7 +113,7 @@ function(lang, declare, Deferred, on, ready, baseWindow, dom, Model, View, LoadC
on.emit(this.domNode, event, params);
},
- // load default view and startup the default view
+ // load default view and setupControllers and startup the default view
start: function(){
// create application template view
if(this.template){
@@ -126,13 +126,14 @@ function(lang, declare, Deferred, on, ready, baseWindow, dom, Model, View, LoadC
});
Deferred.when(this.view.start(), lang.hitch(this, function(){
this.domNode = this.view.domNode;
- this.startup();
+ this.setupControllers();
}));
}else{
- this.startup();
+ this.setupControllers();
}
},
- startup: function(){
+
+ setupControllers: function(){
// create application controller instance
new LoadController(this);
new TransitionController(this);
@@ -145,8 +146,30 @@ function(lang, declare, Deferred, on, ready, baseWindow, dom, Model, View, LoadC
//create application level data store
this.createDataStore(this.params);
- // create application level data model
- this.loadedModels = Model(this.params.models, this);
+ // create application level data model
+ var loadModelLoaderDeferred = new Deferred();
+ var createPromise;
+ try{
+ createPromise = Model(this.params.models, this);
+ }catch(ex){
+ loadModelLoaderDeferred.reject("load model error.");
+ return loadModelLoaderDeferred.promise;
+ }
+ if(createPromise.then){
+ Deferred.when(createPromise, lang.hitch(this, function(newModel){
+ this.loadedModels = newModel;
+ this.startup();
+ }),
+ function(){
+ loadModelLoaderDeferred.reject("load model error.")
+ });
+ }else{
+ this.loadedModels = createPromise;
+ this.startup();
+ }
+ },
+
+ startup: function(){
// load controllers in configuration file
var controllers = this.createControllers(this.params.controllers);
Deferred.when(controllers, lang.hitch(this, function(result){
View
109 model.js
@@ -1,28 +1,101 @@
-define(["dojo/_base/lang", "dojo/_base/Deferred", "dojox/mvc/_base"], function(dlang, deferred, mvc){
- return function(config, parent){
- //load models here. create dojox.newStatefulModel
- //using the configuration data for models
+define(["dojo/_base/lang", "dojo/_base/Deferred", "dojo/_base/config", "dojo/store/DataStore"],
+function(lang, Deferred, config, dataStore){
+ return function(/*Object*/ config, /*Object*/ parent){
+ // summary:
+ // model is called to create all of the models for the app, and all models for a view, it will
+ // create and call the appropriate model utility based upon the modelLoader set in the model in the config
+ // description:
+ // Called for each view or for the app. For each model in the config, it will
+ // create the model utility based upon the modelLoader and call it to create and load the model.
+ // config: Object
+ // The models section of the config for this view or for the app.
+ // parent: Object
+ // The parent of this view or the app itself, so that models from the parent will be
+ // available to the view.
+ // returns: loadedModels
+ // loadedModels is an object holding all of the available loaded models for this view.
+ //var config = params.config;
+ //var parent = params.parent;
+ this.defCount = 0;
var loadedModels = {};
+ var allModelsLoadedDeferred = new Deferred();
if(parent.loadedModels){
- dlang.mixin(loadedModels, parent.loadedModels);
+ lang.mixin(loadedModels, parent.loadedModels);
}
if(config){
+ var loadModelDeferred = loadedModels;
+ for(var test in config){
+ if(test.charAt(0) !== "_"){
+ this.defCount++;
+ }
+ }
+ if(this.defCount == 0){
+ return loadedModels;
+ }
for(var item in config){
if(item.charAt(0) !== "_"){
- var params = config[item].params ? config[item].params : {};
- var options = {
- "store": params.store.store,
- "query": params.store.query ? params.store.query : {}
- };
-
- //TODO improve performance of loading at here
- // do not wait for the models to be created.
- loadedModels[item] = deferred.when(mvc.newStatefulModel(options), function(model){
- return model;
- });
+ setupModel(config, item, parent, allModelsLoadedDeferred, loadedModels);
}
}
+ return allModelsLoadedDeferred;
+ }else{
+ return loadedModels;
}
- return loadedModels;
- }
+ return allModelsLoadedDeferred;
+ };
+
+ function setupModel(config, item, parent, allModelsLoadedDeferred, loadedModels){
+ // Here we need to create the modelLoader and call it passing in the item and the config[item].params
+ params = config[item].params ? config[item].params : {};
+ var def = new Deferred();
+
+ var modelLoader = config[item].modelLoader ? config[item].modelLoader : "dojox/app/utils/simpleModel";
+ require([modelLoader], // require the model type
+ function( requirement ){
+ def.resolve( requirement );
+ }
+ );
+ var loadModelDeferred = new Deferred();
+ return Deferred.when(def, lang.hitch(this, function(modelCtor){
+ var createModelPromise;
+ try{
+ createModelPromise = modelCtor(config, params, item);
+ }catch(ex){
+ loadModelDeferred.reject("load model error in model.", ex);
+ return loadModelDeferred.promise;
+ }
+ if(createModelPromise.then){
+ Deferred.when(createModelPromise, lang.hitch(this, function(newModel){
+ loadedModels[item] = newModel;
+ if(dojox.debugDataBinding){
+ console.log("in model, loadedModels for item="+item);
+ console.log(loadedModels);
+ }
+ this.defCount--;
+ if(this.defCount == 0){
+ allModelsLoadedDeferred.resolve(loadedModels);
+ }
+ loadModelDeferred.resolve(loadedModels);
+ return loadedModels;
+ }),
+ function(){
+ loadModelDeferred.reject("load model error in models.");
+ });
+ return loadModelDeferred;
+ }else{
+ loadedModels[item] = createModelPromise;
+ if(dojox.debugDataBinding){
+ console.log("in model else path, loadedModels for item="+item);
+ console.log(loadedModels);
+ }
+ this.defCount--;
+ if(this.defCount == 0){
+ allModelsLoadedDeferred.resolve(loadedModels);
+ }
+ loadModelDeferred.resolve(loadedModels);
+ return loadedModels;
+ }
+ }));
+ return loadModelDeferred;
+ }
});
View
22 tests/modelApp/config.json
@@ -12,11 +12,11 @@
"dojox/mobile/Button",
"dojox/mobile/RoundRect",
"dojox/mobile/Heading",
- "dojox/mvc/StatefulModel", //TODO remove the explicit dependency for stores.
- "dojo/store/Memory", //TODO remove the explicit dependency for stores.
+ "dojo/store/Memory",
"dojox/mvc/Group",
"dojox/mvc/Repeat",
- "dojox/mvc"
+ "dojox/mvc/Output",
+ "dojox/mobile/deviceTheme"
],
// Modules for the application. The are basically used as the second
// array of mixins in a dojo.declare(). Modify the top level behavior
@@ -51,9 +51,11 @@
//one to overide the class that will be used for the model. By default it is dojox/mvc/model
"models": {
"names": {
- "params":{
- "store": {"$ref":"#stores.namesStore"}
- }
+ "modelLoader": "dojox/app/utils/mvcModel",
+ "type": "dojox/mvc/EditStoreRefListController",
+ "params":{
+ "store": {"$ref":"#stores.namesStore"}
+ }
}
},
@@ -79,9 +81,11 @@
"repeat": {
"models": {
"repeatmodels": {
- "params":{
- "store": {"$ref":"#stores.repeatStore"}
- }
+ "modelLoader": "dojox/app/utils/mvcModel",
+ "type": "dojox/mvc/EditStoreRefListController",
+ "params":{
+ "store": {"$ref":"#stores.repeatStore"}
+ }
}
},
"template": "templates/repeat.html",
View
37 tests/modelApp/modelApp.js
@@ -41,24 +41,25 @@ dojo.registerModulePath("app",path);
require(["dojo", "dojox/app/main", "dojox/json/ref", "dojo/text!app/config.json", "dojo/_base/connect"], function(dojo, Application, jsonRef, config, connect){
//app = Application(dojox.json.ref.resolveJson(config), dojo.body());
dojo.global.modelApp = {};
- modelApp.names = [{
- "Serial" : "360324",
- "First" : "John",
- "Last" : "Doe",
- "Email" : "jdoe@us.ibm.com",
- "ShipTo" : {
- "Street" : "123 Valley Rd",
- "City" : "Katonah",
- "State" : "NY",
- "Zip" : "10536"
- },
- "BillTo" : {
- "Street" : "17 Skyline Dr",
- "City" : "Hawthorne",
- "State" : "NY",
- "Zip" : "10532"
- }
- }];
+ modelApp.names = {identifier: "id", items: [{
+ "id" : "1",
+ "Serial": "360324",
+ "First": "John",
+ "Last": "Doe",
+ "Email": "jdoe@us.ibm.com",
+ "ShipTo": {
+ "Street": "123 Valley Rd",
+ "City": "Katonah",
+ "State": "NY",
+ "Zip": "10536"
+ },
+ "BillTo": {
+ "Street": "17 Skyline Dr",
+ "City": "Hawthorne",
+ "State": "NY",
+ "Zip": "10532"
+ }
+ }]};
modelApp.repeatData = [
{
"First" : "Chad",
View
6 tests/modelApp/templates/main.html
@@ -2,13 +2,13 @@
<h1 dojoType="dojox.mobile.Heading">Mobile MVC Demo</h1>
<h2 dojoType="dojox.mobile.RoundRectCategory">Mobile MVC Views</h2>
<ul dojoType="dojox.mobile.RoundRectList">
- <li dojoType="dojox.mobile.ListItem" clickable="true" transitionOptions="{title:'simple',target:'simple'}">
+ <li dojoType="dojox.mobile.ListItem" clickable="true" transitionOptions="{title:'simple',target:'simple',url:'#simple'}">
Simple Data Binding
</li>
- <li dojoType="dojox.mobile.ListItem" clickable="true" transitionOptions="{title:'repeat',target:'repeat'}">
+ <li dojoType="dojox.mobile.ListItem" clickable="true" transitionOptions="{title:'repeat',target:'repeat',url:'#repeat'}">
Repeat Data Binding
</li>
- <li dojoType="dojox.mobile.ListItem" clickable="true" transitionOptions="{title:'generate',target:'generate'}">
+ <li dojoType="dojox.mobile.ListItem" clickable="true" transitionOptions="{title:'generate',target:'generate',url:'#generate'}">
Simple Form Generate
</li>
</ul>
View
86 tests/modelApp/templates/repeat.html
@@ -2,53 +2,61 @@
<h1 dojoType="dojox.mobile.Heading" back="Home">Repeat Data Binding Example</h1>
<form name="repeatTestForm" id="repeatTestForm">
<div class="field-title">Search Results</div>
-
- <div id="repeatWidget" class="fieldset" data-dojo-type="dojox.mvc.Repeat" data-dojo-props="exprchar: '#', ref: 'repeatmodels'" >
- <div dojoType="dojox.mvc.Group" ref="'rel:#{this.index}'">
- <div class="row">
+ <div id="repeatWidget" class="fieldset" data-dojo-type="dojox/mvc/Repeat"
+ data-dojo-props="exprchar: '#', children: this.loadedModels.repeatmodels.model" >
+ <div class="row">
<input dojoType="dojox.mobile.TextBox"
- id="nameInput#{this.index}" ref="'rel:First'" placeHolder="First Name"></input>
- <button type="button" data-dojo-type="dojox.mobile.Button" class="mblBlueButton" data-dojo-props="onClick: function(e){setDetailsContext('#{this.index}');}">
+ id="nameInput#{this.index}" data-dojo-props="value: dojox.mvc.at('rel:#{this.index}','First')" placeHolder="First Name"></input>
+ <button type="button" data-dojo-type="dojox/mobile/Button" class="mblBlueButton" data-dojo-props="onClick: function(e){setDetailsContext('#{this.index}');}">
Details
</button>
- <button type="button" data-dojo-type="dojox.mobile.Button" class="mblBlueButton" data-dojo-props="onClick: function(){insertResult('#{this.index}');}">
+ <button type="button" data-dojo-type="dojox/mobile/Button" class="mblBlueButton" data-dojo-props="onClick: function(){insertResult('#{this.index}');}">
+
</button>
- <button type="button" data-dojo-type="dojox.mobile.Button" class="mblBlueButton" data-dojo-props="onClick: function(){deleteResult('#{this.index}');}">
+ <button type="button" data-dojo-type="dojox/mobile/Button" class="mblBlueButton" data-dojo-props="onClick: function(){deleteResult('#{this.index}');}">
-
</button>
</div>
- </div>
</div>
-
<div class="spacer"></div>
- <div dojoType="dojox.mvc.Group" ref="'repeatmodels'">
- <div id="detailsBanner">Details for selected index:</div>
- <div class="fieldset" id="detailsGroup" dojoType="dojox.mvc.Group" ref="'rel:0'">
- <div class="field-row">
- <span>First Name</span>
- <input type=text id="firstInput" dojoType="dojox.mobile.TextBox"
- placeholder="First Name" ref="'rel:First'"></input>
- </div>
- <div class="field-row">
- <span>Last Name</span>
- <input type=text id="lastInput" dojoType="dojox.mobile.TextBox"
- placeholder="Last Name" ref="'rel:Last'"></input>
- </div>
- <div class="field-row">
- <span>Email</span>
- <input type=text id="emailInput2" dojoType="dojox.mobile.TextBox"
- placeholder="Email" ref="'rel:Email'"></input>
- </div>
- <div class="field-row">
- <span>Telephone</span>
- <input type=text id="telInput" dojoType="dojox.mobile.TextBox"
- placeholder="Telephone" ref="'rel:Tel'"></input>
- </div>
- </div>
- </div>
- <div class="spacer"></div>
- <button id="save" type="button" dojoType="dojox.mobile.Button" class="mblBlueButton" data-dojo-props="onClick: function(){console.log(repeatmodel[selectedIndex].toPlainObject());repeatmodel[selectedIndex].commit();}">Save</button>
- <button id="reset2" type="button" dojoType="dojox.mobile.Button" class="mblBlueButton" data-dojo-props="onClick: function(){repeatmodel.reset();}">Reset</button>
-
+ <div data-dojo-type="dojox/mvc/Group"
+ data-dojo-props="target: dojox.mvc.at(this.loadedModels.repeatmodels, 'cursor')">
+ <div class="field-title">
+ <div style="display: inline-block;" id="detailsBanner">Details for selected index:</div>
+ <span class="cell" id="indexOutput"
+ data-dojo-type="dojox/mvc/Output"
+ data-dojo-props="value: dojox.mvc.at(this.loadedModels.repeatmodels, 'cursorIndex')"></span>
+ </div>
+ <table id="table" cellspacing="10" style="width: 100%">
+ <tr>
+ <td style="width: 100px;" class="layout">First Name</td>
+ <td class="layout">
+ <input id="firstInput" data-dojo-type="dojox.mobile.TextBox"
+ data-dojo-props="value: dojox.mvc.at('rel:', 'First'), placeholder:'First Name'">
+ </td>
+ </tr>
+ <tr>
+ <td style="width: 100px;" class="layout">Last Name</td>
+ <td class="layout">
+ <input id="lastInput" data-dojo-type="dojox.mobile.TextBox"
+
+ data-dojo-props="placeholder:'Last Name', value: dojox.mvc.at('rel:', 'Last')">
+ </td>
+ </tr>
+ <tr>
+ <td style="width: 100px;" class="layout">Email</td>
+ <td class="layout">
+ <input id="emailInput2" data-dojo-type="dojox.mobile.TextBox"
+ data-dojo-props="value: dojox.mvc.at('rel:', 'Email'), placeholder:'Email'">
+ </td>
+ </tr>
+ <tr>
+ <td style="width: 100px;" class="layout">Telephone</td>
+ <td class="layout">
+ <input id="telInput" data-dojo-type="dojox.mobile.TextBox"
+ data-dojo-props="value: dojox.mvc.at('rel:', 'Tel'), placeholder:'Telephone'">
+ </td>
+ </tr>
+ </table>
+ </div>
</div>
View
120 tests/modelApp/templates/simple.html
@@ -1,51 +1,77 @@
<div id="settings" class="view mblView">
- <h1 dojoType="dojox.mobile.Heading" back="Home">Data Binding Example</h1>
+ <h1 data-dojo-type="dojox.mobile.Heading" data-dojo-props='back:"Home"'>Data Binding Example</h1>
<form name="testForm" id="testForm">
- <div class="field-title">Ship to - Bill to Address</div>
- <div id="infoGroup" class="fieldset" dojoType="dojox.mvc.Group" ref="'names.0'">
- <div class="field-row">
- <span>Order #</span>
- <input type=text id="lastnameInput" dojoType="dojox.mobile.TextBox"
- placeholder="Order #" ref="'rel:Serial'"></input>
- </div>
- <div class="field-row">
- <span>Last</span>
- <input type=text id="serialInput" dojoType="dojox.mobile.TextBox"
- placeholder="Last" ref="'rel:Last'"></input>
- </div>
- <div class="field-row">
- <span>Email</span>
- <input type=text id="emailInput1" dojoType="dojox.mobile.TextBox"
- placeholder="Last" ref="'rel:Email'"></input>
- </div>
- </div>
- <div class="spacer"></div>
- <button id="shipto" type="button" dojoType="dojox.mobile.Button" class="mblBlueButton">Ship To</button>
- <button id="billto" type="button" dojoType="dojox.mobile.Button" class="mblBlueButton">Bill To</button>
- <br/>
- <div class="fieldset" id="addrGroup" dojoType="dojox.mvc.Group" ref="'names.0.ShipTo'">
- <div class="field-row">
- <span>Street</span>
- <input type=text id="streetInput" dojoType="dojox.mobile.TextBox"
- placeholder="Street" ref="'rel:Street'"></input>
- </div>
- <div class="field-row">
- <span>City</span>
- <input type=text id="cityInput" dojoType="dojox.mobile.TextBox"
- placeholder="City" ref="'rel:City'"></input>
- </div>
- <div class="field-row">
- <span>State</span>
- <input type=text id="stateInput" dojoType="dojox.mobile.TextBox"
- placeholder="State" ref="'rel:State'"></input>
- </div>
- <div class="field-row">
- <span>ZIP Code</span>
- <input type=text id="zipInput" dojoType="dojox.mobile.TextBox"
- placeholder="ZIP Code" ref="'rel:Zip'"></input>
- </div>
- </div>
- <div class="spacer"></div>
- <button id="reset1" type="button" dojoType="dojox.mobile.Button" class="mblBlueButton" onclick="dijit.byId('infoGroup').get('ref').reset();">Reset</button>
+ <div class="field-title">Ship to - Bill to Address</div>
+ <div class="fieldset" data-dojo-type="dojox/mvc/Group" data-dojo-props="target: at(this.loadedModels.names, 'model')">
+ <div data-dojo-type="dojox/mvc/Group" data-dojo-props="target: at('rel:', 0)">
+ <table id="table" cellspacing="10" style="width: 100%">
+ <tr>
+ <td style="width: 100px;" class="layout">First</td>
+ <td class="layout">
+ <input id="firstInput1" data-dojo-type="dojox.mobile.TextBox"
+ data-dojo-props="value: dojox.mvc.at('rel:', 'First'), placeholder:'First'">
+ </td>
+ </tr>
+ <tr>
+ <td style="width: 100px;" class="layout">Last Name</td>
+ <td class="layout">
+ <input id="lastInput1" data-dojo-type="dojox.mobile.TextBox"
+
+ data-dojo-props="placeholder:'Last Name', value: dojox.mvc.at('rel:', 'Last')">
+ </td>
+ </tr>
+ <tr>
+ <td style="width: 100px;" class="layout">Email</td>
+ <td class="layout">
+ <input id="emailInput1" data-dojo-type="dojox.mobile.TextBox"
+ data-dojo-props="value: dojox.mvc.at('rel:', 'Email'), placeholder:'Email'">
+ </td>
+ </tr>
+ </table>
+
+
+ <div class="spacer"></div>
+ <button id="shipto" type="button" data-dojo-type="dojox.mobile.Button" class="mblBlueButton">Ship To</button>
+ <button id="billto" type="button" data-dojo-type="dojox.mobile.Button" class="mblBlueButton">Bill To</button>
+ <br/>
+ <div class="fieldset" id="addrGroup" data-dojo-type="dojox/mvc/Group"
+ data-dojo-props="target: at('rel:','ShipTo')">
+ <table id="table" cellspacing="10" style="width: 100%">
+ <tr>
+ <td style="width: 100px;" class="layout">Street</td>
+ <td class="layout">
+ <input id="streetInput" data-dojo-type="dojox.mobile.TextBox"
+ data-dojo-props="value: dojox.mvc.at('rel:', 'Street'), placeholder:'Street'">
+ </td>
+ </tr>
+ <tr>
+ <td style="width: 100px;" class="layout">City</td>
+ <td class="layout">
+ <input id="cityInput" data-dojo-type="dojox.mobile.TextBox"
+
+ data-dojo-props="placeholder:'City', value: dojox.mvc.at('rel:', 'City')">
+ </td>
+ </tr>
+ <tr>
+ <td style="width: 100px;" class="layout">State</td>
+ <td class="layout">
+ <input id="StateInput" data-dojo-type="dojox.mobile.TextBox"
+ data-dojo-props="value: dojox.mvc.at('rel:', 'State'), placeholder:'State'">
+ </td>
+ </tr>
+ <tr>
+ <td style="width: 100px;" class="layout">State</td>
+ <td class="layout">
+ <input id="ZipInput" data-dojo-type="dojox.mobile.TextBox"
+ data-dojo-props="value: dojox.mvc.at('rel:', 'Zip'), placeholder:'Zip Code'">
+ </td>
+ </tr>
+ </table>
+ </div>
+ </div>
+ </div>
+
+ <div class="spacer"></div>
+ <button id="reset1" type="button" data-dojo-type="dojox.mobile.Button" class="mblBlueButton">Reset</button>
</form>
</div>
View
36 tests/modelApp/views/repeat.js
@@ -1,38 +1,30 @@
define(["dojo/dom", "dojo/_base/connect", "dijit/registry", "dojox/mvc/at", "dojox/mvc/Repeat", "dojox/mvc/getStateful", "dojox/mvc/Output"],
function(dom, connect, registry, at, Repeat, getStateful, Output){
+ window.at = at;
+ dojox.debugDataBinding = true;
+
selectedIndex = 0;
repeatmodel = null;
deleteResult = function(index){
- repeatmodel.remove(index);
- repeatmodel.commit();
+ var nextIndex = currentModel.get("cursorIndex");
+ if(nextIndex >= index){
+ nextIndex = nextIndex-1;
+ }
+ repeatmodel.model.splice(index, 1);
+ repeatmodel.set("cursorIndex", nextIndex);
};
setDetailsContext = function(index){
- var widget = dijit.byId("detailsGroup");
- widget.set("ref", index);
- selectedIndex = index;
+ repeatmodel.set("cursorIndex", index);
};
// used in the Repeat Data binding demo
insertResult = function(index){
- index = parseInt(index) + 1;
- if(index >= repeatmodel.length || repeatmodel[index].First.value !== ""){
- var insert = dojox.mvc.newStatefulModel({
- "data": {
- "First": "",
- "Last": "",
- "Location": "CA",
- "Office": "",
- "Email": "",
- "Tel": "",
- "Fax": ""
- }
- });
- repeatmodel.add(index, insert);
- repeatmodel.commit();
- setDetailsContext(index);
- }
+ var data = {id:Math.random(), "First": "", "Last": "", "Location": "CA", "Office": "", "Email": "",
+ "Tel": "", "Fax": ""};
+ repeatmodel.model.push(new getStateful(data));
+ setDetailsContext(repeatmodel.model.length-1);
};
return {
View
33 tests/modelApp/views/simple.js
@@ -1,31 +1,40 @@
-define(["dojo/dom", "dojo/_base/connect", "dijit/registry", "dojox/mvc/at", "dojox/mvc/Group"],
-function(dom, connect, registry, at, Group){
+define(["dojo/dom", "dojo/_base/connect", "dijit/registry", "dojox/mvc/at", "dojox/mvc/Group"],
+ function(dom, connect, registry, at, Group){
+ window.at = at;
+ dojox.debugDataBinding = true;
return {
init: function(){
+ // could have used app.children.modelApp_simple.loadedModels.names
+ // instead of app.currentLoadedModels.names
+ //var currentModel = app.children.modelApp_simple.loadedModels.names;
var currentModel = this.loadedModels.names;
- function setRef(id, model, attr){
- require(["dijit/registry", "dojox/mvc/at"], function(registry, at){
- var widget = registry.byId(id);
- widget.set("target", model[attr]);
- console.log("setRef done. " + attr);
- });
+ function setRef(id, attr) {
+ require([
+ "dijit/registry",
+ "dojox/mvc/at"
+ ], function(registry, at){
+ var widget = registry.byId(id);
+ widget.set("target", at("rel:", attr));
+ console.log("setRef done. "+attr);
+ });
+
};
connect.connect(dom.byId('shipto'), "click", function(){
- setRef('addrGroup', currentModel[0], 'ShipTo');
+ setRef('addrGroup', 'ShipTo');
});
connect.connect(dom.byId('billto'), "click", function(){
- setRef('addrGroup', currentModel[0], 'BillTo');
+ setRef('addrGroup', 'BillTo');
});
connect.connect(dom.byId('reset1'), "click", function(){
console.log("reset called. ");
currentModel.reset();
console.log("reset done. ");
});
-
- console.log("simple init done.");
+
+ console.log("simple view init ok");
}
}
});
View
73 tests/simpleModelApplication/config.json
@@ -0,0 +1,73 @@
+{
+ "id": "simpleModelApplication",
+ "name": "Simple Model App",
+ "description": "A simple modelApp",
+ "splash": "splash",
+
+ "dependencies": [
+ "dojox/mobile/_base",
+ "dojox/mobile/TabBar",
+ "dojox/mobile/RoundRect",
+ "dojox/mobile/TabBarButton",
+ "dojox/mobile/Button",
+ "dojox/mobile/RoundRect",
+ "dojox/mobile/Heading",
+ "dojo/store/Memory",
+ "dijit/form/Textbox",
+ "dojo/store/Memory",
+ "dojox/mobile/deviceTheme"
+ ],
+ // Modules for the application. The are basically used as the second
+ // array of mixins in a dojo.declare(). Modify the top level behavior
+ // of the application, how it processes the config or any other life cycle
+ // by creating and including one or more of these
+ "modules": [
+ "dojox/app/module/env",
+ "dojox/app/module/lifecycle"
+ ],
+
+ "controllers": [
+ "dojox/app/controllers/History"
+ ],
+
+ //stores we are using
+ "stores": {
+ "namesStore":{
+ "type": "dojo.store.Memory",
+ "params": {
+ "data": "modelApp.names"
+ }
+ }
+ },
+
+ //models and instantiation parameters for the models. Including 'type' as a property allows
+ //one to overide the class that will be used for the model. By default it is dojox/mvc/model
+ "models": {
+ "names": {
+ "modelLoader": "dojox/app/utils/simpleModel",
+ "params":{
+ "store": {"$ref":"#stores.namesStore"}
+ }
+ }
+ },
+
+ //the name of the scene to load when the app is initialized.
+ "defaultView": "home",
+
+ "defaultTransition": "slide",
+ //scenes are groups of views and models loaded at once
+ "views": {
+
+ "home": {
+ "definition" : "none",
+ "dependencies":["dojox/mobile/ListItem","dojox/mobile/RoundRectList","dojox/mobile/RoundRectCategory","dojox/mobile/Heading"],
+ "template": "templates/main.html"
+ },
+
+ "simple":{
+ "definition" : "views/simple.js",
+ "template": "templates/simple.html",
+ "dependencies":["dojox/mobile/TextBox"]
+ }
+ }
+}
View
60 tests/simpleModelApplication/index.html
@@ -0,0 +1,60 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+ <head>
+ <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no"/>
+ <meta name="apple-mobile-web-app-capable" content="yes" />
+ <title>Model App Test</title>
+ <link href="../../../mobile/themes/iphone/base.css" rel="stylesheet"></link>
+ <style>
+ html,body {
+ width: 100%;
+ height: 100%;
+ background: #eee;
+ font-family: arial;
+ color: #333;
+ overflow: hidden;
+ margin: 0px;
+ padding: 0px;
+ visibility: visible;
+ }
+
+ #splash {
+ width: 90%;
+ height: 90%;
+ margin: auto;
+ overflow: hidden;
+ border: 2px solid green;
+ font-color: #333;
+ text-align: center;
+ }
+
+ </style>
+ <script type="text/javascript">
+ dojoConfig = {
+ parseOnLoad: false,
+ mblHideAddressBar: false,
+ mblAndroidWorkaround: false,
+ mblAlwaysHideAddressBar: false,
+ traceSet:{
+ "loader-inject":1,
+ "loader-define":1,
+ "loader-runFactory":1,
+ "loader-execModule":1,
+ "loader-execModule-out":1,
+ "loader-defineModule":1
+ },
+ async:1
+ }
+ </script>
+ <script type="text/javascript" src="../../../../dojo/dojo.js"></script>
+
+ <script>
+ console.log("post dojo");
+ // the actual launcher
+ require(["./modelApp.js"], function(){});
+ </script>
+
+ </head>
+ <body>
+ </body>
+</html>
View
99 tests/simpleModelApplication/modelApp.js
@@ -0,0 +1,99 @@
+require(["dojo/_base/kernel", "dojo/_base/lang", "dojo/_base/loader"], function(dojo, lang){
+var path = window.location.pathname;
+if (path.charAt(path.length)!="/"){
+ path = path.split("/");
+ path.pop();
+ path=path.join("/");
+}
+dojo.registerModulePath("app",path);
+
+ // search script tag and create new tag in head to fix IE and Firefox not load script.
+ // In IE, set script text to innerHTML with <script type="text/javascript" defer> can load script.
+ // In Firefox and Chrome, not support defer in innerHTML, but support defer in static page.
+ // Use string.match(/<script.*?>.*?<\/script>/, templateString) cannot get matches because templateString contains "\n".
+ // So use string.indexOf to check "<script" and "</script>", then replace "<script*" to empty.
+ var addDynamicScript = function(node){
+ if (!node.templateString) {
+ return;
+ }
+ var tempStr = node.templateString;
+ var scriptText = "";
+ var startIndex = tempStr.indexOf("<script");
+ var endIndex = tempStr.indexOf("<\/script>");
+
+ while ((startIndex > -1) && (endIndex > -1) && (endIndex > startIndex)) {
+ var str = tempStr.substring(startIndex, endIndex);
+ str = str.replace(/<script.*?>.*?/, "");
+ scriptText += str;
+
+ startIndex = tempStr.indexOf("<script", endIndex);
+ endIndex = tempStr.indexOf("<\/script>", endIndex);
+ }
+
+ if (scriptText) {
+ var header = document.getElementsByTagName('head')[0];
+ var scriptTag = document.createElement('script');
+ scriptTag.text = scriptText;
+ header.appendChild(scriptTag);
+ }
+ };
+
+ require(["dojo", "dojox/app/main", "dojox/json/ref", "dojo/text!app/config.json", "dojo/_base/connect"], function(dojo, Application, jsonRef, config, connect){
+ //app = Application(dojox.json.ref.resolveJson(config), dojo.body());
+ dojo.global.modelApp = {};
+ modelApp.names = {identifier: "id", items: [{
+ "id" : "1",
+ "Serial": "360324",
+ "First": "John",
+ "Last": "Doe",
+ "Email": "jdoe@us.ibm.com",
+ "ShipTo": {
+ "Street": "123 Valley Rd",
+ "City": "Katonah",
+ "State": "NY",
+ "Zip": "10536"
+ },
+ "BillTo": {
+ "Street": "17 Skyline Dr",
+ "City": "Hawthorne",
+ "State": "NY",
+ "Zip": "10532"
+ }
+ }]};
+ modelApp.repeatData = [
+ {
+ "First" : "Chad",
+ "Last" : "Chapman",
+ "Location": "CA",
+ "Office" : "1278",
+ "Email" : "c.c@test.com",
+ "Tel" : "408-764-8237",
+ "Fax" : "408-764-8228"
+ },
+ {
+ "First" : "Irene",
+ "Last" : "Ira",
+ "Location": "NJ",
+ "Office" : "F09",
+ "Email" : "i.i@test.com",
+ "Tel" : "514-764-6532",
+ "Fax" : "514-764-7300"
+ },
+ {
+ "First" : "John",
+ "Last" : "Jacklin",
+ "Location": "CA",
+ "Office" : "6701",
+ "Email" : "j.j@test.com",
+ "Tel" : "408-764-1234",
+ "Fax" : "408-764-4321"
+ }
+ ];
+ app = Application(jsonRef.fromJson(config));
+
+ connect.subscribe("/app/loadchild", lang.hitch(app, function(node){
+ console.log(node);
+ addDynamicScript(node);
+ }));
+});
+});
View
9 tests/simpleModelApplication/templates/main.html
@@ -0,0 +1,9 @@
+<div class="view mblView">
+ <h1 dojoType="dojox.mobile.Heading">Simple Model Demo</h1>
+ <h2 dojoType="dojox.mobile.RoundRectCategory">Simple Model Views</h2>
+ <ul dojoType="dojox.mobile.RoundRectList">
+ <li dojoType="dojox.mobile.ListItem" clickable="true" transitionOptions="{title:'simple',target:'simple',url:'#simple'}">
+ Simple Data Binding
+ </li>
+ </ul>
+</div>
View
102 tests/simpleModelApplication/templates/simple.html
@@ -0,0 +1,102 @@
+<div id="settings" class="view mblView">
+ <h1 data-dojo-type="dojox.mobile.Heading" data-dojo-props='back:"Home"'>Simple Model Binding Example</h1>
+ <form name="testForm" id="testForm">
+ <div class="field-title">Ship to - Bill to Address</div>
+ <table id="table" cellspacing="10" style="width: 100%">
+ <tr>
+ <td style="width: 100px;" class="layout">First</td>
+ <td class="layout">
+ <input id="firstInput1" data-dojo-type="dojox.mobile.TextBox"
+ data-dojo-props="placeholder:'First'">
+ </td>
+ </tr>
+ <tr>
+ <td style="width: 100px;" class="layout">Last Name</td>
+ <td class="layout">
+ <input id="lastInput1" data-dojo-type="dojox.mobile.TextBox"
+ data-dojo-props="placeholder:'Last Name'">
+ </td>
+ </tr>
+ <tr>
+ <td style="width: 100px;" class="layout">Last Name</td>
+ <td class="layout">
+ <input id="emailInput1" data-dojo-type="dojox.mobile.TextBox"
+ data-dojo-props="placeholder:'Email'">
+ </td>
+ </tr>
+ </table>
+
+
+ <div class="spacer"></div>
+ <button id="shipto" type="button" data-dojo-type="dojox.mobile.Button" class="mblBlueButton">Ship To</button>
+ <button id="billto" type="button" data-dojo-type="dojox.mobile.Button" class="mblBlueButton">Bill To</button>
+ <br/>
+ <div class="fieldset" id="shiptodiv" >Ship To:
+ <table id="table" cellspacing="10" style="width: 100%">
+ <tr>
+ <td style="width: 100px;" class="layout">Street</td>
+ <td class="layout">
+ <input id="shiptostreetInput1" data-dojo-type="dojox.mobile.TextBox"
+ data-dojo-props="placeholder:'Street'">
+ </td>
+ </tr>
+ <tr>
+ <td style="width: 100px;" class="layout">City</td>
+ <td class="layout">
+ <input id="shiptocityInput1" data-dojo-type="dojox.mobile.TextBox"
+ data-dojo-props="placeholder:'City'">
+ </td>
+ </tr>
+ <tr>
+ <td style="width: 100px;" class="layout">State</td>
+ <td class="layout">
+ <input id="shiptostateInput1" data-dojo-type="dojox.mobile.TextBox"
+ data-dojo-props="placeholder:'State'">
+ </td>
+ </tr>
+ <tr>
+ <td style="width: 100px;" class="layout">Zip Code</td>
+ <td class="layout">
+ <input id="shiptozipInput1" data-dojo-type="dojox.mobile.TextBox"
+ data-dojo-props="placeholder:'Zip Code'">
+ </td>
+ </tr>
+ </table>
+ </div>
+ <div class="fieldset" id="billtodiv" >Bill To:
+ <table id="table" cellspacing="10" style="width: 100%">
+ <tr>
+ <td style="width: 100px;" class="layout">Street</td>
+ <td class="layout">
+ <input id="billtostreetInput1" data-dojo-type="dojox.mobile.TextBox"
+ data-dojo-props="placeholder:'Street'">
+ </td>
+ </tr>
+ <tr>
+ <td style="width: 100px;" class="layout">City</td>
+ <td class="layout">
+ <input id="billtocityInput1" data-dojo-type="dojox.mobile.TextBox"
+ data-dojo-props="placeholder:'City'">
+ </td>
+ </tr>
+ <tr>
+ <td style="width: 100px;" class="layout">State</td>
+ <td class="layout">
+ <input id="billtostateInput1" data-dojo-type="dojox.mobile.TextBox"
+ data-dojo-props="placeholder:'State'">
+ </td>
+ </tr>
+ <tr>
+ <td style="width: 100px;" class="layout">Zip Code</td>
+ <td class="layout">
+ <input id="billtozipInput1" data-dojo-type="dojox.mobile.TextBox"
+ data-dojo-props="placeholder:'Zip Code'">
+ </td>
+ </tr>
+ </table>
+ </div>
+ <div class="spacer"></div>
+ <button id="save1" type="button" data-dojo-type="dojox.mobile.Button" class="mblBlueButton">Save current model</button>
+ <button id="reset1" type="button" data-dojo-type="dojox.mobile.Button" class="mblBlueButton">Reset to last saved</button>
+ </form>
+</div>
View
62 tests/simpleModelApplication/views/simple.js
@@ -0,0 +1,62 @@
+define(["dojo/_base/lang", "dojo/dom", "dojo/_base/connect", "dijit/registry"],
+ function(lang, dom, connect, registry){
+ return {
+ init: function(){
+
+ connect.connect(dom.byId('reset1'), "click", lang.hitch(this, function(){
+ console.log("reset called. ");
+ this.setFromModel();
+ console.log("reset done. ");
+ }));
+
+ connect.connect(dom.byId('save1'), "click", lang.hitch(this, function(){
+ this.saveToModel();
+ }));
+
+ connect.connect(dom.byId('shipto'), "click", lang.hitch(this, function(){
+ console.log("shipTo called. ");
+ dom.byId("billtodiv").style.display = "none";
+ dom.byId("shiptodiv").style.display = "";
+ //this.saveToModel();
+ }));
+
+ connect.connect(dom.byId('billto'), "click", lang.hitch(this, function(){
+ console.log("billTo called. ");
+ dom.byId("billtodiv").style.display = "";
+ dom.byId("shiptodiv").style.display = "none";
+ //this.saveToModel();
+ }));
+
+ dom.byId("billtodiv").style.display = "none";
+ this.setFromModel();
+ },
+
+ setFromModel: function(){
+ registry.byId("firstInput1").set('value', this.loadedModels.names[0].First);
+ registry.byId("lastInput1").set('value', this.loadedModels.names[0].Last);
+ registry.byId("emailInput1").set('value', this.loadedModels.names[0].Email);
+ registry.byId("shiptostreetInput1").set('value', this.loadedModels.names[0].ShipTo.Street);
+ registry.byId("shiptocityInput1").set('value', this.loadedModels.names[0].ShipTo.City);
+ registry.byId("shiptostateInput1").set('value', this.loadedModels.names[0].ShipTo.State);
+ registry.byId("shiptozipInput1").set('value', this.loadedModels.names[0].ShipTo.Zip);
+ registry.byId("billtostreetInput1").set('value', this.loadedModels.names[0].BillTo.Street);
+ registry.byId("billtocityInput1").set('value', this.loadedModels.names[0].BillTo.City);
+ registry.byId("billtostateInput1").set('value', this.loadedModels.names[0].BillTo.State);
+ registry.byId("billtozipInput1").set('value', this.loadedModels.names[0].BillTo.Zip);
+ },
+
+ saveToModel: function(){
+ this.loadedModels.names[0].First = registry.byId("firstInput1").get('value');
+ this.loadedModels.names[0].Last = registry.byId("lastInput1").get('value');
+ this.loadedModels.names[0].Email = registry.byId("emailInput1").get('value');
+ this.loadedModels.names[0].ShipTo.Street = registry.byId("shiptostreetInput1").get('value');
+ this.loadedModels.names[0].ShipTo.City = registry.byId("shiptocityInput1").get('value');
+ this.loadedModels.names[0].ShipTo.State = registry.byId("shiptostateInput1").get('value');
+ this.loadedModels.names[0].ShipTo.Zip = registry.byId("shiptozipInput1").get('value');
+ this.loadedModels.names[0].BillTo.Street = registry.byId("billtostreetInput1").get('value');
+ this.loadedModels.names[0].BillTo.City = registry.byId("billtocityInput1").get('value');
+ this.loadedModels.names[0].BillTo.State = registry.byId("billtostateInput1").get('value');
+ this.loadedModels.names[0].BillTo.Zip = registry.byId("billtozipInput1").get('value');
+ }
+ }
+});
View
79 utils/mvcModel.js
@@ -0,0 +1,79 @@
+define(["dojo/_base/lang", "dojo/_base/Deferred", "dojo/_base/config",
+ "dojo/store/DataStore"],
+function(lang, Deferred, config, dataStore){
+ return function(/*Object*/config, /*Object*/params, /*String*/item){
+ // summary:
+ // mvcModel is called for each mvc model, to create the mvc model based upon the type and params.
+ // It will also load models and return the either the loadedModels or a promise.
+ // description:
+ // Called for each model with a modelLoader of "dojox/app/utils/mvcModel", it will
+ // create the model based upon the type and the params set for the model in the config.
+ // config: Object
+ // The models section of the config for this view or for the app.
+ // params: Object
+ // The params set into the config for this model.
+ // item: String
+ // The String with the name of this model
+ // returns: model
+ // The model, of the type specified in the config for this model.
+ var loadedModels = {};
+ var loadMvcModelDeferred = new Deferred();
+
+ var options;
+ if(params.store.params.data){
+ options = {
+ "store": params.store.store,
+ "query": params.store.query ? params.store.query: {}
+ };
+ }else if(params.store.params.url){
+ options = {
+ "store": new dataStore({
+ store: params.store.store
+ }),
+ "query": params.store.query ? params.store.query: {}
+ };
+ }
+ var modelCtor;
+ var ctrl = null;
+ var newModel = null;
+ var type = config[item].type ? config[item].type : "dojox/mvc/EditStoreRefListController";
+ // need to load the class to use for the model
+ var def = new Deferred();
+ require([type], // require the model type
+ function(requirement){
+ def.resolve(requirement);
+ });
+
+ Deferred.when(def, function(modelCtor){
+ newModel = new modelCtor(options);
+ var createMvcPromise;
+ try{
+ createMvcPromise = newModel.queryStore();
+ }catch(ex){
+ loadMvcModelDeferred.reject("load mvc model error.");
+ return loadMvcModelDeferred.promise;
+ }
+ if(createMvcPromise.then){
+ Deferred.when(createMvcPromise, lang.hitch(this, function() {
+ // now the loadedModels[item].models is set.
+ if(dojox.debugDataBinding){
+ console.log("in mvcModel promise path, loadedModels = ", loadedModels);
+ }
+ loadedModels[item] = newModel;
+ loadMvcModelDeferred.resolve(loadedModels);
+ return loadedModels;
+ }), function(){
+ loadModelLoaderDeferred.reject("load model error.")
+ });
+ }else{ // query did not return a promise, so use newModel
+ loadedModels = newModel;
+ if(dojox.debugDataBinding){
+ console.log("in mvcModel else path, loadedModels = ",loadedModels);
+ }
+ loadMvcModelDeferred.resolve(loadedModels);
+ return loadedModels;
+ }
+ });
+ return loadMvcModelDeferred;
+ }
+});
View
79 utils/simpleModel.js
@@ -0,0 +1,79 @@
+define(["dojo/_base/lang", "dojo/_base/Deferred", "dojo/_base/config",
+ "dojo/store/DataStore"],
+function(lang, Deferred, config, DataStore){
+ return function(/*Object*/config, /*Object*/params, /*String*/item){
+ // summary:
+ // simpleModel is called for each simple model, to create the simple model from the DataStore
+ // based upon the store and query params.
+ // It will also load models and return the either the loadedModels or a promise.
+ // description:
+ // Called for each model with a modelLoader of "dojox/app/utils/simpleModel", it will
+ // create the model based upon the store and query params set for the model in the config.
+ // config: Object
+ // The models section of the config for this view or for the app.
+ // params: Object
+ // The params set into the config for this model.
+ // item: String
+ // The String with the name of this model
+ // returns: model
+ // The model, of the store and query params specified in the config for this model.
+ var loadedModels = {};
+ var loadSimpleModelDeferred = new Deferred();
+
+ var options;
+ if(params.store.params.data){
+ options = {
+ "store": params.store.store,
+ "query": params.store.query ? params.store.query: {}
+ };
+ }else if(params.store.params.url){
+ options = {
+ "store": new dataStore({
+ store: params.store.store
+ }),
+ "query": params.store.query ? params.store.query: {}
+ };
+ }
+ var modelCtor;
+ var ctrl = null;
+ var newModel = null;
+ //var type = config[item].type ? config[item].type
+ // : "dojox/mvc/StatefulModel";
+ // need to load the class to use for the model
+ //var def = new Deferred();
+ //require([type], // require the model type
+ //function(requirement){
+ // def.resolve(requirement);
+ //});
+
+ //Deferred.when(def, function(modelCtor){
+ //newModel = new DataStore(options.store);
+ //var loadSimpleModelDeferred = new Deferred();
+ var createMvcPromise;
+ try{
+ //createMvcPromise = loadedModels[item].queryStore();
+ createMvcPromise = options.store.query(options.query);
+ }catch(ex){
+ loadSimpleModelDeferred.reject("load mvc model error.");
+ return loadSimpleModelDeferred.promise;
+ }
+ if(createMvcPromise.then){
+ Deferred.when(createMvcPromise, lang.hitch(this, function(newModel) {
+ // now the loadedModels[item].models is set.
+ console.log("in simpleModel promise path, loadedModels = ", loadedModels);
+ loadedModels = newModel;
+ loadSimpleModelDeferred.resolve(loadedModels);
+ return loadedModels;
+ }), function(){
+ loadModelLoaderDeferred.reject("load model error.")
+ });
+ }else{ // query did not return a promise, so use newModel
+ loadedModels = createMvcPromise;
+ console.log("in simpleModel else path, loadedModels = ",loadedModels);
+ loadSimpleModelDeferred.resolve(loadedModels);
+ return loadedModels;
+ }
+ //});
+ return loadSimpleModelDeferred;
+ }
+});
View
70 view.js
@@ -167,16 +167,51 @@ function(declare, lang, Deferred, dattr, TemplatedMixin, WidgetsInTemplateMixin,
var _definitionDef = this._loadViewDefinition();
var _templateDef = this._loadViewTemplate();
- var _startDef = new Deferred();
+ this._startDef = new Deferred();
Deferred.when(_definitionDef, lang.hitch(this, function(definition){
this._definition = definition;
Deferred.when(_templateDef, lang.hitch(this, function(){
- this._startup();
- this._started = true;
- _startDef.resolve(this);
+ // call setupModel, after setupModel startup will be called after startup the loadViewDeferred will be resolved
+ this._setupModel();
}));
}));
- return _startDef;
+ return this._startDef;
+ },
+
+ _setupModel: function(){
+ //load views model if it is not already loaded then call startup
+ if (!this.loadedModels) {
+ var loadModelLoaderDeferred = new Deferred();
+ var createPromise;
+ try{
+ createPromise = Model(this.models, this.parent);
+ }catch(ex){
+ loadModelLoaderDeferred.reject("load model error.");
+ return loadModelLoaderDeferred.promise;
+ }
+ if(createPromise.then){ // model returned a promise, so set loadedModels and call startup after the .when
+ Deferred.when(createPromise, lang.hitch(this, function(newModel){
+ if(newModel){
+ this.loadedModels = newModel;
+ }
+ if(dojox.debugDataBinding){
+ console.log("in view setupModel, this.loadedModels =",this.loadedModels);
+ }
+ this._startup();
+ }),
+ function(){
+ loadModelLoaderDeferred.reject("load model error.")
+ });
+ }else{ // model returned the actual model not a promise, so set loadedModels and call _startup
+ this.loadedModels = createPromise;
+ if(dojox.debugDataBinding){
+ console.log("in view setupModel else, this.loadedModels =",this.loadedModels);
+ }
+ this._startup();
+ }
+ }else{ // loadedModels already created so call _startup
+ this._startup();
+ }
},
_startup: function(){
@@ -186,7 +221,6 @@ function(declare, lang, Deferred, dattr, TemplatedMixin, WidgetsInTemplateMixin,
this._widget = this.render(this.templateString);
// bind view level data model
- this.bindModel(this._widget);
this.domNode = this._widget.domNode;
this.parent.domNode.appendChild(this.domNode);
@@ -206,6 +240,10 @@ function(declare, lang, Deferred, dattr, TemplatedMixin, WidgetsInTemplateMixin,
// call view assistant's init() method to initialize view
this.init();
+ this._started = true;
+ if(this._startDef){
+ this._startDef.resolve(this);
+ }
},
render: function(templateString){
@@ -215,23 +253,19 @@ function(declare, lang, Deferred, dattr, TemplatedMixin, WidgetsInTemplateMixin,
// template string
var widgetTemplate = new TemplatedMixin();
var widgetInTemplate = new WidgetsInTemplateMixin();
+ // set the loadedModels here to be able to access the model on the parse.
+ if(this.loadedModels){
+ widgetInTemplate.loadedModels = this.loadedModels;
+ if(dojox.debugDataBinding){
+ console.log("in view render, this.loadedModels =",this.loadedModels);
+ }
+ }
lang.mixin(widgetTemplate, widgetInTemplate);
widgetTemplate.templateString = templateString;
widgetTemplate.buildRendering();
return widgetTemplate;
},
-
- bindModel: function(widget){
- // summary:
- // bind view level data model to view widget
- // templateString:
- // template string
- if(!this.loadedModels){
- this.loadedModels = Model(this.models, this.parent);
- Bind([widget], this.loadedModels);
- }
- },
-
+
init: function(){
// summary:
// view life cycle init()

0 comments on commit 061f1a3

Please sign in to comment.
Something went wrong with that request. Please try again.