Example #1
0
        private void CheckLimit()
        {
            bool allowadd = false;

            for (int i = 0; i < _maxNumber; i++)
            {
                MacroEditor current = ((MacroEditor)this.ContentTemplateContainer.FindControl(ID + "macroeditor_" + i.ToString()));

                if (!current.Visible)
                {
                    allowadd = true;
                    break;
                }
                ;
            }

            if (!allowadd)
            {
                _addMacro.Enabled = false;
                _limit.Visible    = true;
            }
            else
            {
                _addMacro.Enabled = true;
                _limit.Visible    = false;
            }
        }
Example #2
0
        private void _addMacro_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < _maxNumber; i++)
            {
                MacroEditor current = ((MacroEditor)this.ContentTemplateContainer.FindControl(ID + "macroeditor_" + i.ToString()));

                if (!current.Visible)
                {
                    current.Visible = true;
                    MacroContainerEvent.Add();
                    break;
                }
                ;
            }
        }
Example #3
0
        public void Save()
        {
            string value = string.Empty;

            if (HttpContext.Current.Session[ID + "sortorder"] != null)
            {
                string sortorder = HttpContext.Current.Session[ID + "sortorder"].ToString();

                foreach (string temp in sortorder.Split('&'))
                {
                    string number = temp.Substring(temp.LastIndexOf('=') + 1);

                    if (this.ContentTemplateContainer.FindControl(ID + "macroeditor_" + number) != null)
                    {
                        MacroEditor current = ((MacroEditor)this.ContentTemplateContainer.FindControl(ID + "macroeditor_" + number));
                        if (current.Visible)
                        {
                            value += current.MacroTag;
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < _maxNumber; i++)
                {
                    if (this.ContentTemplateContainer.FindControl(ID + "macroeditor_" + i.ToString()) != null)
                    {
                        MacroEditor current = ((MacroEditor)this.ContentTemplateContainer.FindControl(ID + "macroeditor_" + i.ToString()));
                        if (current.Visible)
                        {
                            value += current.MacroTag;
                        }
                    }
                }
            }
            _data.Value = value;
        }
Example #4
0
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            //SD: This is useless as it won't work in live editing anyways whilst using MS Ajax/ScriptManager for ajax calls
            if (!UmbracoContext.Current.LiveEditingContext.Enabled)
            {
                presentation.webservices.ajaxHelpers.EnsureLegacyCalls(base.Page);
                ScriptManager sm = ScriptManager.GetCurrent(base.Page);
                ServiceReference webservicePath = new ServiceReference(Umbraco.Core.IO.IOHelper.ResolveUrl(Umbraco.Core.IO.SystemDirectories.Umbraco) + "/webservices/MacroContainerService.asmx");

                if (!sm.Services.Contains(webservicePath))
                    sm.Services.Add(webservicePath);
            }
            else
            {
                ClientDependencyLoader.Instance.RegisterDependency("webservices/legacyAjaxCalls.asmx/js", "UmbracoRoot", ClientDependencyType.Javascript);
                ClientDependencyLoader.Instance.RegisterDependency("webservices/MacroContainerService.asmx/js", "UmbracoRoot", ClientDependencyType.Javascript);
            }

            _addMacro = new LinkButton();
            _addMacro.ID = ID + "_btnaddmacro";


            _addMacro.Click += new EventHandler(_addMacro_Click);
            _addMacro.Text = ui.Text("insertMacro");
            _addMacro.CssClass = "macroContainerAdd";

            this.ContentTemplateContainer.Controls.Add(_addMacro);


            _limit = new Literal();
            _limit.Text = string.Format(" Only {0} macros are allowed", _maxNumber);
            _limit.ID = ID + "_litlimit";
            _limit.Visible = false;

            this.ContentTemplateContainer.Controls.Add(_limit);

            string widthHeight = "";
            if (_preferedHeight > 0 && _preferedWidth > 0)
            {
                widthHeight = String.Format(" style=\"min-width: {0}px; min-height: {1}px;\"", _preferedWidth, _preferedHeight);
            }

            this.ContentTemplateContainer.Controls.Add(new LiteralControl(String.Format("<div id=\"" + ID + "container\" class=\"macrocontainer\"{0}>", widthHeight)));

            Regex tagregex = new Regex("<[^>]*(>|$)", RegexOptions.Singleline | RegexOptions.ExplicitCapture | RegexOptions.Compiled);
            MatchCollection tags = tagregex.Matches(_data.Value.ToString());

            List<int> editornumbers = new List<int>();
            string sortorder = string.Empty;


            for (int i = 0; i < _maxNumber; i++)
            {
                if (!editornumbers.Contains(i))
                {
                    string data = string.Empty;

                    if (tags.Count > i)
                        data = tags[i].Value;

                    MacroEditor macroEditor = new MacroEditor(data, _allowedMacros);
                    macroEditor.ID = ID + "macroeditor_" + i;

                    this.ContentTemplateContainer.Controls.Add(macroEditor);
                }


            }

            this.ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));

            if (tags.Count == _maxNumber)
            {
                _addMacro.Enabled = false;
                _limit.Visible = true;
            }



            MacroContainerEvent.Execute += new MacroContainerEvent.ExecuteHandler(MacroContainerEvent_Execute);

        }
        /// <summary>
        /// Creates child controls for this control
        /// </summary>
        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            // get prevalues, load them into the controls.
            var options = this.GetPreValueOptions<RenderMacroOptions>() ?? new RenderMacroOptions(true);
            this.AllowedMacros = Macro.GetAll().Select(m => m.Alias).ToList();

            // if the value of the macro tag is empty, assign the default value.
            if (string.IsNullOrEmpty(options.MacroTag))
            {
                options.MacroTag = RenderMacroOptions.DEFAULT_MACRO_TAG;
            }

            // set-up child controls
            this.MacroEditor = new MacroEditor(options.MacroTag, this.AllowedMacros) { ID = "MacroEditor" };
            this.ShowLabel = new CheckBox() { ID = "ShowLabel", Checked = options.ShowLabel };
            this.Styles = new Literal() { ID = "Styles", Text = "<style type='text/css'>.macroeditor h4, .macroeditor .macroDelete {display:none;}</style>" };

            // add the child controls
            this.Controls.AddPrevalueControls(this.ShowLabel, this.MacroEditor, this.Styles);
        }
