Beispiel #1
0
    object gridData_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        switch (sourceName.ToLower())
        {
        case "publicstatusdisplayname":
            return(HTMLHelper.HTMLEncode(ResHelper.LocalizeString(Convert.ToString(parameter))));

        case "skuenabled":
            return(UniGridFunctions.ColoredSpanYesNo(parameter));

        case "skuprice":
            DataRowView row    = (DataRowView)parameter;
            double      value  = ValidationHelper.GetDouble(row["SKUPrice"], 0);
            int         siteId = ValidationHelper.GetInteger(row["SKUSiteID"], 0);

            return(CurrencyInfoProvider.GetFormattedPrice(value, siteId));

        case "skusiteid":
            return(UniGridFunctions.ColoredSpanYesNo(parameter == DBNull.Value));
        }

        return(parameter);
    }
Beispiel #2
0
    private object gridViews_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        switch (sourceName.ToLowerCSafe())
        {
        case "iscustom":
            bool isCustom = ValidationHelper.GetBoolean(parameter, false);
            return(UniGridFunctions.ColoredSpanYesNo(isCustom));

        case "delete":
            if (!SystemContext.DevelopmentMode)
            {
                // Disable "delete" button for system objects
                bool delete = ValidationHelper.GetBoolean(((DataRowView)((GridViewRow)parameter).DataItem).Row["IsCustom"], false);
                if (!delete)
                {
                    CMSGridActionButton button = ((CMSGridActionButton)sender);
                    button.Enabled = false;
                }
            }
            break;
        }
        return(sender);
    }
Beispiel #3
0
    protected object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        switch (sourceName.ToLowerCSafe())
        {
        case "approved":
            return(UniGridFunctions.ColoredSpanYesNo(parameter, true));

        case "approve":
            CMSGridActionButton button = ((CMSGridActionButton)sender);
            if (button != null)
            {
                bool isApproved = ValidationHelper.GetBoolean(((DataRowView)((GridViewRow)parameter).DataItem).Row["SubscriptionApproved"], true);

                if (isApproved)
                {
                    button.Visible = false;
                }
            }
            break;
        }

        return(HTMLHelper.HTMLEncode(Convert.ToString(parameter)));
    }
    /// <summary>
    /// Handles the UniGrid's OnExternalDataBound event.
    /// </summary>
    protected object UniGridStrings_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        switch (sourceName.ToLowerCSafe())
        {
        case "edititem":
            ImageButton ib = sender as ImageButton;
            if (ib != null)
            {
                GridViewRow gvr = parameter as GridViewRow;
                if (gvr != null)
                {
                    DataView dv = gvr.DataItem as DataView;
                    if (dv != null)
                    {
                        if (ui != null)
                        {
                            ResourceStringInfo ri = SqlResourceManager.GetResourceStringInfo(ValidationHelper.GetString(dv[0], ""), ui.UICultureCode);
                            if (ri != null)
                            {
                                ib.OnClientClick = String.Format("location.href='Edit.aspx?stringid={0}&uicultureid={1}'; return false;", ri.StringId, ui.UICultureID);
                            }
                        }
                    }
                }
            }
            break;

        case "stringiscustom":
            return(UniGridFunctions.ColoredSpanYesNo(parameter));

        case "culturetext":
        case "defaulttext":
            return(MacroResolver.RemoveSecurityParameters(parameter.ToString(), true, null));
        }

        return(parameter);
    }
Beispiel #5
0
    protected object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        switch (sourceName.ToLowerCSafe())
        {
        case "couponvalue":
            DataRowView row    = (DataRowView)parameter;
            double      value  = ValidationHelper.GetDouble(row["DiscountCouponValue"], 0);
            bool        isFlat = ValidationHelper.GetBoolean(row["DiscountCouponIsFlatValue"], false);
            int         siteId = ValidationHelper.GetInteger(row["DiscountCouponSiteID"], 0);

            if (isFlat)
            {
                return(CurrencyInfoProvider.GetFormattedPrice(value, siteId));
            }
            else
            {
                return(value.ToString() + "%");
            }

        case "discountcouponsiteid":
            return(UniGridFunctions.ColoredSpanYesNo(parameter == DBNull.Value));
        }
        return(parameter);
    }
Beispiel #6
0
    private object gridViews_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        switch (sourceName.ToLowerCSafe())
        {
        case "iscustom":
            bool isCustom = ValidationHelper.GetBoolean(parameter, false);
            return(UniGridFunctions.ColoredSpanYesNo(isCustom));

        case "delete":
            if (!SettingsKeyProvider.DevelopmentMode)
            {
                // Disable "delete" button for system objects
                bool delete = ValidationHelper.GetBoolean(((DataRowView)((GridViewRow)parameter).DataItem).Row["IsCustom"], false);
                if (!delete)
                {
                    ImageButton button = ((ImageButton)sender);
                    button.Attributes.Add("src", GetImageUrl("Design/Controls/UniGrid/Actions/DeleteDisabled.png"));
                    button.Enabled = false;
                }
            }
            break;
        }
        return(sender);
    }
    protected object gridComments_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        bool approve = false;

        switch (sourceName.ToLower())
        {
        case "commentusername":
            return(HTMLHelper.HTMLEncode(Convert.ToString(parameter)));

        case "commenttext":
            string text = Convert.ToString(parameter);
            if (text.Length > 50)
            {
                text = text.Substring(0, 50) + "...";
            }
            return(HTMLHelper.HTMLEncode(text));

        case "commentapproved":
            return(UniGridFunctions.ColoredSpanYesNo(parameter));

        case "commentisspam":

            return(UniGridFunctions.ColoredSpanYesNoReversed(parameter));

        case "approve":
            approve = ValidationHelper.GetBoolean(((DataRowView)((GridViewRow)parameter).DataItem).Row["CommentApproved"], false);
            if (!approve)
            {
                ImageButton button = ((ImageButton)sender);
                button.ImageUrl = GetImageUrl("Design/Controls/UniGrid/Actions/Approve.png");
                button.ToolTip  = GetString("general.approve");
            }
            else
            {
                ImageButton button = ((ImageButton)sender);
                button.ImageUrl = GetImageUrl("Design/Controls/UniGrid/Actions/Reject.png");
                button.ToolTip  = GetString("general.reject");
            }
            break;

        case "edit":
            string commentId = ((DataRowView)((GridViewRow)parameter).DataItem).Row["CommentID"].ToString();

            ImageButton editButton = ((ImageButton)sender);

            //Get filter query string
            string queryCondition = String.Empty;
            if (ShowFilter)
            {
                queryCondition = this.filterElem.FilterQueryString;
            }
            else
            {
                queryCondition = FilterQueryString;
            }

            //If no display use postback for refresh
            string usePostback = String.Empty;
            if (!ShowFilter)
            {
                usePostback = "&usepostback=true";
            }

            editButton.OnClientClick = "modalDialog('" + ResolveUrl("~/CMSModules/Blogs/Controls/Comment_Edit.aspx") + "?commentID=" + commentId + queryCondition + usePostback + "', 'CommentEdit', 500, 440); return false;";
            break;
        }

        return(parameter);
    }
    /// <summary>
    /// Handles external databound event of unigrid.
    /// </summary>
    protected object OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        int  userID;
        bool isUserAdministrator;

        switch (sourceName.ToLowerCSafe())
        {
        case "userenabled":
            return(UniGridFunctions.ColoredSpanYesNo(parameter));

        case "edit":
            // Edit action
            userID = ValidationHelper.GetInteger(((DataRowView)((GridViewRow)parameter).DataItem).Row["UserID"], 0);
            isUserAdministrator = ValidationHelper.GetBoolean(((DataRowView)((GridViewRow)parameter).DataItem).Row["UserIsGlobalAdministrator"], false);
            if (!CurrentUserObj.CheckPrivilegeLevel(UserPrivilegeLevelEnum.GlobalAdmin) && isUserAdministrator && (userID != CurrentUserObj.UserID))
            {
                CMSGridActionButton button = ((CMSGridActionButton)sender);
                button.Enabled = false;
            }

            break;

        case "delete":
            // Delete action
            isUserAdministrator = ValidationHelper.GetBoolean(((DataRowView)((GridViewRow)parameter).DataItem).Row["UserIsGlobalAdministrator"], false);
            if (!CurrentUserObj.CheckPrivilegeLevel(UserPrivilegeLevelEnum.GlobalAdmin) && isUserAdministrator)
            {
                CMSGridActionButton button = ((CMSGridActionButton)sender);
                button.Enabled = false;
            }
            break;

        case "roles":
            // Roles action
            userID = ValidationHelper.GetInteger(((DataRowView)((GridViewRow)parameter).DataItem).Row["UserID"], 0);
            isUserAdministrator = ValidationHelper.GetBoolean(((DataRowView)((GridViewRow)parameter).DataItem).Row["UserIsGlobalAdministrator"], false);

            if (!CurrentUserObj.CheckPrivilegeLevel(UserPrivilegeLevelEnum.GlobalAdmin) && isUserAdministrator && (userID != CurrentUserObj.UserID))
            {
                CMSGridActionButton button = ((CMSGridActionButton)sender);
                button.Enabled = false;
            }

            break;

        case "haspassword":
            // Has password action
        {
            CMSGridActionButton button = ((CMSGridActionButton)sender);

            if (!CurrentUserObj.IsGlobalAdministrator)
            {
                button.Visible = false;
            }
            else
            {
                bool isExternal  = ValidationHelper.GetBoolean(((DataRowView)((GridViewRow)parameter).DataItem).Row["UserIsExternal"], false);
                bool isPublic    = ValidationHelper.GetString(((DataRowView)((GridViewRow)parameter).DataItem).Row["UserName"], string.Empty).EqualsCSafe("public", true);
                bool hasPassword = ValidationHelper.GetBoolean(((DataRowView)((GridViewRow)parameter).DataItem).Row["UserHasPassword"], true);

                button.OnClientClick = "return false;";
                button.Visible       = !hasPassword && !isPublic && !isExternal;
            }
        }
        break;

        case "formattedusername":
            return(HTMLHelper.HTMLEncode(Functions.GetFormattedUserName(Convert.ToString(parameter))));

        case "#objectmenu":
            userID = ValidationHelper.GetInteger(((DataRowView)((GridViewRow)parameter).DataItem).Row["UserID"], 0);
            isUserAdministrator = ValidationHelper.GetBoolean(((DataRowView)((GridViewRow)parameter).DataItem).Row["UserIsGlobalAdministrator"], false);
            if (!CurrentUserObj.CheckPrivilegeLevel(UserPrivilegeLevelEnum.GlobalAdmin) && isUserAdministrator && (userID != CurrentUserObj.UserID))
            {
                CMSGridActionButton button = ((CMSGridActionButton)sender);
                button.Visible = false;
            }
            break;
        }
        return(parameter);
    }
    /// <summary>
    /// Handles Unigrid's OnExternalDataBound event.
    /// </summary>
    protected object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        int  userID;
        bool isUserAdministrator;

        switch (sourceName.ToLowerCSafe())
        {
        case "userenabled":
            return(UniGridFunctions.ColoredSpanYesNo(parameter));

        case "edit":
            // Edit action
            userID = ValidationHelper.GetInteger(((DataRowView)((GridViewRow)parameter).DataItem).Row["UserID"], 0);
            isUserAdministrator = ValidationHelper.GetBoolean(((DataRowView)((GridViewRow)parameter).DataItem).Row["UserIsGlobalAdministrator"], false);
            if ((!CurrentUserObj.IsGlobalAdministrator || (CurrentUserObj.IsGlobalAdministrator && CurrentUserObj.UserSiteManagerDisabled)) && isUserAdministrator && (userID != CurrentUserObj.UserID))
            {
                ImageButton button = ((ImageButton)sender);
                button.ImageUrl = GetImageUrl("Design/Controls/UniGrid/Actions/Editdisabled.png");
                button.Enabled  = false;
            }

            break;

        case "delete":
            // Delete action
            isUserAdministrator = ValidationHelper.GetBoolean(((DataRowView)((GridViewRow)parameter).DataItem).Row["UserIsGlobalAdministrator"], false);
            if ((!CurrentUserObj.IsGlobalAdministrator || (CurrentUserObj.IsGlobalAdministrator && CurrentUserObj.UserSiteManagerDisabled)) && isUserAdministrator)
            {
                ImageButton button = ((ImageButton)sender);
                button.ImageUrl = GetImageUrl("Design/Controls/UniGrid/Actions/Deletedisabled.png");
                button.Enabled  = false;
            }
            break;

        case "roles":
            // Roles action
            userID = ValidationHelper.GetInteger(((DataRowView)((GridViewRow)parameter).DataItem).Row["UserID"], 0);
            isUserAdministrator = ValidationHelper.GetBoolean(((DataRowView)((GridViewRow)parameter).DataItem).Row["UserIsGlobalAdministrator"], false);

            if ((!CurrentUserObj.IsGlobalAdministrator || (CurrentUserObj.IsGlobalAdministrator && CurrentUserObj.UserSiteManagerDisabled)) && isUserAdministrator && (userID != CurrentUserObj.UserID))
            {
                ImageButton button = ((ImageButton)sender);
                button.ImageUrl = GetImageUrl("Design/Controls/UniGrid/Actions/Managerolesdisabled.png");
                button.Enabled  = false;
            }

            break;

        case "haspassword":
            // Has password action
        {
            ImageButton button = ((ImageButton)sender);

            if (!CurrentUserObj.IsGlobalAdministrator)
            {
                button.Visible = false;
            }
            else
            {
                bool isExternal  = ValidationHelper.GetBoolean(((DataRowView)((GridViewRow)parameter).DataItem).Row["UserIsExternal"], false);
                bool isPublic    = ValidationHelper.GetString(((DataRowView)((GridViewRow)parameter).DataItem).Row["UserName"], string.Empty).EqualsCSafe("public", true);
                bool hasPassword = ValidationHelper.GetBoolean(((DataRowView)((GridViewRow)parameter).DataItem).Row["UserHasPassword"], true);

                button.OnClientClick = "return false;";
                button.Style.Add("cursor", "default");
                button.Visible = !hasPassword && !isPublic && !isExternal;
            }
        }
        break;

        case "formattedusername":
            return(HTMLHelper.HTMLEncode(Functions.GetFormattedUserName(Convert.ToString(parameter))));

        case "#objectmenu":
            userID = ValidationHelper.GetInteger(((DataRowView)((GridViewRow)parameter).DataItem).Row["UserID"], 0);
            isUserAdministrator = ValidationHelper.GetBoolean(((DataRowView)((GridViewRow)parameter).DataItem).Row["UserIsGlobalAdministrator"], false);
            if ((!CurrentUserObj.IsGlobalAdministrator || (CurrentUserObj.IsGlobalAdministrator && CurrentUserObj.UserSiteManagerDisabled)) && isUserAdministrator && (userID != CurrentUserObj.UserID))
            {
                ImageButton button = ((ImageButton)sender);
                button.Visible = false;
            }
            break;
        }
        return(parameter);
    }
    protected object gridComments_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        switch (sourceName.ToLowerCSafe())
        {
        case "commentusername":
            return(HTMLHelper.HTMLEncode(Convert.ToString(parameter)));

        case "commenttext":
            string text = Convert.ToString(parameter);
            if (text.Length > 50)
            {
                text = text.Substring(0, 50) + "...";
            }
            return(HTMLHelper.HTMLEncode(text));

        case "commentapproved":
            return(UniGridFunctions.ColoredSpanYesNo(parameter));

        case "commentisspam":

            return(UniGridFunctions.ColoredSpanYesNoReversed(parameter));

        case "approve":
            bool approve = ValidationHelper.GetBoolean(((DataRowView)((GridViewRow)parameter).DataItem).Row["CommentApproved"], false);
            if (!approve)
            {
                CMSGridActionButton button = ((CMSGridActionButton)sender);
                button.IconCssClass = "icon-check-circle";
                button.IconStyle    = GridIconStyle.Allow;
                button.ToolTip      = GetString("general.approve");
            }
            else
            {
                CMSGridActionButton button = ((CMSGridActionButton)sender);
                button.IconCssClass = "icon-times-circle";
                button.IconStyle    = GridIconStyle.Critical;
                button.ToolTip      = GetString("general.reject");
            }
            break;

        case "edit":
            string commentId = ((DataRowView)((GridViewRow)parameter).DataItem).Row["CommentID"].ToString();

            CMSGridActionButton editButton = ((CMSGridActionButton)sender);

            // Get filter query string
            string queryCondition = ShowFilter ? filterElem.FilterQueryString : FilterQueryString;

            // If no display use postback for refresh
            string usePostback = String.Empty;
            if (!ShowFilter)
            {
                usePostback = "&usepostback=true";
            }

            editButton.OnClientClick = "modalDialog('" + ResolveUrl("~/CMSModules/Blogs/Controls/Comment_Edit.aspx") + "?commentID=" + commentId + queryCondition + usePostback + "', 'CommentEdit', 850, 480); return false;";
            break;
        }

        return(parameter);
    }
