fix javascript error if enacted is undefined
[plstackapi.git] / planetstack / core / xoslib / templates / xosAdmin.html
1 <!-- Error and Success templates -->
2
3 <script type="text/template" id="xos-error-response">
4   <h5>Error</h5>
5   <table>
6   <tr><td>error:</td><td><%= error %></td></tr>
7   <tr><td>check:</td><td><%= specific_error %></td></tr>
8   </table>
9   <h5>Details:</h5>
10       <table>
11       <tbody>
12       <% _.each(reasons, function(element, index) { %>
13           <tr><td><%= index %></td><td><%= element %></td></tr>
14       <% }); %>
15       </tbody>
16       </table>
17 </script>
18
19 <script type="text/template" id="xos-error-rawresponse">
20   <h5>Error</h5>
21   <pre>The server returned:
22 "<%= responseText %>"</pre>
23 </script>
24
25 <script type="text/template" id="xos-error-template">
26   <button id="close-error-box">Close Error Message</button>
27   <h3>An error has occurred.</h3>
28   <table class="test-error-table">
29   <tr><td>Code:</td><td><%= status %></td></tr>
30   <tr><td>Message:</td><td><%= statusText %></td></tr>
31   </table>
32 </script>
33
34 <script type="text/template" id="xos-success-template">
35   <button id="close-success-box">Close Success Message</button>
36   <h3>Success!</h3>
37   <table class="test-success-table">
38   <tr><td>Code:</td><td><%= status %></td></tr>
39   <tr><td>Message:</td><td><%= statusText %></td></tr>
40   </table>
41 </script>
42
43 <script type="text/template" id="xos-navbutton-old">
44   <button class="btn btn-default btn-xosnav" onclick="<%= router %>.navigate('<%= routeUrl %>', {trigger: true})"><%= name %></button><br>
45 </script>
46
47 <script type="text/template" id="xos-status-template">
48   <div class="xos-status xos-<%= statusclass %>"><%= what %>: <%= statusText %> (<%= status %>)</div>
49 </script>
50
51 <script type="text/template" id="xos-tabs-template">
52   <ul class="xos-nav-list">
53   <% _.each(tabs, function(tab) { %>
54       <li class="xos-nav-item" id="xos-nav-<%= tab["region"] %>"><%= tab["name"] %></li>
55   <% }); %>
56   </ul>
57 </script>
58
59 <script type="text/template" id="xos-title-list">
60   <h3><img src="/static/img/brokencircle.gif" height=16 width=16 id="xos-list-title-spinner"> <%= title %></h3>
61 </script>
62
63 <script type="text/template" id="xos-title-detail">
64   <h3><%= title %></h3>
65 </script>
66
67 <script type="text/template" id="xos-navbutton">
68   <li>
69       <a href="<%= routeUrl %>">
70           <i class="<%= iconClass %>"></i>
71           <%= name %>
72       </a>
73   </li>
74 </script>
75
76 <script type="text/template" id="xos-inline-detail-buttons-template">
77     <tr>
78        <td colspan=2><button class="btn js-submit btn-xos-detail btn-xos-save-leave">Save</button>
79            <button class="btn js-submit btn-xos-detail btn-xos-save-continue">Save and Continue Editing</button>
80            <button class="btn js-submit btn-xos-detail btn-xos-save-another">Save and Add Another</button>
81            <button class="btn js-submit btn-xos-detail btn-xos-delete">Delete</button>
82        </td>
83     </tr>
84 </script>
85
86 <script type="text/template" id="xos-backend-status-icon-template">
87     <% if (model.enacted === undefined) { %>
88         <!-- enacted is undefined; this must be a new object -->
89     <% } else if ((enacted) && (enacted >= updated)) { %>
90         <span style="min-width:16px;"><img src="/static/admin/img/icon_success.gif"></span>
91     <% } else { %>
92         <% if ((backend_status == "Provisioning in progress") || (!backend_status)) { %>
93             <span style="min-width:16px;" title="<%= _.escape(backend_status) %>"><img src="/static/admin/img/icon_clock.gif"></span>
94         <% } else { %>
95             <span style="min-width:16px;" title="<%= _.escape(backend_status) %>"><img src="/static/admin/img/icon_error.gif"></span>
96         <% } %>
97     <% } %>
98 </script>
99
100 <script type="text/template" id="xos-backend-status-text-template">
101     <%= xosBackendStatusIconTemplate.apply(this,arguments) %>
102     <% if (model.enacted === undefined) { %>
103         <!-- enacted is undefined; this must be a new object -->
104     <% } else if ((enacted) && (enacted >= updated)) { %>
105         Successfully enacted
106     <% } else { %>
107         <%= _.escape(backend_status) %>
108     <% } %>
109 </script>
110
111 <script type="text/template" id="xos-list-header-template">
112     <button class="btn js-submit btn-xos-list btn-xos-add">Add</button>
113     <button class="btn js-submit btn-xos-list btn-xos-refresh">Refresh</button>
114 </script>
115
116 <script type="text/template" id="xos-list-footer-template">
117     <% if (addChildHash) { %>
118         <a href="<%= addChildHash %>">Add...</a>
119     <% } %>
120 </script>
121
122 <script type="text/template" id="xos-delete-button-template">
123     <a href="#delete<%= firstCharUpper(modelName) %>/<%= id %>">delete</a>
124 </script>
125
126 <script type="text/template" id="xos-detail-link-template">
127     <a href="#<%= collectionName %>/<%= id %>"><%= text %></a>
128 </script>
129
130 <script type="text/template" id="xos-add-template">
131   <h3 class="xos-detail-title">Add Object: <%= modelName %></h3>
132   <form>
133   <table>\r
134   <% args = arguments; %>\r
135   <% _.each(addFields, function(fieldName) { %>\r
136      <tr><td><%= fieldNameToHumanReadable(fieldName) %>:</td>\r
137         <% readOnly = $.inArray(fieldName, model.readOnlyFields)>=0 ? " readonly" : "";  %>\r
138         <% if (fieldName in foreignFields) { %>\r
139             <td><%= idToSelect(fieldName, model.attributes[fieldName], foreignFields[fieldName], "humanReadableName", readOnly) %></td>\r
140         <% } else if (inputType[fieldName] == "checkbox") { %>\r
141             <td><input type="checkbox" name="<%= fieldName %>" <% if (model.attributes[fieldName]) print("checked"); %><%= readOnly %>></td>\r
142         <% } else if (fieldName=="backend_status") { %>\r
143             <td><%= xosBackendStatusTextTemplate.apply(this, args) %></td>\r
144         <% } else { %>\r
145             <td><input type="text" name="<%= fieldName %>" value="<%= model.attributes[fieldName] %>"<%= readOnly %>></td>\r
146         <% } %>\r
147      </tr>\r
148   <% }); %>\r
149   <%= xosInlineDetailButtonsTemplate() %>\r
150   </table>\r
151   </form>\r
152 </script>
153
154 <script type="text/template" id="xos-detail-template">
155   <h3 class="xos-detail-title">Edit Object: <%= modelName %></h3>
156   <form>
157   <table>\r
158   <% args = arguments; %>\r
159   <% _.each(detailFields, function(fieldName) { %>\r
160      <tr><td><%= fieldNameToHumanReadable(fieldName) %>:</td>\r
161         <% readOnly = $.inArray(fieldName, model.readOnlyFields)>=0 ? " readonly" : "";  console.log(fieldName + " " + readOnly); console.log(model.readOnlyFields); %>\r
162         <% if (fieldName in foreignFields) { %>\r
163             <td><%= idToSelect(fieldName, model.attributes[fieldName], foreignFields[fieldName], "humanReadableName", readOnly) %></td>\r
164         <% } else if (inputType[fieldName] == "checkbox") { %>\r
165             <td><input type="checkbox" name="<%= fieldName %>" <% if (model.attributes[fieldName]) print("checked"); %><%= readOnly %>></td>\r
166         <% } else if (inputType[fieldName] == "picker") { %>\r
167             <% lookupFunc = makeIdToName(model.m2mFields[fieldName], "humanReadableName"); %>\r
168             <td><%= xosPickerTemplate({pickedItems: model.attributes[fieldName], unpickedItems: model.getChoices(fieldName,true), id: "picker_" + fieldName, fieldName: fieldName, detailView: detailView, lookupFunc: lookupFunc}) %></td>\r
169         <% } else if (fieldName=="backend_status") { %>\r
170             <td><%= xosBackendStatusTextTemplate.apply(this, args) %></td>\r
171         <% } else { %>\r
172             <td><input type="text" name="<%= fieldName %>" value="<%= model.attributes[fieldName] %>"<%= readOnly %>></td>\r
173         <% } %>\r
174      </tr>\r
175   <% }); %>\r
176   <%= xosInlineDetailButtonsTemplate() %>\r
177   </table>\r
178   </form>\r
179 </script>
180
181 <script type="text/template" id="xos-list-template">
182   <h3 class="xos-list-title"><%= title %></h3>
183   <%= xosListHeaderTemplate() %>
184   <table class="test-table">
185   <thead>
186   <tr>
187   <% _.each(listFields, function(fieldName) { %>
188       <th><%= fieldNameToHumanReadable(fieldName) %></th>
189   <% }); %>
190   <th>delete</th>
191   </tr></thead>
192   <tbody></tbody>
193   </table>
194   <%= xosListFooterTemplate({addChildHash: addChildHash}) %>
195 </script>
196
197 <script type="text/template" id="xos-listitem-template">
198   <% _.each(listFields, function(fieldName) { %>
199       <% if ($.inArray(fieldName, model.detailLinkFields)>=0) { %>
200           <td><%= xosDetailLinkTemplate({collectionName: collectionName, id: id, text: model.attributes[fieldName]}) %></td>
201       <% } else if (fieldName in foreignFields) { %>
202           <td><%= idToName(model.attributes[fieldName], foreignFields[fieldName], "humanReadableName") %></td>
203       <% } else { %>
204       <td><%= model.attributes[fieldName] %></td>
205       <% } %>
206   <% }); %>
207   <td><%= xosDeleteButtonTemplate({modelName: modelName, id: id}) %></td>
208 </script>
209
210 <script type="text/template" id="xos-savebuttons-template">
211   <div class="box save-box">
212     <button class="btn btn-high btn-info btn-xos-contentButtonPanel btn-xos-save-leave">Save</button>
213     <button class="btn btn-high btn-xos-contentButtonPanel btn-xos-save-continue">Save and continue editing</button>
214     <button class="btn btn-high btn-xos-contentButtonPanel btn-xos-save-another">Save and add another</button>
215     <button class="btn btn-danger btn-xos-contentButtonPanel btn-xos-delete">Delete</button>
216   </div>
217 </script>
218
219 <script type="text/template" id="xos-listbuttons-template">
220   <div class="box save-box">
221     <button class="btn btn-high btn-primary btn-xos-contentButtonPanel btn-xos-refresh">Refresh</button>
222     <button class="btn btn-high btn-success btn-xos-contentButtonPanel btn-xos-add">Add</button>
223   </div>
224 </script>
225
226
227 <script type="text/template" id="xos-picker-template">
228     <!-- arguments: unpickedItems, pickedItems -->
229     <div id="<%= id %>">
230     <div class="picker_row">
231     <div class="picker_column">\r
232     <div>Available</div>\r
233     <select name="pickerfrom" class="select-picker-from" multiple size="5">\r
234         <% _.each(unpickedItems, function(item) { %>\r
235            <option value="<%= item %>"><%= lookupFunc? lookupFunc(item) : item %></option>
236         <% });%>\r
237     </select>\r
238     </div>\r
239     <div class="picker_column">\r
240     <br>\r
241     <div class="btn btn-success btn-picker-add">Add &raquo;</div><br><br>\r
242     <div class="btn btn-success btn-picker-remove">&laquo; Remove</div>\r
243     </div>\r
244     <div class="picker_column">\r
245     <div>Selected</div>\r
246     <select name=<%= fieldName %> class="select-picker-to syphonall" multiple size="5">\r
247         <% _.each(pickedItems, function(item) { %>\r
248            <option value="<%= item %>"><%= lookupFunc ? lookupFunc(item) : item %></option>
249         <% }); %>\r
250     </select>\r
251     </div>\r
252     <div class="picker_column">\r
253     <br>\r
254     <div class="btn btn-success btn-picker-up">Up</div><br><br>\r
255     <div class="btn btn-success btn-picker-down">Down</div>\r
256     </div>\r
257     </div>
258     </div>
259     <% detailView.viewInitializers.push( function() { init_picker("#" + id); } ); %>
260 </script>
261
262 <script>
263 xosInlineDetailButtonsTemplate = _.template($("#xos-inline-detail-buttons-template").html());
264 xosListHeaderTemplate = _.template($("#xos-list-header-template").html());
265 xosListFooterTemplate = _.template($("#xos-list-footer-template").html());
266 xosDeleteButtonTemplate = _.template($("#xos-delete-button-template").html());
267 xosDetailLinkTemplate = _.template($("#xos-detail-link-template").html());
268 xosBackendStatusIconTemplate = _.template($("#xos-backend-status-icon-template").html());
269 xosBackendStatusTextTemplate = _.template($("#xos-backend-status-text-template").html());
270 xosPickerTemplate = _.template($("#xos-picker-template").html());
271 </script>
272