Example #1
0
 /// <summary>
 /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering.
 /// </summary>
 protected override void CreateChildControls()
 {
     if (this.PropertyControlUid != string.Empty)
     {
         Control c = DynamicControlFactory.CreatePropertyPage(this.Page, this.PropertyControlUid);
         c.ID = String.Format("wrapControl{0}", this.PropertyControlUid.Replace("-", string.Empty));
         mainContainer.Controls.Add(c);
     }
 }
Example #2
0
        /// <summary>
        /// Handles the ValueChanged event of the hfPrimary control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        void hfPrimary_ValueChanged(object sender, EventArgs e)
        {
            if (hfPrimary.Value == string.Empty || hfPrimary.Value.Split('^').Length < 2)
            {
                throw new ArgumentException("hfUpdate");
            }

            string uid = hfPrimary.Value.Split('^')[0];

            mainContainer.Style.Add("display", "block");
            buttonContainer.Style.Add("display", "block");
            backgroundContainer.Style.Add("display", "block");

            this.PropertyControlUid = uid;

            Control c = DynamicControlFactory.CreatePropertyPage(this.Page, uid);

            c.ID = String.Format("wrapControl{0}", uid.Replace("-", String.Empty));
            mainContainer.Controls.Add(c);
            //TO DO: load PropertyPageControl + Bind
        }
Example #3
0
        /// <summary>
        /// When overridden in an abstract class, creates the control hierarchy that is used to render the composite data-bound control based on the values from the specified data source.
        /// </summary>
        /// <param name="dataSource">An <see cref="T:System.Collections.IEnumerable"></see> that contains the values to bind to the control.</param>
        /// <param name="dataBinding">true to indicate that the <see cref="M:System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls(System.Collections.IEnumerable,System.Boolean)"></see> is called during data binding; otherwise, false.</param>
        /// <returns>
        /// The number of items created by the <see cref="M:System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls(System.Collections.IEnumerable,System.Boolean)"></see>.
        /// </returns>
        protected override int CreateChildControls(System.Collections.IEnumerable dataSource, bool dataBinding)
        {
            int counter = 0;

            controlsJson = string.Empty;

            string _sourceInfo  = string.Empty;
            int    cpPartsCount = 3;

            if (dataBinding)
            {
                foreach (string val in dataSource)
                {
                    if (val == string.Empty || val.Split('^').Length != cpPartsCount)
                    {
                        continue;
                    }

                    string _uid         = val.Split('^')[0];
                    string _collapsed   = val.Split('^')[1].ToLowerInvariant();
                    string _instanceUid = val.Split('^')[2].ToLowerInvariant();

                    counter++;

                    DynamicControlInfo dci = DynamicControlFactory.GetControlInfo(_uid);

                    //fix when user has deleted controls
                    if (dci == null)
                    {
                        continue;
                    }

                    controlsJson += this.bindControl(dci, _collapsed, counter, _instanceUid, ref _sourceInfo);
                }

                if (_sourceInfo.Length > 0)
                {
                    _sourceInfo = _sourceInfo.Remove(_sourceInfo.Length - 1);
                }

                this.ViewState[this.ID + "_sourceInfo"] = _sourceInfo;
            }
            else
            {
                if (this.ViewState[this.ID + "_sourceInfo"] == null)
                {
                    throw new ArgumentNullException("SourceInfo");
                }

                _sourceInfo = this.ViewState[this.ID + "_sourceInfo"].ToString();

                if (_sourceInfo.Length == 0)
                {
                    return(0);
                }

                foreach (string val in _sourceInfo.Split(':'))
                {
                    if (val == string.Empty || val.Split('^').Length != cpPartsCount)
                    {
                        continue;
                    }

                    string _uid         = val.Split('^')[0];
                    string _collapsed   = val.Split('^')[1].ToLowerInvariant();
                    string _instanceUid = val.Split('^')[2].ToLowerInvariant();

                    counter++;

                    DynamicControlInfo dci = DynamicControlFactory.GetControlInfo(_uid);
                    controlsJson += this.bindControl(dci, _collapsed, counter, _instanceUid, ref _sourceInfo);
                }
            }

            if (controlsJson.Length > 0)
            {
                controlsJson = controlsJson.Remove(controlsJson.Length - 1);
            }

            return(counter);
        }