Beispiel #11
0
 /// <summary>
 /// Returns colored boolean value string (TRUE -> green color, FALSE - red color)
 /// </summary>
 /// <param name="val">Boolean value string</param>
 protected string GetColoredBooleanString(object val)
 {
     return(UniGridFunctions.ColoredSpanYesNo(val));
 }
Beispiel #12
0
    private object gridData_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        DataRowView row = parameter as DataRowView;

        if (DocumentListingDisplayed)
        {
            switch (sourceName.ToLowerInvariant())
            {
            case "skunumber":
            case "skuavailableitems":
            case "publicstatusid":
            case "allowforsale":
            case "skusiteid":
            case "typename":
            case "skuprice":

                if (ShowSections && (row["NodeSKUID"] == DBNull.Value))
                {
                    return(NO_DATA_CELL_VALUE);
                }

                break;

            case "edititem":
                row = ((GridViewRow)parameter).DataItem as DataRowView;

                if ((row != null) && ((row["NodeSKUID"] == DBNull.Value) || showProductsInTree))
                {
                    CMSGridActionButton btn = sender as CMSGridActionButton;
                    if (btn != null)
                    {
                        int currentNodeId = ValidationHelper.GetInteger(row["NodeID"], 0);
                        int nodeParentId  = ValidationHelper.GetInteger(row["NodeParentID"], 0);

                        if (row["NodeSKUID"] == DBNull.Value)
                        {
                            btn.IconCssClass = "icon-eye";
                            btn.IconStyle    = GridIconStyle.Allow;
                            btn.ToolTip      = GetString("com.sku.viewproducts");
                        }

                        // Go to the selected document
                        btn.OnClientClick = "EditItem(" + currentNodeId + ", " + nodeParentId + "); return false;";
                    }
                }

                break;
            }
        }

        switch (sourceName.ToLowerInvariant())
        {
        case "skunumber":
            string skuNumber = ValidationHelper.GetString(row["SKUNumber"], null);
            return(HTMLHelper.HTMLEncode(ResHelper.LocalizeString(skuNumber) ?? ""));

        case "skuavailableitems":
            var sku            = new SKUInfo(row.Row);
            int availableItems = sku.SKUAvailableItems;

            // Inventory tracked by variants
            if (sku.SKUTrackInventory == TrackInventoryTypeEnum.ByVariants)
            {
                return(GetString("com.inventory.trackedbyvariants"));
            }

            // Inventory tracking disabled
            if (sku.SKUTrackInventory == TrackInventoryTypeEnum.Disabled)
            {
                return(GetString("com.inventory.nottracked"));
            }

            // Ensure correct values for unigrid export
            if (sender == null)
            {
                return(availableItems);
            }

            // Tracking by products
            var inlineAvailableItems = new InlineEditingTextBox
            {
                Text          = availableItems.ToString(),
                DelayedReload = DocumentListingDisplayed,
                EnableEncode  = false
            };

            inlineAvailableItems.Formatting += (s, e) =>
            {
                var reorderAt = sku.SKUReorderAt;

                // Emphasize the number when product needs to be reordered
                if (availableItems <= reorderAt)
                {
                    // Format message informing about insufficient stock level
                    string reorderMsg = string.Format(GetString("com.sku.reorderatTooltip"), reorderAt);
                    string message    = string.Format("<span class=\"alert-status-error\" onclick=\"UnTip()\" onmouseout=\"UnTip()\" onmouseover=\"Tip('{1}')\">{0}</span>", availableItems, reorderMsg);
                    inlineAvailableItems.FormattedText = message;
                }
            };

            // Unigrid with delayed reload in combination with inline edit control requires additional postback to sort data.
            // Update data only if external data bound is called for the first time.
            if (!forceReloadData)
            {
                inlineAvailableItems.Update += (s, e) =>
                {
                    var newNumberOfItems = ValidationHelper.GetInteger(inlineAvailableItems.Text, availableItems);

                    if (ValidationHelper.IsInteger(inlineAvailableItems.Text) && (-1000000000 <= newNumberOfItems) && (newNumberOfItems <= 1000000000))
                    {
                        CheckModifyPermission(sku);

                        // Ensures that grid will display inserted value
                        sku.SKUAvailableItems = newNumberOfItems;

                        // Document list is used to display products -> document has to be updated to ensure correct sku mapping
                        if (DocumentListingDisplayed)
                        {
                            int documentId = ValidationHelper.GetInteger(row.Row["DocumentID"], 0);

                            // Create an instance of the Tree provider and select edited document with coupled data
                            var tree     = new TreeProvider(MembershipContext.AuthenticatedUser);
                            var document = tree.SelectSingleDocument(documentId);
                            if (document == null)
                            {
                                return;
                            }

                            document.SetValue("SKUAvailableItems", newNumberOfItems);
                            document.Update();

                            forceReloadData = true;
                        }
                        // Stand-alone product -> only product has to be updated
                        else
                        {
                            sku.MakeComplete(true);
                            sku.Update();

                            gridData.ReloadData();
                        }
                    }
                    else
                    {
                        inlineAvailableItems.ErrorText = GetString("com.productedit.availableitemsinvalid");
                    }
                };
            }

            return(inlineAvailableItems);

        case "skuprice":

            var product        = new SKUInfo(row.Row);
            var currency       = CurrencyInfoProvider.GetMainCurrency(product.SKUSiteID);
            var formattedValue = CurrencyInfoProvider.GetFormattedValue(product.SKUPrice, currency);

            // Ensure correct values for unigrid export
            if (sender == null)
            {
                return(formattedValue);
            }

            var inlineSkuPrice = new InlineEditingTextBox
            {
                Text          = formattedValue,
                FormattedText = CurrencyInfoProvider.GetFormattedPrice(product.SKUPrice, currency),
                DelayedReload = DocumentListingDisplayed
            };

            // Unigrid with delayed reload in combination with inline edit control requires additional postback to sort data.
            // Update data only if external data bound is called for the first time.
            if (!forceReloadData)
            {
                inlineSkuPrice.Update += (s, e) =>
                {
                    CheckModifyPermission(product);

                    var price = ValidationHelper.GetDecimal(inlineSkuPrice.Text, -1);
                    var error = ValidatePrice(price, currency, product);
                    if (String.IsNullOrEmpty(error))
                    {
                        UpdatePrice(product, price, row.Row);
                    }
                    else
                    {
                        inlineSkuPrice.ErrorText = error;
                    }
                };
            }

            return(inlineSkuPrice);

        case "publicstatusid":
            int id = ValidationHelper.GetInteger(row["SKUPublicStatusID"], 0);
            PublicStatusInfo publicStatus = PublicStatusInfoProvider.GetPublicStatusInfo(id);
            if (publicStatus != null)
            {
                // Localize and encode
                return(HTMLHelper.HTMLEncode(ResHelper.LocalizeString(publicStatus.PublicStatusDisplayName)));
            }

            return(string.Empty);

        case "allowforsale":
            // Get "on sale" flag
            return(UniGridFunctions.ColoredSpanYesNo(ValidationHelper.GetBoolean(row["SKUEnabled"], false)));

        case "typename":
            string docTypeName = ValidationHelper.GetString(row["ClassDisplayName"], null);

            // Localize class display name
            if (!string.IsNullOrEmpty(docTypeName))
            {
                return(HTMLHelper.HTMLEncode(ResHelper.LocalizeString(docTypeName)));
            }

            return(string.Empty);
        }

        return(parameter);
    }
