| 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <meta http-equiv="Content-type" content="text/html; charset=utf-8"> |
| 5 | <title>View generation -- Model-bound generation example with a store, commit and reset</title> |
| 6 | |
| 7 | <script src="../../../../dojo/dojo.js" |
| 8 | type="text/javascript" |
| 9 | djConfig="isDebug: true, parseOnLoad: true"> |
| 10 | </script> |
| 11 | <style type="text/css"> |
| 12 | @import "css/app-format.css"; |
| 13 | @import "../../../../dijit/themes/claro/claro.css"; |
| 14 | </style> |
| 15 | <script type="text/javascript" > |
| 16 | dojo.require("dojox.mvc"); |
| 17 | dojo.require("dojox.mvc.Generate"); |
| 18 | dojo.require("dijit.form.Textarea"); |
| 19 | dojo.require("dijit.form.Button"); |
| 20 | dojo.require("dojo.data.ItemFileReadStore"); |
| 21 | dojo.require("dojo.data.ItemFileWriteStore"); |
| 22 | dojo.require("dojo.store.DataStore"); |
| 23 | dojo.require("dojo.parser"); |
| 24 | |
| 25 | var model; |
| 26 | |
| 27 | function setup(){ |
| 28 | var theWriteStore = new dojo.data.ItemFileWriteStore({url: dojo.moduleUrl("dojox.mvc.tests._data", "mvcGenerateData.json")}); |
| 29 | // this is used to see what would have been written out if we were using a real service |
| 30 | theWriteStore._saveEverything = function(c, e, n){ |
| 31 | console.log(n); |
| 32 | c.call(); |
| 33 | }; |
| 34 | var theDataStore = new dojo.store.DataStore({store: theWriteStore}); |
| 35 | var theModelPromise = dojox.mvc.newStatefulModel({store: theDataStore}); // query() returns a deferred.promise |
| 36 | theModelPromise.then(function(theStatefulModel){ |
| 37 | model = theStatefulModel; |
| 38 | dijit.byId("view").set("ref", "model"); |
| 39 | }); |
| 40 | }; |
| 41 | |
| 42 | dojo.addOnLoad(setup); |
| 43 | </script> |
| 44 | </head> |
| 45 | <body class="claro"> |
| 46 | <div id="wrapper"> |
| 47 | <div id="header"> |
| 48 | <div id="navigation"> |
| 49 | </div> |
| 50 | <div id="headerInsert"> |
| 51 | <h1>View generation example</h1> |
| 52 | <h2>Data Binding - Generate Container, with a store, commit and reset.</h2> |
| 53 | </div> |
| 54 | </div> |
| 55 | <div id="main"> |
| 56 | <div id="leftNav"> |
| 57 | </div> |
| 58 | <div id="mainContent"> |
| 59 | <h3>Generated View</h3> |
| 60 | <div id="view" data-dojo-type="dojox.mvc.Generate"> |
| 61 | </div> |
| 62 | <div class="row"> |
| 63 | <div class="spacer"></div> |
| 64 | <button type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){model.commit();}">Commit</button> |
| 65 | <button type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){model.reset();}">Reset</button> |
| 66 | </div> |
| 67 | </div> |
| 68 | </div> |
| 69 | </div> |
| 70 | </body> |
| 71 | </html> |