void Grid_OnAction(string actionName, object actionArgument)
    {
        int cannedResponseID = ValidationHelper.GetInteger(actionArgument, 0);

        switch (actionName)
        {
        case "delete":
            ChatSupportCannedResponseInfo cannedResponse = ChatSupportCannedResponseInfoProvider.GetChatSupportCannedResponseInfo(cannedResponseID);

            if (cannedResponse == null)
            {
                return;
            }

            CheckModifyPermissions(cannedResponse);

            ChatSupportCannedResponseInfoProvider.DeleteChatSupportCannedResponseInfo(cannedResponseID);
            break;
        }
    }
Пример #2
0
    private string BuildStartupScript()
    {
        bool       enBBCode = IsSupport || (ChatSettingsProvider.EnableBBCodeSetting && EnableBBCode);
        WebControl input    = enBBCode ? ucBBEditor.TextArea : txtMessage;

        if (enBBCode)
        {
            txtMessage.Visible = false;
        }
        else
        {
            ucBBEditor.Visible = false;
        }

        string json = JsonConvert.SerializeObject(
            new
        {
            roomID                        = RoomID,
            inputClientID                 = GetString(input),
            buttonClientID                = GetString(btnSendMessage),
            groupID                       = GroupID,
            chbWhisperClientID            = GetString(chbWhisper),
            drpRecipientClientID          = GetString(drpRecipient),
            pnlRecipientContainerClientID = GetString(pnlRecipientContainer),
            noneLabel                     = ResHelper.GetString("chat.everyone"),
            enableBBCode                  = enBBCode,
            bbCodeClientID                = GetString(ucBBEditor),
            btnCannedResponses            = GetString(btnCannedResponses),
            pnlContent                    = GetString(pnlWebpartContent),
            envelopeID                    = "#envelope_" + ClientID,
            informDialogID                = GetString(pnlChatMessageSendInfoDialog),
            btnInformDialogClose          = GetString(btnChatMessageSendInformDialogClose)
        },
            new JsonSerializerSettings {
            StringEscapeHandling = StringEscapeHandling.EscapeHtml
        }
            );
        string startupScript = String.Format("InitChatSenderWebpart({0});", json);

        // If this webpart is for support person -> generate "Canned responses"
        if ((ChatOnlineUserHelper.GetLoggedInChatUser() != null) && (IsSupport == true))
        {
            // Get canned responses from database
            IEnumerable <ChatSupportCannedResponseInfo> cannedResponses = ChatSupportCannedResponseInfoProvider.GetCannedResponses(ChatOnlineUserHelper.GetLoggedInChatUser().ChatUserID, SiteContext.CurrentSiteID);

            if (cannedResponses.Any())
            {
                plcCannedResponses.Visible = true;

                // Register necessary files
                ScriptHelper.RegisterScriptFile(Page, "~/CMSWebParts/Chat/ChatMessageSend_files/CannedResponses.js");
                CssRegistration.RegisterCssLink(Page, "~/App_Themes/Design/Chat/ChatIntelliSense.css");

                // Creates canned responses in format expected in javascript
                var cannedResponseToSerialize = from cr in cannedResponses
                                                let resolvedText = MacroResolver.Resolve(cr.ChatSupportCannedResponseText)
                                                                   select new
                {
                    label   = "#" + HTMLHelper.HTMLEncode(cr.ChatSupportCannedResponseTagName),
                    tooltip = HTMLHelper.HTMLEncode(TextHelper.LimitLength(resolvedText, mTooltipLength)),
                    value   = resolvedText
                };

                // Serialize canned responses to JS Array expected by javascript
                string cannedResponsesJSArray = "";
                try
                {
                    cannedResponsesJSArray = JsonConvert.SerializeObject(cannedResponseToSerialize, new JsonSerializerSettings {
                        StringEscapeHandling = StringEscapeHandling.EscapeHtml
                    });
                }
                catch (Exception ex)
                {
                    EventLogProvider.LogException("Chat", "JSON serialization of canned responses", ex);
                }
                startupScript += string.Format("var CannedResponses = {0};", cannedResponsesJSArray);

                startupScript += string.Format("InitCannedResponses({0}, {1});", ScriptHelper.GetString("#" + input.ClientID), ScriptHelper.GetString("#" + btnCannedResponses.ClientID));
            }
        }

        return(startupScript);
    }