Example #6
0
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            //SD: This is useless as it won't work in live editing anyways whilst using MS Ajax/ScriptManager for ajax calls
            if (!UmbracoContext.Current.LiveEditingContext.Enabled)
            {
                presentation.webservices.ajaxHelpers.EnsureLegacyCalls(base.Page);
                ScriptManager    sm             = ScriptManager.GetCurrent(base.Page);
                ServiceReference webservicePath = new ServiceReference(umbraco.IO.IOHelper.ResolveUrl(umbraco.IO.SystemDirectories.Umbraco) + "/webservices/MacroContainerService.asmx");

                if (!sm.Services.Contains(webservicePath))
                {
                    sm.Services.Add(webservicePath);
                }
            }
            else
            {
                ClientDependencyLoader.Instance.RegisterDependency("webservices/legacyAjaxCalls.asmx/js", "UmbracoRoot", ClientDependencyType.Javascript);
                ClientDependencyLoader.Instance.RegisterDependency("webservices/MacroContainerService.asmx/js", "UmbracoRoot", ClientDependencyType.Javascript);
            }

            _addMacro    = new LinkButton();
            _addMacro.ID = ID + "_btnaddmacro";


            _addMacro.Click   += new EventHandler(_addMacro_Click);
            _addMacro.Text     = ui.Text("insertMacro");
            _addMacro.CssClass = "macroContainerAdd";

            this.ContentTemplateContainer.Controls.Add(_addMacro);


            _limit         = new Literal();
            _limit.Text    = string.Format(" Only {0} macros are allowed", _maxNumber);
            _limit.ID      = ID + "_litlimit";
            _limit.Visible = false;

            this.ContentTemplateContainer.Controls.Add(_limit);

            string widthHeight = "";

            if (_preferedHeight > 0 && _preferedWidth > 0)
            {
                widthHeight = String.Format(" style=\"min-width: {0}px; min-height: {1}px;\"", _preferedWidth, _preferedHeight);
            }

            this.ContentTemplateContainer.Controls.Add(new LiteralControl(String.Format("<div id=\"" + ID + "container\" class=\"macrocontainer\"{0}>", widthHeight)));

            Regex           tagregex = new Regex("<[^>]*(>|$)", RegexOptions.Singleline | RegexOptions.ExplicitCapture | RegexOptions.Compiled);
            MatchCollection tags     = tagregex.Matches(_data.Value.ToString());

            List <int> editornumbers = new List <int>();
            string     sortorder     = string.Empty;


            for (int i = 0; i < _maxNumber; i++)
            {
                if (!editornumbers.Contains(i))
                {
                    string data = string.Empty;

                    if (tags.Count > i)
                    {
                        data = tags[i].Value;
                    }

                    MacroEditor macroEditor = new MacroEditor(data, _allowedMacros);
                    macroEditor.ID = ID + "macroeditor_" + i;

                    this.ContentTemplateContainer.Controls.Add(macroEditor);
                }
            }

            this.ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));

            if (tags.Count == _maxNumber)
            {
                _addMacro.Enabled = false;
                _limit.Visible    = true;
            }



            MacroContainerEvent.Execute += new MacroContainerEvent.ExecuteHandler(MacroContainerEvent_Execute);
        }
