source: cows/branches/cows-vis/cows/pylons/project_templates/cows_server/+package+/public/js/yui/examples/attribute/attribute-rw.html @ 5259

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/cows/branches/cows-vis/cows/pylons/project_templates/cows_server/+package+/public/js/yui/examples/attribute/attribute-rw.html@5259
Revision 5259, 15.3 KB checked in by domlowe, 11 years ago (diff)

adding yui javascript

Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2<html>
3<head>
4        <title>YUI Library Examples: Attribute Utility: readOnly and writeOnce Configuration</title>
5    <meta http-equiv="content-type" content="text/html; charset=utf-8">
6        <link rel="stylesheet" type="text/css" href="../../assets/yui.css" >
7
8<style>
9    /*Supplemental CSS for the YUI distribution*/
10    #custom-doc { width: 95%; min-width: 950px; }
11    #pagetitle {background-image: url(../../assets/bg_hd.gif);}
12    #pagetitle h1 {background-image: url(../../assets/title_h_bg.gif);}
13</style>
14
15<link rel="stylesheet" type="text/css" href="../../assets/dpSyntaxHighlighter.css">
16<link type="text/css" rel="stylesheet" href="../../build/cssfonts/fonts-min.css" />
17<script type="text/javascript" src="../../build/yui/yui-min.js"></script>
18<style type="text/css">
19    #example-out .entry {
20        font-family:courier;
21        margin-top:2px;
22        margin-left:10px;
23    }
24
25    #example-out .header {
26        font-weight:bold;
27        font-family:arial;
28        color:#8dd5e7;
29        margin-top:10px;
30        margin-bottom:3px;
31        margin-left:0px;
32    }
33
34    #example-out .subheader {
35        font-weight:bold;
36        font-family:arial;
37        color:#EDFF9F;
38    }
39
40    #example-out {
41        margin:5px;
42        border:1px solid #000;
43        color:#ffffff;
44        background-color:#004c6d;
45        overflow:auto;
46        width:30em;
47        height:22em;
48        padding:2px 5px;
49    }
50</style>
51<script type="text/javascript">
52    YUI.namespace("example");
53    YUI.example.print = function(msg, cl) {
54        var o = document.getElementById("example-out");
55        if (o) {
56            cl = cl || "";
57            o.innerHTML += '<div class="entry ' + cl + '">' + msg + '</div>';
58        }
59    }
60</script>
61
62</head>
63<body id="yahoo-com" class=" yui-skin-sam">
64<div id="custom-doc" class="yui-t2">
65<div id="hd">
66        <div id="ygunav">
67                <p>
68            <em>
69                <a href="http://developer.yahoo.com/yui/3/">YUI 3.x Home</a> <i> - </i> 
70            </em>
71                </p>
72                <form action="http://search.yahoo.com/search" id="sitesearchform">
73            <input name="vs" type="hidden" value="developer.yahoo.com">
74            <input name="vs" type="hidden" value="yuiblog.com">
75                    <div id="sitesearch">
76                        <label for="searchinput">Site Search (YDN &amp; YUIBlog): </label>
77                            <input type="text" id="searchinput" name="p">
78                            <input type="submit" value="Search" id="searchsubmit" class="ygbt">
79                    </div>
80                </form>
81    </div>
82        <div id="ygma"><a href="../../"><img src="../../assets/logo.gif"  border="0" width="200" height="93"></a></div>
83        <div id="pagetitle"><h1>YUI Library Examples: Attribute Utility: readOnly and writeOnce Configuration</h1></div>
84</div>
85<div id="bd">
86
87        <div id="bar-note"><p><strong>Note:</strong> This is YUI 3.x. Looking for <a href="http://developer.yahoo.com/yui/">YUI 2.x</a>?</p></div>
88
89        <div id="yui-main">
90                <div class="yui-b">
91                  <div class="yui-ge">
92                          <div class="yui-u first example" id="main">
93
94        <h2>Attribute Utility: readOnly and writeOnce Configuration</h2>
95
96        <div id="example" class="promo">
97        <p>
98        Attributes can be configured to be <code>readOnly</code>, stopping them from being modified by the end user, or <code>writeOnce</code> allowing them to only be set by the end user, but only once. This example demonstrates how to setup attributes for your class as <code>readOnly</code> or <code>writeOnce</code> attributes, and shows how their behavior differs when the end user attempts to set their values.
99        </p>   
100
101        <div class="module example-container ">
102                        <div class="hd exampleHd">
103                        <p class="newWindowButton yui-skin-sam">
104                <a href="attribute-rw_clean.html" target="_blank">View example in new window.</a>
105            </p>
106                </div>          <div id="example-canvas" class="bd">
107
108               
109        <!--BEGIN SOURCE CODE FOR EXAMPLE =============================== -->
110       
111        <div id="example-out"></div>
112
113<script type="text/javascript">
114YUI({base:"../../build/", timeout: 10000}).use("node", "attribute", function(Y) {
115
116    // Shortcut to print (unrelated to example)
117    var print = YUI.example.print;
118
119    // Setup a custom class with attribute support
120    function MyClass(cfg) {
121        this._initAtts(MyClass.ATTRIBUTES, cfg);
122    }
123
124    // Setup attribute configuration
125    MyClass.ATTRIBUTES = {
126        "foo" : {
127            value: "Default Foo",
128            readOnly: true
129        },
130 
131        "bar" : {
132            value: "Default Bar",
133            writeOnce: true
134        }
135    };
136
137    MyClass.prototype.doSomething = function() {
138        // ... Do something which requires
139        // MyClass to change the value
140        // of foo ...
141       
142        // Host code can reset value of
143        // readOnly attributes interally,
144        // by working with the private state
145        // property
146
147        this._conf.remove("foo");
148        this.set("foo", "New Default Foo");
149    };
150
151    Y.augment(MyClass, Y.Attribute);
152
153    var o1 = new MyClass({
154        foo: "User Foo",
155        bar: "User Bar"
156    });
157
158    print("Initial Set", "header");
159    print("foo value (readOnly):", "subheader");
160    print(o1.get("foo"));
161
162    print("bar value (writeOnce):", "subheader");
163    print(o1.get("bar"));
164
165    // Attempt to reset values:
166
167    print("Try Setting Again", "header");
168    o1.set("foo", "User Reset Foo");
169    o1.set("bar", "User Reset Bar");
170
171    print("Final foo value (readOnly)", "subheader");
172    print(o1.get("foo"));
173
174    print("Final bar value (writeOnce)", "subheader");
175    print(o1.get("bar"));
176
177    print("Set Value Of Foo Interally", "header");
178    print("foo value (readOnly):", "subheader");
179
180    o1.doSomething();
181    print(o1.get("foo"));
182
183});
184</script>
185       
186        <!--END SOURCE CODE FOR EXAMPLE =============================== -->
187       
188               
189                </div>
190        </div>                 
191        </div>
192               
193        <h3>ReadOnly And WriteOnce</h3>
194
195<p>Attribute supports the ability to configure attributes to be <code>readOnly</code> or <code>writeOnce</code>. <code>readOnly</code> attributes cannot be set by the end user, either through initial values passed to the constructor, or by invoking the <code>set</code> method. <code>writeOnce</code> attributes on the other hand, can be set by the user, but only once, either during initialization or through a call to <code>set</code>. Once a value is established for a <code>writeOnce</code> attribute, it cannot be reset to another value by the user.</p>
196
197<h3>Configuring ReadOnly And WriteOnce Attributes</h3>
198
199<p>This example sets up a custom class, <code>MyClass</code>, with two attributes, <code>foo</code> and <code>bar</code>. <code>foo</code> is configured to be a <code>readOnly</code> attribute, and <code>bar</code> is configured to be a <code>writeOnce</code> attribute:</p>
200
201<textarea name="code" class="JScript" rows="1" cols="60">
202    // Setup a custom class with attribute support
203    function MyClass(cfg) {
204        this._initAtts(MyClass.ATTRIBUTES, cfg);
205    }
206
207    // Setup attribute configuration
208    MyClass.ATTRIBUTES = {
209        "foo" : {
210            value: "Default Foo",
211            readOnly: true
212        },
213
214        "bar" : {
215            value: "Default Bar",
216            writeOnce: true
217        }
218    };
219</textarea>
220
221<h3>Attempting To Set Values</h3>
222
223<p>We first attempt to set values for both attributes in the constructor (used to intialize the attributes) and see that only <code>bar</code>, the <code>writeOnce</code> attribute, gets set to the user provided value:</p>
224
225<textarea name="code" class="JScript" rows="1" cols="60">
226    var o1 = new MyClass({
227        foo: "User Foo",
228        bar: "User Bar"
229    });
230
231    print("Initial Set", "header");
232    print("foo value (readOnly):", "subheader");
233    print(o1.get("foo"));
234
235    print("bar value (writeOnce):", "subheader");
236    print(o1.get("bar"));
237</textarea>
238
239<p>We then attempt to set values for both attributes again, using <code>set</code>, and see that niether of the values are modified:</p>
240
241<textarea name="code" class="JScript" rows="1" cols="60">
242    print("Try Setting Again", "header");
243    o1.set("foo", "User Reset Foo");
244    o1.set("bar", "User Reset Bar");
245
246    print("Final foo value (readOnly)", "subheader");
247    print(o1.get("foo"));
248
249    print("Final bar value (writeOnce)", "subheader");
250    print(o1.get("bar"));
251</textarea>
252
253<h3>Setting The State Of ReadOnly Values Internally</h3>
254
255<p>Although the user cannot update the value of <code>readOnly</code> attributes, it maybe neccessary for the host object to update it's value internally. The example shows how this can be done, using the private <code>_conf</code> state property on the host:</p>
256
257<textarea name="code" class="JScript" rows="1" cols="60">
258    MyClass.prototype.doSomething = function() {
259        // ... Do something which requires
260        // MyClass to change the value
261        // of foo ...
262
263        // Host code can reset value of
264        // readOnly attributes interally,
265        // by working with the private state
266        // property
267
268        this._conf.remove("foo");
269        this.set("foo", "New Default Foo");
270    };
271</textarea>
272                                </div>
273                                <div class="yui-u sidebar">
274                                       
275                               
276                                        <div id="examples" class="mod box4">
277                        <div class="hd">
278                                                <h4>
279    Attribute Utility Examples:</h4>
280                        </div>
281                                                <div class="bd">
282                                                        <ul>
283                                                                <li><a href='../attribute/attribute-basic.html'>Basic Configuration</a></li><li><a href='../attribute/attribute-event.html'>Change Events</a></li><li><a href='../attribute/attribute-getset.html'>Custom Getters, Setters and Validators</a></li><li><a href='../attribute/attribute-clone.html'>Value Clone Configuration</a></li><li class='selected'><a href='../attribute/attribute-rw.html'>readOnly and writeOnce Configuration</a></li>                                                 </ul>
284                                                </div>
285                                        </div>
286                                       
287                                        <div class="mod box4">
288                        <div class="hd">
289                                                <h4>More Attribute Utility Resources:</h4>
290                        </div>
291                        <div class="bd">
292                                                <ul>
293                                                        <!-- <li><a href="http://developer.yahoo.com/yui/attribute/">User's Guide</a> (external)</li> -->
294                                                <li><a href="../../api/module_attribute.html">API Documentation</a></li>
295</ul>
296                        </div>
297                                        </div>
298                          </div>
299                </div>
300               
301                </div>
302        </div>
303
304
305<div class="yui-b toc3" id="tocWrapper">
306<!-- TABLE OF CONTENTS -->
307<div id="toc">
308       
309<ul>
310<li class="sect first">YUI 3.x Project</li><li class="item"><a title="The Yahoo! User Interface (YUI) Library, 3.x Branch, " href="http://developer.yahoo.com/yui/3/">YUI 3 Web Site (external)</a></li><li class="item"><a title="Examples of every YUI utility and control in action" href="../../examples/">YUI 3 Examples</a></li><li class="item"><a title="Instantly searchable API documentation for the entire YUI library." href="../../api/">YUI 3 API Docs</a></li><li class="item"><a title="The YUI Library can be downloaded from SourceForge" href="http://sourceforge.net/projects/yui/">YUI 3 on Sourceforge (external)</a></li><li class="item"><a title="YUI is free and open, offered under a BSD license." href="http://developer.yahoo.com/yui/3/license.html">YUI License (external)</a></li><li class="sect">YUI 3 Core - Examples</li><li class="item"><a title="YUI (Global Prerequisite) - Functional Examples" href="../../examples/yui/index.html">YUI (Global Prerequisite)</a></li><li class="item"><a title="Event - Functional Examples" href="../../examples/event/index.html">Event</a></li><li class="item"><a title="Node - Functional Examples" href="../../examples/node/index.html">Node</a></li><li class="sect">YUI 3 Component Infrastructure - Examples</li><li class="selected "><a title="Attribute - Functional Examples" href="../../examples/attribute/index.html">Attribute</a></li><li class="item"><a title="Base - Functional Examples" href="../../examples/base/index.html">Base</a></li><li class="sect">YUI 3 Utilities - Examples</li><li class="item"><a title="Animation - Functional Examples" href="../../examples/anim/index.html">Animation</a></li><li class="item"><a title="Cookie - Functional Examples" href="../../examples/cookie/index.html">Cookie</a></li><li class="item"><a title="Drag &amp; Drop - Functional Examples" href="../../examples/dd/index.html">Drag &amp; Drop</a></li><li class="item"><a title="Get - Functional Examples" href="../../examples/get/index.html">Get</a></li><li class="item"><a title="IO - Functional Examples" href="../../examples/io/index.html">IO</a></li><li class="item"><a title="JSON (JavaScript Object Notation) - Functional Examples" href="../../examples/json/index.html">JSON</a></li><li class="item"><a title="Queue - Functional Examples" href="../../examples/queue/index.html">Queue</a></li><li class="sect">YUI 3 CSS - Examples</li><li class="item"><a title="YUI CSS Reset - Functional Examples" href="../../examples/cssreset/index.html">CSS Reset</a></li><li class="item"><a title="YUI Fonts - Functional Examples" href="../../examples/cssfonts/index.html">CSS Fonts</a></li><li class="item"><a title="YUI Grids - Functional Examples" href="../../examples/cssgrids/index.html">CSS Grids</a></li><li class="item"><a title="YUI Base - Functional Examples" href="../../examples/cssbase/index.html">CSS Base</a></li><li class="sect">The YUI Community</li><li class="item"><a title="The Yahoo! User Interface Blog" href="http://yuiblog.com">YUI Blog (external)</a></li><li class="item"><a title="The Yahoo! Group YDN-JavaScript hosts the YUI community forum" href="http://tech.groups.yahoo.com/group/ydn-javascript/">YUI Forum (external)</a></li><li class="item"><a title="The Yahoo! Group yui3 is dedicated to the 3.x branch of the Yahoo! User Interface (YUI) Library." href="http://tech.groups.yahoo.com/group/yui3/">YUI 3 Forum (external)</a></li><li class="item"><a title="YUI is used by Yahoo! and by hundreds of other sites, including many you know and love." href="/yui/poweredby/">YUI Sightings (external)</a></li><li class="item"><a title="Videos and podcasts from the YUI Team and from the Yahoo! frontend engineering community." href="http://developer.yahoo.com/yui/theater/">YUI Theater (external)</a></li><li class="sect">YUI Articles on the YUI Website</li><li class="item"><a title="Answers to Frequently Asked Questions about the YUI Library" href="http://developer.yahoo.com/yui/articles/faq/">YUI FAQ (external)</a></li><li class="item"><a title="Yahoo!'s philosophy of Graded Browser Support" href="http://developer.yahoo.com/yui/articles/gbs/">Graded Browser Support (external)</a></li><li class="item"><a title="Reporting Bugs and Making Feature Requests for YUI Components" href="http://developer.yahoo.com/yui/articles/reportingbugs/">Bug Reports/Feature Requests (external)</a></li><li class="item"><a title="Serve YUI source files from Yahoo! -- free, fast, and simple" href="http://developer.yahoo.com/yui/3/articles/hosting/">Serving YUI Files from Yahoo! (external)</a></li></ul>
311</div>
312</div>
313        </div><!--closes bd-->
314
315        <div id="ft">
316        <p class="first">Copyright &copy; 2008 Yahoo! Inc. All rights reserved.</p>
317        <p><a href="http://privacy.yahoo.com/privacy/us/devel/index.html">Privacy Policy</a> -
318            <a href="http://docs.yahoo.com/info/terms/">Terms of Service</a> -
319            <a href="http://docs.yahoo.com/info/copyright/copyright.html">Copyright Policy</a> -
320            <a href="http://careers.yahoo.com/">Job Openings</a></p>
321        </div>
322</div>
323<script src="../../assets/dpSyntaxHighlighter.js"></script>
324<script language="javascript"> 
325dp.SyntaxHighlighter.HighlightAll('code'); 
326</script>
327</body>
328</html>
329<!-- delightfuture.corp.yahoo.com uncompressed/chunked Wed Aug 13 16:45:30 PDT 2008 -->
Note: See TracBrowser for help on using the repository browser.