private void SetFieldControlValue(object value)
        {
            ArrayList       list       = new ArrayList();
            HTML5ImageField imageField = null;

            if (imagePicker != null)
            {
                if (this.ControlMode == SPControlMode.New && imagePicker.Entities.Count == 0)
                {
                    imageField = new HTML5ImageField();

                    HTML5ImagePickerEntity defaultEntity = this.imagePicker.ValidateEntity(new HTML5ImagePickerEntity()
                    {
                        Key = imageField.Src, DisplayText = imageField.Alt
                    });
                    if (defaultEntity != null)
                    {
                        list.Add(defaultEntity);
                    }
                    imagePicker.Entities.Clear();
                    imagePicker.UpdateEntities(list);
                }

                if (value != null)
                {
                    ArrayList              entities = new ArrayList();
                    HTML5ImageField        field    = (HTML5ImageField)value;
                    HTML5ImagePickerEntity entity   = new HTML5ImagePickerEntity(field);
                    entities.Add(entity);
                    imagePicker.UpdateEntities(entities);
                }
            }
        }
        public HTML5ImagePickerEntity GetEntity(HTML5ImageDataSet.HTML5ImagesRow dr)
        {
            // No datarow provided
            if (dr == null)
            {
                return(null);
            }

            // Create new picker
            HTML5ImagePickerEntity entity = new HTML5ImagePickerEntity();

            entity.Key         = dr.Src;
            entity.DisplayText = dr.Src;
            entity.Alt         = dr.Alt;
            entity.Src         = dr.Src;
            entity.Height      = dr.Height;
            entity.Width       = dr.Width;
            entity.Description = dr.Alt;
            entity.Web         = dr.Web;
            entity.List        = dr.List;
            entity.Preview     = dr.Preview;
            entity.IsResolved  = true;
            entity.ItemId      = dr.ImageId;

            return(entity);
        }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public override PickerEntity ValidateEntity(PickerEntity entity)
        {
            if (entity != null)
            {
                HTML5ImagePickerEntity imageEntity = new HTML5ImagePickerEntity(entity);
                entity = ValidateEntity(imageEntity) as PickerEntity;

                if (!entity.IsResolved)
                {
                    PickerEntity[] resolved = ResolveErrorBySearch(entity.DisplayText);
                    if (resolved != null && resolved.Count() == 1)
                    {
                        return(resolved[0] as PickerEntity);
                    }
                    else
                    {
                        entity.MultipleMatches.Add(resolved);
                    }
                    return(entity as PickerEntity);
                }
                else
                {
                    return(entity);
                }
            }
            else
            {
                return(entity);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Validate picker entity
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public HTML5ImagePickerEntity ValidateEntity(HTML5ImagePickerEntity entity)
        {
            //entity.IsResolved = true;
            return(entity);
            //entity.EntityData = imageEntity.EntityData;

            //return base.ValidateEntity(imageEntity);
        }
        protected override void CreateChildControls()
        {
            this.DisableInputFieldLabel = true;
            base.ControlMode            = SPContext.Current.FormContext.FormMode;
            base.CreateChildControls();

            imageField = (HTML5ImageField)ItemFieldValue;

            if (imageField == null)
            {
                imageField = new HTML5ImageField();
            }

            html_image_hidden = (HiddenField)this.TemplateContainer.FindControl("html_image_hidden");
            imagePicker       = (HTML5ImagePicker)this.TemplateContainer.FindControl("ImagePicker");
            image             = (Hemrika.SharePresence.Html5.WebControls.Image) this.TemplateContainer.FindControl("html_image");


            SPListItem item = null;
            SPFile     file = null;

            //SPWeb web = null;

            if (!ChildControlsCreated)
            {
                if (image != null)
                {
                    imageField = (HTML5ImageField)Value;
                    if (imageField != null)
                    {
                        if (imageField.WebId != Guid.Empty && imageField.ItemId != Guid.Empty)
                        {
                            using (SPWeb web = SPContext.Current.Site.OpenWeb(imageField.WebId))
                            {
                                if (web.Exists)
                                {
                                    file = web.GetFile(imageField.ItemId);
                                    if (file.Exists)
                                    {
                                        item      = file.Item;
                                        image.Src = "~/" + file.Url;
                                        image.Alt = Convert.ToString(item["ows_Description"]);

                                        if (string.IsNullOrEmpty(imageField.Title))
                                        {
                                            image.Title = imageField.Title;
                                        }

                                        if (string.IsNullOrEmpty(imageField.Style))
                                        {
                                            image.Style = imageField.Style;
                                        }
                                    }
                                    else
                                    {
                                        image.Visible = false;
                                    }
                                }
                                else
                                {
                                    image.Visible = false;
                                }
                            }
                        }
                        else
                        {
                            bool UseRoot = false;
                            using (SPWeb web = SPContext.Current.Site.OpenWeb(imageField.Src))
                            {
                                if (web.Exists)
                                {
                                    file = web.GetFile(imageField.Src);

                                    if (file.Exists)
                                    {
                                        item      = file.Item;
                                        image.Src = "~/" + file.Url;
                                        image.Alt = Convert.ToString(item["ows_Description"]);

                                        if (string.IsNullOrEmpty(imageField.Title))
                                        {
                                            image.Title = imageField.Title;
                                        }

                                        if (string.IsNullOrEmpty(imageField.Style))
                                        {
                                            image.Style = imageField.Style;
                                        }
                                    }
                                    else
                                    {
                                        image.Visible = false;
                                    }
                                }
                                else
                                {
                                    UseRoot = true;
                                }
                            }

                            if (UseRoot)
                            {
                                SPWeb web = SPContext.Current.Site.RootWeb;

                                if (web.Exists)
                                {
                                    file = web.GetFile(imageField.Src);

                                    if (file.Exists)
                                    {
                                        item      = file.Item;
                                        image.Src = "~/" + file.Url;
                                        image.Alt = Convert.ToString(item["ows_Description"]);

                                        if (string.IsNullOrEmpty(imageField.Title))
                                        {
                                            image.Title = imageField.Title;
                                        }

                                        if (string.IsNullOrEmpty(imageField.Style))
                                        {
                                            image.Style = imageField.Style;
                                        }
                                    }
                                    else
                                    {
                                        image.Visible = false;
                                    }
                                }
                            }
                        }
                    }
                }

                if (base.ControlMode == SPControlMode.Edit || base.ControlMode == SPControlMode.New)
                {
                    if (!Page.IsCallback)
                    {
                        HTML5ImagePropertyBag properties = new HTML5ImagePropertyBag();

                        if (item != null)
                        {
                            properties.ItemId = item.UniqueId;
                            properties.WebId  = item.Web.ID;
                            properties.ListId = item.ParentList.ID;
                        }
                        else
                        {
                            properties.WebId  = SPContext.Current.Web.ID;
                            properties.ListId = SPContext.Current.ListId;
                            properties.ItemId = SPContext.Current.ListItem.UniqueId;
                        }

                        if (imagePicker != null)
                        {
                            upload = (HyperLink)imagePicker.FindControl("upload");

                            if (upload != null)
                            {
                                upload.NavigateUrl = String.Format(upload.NavigateUrl, image.ClientID, imagePicker.ClientID, base.Web.ID);
                            }

                            //imagePicker.OnValueChangedClientScript = "UpdateImageAfterDialog('" + image.ClientID + "','" + imagePicker.ClientID + "');";
                            //imagePicker.AfterCallbackClientScript = "UpdateImageAfterDialog('" + image.ClientID + "','" + imagePicker.ClientID + "');";
                            imagePicker.OnValueChangedClientScript = "UpdateImageAfterDialog('" + html_image_hidden.ClientID + "','" + imagePicker.ClientID + "');";
                            imagePicker.AfterCallbackClientScript  = "UpdateImageAfterDialog('" + html_image_hidden.ClientID + "','" + imagePicker.ClientID + "');";

                            HTML5ImagePickerEntity entity = new HTML5ImagePickerEntity(item);

                            imagePicker.CustomProperty = properties.ToString();
                            imagePicker.Entities.Add(entity);
                            imagePicker.UpdateEntities(imagePicker.Entities);
                        }
                    }
                }
                ChildControlsCreated = true;
            }
        }
        public override void UpdateFieldValueInItem()
        {
            EnsureChildControls();
            string style = string.Empty;
            string title = string.Empty;

            if (html_image_hidden != null)
            {
                string value = html_image_hidden.Value;

                Regex  rimage = new Regex(@"<img\s[^>]*\s[^>]*>", RegexOptions.Compiled);
                string simage = rimage.Match(value).Value;
                if (!string.IsNullOrEmpty(simage))
                {
                    Regex  rstyle = new Regex("style=\"([^\"]*)\"", RegexOptions.Compiled);
                    Regex  rtitle = new Regex("title=\"([^\"]*)\"", RegexOptions.Compiled);
                    string sstyle = rstyle.Match(simage).Value;
                    title = rtitle.Match(value).Value;

                    if (!string.IsNullOrEmpty(sstyle))
                    {
                        StringBuilder builder  = new StringBuilder();
                        Regex         rheight  = new Regex("height:([^;]*);", RegexOptions.Compiled);
                        Regex         rwidth   = new Regex("width:([^;]*);", RegexOptions.Compiled);
                        Regex         rpadding = new Regex("padding:([^;]*);", RegexOptions.Compiled);
                        Regex         rfloat   = new Regex("float:([^;]*);", RegexOptions.Compiled);
                        builder.Append(rheight.Match(sstyle).Value);
                        builder.Append(rwidth.Match(sstyle).Value);
                        builder.Append(rpadding.Match(sstyle).Value);
                        builder.Append(rfloat.Match(sstyle).Value);
                        if (builder.Length > 0)
                        {
                            style = builder.ToString();
                        }
                    }
                }
            }

            if (imagePicker.Enabled)
            {
                imagePicker.Validate();
                if (imagePicker.Entities.Count > 0)
                {
                    PickerEntity entity = null;
                    if (imagePicker.ResolvedEntities.Count == 1)
                    {
                        entity = (PickerEntity)imagePicker.ResolvedEntities[0];
                    }
                    else
                    {
                        entity = (PickerEntity)imagePicker.Entities[0];
                    }

                    HTML5ImagePickerEntity imageEntity = new HTML5ImagePickerEntity(entity);

                    HTML5ImageField itemFieldValue = (HTML5ImageField)this.ItemFieldValue;

                    if (imageEntity.IsResolved)
                    {
                        if (itemFieldValue == null)
                        {
                            itemFieldValue = new HTML5ImageField();
                        }
                        itemFieldValue.Alt    = imageEntity.Alt;
                        itemFieldValue.Src    = imageEntity.Src;
                        itemFieldValue.ItemId = imageEntity.ItemId;
                        itemFieldValue.WebId  = imageEntity.WebId;

                        if (!string.IsNullOrEmpty(title))
                        {
                            itemFieldValue.Title = title;
                        }

                        if (string.IsNullOrEmpty(style))
                        {
                            itemFieldValue.Style = style;
                        }

                        this.ItemFieldValue = itemFieldValue;

                        using (SPWeb web = SPContext.Current.Site.OpenWeb(itemFieldValue.WebId))
                        {
                            SPFile     file = web.GetFile(itemFieldValue.ItemId);
                            SPListItem item = file.Item;

                            image.Src = "~/" + file.Url;
                            image.Alt = Convert.ToString(item["ows_Description"]);

                            if (!string.IsNullOrEmpty(title))
                            {
                                image.Title = title;
                            }

                            if (!string.IsNullOrEmpty(style))
                            {
                                image.Style = style;
                            }
                        }
                    }
                }
            }
        }
        private void CreateTable()
        {
            resultTable = new Table
            {
                Width       = Unit.Percentage(100.0),
                ID          = "resultTable",
                CssClass    = "ms-pickerresulttable",
                CellSpacing = 0,
                CellPadding = 0,
                BackColor   = Color.White
            };
            resultTable.ID = "resultTable";
            resultTable.Attributes.Add("hideFocus", "true");
            resultTable.Attributes.Add("EditorControlClientId", PickerDialog.EditorControl.ClientID);

            //Create Table Header Row
            TableRow child = null;

            if (PickerDialog.Results != null)
            {
                dt = PickerDialog.Results;


                child = new TableRow
                {
                    CssClass = "ms-pickerresultheadertr"
                };

                foreach (string column in columns)
                {
                    TableHeaderCell cell = new TableHeaderCell
                    {
                        CssClass = "ms-ph"
                    };
                    cell.Attributes.Add("UNSELECTABLE", "on");
                    Literal literal = new Literal
                    {
                        Text = SPHttpUtility.HtmlEncode(column)
                    };

                    cell.Controls.Add(literal);
                    child.Controls.Add(cell);
                }

                resultTable.Controls.Add(child);


                if (dt.Rows.Count == 0)
                {
                    child = new TableRow
                    {
                        CssClass = "ms-pickeremptyresulttexttr"
                    };

                    TableCell cell2 = new TableCell
                    {
                        CssClass   = "ms-descriptiontext",
                        ColumnSpan = columns.Length
                    };
                    Literal literal2 = new Literal
                    {
                        Text = SPHttpUtility.HtmlEncode("No search was given")
                    };
                    cell2.Controls.Add(literal2);
                    child.Controls.Add(cell2);
                    resultTable.Controls.Add(child);
                }
                else
                {
                    int    num          = 0;
                    string selectSingle = "PickerResultsSingleSelectOnClick(this);";
                    string selectDouble = "PickerResultsSingleSelectOnDblClick(this);";

                    foreach (HTML5ImageDataSet.HTML5ImagesRow row in dt.Rows)
                    {
                        HTML5ImagePickerEntity entity = PickerDialog.QueryControl.GetEntity(row);

                        if (entity != null)
                        {
                            child = new TableRow
                            {
                                ID = string.Format(CultureInfo.InvariantCulture, "row{0}", new object[] { num })
                            };

                            child.Attributes.Add("tabindex", "-1");
                            child.Attributes.Add("resultRow", "resultRow");

                            if ((num % 2) == 0)
                            {
                                child.CssClass = "ms-alternating";
                            }

                            ArrayList entities = new ArrayList();

                            entities.Add(entity);

                            string callback = PickerDialog.EditorControl.GenerateCallbackData(entities, false);
                            child.Attributes.Add("entityXml", callback);
                            child.Attributes.Add("onmousedown", "return singleselectevent(event);");
                            child.Attributes.Add("onclick", selectSingle);
                            child.Attributes.Add("ondblclick", selectDouble);
                            child.Attributes.Add("onkeydown", "PickerResultsNameOnKeyDown(this, event,false);");
                            child.Attributes.Add("onfocus", "PickerResultsNameOnFocus(this, event, false);");

                            child.Attributes.Add("key", entity.Key);

                            for (int i = 0; i < columns.Length; i++)
                            {
                                this.RenderRowColumn(row, i, child);
                            }
                            resultTable.Controls.Add(child);
                            num++;
                        }
                    }

                    if (base.PickerDialog.Results.Rows.Count > 1)
                    {
                        child = new TableRow
                        {
                            CssClass = "ms-pickersearchsummarytr",
                            ID       = "PickerSearchResultSummaryRow"
                        };
                        TableCell cell3 = new TableCell
                        {
                            CssClass   = "ms-descriptiontext",
                            ColumnSpan = dt.Columns.Count
                        };
                        cell3.Controls.Add(new LiteralControl(SPHttpUtility.HtmlEncode(String.Format("{0} results found.", new object[] { base.PickerDialog.Results.Rows.Count }))));
                        child.Controls.Add(cell3);
                        resultTable.Controls.Add(child);
                    }

                    this.Page.ClientScript.RegisterClientScriptBlock(GetType(), "__SELECTION__HELPER__", "<script type=\"text/javascript\">\r\n                // <![CDATA[\r\n                function " + SPHttpUtility.EcmaScriptStringLiteralEncode(PickerDialog.GetSelectedClientSideFunctionName) + "()\r\n                {\r\n                    var selKeys=new Array(selected.length);\r\n                    for(i=0;i<selected.length;i++)\r\n                    {\r\n                        var uniquekey=selected[i].getAttribute('key').toString();\r\n                        selKeys[i]=uniquekey;\r\n                    }\r\n                    return selKeys;\r\n                }\r\n                // ]]>\r\n                </script>");
                }
            }
        }