tsunami

log in
history

TIME Item.aspx

Luke Breuer
2008-01-13 05:26 UTC

<%@ Page Language="C#" MasterPageFile="~/Main.master" AutoEventWireup="true" CodeBehind="Item.aspx.cs" Inherits="Time.ItemView" 
    Title="Untitled Page" ValidateRequest="false" EnableViewState="false" EnableViewStateMac="false" %>
<%@ MasterType TypeName="Time.Main" %>
<asp:Content ID="Content1" ContentPlaceHolderID="cphLeft" runat="server">

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cphMiddle" runat="server">
    <asp:PlaceHolder ID="plcError" runat="server" Visible="false">
        <asp:Label ID="lblError" runat="server" CssClass="warn" />
    </asp:PlaceHolder>
    
    <div id="divEdit">
        <asp:PlaceHolder ID="plcEditItem" runat="server" Visible="false">
            <asp:HyperLink ID="aEdit" runat="server" AccessKey="e"><img id="Img1" src="~/images/edit.gif" runat="server" alt="edit" /><span id="spanEditText" runat="server">edit item</span></asp:HyperLink>
        </asp:PlaceHolder>
        
        <asp:PlaceHolder ID="plcEditingItem" runat="server" Visible="false">
            <asp:Button ID="btnSave" runat="server" Text="save edit" OnClick="btnSave_Click" AccessKey="s" />
            <asp:Button ID="btnCancel" runat="server" Text="cancel edit" OnClick="btnCancel_Click" AccessKey="q" />
        </asp:PlaceHolder>
    </div>

    <asp:PlaceHolder ID="plcBasicView" runat="Server" Visible="false">
        <h2 id="hBasicName" runat="server"></h2>
        <div id="divBasicKeywords" runat="server" class="filter"></div><br />
        <div id="divBasicRelationship" runat="server" visible="false" class="rel"></div>
        <div id="divBasicData" class="content" runat="server"></div>
    </asp:PlaceHolder>
    
    <asp:PlaceHolder ID="plcBasicEditView" runat="server" Visible="False">
        <div id="divItemFields">
            <asp:Label ID="lblName" runat="server" AssociatedControlID="txtName">item name</asp:Label>
            <asp:TextBox ID="txtName" runat="server" CssClass="text" />
            <asp:Label ID="lblKeywords" runat="server" AssociatedControlID="txtKeywords">tags</asp:Label>
            <asp:TextBox ID="txtKeywords" runat="server" CssClass="filter text" />
            <div id="divRelationshipFields" runat="server" visible="false">
                <asp:Label ID="Label1" runat="server" AssociatedControlID="txtRelSubject">points</asp:Label>
                <asp:TextBox ID="txtRelSubject" runat="server" CssClass="text rel" autocomplete="off"></asp:TextBox>
                <asp:Button ID="btnRelSubject" runat="server" Text="find subject" OnClick="btnRel_Click" />
                <asp:PlaceHolder ID="plcRelSubject" runat="Server" />
            
                <asp:Label ID="Label2" runat="server" AssociatedControlID="txtRelObject">to</asp:Label>
                <asp:TextBox ID="txtRelObject" runat="server" CssClass="text rel" autocomplete="off"></asp:TextBox>
                <asp:Button ID="btnRelObject" runat="server" Text="find object" OnClick="btnRel_Click" />
                <asp:PlaceHolder ID="plcRelObject" runat="Server" />
            
                <asp:Label ID="Label3" runat="server" AssociatedControlID="txtRelPredicate">by</asp:Label>
                <asp:TextBox ID="txtRelPredicate" runat="server" CssClass="text rel" autocomplete="off"></asp:TextBox>
                <asp:Button ID="btnRelPredicate" runat="server" Text="find predicate" OnClick="btnRel_Click" />
                <asp:PlaceHolder ID="plcRelPredicate" runat="Server" />
            
                <script>
function InputWatcher(input, callback, interval)
{
    var id;
    var oldValue = input.value;
    
    this.Input = input;
    
    var OnChange = function()
    {
        if (input.value != oldValue)        
        {
            callback(input);
            oldValue = input.value;
        }       
    };
    
    this.Stop = function() 
    {
        clearInterval(id); 
    };

    this.Resume = function() 
    { 
        id = setInterval(OnChange, interval); 
    };
            
    this.Restart = function() 
    { 
        oldValue = input.value; 
        id = setInterval(OnChange, interval); 
    };
    
    this.Restart();
}