Example #4
0
        /// <summary>
        /// Binds the control.
        /// </summary>
        /// <param name="dci">The dci.</param>
        /// <param name="collapsed">The collapsed.</param>
        /// <param name="counter">The counter.</param>
        /// <param name="sourceInfo">The source info.</param>
        /// <returns></returns>
        private string bindControl(DynamicControlInfo dci, string collapsed, int counter, string instanceUid, ref string sourceInfo)
        {
            StringBuilder sb = new StringBuilder();
            Control       ctrl;

            if (dci != null)
            {
                ctrl = DynamicControlFactory.Create(this.Page, dci.Uid);
            }
            else
            {
                ctrl = this.Page.LoadControl("~/" + dci.Uid.Replace("..\\", string.Empty).Replace("\\", "/"));
            }

            // if control has been removed, return
            if (ctrl == null)
            {
                return(string.Empty);
            }

            HtmlGenericControl divContainer = new HtmlGenericControl("div");
            HtmlGenericControl divHeader    = new HtmlGenericControl("div");

            #region Image ExpandCollapse
            ImageButton imgOpen = new ImageButton();
            imgOpen.ID = String.Format("imgOpen_{0}", counter);
            if (!Convert.ToBoolean(collapsed, CultureInfo.InvariantCulture))
            {
                imgOpen.ImageUrl = this.ResolveUrl("~/Apps/Core/Images/btn_up.gif");
                imgOpen.Attributes.Add("changeUrl", this.ResolveUrl("~/Apps/Core/Images/btn_down.gif"));
            }
            else
            {
                imgOpen.ImageUrl = this.ResolveUrl("~/Apps/Core/Images/btn_down.gif");
                imgOpen.Attributes.Add("changeUrl", this.ResolveUrl("~/Apps/Core/Images/btn_up.gif"));
            }
            imgOpen.Attributes.Add("class", "IbnHeaderWidgetButton");

            imgOpen.Style.Add("right", "25px");
            imgOpen.OnClientClick = "return false;";
            #endregion

            #region Image Close
            ImageButton imgClose = new ImageButton();
            imgClose.ID       = String.Format("imgClose_{0}", counter);
            imgClose.ImageUrl = this.ResolveUrl("~/Apps/Core/Images/btn_close.gif");
            imgClose.Attributes.Add("class", "IbnHeaderWidgetButton");
            imgClose.Style.Add("right", "5px");
            imgClose.OnClientClick = "return false;";
            #endregion

            #region Image PropertyPage
            ImageButton imgProperty = new ImageButton();
            imgProperty.ID       = String.Format("imgProperty_{0}", counter);
            imgProperty.ImageUrl = this.ResolveUrl("~/Apps/Core/Images/btn_prop.gif");
            imgProperty.Attributes.Add("class", "IbnHeaderWidgetButton");
            imgProperty.Style.Add("right", "45px");
            imgProperty.OnClientClick = "return false;";
            #endregion

            #region Label Title
            Label lblTitle = new Label();
            lblTitle.CssClass = "x-panel-header IbnHeaderWidgetButton";
            lblTitle.Style.Add("left", "2px");
            lblTitle.Style.Add("top", "1px");
            lblTitle.Style.Add("right", "75px");
            lblTitle.Style.Add(HtmlTextWriterStyle.BorderWidth, "0px");
            #endregion

            List <WsButton> buttonList = new List <WsButton>();

            divHeader.Attributes.Add("class", "IbnWidgetHeader");
            divHeader.Attributes.Add("dragObj", "0");

            ctrl.ID = String.Format("wrapControl{0}_{1}", dci.Uid.Replace("-", ""), instanceUid);
            IbnWidgetContainer c = new IbnWidgetContainer(ctrl, Convert.ToBoolean(collapsed, CultureInfo.InvariantCulture));
            c.ID = String.Format("id{0}{1}", dci.Uid.Replace("-", ""), counter);
            //this.Controls.Add(c);
            //c.DataBind();

            divContainer.Controls.Add(divHeader);
            divContainer.Controls.Add(c);
            this.Controls.Add(divContainer);

            c.DataBind();

            sourceInfo += String.Format("{0}^{1}^{2}:", dci.Uid, collapsed, instanceUid);             // _uid + ":";

            System.Web.Script.Serialization.JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaScriptSerializer();
            if (dci != null)
            {
                divHeader.Controls.Add(imgClose);
                divHeader.Controls.Add(imgOpen);
                divHeader.Controls.Add(lblTitle);
                buttonList.Add(new WsButton(imgClose.ClientID, "close"));
                buttonList.Add(new WsButton(imgOpen.ClientID, "expand"));
                lblTitle.Text = CHelper.GetResFileString(dci.Title);

                if (!string.IsNullOrEmpty(dci.PropertyPagePath) || !string.IsNullOrEmpty(dci.PropertyPageType))
                {
                    divHeader.Controls.Add(imgProperty);
                    buttonList.Add(new WsButton(imgProperty.ClientID, "property"));
                    sb.AppendFormat("{{ title: '{2}', tools: layoutExtender_tools2, contentEl: '{0}', id:'{4}_{1}', collapsed:{3}, buttons:{5} }},", c.ClientID, instanceUid, CHelper.GetResFileString(dci.Title), collapsed, dci.Uid, jss.Serialize(buttonList));
                }
                else
                {
                    sb.AppendFormat("{{ title: '{2}', tools: layoutExtender_tools, contentEl: '{0}', id:'{4}_{1}', collapsed:{3}, buttons:{5} }},", c.ClientID, instanceUid, CHelper.GetResFileString(dci.Title), collapsed, dci.Uid, jss.Serialize(buttonList));
                }
            }
            else
            {
                sb.AppendFormat("{{ title: '', tools: layoutExtender_tools, contentEl: '{0}', id:'{3}_{1}', collapsed:{2} }},", c.ClientID, instanceUid, collapsed, dci.Uid.Replace("..\\", string.Empty).Replace("\\", "/"));
            }

            return(sb.ToString());
        }
