<commit_before><script>
  $(document).ready(function() {
    //cm-json_table_data = > load list of unused luns 
    LoadUnused_VolumeConf();
    //Volume JQuery data table init()
    var oVolumeConfiguration = $('#volume_configuration').dataTable( {
      "bProcessing": true,
      "bJQueryUI": true,
      "iDisplayLength": 25,
      "bAutoWidth":false,
      "oLanguage": {
        "sEmptyTable": "No Volumes to display"
      },
      "aoColumns": [
        { "sClass": 'txtleft' },
        { "sClass": 'txtleft' },
        { "sClass": 'txtleft' },
        { "sClass": 'txtright' },
        { "sClass": 'txtright' },
        { "bVisible": false },
        { "bVisible": false },
      ]
    });

    $("#btnApplyConfig").click(function ()
	{
      var oSetting = $('#volume_configuration').dataTable().fnSettings();
      var confirmation_markup = "This action will have the following consequences: <br /><br />";
      var api_params = {};
      var alun_ids = [];
      var aprimary_host_ids = [];
      var asecondary_host_ids = [];
      for (var i=1, iLen=oSetting.aoData.length; i<iLen; i++) 
      {
        if (oSetting.aoData[i]._aData[5] != oSetting.aoData[i]._aData[6])
        {
          params = oSetting.aoData[i]._aData[6].split("_") 
          alun_ids.push(parseInt(params[0]));
          aprimary_host_ids.push(parseInt(params[1]));
          asecondary_host_ids.push(parseInt(params[2]));
          confirmation_markup += "- Volume configuration change for "+oSetting.aoData[i]._aData[0]+"<br />";    
        }
      }
      if(alun_ids.length > 0)
      {
      	api_params = {'lun_ids': alun_ids, 'primary_host_ids': aprimary_host_ids, 'secondary_host_ids': asecondary_host_ids};
      	save_primary_failover_server(confirmation_markup, api_params);
      }
	});

    $('select[id *="_host"]').live('change', function ()
    {
      var oSetting = $('#volume_configuration').dataTable().fnSettings();
      //Note : Lun_id i storage as part of select control id E.g. primary_host_<Lun_id>
      var Lun_id = $(this).attr("id").split("_")[2];
      for (var i=1, iLen=oSetting.aoData.length; i<iLen; i++)
      {
        var rowParams = oSetting.aoData[i]._aData[6].split("_");
        var row_lun_id = rowParams[0];
        var old_primary_host_id = rowParams[1];
        var old_secondary_host_id =  rowParams[2];
        var new_primary_host_id;
        var new_secondary_host_id;
        if($(this).attr("id").indexOf("primary_host") == 0)
        {
          new_primary_host_id  = $(this).val();
          new_secondary_host_id = old_secondary_host_id;
        }
        else
        {
          new_secondary_host_id = $(this).val();
          new_primary_host_id = old_primary_host_id  
        }
        if (Lun_id == row_lun_id && (old_primary_host_id != new_primary_host_id || old_secondary_host_id != new_secondary_host_id))
        { 
          oSetting.aoData[i]._aData[6] = Lun_id + '_' + 
                                         new_primary_host_id + '_' +
                                         new_secondary_host_id;
        }
      }
    });
  });
</script>
</head>
<h2 class='section_header'>Volume configuration</h2>
<table class="display tight_lines" id="volume_configuration" width="100%">
  <thead>
    <tr>
      <th width="20%">Name</th>
      <th width="25%">Primary server</th>
      <th width="25%">Failover server</th>
      <th width="10%">Size</th>
      <th width="20%">Status</th>
      <th></th>
      <th></th>
    </tr>
  </thead>
  <tbody id="volume_configuration_content">
    <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
  </tbody>
</table>
<div align="right">
  <button type="button" id="btnApplyConfig">Apply</button>
  <button type="button" id="btnCancelConfig">Cancel</button>
