{* Smarty *}

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

function SvtPoDel(){
  var VarId = $("#GridSvtPo").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/SvtPoDel.ajax.php{literal}",
              data: {
                svtpo_id: VarId
              },
              success: function(answ){
                if("undefined" == typeof(answ["error"])){
                  $("#GridSvtPo").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 PoSelect(){
  var VarCountSelectedRows = $("#GridPo").jqGrid('getGridParam','selarrrow').length;
  if(1 == VarCountSelectedRows){
    var VarId = $("#GridPo").jqGrid('getGridParam','selrow');
    $.ajax({
      async: false,
      timeout: 3000,
      type: 'GET',
      url: "{/literal}{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/SvtPoSave.ajax.php{literal}",
      data: {
        po_id: VarId,
        svt_id: "{/literal}{$smarty.get.svt_id}{literal}"
      },
      success: function(answ){
        if("undefined" == typeof(answ["error"])){
          $("#GridSvtPo").trigger("reloadGrid");
          DialogStandartMessageOpen('message', answ["message"]);
        }
        else{
          DialogStandartMessageOpen('error', answ["error"]);
        }
      }
    });
  }
  else{
    DialogStandartMessageOpen('error', "{/literal}{$MS_SP->Sp_LangMessage.warning.WarnShouldSelectOnlyOneRecord}{literal}");
  }
}

//$(function(){
//  $("#flexSvtPo").flexigrid({
//    url: "{/literal}{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/SvtPoList.ajax.php{literal}",
//    dataType: "json",
//    colModel : [
//      {display: "Наименование", name : "po_name", width : 350, sortable : true, align: "left"},
//      {display: "Примечание", name : "po_note", width : 350, sortable : true, align: "left"}//,
//    ],
//    buttons : [
//      {name: 'Добавить', bclass: 'add', onpress : SvtPoAdd},
//      {name: 'Удалить', bclass: 'delete', onpress : SvtPoDel}
//{/literal}
//      {if isset($VarSvtPoSelect) &&  1 eq $VarSvtPoSelect}
//{literal}
//      ,{separator: true},
//       {name: 'Выбрать', bclass: 'select', onpress : SvtPoSelect}
//{/literal}
//      {/if}
//{literal}
//    ],
//    searchitems : [
//      {display: "Наименование", name : "po_name", isdefault: true}
//    ],
//    sortname: "po_name",
//    sortorder: "asc",
//    usepager: true,
//    title: "ПО",
//    pagetext: "Страница",
//    outof: "из",
//    findtext: "Искать",
//    errormsg: "Нет соединения",
//    pagestat: "Отображается с {from} по {to} из {total} записей",
//    procmsg: "Идет запрос, подождите пожалуйста ...",
//    nomsg: "Нет записей",
//    singleSelect: true,
//    nowrap: false,
//    useRp: true,
//    rp: 100,
//    rpOptions: [100,250,500,1000],
//    showTableToggleBtn: true,
//    height: 400
//    {/literal}
//    {if isset($smarty.get.svt_id) && is_numeric($smarty.get.svt_id)}
//    {literal}
//    ,
//    params:[
//      {name: 'svt_id', value: '{/literal}{$smarty.get.svt_id}{literal}'}
//    ]
//    {/literal}
//    {/if}
//    {literal}
//  });
//});

$(function BuildGrid(){
  $("#GridSvtPo").jqGrid('jqGridImport',{imptype:"jsonstring", impstring:window.localStorage.getItem("{/literal}{$smarty.session.SessionAuth.id}-GridSvtPo{literal}")});
  $("#GridSvtPo").jqGrid({
    caption:{/literal}'{$MS_SP->Sp_LangMessage.GridsCaptions.Po}'{literal},
    datatype: "json",
    url:"{/literal}{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/SvtPoList.ajax.php{literal}",
    colNames:[{/literal}
      '{$MS_SP->Sp_LangMessage.GridsColNames.name}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.note}'{literal}
    ],
    colModel:[
      {name:'po_name', index:'po_name', width:350},
      {name:'po_note', index:'po_note', width:350}
    ],
    multiselect: true,
    multiboxonly:true,
    rowNum:100,
    rowList:[10,25,100,500],
    pager: "#GridSvtPoPager",
    sortname: 'po_name',
    sortorder: "asc",
    viewrecords: true,
    rownumbers: true,
    toolbar: [true,"top"],
    shrinkToFit:false, 
    gridview: true,
    autowidth: true,
    height: 290,
    postData: {"svt_id":"{/literal}{if isset($smarty.get.svt_id)}{$smarty.get.svt_id}{/if}{literal}"}
  });

  $("#GridSvtPo").toolbarButtonAdd("#t_GridSvtPo",{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:SvtPoAdd });
  $("#GridSvtPo").toolbarButtonAdd("#t_GridSvtPo",{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:SvtPoDel });
  $("#GridSvtPo").jqGrid('navGrid','#GridSvtPoPager', {edit:false,add:false,del:false,refresh:false});
  $("#GridSvtPo").jqGrid("navButtonAdd","#GridSvtPoPager",{
    caption: "",
    title: "{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Refresh}{literal}",
    buttonicon :'ui-icon-refresh',
    onClickButton : function (){
      $("#GridSvtPo").trigger("reloadGrid");
    }
  });
  $("#GridSvtPo").jqGrid("navButtonAdd","#GridSvtPoPager",{
    caption: "",
    title: "{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.ColumnChooser}{literal}",
    buttonicon :'ui-icon-transfer-e-w',
    onClickButton : function (){
      $("#GridSvtPo").jqGrid('columnChooser');
    }
  });
  $("#GridSvtPo").navButtonAdd("#GridSvtPoPager",{ 
    caption: "", 
    title: "{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.SaveSettings}{literal}", 
    buttonicon :'ui-icon-disk',
    onClickButton: function () {
      if (typeof window.localStorage !== 'undefined') {
        delete $("#GridSvtPo").jqGrid('getGridParam' ,'postData' )['filters'];
        window.localStorage.setItem("{/literal}{$smarty.session.SessionAuth.id}-GridSvtPo{literal}",$("#GridSvtPo").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}");
      }
    }
  });
  $("#GridSvtPo").navButtonAdd("#GridSvtPoPager",{ 
    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}-GridSvtPo{literal}");
            $(this).dialog('close');
            $("#GridSvtPo").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');
          }
        }
      });
    }
  });
  $("#GridSvtPo").jqGrid('filterToolbar',{stringResult: true, searchOnEnter : true, defaultSearch:"cnof"});
  UpdateJqGrid("GridSvtPo","GridSvtPoWrapper");
});
//]]>
</script>
{/literal}

<div id="GridSvtPoWrapper" class="ui-widget-content ui-corner-all">
  <table id="GridSvtPo"><tr><td></td></tr></table>
  <div id="GridSvtPoPager"></div>
  <div id="t_toolbar1"></div>
</div>