{* Smarty *}

{literal}
<script type="text/javascript">
//<![CDATA[
function SvtMoveAdd(){
  $.ajax({
    async: false,
    timeout: 3000,
    type: 'GET',
    url: "{/literal}{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/SvtMoveEdit.ajax.php{literal}",
    data: {
      "svt_id": "{/literal}{$smarty.get.svt_id}{literal}"
    },
    success: function(answ){
      DialogStandartOpen('SvtMoveFrm', answ, "{/literal}{$MS_SP->Sp_LangMessage.message.MessRecordEdit}{literal}");
    }
  });
}

function SvtMoveDel(){
  var VarId = $("#GridSvtMove").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/SvtMoveDel.ajax.php{literal}",
              data: {
                svtmove_id: VarId
              },
              success: function(answ){
                if("undefined" == typeof(answ["error"])){
                  $("#GridSvtMove").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.warning.WarnShouldSelectOnlyOneRecord}{literal}");
  }
}

function PrintSvtMoveQrTHeadPrepare(VarTHead){
  return VarTHead
          .replace(/<\/?[^>]+>/gi, '')
          .replace('&nbsp;', '');
}

function PrintSvtMoveQrTBodyPrepare(VarTBody){
  return VarTBody
          .replace(/<\/?[^>]+>/gi, '')
          .replace('&nbsp;', '')
          .replace(/&/g, "&amp;")
          .replace(/</g, "&lt;")
          .replace(/>/g, "&gt;")
          .replace(/"/g, "&quot;")
          .replace(/'/g, "&#039;")
          .replace(/^\s+|\s+$/g, "");
}

function PrintSvtMoveQr(jqgridid){
  $('#'+jqgridid).jqGrid('hideCol','cb');
  var VarTHead=PrintSvtMoveQrTHeadPrepare('&thead={/literal}{$MS_SP->Sp_LangMessage.GridsColNames.qr_code}{literal}');
//  var VarTHead='';
  var VarTHeadAdd = '';
  $('#gview_'+jqgridid+' .ui-jqgrid-labels > th:visible').each(function(){
    VarTHeadAdd = PrintSvtMoveQrTHeadPrepare('&thead=' + $(this).html());
//    alert("VarTHeadAdd"+VarTHeadAdd);
    VarTHead = VarTHead + VarTHeadAdd;
  });
  var VarTBody='';
  var VarColspan='';
  var VarRowId='';
  var VarTBodyAdd = '';
  var i = 0;
  $("#"+jqgridid+" input[id^='jqg']:checked").each(function() {
    VarRowId = $(this).parent().parent().find("input[role='checkbox']:first").attr("id").replace("jqg_"+jqgridid+"_", "");
//    alert("ids: " + $(this).parent().parent().children("input[role='checkbox']").attr("id"));
//    alert("ids: " + );
    VarTBody=VarTBody+PrintSvtMoveQrTBodyPrepare('&tbody='+VarRowId);
    $(this).parent().parent().children().filter("td:visible").each(function(){ 
      VarTBodyAdd = PrintSvtMoveQrTBodyPrepare('&tbody=' + $(this).html());
//      alert("VarTHeadAdd"+VarTBodyAdd);
      VarTBody = VarTBody + VarTBodyAdd;
      if(0<$(this).attr('colspan')){
        VarColspan = VarColspan + '&colspan['+i+']=' + $(this).attr('colspan');
      }
      i++;
    });
  });
    $('<form action="./libs/site/AjaxServer/PrintSvtMoveQrDocx.ajax.php" method="post"><input type="hidden" name="PrintSvtMoveQrDocx" value="'+ 'grid=' + jqgridid + VarTHead + VarTBody + VarColspan +'" /></form>')
    .appendTo('body').submit().remove();
  $('#'+jqgridid).jqGrid('showCol','cb');
}

$(function BuildGrid(){
  var param = '';
  if($("#DateForm").length > 0){
    param = GetParamForGrid($("#DateForm").serialize());
  }
  else{
    param = {svt_id:"{/literal}{$smarty.get.svt_id}{literal}"};
  }
  $("#GridSvtMove").jqGrid('jqGridImport',{imptype:"jsonstring", impstring:window.localStorage.getItem("{/literal}{$smarty.session.SessionAuth.id}-GridSvtMove{literal}")});
  $("#GridSvtMove").jqGrid({
    caption:{/literal}'{$MS_SP->Sp_LangMessage.GridsCaptions.SvtMove}'{literal},
    datatype: "json",
    url:"{/literal}{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/SvtMoveList.ajax.php{literal}",
    colNames:[{/literal}
      '{$MS_SP->Sp_LangMessage.GridsColNames.svt_name}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.svt_buxname}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.svttype_name}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.svt_invnum}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.svt_serialnum}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.structureorganization_title_from}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.users_fio_from}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.structureorganization_title_to}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.users_fio_to}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.svtmove_date}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.note}'{literal}
    ],
    colModel:[
      {name:'svt_name', index:'svt_name', width:110},
      {name:'svt_buxname', index:'svt_buxname', width:110},
      {name:'svttype_name', index:'svttype_name', width:80},
      {name:'svt_invnum', index:'svt_invnum', width:60},
      {name:'svt_serialnum', index:'svt_serialnum', width:90},
      {name:'so1.structureorganization_title', index:'so1.structureorganization_title', width:120},
      {name:'u1.users_fio', index:'u1.users_fio', width:120},
      {name:'so2.structureorganization_title', index:'so2.structureorganization_title', width:120},
      {name:'u2.users_fio', index:'u2.users_fio', width:120},
      {name:'svtmove_date', index:'svtmove_date', width:90, sorttype:'date', datefmt: 'dd.mm.YYYY', formatter: 'date', 
        searchoptions:{
          dataInit:function(el){
            $(el).prop("VarGridName", 'GridSvtMove');
            GridDatepickerSetParam(el);
          }
        }
      },
      {name:'svtmove_note', index:'svtmove_note', width:180}
    ],
    multiselect: true,
    multiboxonly:true,
    rowNum:100,
    rowList:[10,25,100,500],
    pager: "#GridSvtMovePager",
    sortname: 'svtmove_date',
    sortorder: "desc",
    viewrecords: true,
    toolbar: [true,"top"],
    shrinkToFit:false,
    autowidth: true, 
    gridview: true,
    height: 290,
    postData: param
  });
  $("#GridSvtMove").toolbarButtonAdd("#t_GridSvtMove",{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('GridSvtMove');}});
  $("#GridSvtMove").toolbarButtonAdd("#t_GridSvtMove",{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:SvtMoveAdd });
{/literal}
  {if isset($smarty.session.SessionAuth.SvtAdmin.reg) && 1 eq $smarty.session.SessionAuth.SvtAdmin.reg}
{literal}
  $("#GridSvtMove").toolbarButtonAdd("#t_GridSvtMove",{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:SvtMoveDel });
{/literal}
  {/if}
  {if isset($VarSvtMoveSelect) && 1 eq $VarSvtMoveSelect}
  {literal}
    $("#GridSvtMove").toolbarButtonAdd("#t_GridSvtMove",{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:SvtMoveSelect });
  {/literal}
  {/if}
  {literal}
  $("#GridSvtMove").jqGrid('navGrid','#GridSvtMovePager', {edit:false,add:false,del:false,refresh:false});
  $("#GridSvtMove").jqGrid("navButtonAdd","#GridSvtMovePager",{
    caption: "",
    title: "{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Refresh}{literal}",
    buttonicon :'ui-icon-refresh',
    onClickButton : function (){
      $("#GridSvtMove").trigger("reloadGrid");
    }
  });
  $("#GridSvtMove").jqGrid("navButtonAdd","#GridSvtMovePager",{
    caption: "",
    title: "{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.ColumnChooser}{literal}",
    buttonicon :'ui-icon-transfer-e-w',
    onClickButton : function (){
      $("#GridSvtMove").jqGrid('columnChooser');
    }
  });
  $("#GridSvtMove").navButtonAdd("#GridSvtMovePager",{ 
    caption: "", 
    title: "{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.SaveSettings}{literal}", 
    buttonicon :'ui-icon-disk',
    onClickButton: function () {
      if (typeof window.localStorage !== 'undefined') {
        delete $("#GridSvtMove").jqGrid('getGridParam' ,'postData' )['filters'];
        window.localStorage.setItem("{/literal}{$smarty.session.SessionAuth.id}-GridSvtMove{literal}",$("#GridSvtMove").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}");
      }
    }
  });
  $("#GridSvtMove").navButtonAdd("#GridSvtMovePager",{ 
    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}-GridSvtMove{literal}");
            $(this).dialog('close');
            $("#GridSvtMove").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');
          }
        }
      });
    }
  });
  $("#GridSvtMove").jqGrid('filterToolbar',{stringResult: true, searchOnEnter : true, defaultSearch:"cnof"});
  UpdateJqGrid("GridSvtMove","GridSvtMoveWrapper");
});
//]]>
</script>
{/literal}

<div id="GridSvtMoveWrapper" class="ui-widget-content ui-corner-all">
  <table id="GridSvtMove"><tr><td></td></tr></table>
  <div id="GridSvtMovePager"></div>
  <div id="t_toolbar1"></div>
</div>