Statistics
| Branch: | Tag: | Revision:

root / ui / templates / list.html @ fb66080c

History | View | Annotate | Download (6.8 kB)

1
<div id="machinesview" class="list">
2
    <div id="spinner"></div>
3
    <div class="actions">
4
        <a id="action-start">Start</a>
5
        <a id="action-reboot">Reboot</a>
6
        <a id="action-shutdown">Shutdown</a>
7
        <br />
8
        <a id="action-destroy">Destroy</a>
9
        <br />
10
        <a id="action-details">Show Details</a>
11
        <a id="action-group">Add to group</a>
12
        <br />
13
        <a id="action-band">Out of band</a>
14
        <br />
15
        <a id="action-attach">Attach disk</a>
16
        <a id="action-detach">Detach disk</a>
17
        <br />
18
        <a id="action-connect">Connect to network</a>
19
        <a id="action-disconnect">Disconnect from net</a>
20
    </div>
21
    <table>
22
        <thead> 
23
            <tr> 
24
                <th id="selection" class="select-running">
25
                    <input type="checkbox"/>
26
                    <ul>
27
                        <li><a class="select-all" href="#">All</a></li>
28
                        <li><a class="select-none" href="#">None</a></li>
29
                        <li><a class="select-group" href="#">group</a></li>
30
                    </ul>                
31
                </th> 
32
                <th id="os">OS</th> 
33
                <th id="name">Name</th> 
34
                <th id="ip">IP</th> 
35
                <th id="group">Group</th>
36
                <th id="status">Status</th> 
37
                <th class="scroll"></th>
38
            </tr>
39
            <tr id="machine-template" style="display: none">
40
                <td><input type="checkbox" id="node-id" /></td>
41
                <td><span class="imagetag"></span><img class="list-logo" src="" width="16" height="16" /></td>
42
                <td><a class="name"><span class="name">node.name</span></a></td> 
43
                <td><a class="ip"><span class="public">node.public_ip</span></a></td>
44
                <td>group</td>
45
                <td class="status">Running</td>
46
            </tr>                        
47
        </thead> 
48
        <tbody class="running">
49

    
50
        </tbody>
51
    </table>
52
    <div id="mini" class="seperator"></div>
53
    <table>
54
        <thead> 
55
            <tr> 
56
                <th id="selection" class="select-terminated">
57
                    <input type="checkbox"/>
58
                    <ul>
59
                        <li><a class="select-all" href="#">All</a></li>
60
                        <li><a class="select-none" href="#">None</a></li>
61
                        <li><a class="select-group" href="#">group</a></li>
62
                    </ul>  
63
                </th> 
64
                <th id="os">OS</th> 
65
                <th id="name">Name</th> 
66
                <th id="ip">IP</th> 
67
                <th id="group">Group</th>
68
                <th id="status">Status</th> 
69
            </tr>  
70
        </thead> 
71
        <tbody class="terminated"></tbody>
72
    </table>
73
</div>
74

    
75

    
76
<script>
77

78
// select/deselect all from checkbox widget of table headers
79
$("table thead tr th#selection :checkbox").live('change', function() {
80
    // select/deselect running or terminated?
81
    var state = $(this).parent().attr("class").replace('select-','');
82
    if ( $(this).is(":checked") ) {
83
        $("." + state + " :checkbox").attr("checked", true);
84
    }
85
    else {
86
        $("." + state + " :checkbox").attr("checked", false);
87
    }
88
        updateActions();
89
});
90

91
// select all/none from drop down menu
92
$("table thead tr th#selection ul li a").live('click', function() {
93
    // find the state of the machines
94
    var state = $(this).closest("th#selection").attr("class").replace('select-','');
95
    // all or none?
96
    var all = ($(this).attr("class") == "select-all");
97
    // toggle checkboxes
98
    $("." + state + " :checkbox").attr("checked", all);
99
    // update actions
100
        updateActions();
101
});
102

103
// select group from drop down menu
104
$("table thead tr th#selection ul li a.select-group").live('click', function() {
105
    // find the state of the machines
106
    var state = $(this).closest("th#selection").attr("class").replace('select-','');
107
    $("." + state + " :checkbox").attr("checked", true);
108
        updateActions();
109
});
110