</div><commit_msg>Fix for HYD-497: - Added validation when server setting is selected to "---" value - Added validation to check that primary and failover server are not same - Added handler for cancel button<commit_after><script>
  var config_change_flag = false; 
  $(document).ready(function() {
    //cm-json_table_data = > load list of unused luns 
    LoadUnused_VolumeConf();
    //Volume JQuery data table init()
    var oVolumeConfiguration = $('#volume_configuration').dataTable( {
      "bProcessing": true,
      "bJQueryUI": true,
      "iDisplayLength": 25,
      "bAutoWidth":false,
      "oLanguage": {
        "sEmptyTable": "No Volumes to display"
      },
      "aoColumns": [
        { "sClass": 'txtleft' },
        { "sClass": 'txtleft' },
        { "sClass": 'txtleft' },
        { "sClass": 'txtright' },
        { "sClass": 'txtright' },
        { "bVisible": false },
        { "bVisible": false },
      ]
    });

    $("#btnApplyConfig").click(function ()
	{
      var oSetting = $('#volume_configuration').dataTable().fnSettings();
      var confirmation_markup = "This action will have the following consequences: <br /><br />";
      var same_primary_secondary_error_markup = "<b>Volumes should have different primary and secondary servers</b><br /><br />"+
      											"Following volumes are having same primary and secondary servers:<br /><br />";
      var no_server_error_markup  = "<b>Please select valid Primary/Failover server for following volumes:</b><br /><br />";
	  var same_server_error_flag = false;
	  var no_server_error_flag = false;
      var api_params = {};
      var alun_ids = [];
      var aprimary_host_ids = [];
      var asecondary_host_ids = [];
      for (var i=0, iLen=oSetting.aoData.length; i<iLen; i++) 
      {
        if (oSetting.aoData[i]._aData[5] != oSetting.aoData[i]._aData[6])
        {
          params = oSetting.aoData[i]._aData[6].split("_") 
          alun_ids.push(parseInt(params[0]));
          aprimary_host_ids.push(parseInt(params[1]));
          asecondary_host_ids.push(parseInt(params[2]));
          if(parseInt(params[1]) == -1 || parseInt(params[2]) == -1)
          {
            no_server_error_markup += "- "+oSetting.aoData[i]._aData[0]+"<br />";
            no_server_error_flag = true;
          }
          else if(parseInt(params[1]) == parseInt(params[2]))
          {
            same_primary_secondary_error_markup += "- "+oSetting.aoData[i]._aData[0]+"<br />";
            same_server_error_flag = true;
          }
          else
          {
            confirmation_markup += "- Volume configuration change for "+oSetting.aoData[i]._aData[0]+"<br />";
          }
        }
      }
      
      if(alun_ids.length > 0 && !same_server_error_flag && !no_server_error_flag)
      {
        api_params = {'lun_ids': alun_ids, 'primary_host_ids': aprimary_host_ids, 'secondary_host_ids': asecondary_host_ids};
      	save_primary_failover_server(confirmation_markup, api_params);
      }
      else
      {
        if(no_server_error_flag)
        {
          $('#volume_error_dialog').html(no_server_error_markup);
          $('#volume_error_dialog').dialog('open');
        }
        else if(same_server_error_flag)
        {
          $('#volume_error_dialog').html(same_primary_secondary_error_markup);
          $('#volume_error_dialog').dialog('open');
        }
      }
	});

    $("#btnCancelConfig").click(function ()
    {
      if(config_change_flag)
      {
        $('#cancel_volume_conf').html("<br /><br />Do you want to continue cancelling changes ?");
        $('#cancel_volume_conf').dialog('open');
      }
    });

    $('#cancel_volume_conf').dialog
    ({
      autoOpen: false,
      width: 450,
      height:200,
      show: "clip",
      modal: true,
      position:"center",
      buttons: 
      {
        "Yes": function() {
      	    config_change_flag = false;
      		LoadUnused_VolumeConf();
      		$(this).dialog("close");
        },
        "No": function() {
          $(this).dialog("close");
        }, 
      }
    });

    $('#volume_error_dialog').dialog
    ({
      autoOpen: false,
      width: 500,
      height:200,
      show: "clip",
      modal: true,
      position:"center",
      buttons: 
      {
        "Ok": function() {
      	  $(this).dialog("close");
        } 
      }
    });

    $('select[id *="_host"]').live('change', function ()
    {
      var oSetting = $('#volume_configuration').dataTable().fnSettings();
      //Note : Lun_id i storage as part of select control id E.g. primary_host_<Lun_id>
      var Lun_id = $(this).attr("id").split("_")[2];
      for (var i=0, iLen=oSetting.aoData.length; i<iLen; i++)
      {
        var rowParams = oSetting.aoData[i]._aData[6].split("_");
        var row_lun_id = rowParams[0];
        var old_primary_host_id = rowParams[1];
        var old_secondary_host_id =  rowParams[2];
        var new_primary_host_id;
        var new_secondary_host_id;
        if($(this).attr("id").indexOf("primary_host") == 0)
        {
          new_primary_host_id  = $(this).val();
          new_secondary_host_id = old_secondary_host_id;
        }
        else
        {
          new_secondary_host_id = $(this).val();
          new_primary_host_id = old_primary_host_id  
        }
        if (Lun_id == row_lun_id && (old_primary_host_id != new_primary_host_id || old_secondary_host_id != new_secondary_host_id))
        { 
          oSetting.aoData[i]._aData[6] = Lun_id + '_' + 
                                         new_primary_host_id + '_' +
                                         new_secondary_host_id;

          config_change_flag = true;
        }
      }
    });
  });
</script>
</head>
<h2 class='section_header'>Volume configuration</h2>
<table class="display tight_lines" id="volume_configuration" width="100%">
  <thead>
    <tr>
      <th width="20%">Name</th>
      <th width="25%">Primary server</th>
      <th width="25%">Failover server</th>
      <th width="10%">Size</th>
      <th width="20%">Status</th>
      <th></th>
      <th></th>
    </tr>
  </thead>
  <tbody id="volume_configuration_content">
    <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
  </tbody>
</table>
<div align="right">
  <button type="button" id="btnApplyConfig">Apply</button>
  <button type="button" id="btnCancelConfig">Cancel</button>
</div>
<!-- Markup for cancel volume confirmation dialog -->
<div id="cancel_volume_conf">
</div>
<!-- End markup for cancel volume confirmation dialog -->
<!-- Markup for volume configuration error dialog -->
<div style="overflow-y: auto; max-height: 700px;" id="volume_error_dialog">
</div>
<!-- End markup for volume configuration error dialog -->
{'fraction_non_alphanumeric': 0.16109364580356292, 'fraction_numerical': 0.008954939506525674, 'mean_word_length': 2.5145631067961167, 'pattern_counts': {'":': 31, '<': 135, '<?xml version=': 0, '>': 135, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '122510', 'n_tokens_mistral': 3445, 'n_tokens_neox': 3378, 'n_words': 592}