{* Smarty *}

{literal}
<script type="text/javascript">
//<![CDATA[
function RepairAdd(){
  $.ajax({
    async: false,
    timeout: 3000,
    type: 'GET',
    url: "{/literal}{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/RepairEdit.ajax.php{literal}",
    success: function(answ){
      DialogStandartOpen('RepairEditFrm', answ, "{/literal}{$MS_SP->Sp_LangMessage.message.MessRecordAdd}{literal}");
    }
  });
}

function RepairEdit(){
  var VarCountSelectedRows = $("#GridRepair").jqGrid('getGridParam','selarrrow').length;
  if(0 == VarCountSelectedRows){
    DialogStandartMessageOpen('error', "{/literal}{$MS_SP->Sp_LangMessage.warning.WarnShouldSelectRecord}{literal}");
  }
  else if(1 == VarCountSelectedRows){
    var VarId = $("#GridRepair").jqGrid('getGridParam','selrow');
    $.ajax({
      async: false,
      timeout: 3000,
      type: 'GET',
      url: "{/literal}{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/RepairEdit.ajax.php{literal}",
      data: {
        "repair_id": VarId
      },
      success: function(answ){
        DialogStandartOpen('RepairEditFrm', answ, "{/literal}{$MS_SP->Sp_LangMessage.message.MessRecordEdit}{literal}");
      }
    });
  }
  else{
    DialogStandartMessageOpen('error', "{/literal}{$MS_SP->Sp_LangMessage.warning.WarnShouldSelectOnlyOneRecord}{literal}");
  }
}

function RepairDel(){
  var VarId = $("#GridRepair").jqGrid('getGridParam','selarrrow');
  var VarCountSelectedRows = VarId.length;
  if(0 == VarCountSelectedRows){
    DialogStandartMessageOpen('error', "{/literal}{$MS_SP->Sp_LangMessage.warning.WarnShouldSelectRecord}{literal}");
  }
  else if(1 <= VarCountSelectedRows){
    $(function() {
      CreateDivForMessage("DialogConfirmMessage");
      $("#DialogConfirmMessageText").html("{/literal}{$MS_SP->Sp_LangMessage.message.MessAreYouSureDelete}{literal}");
      $("#DialogConfirmMessage").dialog({
        title: "{/literal}{$MS_SP->Sp_LangMessage.label.GridDelete}{literal}",
        resizable: false,
        height:180,
        modal: true,
        buttons: {
          "{/literal}{$MS_SP->Sp_LangMessage.label.GridDeleteYes}{literal}": function() {
            $.ajax({
              async: false,
              timeout: 3000,
              type: "GET",
              url: "{/literal}{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/RepairDel.ajax.php{literal}",
              data: {
                repair_id: VarId
              },
              success: function(answ){
                if("undefined" == typeof(answ["error"])){
                  $("#GridRepair").trigger("reloadGrid");
                  DialogStandartMessageOpen('message', answ["message"]);
                }
                else{
                  DialogStandartMessageOpen('error', answ["error"]);
                }
              }
            });
            $(this).dialog("close");
          },
          "{/literal}{$MS_SP->Sp_LangMessage.label.GridDeleteNo}{literal}": function() {
            $(this).dialog("close");
          }
        }
      });
    });
  }
  else{
    DialogStandartMessageOpen('error', "{/literal}{$MS_SP->Sp_LangMessage.error.ErrUnknownError}{literal}");
  }
}

function DemandTransportPrint(com,grid){
  var VarCountSelectedRows = $("#GridRepair").jqGrid('getGridParam','selarrrow').length;
  if(0 == VarCountSelectedRows){
    DialogStandartMessageOpen('error', "{/literal}{$MS_SP->Sp_LangMessage.warning.WarnShouldSelectRecord}{literal}");
  }
  else if(1 == VarCountSelectedRows){
    var VarId = $("#GridRepair").jqGrid('getGridParam','selrow');
    $('<form action="{/literal}{$MS_SP->Sp_PathTop}{literal}/libs/site/AjaxServer/PrintDemandTransportDocx.ajax.php" method="get"><input type="hidden" name="repair_id" value="'+ VarId +'" /></form>')
    .appendTo('body').submit().remove();
  }
  else{
    DialogStandartMessageOpen('error', "{/literal}{$MS_SP->Sp_LangMessage.warning.WarnShouldSelectOnlyOneRecord}{literal}");
  }
}

