Ejemplo n.º 1
0
        public static void RequestMatch(jQueryEvent e)
        {
            jQueryObject   button     = jQuery.FromElement(e.CurrentTarget);
            jQueryUIObject dialog     = (jQueryUIObject)jQuery.Select("#challengeDialog");
            jQueryUIObject datePicker = (jQueryUIObject)dialog.Find(".datepicker");

            Utility.WireLocationAutoComplete((jQueryUIObject)dialog.Find(".placesAutoFill"), (jQueryUIObject)dialog.Find(".placesAutoValue"));

            string id = button.GetElement(0).ID;

            datePicker.DatePicker("disable");

            dialog.Dialog(
                new JsonObject(
                    "width", "260",
                    "height", "324",
                    "modal", true,
                    "title", button.GetAttribute("Title"),
                    "buttons", new JsonObject(
                        "Challenge!", (jQueryEventHandler) delegate(jQueryEvent ex)
            {
                CreateMatch(id);
            }
                        ),
                    "open", (Callback) delegate()
            {
                dialog.Find(".comments").Focus();
                datePicker.DatePicker("enable");
            },
                    "position", "top"
                    )
                );
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Shows the dialog to select users from the player grid
        /// </summary>
        /// <param name="e"></param>
        private void SelectUserDialog(jQueryEvent e)
        {
            jQueryObject button = jQuery.FromElement(e.CurrentTarget);

            // Get the offer id from the button's attribute
            string offerId = button.GetAttribute("data-offerId");

            // Find the user selection dialog and communicate the offer id to the dialog so it can be posted on the dialog's select user event
            jQueryUIObject dialog = (jQueryUIObject)jQuery.Select("#playerGridCard");

            dialog.Children().First().Html("Loading...");
            dialog.Attribute("data-offerId", offerId);

            // Post the request to get the users who have accepted this offer
            JsonObject parameters = new JsonObject("page", 0, "offerId", offerId);

            jQuery.Post("/services/AcceptPlayerGrid?signed_request=" + Utility.GetSignedRequest(), Json.Stringify(parameters), (AjaxRequestCallback <object>) delegate(object data, string textStatus, jQueryXmlHttpRequest <object> request)
            {
                Utility.ProcessResponse((Dictionary)data);
            }
                        );

            // Display the dialog in modal fashion
            dialog.Dialog(
                new JsonObject(
                    "width", jQuery.Window.GetWidth() - 120,
                    "height", jQuery.Window.GetHeight() - 40,
                    "modal", true,
                    "title", "Select Your Opponent",
                    "closeOnEscape", true,
                    "position", "top"
                    )
                );
        }
Ejemplo n.º 3
0
        public static jQueryObject FindElementWithRelativeId(jQueryObject element, string relativeId)
        {
            var elementId = element.GetAttribute("id");

            if (elementId.IsEmptyOrNull())
                return J("#" + relativeId);

            var result = J(elementId + relativeId);
            if (result.Length > 0)
                return result;

            result = J(elementId + "_" + relativeId);
            if (result.Length > 0)
                return result;

            while (true)
            {
                var idx = elementId.LastIndexOf('_');
                if (idx <= 0)
                    return J("#" + relativeId);

                elementId = elementId.Substring(0, idx);

                result = J("#" + elementId + "_" + relativeId);
                if (result.Length > 0)
                    return result;
            }
        }
Ejemplo n.º 4
0
        public static string GetFetchXmlParentFilter(FetchQuerySettings query, string parentAttribute)
        {
            jQueryObject fetchElement = query.FetchXml.Find("fetch");

            fetchElement.Attribute("count", "{0}");
            fetchElement.Attribute("paging-cookie", "{1}");
            fetchElement.Attribute("page", "{2}");
            fetchElement.Attribute("returntotalrecordcount", "true");
            fetchElement.Attribute("distinct", "true");
            fetchElement.Attribute("no-lock", "true");
            jQueryObject orderByElement = fetchElement.Find("order");

            // Get the default order by field - currently only supports a single sort by column
            query.OrderByAttribute = orderByElement.GetAttribute("attribute");
            query.OrderByDesending = orderByElement.GetAttribute("descending") == "true";

            orderByElement.Remove();

            // Get the root filter (if there is one)
            jQueryObject filter = fetchElement.Find("entity>filter");

            if (filter != null)
            {
                // Check that it is an 'and' filter
                string filterType = filter.GetAttribute("type");
                if (filterType == "or")
                {
                    // wrap up in an and filter
                    jQueryObject andFilter = jQuery.FromHtml("<filter type='and'>" + filter.GetHtml() + "</filter>");

                    // remove existing filter
                    filter.Remove();

                    filter = andFilter;
                    // Add in the existing filter
                    fetchElement.Find("entity").Append(andFilter);
                }
            }

            // Add in the parent query filter
            jQueryObject parentFilter = jQuery.FromHtml("<condition attribute='" + parentAttribute + "' operator='eq' value='" + ParentRecordPlaceholder + "'/>");

            filter.Append(parentFilter);

            // Add the order by placeholder for the EntityDataViewModel
            return(query.FetchXml.GetHtml().Replace("</entity>", "{3}</entity>"));
        }
Ejemplo n.º 5
0
        private void ParseFetchXml(FetchQuerySettings querySettings)
        {
            jQueryObject fetchElement = querySettings.FetchXml;

            // Get the entities and link entities - only support 1 level deep
            jQueryObject entityElement = fetchElement.Find("entity");
            string       logicalName   = entityElement.GetAttribute("name");

            EntityQuery rootEntity;

            // Get query from cache or create new
            if (!EntityLookup.ContainsKey(logicalName))
            {
                rootEntity             = new EntityQuery();
                rootEntity.LogicalName = logicalName;
                rootEntity.Attributes  = new Dictionary <string, AttributeQuery>();
                EntityLookup[rootEntity.LogicalName] = rootEntity;
            }
            else
            {
                rootEntity = EntityLookup[logicalName];
            }

            // Get Linked Entities(1 deep)
            jQueryObject linkEntities = entityElement.Find("link-entity");

            linkEntities.Each(delegate(int index, Element element)
            {
                EntityQuery link = new EntityQuery();
                link.Attributes  = new Dictionary <string, AttributeQuery>();
                link.AliasName   = element.GetAttribute("alias").ToString();
                link.LogicalName = element.GetAttribute("name").ToString();

                if (!EntityLookup.ContainsKey(link.LogicalName))
                {
                    EntityLookup[link.LogicalName] = link;
                }
                else
                {
                    string alias   = link.AliasName;
                    link           = EntityLookup[link.LogicalName];
                    link.AliasName = alias;
                }

                if (!AliasEntityLookup.ContainsKey(link.AliasName))
                {
                    AliasEntityLookup[link.AliasName] = link;
                }
            });

            querySettings.RootEntity = rootEntity;
        }
Ejemplo n.º 6
0
        private void CancelOffer(jQueryEvent e)
        {
            this.Obj.Attribute("disabled", "disabled").AddClass("ui-state-disabled");
            jQueryObject button = jQuery.FromElement(e.CurrentTarget);

            JsonObject parameters = new JsonObject("offerId", button.GetAttribute("data-offerId"));

            jQuery.Post("/services/CancelOffer?signed_request=" + Utility.GetSignedRequest(), Json.Stringify(parameters), (AjaxRequestCallback <object>) delegate(object data, string textStatus, jQueryXmlHttpRequest <object> request)
            {
                Utility.ProcessResponse((Dictionary)data);
            }
                        );
        }
        /// <summary>Scrolls to the specified element.</summary>
        /// <param name="container">The element to scroll to.</param>
        /// <param name="duration">The duration of the scroll animation (in seconds).</param>
        /// <param name="easing">The easing effect to apply.</param>
        /// <param name="onComplete">Action to invoke on complete.</param>
        public void ToBottom(jQueryObject container, double duration, EffectEasing easing, Action onComplete)
        {
            // Prepare the animation properties.
            Dictionary props = new Dictionary();
            props[Html.ScrollTop] = container.GetAttribute(Html.ScrollHeight);

            // Animate.
            container.Animate(
                                props, 
                                Helper.Time.ToMsecs(duration), 
                                easing, 
                                delegate
                                    {
                                        Helper.Invoke(onComplete);
                                    });
        }
        public HtmlContentEditor(jQueryObject textArea, HtmlContentEditorOptions opt)
            : base(textArea, opt)
        {
            IncludeCKEditor();

            string id = textArea.GetAttribute("id");

            if (id.IsTrimmedEmpty())
            {
                textArea.Attribute("id", this.uniqueName);
                id = this.uniqueName;
            }

            if (options.Cols != null)
            {
                textArea.Attribute("cols", options.Cols.Value.ToString());
            }

            if (options.Rows != null)
            {
                textArea.Attribute("rows", options.Rows.Value.ToString());
            }

            var self = this;

            this.AddValidationRule(this.uniqueName, e =>
            {
                if (e.HasClass("required"))
                {
                    var value = self.Value.TrimToNull();
                    if (value == null)
                    {
                        return(Q.Text("Validation.Required"));
                    }
                }

                return(null);
            });

            LazyLoadHelper.ExecuteOnceWhenShown(this.element, () =>
            {
                var config = GetConfig();
                CKEditor.Replace(id, config);
            });
        }
Ejemplo n.º 9
0
        public static jQueryObject FindElementWithRelativeId(jQueryObject element, string relativeId)
        {
            var elementId = element.GetAttribute("id");

            if (elementId.IsEmptyOrNull())
            {
                return(J("#" + relativeId));
            }

            var result = J(elementId + relativeId);

            if (result.Length > 0)
            {
                return(result);
            }

            result = J(elementId + "_" + relativeId);
            if (result.Length > 0)
            {
                return(result);
            }

            while (true)
            {
                var idx = elementId.LastIndexOf('_');
                if (idx <= 0)
                {
                    return(J("#" + relativeId));
                }

                elementId = elementId.Substring(0, idx);

                result = J("#" + elementId + "_" + relativeId);
                if (result.Length > 0)
                {
                    return(result);
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Static method that gets called when a user is selected from the grid (the wiring is hard-coded in PlayerGrid itself for now)
        /// </summary>
        /// <param name="e"></param>
        public static void SelectUser(jQueryEvent e)
        {
            // Get the button that was selected - id should be the FacebookId of the selected user
            jQueryObject button         = jQuery.FromElement(e.CurrentTarget);
            string       selectedUserId = button.GetAttribute("data-fbId");

            // Get the offer id from the dialg attribute
            jQueryUIObject dialog  = (jQueryUIObject)jQuery.Select("#playerGridCard");
            string         offerId = dialog.GetAttribute("data-offerId");

            // Script.Alert("offerId: " + offerId + " uid: " + selectedUserId);

            // Post the confirmation - now that we have the offer id and the selected user
            JsonObject parameters = new JsonObject("offerId", offerId, "uid", selectedUserId);

            dialog.Attribute("disabled", "disabled").AddClass("ui-state-disabled");
            jQuery.Post("/services/ConfirmOfferFromPage?signed_request=" + Utility.GetSignedRequest(), Json.Stringify(parameters), (AjaxRequestCallback <object>) delegate(object data, string textStatus, jQueryXmlHttpRequest <object> request)
            {
                dialog.Dialog("close");
                Utility.ProcessResponse((Dictionary)data);
            }
                        );
        }
Ejemplo n.º 11
0
        // image preview function, demonstrating the ui.dialog used as a modal window
        static void ViewLargerImage(jQueryObject link)
        {
            string       src   = link.GetAttribute("href");
            string       title = link.Siblings("img").GetAttribute("alt");
            jQueryObject modal = jQuery.Select("img[src$='" + src + "']");

            if (modal.Length > 0)
            {
                modal.Plugin <DialogObject>()
                .Dialog(DialogMethod.Open);
            }
            else
            {
                jQueryObject img
                    = jQuery.FromHtml("<img alt='" + title + "' width='384' height='288' style='display: none; padding: 8px;' />")
                      .Attribute("src", src).AppendTo("body");

                img.Plugin <DialogObject>()
                .Dialog(new DialogOptions(DialogOption.Title, title,
                                          DialogOption.Width, 400,
                                          DialogOption.Modal, true
                                          ));
            }
        }
Ejemplo n.º 12
0
        public static jQueryObject SetReadOnly(jQueryObject elements, bool isReadOnly)
        {
            elements.Each(delegate(int index, Element el)
            {
                jQueryObject elx = jQuery.FromElement(el);

                string type = elx.GetAttribute("type");

                if (elx.Is("select") || (type == "radio") || (type == "checkbox"))
                {
                    if (isReadOnly)
                    {
                        elx.AddClass("readonly").Attribute("disabled", "disabled");
                    }
                    else
                    {
                        elx.RemoveClass("readonly").RemoveAttr("disabled");
                    }
                }
                else
                {
                    if (isReadOnly)
                    {
                        elx.AddClass("readonly").Attribute("readonly", "readonly");
                    }
                    else
                    {
                        elx.RemoveClass("readonly").RemoveAttr("readonly");
                    }
                }

                return(true);
            });

            return(elements);
        }
Ejemplo n.º 13
0
 /// <summary>Copies the CSS classes from one element to another.</summary>
 /// <param name="source">The source element to copy from.</param>
 /// <param name="target">The target element to copy to.</param>
 public static void CopyClasses(jQueryObject source, jQueryObject target)
 {
     string classes = source.GetAttribute(Html.ClassAttr);
     if (string.IsNullOrEmpty(classes)) return;
     AddClasses(target, classes);
 }
Ejemplo n.º 14
0
 public static string GetItemType(jQueryObject link)
 {
     return(GetItemType(link.GetAttribute("href")));
 }
Ejemplo n.º 15
0
 /// <summary>Gets the elements ID, creating a unique ID of the element doesn't already have one.</summary>
 /// <param name="element">The element to get the ID for.</param>
 public static string GetOrCreateId(jQueryObject element)
 {
     string id = element.GetAttribute(Id);
     if (string.IsNullOrEmpty(id))
     {
         id = Helper.CreateId();
         element.Attribute(Id, id);
     }
     return id;
 }
Ejemplo n.º 16
0
        // image preview function, demonstrating the ui.dialog used as a modal window
        static void ViewLargerImage(jQueryObject link)
        {
            string src = link.GetAttribute("href");
            string title = link.Siblings("img").GetAttribute("alt");
            jQueryObject modal = jQuery.Select("img[src$='" + src + "']");

            if (modal.Length > 0)
            {
                modal.Plugin<DialogObject>()
                     .Dialog(DialogMethod.Open);
            }
            else
            {
                jQueryObject img
                    = jQuery.FromHtml("<img alt='" + title + "' width='384' height='288' style='display: none; padding: 8px;' />")
                            .Attribute("src", src).AppendTo("body");

                img.Plugin<DialogObject>()
                   .Dialog(new DialogOptions("title", title,
                                            "width", 400,
                                            "modal", true
                ));
            }
        }
Ejemplo n.º 17
0
        private static AdvancedLayoutState ParseAdvancedLayout(jQueryObject element)
        {
            // gather margins
            Thickness margin = GetMargin(element);

            // gather padding
            float paddingTop, paddingRight, paddingBottom, paddingLeft;
            {
                string padding = element.GetAttribute(AttributeNamePrefix + "padding");
                if (!string.IsNullOrEmpty(padding))
                {
                    string[] split = padding.Trim().Split(" ");
                    paddingTop = float.Parse(split[0]);
                    paddingRight = float.Parse(split[1]);
                    paddingBottom = float.Parse(split[2]);
                    paddingLeft = float.Parse(split[3]);
                }
                else
                {
                    paddingTop = 0;
                    paddingRight = 0;
                    paddingBottom = 0;
                    paddingLeft = 0;
                }
            }

            // gather dimensions
            Number advancedWidth, advancedHeight;
            {
                string width = element.GetAttribute(AttributeNamePrefix + "width");
                string height = element.GetAttribute(AttributeNamePrefix + "height");
                if (string.IsNullOrEmpty(width))
                {
                    advancedWidth = Number.NaN;
                }
                else
                {
                    advancedWidth = Number.Parse(width);
                }

                if (string.IsNullOrEmpty(height))
                {
                    advancedHeight = Number.NaN;
                }
                else
                {
                    advancedHeight = Number.Parse(height);
                }
            }

            // gather vertical alignment
            VerticalAlignment verticalAlignment
                = VerticalAlignmentFromString(element.GetAttribute(AttributeNamePrefix + "vertical-alignment"));

            // gather horizontal alignment
            HorizontalAlignment horizontalAlignment
                = HorizontalAlignmentFromString(element.GetAttribute(AttributeNamePrefix + "horizontal-alignment"));

            // hack: override alignments
            if (verticalAlignment != VerticalAlignment.Stretch && Number.IsNaN(advancedHeight))
            {
                verticalAlignment = VerticalAlignment.Stretch;
            }
            if (horizontalAlignment != HorizontalAlignment.Stretch && Number.IsNaN(advancedWidth))
            {
                horizontalAlignment = HorizontalAlignment.Stretch;
            }

            AdvancedLayoutState state = new AdvancedLayoutState();
            state.Height = advancedHeight;
            state.Width = advancedWidth;
            state.VerticalAlignment = verticalAlignment;
            state.HorizontalAlignment = horizontalAlignment;
            state.Margin = margin;
            state.Padding = new Thickness();
            state.Padding.Top = paddingTop;
            state.Padding.Right = paddingRight;
            state.Padding.Bottom = paddingBottom;
            state.Padding.Left = paddingLeft;

            return state;
        }
Ejemplo n.º 18
0
        private static string GetLocalId(jQueryObject jqElement)
        {
            string strLocalId = jqElement.GetAttribute(AttributeNameLocalId);
            if (string.IsNullOrEmpty(strLocalId))
            {
                return null;
            }
            strLocalId = strLocalId.Trim();
            if (strLocalId.Length == 0)
            {
                return null;
            }

            return strLocalId;
        }
Ejemplo n.º 19
0
        private void ParseFetchXml(FetchQuerySettings querySettings)
        {
            jQueryObject fetchElement = querySettings.FetchXml;

            // Get the entities and link entities - only support 1 level deep
            jQueryObject entityElement = fetchElement.Find("entity");
            string       logicalName   = entityElement.GetAttribute("name");

            EntityQuery rootEntity;

            // Get query from cache or create new
            if (!EntityLookup.ContainsKey(logicalName))
            {
                rootEntity             = new EntityQuery();
                rootEntity.LogicalName = logicalName;
                rootEntity.Attributes  = new Dictionary <string, AttributeQuery>();
                EntityLookup[rootEntity.LogicalName] = rootEntity;
            }
            else
            {
                rootEntity = EntityLookup[logicalName];
            }

            // Get Linked Entities(1 deep)
            jQueryObject linkEntities = entityElement.Find("link-entity");

            linkEntities.Each(delegate(int index, Element element)
            {
                EntityQuery link = new EntityQuery();
                link.Attributes  = new Dictionary <string, AttributeQuery>();
                link.AliasName   = element.GetAttribute("alias").ToString();
                link.LogicalName = element.GetAttribute("name").ToString();
                link.Views       = new Dictionary <string, FetchQuerySettings>();

                if (!EntityLookup.ContainsKey(link.LogicalName))
                {
                    EntityLookup[link.LogicalName] = link;
                }
                else
                {
                    string alias   = link.AliasName;
                    link           = EntityLookup[link.LogicalName];
                    link.AliasName = alias;
                }

                if (!AliasEntityLookup.ContainsKey(link.AliasName))
                {
                    AliasEntityLookup[link.AliasName] = link;
                }
            });

            querySettings.RootEntity = rootEntity;

            // Issue #35 - Add any lookup/picklist quick find fields that are not included in results attributes will cause a format execption
            // because we don't have the metadata - this means that 'name' is not appended to the attribute

            // Add the search string and adjust any lookup columns
            jQueryObject conditions = fetchElement.Find("filter[isquickfindfields='1']");

            conditions.First().Children().Each(delegate(int index, Element element)
            {
                logicalName    = element.GetAttribute("attribute").ToString();
                jQueryObject e = jQuery.FromElement(element);
                jQueryObject p = e.Parents("link-entity");
                if (!querySettings.RootEntity.Attributes.ContainsKey(logicalName))
                {
                    AttributeQuery attribute = new AttributeQuery();
                    attribute.LogicalName    = logicalName;
                    attribute.Columns        = new List <Column>();
                    querySettings.RootEntity.Attributes[logicalName] = attribute;
                }
            });
        }
Ejemplo n.º 20
0
        protected override void OnBeforeInsert(jQueryObject targetElement, InsertMode mode)
        {
            // Setup initial conditions.
            if (mode != InsertMode.Replace) return;

            // Retrieve the 'value' if there is one.
            string value = targetElement.GetAttribute(Html.Value);
            if (!Script.IsUndefined(value))
            {
                Text = value;
            }

            // Finish up.
            base.OnBeforeInsert(targetElement, mode);
        }
Ejemplo n.º 21
0
 public static Int64?GetItemId(jQueryObject link)
 {
     return(GetItemId(link.GetAttribute("href")));
 }