HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/TDijk1/erp-apps.eu/wwwroot/CMSWebParts/Pux/HTML/ResourceBundlerComponent.ascx.cs
using CMS.Helpers;
using CMS.PortalControls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class CMSWebParts_Pux_HTML_ResourceBundlerComponent : CMSAbstractWebPart
{
    public string Files
    {
        get
        {
            return ValidationHelper.GetString(GetValue("Files"), string.Empty);
        }
        set
        {
            SetValue("Files", value);
        }
    }

    public string GroupCss
    {
        get
        {
            return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("GroupCss"), string.Empty), WebPartID);
        }
        set
        {
            SetValue("GroupCss", value);
        }
    }

    public string GroupJs
    {
        get
        {
            return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("GroupJs"), string.Empty), WebPartID);
        }
        set
        {
            SetValue("GroupJs", value);
        }
    }


    public override void OnContentLoaded()
    {
        base.OnContentLoaded();
        SetupControl();
    }

    protected void SetupControl()
    {
        if (this.StopProcessing || !Enabled)
        {
            // Do not process
            Visible = false;
        }
        else
        {
            if (string.IsNullOrEmpty(Files))
            {
                // nothing to do
                return;
            }

            var files = Files.Split('\n').Select(p => p.Trim()).Where(p => !string.IsNullOrEmpty(p.Trim())).ToList();
            var cssFiles = files.Where(p => p.EndsWith(".css") || p.EndsWith(" [css]")).Select(p => p.Replace(" [css]", "").Trim());
            var javascriptFiles = files.Where(p => p.EndsWith(".js") || p.EndsWith(" [js]")).Select(p => p.Replace(" [js]", "").Trim());

            if (cssFiles.Any())
            {
                ResourceBundlerCss.Files = cssFiles.Join(Environment.NewLine);
                ResourceBundlerCss.Group = GroupCss;
            }
            else
            {
                ResourceBundlerCss.StopProcessing = true;
            }

            if (javascriptFiles.Any())
            {
                ResourceBundlerJavaScript.Files = javascriptFiles.Join(Environment.NewLine);
                ResourceBundlerJavaScript.Group = GroupJs;
            }
            else
            {
                ResourceBundlerJavaScript.StopProcessing = true;
            }
        }
    }

    public override void ReloadData()
    {
        base.ReloadData();

        SetupControl();
    }


    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);

        // render HTML comment for easier debugging
        //Page.Header.Controls.Add(new LiteralControl(string.Format("<!-- {0} -->\r\n", DataHelper.GetNotEmpty(WebPartTitle, WebPartID))));
    }
}