public void AssignContext(string controller, string view, ControllerConfiguration config) { _controller = controller; _view = view; string referrer = String.Empty; if ((PageSize == 1000) && String.IsNullOrEmpty(this.SortExpression)) { // we are processing a request to retrieve static lookup data XPathNavigator sortExpressionNode = config.SelectSingleNode("c:dataController/c:views/c:view[@id=\'{0}\']/@sortExpression", view); if ((sortExpressionNode != null) && !(String.IsNullOrEmpty(sortExpressionNode.Value))) { this.SortExpression = sortExpressionNode.Value; } } if ((HttpContext.Current != null) && (HttpContext.Current.Request.UrlReferrer != null)) { referrer = HttpContext.Current.Request.UrlReferrer.AbsolutePath; } this._contextKey = string.Format("{0}/{1}.{2}.{3}", referrer, controller, view, ContextKey); }
public virtual ControllerConfiguration EnsureVitalElements() { // verify that the data controller has views and actions XPathNavigator root = SelectSingleNode("/c:dataController[c:views/c:view and c:actions/c:actionGroup]"); if (root != null) { return(this); } // add missing configuration elements XmlDocument doc = new XmlDocument(); doc.LoadXml(_navigator.OuterXml); ControllerConfiguration config = new ControllerConfiguration(doc.CreateNavigator()); XPathNavigator fieldsNode = config.SelectSingleNode("/c:dataController/c:fields[not(c:field[@isPrimaryKey=\'true\'])]"); if (fieldsNode != null) { fieldsNode.AppendChild("<field name=\"PrimaryKey\" type=\"Int32\" isPrimaryKey=\"true\" readOnly=\"true\"/>"); } root = config.SelectSingleNode("/c:dataController"); EnsureChildNode(root, "views"); XPathNavigator viewsNode = config.SelectSingleNode("/c:dataController/c:views[not(c:view)]"); if (viewsNode != null) { StringBuilder sb = new StringBuilder("<view id=\"view1\" type=\"Form\" label=\"Form\"><categories><category id=\"c1\" flow=\"New" + "Column\"><dataFields>"); XPathNodeIterator fieldIterator = config.Select("/c:dataController/c:fields/c:field"); while (fieldIterator.MoveNext()) { string fieldName = fieldIterator.Current.GetAttribute("name", String.Empty); bool hidden = (fieldName == "PrimaryKey"); string length = fieldIterator.Current.GetAttribute("length", String.Empty); if (String.IsNullOrEmpty(length) && (((bool)(fieldIterator.Current.Evaluate("not(c:items/@style!=\'\')", _resolver))) == true)) { if (fieldIterator.Current.GetAttribute("type", String.Empty) == "String") { length = "50"; } else { length = "20"; } } sb.AppendFormat("<dataField fieldName=\"{0}\" hidden=\"{1}\"", fieldName, hidden.ToString().ToLower()); if (!(String.IsNullOrEmpty(length))) { sb.AppendFormat(" columns=\"{0}\"", length); } sb.Append(" />"); } sb.Append("</dataFields></category></categories></view>"); viewsNode.AppendChild(sb.ToString()); } EnsureChildNode(root, "actions"); XPathNavigator actionsNode = config.SelectSingleNode("/c:dataController/c:actions[not(c:actionGroup)]"); if (actionsNode != null) { actionsNode.AppendChild(@"<actionGroup id=""ag1"" scope=""Form""> <action id=""a1"" commandName=""Confirm"" causesValidation=""true"" whenLastCommandName=""New"" /> <action id=""a2"" commandName=""Cancel"" whenLastCommandName=""New"" /> <action id=""a3"" commandName=""Confirm"" causesValidation=""true"" whenLastCommandName=""Edit"" /> <action id=""a4"" commandName=""Cancel"" whenLastCommandName=""Edit"" /> <action id=""a5"" commandName=""Edit"" causesValidation=""true"" /> </actionGroup>"); } XPathNavigator plugIn = config.SelectSingleNode("/c:dataController/@plugIn"); if (plugIn != null) { plugIn.DeleteSelf(); config._plugIn = null; } return(config); }
void IPlugIn.PreProcessPageRequest(PageRequest request, ViewPage page) { XPathNavigator view = _config.SelectSingleNode("//c:view[@id=\'{0}\' and @type=\'Form\']/c:categories", request.View); if ((view != null) && ((request.PageSize > 0) && (!(request.Inserting) && (_config.SelectSingleNode("/c:dataController/c:fields/c:field[@name=\'_Annotation_NoteNew\']") == null)))) { _requireProcessing = true; string ns = ControllerConfiguration.Namespace; List <DynamicExpression> expressions = new List <DynamicExpression>(_config.Expressions); // create NewXXX fields under "fields" node StringBuilder sb = new StringBuilder(); XmlWriterSettings settings = new XmlWriterSettings(); settings.ConformanceLevel = ConformanceLevel.Fragment; XmlWriter writer = XmlWriter.Create(sb, settings); // NoteNew field writer.WriteStartElement("field", ns); writer.WriteAttributeString("name", "_Annotation_NoteNew"); writer.WriteAttributeString("type", "String"); writer.WriteAttributeString("allowSorting", "false"); writer.WriteAttributeString("allowQBE", "false"); writer.WriteAttributeString("label", Localizer.Replace("AnnotationNoteNewFieldLabel", "Notes")); writer.WriteAttributeString("computed", "true"); writer.WriteElementString("formula", ns, "null"); writer.WriteEndElement(); DynamicExpression de = new DynamicExpression(); de.Target = "_Annotation_NoteNew"; de.Scope = DynamicExpressionScope.DataFieldVisibility; de.Type = DynamicExpressionType.ClientScript; de.Test = "this.get_isEditing()"; de.ViewId = request.View; expressions.Add(de); // AttachmentNew field writer.WriteStartElement("field", ns); writer.WriteAttributeString("name", "_Annotation_AttachmentNew"); writer.WriteAttributeString("type", "Byte[]"); writer.WriteAttributeString("onDemand", "true"); writer.WriteAttributeString("sourceFields", this.KeyFields); writer.WriteAttributeString("onDemandHandler", "AnnotationPlugIn"); writer.WriteAttributeString("allowQBE", "false"); writer.WriteAttributeString("allowSorting", "false"); writer.WriteAttributeString("label", Localizer.Replace("AnnotationAttachmentNewFieldLabel", "Attachment")); writer.WriteAttributeString("computed", "true"); writer.WriteElementString("formula", ns, "null"); writer.WriteEndElement(); writer.Close(); this.Fields.AppendChild(sb.ToString()); DynamicExpression ade = new DynamicExpression(); ade.Target = "_Annotation_AttachmentNew"; ade.Scope = DynamicExpressionScope.DataFieldVisibility; ade.Type = DynamicExpressionType.ClientScript; ade.Test = "this.get_isEditing()"; ade.ViewId = request.View; expressions.Add(ade); // create NewXXX data fields under "view/dataFields" node sb = new StringBuilder(); writer = XmlWriter.Create(sb); writer.WriteStartElement("category", ns); writer.WriteAttributeString("id", "Annotations"); writer.WriteAttributeString("headerText", Localizer.Replace("AnnotationCategoryHeaderText", "Notes and Attachments")); writer.WriteElementString("description", ns, Localizer.Replace("AnnotationCategoryDescription", "Enter optional notes and attach files.")); writer.WriteStartElement("dataFields", ns); // _Annotation_NoteNew dataField writer.WriteStartElement("dataField", ns); writer.WriteAttributeString("fieldName", "_Annotation_NoteNew"); writer.WriteAttributeString("columns", "50"); writer.WriteAttributeString("rows", "7"); writer.WriteEndElement(); // _Annotation_AttachmentNew writer.WriteStartElement("dataField", ns); writer.WriteAttributeString("fieldName", "_Annotation_AttachmentNew"); writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndElement(); writer.Close(); view.AppendChild(sb.ToString()); _retrieveAnnotations = !(request.Inserting); _config.Expressions = expressions.ToArray(); } }