function RelSearch(txt)
{
    if (txt.value.length >= 2)
        _rels[txt.id].Req.PerformGet('ajaxSearch=' + escape(txt.value) + '&relTxtId=' + txt.id, true);
}

function GotRelData(data)
{
    var match = /^([a-zA-Z0-9_]+):(.*)$/.exec(data);
    var txtId = match[1];
    var html = match[2];
    // the _ is included to make replacing the wrong thing less likely
    var dl = $(txtId.replace('_txt', '_dl'));
    var btn = $(txtId.replace('_txt', '_btn'));
    
    if (dl != null)
        dl.parentNode.removeChild(dl);
    
    var div = document.createElement('div');
    div.innerHTML = html;
        
    btn.parentNode.insertBefore(div.firstChild, btn.nextSibling.nextSibling);
}

var _rels = {
    '<%=txtRelSubject.ClientID%>' :
    {
        Req: new XmlHttpRequest(GotRelData, null),
        Watcher: new InputWatcher($('<%=txtRelSubject.ClientID%>'), RelSearch, 300)
    },
    '<%=txtRelObject.ClientID%>' :
    {
        Req: new XmlHttpRequest(GotRelData, null),
        Watcher: new InputWatcher($('<%=txtRelObject.ClientID%>'), RelSearch, 300)
    },
    '<%=txtRelPredicate.ClientID%>' :
    {
        Req: new XmlHttpRequest(GotRelData, null),
        Watcher: new InputWatcher($('<%=txtRelPredicate.ClientID%>'), RelSearch, 300)
    }   
}
                </script>
            </div>
            <asp:Label ID="lblData" runat="server" AssociatedControlID="txtData"></asp:Label>
            <asp:TextBox ID="txtData" runat="server" TextMode="multiLine" />
        </div>
    </asp:PlaceHolder>
    
    <asp:PlaceHolder ID="plcItemList" runat="server" Visible="false">
        <h2 id="hItemList" runat="server"></h2>
        <dl id="dlItems" runat="server"></dl>
    </asp:PlaceHolder>
    
    <asp:PlaceHolder ID="plcKeywordList" runat="server" Visible="false">
        <a id="aFloatOff" href="#">toggle list style</a>
        <ul id="ulKeywordList" runat="server" class="filter floatList"></ul>
        <script type="text/javascript">
            $('aFloatOff').onclick = function()
            {
                var ul = $('<%=ulKeywordList.ClientID%>');
                
                // HACK: use ToggleClass method instead
                ul.className = ul.className != 'filter'
                    ? 'filter'
                    : 'filter floatList';                   
                
                return false;
            }
        </script>
    </asp:PlaceHolder>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="cphRight" runat="server">  
    <asp:PlaceHolder ID="plcRelationshipList" runat="server" Visible="false">
        <asp:PlaceHolder ID="plcSubjectFor" runat="server">
            <fieldset id="fldSubjectFor" runat="server">
                <legend>points to</legend>
                <dl id="dlSubjectFor" runat="server" visible="false"></dl>
                <a href="?add=subject" rel="nofollow"><img src="~/images/add.gif" runat="server" alt="add" /> add</a>
            </fieldset>
        </asp:PlaceHolder>
    
        <asp:PlaceHolder ID="plcObjectFor" runat="server">
            <fieldset id="fldObjectFor" runat="server">
                <legend>pointed to by</legend>
                <dl id="dlObjectFor" runat="server" visible="false"></dl>
                <a href="?add=object" rel="nofollow"><img src="~/images/add.gif" runat="server" alt="add" /> add</a>
            </fieldset>
        </asp:PlaceHolder>
    
        <asp:PlaceHolder ID="plcPredicateFor" runat="server">
            <fieldset id="fldPredicateFor" runat="server">
                <legend>points</legend>
                <dl id="dlPredicateFor" runat="server" visible="false"></dl>
                <a href="?add=predicate" rel="nofollow"><img src="~/images/add.gif" runat="server" alt="add" /> add</a>
            </fieldset>
        </asp:PlaceHolder>
    </asp:PlaceHolder>
</asp:Content>