{* Smarty *}

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

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

function PoLicenceDel(){
  var VarId = $("#GridPoLicence").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/PoLicenceDel.ajax.php{literal}",
              data: {
                policence_id: VarId
              },
              success: function(answ){
                if("undefined" == typeof(answ["error"])){
                  $("#GridPoLicence").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(){
  $("#GridPoLicence").jqGrid('jqGridImport',{imptype:"jsonstring", impstring:window.localStorage.getItem("{/literal}{$smarty.session.SessionAuth.id}-GridPoLicence{literal}")});
  $("#GridPoLicence").jqGrid({
    caption:{/literal}'{$MS_SP->Sp_LangMessage.GridsCaptions.LicensePo}'{literal},
    datatype: "json",
    url:"{/literal}{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/PoLicenceList.ajax.php{literal}",
    colNames:[{/literal}
      '{$MS_SP->Sp_LangMessage.GridsColNames.name}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.po_name}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.seller}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.policence_number}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.date_from}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.date_to}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.note}'{literal}
    ],
    colModel:[
      {name:'policence_name', index:'policence_name', width:200},
      {name:'po_name', index:'po_name', width:200},
      {name:'organiz_name', index:'organiz_name', width:160},
      {name:'policence_number', index:'policence_number', width:100, formatter: 'number', sorttype: 'number', align: 'right'},
      {name:'policence_dateb', index:'policence_dateb', width:70, sorttype:'date', datefmt: 'dd.mm.YYYY', formatter: 'date', 
        searchoptions:{
          dataInit:function(el){ 
            $(el).prop("VarGridName", 'GridPoLicence');
            GridDatepickerSetParam(el);
          }
        }
      },
      {name:'policence_datee', index:'policence_datee', width:70, sorttype:'date', datefmt: 'dd.mm.YYYY', formatter: 'date', 
        searchoptions:{
          dataInit:function(el){ 
            $(el).prop("VarGridName", 'GridPoLicence');
            GridDatepickerSetParam(el);
          }
        }
      },
      {name:'policence_note', index:'policence_note', width:200}
    ],
    multiselect: true,
    multiboxonly:true,
    rowNum:100,
    rowList:[10,25,100,500],
    pager: "#GridPoLicencePager",
    sortname: 'policence_name',
    sortorder: "asc",
    viewrecords: true,
    rownumbers: true,
    toolbar: [true,"top"],
    shrinkToFit:false, 
    gridview: true,
    autowidth: true,
    height: 290
  });
  $("#GridPoLicence").toolbarButtonAdd("#t_GridPoLicence",{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('GridPoLicence');}});
  $("#GridPoLicence").toolbarButtonAdd("#t_GridPoLicence",{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:PoLicenceAdd });
  $("#GridPoLicence").toolbarButtonAdd("#t_GridPoLicence",{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:PoLicenceEdit });
{/literal}
  {if isset($smarty.session.SessionAuth.SvtAdmin.reg) && 1 eq $smarty.session.SessionAuth.SvtAdmin.reg}
{literal}
  $("#GridPoLicence").toolbarButtonAdd("#t_GridPoLicence",{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:PoLicenceDel });
{/literal}
  {/if}
  {if isset($VarPoLicenceSelect) && 1 eq $VarPoLicenceSelect}
  {literal}
    $("#GridPoLicence").toolbarButtonAdd("#t_GridPoLicence",{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:PoLicenceSelect });
  {/literal}
  {/if}
  {literal}
$("#GridPoLicence").jqGrid("navButtonAdd","#GridPoLicencePager",{
    caption: "",
    title: "{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Refresh}{literal}",
    buttonicon :'ui-icon-refresh',
    onClickButton : function (){
      $("#GridPoLicence").trigger("reloadGrid");
    }
  });
  $("#GridPoLicence").jqGrid("navButtonAdd","#GridPoLicencePager",{
    caption: "",
    title: "{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.ColumnChooser}{literal}",
    buttonicon :'ui-icon-transfer-e-w',
    onClickButton : function (){
      $("#GridPoLicence").jqGrid('columnChooser');
    }
  });
  $("#GridPoLicence").navButtonAdd("#GridPoLicencePager",{ 
    caption: "", 
    title: "{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.SaveSettings}{literal}", 
    buttonicon :'ui-icon-disk',
    onClickButton: function () {
      if (typeof window.localStorage !== 'undefined') {
        delete $("#GridPoLicence").jqGrid('getGridParam' ,'postData' )['filters'];
        window.localStorage.setItem("{/literal}{$smarty.session.SessionAuth.id}-GridPoLicence{literal}",$("#GridPoLicence").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}");
      }
    }
  });
  $("#GridPoLicence").navButtonAdd("#GridPoLicencePager",{ 
    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}-GridPoLicence{literal}");
            $(this).dialog('close');
            $("#GridPoLicence").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');
          }
        }
      });
    }
  });
  $("#GridPoLicence").jqGrid('filterToolbar',{stringResult: true, searchOnEnter : true, defaultSearch:"cnof"});
  UpdateJqGrid("GridPoLicence","GridPoLicenceWrapper");
});
//]]>
</script>
{/literal}

<div id="GridPoLicenceWrapper" class="ui-widget-content ui-corner-all">
  <table id="GridPoLicence"><tr><td></td></tr></table>
  <div id="GridPoLicencePager"></div>
  <div id="t_toolbar1"></div>
</div>