Example #5
0
        /// <summary>
        /// Gets the ids for control place.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        String GetIdsForControlPlace(string id)
        {
            String retVal  = String.Empty;
            String pageKey = this.PageUid;

            // get this string from the database
            string          userSettings = String.Empty;
            CustomerProfile profile      = ProfileContext.Current.Profile;

            if (profile != null && profile.PageSettings != null)
            {
                userSettings = profile.PageSettings.GetSettingString(pageKey);
            }

            if (String.IsNullOrEmpty(userSettings))
            {
                userSettings = Mediachase.Commerce.Manager.Dashboard.Home._DefaultControls;
            }

            // TODO: add security check here

            // deserialize user settings
            System.Web.Script.Serialization.JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaScriptSerializer();
            List <CpInfo> list = null;

            try
            {
                list = jss.Deserialize <List <CpInfo> >(userSettings);
            }
            catch
            {
                // something's wrong with user settings, reset it
                userSettings = null;
            }

            // get default control info, if it has not been customized and saved yet
            if (String.IsNullOrEmpty(userSettings))
            {
                int counter = 0;
                foreach (DynamicControlInfo dci in DynamicControlFactory.GetControlInfos())
                {
                    if (id == "Column1" && (counter % 2) == 0)
                    {
                        retVal += String.Format("{0}^false^{1}:", dci.Uid, Guid.NewGuid().ToString("N"));                         //dci.Uid + ":";
                    }

                    if (id == "Column2" && (counter % 2) != 0)
                    {
                        retVal += String.Format("{0}^false^{1}:", dci.Uid, Guid.NewGuid().ToString("N"));                          //dci.Uid + ":";
                    }

                    counter++;
                }

                if (retVal.Length > 0)
                {
                    retVal = retVal.TrimEnd(':');
                }

                return(retVal);
            }

            foreach (CpInfo cpInfo in list)
            {
                if (cpInfo.Id == id)
                {
                    for (int i = 0; i < cpInfo.Items.Count; i++)
                    {
                        retVal += String.Format("{0}^{1}^{2}:", cpInfo.Items[i].Id, cpInfo.Items[i].Collapsed, cpInfo.Items[i].InstanceUid);
                    }
                }
            }

            if (retVal.Length > 0)
            {
                retVal = retVal.TrimEnd(':');
            }

            return(retVal);
        }