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.

192 lines (173 loc) 7.79 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> <!-- required: the default dijit theme: --> <link id="themeStyles" rel="stylesheet" href="../../../../../dijit/themes/claro/claro.css"/> <!-- required: dojo.js --> <script src="../../../../../dojo/dojo.js" type="text/javascript" data-dojo-config="parseOnLoad: 0, isDebug: 1, mvc: {debugBindings: 1}"></script> <script type="text/javascript" src="../helpers.js"></script> <script type="text/javascript"> var templateString = '<div class="row">' + '<script type="dojo/require">at: "dojox/mvc/at"<\/script>' + '<label class="cell">Name:</label>' + '<input id="${parent.id}_textbox${indexAtStartup}" class="cell" data-dojo-type="dijit.form.TextBox" data-dojo-props="value: at(\'rel:\', \'First\')"></input>' + '<button type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){ ctrl.set(\'cursorIndex\', \'${indexAtStartup}\'); }">Details</button>' + '</div>'; require([ "doh/runner", "dojo/_base/declare", "dojo/when", "dojo/dom", "dojo/parser", "dojo/promise/all", "dojo/store/JsonRest", "dijit/registry", "dijit/_WidgetBase", "dojox/mvc/at", "dojox/mvc/getStateful", "dojox/mvc/EditModelRefController", "dojox/mvc/ListController", "dojox/mvc/WidgetList", "dijit/form/TextBox", "dijit/form/Button", "dojox/mvc/Group", "dojo/domReady!" ], function(doh, declare, when, ddom, parser, all, JsonRest, registry, _WidgetBase, at, getStateful, EditModelRefController, ListController, WidgetList){ var ctrlClass = declare([_WidgetBase, EditModelRefController, ListController], {}); (ctrl = (new ctrlClass({srcNodeRef: ddom.byId("detailsGroup"), cursorIndex: 0}))).startup(); (new WidgetList({templateString: templateString, children: at(ctrl, "model")}, ddom.byId("repeat2"))).startup(); when(all([parser.parse(), new JsonRest({target: require.toUrl("dojox/mvc/tests/_data/mvcRepeatData.json")}).query({})]), function(a){ // ctrl.set("sourceModel", getStateful(a[1].items)); // should be able to verify all of the inputs doh.register("Check values and bindings", [ { name: "setup", runTest: function(){ ctrl.set("sourceModel", getStateful(a[1].items)); } }, { name: "Initial", runTest: function(){ doh.is("Anne", registry.byId("repeat2_textbox0").value, "textbox0 should be Anne"); doh.is("Anne", registry.byId("firstInput").value, "firstInput should be Anne"); } }, { name: "TestBen", runTest: function(){ ctrl.set("cursorIndex", 1); doh.is("Ben", registry.byId("repeat2_textbox1").value, "textbox1 should be Ben"); doh.is("Ben", registry.byId("firstInput").value, "firstInput should be Ben"); } }, { name: "TestJohn", runTest: function(){ ctrl.set("cursorIndex", 9); doh.is("John", registry.byId("repeat2_textbox9").value, "textbox9 should be John"); doh.is("John", registry.byId("firstInput").value, "firstInput should be John"); registry.byId("firstInput").set("value", "Johnny"); doh.is("Johnny", ctrl.get("model").get(9).get("First"), "First name of the 10th entry should be changed to Johnny"); } }, { name: "TestCommitReset", runTest: function(){ ctrl.set("cursorIndex", 8); doh.is("Irene", registry.byId("repeat2_textbox8").value, "textbox8 should be Irene"); doh.is("Irene", registry.byId("firstInput").value, "firstInput should be Irene"); registry.byId("firstInput").set("value", "IreneThisUpdateShouldBeSaved"); ctrl.commit(); registry.byId("lastInput").set("value", "IraThisUpdateShouldBeReset"); ctrl.reset(); doh.is("IreneThisUpdateShouldBeSaved", registry.byId("repeat2_textbox8").value, "textbox8 should be IreneThisUpdateShouldBeSaved"); doh.is("IreneThisUpdateShouldBeSaved", registry.byId("firstInput").value, "firstInput should be IreneThisUpdateShouldBeSaved"); doh.is("Ira", registry.byId("lastInput").value, "lastInput should be Ira"); } } ]); doh.run(); }); }); </script> </head> <body class="claro"> <script type="dojo/require">at: "dojox/mvc/at"</script> <h1 class="testTitle">doh_mvc_programmatic-repeat-store.html automated tests (non-robot)</h1> <div id="wrapper"> <div id="header"> <div id="navigation"></div> <div id="headerInsert"> <h2>Master Detail Example - With repeat container, using a store, with save, commit and reset.</h2> </div> </div> <div id="main"> <div id="leftNav"></div> <div id="mainContent"> <div id="searchBanner">Search Results for term: </div> <table> <tbody> <tr> <td> <div> <div>Programatic Repeat using my.Repeat and its templateString: </div> <div id="repeat2"></div> </div> </td> <td> <div> <div>Declarative Repeat using my.Repeat does not pass templateString: </div> <div id="repeatId2" data-dojo-type="dojox/mvc/WidgetList" data-dojo-props="templateString: templateString, children: at(ctrl, 'model')"></div> </div> </td> </tr> </tbody> </table> <div class="spacer"></div> <div id="detailsBanner">Details for selected index:</div> <div id="detailsGroup"> <div class="row"> <label class="cell" for="firstInput">First Name:</label> <input class="cell" id="firstInput" data-dojo-type="dijit.form.TextBox" data-dojo-props="value: at('rel:', 'First')"></input> </div> <div class="row"> <label class="cell" for="lastInput">Last Name:</label> <input class="cell" id="lastInput" data-dojo-type="dijit.form.TextBox" data-dojo-props="value: at('rel:', 'Last')"></input> </div> <div class="row"> <label class="cell" for="locationInput">Location:</label> <input class="cell" id="locationInput" data-dojo-type="dijit.form.TextBox" data-dojo-props="value: at('rel:', 'Location')"></input> </div> <div class="row"> <label class="cell" for="officeInput">Office:</label> <input class="cell" id="officeInput" data-dojo-type="dijit.form.TextBox" data-dojo-props="value: at('rel:', 'Office')"></input> </div> <div class="row"> <label class="cell" for="emailInput">Email:</label> <input class="cell" id="emailInput" data-dojo-type="dijit.form.TextBox" data-dojo-props="value: at('rel:', 'Email')"></input> </div> <div class="row"> <label class="cell" for="telInput">Telephone:</label> <input class="cell" id="telInput" data-dojo-type="dijit.form.TextBox" data-dojo-props="value: at('rel:', 'Tel')"></input> </div> <div class="row"> <label class="cell" for="faxInput">Fax:</label> <input class="cell" id="faxInput" data-dojo-type="dijit.form.TextBox" data-dojo-props="value: at('rel:', 'Fax')"></input> </div> <div class="row"> <div class="spacer"></div> <button type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){ ctrl.commit();}">Commit All</button> <button type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){ ctrl.reset(); }">Reset to last saved</button> </div> </div> </div> </div> </div> </body> </html>