Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php header ( "Content-type: text/javascript" ); ?>
  2. <?php include '../../../../../eindex.php'; ?>
  3. var data;
  4. var selectedShlsIds = new Array();
  5. var selectedShlsStr = "";
  6. $(document).ready
  7. (
  8.     function()
  9.     {
  10.         $(".shls-search-term").keyup
  11.         (
  12.             function()
  13.             {
  14.                 sendShlsSearchTerm($(this).val());
  15.             }
  16.         );
  17.     }
  18. );
  19. function sendShlsSearchTerm(term)
  20. {
  21.     $(".shls-search-res").html('<img src="<?php echo Reg::get("url")."web/images/system/interface/ajax-loader.gif"; ?>"/>');
  22.     $.ajax
  23.     (
  24.         {
  25.             type: "POST",
  26.             url: '<?php echo Reg::get ( "url" ); ?>Units/Shls/Main/SearchAjax',
  27.             async: false,
  28.             dataType: "json",
  29.             data:
  30.             {
  31.                 term: term,
  32.             } ,
  33.             success:function(inside)
  34.             {
  35.                  data = inside;
  36.                  var result;
  37.                  result += '<table class="shls-search-res">';
  38.                  result += "<thead>";
  39.                  result += "<td>کد</td>";
  40.                  result += "<td>نام</td>";
  41.                  result += "<td>مرکز</td>";
  42.                  result += "<td>عملیات</td>";
  43.                  result += "</thead>";
  44.                  result += "<tbody>";
  45.                  
  46.                  length = 0;
  47.                  length = data.shls.length;
  48.                  for(count = 0 ; count < length ; count ++)
  49.                  {
  50.                     className = (count % 2 == 0) ? 'even' : 'odd';
  51.                     result += "<tr onclick='set(data.shls["+count+"])' class='"+className+"'>";
  52.                         result += "<td>" + data.shls[count].code + "</td>";
  53.                         result += "<td>" + data.shls[count].name + "</td>";
  54.                         result += "<td>" + data.shls[count].shl_center + "</td>";
  55.                         result += "<td>" + "<input name='id_shls_"+data.shls[count].id+"' value ='"+data.shls[count].id+"' id='id_shls_"+data.shls[count].id+"' type='checkbox' />" + "</td>";
  56.                     result += "</tr>";
  57.                  }
  58.                  if(length > 0)
  59.                  {
  60.                  result += '<tr><td colspan="4" style="text-align: center;background-color: #6891C3;"><input type="button" id="shls-add-to-graph" value="اضافه" /></td></tr>';
  61.                  }
  62.                  result += '</tbody>';
  63.                  result += "</table>";
  64.                  
  65.                  $(".shls-search-res").html(result);
  66.             }
  67.         }
  68.     )
  69. }
  70.  
  71. function addToSelectedShls()
  72. {
  73.     checkBoxes = $('table.shls-search-res input[type=checkbox]:checked');
  74.     countCheckBoxes = checkBoxes.length;
  75.     countSelectedShlsIds = selectedShlsIds.length;
  76.     for(checkBoxesCounter = 0 ; checkBoxesCounter < countCheckBoxes ; checkBoxesCounter ++)
  77.     {
  78.         if( shlsExisted(checkBoxes[checkBoxesCounter].value) == false )
  79.         {
  80.             selectedShlsIds.push ( checkBoxes[checkBoxesCounter].value ) ;
  81.         }
  82.     }
  83.     renderSelectedShls ();
  84. }
  85.  
  86. function renderSelectedShls()
  87. {
  88.     shlsSelectedLenth = selectedShlsIds.length;
  89.     for( counter = 0 ; counter < shlsSelectedLenth ; counter++ )
  90.     {
  91.         selectedShlsStr += '<div id="id_shls_" ' + selectedShlsIds[counter] + ' class="selected-units-items">'+selectedShlsIds[counter]+'</div>';
  92.     }
  93.     if(shlsSelectedLenth > 0)
  94.     selectedShlsStr += '<div style="clear: both;"><input id="draw-btn" type="button" name="draw" value="ترسیم"/></div>';
  95.     $("#selected-units").html(selectedShlsStr);
  96.     selectedShlsStr = "";
  97. }
  98. function shlsExisted( shlsId )
  99. {
  100.     countSelectedShlsIds = selectedShlsIds.length;
  101.     //console.log(shlsId);
  102.     //console.log(selectedShlsIds);
  103.     for(counter = 0 ; counter < countSelectedShlsIds ; counter++)
  104.     {
  105.         if( selectedShlsIds[counter] ==  shlsId )
  106.         {
  107.             return true;
  108.         }
  109.     }
  110.     return false;
  111. }
  112. function removeSelectedItem()
  113. {
  114.    
  115. }
  116. $("#shls-add-to-graph").click
  117. (
  118.     function()
  119.     {
  120.         alert("hello");
  121.         addToSelectedShls();
  122.     }
  123. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement