Пример #1
0
        private static void LoadResources()
        {
            jQueryAjaxOptions options = new jQueryAjaxOptions();

            options.Async = false;
            int lcid = Page.Context.GetUserLcid();

            if (_siteMap == null)
            {
                options.Url = Page.Context.GetClientUrl() + "/" + PageEx.GetCacheKey() + "/WebResources/dev1_/js/SiteMap" + lcid.ToString() + ".js";
                _siteMap    = jQuery.ParseJsonData <SiteMap>(jQuery.Ajax(options).ResponseText);
            }

            if (_resources == null)
            {
                Dictionary <string, string> loadedResources = null;
                options.Url = GetResourceStringWebResourceUrl(lcid);
                try
                {
                    loadedResources = jQuery.ParseJsonData <Dictionary <string, string> >(jQuery.Ajax(options).ResponseText);
                }
                catch { }

                if (loadedResources == null)
                {
                    // We fall back to the 1033 because this is included in the solution
                    options.Url     = GetResourceStringWebResourceUrl(1033);
                    loadedResources = jQuery.ParseJsonData <Dictionary <string, string> >(jQuery.Ajax(options).ResponseText);
                }
                _resources = loadedResources;
            }
        }
Пример #2
0
        public IDeferred <IEnumerable <Photo> > SearchPhotos(string tags, int count)
        {
            jQueryAjaxOptions ajaxOptions =
                new jQueryAjaxOptions("url", String.Format(SearchUriFormat, _apiKey, tags.EncodeUriComponent(), count),
                                      "jsonp", "jsoncallback",
                                      "dataType", "jsonp");

            return(jQuery.AjaxRequest <SearchResponse>(ajaxOptions).Pipe <IEnumerable <Photo> >(
                       delegate(SearchResponse response) {
                List <Photo> photos =
                    response.PhotoResponse.PhotoList.Map <Photo>(delegate(PhotoResult photoResult) {
                    return new Photo(photoResult.ID,
                                     photoResult.Title,
                                     "http://flic.kr/p/" + Base58Encode(photoResult.ID),
                                     photoResult.Url_m,
                                     photoResult.Url_t,
                                     Int32.Parse(photoResult.Width_m),
                                     Int32.Parse(photoResult.Height_m),
                                     Int32.Parse(photoResult.Width_t),
                                     Int32.Parse(photoResult.Height_t));
                });

                return photos;
            }));
        }
Пример #3
0
        /// <summary>
        /// Load the content by inserting the lcid after the filename, before the extension
        /// E.g. someResource.html is replaced with someResource_1033.js
        /// Ideally this url should be relative so to benefit from caching without having
        /// to explicitly specify the cache key
        /// </summary>
        /// <param name="webresourceFileName"></param>
        /// <param name="lcid"></param>
        /// <param name="callback"></param>
        public void LoadContent(string webresourceFileName, int lcid, Action callback)
        {
            // If the filename starts in '/Webresources/' we must prefix with the cache key
            // TODO
            // Xrm.Sparkle.Page.GetCacheKey()

            // Check the locale is in the supported locales
            if (!SupportedLCIDs.Contains(lcid))
            {
                lcid = FallBackLCID;
            }

            int    pos = webresourceFileName.LastIndexOf('.');
            string resourceFileName = webresourceFileName.Substr(0, pos - 1) + "_" + lcid.ToString() + webresourceFileName.Substr(pos);

            jQueryAjaxOptions options = new jQueryAjaxOptions();

            options.Type     = "GET";
            options.Url      = resourceFileName;
            options.DataType = "script";
            options.Success  = delegate(object data, string textStatus, jQueryXmlHttpRequest request)
            {
                callback();
            };
            options.Error = delegate(jQueryXmlHttpRequest request, string textStatus, Exception error)
            {
                Script.Alert(String.Format("Could not load resource file '{0}'. Please contact your system adminsitrator.", resourceFileName));
            };
            jQuery.Ajax(options);
        }
Пример #4
0
        /// <summary>
        /// Load the content by inserting the lcid after the filename, before the extension
        /// E.g. someResource.html is replaced with someResource_1033.js
        /// Ideally this url should be relative so to benefit from caching without having
        /// to explicitly specify the cache key
        /// </summary>
        /// <param name="webresourceFileName"></param>
        /// <param name="lcid"></param>
        /// <param name="callback"></param>
        public static void LoadContent(string webresourceFileName, int lcid, Action callback)
        {
            bool lcidSupported = SupportedLCIDs.Contains(0) || SupportedLCIDs.Contains(lcid);

            // Check the locale is in the supported locales
            if (!lcidSupported || (lcid == FallBackLCID))
            {
                callback();
                return;
            }

            int    pos = webresourceFileName.LastIndexOf('.');
            string resourceFileName = Page.Context.GetClientUrl() + "/" + PageEx.GetCacheKey() + "WebResources/" + webresourceFileName.Substr(0, pos) + "_" + lcid.ToString() + webresourceFileName.Substr(pos);

            jQueryAjaxOptions options = new jQueryAjaxOptions();

            options.Type     = "GET";
            options.Url      = resourceFileName;
            options.DataType = "script";
            options.Cache    = true;
            options.Success  = delegate(object data, string textStatus, jQueryXmlHttpRequest request)
            {
                callback();
            };
            options.Error = delegate(jQueryXmlHttpRequest request, string textStatus, Exception error)
            {
                Script.Alert(String.Format("Could not load resource file '{0}'. Please contact your system adminsitrator.\n\n{1}:{2}", resourceFileName, textStatus, error.Message));
                callback();
            };
            jQuery.Ajax(options);
        }
        private void SaveCustomer(jQueryEvent evt)
        {
            var opts = new jQueryAjaxOptions {
                Url = "/Home/SaveCustomer"
            };

            ((dynamic)opts).data = jQuery.Select("#customerForm").Serialize();
            var req = jQuery.Ajax(opts);

            req.Success(_ => {
                ((DialogObject)jQuery.Select("#customerForm")).Close();
                LoadCustomers();
            });
            req.Fail(_ => Window.Alert("Save failed"));
        }