Beispiel #1
0
        /// <summary>
        /// 从 Ajax 设置创建一个 JQuery 实例, 如果设置中的请求地址为空, 则返回 null.
        /// </summary>
        /// <param name="setting">Ajax 相关设置.</param>
        /// <returns>JQuery 实例.</returns>
        public static JQuery Create(AjaxSetting setting)
        {
            if (string.IsNullOrEmpty(setting.Url))
            {
                return(null);
            }

            string quote;

            if (setting.IsSingleQuote)
            {
                quote = "'";
            }
            else
            {
                quote = "\"";
            }

            string data;
            bool   isWebService = !string.IsNullOrEmpty(setting.MethodName);

            if (!string.IsNullOrEmpty(setting.Data))
            {
                data = setting.Data;
            }
            else if (string.IsNullOrEmpty(setting.Form))
            {
                data = makeParameterExpression(setting.Parameters, isWebService, quote);
            }
            else
            {
                data = JQuery.Create(setting.Form, false).Serialize( ).Code;
            }

            string map = string.Format("url: {0}{1}{0}, dataType: {0}{2}{0}, data: {3}, type: {0}{4}{0}",
                                       quote,
                                       setting.Url + (isWebService ? "/" + setting.MethodName : string.Empty),
                                       setting.DataType,
                                       data,
                                       setting.Type
                                       );

            if (!string.IsNullOrEmpty(setting.ContentType))
            {
                map += string.Format(", contentType: {0}{1}{0}", quote, setting.ContentType);
            }

            foreach (Event @event in setting.SettingHelper.Events)
            {
                if (@event.Type != EventType.none && @event.Type != EventType.__init && !string.IsNullOrEmpty(@event.Value))
                {
                    map += ", " + @event.Type + ": " + @event.Value;
                }
            }

            return(JQuery.Create(false, false).Ajax("{" + map + "}"));
        }
Beispiel #2
0
		/// <summary>
		/// 为 AjaxSetting 增加参数, 将排除已经存在的参数.
		/// </summary>
		/// <param name="ajax">增加参数的 AjaxSetting.</param>
		/// <param name="parameters">增加的参数.</param>
		public static void AppendParameter (AjaxSetting ajax, Parameter[] parameters )
		{

			if ( null == ajax || null == parameters )
				return;

			List<string> names = new List<string> ( );

			foreach ( Parameter parameter in ajax.ParameterList )
				names.Add ( parameter.Name );

			foreach ( Parameter parameter in parameters )
				if ( null != parameter && !names.Contains ( parameter.Name ) )
					ajax.ParameterList.Add ( parameter );

		}
Beispiel #3
0
        /// <summary>
        /// 在 jQuery 中包含的页面元素的某个事件中执行或者直接执行 Ajax 调用.
        /// </summary>
        /// <param name="setting">Ajax 相关设置.</param>
        /// <returns>更新后的 JQueryUI.</returns>
        public JQueryUI Ajax(AjaxSetting setting)
        {
            if (setting.EventType == EventType.none)
            {
                return(this);
            }

            string code;

            if (string.IsNullOrEmpty(setting.ClientFunction))
            {
                JQuery ajax = JQueryUI.Create(setting);

                if (null == ajax)
                {
                    return(this);
                }

                code = "function(e){" + ajax.EndLine( ).Code + "}";
            }
            else
            {
                code = setting.ClientFunction;
            }

            if (setting.EventType == EventType.__init)
            {
                if (this.code != string.Empty)
                {
                    this.EndLine( );
                }

                this.AppendCode(code);
            }
            else
            {
                this.Bind(string.Format("'{0}'", setting.EventType), code);
            }

            return(this);
        }
Beispiel #4
0
        /// <summary>
        /// 为 AjaxSetting 增加参数, 将排除已经存在的参数.
        /// </summary>
        /// <param name="ajax">增加参数的 AjaxSetting.</param>
        /// <param name="parameters">增加的参数.</param>
        public static void AppendParameter(AjaxSetting ajax, Parameter[] parameters)
        {
            if (null == ajax || null == parameters)
            {
                return;
            }

            List <string> names = new List <string> ( );

            foreach (Parameter parameter in ajax.ParameterList)
            {
                names.Add(parameter.Name);
            }

            foreach (Parameter parameter in parameters)
            {
                if (null != parameter && !names.Contains(parameter.Name))
                {
                    ajax.ParameterList.Add(parameter);
                }
            }
        }
Beispiel #5
0
		/// <summary>
		/// 在 jQuery 中包含的页面元素的某个事件中执行或者直接执行 Ajax 调用.
		/// </summary>
		/// <param name="setting">Ajax 相关设置.</param>
		/// <returns>更新后的 JQueryUI.</returns>
		public JQueryUI Ajax ( AjaxSetting setting )
		{

			if ( setting.EventType == EventType.none )
				return this;

			string code;

			if ( string.IsNullOrEmpty ( setting.ClientFunction ) )
			{
				JQuery ajax = JQueryUI.Create ( setting );

				if ( null == ajax )
					return this;

				code = "function(e){" + ajax.EndLine ( ).Code + "}";
			}
			else
				code = setting.ClientFunction;

			if ( setting.EventType == EventType.__init )
			{

				if ( this.code != string.Empty )
					this.EndLine ( );

				this.AppendCode ( code );
			}
			else
				this.Bind ( string.Format ( "'{0}'", setting.EventType ), code );

			return this;
		}
Beispiel #6
0
		/// <summary>
		/// 从 Ajax 设置创建一个 JQuery 实例, 如果设置中的请求地址为空, 则返回 null.
		/// </summary>
		/// <param name="setting">Ajax 相关设置.</param>
		/// <returns>JQuery 实例.</returns>
		public static JQuery Create ( AjaxSetting setting )
		{

			if ( string.IsNullOrEmpty ( setting.Url ) )
				return null;

			string quote;

			if ( setting.IsSingleQuote )
				quote = "'";
			else
				quote = "\"";

			string data;
			bool isWebService = !string.IsNullOrEmpty ( setting.MethodName );

			if ( !string.IsNullOrEmpty ( setting.Data ) )
				data = setting.Data;
			else if ( string.IsNullOrEmpty ( setting.Form ) )
				data = makeParameterExpression ( setting.Parameters, isWebService, quote );
			else
				data = JQuery.Create ( setting.Form, false ).Serialize ( ).Code;

			string map = string.Format ( "url: {0}{1}{0}, dataType: {0}{2}{0}, data: {3}, type: {0}{4}{0}",
				quote,
				setting.Url + ( isWebService ? "/" + setting.MethodName : string.Empty ),
				setting.DataType,
				data,
				setting.Type
				);

			if ( !string.IsNullOrEmpty ( setting.ContentType ) )
				map += string.Format ( ", contentType: {0}{1}{0}", quote, setting.ContentType );

			foreach ( Event @event in setting.SettingHelper.Events )
				if ( @event.Type != EventType.none && @event.Type != EventType.__init && !string.IsNullOrEmpty ( @event.Value ) )
					map += ", " + @event.Type + ": " + @event.Value;

			return JQuery.Create ( false, false ).Ajax ( "{" + map + "}" );
		}