Beispiel #13
0
    /// <summary>
    /// Grid external data bound handler.
    /// </summary>
    protected object gridFiles_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        // Get the data row view from parameter
        DataRowView drv = null;

        if (parameter is DataRowView)
        {
            drv = (DataRowView)parameter;
        }
        else if (parameter is GridViewRow)
        {
            // Get data from the grid view row
            drv = (DataRowView)((GridViewRow)parameter).DataItem;
        }

        // Get the action button
        var btn = sender as CMSGridActionButton;

        switch (sourceName)
        {
        case "delete":
        {
            // Delete action
            int    siteId   = ValidationHelper.GetInteger(drv["AttachmentSiteID"], 0);
            string siteName = SiteInfoProvider.GetSiteName(siteId);

            Guid   guid      = ValidationHelper.GetGuid(drv["AttachmentGUID"], Guid.Empty);
            string extension = ValidationHelper.GetString(drv["AttachmentExtension"], "");

            // Check if the file is in DB
            bool db = ValidationHelper.GetBoolean(drv["HasBinary"], false);

            // Check if the file is in the file system
            bool   fs   = false;
            string path = AttachmentBinaryHelper.GetFilePhysicalPath(siteName, guid.ToString(), extension);
            if (File.Exists(path))
            {
                fs = true;
            }

            // If the file is present in both file system and database, delete is allowed
            if (fs && db)
            {
                var filesLocationType = GetFilesLocationType(siteId);

                // If the files are stored in file system or use both locations, delete is allowed in database
                if (filesLocationType != FilesLocationTypeEnum.Database)
                {
                    btn.OnClientClick = btn.OnClientClick.Replace("'delete'", "'deleteindatabase'");
                    btn.ToolTip       = "Delete from database";
                    return(parameter);
                }

                // Else the files are stored in database, delete is allowed in file system
                btn.OnClientClick = btn.OnClientClick.Replace("'delete'", "'deleteinfilesystem'");
                btn.ToolTip       = "Delete from file system";
                return(parameter);
            }

            btn.Visible = false;
        }
        break;

        case "copy":
        {
            // Delete action
            int    siteId   = ValidationHelper.GetInteger(drv["AttachmentSiteID"], 0);
            string siteName = SiteInfoProvider.GetSiteName(siteId);

            Guid   guid      = ValidationHelper.GetGuid(drv["AttachmentGUID"], Guid.Empty);
            string extension = ValidationHelper.GetString(drv["AttachmentExtension"], "");

            // Check if the file is in DB
            bool db = ValidationHelper.GetBoolean(drv["HasBinary"], false);

            // Check if the file is in the file system
            bool   fs   = false;
            string path = AttachmentBinaryHelper.GetFilePhysicalPath(siteName, guid.ToString(), extension);
            if (File.Exists(path))
            {
                fs = true;
            }

            var filesLocationType = GetFilesLocationType(siteId);

            // If the file is stored in file system and the file is not present in database, copy to database is allowed
            if (fs && !db && (filesLocationType == FilesLocationTypeEnum.Both))
            {
                btn.OnClientClick = btn.OnClientClick.Replace("'copy'", "'copytodatabase'");
                btn.ToolTip       = "Copy to database";
                //btn.ImageUrl =
                return(parameter);
            }
            // If the file is stored in database and the file is not present in file system, copy to file system is allowed
            if (db && !fs && filesLocationType != FilesLocationTypeEnum.Database)
            {
                btn.OnClientClick = btn.OnClientClick.Replace("'copy'", "'copytofilesystem'");
                btn.ToolTip       = "Copy to file system";
                //btn.ImageUrl =
                return(parameter);
            }

            btn.Visible = false;
        }
        break;

        case "name":
            return(GetAttachmentHtml(new DataRowContainer(drv)));

        case "size":
            // File size
            return(DataHelper.GetSizeString(ValidationHelper.GetInteger(parameter, 0)));

        case "yesno":
            // Yes / No
            return(UniGridFunctions.ColoredSpanYesNo(parameter));

        case "site":
        {
            int siteId = ValidationHelper.GetInteger(parameter, 0);
            if (siteId > 0)
            {
                SiteInfo si = SiteInfoProvider.GetSiteInfo(siteId);
                if (si != null)
                {
                    return(si.DisplayName);
                }
            }
            return(null);
        }

        case "storedinfilesystem":
        {
            // Delete action
            int    siteId   = ValidationHelper.GetInteger(drv["AttachmentSiteID"], 0);
            string siteName = SiteInfoProvider.GetSiteName(siteId);

            Guid   guid      = ValidationHelper.GetGuid(drv["AttachmentGUID"], Guid.Empty);
            string extension = ValidationHelper.GetString(drv["AttachmentExtension"], "");

            // Check if the file is in DB
            bool db = ValidationHelper.GetBoolean(drv["HasBinary"], false);

            // Check if the file is in the file system
            bool   fs   = false;
            string path = AttachmentBinaryHelper.GetFilePhysicalPath(siteName, guid.ToString(), extension);
            if (File.Exists(path))
            {
                fs = true;
            }

            return(UniGridFunctions.ColoredSpanYesNo(fs));
        }
        }

        return(parameter);
    }
