Creare Gadged nella barra laterale

Modificata il mercoledì, 23 settembre 2009 16:45 da roberto — Categorizzata come: Non Categorizzata

Disponibile dalla versione 6.8 di Tustena CRM

La barra laterale di Tustena, può essere personalizzata con l'aggiunta di nuovi gadget e funzionalità

Per creare un nuovo Gadget, per prima cosa bisogna aggiungere un file .ascx (il nome è indifferente) nella cartella SideBar.

Una volta creato il file .cs, bisogna far ereditare la classe da SideBarControl e dall'interfaccia ISideBar. Successivamente nel costruttore, bisogna impostare un ID e un Titolo (this.ID e this.Title) al controllo.

Questa pagina è solo un Draft, il contenuto può essere incompleto e contenere errori.

Allego un esempio di codebehind per semplificare le cose: In questo esempio viene creata una semplice Chat per lo scambio di messaggi tra gli Utenti di Tustena. I messaggi vengono salvati in Application, quindi non avranno una vera e propria persistenza, ma saranno rimossi al riciclo dell'applicazione.

Inoltre in questo esempio c'è un approccio su come utilizzare il motore Ajaxed per eseguire un PostBack parziale su dati parziali della pagina.

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Digita.Tustena.WebControls;
using Digita;

public partial class SideBar_MyGadget : SideBarControl, ISideBar
{
    public SideBar_MyGadget()
    {
        this.ID = "MyGadget";
        this.Title = "La mia Chat Interna";
        if (HttpContext.Current.Application["Chat_Box"] == null)
        {
            HttpContext.Current.Application.Add("Chat_Box", string.Empty);
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        ((AjaxedPage)Page).GetAjaxed(PostMessage, "MessageList", null, AjaxedPage.AjaxedType.PostbackEvent);
    }

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        PostMessage.Click += new EventHandler(PostMessage_Click);
    }

    void PostMessage_Click(object sender, EventArgs e)
    {
        ((AjaxedPage)Page).RemoveAllAjaxedControl();
        ((AjaxedPage)Page).GetAjaxed(MessageList, "MessageList", null, AjaxedPage.AjaxedType.Inner);
        ((AjaxedPage)Page).GetAjaxed(Message, null, null, AjaxedPage.AjaxedType.Inner);
        ((AjaxedPage)Page).GetAjaxed(PostMessage, null, null, AjaxedPage.AjaxedType.Inner);
        
        if (!string.IsNullOrEmpty(Message.Text))
        {
            string msg = string.Format("<span style=\"color:Red\">{1} scrive:</span>{0}{2}{0}{3}", Environment.NewLine, UC.UserRealName, Message.Text, Application["Chat_Box"]);
            Message.Text = string.Empty;
            if (msg.Length > 1000)
            {
                msg=msg.Substring(0, msg.LastIndexOf("<span "));
            }
                Application["Chat_Box"] = msg;
        }
    }

    protected override void OnPreRender(EventArgs e)
    {
        MessageList.Text = Application["Chat_Box"].ToString().Replace(Environment.NewLine, "<br/>");
        
        base.OnPreRender(e);
    }
    protected override void Render(HtmlTextWriter writer)
    {
        base.Render(writer);
    }
}

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="MyGadget.ascx.cs" Inherits="SideBar_MyGadget" %>
<twc:jscontrolid runat="server" Identifier="Chat"></twc:jscontrolid>
<div style=" color:Black; padding:2px; margin:2px; width:100%; height:100px; overflow-y: scroll; background-color:White; margin:2px;" id="MessageList">
    <asp:Literal ID="MessageList" runat="server"></asp:Literal>
</div>
<div>
    <asp:TextBox runat="server" ID="Message" CssClass="BoxDesign"></asp:TextBox>
</div>
<div class="Tbutton" style="text-align:right">
    <twc:LocTustenaButton runat="server" ID="PostMessage" Logo="plus" Text="Invia"></twc:LocTustenaButton>
</div>
<script type="text/javascript">
    function poolChat() {
        eval($('#' + jsControlIdChat + 'PostMessage').attr('href'));
        chatTimeout = setTimeout('poolChat()', 5000);
    }
    AJAXED.scrollToInjection = false;
    var chatTimeout=setTimeout('poolChat()', 5000);
</script>