OSDN Git Service

modified
[karesansui/karesansui.git] / karesansui / templates / default / guest / guest.part
1 <%doc>Copyright (C) 2009 HDE, Inc.</%doc>
2 <%inherit file="../include/common.part" />
3
4 <%!
5 from karesansui.lib.template import img_status, str_status, clipping
6 from karesansui.lib.const import MACHINE_NAME_CLIPPING_RANGE
7 %>
8 <script type="text/javascript">
9 <!--
10 $(document).ready(function(){
11
12 // lib
13 function guest_location(id){
14     var uri = "${ctx.homepath}${ctx.path}".replace(".part", "");
15     location.href = uri + "/" + id + ".html";
16 }
17 function get_target_id(){
18     var target_id = null;
19     $("#guests div").each(function(){
20         if($(this).hasClass("active") == true){
21             target_id = $(this).attr("id").replace("guest_", "");
22         }
23     });
24     return target_id
25 }
26 // init
27 var active_id;
28 var past_active_id;
29 var uri;
30 $("#guests div").each(function(){
31     // event
32     $(this).click(function(){
33         past_active_id = active_id
34         active_id = $(this).attr("id").replace("guest_", "")
35         
36         if($(this).hasClass("active") == true){
37             guest_location(active_id);
38         }
39
40         if($(this).hasClass("passive") == true){
41             uri = "${ctx.homepath}${ctx.path}".replace(".part", "");
42             // guest 
43             ajax_json(
44                 uri + "/" + active_id + ".json",
45                 null,
46                 function(data, status) {
47                         var _s = "<table class='detail-contents'>";
48
49                         // General
50                         var _g = "<table cellspacing='0' cellpadding='0' class='detail-sub-contents'>";
51                         _g += make_tr("${_('Name')}", data.model.name);
52                         _g += make_tr("${_('State')}", str_status(data.virt.state));
53                         _g += make_tr("${_('Unique Key')}", data.model.uniq_key);
54                         _g += make_tr("${_('Domain Name')}", data.virt.name);
55
56                         var autostart = "";
57                         if(data.autostart == true){
58                             autostart = "${_('ON')}";
59                         } else {
60                             autostart = "${_('OFF')}";
61                         }
62                         _g += make_tr("${_('Autostart')}", autostart);
63
64                         var os = "";
65                         if(data.info["os"] != null){
66                             os = data.info["os"];
67                         } else {
68                             os = "${_('Unknown')}";
69                         }
70                         _g += make_tr("${_('OS Type')}", os);
71
72                         var tags = ""
73                         if(data.model.tags.length > 0){
74                             for(var i = 0; i < data.model.tags.length; i++){
75                                 tags += data.model.tags[i].name + ", ";
76                             }
77                             tags = tags.slice(0, tags.length - 2)
78                         } else {
79                             tags = "${_('No tag')}"
80                         }
81                         _g += make_tr("${_('Tag Name')}", tags);
82
83                         _g += "</table>";
84                         _s += make_tr("${_('General Information')}", _g, true);
85
86                         _s += make_space()
87
88                         // Note
89                         var _n = "<table cellspacing='0' cellpadding='0' class='detail-sub-contents'>";
90                         var notebook_title = ""
91                         if(data.model.notebook.title != ""){
92                             notebook_title = data.model.notebook.title
93                         } else {
94                             notebook_title = "${_('No title')}"
95                         }
96                         _n += make_tr("${_('Title')}", notebook_title);
97
98                         var notebook_value = ""
99                         if(data.model.notebook.value != ""){
100                             notebook_value = data.model.notebook.value
101                         } else {
102                             notebook_value = "${_('N/A')}"
103                         }
104                         _n += make_tr("${_('Note')}", notebook_value);
105
106                         _n += "</table>";
107                         _s += make_tr("${_('Notebook')}", _n, true);
108
109                         _s += make_space()
110
111                         // Device
112                         var _d = "<table cellspacing='0' cellpadding='0' class='detail-sub-contents'>";
113                         _d += make_tr("${_('CPU Time (seconds)')}", format_cputime(data.info["cpu"] / (1000.00 * 1000.00 * 1000.00)));
114                         _d += make_tr("${_('Memory Size (MB)')}", Math.floor(data.info["memory"] / 1024));
115
116                         var disks = "";
117                         if(data.diskinfo.length > 0){
118                             disks = join_comma(data.diskinfo)
119                         } else {
120                             disks = "${_('No Disk')}"
121                         }
122                         _d += make_tr("${_('Disk Info')}", disks);
123
124                         var inters = "";
125                         if(data.interfaceinfo.length > 0){
126                             inters = join_comma(data.interfaceinfo)
127                         } else {
128                             inters = "${_('No interface')}"
129                         }
130                         _d += make_tr("${_('Interface Info')}", inters);
131
132                         var nets = "";
133                         if(data.netinfo.length > 0){
134                             nets = join_comma(data.netinfo)
135                         } else {
136                             nets = "${_('No network')}"
137                         }
138                         _d += make_tr("${_('Network Info')}", nets);
139
140                         _d += "</table>";
141                         _s += make_tr("${_('Device')}", _d, true);
142
143                         _s += make_space()
144
145                         // Audit
146                         var _a = "<table cellspacing='0' cellpadding='0' class='detail-sub-contents'>";
147                         _a += make_tr("${_('Created User')}", data.model.created_user.nickname);
148                         _a += make_tr("${_('Modified User')}", data.model.modified_user.nickname);
149                         _a += make_tr("${_('Date Created')}", data.model.created);
150                         _a += make_tr("${_('Date Modified')}", data.model.modified);
151                         _a += "</table>";
152                         _s += make_tr("${_('Audit')}", _a, true);
153
154                         _s += "</table>";
155                         $("#detail_value").html(_s);
156
157                 },
158                 false
159             );
160             // privent illegal error by assign class complete ajax communication
161             $("#guests div").each(function() {
162                 $(this).removeClass("active").addClass("passive")
163             });
164             $(this).removeClass("passive").addClass("active")
165             if(typeof(past_active_id) != "undefined"){
166                 $("#guest_" + past_active_id).unbind("click.active");
167             }
168
169         }
170     });
171     
172     // first click event
173     $(this).one("click.once", function(){
174         // edit
175          $("#edit_guest").click(function(){
176             var target_id = get_target_id();
177             if(target_id != null){
178                 grayout_open("GET",
179                     "${ctx.homepath}/grayout.part",
180                     "${ctx.homepath}");
181                 grayout_view("GET",
182                     uri + "/" + target_id + ".part?mode=input",
183                     "${_('Guest Settings')}",
184                     "${ctx.homepath}${ctx.path}");
185             } else {
186                 alert_on(".alert", "ERROR", "${_('Please select a target.')}");
187             }
188         });
189         tool_reset("#edit_guest");
190
191         // -- replicate
192         $("#replicate_guest").click(function(){
193             var target_id = get_target_id();
194             if(target_id != null){
195                 grayout_open("GET",
196                     "${ctx.homepath}/grayout.part",
197                     "${ctx.homepath}");
198                 grayout_view("GET",
199                     uri + "/replicate?mode=input&src_id=" + target_id,
200                     "${_('Guest Settings')}",
201                     "${ctx.homepath}${ctx.path}");
202             } else {
203                 alert_on(".alert", "ERROR", "${_('Please select a target.')}");
204             }
205         });
206         tool_reset("#replicate_guest");
207         
208         // -- delete
209         $("#delete_guest").click(function(){
210             var target_id = get_target_id();
211             if(target_id != null){
212                 url = uri + "/" + target_id + ".part";
213                 reflush = "${ctx.homepath}${ctx.path}"
214                 param = null;
215                 delete_dialog("#dialog", url, param, reflush, "#delete_guest");
216             } else {
217                 alert_on(".alert", "ERROR", "${_('Please select a target.')}");
218             }
219         });
220         tool_reset("#delete_guest");
221
222         $("#guests div").each(function(){
223             $(this).unbind("click.once");
224         });
225     }); 
226     renew_main_event("#tool_renew", "${ctx.homepath}${ctx.path}");
227 });
228
229 // event
230 $("#create_guest").click(function(){
231     grayout_open("GET",
232         "${ctx.homepath}/grayout.part",
233         "${ctx.homepath}"
234         )
235     grayout_view("GET",
236         "${ctx.homepath}${ctx.path}?mode=input",
237         "${_('Guest Settings')}",
238         "${ctx.homepath}${ctx.path}");
239 });
240 show_detail_event();
241
242 // tag
243 tag_get_event(
244     "#tag",
245     "#guests",
246     "#detail_value",
247     "${ctx.homepath}${ctx.path}".replace(".part", "") + "/tag.part"
248 );
249 // init action
250 $("#action>a").hover(
251     function(){tool_over(this);},
252     function(){tool_over(this);}
253 ).mousedown(function(){
254     var id = $(this).attr("id");
255     tool_active(this);
256 });
257 tool_invalid("#edit_guest");
258 tool_invalid("#replicate_guest");
259 tool_invalid("#delete_guest");
260
261 });
262 // -->
263 </script>
264 <div class="alert"></div>
265 <div id="dialog"></div> 
266                     <div id="action" >
267                                 <div class="left"></div>
268
269                         <a href="#" class="tool-link" name="create_guest" id="create_guest">
270                             <div class="tool-mid">
271                                 <div class="tool-left"></div>
272                                 <div class="tool-img">
273                                     <img src="${ctx.homepath}/static/images/tool-add.png" alt="" />
274                                 </div>
275                                 <div class="tool-right">
276                                     <div class="tool-text">${_('Create')}</div>
277                                 </div>
278                             </div>
279                         </a>
280                         <a href="#" class="tool-link" id="edit_guest">
281                             <div class="tool-mid">
282                                 <div class="tool-left"></div>
283                                 <div class="tool-img">
284                                     <img src="${ctx.homepath}/static/images/tool-edit.png" alt="" />
285                                 </div>
286                                 <div class="tool-right">
287                                     <div class="tool-text">${_('Edit')}</div>
288                                 </div>
289                             </div>
290                         </a>
291                         <a href="#" class="tool-link" name="" id="replicate_guest">
292                             <div class="tool-mid">
293                                 <div class="tool-left"></div>
294                                 <div class="tool-img">
295                                     <img src="${ctx.homepath}/static/images/tool-copy.png" alt="" />
296                                 </div>
297                                 <div class="tool-right">
298                                     <div class="tool-text">${_('Copy')}</div>
299                                 </div>
300                             </div>
301                         </a>
302                         <a href="#" class="tool-link" name="delete_guest" id="delete_guest">
303                             <div class="tool-mid">
304                                 <div class="tool-left"></div>
305                                 <div class="tool-img">
306                                     <img src="${ctx.homepath}/static/images/tool-trash.png" alt="" />
307                                 </div>
308                                 <div class="tool-right">
309                                     <div class="tool-text">${_('Delete')}</div>
310                                 </div>
311                             </div>
312                         </a>
313
314                         <div class="right">
315                             <a href="#" class="tool-link" >
316                                 <div class="tool-mid">
317                                     <img src="${ctx.homepath}/static/images/reload.gif" alt="renew" id="tool_renew"/>
318                                 </div>
319                             </a>
320                         </div>
321                     </div>
322                     <br style="clear: both;"/>
323                     <div class="space"></div>
324
325
326                     <div id="tag">
327                         <div class="left"></div>
328                         <div class="right"></div>
329                         <div id="tag-main">
330                             <div class="value">
331                                 <ul>
332                                     <li>
333                                         <div class="text">${_('Now loading')}</div>
334                                     </li>
335                                 </ul>
336                             </div>
337                         </div>
338                         <div id="tag-progress"></div>
339                     </div>
340                     <br style="clear: both;"/>
341
342                         <div id="view">
343
344
345                                 <!-- host start -->
346                             <div id="guests">
347 % if guests:
348     % for guest in guests:
349                                 <div id="guest_${guest.info['model'].id}" class="passive">
350                                     <span class="status-b">
351                                         ${img_status(guest.info['virt'].status())}
352                                     </span>
353     % if guest.info['model'].webicon() is None:
354                                     <img src="${ctx.homepath}/static/images/notos.png" alt="" />
355     % else:
356                                     <img src="${guest.info['model'].webicon()}" alt="" width="124px" height="124px" />
357     % endif
358                                     <br/>
359                                     ${clipping(guest.info['model'].name, MACHINE_NAME_CLIPPING_RANGE) | h}
360                                     <br/>
361                                     <span class="status">
362                                         (${str_status(guest.info['virt'].status(), _)})
363                                     </span>
364                                 </div>
365     % endfor
366 % endif
367
368                             </div> 
369                         </div> 
370                         <br style="clear: both;"/>
371                         <div class="space"></div>
372                         <div id="detail">
373                             <div class="panel">
374                                 <div class="wrap">
375                                     <span class="title"> &nbsp;</span>
376                                     <p class="point"> </p>
377                                     <p>
378
379 <img src="${ctx.homepath}/static/images/tree-open.gif" alt="" id="show_detail_switch" class="tree-toggle-button"/><span class="msg-title">${_('Details')}</span><br />
380 <span id="detail_value">--</span>
381
382
383                                     </p>
384                                     <dl><dt>&nbsp;</dt></dl>
385                                 </div>
386                             </div>
387                         </div>
388                         <br style="clear: both;"/>