Beispiel #14
0
    /// <summary>
    /// Unigrid external data bound handler.
    /// </summary>
    protected object uniGrid_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        switch (sourceName.ToLowerInvariant())
        {
        case "yesno":
            return(UniGridFunctions.ColoredSpanYesNo(parameter));

        case "select":
        {
            var ti = iObjectType.TypeInfo;

            DataRowView drv = (DataRowView)parameter;

            // Get item ID
            string itemID = drv[returnColumnName].ToString();

            // Add global object name prefix if required
            if (AddGlobalObjectNamePrefix && HasSiteIdColumn(ti) && (DataHelper.GetIntValue(drv.Row, ti.SiteIDColumn) == 0))
            {
                itemID = "." + itemID;
            }

            // Add checkbox for multiple selection
            switch (selectionMode)
            {
            case SelectionModeEnum.Multiple:
            case SelectionModeEnum.MultipleTextBox:
            case SelectionModeEnum.MultipleButton:
            {
                var itemWithSeparators = string.Format("{0}{1}{0}", valuesSeparator, itemID);

                string checkBox = string.Format("<span class=\"checkbox\"><input id=\"chk{0}\" type=\"checkbox\" onclick=\"ProcessItem(this,false); UpdateCheckboxAllElement();\" class=\"chckbox\" ", itemID);
                if (hidItem.Value.IndexOf(itemWithSeparators, StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    checkBox += "checked=\"checked\" ";
                }
                else
                {
                    allRowsChecked = false;
                }

                if (disabledItems.Contains(itemWithSeparators))
                {
                    checkBox += "disabled=\"disabled\" ";
                }

                checkBox += string.Format("/><label for=\"chk{0}\">&nbsp;</label></span>", itemID);

                return(checkBox);
            }
            }
        }
        break;

        case "itemname":
        {
            DataRowView drv = (DataRowView)parameter;

            // Get item ID
            string itemID = drv[returnColumnName].ToString();

            // Get item name
            string itemName;

            // Special formatted user name
            if (displayNameFormat == UniSelector.USER_DISPLAY_FORMAT)
            {
                string userName = DataHelper.GetStringValue(drv.Row, "UserName");
                string fullName = DataHelper.GetStringValue(drv.Row, "FullName");

                itemName = Functions.GetFormattedUserName(userName, fullName, IsLiveSite);
            }
            else if (displayNameFormat == null)
            {
                itemName = drv[iObjectType.DisplayNameColumn].ToString();
            }
            else
            {
                MacroResolver resolver = MacroResolver.GetInstance();
                foreach (DataColumn item in drv.Row.Table.Columns)
                {
                    resolver.SetNamedSourceData(item.ColumnName, drv.Row[item.ColumnName]);
                }
                itemName = resolver.ResolveMacros(displayNameFormat);
            }

            if (RemoveMultipleCommas)
            {
                itemName = TextHelper.RemoveMultipleCommas(itemName);
            }

            // Add the prefixes
            itemName = ItemPrefix + itemName;
            itemID   = ItemPrefix + itemID;

            var ti = iObjectType.TypeInfo;

            // Add global object name prefix if required
            if (AddGlobalObjectNamePrefix && HasSiteIdColumn(ti) && (DataHelper.GetIntValue(drv.Row, ti.SiteIDColumn) == 0))
            {
                itemID = "." + itemID;
            }

            if (String.IsNullOrEmpty(itemName))
            {
                itemName = emptyReplacement;
            }

            if (AddGlobalObjectSuffix && HasSiteIdColumn(ti))
            {
                itemName += (DataHelper.GetIntValue(drv.Row, ti.SiteIDColumn) > 0 ? string.Empty : " " + GlobalObjectSuffix);
            }

            // Link action
            string onclick  = null;
            bool   disabled = disabledItems.Contains(";" + itemID + ";");
            if (!disabled)
            {
                string safeItemID = GetSafe(itemID);
                string itemHash   = ValidationHelper.GetHashString(itemID, new HashSettings(ClientID));
                switch (selectionMode)
                {
                case SelectionModeEnum.Multiple:
                case SelectionModeEnum.MultipleTextBox:
                case SelectionModeEnum.MultipleButton:
                    onclick = string.Format("ProcessItem(document.getElementById('chk{0}'),true); UpdateCheckboxAllElement(); return false;", ScriptHelper.GetString(itemID).Trim('\''));
                    break;

                case SelectionModeEnum.SingleButton:
                    onclick = string.Format("SelectItems({0},'{1}'); return false;", safeItemID, itemHash);
                    break;

                case SelectionModeEnum.SingleTextBox:
                    if (allowEditTextBox)
                    {
                        if (!mHasDependingFields)
                        {
                            onclick = string.Format("SelectItems({0},{0},{1},{2},{3},'{4}'); return false;", safeItemID, ScriptHelper.GetString(hdnClientId), ScriptHelper.GetString(txtClientId), ScriptHelper.GetString(hashId), itemHash);
                        }
                        else
                        {
                            onclick = string.Format("SelectItemsReload({0},{0},{1},{2},{3},{4},'{5}'); return false;", safeItemID, ScriptHelper.GetString(hdnClientId), ScriptHelper.GetString(txtClientId), ScriptHelper.GetString(hdnDrpId), ScriptHelper.GetString(hashId), itemHash);
                        }
                    }
                    else
                    {
                        if (!mHasDependingFields)
                        {
                            onclick = string.Format("SelectItems({0},{1},{2},{3},{4},'{5}'); return false;", safeItemID, GetSafe(itemName), ScriptHelper.GetString(hdnClientId), ScriptHelper.GetString(txtClientId), ScriptHelper.GetString(hashId), itemHash);
                        }
                        else
                        {
                            onclick = string.Format("SelectItemsReload({0},{1},{2},{3},{4},{5},'{6}'); return false;", safeItemID, GetSafe(itemName), ScriptHelper.GetString(hdnClientId), ScriptHelper.GetString(txtClientId), ScriptHelper.GetString(hdnDrpId), ScriptHelper.GetString(hashId), itemHash);
                        }
                    }
                    break;

                default:
                    onclick = string.Format("SelectItemsReload({0},{1},{2},{3},{4},{5},'{6}'); return false;", safeItemID, GetSafe(itemName), ScriptHelper.GetString(hdnClientId), ScriptHelper.GetString(txtClientId), ScriptHelper.GetString(hdnDrpId), ScriptHelper.GetString(hashId), itemHash);
                    break;
                }

                onclick = "onclick=\"" + onclick + "\" ";
            }

            if (LocalizeItems)
            {
                itemName = ResHelper.LocalizeString(itemName);
            }

            // Custom Tooltip
            string tooltip = "";
            if (!string.IsNullOrWhiteSpace(toolTipFormat))
            {
                MacroResolver resolver = MacroResolver.GetInstance();
                foreach (DataColumn item in drv.Row.Table.Columns)
                {
                    resolver.SetNamedSourceData(item.ColumnName, drv.Row[item.ColumnName]);
                }
                tooltip = resolver.ResolveMacros(toolTipFormat);
            }
            if (!string.IsNullOrWhiteSpace(tooltip))
            {
                tooltip = "title=\"" + CMS.Helpers.HTMLHelper.EncodeForHtmlAttribute(tooltip) + "\" ";
            }

            return("<div " + (!disabled ? "class=\"SelectableItem\" " : null) + onclick + tooltip + ">" + HTMLHelper.HTMLEncode(TextHelper.LimitLength(itemName, 100)) + "</div>");
        }
        }

        return(null);
    }
    /// <summary>
    /// Unigrid external data bound handler.
    /// </summary>
    protected object uniGrid_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        switch (sourceName.ToLowerCSafe())
        {
        case "yesno":
            return(UniGridFunctions.ColoredSpanYesNo(parameter));

        case "select":
        {
            DataRowView drv = (parameter as DataRowView);

            // Get item ID
            string itemID = drv[returnColumnName].ToString();

            // Add global object name prefix if required
            if (AddGlobalObjectNamePrefix && !String.IsNullOrEmpty(iObjectType.SiteIDColumn) && (ValidationHelper.GetInteger(DataHelper.GetDataRowValue(drv.Row, iObjectType.SiteIDColumn), 0) == 0))
            {
                itemID = "." + itemID;
            }

            // Add checkbox for multiple selection
            switch (selectionMode)
            {
            case SelectionModeEnum.Multiple:
            case SelectionModeEnum.MultipleTextBox:
            case SelectionModeEnum.MultipleButton:
            {
                string checkBox = "<input id=\"chk" + itemID + "\" type=\"checkbox\" onclick=\"ProcessItem(this);\" class=\"chckbox\" ";
                if (hidItem.Value.IndexOfCSafe(valuesSeparator + itemID + valuesSeparator, true) >= 0)
                {
                    checkBox += "checked=\"checked\" ";
                }
                if (disabledItems.Contains(";" + itemID + ";"))
                {
                    checkBox += "disabled=\"disabled\" ";
                }
                checkBox += "/>";

                return(checkBox);
            }
            }
        }
        break;

        case "itemname":
        {
            DataRowView drv = (parameter as DataRowView);

            // Get item ID
            string itemID = drv[returnColumnName].ToString();

            // Get item name
            string itemName = "";

            // Special formatted user name
            if (displayNameFormat == UniSelector.USER_DISPLAY_FORMAT)
            {
                string userName = ValidationHelper.GetString(DataHelper.GetDataRowValue(drv.Row, "UserName"), String.Empty);
                string fullName = ValidationHelper.GetString(DataHelper.GetDataRowValue(drv.Row, "FullName"), String.Empty);

                itemName = Functions.GetFormattedUserName(userName, fullName, IsLiveSite);
            }
            else if (displayNameFormat == null)
            {
                itemName = drv[iObjectType.DisplayNameColumn].ToString();
            }
            else
            {
                itemName = th.MergeText(displayNameFormat, drv.Row);
            }

            if (RemoveMultipleCommas)
            {
                itemName = TextHelper.RemoveMultipleCommas(itemName);
            }

            // Add the prefixes
            itemName = ItemPrefix + itemName;
            itemID   = ItemPrefix + itemID;

            // Add global object name prefix if required
            if (AddGlobalObjectNamePrefix && !String.IsNullOrEmpty(iObjectType.SiteIDColumn) && (ValidationHelper.GetInteger(DataHelper.GetDataRowValue(drv.Row, iObjectType.SiteIDColumn), 0) == 0))
            {
                itemID = "." + itemID;
            }

            if (String.IsNullOrEmpty(itemName))
            {
                itemName = emptyReplacement;
            }

            if (AddGlobalObjectSuffix)
            {
                if ((iObjectType != null) && !string.IsNullOrEmpty(iObjectType.SiteIDColumn))
                {
                    itemName += (ValidationHelper.GetInteger(DataHelper.GetDataRowValue(drv.Row, iObjectType.SiteIDColumn), 0) > 0 ? "" : " " + GlobalObjectSuffix);
                }
            }

            // Link action
            string onclick  = null;
            bool   disabled = disabledItems.Contains(";" + itemID + ";");
            if (!disabled)
            {
                switch (selectionMode)
                {
                case SelectionModeEnum.Multiple:
                case SelectionModeEnum.MultipleTextBox:
                case SelectionModeEnum.MultipleButton:
                    onclick = "ProcessItem(document.getElementById('chk" + ScriptHelper.GetString(itemID).Trim('\'') + "'), true); return false;";
                    break;

                case SelectionModeEnum.SingleButton:
                    onclick = "SelectItems(" + GetSafe(itemID) + "); return false;";
                    break;

                case SelectionModeEnum.SingleTextBox:
                    if (allowEditTextBox)
                    {
                        onclick = "SelectItems(" + GetSafe(itemID) + ", " + GetSafe(itemID) + ", " + ScriptHelper.GetString(hdnClientId) + ", " + ScriptHelper.GetString(txtClientId) + "); return false;";
                    }
                    else
                    {
                        onclick = "SelectItems(" + GetSafe(itemID) + ", " + GetSafe(itemName) + ", " + ScriptHelper.GetString(hdnClientId) + ", " + ScriptHelper.GetString(txtClientId) + "); return false;";
                    }
                    break;

                default:
                    onclick = "SelectItemsReload(" + GetSafe(itemID) + ", " + GetSafe(itemName) + ", " + ScriptHelper.GetString(hdnClientId) + ", " + ScriptHelper.GetString(txtClientId) + ", " + ScriptHelper.GetString(hdnDrpId) + "); return false;";
                    break;
                }

                onclick = "onclick=\"" + onclick + "\" ";
            }

            if (LocalizeItems)
            {
                itemName = ResHelper.LocalizeString(itemName);
            }

            return("<div " + (!disabled ? "class=\"SelectableItem\" " : null) + onclick + ">" + HTMLHelper.HTMLEncode(TextHelper.LimitLength(itemName, 100)) + "</div>");
        }
        }

        return(null);
    }
Beispiel #16
0
    /// <summary>
    ///  On external databound event.
    /// </summary>
    object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        int userID = 0;

        switch (sourceName)
        {
        // Check if user was kicked and if so inform about it
        case "formattedusername":
            DataRowView drv = (DataRowView)parameter;
            if (drv != null)
            {
                UserInfo ui = new UserInfo(drv.Row);
                if (ui != null)
                {
                    string userName = Functions.GetFormattedUserName(ui.UserName);
                    if (UserInfoProvider.UserKicked(ui.UserID))
                    {
                        return(HTMLHelper.HTMLEncode(userName) + " <span style=\"color:#ee0000;\">" + GetString("administration.users.onlineusers.kicked") + "</span>");
                    }

                    return(HTMLHelper.HTMLEncode(userName));
                }
            }
            return("");

        // Is user enabled
        case "userenabled":
            return(UniGridFunctions.ColoredSpanYesNo(parameter));

        case "kick":
            userID = ValidationHelper.GetInteger(((DataRowView)((GridViewRow)parameter).DataItem).Row["UserID"], 0);
            bool userIsAdmin = ValidationHelper.GetBoolean(((DataRowView)((GridViewRow)parameter).DataItem).Row["UserIsGlobalAdministrator"], false);

            if (UserInfoProvider.UserKicked(userID) || userIsAdmin)
            {
                ImageButton button = ((ImageButton)sender);
                button.ImageUrl = GetImageUrl("Design/Controls/UniGrid/Actions/Kickdisabled.png");
                button.Enabled  = false;
            }
            else
            {
                ImageButton button = ((ImageButton)sender);
                button.ImageUrl = GetImageUrl("Design/Controls/UniGrid/Actions/Kick.png");
                button.Enabled  = true;
            }
            return("");

        case "undokick":
            userID = ValidationHelper.GetInteger(((DataRowView)((GridViewRow)parameter).DataItem).Row["UserID"], 0);
            if (UserInfoProvider.UserKicked(userID))
            {
                ImageButton button = ((ImageButton)sender);
                button.ImageUrl = GetImageUrl("Design/Controls/UniGrid/Actions/Undo.png");
                button.Enabled  = true;
            }
            else
            {
                ImageButton button = ((ImageButton)sender);
                button.ImageUrl = GetImageUrl("Design/Controls/UniGrid/Actions/Undodisabled.png");
                button.Enabled  = false;
            }
            return("");

        default:
            return("");
        }
    }
