MonoRail Helper that delivers AJAX capabilities.
The following libraries are exposed: Prototype Simplify ajax programming, among other goodies Behaviour Uses css selectors to bind javascript code to DOM elements
상속: AbstractHelper, IServiceEnabledComponent
		protected static void SetUpHelpers(IEngineContext engineContext, IController controller, IControllerContext controllerContext)
		{
			var formHelper = new ARFormHelper();
			formHelper.SetContext(engineContext);
			formHelper.SetController(controller, controllerContext);

			var presentationHelper = new PresentationHelper();
			presentationHelper.SetContext(engineContext);
			presentationHelper.SetController(controller, controllerContext);

			var paginationHelper = new PaginationHelper();
			paginationHelper.SetContext(engineContext);
			paginationHelper.SetController(controller, controllerContext);

			var scriptaculous = new ScriptaculousHelper();
			scriptaculous.SetContext(engineContext);
			scriptaculous.SetController(controller, controllerContext);

			var ajaxHelper = new AjaxHelper();
			ajaxHelper.SetContext(engineContext);
			ajaxHelper.SetController(controller, controllerContext);

			controllerContext.Helpers["Scriptaculous"] = scriptaculous;
			controllerContext.Helpers["Ajax"] = ajaxHelper;
			controllerContext.Helpers["Form"] = formHelper;
			controllerContext.Helpers["PresentationHelper"] = presentationHelper;
			controllerContext.Helpers["PaginationHelper"] = paginationHelper;
		}
예제 #2
0
		/// <summary>
		/// Generate Ajax form tag for ajax based form submission. Experimental.
		/// </summary>
		/// <param name="parameters"></param>
		/// <returns></returns>
		public virtual string AjaxFormTag(IDictionary parameters)
		{
			currentFormId = CommonUtils.ObtainEntryAndRemove(parameters, "id", "form" + ++formCount);
			var afterFormTag = String.Empty;
			
			if (IsValidationEnabled)
			{
				validationConfig = ValidatorProvider.CreateConfiguration(parameters);
				afterFormTag = validationConfig.CreateAfterFormOpened(currentFormId);
			}
			
			var url = UrlHelper.For(parameters);

			parameters["form"] = true;

			if (parameters.Contains("onsubmit"))
			{
				var onSubmitFunc = CommonUtils.ObtainEntryAndRemove(parameters, "onsubmit");
				//remove return to make it compatible for ajax condition
				if (onSubmitFunc.StartsWith("return ", StringComparison.InvariantCultureIgnoreCase))
				{
					onSubmitFunc = onSubmitFunc.Substring(7);
				}
				if (onSubmitFunc.EndsWith(";", StringComparison.InvariantCultureIgnoreCase))
				{
					onSubmitFunc = onSubmitFunc.Remove(onSubmitFunc.Length - 1);
				}
				var conditionFunc = CommonUtils.ObtainEntryAndRemove(parameters, "condition", string.Empty);
				if (!string.IsNullOrEmpty(conditionFunc))
				{
					conditionFunc += " && ";
				}
				conditionFunc += onSubmitFunc;

				parameters["condition"] = conditionFunc;
			}
			var isMethodAssigned = parameters.Contains("method");

			var method = CommonUtils.ObtainEntryAndRemove(parameters, "method", "post");

			parameters["url"] = url;

			// reassign method so in case if there is no value the default is assigned.

			if (isMethodAssigned)
			{
				parameters["method"] = method;
			}

			var remoteFunc = new AjaxHelper().RemoteFunction(parameters);

			var formContent = String.Format("<form id='{1}' method='{2}' {3} onsubmit=\"{0}; return false;\" enctype=\"multipart/form-data\">", remoteFunc, currentFormId, method, GetAttributes(parameters));

			return formContent + afterFormTag;
		}
		protected static void SetUpHelpers(Controller controller)
		{
			ARFormHelper formHelper = new ARFormHelper();
			formHelper.SetController(controller);
	
			ValidationHelper validationHelper = new ValidationHelper();
			validationHelper.SetController(controller);
	
			PresentationHelper presentationHelper = new PresentationHelper();
			presentationHelper.SetController(controller);
	
            PaginationHelper paginationHelper = new PaginationHelper();
            paginationHelper.SetController(controller);

			ScriptaculousHelper scriptaculous = new ScriptaculousHelper();
			scriptaculous.SetController(controller);

			AjaxHelper ajaxHelper = new AjaxHelper();
			ajaxHelper.SetController(controller);

			controller.PropertyBag["Scriptaculous"] = scriptaculous;
			controller.PropertyBag["Ajax"] = ajaxHelper;
			controller.PropertyBag["Form"] = formHelper;
			controller.PropertyBag["ValidationHelper"] = validationHelper;
			controller.PropertyBag["PresentationHelper"] = presentationHelper;
            controller.PropertyBag["PaginationHelper"] = paginationHelper;
		}