|
1 |
| -<html xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:tiles="http://tiles.apache.org/tags-tiles" xmlns:spring="http://www.springframework.org/tags" xmlns:util="urn:jsptagdir:/WEB-INF/tags/util"> |
| 1 | +<html xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:tiles="http://tiles.apache.org/tags-tiles" xmlns:spring="http://www.springframework.org/tags" xmlns:util="urn:jsptagdir:/WEB-INF/tags/util" manifest="cache.manifest"> |
2 | 2 |
|
3 | 3 | <jsp:output doctype-root-element="HTML" doctype-system="about:legacy-compat" />
|
4 | 4 |
|
|
19 | 19 | dojo.require("dijit.form.FilteringSelect");
|
20 | 20 | dojo.require("dijit.form.Form");
|
21 | 21 | dojo.addOnLoad(function(){
|
22 |
| - dojo.declare("Model", null, { |
23 |
| - data : null, |
24 |
| - |
25 |
| - constructor : function(url, callback) { |
26 |
| - var resultHandler = this.load; |
27 |
| - var onload = (!callback ? function(){} : callback); |
28 |
| - var deferred = dojo.xhrGet({ |
29 |
| - url : url.match(/.*[^\?form]/)[0], |
| 22 | + |
| 23 | + var controller = { |
| 24 | + basePath : location.protocol + "//" + location.host + "/" + (location.pathname.search(/spring-html5/) > -1 ? "spring-html5/" : ""), |
30 | 25 |
|
| 26 | + getModel : function(url) { |
| 27 | + return dojo.xhrGet({ |
| 28 | + url : url.match(/.*[^\?form]/)[0], |
| 29 | + |
31 | 30 | preventCache : true,
|
32 |
| - |
| 31 | + |
33 | 32 | handleAs : "json",
|
34 |
| - |
| 33 | + |
35 | 34 | headers : {
|
36 | 35 | "Content-Type": "application/json",
|
37 | 36 | "Accept": "application/json"
|
38 | 37 | }
|
39 | 38 | });
|
40 |
| - var that = this; |
41 |
| - deferred.addCallback(function(result){ |
42 |
| - that.data = result; |
43 |
| - onload(); |
44 |
| - }); |
45 |
| - } |
46 |
| - }); |
47 |
| - |
48 |
| - var controller = { |
49 |
| - basePath : location.protocol + "//" + location.host + "/" + (location.pathname.search(/spring-html5/) > -1 ? "spring-html5/" : ""), |
| 39 | + }, |
| 40 | + |
50 | 41 | getView : function(url) {
|
51 | 42 | var view = { requiresModel : true };
|
52 | 43 | var hasIdentifier = false;
|
|
75 | 66 | view.template = template;
|
76 | 67 | return dojo.isFunction(view.template) ? view : null;
|
77 | 68 | },
|
| 69 | + |
78 | 70 | renderView : function(view, url) {
|
79 |
| - if (view.requiresModel) { |
80 |
| - var model = new Model(url, function(){ |
81 |
| - var content = view.template.apply(window, [{model : model.data}]); |
82 |
| - dojo.html.set(main, content, {parseContent:true, |
83 |
| - onBegin: function(){ |
84 |
| - var existing = dijit.byId("content"); |
85 |
| - if (existing) { |
86 |
| - existing.destroyRecursive(); |
87 |
| - } |
88 |
| - }, |
89 |
| - onEnd: function(){ |
90 |
| - this.inherited("onEnd", arguments); |
91 |
| - dojo.query("#content a").forEach(function(navItem) { |
92 |
| - dojo.connect(navItem, "onclick", function(e) { |
93 |
| - var main = dojo.byId("main"); |
94 |
| - var view = controller.getView(navItem.href); |
95 |
| - if (view) { |
96 |
| - dojo.stopEvent(e); |
97 |
| - controller.renderView(view, navItem.href); |
98 |
| - } |
99 |
| - }); |
100 |
| - }); |
101 |
| - dijit.byId("content").toggle(); |
102 |
| - } |
103 |
| - }); |
104 |
| - }); |
105 |
| - } else { |
106 |
| - var content = view.template.apply(window, [{}]); |
| 71 | + var model = view.requiresModel ? controller.getModel(url) : null; |
| 72 | + dojo.when(model, function(model){ |
| 73 | + var content = view.template.apply(window, [{model : model}]); |
107 | 74 | dojo.html.set(main, content, {parseContent:true,
|
108 | 75 | onBegin: function(){
|
109 | 76 | var existing = dijit.byId("content");
|
|
123 | 90 | }
|
124 | 91 | });
|
125 | 92 | });
|
| 93 | + |
126 | 94 | dijit.byId("content").toggle();
|
127 | 95 | }
|
128 |
| - |
129 | 96 | });
|
130 |
| - } |
| 97 | + }); |
| 98 | + |
131 | 99 | if(location.href != url) {
|
132 |
| - history.pushState({}, "", url); |
| 100 | + history.pushState({}, "view", url); |
133 | 101 | }
|
134 | 102 | }
|
135 | 103 | };
|
| 104 | + |
136 | 105 | dojo.query("a.menuItem").forEach(function(menuItem) {
|
137 | 106 | dojo.connect(menuItem, "onclick", function(e) {
|
138 | 107 | var main = dojo.byId("main");
|
|
143 | 112 | }
|
144 | 113 | });
|
145 | 114 | });
|
| 115 | + |
146 | 116 | dojo.connect(window, "onpopstate", function(e){
|
147 | 117 | if(location.href.search(/html5-index/) > -1) {
|
148 | 118 | location.reload();
|
|
0 commit comments