Debian Codegraph @

dojox/mvc/tests/1.7/test_mvc_bindings-simple.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta http-equiv="Content-type" content="text/html; charset=utf-8">
5 <title>Static Master/Detail Pattern -- Binding Test</title>
6
7 <style type="text/css">
8 @import "css/app-format.css";
9 @import "../../../../dijit/themes/claro/claro.css";
10 </style>
11 <script type="text/javascript" djConfig="parseOnLoad:1,isDebug:1,async:1" src="../../../../dojo/dojo.js"></script>
12 <script type="text/javascript">
13
14 var model;
15
16 require([
17 'dojo/_base/kernel',
18 'dojo/parser',
19 'dojo/ready',
20 'dojox/mvc',
21 'dijit/form/TextBox',
22 'dijit/form/Button',
23 'dijit/form/ValidationTextBox',
24 'dijit/form/NumberTextBox',
25 'dojox/mvc/Group',
26 'dojox/mvc/Output'
27 ], function(dojo, parser, ready, mvc){
28 // The dojox.mvc.StatefulModel class creates a data model instance
29 // where each leaf within the data model is decorated with dojo.Stateful
30 // properties that widgets can bind to and watch for their changes.
31 model = mvc.newStatefulModel({ data :
32 { "First" : "John",
33 "Last" : "Doe",
34 "Email" : "[email protected]",
35 "Num" : 3
36 }
37 });
38 console.log("model is ");
39 console.log(model);
40
41 function testFirstRelevance(newValue) {
42 //newValue = model.First.value;
43 if ( newValue !== "0" ) return true;
44 else return false;
45 }
46
47 function testFirstReadOnly(newValue) {
48 if ( newValue !== "2" && newValue !== "3" ) return false;
49 else return true;
50 }
51
52 function testNumValid(newValue) {
53 if ( newValue !== 1 && newValue !== "1" && newValue !== "3") return true;
54 else return false;
55 }
56
57 function testRequired(newValue) {
58 if ( newValue !== 4 && newValue !== "4") return false;
59 else return true;
60 }
61
62 function testLastRelevance(newValue) {
63 //newValue = model.First.value;
64 if ( newValue !== "0" ) return true;
65 else return false;
66 }
67
68 function testLastValid(newValue) {
69 if ( newValue !== "1" ) return true;
70 else return false;
71 }
72
73 function init(){
74 // bind tests, "read-only" etc.
75 mvc.bind(model.First, "value", model.First, "readOnly", testFirstReadOnly, true);
76 mvc.bind(model.First, "value", model.First, "relevant", testFirstRelevance, true);
77 mvc.bind(model.First, "value", model.First, "valid", testNumValid, true);
78 mvc.bind(model.Num, "value", model.Num, "valid", testNumValid, true);
79
80 // bind tests bind Last value to Email relevant and valid
81 mvc.bind(model.Last, "value", model.Email, "relevant", testFirstRelevance, true);
82 mvc.bind(model.Last, "value", model.Email, "valid", testNumValid, true);
83 mvc.bind(model.Last, "value", model.Email, "readOnly", testFirstReadOnly, true);
84 mvc.bind(model.Last, "value", model.Email, "required", testRequired, true);
85 mvc.bind(model.Last, "value", model.Email, "value");
86 }
87 ready(init);
88 });
89
90 </script>
91 </head>
92 <body class="claro">
93 <div id="wrapper">
94 <div id="header">
95 <div id="navigation">
96 </div>
97 <div id="headerInsert">
98 <h1>Binding Tests</h1>
99 </div>
100 </div>
101 <div id="main">
102 <div id="leftNav">
103 </div>
104 <div id="mainContent">
105 <h2>Bind Self Tests</h2>
106 <div class="row">
107 <label style="display:inline-block; width:100%; text-align:left;">First: Enter 0 to test for Relevant false (disabled) (use Reset to re-enable)</label>
108 <label style="display:inline-block; width:100%; text-align:left;">First: Enter 1 to test for Valid false.</label>
109 <label style="display:inline-block; width:100%; text-align:left;">First: Enter 2 to test for Read-only false (use Reset to re-enable)</label>
110 <label style="display:inline-block; width:100%; text-align:left;">First: Enter 3 to test for Read-only false and Valid false (use Reset to re-enable)</label>
111 </div>
112 <div class="row">
113 <label class="cell" for="firstnameInput">First:</label>
114 <input class="cell" id="firstnameInput" data-dojo-type="dijit.form.ValidationTextBox"
115 data-dojo-props="ref: model.First"></input>
116 <!-- Content in output below will always be in sync with value of textbox above -->
117 <span id="tout" data-dojo-type="dojox.mvc.Output" data-dojo-props="ref: model.First">
118 (first name is: ${this.value})
119 </span>
120
121 </div>
122 <div class="row">
123 <label class="cell" for="firstnameInput"></label>
124 <span data-dojo-type="dojox.mvc.Output" data-dojo-props="ref: model.First">
125 Relevant is: ${this.ref.relevant}, Valid is: ${this.ref.valid}, Read-only is: ${this.ref.readOnly})
126 </span>
127 </div>
128 <div class="row">
129 <label style="display:inline-block; width:100%; text-align:left;">Num: Enter 1 for Valid false</label>
130 </div>
131 <div class="row">
132 <label class="cell" for="numInput">Num:</label>
133 <input class="cell" id="numInput" data-dojo-type="dijit.form.NumberTextBox"
134 data-dojo-props="ref: model.Num"></input>
135 <span data-dojo-type="dojox.mvc.Output" data-dojo-props="ref: model.Num">
136 (num is: ${this.value})
137 </span>
138 </div>
139 <h2>Bind Tests</h2>
140 <div class="row">
141 <label style="display:inline-block; width:100%; text-align:left;">Last: Enter 0 to test for Relevant false (disabled) for Email.</label>
142 <label style="display:inline-block; width:100%; text-align:left;">Last: Enter 1 to test for Valid false for Email.</label>
143 <label style="display:inline-block; width:100%; text-align:left;">Last: Enter 2 to test for Read-only true for Email.</label>
144 <label style="display:inline-block; width:100%; text-align:left;">Last: Enter 3 to test for Read-only true and Valid false for Email.</label>
145 <label style="display:inline-block; width:100%; text-align:left;">Last: Enter 4 to test for Required true for Email.</label>
146 </div>
147
148 <div class="row">
149 <label class="cell" for="lastnameInput">Last:</label>
150 <input class="cell" id="lastnameInput" data-dojo-type="dijit.form.TextBox"
151 data-dojo-props="ref: model.Last"></input>
152 <span data-dojo-type="dojox.mvc.Output" data-dojo-props="ref: model.Last">
153 (last name is: ${this.value})
154 </span>
155 </div>
156 <div class="row">
157 <label class="cell" for="emailInput">Email:</label>
158 <input class="cell" id="emailInput" data-dojo-type="dijit.form.ValidationTextBox"
159 data-dojo-props="ref: model.Email"></input>
160 <span data-dojo-type="dojox.mvc.Output" data-dojo-props="ref: model.Email">
161 (email is: ${this.value})
162 </span>
163 </div>
164 <div class="row">
165 <label class="cell" for="emailInput"></label>
166 <span id="emailOut" data-dojo-type="dojox.mvc.Output" data-dojo-props="ref: model.Email">
167 Relevant is: ${this.ref.relevant}, Valid is: ${this.ref.valid}, Read-only is: ${this.ref.readOnly}, Required is: ${this.ref.required})
168 </span>
169 </div>
170
171 <br/>Model:
172 <button id="reset" type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){doReset()}">Reset</button>
173 </div>
174 </div></div>
175 <script type="text/javascript">
176 function doReset() {
177 model.reset();
178 }
179 </script>
180
181 </body>
182 </html>