<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="AttachmentList.ascx.cs" Inherits="APC.Forms.BaseUserControls.AttachmentList" %>
<%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>
<%@ Register TagPrefix="uc1" TagName="addAttach" Src="~/Forms/BaseUserControls/AddAttachment.ascx"%>
<script language="javascript">
    var prepareCommand = function (grid, command, record, row) 
{
    if (command.command == 'Delete' && !grid.allowEdit && record.data.StatusInt != 1) 
    {
        command.hidden = true;
       command.hideMode = 'display'; //you can try 'visibility' also                 
    }            
 };
</script>
 <ext:GridPanel ID="grdAttach" runat="server" AnchorHorizontal="100%" AnchorVertical="100%" AutoScroll="true" Height="350" runat="server" Width="300">
 <TopBar>
            <ext:Toolbar ID="btnToolbar" runat="server">
            <Items>
                <ext:Button ID="btnAdd" runat="server" Text="Add..." Icon="Add" Disabled="True">
                <DirectEvents>
                    <Click OnEvent="AddAttach_Click">
                        <EventMask ShowMask="true"/>
                    </Click>
                </DirectEvents>
                </ext:Button>
            </Items>
            </ext:Toolbar>
 </TopBar>
 <Store>
<ext:Store ID="Store1" runat="server" OnReadData="AttachList_Refresh">
    <Model>
        <ext:Model runat="server" IDProperty="Oid">
     <Fields>
        <ext:ModelField Name="Description"/>
        <ext:ModelField Name="StatusInt" />
        <ext:ModelField Name="Status" />
        <ext:ModelField Name="UploadDate" SortType="AsDate" Type="Date"/>
        <ext:ModelField Name="Url"/>
    </Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
       <ColumnModel>
            <Columns>
                 <ext:RowNumbererColumn runat="server" Width="15" />
                  <ext:ImageCommandColumn ID="ImageCommandColumn1" runat="server" Width="40">
                            <Commands>
                                <ext:ImageCommand Icon="Magnifier" CommandName="View">
                                    
                                    <ToolTip Text="View Attachment"/>
                                </ext:ImageCommand>
                                <ext:ImageCommand Icon="Delete" CommandName="Delete">
                                    <ToolTip Text="Delete this Attachment" />
                                </ext:ImageCommand>
                            </Commands>
                              <Listeners>
                                <Command Handler="if (command == 'View'){console.log('data = ' + record.data.Url);window.open(record.data.Url); return false;} else {return true;}" />
                            </Listeners>
                            <PrepareCommand Fn="prepareCommand" />
                                           <DirectEvents>
                        <Command OnEvent="Command" Timeout="200000" Success="#{grdAttach}.store.reload();">
                            <Confirmation ConfirmRequest="True" BeforeConfirm="return (command != 'View');" Message="Are you sure ?" Title="Attachment Delete"></Confirmation>
                            <EventMask ShowMask="True"></EventMask>
                            <ExtraParams>
                                <ext:Parameter Name="id" Value="record.data.Oid" Mode="Raw" />
                                <ext:Parameter Name="command" Value="command" Mode="Raw" />
                            </ExtraParams>
                        </Command>
                       </DirectEvents>

                 </ext:ImageCommandColumn>                      
                 <ext:Column ID="Column1" runat="server" Text="Description" DataIndex="Description" Width="200" Sortable="True" Flex="1"/>       
                 <ext:DateColumn runat="server" Format="yyyy-MM-dd hh:mmtt" Text="Upload Date" DataIndex="UploadDate" Width="120" Sortable="True"/>
            </Columns>            
        </ColumnModel>       
        <SelectionModel>
            <ext:RowSelectionModel runat="server" />
        </SelectionModel>
            <Features>
            <ext:GridFilters Local="true">
            <Filters>
            <ext:StringFilter DataIndex="Description" />
            </Filters>
            </ext:GridFilters>
            </Features>
</ext:GridPanel>
 <uc1:addattach id="AddAttach" runat="server" />