Beispiel #17
0
    /// <summary>
    /// External data binding handler.
    /// </summary>
    protected object gridDocuments_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        int currentNodeId;

        sourceName = sourceName.ToLowerCSafe();
        switch (sourceName)
        {
        case "view":
        {
            // Dialog view item
            DataRowView         data = ((DataRowView)((GridViewRow)parameter).DataItem);
            CMSGridActionButton btn  = ((CMSGridActionButton)sender);
            // Current row is the Root document
            isRootDocument    = (ValidationHelper.GetInteger(data["NodeParentID"], 0) == 0);
            isCurrentDocument = (ValidationHelper.GetInteger(data["NodeID"], 0) == WOpenerNodeID);
            string culture = ValidationHelper.GetString(data["DocumentCulture"], string.Empty);

            // Existing document culture
            if (culture.ToLowerCSafe() == CultureCode.ToLowerCSafe())
            {
                string url = ResolveUrl(!isRootDocument ? DocumentURLProvider.GetUrl(Convert.ToString(data["NodeAliasPath"])) : "~/");

                btn.OnClientClick = "ViewItem(" + ScriptHelper.GetString(url) + "); return false;";
            }
            // New culture version
            else
            {
                currentNodeId     = ValidationHelper.GetInteger(data["NodeID"], 0);
                btn.OnClientClick = "wopener.NewDocumentCulture(" + currentNodeId + ", '" + CultureCode + "'); CloseDialog(); return false;";
            }
        }
        break;

        case "edit":
        {
            CMSGridActionButton btn = ((CMSGridActionButton)sender);
            if (IsEditVisible)
            {
                DataRowView data    = ((DataRowView)((GridViewRow)parameter).DataItem);
                string      culture = ValidationHelper.GetString(data["DocumentCulture"], string.Empty);
                currentNodeId = ValidationHelper.GetInteger(data["NodeID"], 0);
                int nodeParentId = ValidationHelper.GetInteger(data["NodeParentID"], 0);

                if (!RequiresDialog || (culture.ToLowerCSafe() == CultureCode.ToLowerCSafe()))
                {
                    // Go to the selected document or create a new culture version when not used in a dialog
                    btn.OnClientClick = "EditItem(" + currentNodeId + ", " + nodeParentId + "); return false;";
                }
                else
                {
                    // New culture version in a dialog
                    btn.OnClientClick = "wopener.NewDocumentCulture(" + currentNodeId + ", '" + CultureCode + "'); CloseDialog(); return false;";
                }
            }
            else
            {
                btn.Visible = false;
            }
        }
        break;

        case "delete":
        {
            // Delete button
            CMSGridActionButton btn = ((CMSGridActionButton)sender);

            // Hide the delete button for the root document
            btn.Visible = !isRootDocument;
        }
        break;

        case "contextmenu":
        {
            // Dialog context menu item
            CMSGridActionButton btn = ((CMSGridActionButton)sender);

            // Hide the context menu for the root document
            btn.Visible = !isRootDocument && !ShowAllLevels;
        }
        break;

        case "published":
        {
            // Published state
            return(UniGridFunctions.ColoredSpanYesNo(parameter));
        }

        case "versionnumber":
        {
            // Version number
            if (parameter == DBNull.Value)
            {
                parameter = "-";
            }
            parameter = HTMLHelper.HTMLEncode(parameter.ToString());

            return(parameter);
        }

        case "documentname":
        {
            // Document name
            DataRowView data             = (DataRowView)parameter;
            string      className        = ValidationHelper.GetString(data["ClassName"], string.Empty);
            string      classDisplayName = ValidationHelper.GetString(data["classdisplayname"], null);
            string      name             = ValidationHelper.GetString(data["DocumentName"], string.Empty);
            string      culture          = ValidationHelper.GetString(data["DocumentCulture"], string.Empty);
            string      cultureString    = null;

            currentNodeId = ValidationHelper.GetInteger(data["NodeID"], 0);
            int nodeParentId = ValidationHelper.GetInteger(data["NodeParentID"], 0);

            if (isRootDocument)
            {
                // User site name for the root document
                name = SiteContext.CurrentSiteName;
            }

            // Default culture
            if (culture.ToLowerCSafe() != CultureCode.ToLowerCSafe())
            {
                cultureString = " (" + culture + ")";
            }

            StringBuilder sb = new StringBuilder();

            if (ShowDocumentTypeIcon)
            {
                // Prepare tooltip for document type icon
                string iconTooltip = "";
                if (ShowDocumentTypeIconTooltip && (classDisplayName != null))
                {
                    iconTooltip = string.Format("onmouseout=\"UnTip()\" onmouseover=\"Tip('{0}')\"", HTMLHelper.HTMLEncode(ResHelper.LocalizeString(classDisplayName)));
                }

                if (className.EqualsCSafe("cms.file", true))
                {
                    string extension = ValidationHelper.GetString(data["DocumentType"], string.Empty);
                    sb.Append(UIHelper.GetFileIcon(Page, extension, additionalAttributes: iconTooltip));
                }
                // Use class icons
                else
                {
                    var dataClass = DataClassInfoProvider.GetDataClassInfo(className);
                    if (dataClass != null)
                    {
                        var iconClass = (string)dataClass.GetValue("ClassIconClass");
                        sb.Append(UIHelper.GetDocumentTypeIcon(Page, className, iconClass, additionalAttributes: iconTooltip));
                    }
                }
            }

            string safeName = HTMLHelper.HTMLEncode(TextHelper.LimitLength(name, 50));
            if (DocumentNameAsLink && !isRootDocument)
            {
                string tooltip = UniGridFunctions.DocumentNameTooltip(data);

                string selectFunction = SelectItemJSFunction + "(" + currentNodeId + ", " + nodeParentId + ");";
                sb.Append("<a href=\"javascript: ", selectFunction, "\"");

                // Ensure onclick action on mobile devices. This is necessary due to Tip/UnTip functions. They block default click behavior on mobile devices.
                if (DeviceContext.CurrentDevice.IsMobile)
                {
                    sb.Append(" ontouchend=\"", selectFunction, "\"");
                }

                sb.Append(" onmouseout=\"UnTip()\" onmouseover=\"Tip('", tooltip, "')\">", safeName, cultureString, "</a>");
            }
            else
            {
                sb.Append(safeName, cultureString);
            }

            // Show document marks only if method is not called from grid export and document marks are allowed
            if ((sender != null) && ShowDocumentMarks)
            {
                // Prepare parameters
                int workflowStepId            = ValidationHelper.GetInteger(DataHelper.GetDataRowViewValue(data, "DocumentWorkflowStepID"), 0);
                WorkflowStepTypeEnum stepType = WorkflowStepTypeEnum.Undefined;

                if (workflowStepId > 0)
                {
                    WorkflowStepInfo stepInfo = WorkflowStepInfoProvider.GetWorkflowStepInfo(workflowStepId);
                    if (stepInfo != null)
                    {
                        stepType = stepInfo.StepType;
                    }
                }

                // Create data container
                IDataContainer container = new DataRowContainer(data);

                // Add icons and use current culture of processed node because of 'Not translated document' icon
                sb.Append(" ", DocumentHelper.GetDocumentMarks(Page, currentSiteName, ValidationHelper.GetString(container.GetValue("DocumentCulture"), string.Empty), stepType, container));
            }

            return(sb.ToString());
        }

        case "documentculture":
        {
            DocumentFlagsControl ucDocFlags = null;

            if (OnDocumentFlagsCreating != null)
            {
                // Raise event for obtaining custom DocumentFlagControl
                object result = OnDocumentFlagsCreating(this, sourceName, parameter);
                ucDocFlags = result as DocumentFlagsControl;

                // Check if something other than DocumentFlagControl was returned
                if ((ucDocFlags == null) && (result != null))
                {
                    return(result);
                }
            }

            // Dynamically load document flags control when not created
            if (ucDocFlags == null)
            {
                ucDocFlags = LoadUserControl("~/CMSAdminControls/UI/DocumentFlags.ascx") as DocumentFlagsControl;
            }

            // Set document flags properties
            if (ucDocFlags != null)
            {
                DataRowView data = (DataRowView)parameter;

                // Get node ID
                currentNodeId = ValidationHelper.GetInteger(data["NodeID"], 0);

                if (!string.IsNullOrEmpty(SelectLanguageJSFunction))
                {
                    ucDocFlags.SelectJSFunction = SelectLanguageJSFunction;
                }

                ucDocFlags.ID             = "docFlags" + currentNodeId;
                ucDocFlags.SiteCultures   = SiteCultures;
                ucDocFlags.NodeID         = currentNodeId;
                ucDocFlags.StopProcessing = true;
                ucDocFlags.ItemUrl        = ResolveUrl(DocumentURLProvider.GetUrl(Convert.ToString(data["NodeAliasPath"])));

                // Keep the control for later usage
                FlagsControls.Add(ucDocFlags);
                return(ucDocFlags);
            }
        }
        break;

        case "modifiedwhen":
        case "modifiedwhentooltip":
            // Modified when
            if (string.IsNullOrEmpty(parameter.ToString()))
            {
                return(string.Empty);
            }
            else
            {
                DateTime modifiedWhen = ValidationHelper.GetDateTime(parameter, DateTimeHelper.ZERO_TIME);
                currentUserInfo = currentUserInfo ?? MembershipContext.AuthenticatedUser;
                currentSiteInfo = currentSiteInfo ?? SiteContext.CurrentSite;

                if (sourceName.EqualsCSafe("modifiedwhen", StringComparison.InvariantCultureIgnoreCase))
                {
                    return(TimeZoneHelper.ConvertToUserTimeZone(modifiedWhen, true, currentUserInfo, currentSiteInfo));
                }
                else
                {
                    return(TimeZoneHelper.GetUTCLongStringOffset(currentUserInfo, currentSiteInfo));
                }
            }

        case "classdisplayname":
        case "classdisplaynametooltip":
            // Localize class display name
            if (!string.IsNullOrEmpty(parameter.ToString()))
            {
                return(HTMLHelper.HTMLEncode(ResHelper.LocalizeString(parameter.ToString())));
            }

            return(string.Empty);

        default:
            if (OnExternalAdditionalDataBound != null)
            {
                return(OnExternalAdditionalDataBound(sender, sourceName, parameter));
            }

            break;
        }

        return(parameter);
    }
Beispiel #18
0
    /// <summary>
    /// Loads the index information.
    /// </summary>
    public void LoadData()
    {
        if (SearchIndex == null)
        {
            return;
        }

        var isInAction = (SearchIndex.IndexStatus == IndexStatusEnum.REBUILDING || SearchIndex.IndexStatus == IndexStatusEnum.OPTIMIZING);
        var isNotReady = (!isInAction && SearchIndex.IndexStatus != IndexStatusEnum.READY);

        // Items count
        lblItemCount.Text = ValidationHelper.GetString(SearchIndex.NumberOfIndexedItems, "0");

        // File size
        lblFileSize.Text = DataHelper.GetSizeString(SearchIndex.IndexFileSize);

        // Status
        string statusName = GetString("srch.status." + SearchIndex.IndexStatus.ToString());

        // Show preloader image and link to thread log in status when in action
        if (isInAction)
        {
            var statusText = "";
            if (SearchTaskInfoProvider.IndexerThreadGuid != Guid.Empty)
            {
                string url = URLHelper.ResolveUrl("~/CMSModules/System/Debug/System_ViewLog.aspx");
                url = URLHelper.UpdateParameterInUrl(url, "threadGuid", SearchTaskInfoProvider.IndexerThreadGuid.ToString());
                if (WebFarmHelper.WebFarmEnabled)
                {
                    url = URLHelper.UpdateParameterInUrl(url, "serverName", WebFarmHelper.ServerName);
                }
                statusText = "<a href=\"javascript:void(0)\" onclick=\"modalDialog('" + url + "', 'ThreadProgress', '1000', '700');\" >" + statusName + "</a>";
            }

            ltlStatus.Text    = ScriptHelper.GetLoaderInlineHtml(Page, statusText, "form-control-text");
            ltlStatus.Visible = true;
            lblStatus.Visible = false;
        }
        else
        {
            lblStatus.Text = statusName;
        }

        // Show colored status name
        if (isNotReady)
        {
            lblStatus.Text = "<span class=\"StatusDisabled\">" + statusName + "</span>";
        }
        else if (SearchIndex.IndexStatus == IndexStatusEnum.READY)
        {
            lblStatus.Text = "<span class=\"StatusEnabled\">" + statusName + "</span>";
        }

        // Is optimized
        lblIsOptimized.Text = UniGridFunctions.ColoredSpanYesNo(SearchIndex.IsOptimized());

        // Last update
        lblLastUpdate.Text = SearchIndex.IndexLastUpdate.ToString();

        // Last rebuild
        lblLastRebuild.Text = GetString("general.notavailable");

        if (SearchIndex.IndexLastRebuildTime != DateTimeHelper.ZERO_TIME)
        {
            lblLastRebuild.Text = ValidationHelper.GetString(SearchIndex.IndexLastRebuildTime, "");
        }
    }
