{* Smarty *}

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

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

function SvtGiveoutDel(){
  var VarId = $("#GridSvtGiveout").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/SvtGiveoutDel.ajax.php{literal}",
              data: {
                svtgiveout_id: VarId
              },
              success: function(answ){
                if("undefined" == typeof(answ["error"])){
                  $("#GridSvtGiveout").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 BuildGrid(){
  var param = GetParamForGrid(location.search.substring(1));
  $("#GridSvtGiveout").jqGrid('jqGridImport',{imptype:"jsonstring", impstring:window.localStorage.getItem("{/literal}{$smarty.session.SessionAuth.id}-GridSvtGiveout{literal}")});
  $("#GridSvtGiveout").jqGrid({
    caption:{/literal}'{$MS_SP->Sp_LangMessage.GridsCaptions.SvtGiveout}'{literal},
    datatype: "json",
    url:"{/literal}{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/SvtGiveoutList.ajax.php{literal}",
    colNames:[{/literal}
      '{$MS_SP->Sp_LangMessage.GridsColNames.users_fio_who_giveout}',
      '{$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.users_fio_whom_giveout}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.date_from}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.date_to}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.note}'{literal}
    ],
    colModel:[
      {name:'g.users_fio', index:'g.users_fio', width:145},
      {name:'svtgiveoutstatus_name', index:'svtgiveoutstatus_name', width:80},
      {name:'svt_buxname', index:'svt_buxname', width:100},
      {name:'svt_name', index:'svt_name', width:100},
      {name:'svt_invnum', index:'svt_invnum', width:60},
      {name:'svt_serialnum', index:'svt_serialnum', width:90},
      {name:'b.users_fio', index:'b.users_fio', width:160},
      {name:'svtgiveout_date_b', index:'svtgiveout_date_b', width:70, align:"right", sorttype:'date', datefmt: 'dd.mm.YYYY', formatter: 'date', 
        searchoptions:{
          dataInit:function(el){ 
            $(el).prop("VarGridName", 'GridSvtGiveout');
            GridDatepickerSetParam(el);
          }
        }
      },
      {name:'svtgiveout_date_e', index:'svtgiveout_date_e', width:70, align:"right", sorttype:'date', datefmt: 'dd.mm.YYYY', formatter: 'date', 
        searchoptions:{
          dataInit:function(el){ 
            $(el).prop("VarGridName", 'GridSvtGiveout');
            GridDatepickerSetParam(el);
          }
        }
      },
      {name:'svtgiveout_note', index:'svtgiveout_note', width:250}
    ],
    multiselect: true,
    multiboxonly:true,
    rowNum:100,
    rowList:[10,25,100,500],
    pager: "#GridSvtGiveoutPager",
    sortname: 'svtgiveoutstatus_order',
    sortorder: "asc",
    viewrecords: true,
    rownumbers: true,
    toolbar: [true,"top"],
    shrinkToFit:false, 
    gridview: true,
    autowidth: true,
    height: 290,
    postData: param
  });
  $("#GridSvtGiveout").toolbarButtonAdd("#t_GridSvtGiveout",{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('GridSvtGiveout');}});
  $("#GridSvtGiveout").toolbarButtonAdd("#t_GridSvtGiveout",{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:SvtGiveoutAdd });
  $("#GridSvtGiveout").toolbarButtonAdd("#t_GridSvtGiveout",{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:SvtGiveoutEdit });
{/literal}
  {if isset($smarty.session.SessionAuth.SvtAdmin.reg) && 1 eq $smarty.session.SessionAuth.SvtAdmin.reg}
{literal}
  $("#GridSvtGiveout").toolbarButtonAdd("#t_GridSvtGiveout",{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:SvtGiveoutDel });
{/literal}
  {/if}
  {if isset($VarSvtGiveoutSelect) && 1 eq $VarSvtGiveoutSelect}
  {literal}
    $("#GridSvtGiveout").toolbarButtonAdd("#t_GridSvtGiveout",{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:SvtGiveoutSelect });
  {/literal}
  {/if}
  {literal}
  $("#GridSvtGiveout").jqGrid('navGrid','#GridSvtGiveoutPager', {edit:false,add:false,del:false,refresh:false});
  $("#GridSvtGiveout").jqGrid("navButtonAdd","#GridSvtGiveoutPager",{
    caption: "",
    title: "{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Refresh}{literal}",
    buttonicon :'ui-icon-refresh',
    onClickButton : function (){
      $("#GridSvtGiveout").trigger("reloadGrid");
    }
  });
  $("#GridSvtGiveout").jqGrid("navButtonAdd","#GridSvtGiveoutPager",{
    caption: "",
    title: "{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.ColumnChooser}{literal}",
    buttonicon :'ui-icon-transfer-e-w',
    onClickButton : function (){
      $("#GridSvtGiveout").jqGrid('columnChooser');
    }
  });
  $("#GridSvtGiveout").navButtonAdd("#GridSvtGiveoutPager",{ 
    caption: "", 
    title: "{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.SaveSettings}{literal}", 
    buttonicon :'ui-icon-disk',
    onClickButton: function () {
      if (typeof window.localStorage !== 'undefined') {
        delete $("#GridSvtGiveout").jqGrid('getGridParam' ,'postData' )['filters'];
        window.localStorage.setItem("{/literal}{$smarty.session.SessionAuth.id}-GridSvtGiveout{literal}",$("#GridSvtGiveout").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}");
      }
    }
  });
  $("#GridSvtGiveout").navButtonAdd("#GridSvtGiveoutPager",{ 
    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}-GridSvtGiveout{literal}");
            $(this).dialog('close');
            $("#GridSvtGiveout").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');
          }
        }
      });
    }
  });
  $("#GridSvtGiveout").jqGrid('filterToolbar',{stringResult: true, searchOnEnter : true, defaultSearch:"cnof"});
  UpdateJqGrid("GridSvtGiveout","GridSvtGiveoutWrapper");
});
//]]>
</script>
{/literal}

<div id="GridSvtGiveoutWrapper" class="ui-widget-content ui-corner-all">
  <table id="GridSvtGiveout"><tr><td></td></tr></table>
  <div id="GridSvtGiveoutPager"></div>
  <div id="t_toolbar1"></div>
</div>