111
var actions = { 'reboot':                ['PE_VM_RUNNING', 'PE_VM_MIGRATING', 'multiple'],
112
                                'shutdown':                ['PE_VM_RUNNING', 'PE_VM_MIGRATING', 'multiple'],
113
                                'connect':                ['PE_VM_RUNNING', ],
114
                                'disconnect':        ['PE_VM_RUNNING', 'network'],
115
                                'band':                        ['PE_VM_RUNNING', 'PE_VM_MIGRATING'],
116
                                'details':                ['PE_VM_RUNNING', 'PE_VM_MIGRATING', 'PE_VM_SUSPENDED'],
117
                                'start':                 ['PE_VM_SUSPENDED', 'multiple'],
118
                                'destroy':                ['PE_VM_RUNNING', 'PE_VM_SUSPENDED', 'PE_VM_MIGRATING', 'multiple'],
119
                                'group':                ['PE_VM_RUNNING', 'PE_VM_SUSPENDED', 'PE_VM_MIGRATING','multiple'],
120
                           };
121

122
// on checkbox click, update the actions
123
$("tbody input[type='checkbox']").live('change', function() { updateActions(); });
124

125
function updateActions() {
126
        var states = [];
127
        var on = [];
128
        var checked = $("table tbody input[type='checkbox']:checked").toArray();
129
        
130
        // disable all actions to begin with
131
        for (action in actions) {
132
                $("#action-" + action).removeClass('enabled');
133
        }
134

135
        // are there multiple machines selected?
136
        if (checked.length>1)
137
                states[0] = 'multiple';
138
        
139
        // check the states of selected machines
140
        checked.forEach(function(checkbox) {
141
                states[states.length] = checkbox.className;
142
                var ip = $("#" + checkbox.id.replace('input-','') + ".ip span.public").text();
143
                if (ip.replace('undefined','').length)
144
                        states[states.length] = 'network';
145
        });
146

147
        // decide which actions should be enabled
148
        for (a in actions) {
149
                var enabled = false;
150
                for (s in states) {
151
                        if (actions[a].indexOf(states[s]) != -1 ) {
152
                                enabled = true;
153
                        } else {
154
                                enabled = false;
155
                                break;
156
                        }
157
                }
158
                if (enabled)
159
                        on[on.length]=a;
160
        }
161
        // enable those actions
162
        for (action in on) {
163
                $("#action-" + on[action]).addClass('enabled');
164
        }
165
}
166

167
// destroy action
168
$("a.enabled#action-destroy").live('click', function() {
169
        var checked = $("tbody input[type='checkbox']:checked").toArray();        
170
        for (c in checked) {
171
                $.ajax({
172
                        url: '/api/v1.0/servers/' + checked[c].id.replace('input-',''),
173
                        type: "DELETE",
174
                        //async: false,
175
                        dataType: "json",
176
                        success: function() {}
177
                });
178
        }
179
});
180

181
// reboot action
182
$("a.enabled#action-reboot").live('click', function() {
183
        var checked = $("tbody input[type='checkbox']:checked").toArray();        
184
        for (c in checked) {
185
                $.ajax({
186
                        url: '/api/v1.0/servers/' + checked[c].id.replace('input-','') + '/action',
187
                        type: "POST",
188
                        data: {
189
                                "reboot": '{"type" : "HARD"}'
190
                                },
191
                        //async: false,
192
                        dataType: "json",
193
                        success: function() {}
194
                });
195
        }
196
});
197

198
// shutdown action. Not implemented by rackspace API atm
199
$("a.enabled#action-shutdown").live('click', function() {
200
        var checked = $("tbody input[type='checkbox']:checked").toArray();        
201
        for (c in checked) {
202
                $.ajax({
203
                        url: '/api/v1.0/servers/' + checked[c].id.replace('input-','') + '/action',
204
                        type: "POST",
205
                        data: {
206
                                "shutdown": '{"timeout" : "5"}'
207
                                },
208
                        //async: false,
209
                        dataType: "json",
210
                        success: function() {}
211
                });
212
        }
213
});
214

    
215
</script>