Beispiel #19
0
    /// <summary>
    /// Reloads info panel.
    /// </summary>
    protected void ReloadInfoPanel()
    {
        if (sii != null)
        {
            // Keep flag if is in action status
            bool isInAction = (sii.IndexStatus == IndexStatusEnum.REBUILDING || sii.IndexStatus == IndexStatusEnum.OPTIMIZING);

            // Keep flag if index is not usable
            bool isNotReady = (!isInAction && sii.IndexStatus != IndexStatusEnum.READY);

            // get status name
            string statusName = GetString("srch.status." + sii.IndexStatus.ToString());

            // Set progress if is action status
            ltrProgress.Text = String.Empty;
            if (isInAction)
            {
                ltrProgress.Text = "<img style=\"width:12px;height:12px;\" src=\"" + UIHelper.GetImageUrl(this.Page, "Design/Preloaders/preload16.gif") + "\" alt=\"" + statusName + "\" tooltip=\"" + statusName + "\"  />";
            }

            // Fill panel info with informations about index
            lblNumberOfItemsValue.Text = ValidationHelper.GetString(sii.NumberOfIndexedItems, "0");
            lblIndexFileSizeValue.Text = DataHelper.GetSizeString(sii.IndexFileSize);
            lblIndexStatusValue.Text   = statusName;

            // use coloring for status name
            if (isNotReady)
            {
                lblIndexStatusValue.Text = "<span class=\"StatusDisabled\">" + statusName + "</span>";
            }
            else if (sii.IndexStatus == IndexStatusEnum.READY)
            {
                lblIndexStatusValue.Text = "<span class=\"StatusEnabled\">" + statusName + "</span>";
            }

            lblLastRebuildTimeValue.Text = GetString("general.notavailable");
            lblLastUpdateValue.Text      = sii.IndexLastUpdate.ToString();

            if (sii.IndexLastRebuildTime != DateTimeHelper.ZERO_TIME)
            {
                lblLastRebuildTimeValue.Text = ValidationHelper.GetString(sii.IndexLastRebuildTime, "");
            }
            lblIndexIsOptimizedValue.Text = UniGridFunctions.ColoredSpanYesNo(false);

            if (sii.IndexStatus == IndexStatusEnum.READY)
            {
                IndexSearcher searcher = sii.GetSearcher();
                if (searcher != null)
                {
                    IndexReader reader = searcher.GetIndexReader();
                    if (reader != null)
                    {
                        if (reader.IsOptimized())
                        {
                            lblIndexIsOptimizedValue.Text = UniGridFunctions.ColoredSpanYesNo(true);
                        }
                    }
                }
            }
        }
    }
    /// <summary>
    /// Grid external data bound handler.
    /// </summary>
    protected object gridFiles_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        // Get the data row view from parameter
        DataRowView drv = null;

        if (parameter is DataRowView)
        {
            drv = (DataRowView)parameter;
        }
        else if (parameter is GridViewRow)
        {
            // Get data from the grid view row
            GridViewRow gvr = (parameter as GridViewRow);
            if (gvr != null)
            {
                drv = (DataRowView)gvr.DataItem;
            }
        }

        // Get the action button
        CMSGridActionButton btn = null;

        if (sender is CMSGridActionButton)
        {
            btn = (CMSGridActionButton)sender;
        }

        switch (sourceName)
        {
        case "delete":
        {
            // Delete action
            int    siteId   = ValidationHelper.GetInteger(drv["AttachmentSiteID"], 0);
            string siteName = GetSiteName(siteId);

            Guid   guid      = ValidationHelper.GetGuid(drv["AttachmentGUID"], Guid.Empty);
            string extension = ValidationHelper.GetString(drv["AttachmentExtension"], "");

            // Check if the file is in DB
            bool db = ValidationHelper.GetBoolean(drv["HasBinary"], false);

            // Check if the file is in the file system
            bool   fs   = false;
            string path = AttachmentInfoProvider.GetFilePhysicalPath(siteName, guid.ToString(), extension);
            if (File.Exists(path))
            {
                fs = true;
            }

            // If the file is present in both file system and database, delete is allowed
            if (fs && db)
            {
                // If the files are stored in file system, delete is allowed in database
                if (StoreInFileSystem(siteId))
                {
                    btn.OnClientClick = btn.OnClientClick.Replace("'delete'", "'deleteindatabase'");
                    btn.ToolTip       = "Delete from database";
                    return(parameter);
                }
                // If the files are stored in database, delete is allowed in file system
                if (StoreInDatabase(siteId))
                {
                    btn.OnClientClick = btn.OnClientClick.Replace("'delete'", "'deleteinfilesystem'");
                    btn.ToolTip       = "Delete from file system";
                    return(parameter);
                }
            }

            btn.Visible = false;
        }
        break;

        case "copy":
        {
            // Delete action
            int    siteId   = ValidationHelper.GetInteger(drv["AttachmentSiteID"], 0);
            string siteName = GetSiteName(siteId);

            Guid   guid      = ValidationHelper.GetGuid(drv["AttachmentGUID"], Guid.Empty);
            string extension = ValidationHelper.GetString(drv["AttachmentExtension"], "");

            // Check if the file is in DB
            bool db = ValidationHelper.GetBoolean(drv["HasBinary"], false);

            // Check if the file is in the file system
            bool   fs   = false;
            string path = AttachmentInfoProvider.GetFilePhysicalPath(siteName, guid.ToString(), extension);
            if (File.Exists(path))
            {
                fs = true;
            }

            // If the file is stored in file system and the file is not present in database, copy to database is allowed
            if (fs && !db && StoreInDatabase(siteId) && StoreInFileSystem(siteId))
            {
                btn.OnClientClick = btn.OnClientClick.Replace("'copy'", "'copytodatabase'");
                btn.ToolTip       = "Copy to database";
                //btn.ImageUrl =
                return(parameter);
            }
            // If the file is stored in database and the file is not present in file system, copy to file system is allowed
            if (db && !fs && StoreInFileSystem(siteId))
            {
                btn.OnClientClick = btn.OnClientClick.Replace("'copy'", "'copytofilesystem'");
                btn.ToolTip       = "Copy to file system";
                //btn.ImageUrl =
                return(parameter);
            }

            btn.Visible = false;
        }
        break;

        case "name":
        {
            // Attachment name
            string name      = ValidationHelper.GetString(drv["AttachmentName"], "");
            Guid   guid      = ValidationHelper.GetGuid(drv["AttachmentGUID"], Guid.Empty);
            int    siteId    = ValidationHelper.GetInteger(drv["AttachmentSiteID"], 0);
            string extension = ValidationHelper.GetString(drv["AttachmentExtension"], "");

            // File name
            name = Path.GetFileNameWithoutExtension(name);

            string url = ResolveUrl("~/CMSPages/GetFile.aspx?guid=") + guid;
            if (siteId != currentSiteId)
            {
                // Add the site name to the URL if not current site
                SiteInfo si = SiteInfoProvider.GetSiteInfo(siteId);
                if (si != null)
                {
                    url += "&sitename=" + si.SiteName;
                }
            }

            string tooltipSpan = name;
            bool   isImage     = ImageHelper.IsImage(extension);
            if (isImage)
            {
                int imageWidth  = ValidationHelper.GetInteger(DataHelper.GetDataRowViewValue(drv, "AttachmentImageWidth"), 0);
                int imageHeight = ValidationHelper.GetInteger(DataHelper.GetDataRowViewValue(drv, "AttachmentImageHeight"), 0);

                string tooltip = UIHelper.GetTooltipAttributes(url, imageWidth, imageHeight, null, name, extension, null, null, 300);
                tooltipSpan = "<span id=\"" + guid + "\" " + tooltip + ">" + name + "</span>";
            }

            return(UIHelper.GetFileIcon(Page, extension, tooltip: name) + "&nbsp;<a href=\"" + url + "\" target=\"_blank\">" + tooltipSpan + "</a>");
        }

        case "size":
            // File size
            return(DataHelper.GetSizeString(ValidationHelper.GetInteger(parameter, 0)));

        case "yesno":
            // Yes / No
            return(UniGridFunctions.ColoredSpanYesNo(parameter));

        case "site":
        {
            int siteId = ValidationHelper.GetInteger(parameter, 0);
            if (siteId > 0)
            {
                SiteInfo si = SiteInfoProvider.GetSiteInfo(siteId);
                if (si != null)
                {
                    return(si.DisplayName);
                }
            }
            return(null);
        }

        case "storedinfilesystem":
        {
            // Delete action
            int    siteId   = ValidationHelper.GetInteger(drv["AttachmentSiteID"], 0);
            string siteName = GetSiteName(siteId);

            Guid   guid      = ValidationHelper.GetGuid(drv["AttachmentGUID"], Guid.Empty);
            string extension = ValidationHelper.GetString(drv["AttachmentExtension"], "");

            // Check if the file is in DB
            bool db = ValidationHelper.GetBoolean(drv["HasBinary"], false);

            // Check if the file is in the file system
            bool   fs   = false;
            string path = AttachmentInfoProvider.GetFilePhysicalPath(siteName, guid.ToString(), extension);
            if (File.Exists(path))
            {
                fs = true;
            }

            return(UniGridFunctions.ColoredSpanYesNo(fs));
        }
        }

        return(parameter);
    }
