Ejemplo n.º 1
0
        /// <summary>
        /// Binds the data.
        /// </summary>
        /// <param name="uid">The uid.</param>
        private void BindData(string uid)
        {
            if (uid == null)
            {
                throw new ArgumentNullException("uid");
            }

            WorkspaceTemplateInfo wti = WorkspaceTemplateFactory.GetTemplateInfo(uid);

            if (wti == null)
            {
                throw new ArgumentException(string.Format("Cant find Template with uid: {0}", uid));
            }

            List <ColumnInfo> list = UtilHelper.JsonDeserialize <List <ColumnInfo> >(wti.ColumnInfo);

            foreach (ColumnInfo ci in list)
            {
                IbnControlPlace icp = new IbnControlPlace();
                icp.WidthPercentage = ci.Width;
                icp.ID             = ci.Id;
                icp.ControlPlaceId = ci.Id;
                icp.PageUid        = this.PageUid;
                icp.IsAdmin        = this.IsAdmin;
                this.Controls.Add(icp);
            }
        }
Ejemplo n.º 2
0
        private void BindTemplates()
        {
            List <ListItem> listItems = new List <ListItem>();

            foreach (WorkspaceTemplateInfo wti in WorkspaceTemplateFactory.GetTemplateInfos())
            {
                listItems.Add(new ListItem(CHelper.GetResFileString(wti.Title), wti.Uid.ToLowerInvariant()));
            }

            listItems.Sort(delegate(ListItem x, ListItem y) { return(x.Text.CompareTo(y.Text)); });
            TemplateList.Items.AddRange(listItems.ToArray());
        }
