Exemplo n.º 1
0
        public override string GetFieldValueAsText(object value)
        {
            HTML5RatingField field = (HTML5RatingField)value;

            if (field != null)
            {
                return(field.ToString());
            }
            return(string.Empty);
        }
Exemplo n.º 2
0
        protected override void CreateChildControls()
        {
            this.DisableInputFieldLabel = true;
            base.ControlMode            = SPContext.Current.FormContext.FormMode;

            if (base.ControlMode == SPControlMode.Display || base.ControlMode == SPControlMode.Invalid)
            {
                ScriptManager.GetCurrent(Page).RegisterAsyncPostBackControl(this);
                //Page.RegisterRequiresPostBack(this);
                //Page.RegisterRequiresRaiseEvent(this);
            }

            base.CreateChildControls();
            RatingField = (HTML5RatingField)ItemFieldValue;

            if (RatingField == null)
            {
                try
                {
                    url = SPContext.Current.Web.Url;
                    Guid listId = this.ListId;
                    Guid itemId = this.ListItem.UniqueId;

                    using (SPSite site = new SPSite(url))
                    {
                        using (SPWeb web = site.OpenWeb())
                        {
                            SPListItem item = web.Lists[listId].Items[itemId];
                            //SPFile file = web.GetFile(itemId);
                            //SPListItem item = file.ListItemAllFields;

                            RatingField    = item[BuildFieldId.Rating] as HTML5RatingField;
                            ItemFieldValue = RatingField;
                        }
                    }
                }
                catch (Exception)
                {
                    RatingField = new HTML5RatingField();
                }
                if (RatingField == null)
                {
                    RatingField = new HTML5RatingField();
                }
            }

            if (settings == null)
            {
                settings = new RatingSettings();
                settings = settings.Load();
            }

            if (base.ControlMode == SPControlMode.Edit || base.ControlMode == SPControlMode.New)
            {
                RatingField.Maximum = settings.Maximum;
                RatingField.Minimum = settings.Minimum;
                RatingField.Step    = settings.Step;
            }
            else
            {
                input_rating = (RatingInput)this.TemplateContainer.FindControl("RatingInput");

                if (input_rating != null)
                {
                    if (!Page.ClientScript.IsClientScriptIncludeRegistered("jQuery"))
                    {
                        Page.ClientScript.RegisterClientScriptInclude(typeof(HTML5RatingControl), "jQuery", "/_layouts/Hemrika/Content/js/jquery.min.js");
                    }

                    if (!Page.ClientScript.IsClientScriptIncludeRegistered("RateIt"))
                    {
                        Page.ClientScript.RegisterClientScriptInclude(typeof(HTML5RatingControl), "RateIt", "/_layouts/Hemrika/Content/js/jquery.rateit.js");
                    }

                    CssRegistration.Register("/_layouts/Hemrika/Content/css/rateit.css");

                    input_rating.TextChanged += new EventHandler(input_rating_TextChanged);
                    input_rating.Step         = RatingField.Step;
                    input_rating.Maximum      = settings.Maximum;
                    input_rating.Minimum      = settings.Minimum;
                    input_rating.Votes        = RatingField.Votes;

                    if (RatingField.Votes > 0)
                    {
                        input_rating.Value = float.Parse((RatingField.Rating / RatingField.Votes).ToString());
                        input_rating.Text  = float.Parse((RatingField.Rating / RatingField.Votes).ToString()).ToString("F2", CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        input_rating.Value = 0.0f;
                        input_rating.Text  = "0.0";
                    }

                    //input_rating.Value = 0.0f;
                    //input_rating.Text = "0.0f";

                    HtmlGenericControl rating = new HtmlGenericControl("div");
                    rating.Attributes.Add("class", "rateit");
                    rating.Attributes.Add("data-rateit-backingfld", "#" + input_rating.ClientID);
                    rating.Attributes.Add("data-rateit-resetable", "false");

                    if (Page.IsPostBack || HasVote())
                    {
                        rating.Attributes.Add("data-rateit-readonly", "true");
                    }

                    this.Controls.Add(rating);
                    //ScriptManager.GetCurrent(Page).RegisterAsyncPostBackControl(rating);
                }

                MicroDate();
            }
        }