UNPKG

dojox

Version:

Dojo eXtensions, a rollup of many useful sub-projects and varying states of maturity – from very stable and robust, to alpha and experimental. See individual projects contain README files for details.

248 lines (218 loc) 9.13 kB
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8"> <title>MVC DOH Test</title> <style> @import "../../../../../dojo/resources/dojo.css"; @import "../../../../../dijit/tests/css/dijitTests.css"; @import "../css/app-format.css"; </style> <link id="themeStyles" rel="stylesheet" href="../../../../../dijit/themes/claro/claro.css"/> <script src="../../../../../dojo/dojo.js" type="text/javascript" djConfig="isDebug: true"></script> <script type="text/javascript" src="../helpers.js"></script> <script type="text/javascript"> dojo.require("dojox.mvc"); dojo.require("dojox.mvc.Output"); dojo.require("dojox.mvc.Group"); dojo.require("dojox.mvc.Repeat"); dojo.require("dijit.form.TextBox"); dojo.require("dijit.form.Button"); dojo.require("dojo.store.Memory"); dojo.require("dojo.parser"); var search_results_init1 = [{ "Query" : "Engineers1", "Results" : [ { "First" : "Anne1", "Last" : "Ackerman1" }, { "First" : "Ben1", "Last" : "Beckham1" }, { "First" : "Chad1", "Last" : "Chapman1" } ] }]; var search_results_init2 = [{ "Query" : "Engineers2", "Results" : [ { "First" : "Anne2", "Last" : "Ackerman2" }, { "First" : "Ben2", "Last" : "Beckham2" } ] }]; var search_results_init3 = [{ "Query" : "Engineers3", "Results" : [ { "First" : "", "Last" : "" } ] }]; var memStore1 = new dojo.store.Memory({data : search_results_init1}); var model1 = dojox.mvc.newStatefulModel({ store : memStore1 })[0]; var memStore2 = new dojo.store.Memory({data : search_results_init2}); var model2 = dojox.mvc.newStatefulModel({ store : memStore2 })[0]; var memStore3 = new dojo.store.Memory({data : search_results_init3}); var model3 = dojox.mvc.newStatefulModel({ store : memStore3 })[0]; </script> <script type="text/javascript"> dojo.require('doh.runner'); dojo.require("dijit.dijit"); // optimize: load dijit layer dojo.require("dojo.parser"); // scan page for widgets and instantiate them dojo.addOnLoad(function() { doh.register("parse", function() { dojo.parser.parse(); }); // should be able to verify all of the inputs doh.register("check initial values and bindings", [{ name : "initial", runTest : function() { doh.is("Anne1", dijit.byId("nameInput0").get('value'),"nameInput0 should be Anne1"); doh.is("Ben1", dijit.byId("nameInput1").get('value'),"nameInput1 should be Ben1 "); doh.is("Chad1", dijit.byId("nameInput2").get('value'),"nameInput2 should be Chad1"); doh.is("Anne1", dijit.byId("firstnameOutput10").get('value'),"firstnameOutput10 should be Anne1"); doh.is("Ben1", dijit.byId("firstnameOutput11").get('value'),"firstnameOutput11 should be Ben1 "); doh.is("Chad1", dijit.byId("firstnameOutput12").get('value'),"firstnameOutput12 should be Chad1"); doh.is("Anne2", dijit.byId("firstnameOutput20").get('value'),"firstnameOutput20 should be Anne2"); doh.is("Ben2", dijit.byId("firstnameOutput21").get('value'),"firstnameOutput21 should be Ben2 "); doh.is("", dijit.byId("firstnameOutput30").get('value'),"firstnameOutput30 should be blank"); } }]); doh.register("SelectModel2", [{ name : "SelectModel2", runTest : function() { //doh.robot.mouseMoveAt("dijit_form_Button_1", 500, 0); //doh.robot.mouseClick({left:true}, 500); dijit.byId('outergroupId').set('ref',model2); doh.is("Anne2", dijit.byId("nameInput0").get('value'),"nameInput0 should be Anne2"); doh.is("Ben2", dijit.byId("nameInput1").get('value'),"nameInput1 should be Ben2 "); } }]); doh.register("ChangeModel2", [{ name : "ChangeModel2", runTest : function() { dijit.byId('nameInput0').set('value',"Anne2-Update"); doh.is("Anne2-Update", dijit.byId("nameInput0").get('value'),"nameInput0 should be Anne2-Update"); doh.is("Ben2", dijit.byId("nameInput1").get('value'),"nameInput1 should be Ben2 "); doh.is("Anne2-Update", dijit.byId("firstnameOutput20").get('value'),"firstnameOutput20 should be Anne2-Update"); doh.is("Ben2", dijit.byId("firstnameOutput21").get('value'),"firstnameOutput21 should be Ben2 "); } }]); doh.register("SelectModel3", [{ name : "SelectModel3", runTest : function() { dijit.byId('outergroupId').set('ref',model3); doh.is("", dijit.byId("nameInput0").get('value'),"nameInput0 should be blank"); } }]); doh.register("ChangeModel3", [{ name : "ChangeModel3", runTest : function() { dijit.byId('nameInput0').set('value',"Anne3-Update"); doh.is("Anne3-Update", dijit.byId("nameInput0").get('value'),"nameInput0 should be Anne3-Update"); doh.is("Anne3-Update", dijit.byId("firstnameOutput30").get('value'),"firstnameOutput30 should be Anne3-Update"); } }]); doh.register("ResetAll", [{ name : "ResetAll", runTest : function() { dijit.byId('outergroupId').set('ref',model1); model1.reset(); model2.reset(); model3.reset(); doh.is("Anne1", dijit.byId("nameInput0").get('value'),"nameInput0 should be Anne1"); doh.is("Ben1", dijit.byId("nameInput1").get('value'),"nameInput1 should be Ben1 "); doh.is("Chad1", dijit.byId("nameInput2").get('value'),"nameInput2 should be Chad1"); doh.is("Anne1", dijit.byId("firstnameOutput10").get('value'),"firstnameOutput10 should be Anne1"); doh.is("Ben1", dijit.byId("firstnameOutput11").get('value'),"firstnameOutput11 should be Ben1 "); doh.is("Chad1", dijit.byId("firstnameOutput12").get('value'),"firstnameOutput12 should be Chad1"); doh.is("Anne2", dijit.byId("firstnameOutput20").get('value'),"firstnameOutput20 should be Anne2"); doh.is("Ben2", dijit.byId("firstnameOutput21").get('value'),"firstnameOutput21 should be Ben2 "); doh.is("", dijit.byId("firstnameOutput30").get('value'),"firstnameOutput30 should be blank"); } }]); doh.run(); }); </script> </head> <body class="claro"> <div id="wrapper"> <div id="header"> <div id="navigation"></div> <div id="headerInsert"> <h1>Input Output Sync</h1> <h2>Data Binding Example</h2> </div> </div> <div id="main"> <div id="leftNav"></div> <div id="mainContent"> <div class="row"> <button type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){dijit.byId('outergroupId').set('ref',model1);}">Swap Model1</button> <button type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){dijit.byId('outergroupId').set('ref',model2);}">Swap Model2</button> <button type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){dijit.byId('outergroupId').set('ref',model3);}">Swap Model3</button> </div> <div id="outergroupId" data-dojo-type="dojox.mvc.Group" data-dojo-props="ref: 'model1'"> <div id="innergroupId" data-dojo-type="dojox.mvc.Group"> <div id="repeatId" data-dojo-type="dojox.mvc.Repeat" data-dojo-props="ref: 'Results'"> <div class="row" data-dojo-type="dojox.mvc.Group" data-dojo-props="ref: '${this.index}'"> <label class="cell" for="nameInput${this.index}">Name:</label> <input class="cell" data-dojo-type="dijit.form.TextBox" id="nameInput${this.index}" data-dojo-props="ref: 'First'"/> </div> </div> </div> </div> <div class="row"> <span> Model1 Output is ==> </span> <span id="firstnameOutput10" data-dojo-type="dojox.mvc.Output" data-dojo-props="ref: model1.Results[0].First"> Name1 is "${this.value}" : </span> <span id="firstnameOutput11" data-dojo-type="dojox.mvc.Output" data-dojo-props="ref: model1.Results[1].First"> Name2 is "${this.value}" : </span> <span id="firstnameOutput12" data-dojo-type="dojox.mvc.Output" data-dojo-props="ref: model1.Results[2].First"> Name3 is "${this.value}" </span> </div> <div class="row"> <span> Model2 Output is ==> </span> <span id="firstnameOutput20" data-dojo-type="dojox.mvc.Output" data-dojo-props="ref: model2.Results[0].First"> Name1 is "${this.value}" : </span> <span id="firstnameOutput21" data-dojo-type="dojox.mvc.Output" data-dojo-props="ref: model2.Results[1].First"> Name2 is "${this.value}" </span> </div> <div class="row"> <span> Model3 Output is ==> </span> <span id="firstnameOutput30" data-dojo-type="dojox.mvc.Output" data-dojo-props="ref: model3.Results[0].First"> Name1 is "${this.value}" </span> </div> <br/>Model: <button id="reset" type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){model1.reset();model2.reset();model3.reset();}">Reset all</button> </div> </div> </div> </body> </html>