Ejemplo n.º 3
0
        private string GetNewJson(string jsonData, Guid newTemplateId)
        {
            List <CpInfo> list = UtilHelper.JsonDeserialize <List <CpInfo> >(jsonData);

            WorkspaceTemplateInfo wti = WorkspaceTemplateFactory.GetTemplateInfo(newTemplateId.ToString());

            List <ColumnInfo> templateColumn = UtilHelper.JsonDeserialize <List <ColumnInfo> >(wti.ColumnInfo);

            if (templateColumn.Count == 0)
            {
                throw new ArgumentException("Template must contain minumum 1 column");
            }

            if (list.Count == 0)
            {
                throw new ArgumentException("Invalid workspace personalize data");
            }

            int       counter      = 0;
            ArrayList deletedItems = new ArrayList();

            foreach (CpInfo info in list)
            {
                if (!templateColumn.Contains(new ColumnInfo(info.Id)))
                {
                    info.Id = templateColumn[0].Id;

                    if (counter > 0)
                    {
                        foreach (CpInfoItem item in info.Items)
                        {
                            list[0].Items.Add(item);
                        }

                        deletedItems.Add(info);
                    }
                }

                counter++;
            }

            if (deletedItems.Count > 0)
            {
                foreach (CpInfo info in deletedItems)
                {
                    list.Remove(info);
                }
            }

            return(UtilHelper.JsonSerialize(list));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gens the templates data source.
        /// </summary>
        /// <returns></returns>
        private DataTable GenTemplatesDataSource()
        {
            DataTable retVal = new DataTable();

            retVal.Columns.Add(new DataColumn("Id", typeof(string)));
            retVal.Columns.Add(new DataColumn("Title", typeof(string)));
            retVal.Columns.Add(new DataColumn("Description", typeof(string)));
            retVal.Columns.Add(new DataColumn("ImageUrl", typeof(string)));

            foreach (WorkspaceTemplateInfo wti in WorkspaceTemplateFactory.GetTemplateInfos())
            {
                DataRow row = retVal.NewRow();
                row["Id"]          = wti.Uid;
                row["Title"]       = CHelper.GetResFileString(wti.Title);
                row["Description"] = CHelper.GetResFileString(wti.Description);
                row["ImageUrl"]    = CHelper.GetAbsolutePath(wti.ImageUrl);

                retVal.Rows.Add(row);
            }

            return(retVal);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Handles the ItemCommand event of the grdMain control.
        /// </summary>
        /// <param name="source">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.DataGridCommandEventArgs"/> instance containing the event data.</param>
        void grdMain_ItemCommand(object source, DataGridCommandEventArgs e)
        {
            if (e.CommandName == "Add")
            {
                string        Ids      = e.CommandArgument.ToString();
                List <CpInfo> userList = new List <CpInfo>();

                CustomPageEntity page = null;
                if (!this.IsAdmin)
                {
                    page = CustomPageManager.GetCustomPage(PageUid, null, Mediachase.IBN.Business.Security.CurrentUser.UserID);
                }
                else
                {
                    page = CustomPageManager.GetCustomPage(PageUid, ProfileId, UserId);
                }

                string userData    = page.JsonData;
                Guid   templateUid = page.TemplateId;

                List <ColumnInfo> list = new List <ColumnInfo>();
                if (this.IsAdmin)
                {
                    WorkspaceTemplateInfo wti = WorkspaceTemplateFactory.GetTemplateInfo(templateUid.ToString());
                    list = UtilHelper.JsonDeserialize <List <ColumnInfo> >(wti.ColumnInfo);
                }
                userList = UtilHelper.JsonDeserialize <List <CpInfo> >(userData.Replace("\\", ""));

                List <string> currentColumnsId = new List <string>();
                foreach (CpInfo cpItem in userList)
                {
                    currentColumnsId.Add(cpItem.Id);
                }

                List <CpInfo> newUserList = new List <CpInfo>();
                newUserList.AddRange(userList);

                if (this.IsAdmin)
                {
                    foreach (CpInfo cpItem in userList)
                    {
                        foreach (ColumnInfo info in list)
                        {
                            if (currentColumnsId.Contains(info.Id))
                            {
                                continue;
                            }

                            CpInfo cInfo = new CpInfo();
                            cInfo.Id    = info.Id;
                            cInfo.Items = new List <CpInfoItem>();
                            newUserList.Add(cInfo);
                        }
                    }
                }

                foreach (CpInfo cpItem in newUserList)
                {
                    if (cpItem.Id == this.ColumnId)
                    {
                        CpInfoItem newItem = new CpInfoItem();
                        newItem.Collapsed   = "false";
                        newItem.Id          = Ids;
                        newItem.InstanseUid = Guid.NewGuid().ToString("N");
                        cpItem.Items.Add(newItem);
                    }
                }

                string newJsonData = UtilHelper.JsonSerialize(newUserList);

                // Perform save to storage
                if (!IsAdmin)
                {
                    CustomPageManager.UpdateCustomPage(PageUid, newJsonData, templateUid, null, Mediachase.IBN.Business.Security.UserID);
                }
                else
                {
                    CustomPageManager.UpdateCustomPage(PageUid, newJsonData, templateUid, ProfileId, UserId);
                }

                divTemplateUpdate.Style.Add(HtmlTextWriterStyle.Display, "block");
                this.ForcePostback = true;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Templates the change.
        /// </summary>
        /// <param name="page">The page.</param>
        private void TemplateChange(CustomPageEntity page)
        {
            string userSettings = page.JsonData;

            List <CpInfo> list = UtilHelper.JsonDeserialize <List <CpInfo> >(userSettings);

            WorkspaceTemplateInfo wti = WorkspaceTemplateFactory.GetTemplateInfo(this.selectedUid.ToString());

            if (wti == null)
            {
                throw new NullReferenceException(String.Format("Cant find template: {0}", this.selectedUid));
            }

            List <ColumnInfo> templateColumn = UtilHelper.JsonDeserialize <List <ColumnInfo> >(wti.ColumnInfo);

            if (templateColumn.Count == 0)
            {
                throw new ArgumentException("Template must contain minumum 1 column");
            }

            if (list.Count == 0)
            {
                throw new ArgumentException("Invalid workspace personalize data");
            }

            int       counter      = 0;
            ArrayList deletedItems = new ArrayList();

            foreach (CpInfo info in list)
            {
                if (!templateColumn.Contains(new ColumnInfo(info.Id)))
                {
                    info.Id = templateColumn[0].Id;

                    if (counter > 0)
                    {
                        foreach (CpInfoItem item in info.Items)
                        {
                            list[0].Items.Add(item);
                        }

                        deletedItems.Add(info);
                    }
                }

                counter++;
            }

            if (deletedItems.Count > 0)
            {
                foreach (CpInfo info in deletedItems)
                {
                    list.Remove(info);
                }
            }

            string jsonData = UtilHelper.JsonSerialize(list);

            if (!this.IsAdmin)
            {
                CustomPageManager.UpdateCustomPage(PageUid, jsonData, this.selectedUid, null, Mediachase.IBN.Business.Security.UserID);
            }
            else
            {
                CustomPageManager.UpdateCustomPage(PageUid, jsonData, this.selectedUid, ProfileId, UserId);
            }
        }
Ejemplo n.º 7
0
        protected void SaveButton_ServerClick(object sender, EventArgs e)
        {
            string className      = string.Empty;
            string objectIdString = string.Empty;
            int    objectId       = 0;

            if (int.TryParse(Request["ObjectId"], out objectId))                // for portal level we can get "{QueryString:ObjectId}"
            {
                objectIdString = objectId.ToString();
                className      = Request["ClassName"];
            }

            PrimaryKeyId pageId = PrimaryKeyId.Empty;

            if (CustomPageId == PrimaryKeyId.Empty)             // new
            {
                Guid pageUid = Guid.NewGuid();

                CustomPageEntity page = BusinessManager.InitializeEntity <CustomPageEntity>(CustomPageEntity.ClassName);
                page.Title       = ctrlTitleText.Text;           //TitleText.Text;
                page.Description = DescriptionText.Text;
                page.TemplateId  = new Guid(TemplateList.SelectedValue);
                page.ProfileId   = ProfileId;
                page.UserId      = UserId;
                page.Uid         = pageUid;

                // Json
                List <CpInfo>         list           = new List <CpInfo>();
                WorkspaceTemplateInfo wti            = WorkspaceTemplateFactory.GetTemplateInfo(TemplateList.SelectedValue);
                List <ColumnInfo>     columnInfoList = UtilHelper.JsonDeserialize <List <ColumnInfo> >(wti.ColumnInfo);
                foreach (ColumnInfo columnInfo in columnInfoList)
                {
                    CpInfo cpInfo = new CpInfo();
                    cpInfo.Id    = columnInfo.Id;
                    cpInfo.Items = new List <CpInfoItem>();
                    list.Add(cpInfo);
                }
                page.JsonData = UtilHelper.JsonSerialize(list);
                //

                pageId = BusinessManager.Create(page);

                Response.Redirect(
                    String.Format(CultureInfo.InvariantCulture,
                                  "~/Apps/WidgetEngine/Pages/CustomPageDesign.aspx?id={0}&ClassName={1}&ObjectId={2}&PageUid={3}",
                                  pageId,
                                  className,
                                  objectIdString,
                                  pageUid)
                    );
            }
            else             // edit
            {
                CustomPageEntity page          = (CustomPageEntity)BusinessManager.Load(CustomPageEntity.ClassName, CustomPageId);
                Guid             pageUid       = page.Uid;
                Guid             newTemplateId = new Guid(TemplateList.SelectedValue);

                // if we edit the page from the current layer
                if ((page.UserId.HasValue && UserId.HasValue && (int)page.UserId.Value == UserId.Value)
                    ||
                    (page.ProfileId.HasValue && ProfileId.HasValue && (int)page.ProfileId.Value == ProfileId.Value)
                    ||
                    (!page.UserId.HasValue && !page.ProfileId.HasValue && !UserId.HasValue && !ProfileId.HasValue && !page.Properties.Contains(LocalDiskEntityObjectPlugin.IsLoadDiskEntityPropertyName)))
                {
                    page.Title       = ctrlTitleText.Text;              // TitleText.Text;
                    page.Description = DescriptionText.Text;

                    if (page.TemplateId != newTemplateId)
                    {
                        page.TemplateId = newTemplateId;
                        page.JsonData   = GetNewJson(page.JsonData, newTemplateId);
                    }

                    BusinessManager.Update(page);
                }
                else                 // if we edit the page from the above layer
                {
                    CustomPageEntity newPage = BusinessManager.InitializeEntity <CustomPageEntity>(CustomPageEntity.ClassName);
                    newPage.Title       = ctrlTitleText.Text;              // TitleText.Text;
                    newPage.Description = DescriptionText.Text;
                    newPage.ProfileId   = ProfileId;
                    newPage.UserId      = UserId;
                    newPage.Uid         = pageUid;
                    newPage.TemplateId  = newTemplateId;
                    if (page.TemplateId != newTemplateId)
                    {
                        page.JsonData = GetNewJson(page.JsonData, newTemplateId);
                    }
                    else
                    {
                        newPage.JsonData = page.JsonData;
                    }

                    BusinessManager.Create(newPage);
                }

                Response.Redirect(GetLinkToList());
            }
        }