{* Smarty *}

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

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

function PassDel(){
  var VarId = $("#GridPass").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/PassDel.ajax.php{literal}",
              data: {
                pass_id: VarId
              },
              success: function(answ){
                if("undefined" == typeof(answ["error"])){
                  $("#GridPass").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 PassView(com,grid){
  var VarCountSelectedRows = $("#GridPass").jqGrid('getGridParam','selarrrow').length;
  if(0 == VarCountSelectedRows){
    DialogStandartMessageOpen('error', "{/literal}{$MS_SP->Sp_LangMessage.warning.WarnShouldSelectRecord}{literal}");
  }
  else if(1 == VarCountSelectedRows){
    var VarId = $("#GridPass").jqGrid('getGridParam','selrow');
    $.ajax({
      async: false,
      timeout: 3000,
      type: 'GET',
      url: "{/literal}{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/PassView.ajax.php{literal}",
      data: {
        pass_id: VarId
      },
      success: function(answ){
        DialogStandartOpen('PassViewFrm', answ, "{/literal}{$MS_SP->Sp_LangMessage.message.MessPassView}{literal}");
      }
    });
  }
  else{
    DialogStandartMessageOpen('error', "{/literal}{$MS_SP->Sp_LangMessage.warning.WarnShouldSelectOnlyOneRecord}{literal}");
  }
}

$(function BuildGrid(){
  $("#GridPass").jqGrid('jqGridImport',{imptype:"jsonstring", impstring:window.localStorage.getItem("{/literal}{$smarty.session.SessionAuth.id}-GridPass{literal}")});
  $("#GridPass").jqGrid({
    caption:{/literal}'{$MS_SP->Sp_LangMessage.GridsCaptions.Pass}'{literal},
    datatype: "json",
    url:"{/literal}{$MS_SP->Sp_PathTop}{$MS_SP->Sp_PathToSite}/AjaxServer/PassList.ajax.php{literal}",
    colNames:[{/literal}
      '{$MS_SP->Sp_LangMessage.GridsColNames.privacy}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.name}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.users_name}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.date}',
      '{$MS_SP->Sp_LangMessage.GridsColNames.note}'{literal}
    ],
    colModel:[
      {name:'pass_share', index:'pass_share', width:100},
      {name:'pass_name', index:'pass_name', width:200},
      {name:'pass_login', index:'pass_login', width:200},
      {name:'pass_date', index:'pass_date', width:60, sorttype:'date', datefmt: 'dd.mm.YYYY', formatter: 'date', 
        searchoptions:{
          dataInit:function(el){ 
            $(el).prop("VarGridName", 'GridPass');
            GridDatepickerSetParam(el);
          }
        }
      },
      {name:'pass_note', index:'pass_note', width:300}
    ],
    multiselect: true,
    multiboxonly:true,
    rowNum:100,
    rowList:[10,25,100,500],
    pager: "#GridPassPager",
    sortname: 'pass_name',
    sortorder: "asc",
    viewrecords: true,
    rownumbers: true,
    toolbar: [true,"top"],
    shrinkToFit:false, 
    gridview: true,
    autowidth: true,
    height: 290
  });
  $("#GridPass").toolbarButtonAdd("#t_GridPass",{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('GridPass');}});
  $("#GridPass").toolbarButtonAdd("#t_GridPass",{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:PassAdd });
  $("#GridPass").toolbarButtonAdd("#t_GridPass",{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:PassEdit });
{/literal}
  {if isset($smarty.session.SessionAuth.SvtAdmin.reg) && 1 eq $smarty.session.SessionAuth.SvtAdmin.reg}
{literal}
  $("#GridPass").toolbarButtonAdd("#t_GridPass",{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:PassDel });
{/literal}
  {/if}
{literal}
  $("#GridPass").toolbarButtonAdd("#t_GridPass",{caption:"{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.PassView}{literal}",position:"last",title:"{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.PassView}{literal}", buttonicon :'ui-icon-unlocked', cursor: "pointer", onClickButton:PassView });
{/literal}
  {if isset($VarPassSelect) && 1 eq $VarPassSelect}
{literal}
    $("#GridPass").toolbarButtonAdd("#t_GridPass",{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:PassSelect });
{/literal}
  {/if}
{literal}
$("#GridPass").jqGrid("navButtonAdd","#GridPassPager",{
    caption: "",
    title: "{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.Refresh}{literal}",
    buttonicon :'ui-icon-refresh',
    onClickButton : function (){
      $("#GridPass").trigger("reloadGrid");
    }
  });
  $("#GridPass").jqGrid("navButtonAdd","#GridPassPager",{
    caption: "",
    title: "{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.ColumnChooser}{literal}",
    buttonicon :'ui-icon-transfer-e-w',
    onClickButton : function (){
      $("#GridPass").jqGrid('columnChooser');
    }
  });
  $("#GridPass").navButtonAdd("#GridPassPager",{ 
    caption: "", 
    title: "{/literal}{$MS_SP->Sp_LangMessage.GridsButtons.SaveSettings}{literal}", 
    buttonicon :'ui-icon-disk',
    onClickButton: function () {
      if (typeof window.localStorage !== 'undefined') {
        delete $("#GridPass").jqGrid('getGridParam' ,'postData' )['filters'];
        window.localStorage.setItem("{/literal}{$smarty.session.SessionAuth.id}-GridPass{literal}",$("#GridPass").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}");
      }
    }
  });
  $("#GridPass").navButtonAdd("#GridPassPager",{ 
    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}-GridPass{literal}");
            $(this).dialog('close');
            $("#GridPass").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');
          }
        }
      });
    }
  });
  $("#GridPass").jqGrid('filterToolbar',{stringResult: true, searchOnEnter : true, defaultSearch:"cnof"});
  UpdateJqGrid("GridPass","GridPassWrapper");
});
//]]>
</script>
{/literal}

<div id="GridPassWrapper" class="ui-widget-content ui-corner-all">
  <table id="GridPass"><tr><td></td></tr></table>
  <div id="GridPassPager"></div>
  <div id="t_toolbar1"></div>
</div>