Example #7
0
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            ajaxHelpers.EnsureLegacyCalls(base.Page);
            var sm = ScriptManager.GetCurrent(base.Page);
            var webservicePath = new ServiceReference(IOHelper.ResolveUrl(SystemDirectories.Umbraco) + "/webservices/MacroContainerService.asmx");

            if (!sm.Services.Contains(webservicePath))
                sm.Services.Add(webservicePath);

            _addMacro = new LinkButton();
            _addMacro.ID = ID + "_btnaddmacro";


            _addMacro.Click += _addMacro_Click;
            _addMacro.Text = ui.Text("insertMacro");
            _addMacro.CssClass = "macroContainerAdd";

            this.ContentTemplateContainer.Controls.Add(_addMacro);


            _limit = new Literal();
            _limit.Text = string.Format(" Only {0} macros are allowed", _maxNumber);
            _limit.ID = ID + "_litlimit";
            _limit.Visible = false;

            this.ContentTemplateContainer.Controls.Add(_limit);

            string widthHeight = "";
            if (_preferedHeight > 0 && _preferedWidth > 0)
            {
                widthHeight = String.Format(" style=\"min-width: {0}px; min-height: {1}px;\"", _preferedWidth, _preferedHeight);
            }

            this.ContentTemplateContainer.Controls.Add(new LiteralControl(String.Format("<div id=\"" + ID + "container\" class=\"macrocontainer\"{0}>", widthHeight)));

            Regex tagregex = new Regex("<[^>]*(>|$)", RegexOptions.Singleline | RegexOptions.ExplicitCapture | RegexOptions.Compiled);
            MatchCollection tags = tagregex.Matches(_data.Value.ToString());

            List<int> editornumbers = new List<int>();
            string sortorder = string.Empty;


            for (int i = 0; i < _maxNumber; i++)
            {
                if (!editornumbers.Contains(i))
                {
                    string data = string.Empty;

                    if (tags.Count > i)
                        data = tags[i].Value;

                    MacroEditor macroEditor = new MacroEditor(data, _allowedMacros);
                    macroEditor.ID = ID + "macroeditor_" + i;

                    this.ContentTemplateContainer.Controls.Add(macroEditor);
                }


            }

            this.ContentTemplateContainer.Controls.Add(new LiteralControl("</div>"));

            if (tags.Count == _maxNumber)
            {
                _addMacro.Enabled = false;
                _limit.Visible = true;
            }



            MacroContainerEvent.Execute += new MacroContainerEvent.ExecuteHandler(MacroContainerEvent_Execute);

        }