//function DemandTransportPrint(com,grid){
//  var VarCountSelectedRows = $("#GridRepair").jqGrid('getGridParam','selarrrow').length;
//  if(0 == VarCountSelectedRows){
//    DialogStandartMessageOpen('error', "{/literal}{$MS_SP->Sp_LangMessage.warning.WarnShouldSelectRecord}{literal}");
//  }
//  else if(1 == VarCountSelectedRows){
//    var VarId = $("#GridRepair").jqGrid('getGridParam','selrow');
//    childWindow=open('{/literal}{$MS_SP->Sp_PathTop}{literal}/DemandTransportPrint.php?repair_id=' + VarId,'{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.DemandTransportPrint}{literal}','width=1000,height=550,menubar=1,resizable=1,scrollbars=1');
//    if (childWindow.opener == null) childWindow.opener = self;
//  }
//  else{
//    DialogStandartMessageOpen('error', "{/literal}{$MS_SP->Sp_LangMessage.error.ErrUnknownError}{literal}");
//  }
//}

$(function BuildGrid(){
  var param = GetParamForGrid(location.search.substring(1));
  $("#GridRepair").jqGrid('jqGridImport',{imptype:"jsonstring", impstring:window.localStorage.getItem("{/literal}{$smarty.session.SessionAuth.id}-GridRepair{literal}")});
  $("#GridRepair").jqGrid({
    caption:{/literal}'{$MS_SP->Sp_LangMessage.GridsCaptions.Repair}'{literal},
    datatype: "json",
    url:"{/literal}{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/RepairForOperatorsList.ajax.php{literal}",
    colNames:[{/literal}
      '{$MS_SP->Sp_LangMessage.GridsColNames.num}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.demands_id}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.status}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.svt_name}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.svt_buxname}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.svt_invnum}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.svt_serialnum}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.repair_content}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.organiz_name_serviceprovider}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.sum}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.repair_numdoc}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.repair_numdocdate}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.users_fio_sysing}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.repair_date_b}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.repair_date_e}'{literal}
    ],
    colModel:[
      {name:'repair_id', index:'repair_id', width:50, sorttype: 'number', align: 'right'},
      {name:'demands_id', index:'demands_id', width:70, sorttype: 'number', align: 'right'},
      {name:'repairstatus_name', index:'repairstatus_name', width:90},
      {name:'svt_name', index:'svt_name', width:110},
      {name:'svt_buxname', index:'svt_buxname', width:125},
      {name:'svt_invnum', index:'svt_invnum', width:90},
      {name:'svt_serialnum', index:'svt_serialnum', width:90},
      {name:'repair_content', index:'repair_content', width:200},
      {name:'organiz_name', index:'organiz_name', width:120},
      {name:'repair_summa', index:'repair_summa', width:60, sorttype: 'number', align: 'right'},
      {name:'repair_numdoc', index:'repair_numdoc', width:70},
      {name:'repair_numdocdate', index:'repair_numdocdate', width:70, align:"right", sorttype:'date', datefmt: 'dd.mm.YYYY', formatter: 'date', 
        searchoptions:{
          dataInit:function(el){ 
            $(el).prop("VarGridName", 'GridRepair');
            GridDatepickerSetParam(el);
          }
        }
      },
      {name:'users_fio', index:'users_fio', width:100},
      {name:'repair_date_b', index:'repair_date_b', width:70, align:"right", sorttype:'date', datefmt: 'dd.mm.YYYY', formatter: 'date', 
        searchoptions:{
          dataInit:function(el){ 
            $(el).prop("VarGridName", 'GridRepair');
            GridDatepickerSetParam(el);
          }
        }
      },
      {name:'repair_date_e', index:'repair_date_e', width:70, align:"right", sorttype:'date', datefmt: 'dd.mm.YYYY', formatter: 'date', 
        searchoptions:{
          dataInit:function(el){ 
            $(el).prop("VarGridName", 'GridRepair');
            GridDatepickerSetParam(el);
          }
        }
      }
    ],
    multiselect: true,
    multiboxonly:true,
    rowNum:100,
    rowList:[10,25,100,500],
    pager: "#GridRepairPager",
    sortname: 'repairstatus_order, repair_id',
    sortorder: "desc",
    viewrecords: true,
    rownumbers: true,
    toolbar: [true,"top"],
    shrinkToFit:false, 
    gridview: true,
    autowidth: true,
    height: 290,
    postData: param
  });
  $("#GridRepair").toolbarButtonAdd("#t_GridRepair",{caption:"{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Print}{literal}",position:"first",title:"{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Print}{literal}", buttonicon :'ui-icon-print', cursor: "pointer", onClickButton:function(){GridPrintReport('GridRepair');}});
  $("#GridRepair").toolbarButtonAdd("#t_GridRepair",{caption:"{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Add}{literal}",position:"last",title:"{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Add}{literal}", buttonicon :'ui-icon-plus', cursor: "pointer", onClickButton:RepairAdd });
  $("#GridRepair").toolbarButtonAdd("#t_GridRepair",{caption:"{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Edit}{literal}",position:"last",title:"{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Edit}{literal}", buttonicon :'ui-icon-pencil', cursor: "pointer", onClickButton:RepairEdit });
{/literal}
  {if isset($smarty.session.SessionAuth.SvtAdmin.reg) && 1 eq $smarty.session.SessionAuth.SvtAdmin.reg}
{literal}
  $("#GridRepair").toolbarButtonAdd("#t_GridRepair",{caption:"{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Del}{literal}",position:"last",title:"{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Del}{literal}", buttonicon :'ui-icon-trash', cursor: "pointer", onClickButton:RepairDel });
{/literal}
  {/if}
{literal}
  $("#GridRepair").toolbarButtonAdd("#t_GridRepair",{caption:"{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.DemandTransportPrint}{literal}",position:"last",title:"{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.DemandTransportPrint}{literal}", buttonicon :'ui-icon-print', cursor: "pointer", onClickButton:DemandTransportPrint });
  {/literal}
  {if isset($VarRepairSelect) && 1 eq $VarRepairSelect}
  {literal}
    $("#GridRepair").toolbarButtonAdd("#t_GridRepair",{caption:"{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Select}{literal}",position:"last",title:"{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Select}{literal}", buttonicon :'ui-icon-check', cursor: "pointer", onClickButton:RepairSelect });
  {/literal}
  {/if}
  {literal}
  $("#GridRepair").jqGrid('navGrid','#GridRepairPager', {edit:false,add:false,del:false,refresh:false});
  $("#GridRepair").jqGrid("navButtonAdd","#GridRepairPager",{
    caption: "",
    title: "{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Refresh}{literal}",
    buttonicon :'ui-icon-refresh',
    onClickButton : function (){
      $("#GridRepair").trigger("reloadGrid");
    }
  });
  $("#GridRepair").jqGrid("navButtonAdd","#GridRepairPager",{
    caption: "",
    title: "{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.ColumnChooser}{literal}",
    buttonicon :'ui-icon-transfer-e-w',
    onClickButton : function (){
      $("#GridRepair").jqGrid('columnChooser');
    }
  });
  $("#GridRepair").navButtonAdd("#GridRepairPager",{ 
    caption: "", 
    title: "{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.SaveSettings}{literal}", 
    buttonicon :'ui-icon-disk',
    onClickButton: function () {
      if (typeof window.localStorage !== 'undefined') {
        delete $("#GridRepair").jqGrid('getGridParam' ,'postData' )['filters'];
        window.localStorage.setItem("{/literal}{$smarty.session.SessionAuth.id}-GridRepair{literal}",$("#GridRepair").jqGrid('jqGridExport',{exptype:'jsonstring'}));
        DialogStandartMessageOpen('message', "{/literal}{$MS_SP->Sp_LangMessage.message.MessSettingsSaved}{literal}");
      }
      else{          
        DialogStandartMessageOpen('error', "{/literal}{$MS_SP->Sp_LangMessage.error.ErrNoLocalStorage}{literal}");
      }
    }
  });
  $("#GridRepair").navButtonAdd("#GridRepairPager",{ 
    caption: "", 
    title: "{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.ResetSettings}{literal}", 
    buttonicon :'ui-icon-closethick',
    onClickButton: function () {
      CreateDivForMessage("DialogConfirmMessage");
      $("#DialogConfirmMessageText").html('{/literal}{$MS_SP->Sp_LangMessage.message.MessResetSettConfirm}{literal}');
      $("#DialogConfirmMessage").dialog({
        title: "{/literal}{$MS_SP->Sp_LangMessage.DialogTitles.ResetSettings}{literal}",
        resizable: false,
        height:180,
        modal: true,
        buttons: {
          "{/literal}{$MS_SP->Sp_LangMessage.label.GridDeleteYes}{literal}": function() {
            window.localStorage.removeItem("{/literal}{$smarty.session.SessionAuth.id}-GridRepair{literal}");
            $(this).dialog('close');
            $("#GridRepair").jqGrid('GridUnload');
            BuildGrid();
            DialogStandartMessageOpen('message', "{/literal}{$MS_SP->Sp_LangMessage.message.MessResetSettSuccess}{literal}");
          },
          "{/literal}{$MS_SP->Sp_LangMessage.label.GridDeleteNo}{literal}": function() {
            $(this).dialog('close');
          }
        }
      });
    }
  });
  $("#GridRepair").jqGrid('filterToolbar',{stringResult: true, searchOnEnter : true, defaultSearch:"cnof"});
  UpdateJqGrid("GridRepair","GridRepairWrapper");
});
//]]>
</script>
{/literal}

<div id="GridRepairWrapper" class="ui-widget-content ui-corner-all">
  <table id="GridRepair"><tr><td></td></tr></table>
  <div id="GridRepairPager"></div>
  <div id="t_toolbar1"></div>
</div>