aboutsummaryrefslogtreecommitdiff
path: root/includes/js/dojox/storage/demos/helloworld.html
blob: 44fd739178c90c7d6e9065811b1a2a7b90f5af42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<html>
  <head>
    <script src="../../../dojo/dojo.js"></script>
    <script src="../storage-browser.js"></script>
    
    <script>
      dojo.require("dojox.storage");
      
      function runDemo(){
        // setup event handlers
        dojo.byId("saveButton").onclick = saveValue;
        
        // write out what our storage provider is for debugging
        dojo.byId("currentProvider").innerHTML = 
          dojox.storage.manager.currentProvider.declaredClass;
          
        loadValues();
      }
      
      function loadValues(){
        // get any values that were saved before and write them into the page
        var results = dojox.storage.get("myValues");
      
        if(results){
          var printMe = "<ul>";
          for(var i = 0; i < results.length; i++){
            printMe += "<li>" + results[i] + "</li>";
          }
          printMe += "</ul>";
          dojo.byId("allValues").innerHTML = printMe;
        }
      }
      
      function saveValue(){
        var value = dojo.byId("saveValue").value;
        if(value == undefined || value === ""){
          alert("Please enter a correct value");
          return;
        }
        
        // get the old values first, since we are saving everything
        // as one key
        var results = dojox.storage.get("myValues");
        if(!results){
          results = new Array();
        }
        
        // add new value
        results.push(value);
        
        dojox.storage.put("myValues", results, function(status, keyName){
    			if(status == dojox.storage.FAILED){
    				alert("You do not have permission to store data for this web site.");
    			}else if(status == dojox.storage.SUCCESS){
    			  loadValues();
    			}
    		});
      }
      
      // wait until the storage system is finished loading
      if(!dojox.storage.manager.isInitialized()){
      	dojo.connect(dojox.storage.manager, "loaded", runDemo);
      }else{
      	dojo.connect(dojo, "loaded", runDemo);
      }
    </script>
  </head>
  
  <body>
    <h1>Dojo Storage Hello World</h1>
    
    <p>Simple Dojo Storage example. Enter values below to have them
      persisted in Dojo Storage; refresh browser page or close browser
      and then return to this page to see the values again. Note that
      Dojo Storage will not work from file:// URLs.</p>
      
    <h2>Save Values:</h2>
    <div>
      <input id="saveValue" type="text"></input>
      <button id="saveButton">Save Value</button>
    </div>
    
    <h2>All Saved Values:</h2>
    <p id="allValues"></p>
    
    <p>Using Dojo Storage Provider (autodetected): 
      <span id="currentProvider"></span>
    <p>
  </body>
</html>