Fix error when sorting Job list by object.
[ganeti_webmgr.git] / ganeti_web / static / js / replace_disks_form.js
blob56a0b8a661e8bd1fe03dae969bbbc12f06dfbc54
1 $(function() {
2 /* Live form updating for the create VM template */
4 // -----------
5 // class data
6 // -----------
7 var mode = $("#id_mode");
8 var node = $("#id_node");
9 var iallocator = $("#id_iallocator");
10 var iallocator_hostname = $("#id_iallocator_hostname");
11 var using_str = " Using: ";
13 // ------------
14 // init stuffs
15 // ------------
16 function init(){
17 /* initialize the live form updater */
18 _initChangeHooks();
20 // disable the iallocator stuff by default
21 if(!iallocator_hostname.attr("value")){
22 iallocator.attr("readonly", "readonly");
23 } else{
24 iallocator.after(
25 "<span>" +
26 using_str + iallocator_hostname.val() +
27 "</span>"
31 // only disable iallocator by default if there is no cluster selected
32 // or the cluster already selected does not support iallocator
33 var def_iallocator = iallocator_hostname.val();
34 if (!iallocator.is(":checked")
35 && (def_iallocator == undefined|| def_iallocator == '')
37 _iallocatorDisable();
40 // fire off some initial changes
41 iallocator.change();
42 mode.change();
45 function _initChangeHooks(){
46 /* setup change hooks for the form elements */
47 // iallocator change
48 iallocator.live("change", function() {
49 if(!iallocator.attr("readonly")) {
50 if(iallocator.is(":checked")) {
51 _nodeDisable();
52 } else {
53 _nodeEnable();
55 } else {
56 if(!iallocator.is(":checked")){
57 _nodeEnable();
60 });
62 mode.live("change", function(){
63 if ('replace_new_secondary' == mode.val()) {
65 var def_iallocator = iallocator_hostname.val();
66 if (def_iallocator == undefined || def_iallocator == ''){
67 _nodeEnable();
68 } else {
69 _iallocatorEnable();
72 } else {
73 _iallocatorDisable();
74 _nodeDisable();
79 function _nodeEnable(){
80 /* Disable and hide all of the node stuffs */
81 node.parent().parent().show();
82 node.removeAttr("disabled")
83 .change();
86 function _iallocatorEnable(){
87 /* Disable and hide all of the iallocator stuffs */
88 iallocator.parent().parent("tr").show();
89 iallocator.removeAttr("disabled")
90 .change();
93 function _nodeDisable(){
94 /* Disable and hide all of the node stuffs */
95 node.parent().parent().hide();
96 node.attr("disabled", "disabled")
97 .change();
100 function _iallocatorDisable(){
101 /* Disable and hide all of the iallocator stuffs */
102 iallocator.parent().parent("tr").hide();
103 iallocator.attr("disabled", "disabled")
104 .change();
107 init();