Beispiel #21
0
    /// <summary>
    /// Unigrid external data bound handler.
    /// </summary>
    protected object uniGrid_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        switch (sourceName.ToLowerCSafe())
        {
        case "yesno":
            return(UniGridFunctions.ColoredSpanYesNo(parameter));

        case "select":
        {
            DataRowView drv = (parameter as DataRowView);

            // Get item ID
            string itemID  = drv[returnColumnName].ToString();
            string hashKey = itemID;

            // Add global object name prefix if required
            if (AddGlobalObjectNamePrefix && !String.IsNullOrEmpty(iObjectType.SiteIDColumn) && (ValidationHelper.GetInteger(DataHelper.GetDataRowValue(drv.Row, iObjectType.SiteIDColumn), 0) == 0))
            {
                itemID = "." + itemID;
            }

            // Store hash codes for grid items
            if (!hashItems.ContainsKey(hashKey))
            {
                hashItems.Add(hashKey, ValidationHelper.GetHashString(itemID));
            }

            // Add checkbox for multiple selection
            switch (selectionMode)
            {
            case SelectionModeEnum.Multiple:
            case SelectionModeEnum.MultipleTextBox:
            case SelectionModeEnum.MultipleButton:
            {
                string checkBox = string.Format("<span class=\"checkbox\"><input id=\"chk{0}\" type=\"checkbox\" onclick=\"ProcessItem(this,'{1}',false,true);\" class=\"chckbox\" ", itemID, hashItems[hashKey]);
                if (hidItem.Value.IndexOfCSafe(valuesSeparator + itemID + valuesSeparator, true) >= 0)
                {
                    checkBox += "checked=\"checked\" ";
                }
                if (disabledItems.Contains(string.Format("{0}{1}{0}", valuesSeparator, itemID)))
                {
                    checkBox += "disabled=\"disabled\" ";
                }

                checkBox += string.Format("/><label for=\"chk{0}\">&nbsp;</label></span>", itemID);

                return(checkBox);
            }
            }
        }
        break;

        case "itemname":
        {
            DataRowView drv = (parameter as DataRowView);

            // Get item ID
            string itemID  = drv[returnColumnName].ToString();
            string hashKey = itemID;

            // Get item name
            string itemName;

            // Special formatted user name
            if (displayNameFormat == UniSelector.USER_DISPLAY_FORMAT)
            {
                string userName = ValidationHelper.GetString(DataHelper.GetDataRowValue(drv.Row, "UserName"), String.Empty);
                string fullName = ValidationHelper.GetString(DataHelper.GetDataRowValue(drv.Row, "FullName"), String.Empty);

                itemName = Functions.GetFormattedUserName(userName, fullName, IsLiveSite);
            }
            else if (displayNameFormat == null)
            {
                itemName = drv[iObjectType.DisplayNameColumn].ToString();
            }
            else
            {
                MacroResolver resolver = MacroResolver.GetInstance();
                foreach (DataColumn item in drv.Row.Table.Columns)
                {
                    resolver.SetNamedSourceData(item.ColumnName, drv.Row[item.ColumnName]);
                }
                itemName = resolver.ResolveMacros(displayNameFormat);
            }

            if (RemoveMultipleCommas)
            {
                itemName = TextHelper.RemoveMultipleCommas(itemName);
            }

            // Add the prefixes
            itemName = ItemPrefix + itemName;
            itemID   = ItemPrefix + itemID;

            // Add global object name prefix if required
            if (AddGlobalObjectNamePrefix && !String.IsNullOrEmpty(iObjectType.SiteIDColumn) && (ValidationHelper.GetInteger(DataHelper.GetDataRowValue(drv.Row, iObjectType.SiteIDColumn), 0) == 0))
            {
                itemID = "." + itemID;
            }

            if (String.IsNullOrEmpty(itemName))
            {
                itemName = emptyReplacement;
            }

            if (AddGlobalObjectSuffix)
            {
                if ((iObjectType != null) && !string.IsNullOrEmpty(iObjectType.SiteIDColumn))
                {
                    itemName += (ValidationHelper.GetInteger(DataHelper.GetDataRowValue(drv.Row, iObjectType.SiteIDColumn), 0) > 0 ? string.Empty : " " + GlobalObjectSuffix);
                }
            }

            // Link action
            string onclick  = null;
            bool   disabled = disabledItems.Contains(";" + itemID + ";");
            if (!disabled)
            {
                string safeItemID = GetSafe(itemID);
                string itemHash   = ValidationHelper.GetHashString(itemID);
                switch (selectionMode)
                {
                case SelectionModeEnum.Multiple:
                case SelectionModeEnum.MultipleTextBox:
                case SelectionModeEnum.MultipleButton:
                    onclick = string.Format("ProcessItem(document.getElementById('chk{0}'),'{1}',true,true); return false;", ScriptHelper.GetString(itemID).Trim('\''), hashItems[hashKey]);
                    break;

                case SelectionModeEnum.SingleButton:
                    onclick = string.Format("SelectItems({0},'{1}'); return false;", safeItemID, itemHash);
                    break;

                case SelectionModeEnum.SingleTextBox:
                    if (allowEditTextBox)
                    {
                        onclick = string.Format("SelectItems({0},{0},{1},{2},{3},'{4}'); return false;", safeItemID, ScriptHelper.GetString(hdnClientId), ScriptHelper.GetString(txtClientId), ScriptHelper.GetString(hashId), itemHash);
                    }
                    else
                    {
                        onclick = string.Format("SelectItems({0},{1},{2},{3},{4},'{5}'); return false;", safeItemID, GetSafe(itemName), ScriptHelper.GetString(hdnClientId), ScriptHelper.GetString(txtClientId), ScriptHelper.GetString(hashId), itemHash);
                    }
                    break;

                default:
                    onclick = string.Format("SelectItemsReload({0},{1},{2},{3},{4},{5},'{6}'); return false;", safeItemID, GetSafe(itemName), ScriptHelper.GetString(hdnClientId), ScriptHelper.GetString(txtClientId), ScriptHelper.GetString(hdnDrpId), ScriptHelper.GetString(hashId), itemHash);
                    break;
                }

                onclick = "onclick=\"" + onclick + "\" ";
            }

            if (LocalizeItems)
            {
                itemName = ResHelper.LocalizeString(itemName);
            }

            return("<div " + (!disabled ? "class=\"SelectableItem\" " : null) + onclick + ">" + HTMLHelper.HTMLEncode(TextHelper.LimitLength(itemName, 100)) + "</div>");
        }
        }

        return(null);
    }
    private object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        DataRowView row = parameter as DataRowView;

        switch (sourceName.ToLowerCSafe())
        {
        case "optioncategory":
            int optionCategoryId = ValidationHelper.GetInteger(row["SKUOptionCategoryID"], 0);
            OptionCategoryInfo optionCategory = OptionCategoryInfoProvider.GetOptionCategoryInfo(optionCategoryId);

            // Return option category display name for product option or '-' for product
            if (optionCategory != null)
            {
                return(HTMLHelper.HTMLEncode(optionCategory.CategoryDisplayName ?? ""));
            }
            return("-");

        case "skunumber":
            string skuNumber = ValidationHelper.GetString(row["SKUNumber"], null);
            return(HTMLHelper.HTMLEncode(skuNumber ?? ""));

        case "skuprice":
            double value  = ValidationHelper.GetDouble(row["SKUPrice"], 0);
            int    siteId = ValidationHelper.GetInteger(row["SKUSiteID"], 0);

            // Format price
            return(CurrencyInfoProvider.GetFormattedPrice(value, siteId));

        case "skudepartmentid":
            // Tranform to display name and localize
            int            departmentId = ValidationHelper.GetInteger(row["SKUDepartmentID"], 0);
            DepartmentInfo department   = DepartmentInfoProvider.GetDepartmentInfo(departmentId);

            return((department != null) ? HTMLHelper.HTMLEncode(ResHelper.LocalizeString(department.DepartmentDisplayName)) : "");

        case "skumanufacturerid":
            // Tranform to display name and localize
            int manufacturerId            = ValidationHelper.GetInteger(row["SKUManufacturerID"], 0);
            ManufacturerInfo manufacturer = ManufacturerInfoProvider.GetManufacturerInfo(manufacturerId);

            return((manufacturer != null) ? HTMLHelper.HTMLEncode(ResHelper.LocalizeString(manufacturer.ManufacturerDisplayName)) : "");

        case "skusupplierid":
            // Tranform to display name and localize
            int          supplierId = ValidationHelper.GetInteger(row["SKUSupplierID"], 0);
            SupplierInfo supplier   = SupplierInfoProvider.GetSupplierInfo(supplierId);

            return((supplier != null) ? HTMLHelper.HTMLEncode(ResHelper.LocalizeString(supplier.SupplierDisplayName)) : "");

        case "skuavailableitems":
            int?count     = row["SKUAvailableItems"] as int?;
            int?reorderAt = row["SKUReorderAt"] as int?;

            // Emphasise the number when product needs to be reordered
            if (count.HasValue && ((reorderAt.HasValue && (count <= reorderAt)) || (!reorderAt.HasValue && (count <= 0))))
            {
                // Format message informing about insufficient stock level
                string reorderMsg = string.Format(GetString("com.sku.reorderatTooltip"), reorderAt);
                return(string.Format("<span class=\"OperationFailed\">{0}</span>", count));
            }
            return(count);

        case "itemstobereordered":
            int skuReorderAt      = ValidationHelper.GetInteger(row["SKUReorderAt"], 0);
            int skuAvailableItems = ValidationHelper.GetInteger(row["SKUAvailableItems"], 0);
            int difference        = skuReorderAt - skuAvailableItems;

            // Return difference, or '-'
            return((difference > 0) ? difference.ToString() : "-");

        case "skusiteid":
            return(UniGridFunctions.ColoredSpanYesNo(row["SKUSiteID"] == DBNull.Value));
        }

        return(parameter);
    }
    /// <summary>
    /// Loads the index information.
    /// </summary>
    public void LoadData()
    {
        if (SearchIndex == null)
        {
            return;
        }
        var isAzureIndex = IsAzureIndex();

        if (isAzureIndex)
        {
            SearchIndex.InvalidateIndexStatistics();
        }

        var indexStatus = SearchIndexInfoProvider.GetIndexStatus(SearchIndex);
        var isInAction  = indexStatus == IndexStatusEnum.REBUILDING || indexStatus == IndexStatusEnum.OPTIMIZING;
        var isNotReady  = !isInAction && indexStatus != IndexStatusEnum.READY;

        // Items count
        lblItemCount.Text = SearchIndex.IndexDocumentCount.HasValue ? SearchIndex.IndexDocumentCount.ToString() : GetString("general.notavailable");

        // File size
        lblFileSize.Text = SearchIndex.IndexSize.HasValue ? DataHelper.GetSizeString(SearchIndex.IndexSize.Value) : GetString("general.notavailable");

        // Status
        var statusString = (indexStatus == IndexStatusEnum.READY) && SearchIndex.IndexIsOutdated
                        ? "srch.status.readybutoutdated"
                        : "srch.status." + indexStatus;

        string statusName = GetString(statusString);

        // Show preloader image and link to thread log in status when in action
        if (isInAction)
        {
            var statusText = "";
            if (SearchTaskInfoProvider.IndexerThreadGuid != Guid.Empty)
            {
                string url = UrlResolver.ResolveUrl("~/CMSModules/System/Debug/System_ViewLog.aspx");
                url = URLHelper.UpdateParameterInUrl(url, "threadGuid", SearchTaskInfoProvider.IndexerThreadGuid.ToString());
                if (WebFarmHelper.WebFarmEnabled)
                {
                    url = URLHelper.UpdateParameterInUrl(url, "serverName", WebFarmHelper.ServerName);
                }
                statusText = "<a href=\"javascript:void(0)\" onclick=\"modalDialog('" + url + "', 'ThreadProgress', '1000', '700');\" >" + statusName + "</a>";
            }

            ltlStatus.Text    = ScriptHelper.GetLoaderInlineHtml(statusText, "form-control-text");
            ltlStatus.Visible = true;
            lblStatus.Visible = false;
        }
        else
        {
            // Show colored status name
            lblStatus.Text = statusName;

            string cssClass = String.Empty;

            if (isNotReady)
            {
                cssClass = "StatusDisabled";
            }
            else if (indexStatus == IndexStatusEnum.READY)
            {
                cssClass = SearchIndex.IndexIsOutdated ? "color-orange-80" : "StatusEnabled";
            }

            lblStatus.CssClass += " " + cssClass;
        }

        // Is optimized visible only if the search index is Azure based
        DateTime lastFileUpdate = DateTimeHelper.ZERO_TIME;

        if (isAzureIndex)
        {
            plcOptimized.Visible = false;
        }
        else
        {
            lblIsOptimized.Text = UniGridFunctions.ColoredSpanYesNo(SearchIndex.IsOptimized());
            lastFileUpdate      = SearchIndex.IndexFilesLastUpdate;
        }

        // Last update
        var lastUpdate = SearchIndex.IndexLastModified;

        if (lastFileUpdate > lastUpdate)
        {
            lastUpdate = lastFileUpdate;
        }

        lblLastUpdate.Text = lastUpdate.ToString();

        // Last rebuild
        lblLastRebuild.Text = SearchIndex.IndexLastRebuildTime != DateTimeHelper.ZERO_TIME
            ? ValidationHelper.GetString(SearchIndex.IndexLastRebuildTime, "")
            : GetString("general.notavailable");
    }
    private object gridData_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        DataRowView row = parameter as DataRowView;

        if (NodeID > 0)
        {
            switch (sourceName.ToLowerCSafe())
            {
            case "skunumber":
            case "skuavailableitems":
            case "skuprice":
            case "publicstatusid":
            case "allowforsale":
            case "skusiteid":
            case "typename":
                if (ShowSections && (row != null) && (row["NodeSKUID"] == DBNull.Value))
                {
                    return(NO_DATA_CELL_VALUE);
                }

                break;

            case "edititem":
                row = ((GridViewRow)parameter).DataItem as DataRowView;

                if ((row != null) && ((row["NodeSKUID"] == DBNull.Value) || showProductsInTree))
                {
                    ImageButton btn = sender as ImageButton;
                    if (btn != null)
                    {
                        int currentNodeId = ValidationHelper.GetInteger(row["NodeID"], 0);
                        int nodeParentId  = ValidationHelper.GetInteger(row["NodeParentID"], 0);

                        if (row["NodeSKUID"] == DBNull.Value)
                        {
                            btn.ImageUrl = GetImageUrl("Design/Controls/UniGrid/Actions/ViewProducts.png");
                            btn.ToolTip  = GetString("com.sku.viewproducts");
                        }

                        // Go to the selected document
                        btn.OnClientClick = "EditItem(" + currentNodeId + ", " + nodeParentId + "); return false;";
                    }
                }

                break;
            }
        }

        switch (sourceName.ToLowerCSafe())
        {
        case "skunumber":
            string skuNumber = ValidationHelper.GetString(row["SKUNumber"], null);
            return(HTMLHelper.HTMLEncode(skuNumber ?? ""));

        case "skuavailableitems":
            int?count     = row["SKUAvailableItems"] as int?;
            int?reorderAt = row["SKUReorderAt"] as int?;

            // Emphasise the number when product needs to be reordered
            if (count.HasValue && reorderAt.HasValue && (count <= reorderAt))
            {
                // Format message informing about insufficient stock level
                string reorderMsg = string.Format(GetString("com.sku.reorderatTooltip"), reorderAt);
                return(string.Format("<span class=\"OperationFailed\" onmouseout=\"UnTip()\" onmouseover=\"Tip('{1}')\">{0}</span>", count, reorderMsg));
            }

            return(count);

        case "skuprice":
            double value  = ValidationHelper.GetDouble(row["SKUPrice"], 0);
            int    siteId = ValidationHelper.GetInteger(row["SKUSiteID"], 0);

            // Format price
            return(CurrencyInfoProvider.GetFormattedPrice(value, siteId));

        case "publicstatusid":
            int id = ValidationHelper.GetInteger(row["SKUPublicStatusID"], 0);
            PublicStatusInfo publicStatus = PublicStatusInfoProvider.GetPublicStatusInfo(id);
            if (publicStatus != null)
            {
                // Localize and encode
                return(HTMLHelper.HTMLEncode(ResHelper.LocalizeString(publicStatus.PublicStatusDisplayName)));
            }

            return(string.Empty);

        case "allowforsale":
            // Get "on sale" flag
            return(UniGridFunctions.ColoredSpanYesNo(ValidationHelper.GetBoolean(row["SKUEnabled"], false)));

        case "skusiteid":
            // Get "is global" flag
            return(UniGridFunctions.ColoredSpanYesNo(row["SKUSiteID"] == DBNull.Value));

        case "typename":
            string docTypeName = ValidationHelper.GetString(row["ClassDisplayName"], null);

            // Localize class display name
            if (!string.IsNullOrEmpty(docTypeName))
            {
                return(HTMLHelper.HTMLEncode(ResHelper.LocalizeString(docTypeName)));
            }

            return(string.Empty);
        }

        return(parameter);
    }
Beispiel #25
0
    private object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        DataRowView rowView = parameter as DataRowView;

        if (rowView != null)
        {
            SKUInfo sku = new SKUInfo(rowView.Row);
            switch (sourceName.ToLowerCSafe())
            {
            case "skuname":
                string fullName = sku.SKUName;

                // For variant, add name from parent SKU
                if (sku.SKUParentSKUID != 0)
                {
                    SKUInfo parentSku = SKUInfoProvider.GetSKUInfo(sku.SKUParentSKUID);
                    fullName = string.Format("{0}: {1}", parentSku.SKUName, sku.SKUName);
                }
                return(HTMLHelper.HTMLEncode(fullName));

            case "optioncategory":
                OptionCategoryInfo optionCategory = OptionCategoryInfoProvider.GetOptionCategoryInfo(sku.SKUOptionCategoryID);

                // Return option category display name for product option or '-' for product
                if (optionCategory != null)
                {
                    return(HTMLHelper.HTMLEncode(optionCategory.CategoryDisplayName ?? ""));
                }
                return("-");

            case "skunumber":
                return(ResHelper.LocalizeString(sku.SKUNumber, null, true));

            case "skuprice":
                // Format price
                return(CurrencyInfoProvider.GetFormattedPrice(sku.SKUPrice, sku.SKUSiteID));

            case "skudepartmentid":
                // Transform to display name and localize
                DepartmentInfo department = DepartmentInfoProvider.GetDepartmentInfo(sku.SKUDepartmentID);
                return((department != null) ? HTMLHelper.HTMLEncode(ResHelper.LocalizeString(department.DepartmentDisplayName)) : "");

            case "skumanufacturerid":
                // Transform to display name and localize
                ManufacturerInfo manufacturer = ManufacturerInfoProvider.GetManufacturerInfo(sku.SKUManufacturerID);
                return((manufacturer != null) ? HTMLHelper.HTMLEncode(ResHelper.LocalizeString(manufacturer.ManufacturerDisplayName)) : "");

            case "skusupplierid":
                // Transform to display name and localize
                SupplierInfo supplier = SupplierInfoProvider.GetSupplierInfo(sku.SKUSupplierID);
                return((supplier != null) ? HTMLHelper.HTMLEncode(ResHelper.LocalizeString(supplier.SupplierDisplayName)) : "");

            case "skupublicstatusid":
                // Transform to display name and localize
                PublicStatusInfo publicStatus = PublicStatusInfoProvider.GetPublicStatusInfo(sku.SKUPublicStatusID);
                return((publicStatus != null) ? HTMLHelper.HTMLEncode(ResHelper.LocalizeString(publicStatus.PublicStatusDisplayName)) : "");

            case "skuinternalstatusid":
                // Transform to display name and localize
                InternalStatusInfo internalStatus = InternalStatusInfoProvider.GetInternalStatusInfo(sku.SKUInternalStatusID);
                return((internalStatus != null) ? HTMLHelper.HTMLEncode(ResHelper.LocalizeString(internalStatus.InternalStatusDisplayName)) : "");

            case "skuavailableitems":
                int?count     = sku.SKUAvailableItems as int?;
                int?reorderAt = sku.SKUReorderAt as int?;

                // Emphasize the number when product needs to be reordered
                if (count.HasValue && ((reorderAt.HasValue && (count <= reorderAt)) || (!reorderAt.HasValue && (count <= 0))))
                {
                    // Format message informing about insufficient stock level
                    return(string.Format("<span class=\"OperationFailed\">{0}</span>", count));
                }
                return(count);

            case "itemstobereordered":
                int difference = sku.SKUReorderAt - sku.SKUAvailableItems;

                // Return difference, or '-'
                return((difference > 0) ? difference.ToString() : "-");

            case "skusiteid":
                return(UniGridFunctions.ColoredSpanYesNo(sku.SKUSiteID == 0));
            }
        }

        return(parameter);
    }
Beispiel #26
0
    private object OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        bool inherited             = false;
        BadWordActionEnum action   = BadWordActionEnum.None;
        string            siteName = SiteContext.CurrentSiteName;

        switch (sourceName.ToLowerCSafe())
        {
        case "wordaction":
            if (!string.IsNullOrEmpty(parameter.ToString()))
            {
                action = (BadWordActionEnum)Enum.Parse(typeof(BadWordActionEnum), parameter.ToString());
            }
            else
            {
                action    = BadWordsHelper.BadWordsAction(siteName);
                inherited = true;
            }

            // Ensure displaying text labels instead of numbers
            switch (action)
            {
            case BadWordActionEnum.Remove:
                parameter = Control.GetString("general.remove");
                break;

            case BadWordActionEnum.Replace:
                parameter = Control.GetString("general.replace");
                break;

            case BadWordActionEnum.ReportAbuse:
                parameter = Control.GetString("BadWords_Edit.ReportAbuse");
                break;

            case BadWordActionEnum.RequestModeration:
                parameter = Control.GetString("BadWords_Edit.RequestModeration");
                break;

            case BadWordActionEnum.Deny:
                parameter = Control.GetString("Security.Deny");
                break;
            }
            if (inherited)
            {
                parameter += " " + Control.GetString("BadWords_Edit.Inherited");
            }
            break;

        case "wordreplacement":

            // Get DataRowView
            DataRowView drv = parameter as DataRowView;
            if (drv != null)
            {
                string replacement = drv.Row["WordReplacement"].ToString();
                string toReturn    = replacement;

                // Set 'inherited' only if WordReplacement is empty
                if (string.IsNullOrEmpty(replacement))
                {
                    // Get action from cell
                    string actionText = drv.Row["WordAction"].ToString();

                    // Get action enum value
                    if (string.IsNullOrEmpty(actionText))
                    {
                        action = BadWordsHelper.BadWordsAction(siteName);
                    }
                    else
                    {
                        action = (BadWordActionEnum)ValidationHelper.GetInteger(actionText, 0);
                    }

                    // Set replacement only if action is replace
                    if (action == BadWordActionEnum.Replace)
                    {
                        // Get inherited replacement from settings
                        if (string.IsNullOrEmpty(toReturn))
                        {
                            string inheritedSetting = SettingsKeyInfoProvider.GetValue(siteName + ".CMSBadWordsReplacement");
                            toReturn += inheritedSetting + " " + Control.GetString("BadWords_Edit.Inherited");
                        }
                    }
                    else
                    {
                        toReturn = string.Empty;
                    }
                }
                return(HTMLHelper.HTMLEncode(toReturn));
            }
            return(null);

        case "global":
            bool global = ValidationHelper.GetBoolean(parameter, false);
            return(UniGridFunctions.ColoredSpanYesNo(global));
        }
        return(HTMLHelper.HTMLEncode(parameter.ToString()));
    }
Beispiel #27
0
 /// <summary>
 /// Returns colored yes/no according to subscriber's approval info.
 /// </summary>
 private string GetSubscriptionApproved(object parameter)
 {
     return(UniGridFunctions.ColoredSpanYesNo(parameter));
 }