Example #1
0
 void IPlugIn.ProcessPageRequest(PageRequest request, ViewPage page)
 {
     if (page.Rows.Count == 0)
     {
         page.Icons = new string[0];
         return;
     }
     if (!(_requireProcessing))
     {
         List<string> icons = new List<string>();
         for (int i = 0; (i < page.Rows.Count); i++)
         {
             string rowDir = AnnotationPlugIn.GenerateDataRecordPath(request.Controller, page, null, i);
             if (Directory.Exists(rowDir))
                 icons.Add("Attachment");
             else
                 icons.Add(null);
         }
         page.Icons = icons.ToArray();
         return;
     }
     List<DynamicExpression> expressions = new List<DynamicExpression>(page.Expressions);
     DynamicExpression de = new DynamicExpression();
     de.Target = "Annotations";
     de.Scope = DynamicExpressionScope.CategoryVisibility;
     de.Type = DynamicExpressionType.ClientScript;
     de.Test = "!this.get_isInserting()";
     de.ViewId = page.View;
     expressions.Add(de);
     page.Expressions = expressions.ToArray();
     if (!(_retrieveAnnotations))
         return;
     DataField field = page.FindField("_Annotation_AttachmentNew");
     if (field != null)
     {
         int fieldIndex = page.Fields.IndexOf(field);
         string newValue = String.Format("{0},{1}|{2}", request.Controller, field.Name, Regex.Replace(((string)(page.Rows[0][fieldIndex])), "^\\w+\\|(.+)$", "$1"));
         if (field.Name == "_Annotation_AttachmentNew")
             newValue = ("null|" + newValue);
         page.Rows[0][fieldIndex] = newValue;
     }
     string p = AnnotationPlugIn.GenerateDataRecordPath(request.Controller, page, null, 0);
     if (Directory.Exists(p))
     {
         string[] files = Directory.GetFiles(p, "*.xml");
         List<object> values = new List<object>(page.Rows[0]);
         int i = (files.Length - 1);
         while (i >= 0)
         {
             string filename = files[i];
             XPathDocument doc = new XPathDocument(filename);
             XPathNavigator nav = doc.CreateNavigator().SelectSingleNode("/*");
             DataField f = null;
             if (nav.Name == "note")
             {
                 f = new DataField();
                 f.Name = "_Annotation_Note";
                 f.Type = "String";
                 f.HeaderText = String.Format(Localizer.Replace("AnnotationNoteDynamicFieldHeaderText", "{0} written at {1}"), ReadNameAndEmail(nav), Convert.ToDateTime(nav.GetAttribute("timestamp", String.Empty)));
                 f.Columns = 50;
                 f.Rows = 7;
                 f.TextMode = TextInputMode.Note;
                 values.Add(nav.Value);
             }
             else
                 if (nav.Name == "attachment")
                 {
                     f = new DataField();
                     f.Name = "_Annotation_Attachment";
                     f.Type = "Byte[]";
                     f.HeaderText = String.Format(Localizer.Replace("AnnotationAttachmentDynamicFieldHeaderText", "{0} attached <b>{1}</b> at {2}"), ReadNameAndEmail(nav), nav.GetAttribute("fileName", String.Empty), Convert.ToDateTime(nav.GetAttribute("timestamp", String.Empty)));
                     f.OnDemand = true;
                     f.OnDemandHandler = "AnnotationPlugIn";
                     f.OnDemandStyle = OnDemandDisplayStyle.Link;
                     if (nav.GetAttribute("contentType", String.Empty).StartsWith("image/"))
                         f.OnDemandStyle = OnDemandDisplayStyle.Thumbnail;
                     f.CategoryIndex = (page.Categories.Count - 1);
                     values.Add(nav.GetAttribute("value", String.Empty));
                 }
             if (f != null)
             {
                 f.Name = (f.Name + Path.GetFileNameWithoutExtension(filename));
                 f.AllowNulls = true;
                 f.CategoryIndex = (page.Categories.Count - 1);
                 if (!(Controller.UserIsInRole("Administrators")))
                     f.ReadOnly = true;
                 page.Fields.Add(f);
             }
             i = (i - 1);
         }
         page.Rows[0] = values.ToArray();
         if (files.Length > 0)
         {
             page.Categories[(page.Categories.Count - 1)].Tab = Localizer.Replace("AnnotationTab", "Notes & Attachments");
             expressions.RemoveAt((expressions.Count - 1));
             page.Expressions = expressions.ToArray();
         }
     }
     else
     {
         de.Test = "this.get_isEditing() && this.get_view()._displayAnnotations";
         ActionGroup g = new ActionGroup();
         page.ActionGroups.Add(g);
         g.Scope = "ActionBar";
         g.Flat = true;
         Action a = new Action();
         g.Actions.Add(a);
         a.WhenLastCommandName = "Edit";
         a.WhenView = page.View;
         a.CommandName = "ClientScript";
         a.CommandArgument = "this.get_view()._displayAnnotations=true;this._focusedFieldName = \'_Annotation_No" +
             "teNew\';this._raiseSelectedDelayed=false;";
         a.HeaderText = Localizer.Replace("AnnotationActionHeaderText", "Annotate");
         a.CssClass = "AttachIcon";
         a.WhenClientScript = "this.get_view()._displayAnnotations!=true;";
     }
 }
        void IPlugIn.ProcessPageRequest(PageRequest request, ViewPage page)
        {
            if (page.Rows.Count == 0)
            {
                page.Icons = new string[0];
                return;
            }
            if (!(_requireProcessing))
            {
                List <string> icons = new List <string>();
                for (int i = 0; (i < page.Rows.Count); i++)
                {
                    string rowDir = AnnotationPlugIn.GenerateDataRecordPath(request.Controller, page, null, i);
                    if (Directory.Exists(rowDir))
                    {
                        icons.Add("Attachment");
                    }
                    else
                    {
                        icons.Add(null);
                    }
                }
                page.Icons = icons.ToArray();
                return;
            }
            List <DynamicExpression> expressions = new List <DynamicExpression>(page.Expressions);
            DynamicExpression        de          = new DynamicExpression();

            de.Target = "Annotations";
            de.Scope  = DynamicExpressionScope.CategoryVisibility;
            de.Type   = DynamicExpressionType.ClientScript;
            de.Test   = "!this.get_isInserting()";
            de.ViewId = page.View;
            expressions.Add(de);
            page.Expressions = expressions.ToArray();
            if (!(_retrieveAnnotations))
            {
                return;
            }
            DataField field = page.FindField("_Annotation_AttachmentNew");

            if (field != null)
            {
                int    fieldIndex = page.Fields.IndexOf(field);
                string newValue   = String.Format("{0},{1}|{2}", request.Controller, field.Name, Regex.Replace(((string)(page.Rows[0][fieldIndex])), "^\\w+\\|(.+)$", "$1"));
                if (field.Name == "_Annotation_AttachmentNew")
                {
                    newValue = ("null|" + newValue);
                }
                page.Rows[0][fieldIndex] = newValue;
            }
            string p = AnnotationPlugIn.GenerateDataRecordPath(request.Controller, page, null, 0);

            if (Directory.Exists(p))
            {
                string[]      files  = Directory.GetFiles(p, "*.xml");
                List <object> values = new List <object>(page.Rows[0]);
                int           i      = (files.Length - 1);
                while (i >= 0)
                {
                    string         filename = files[i];
                    XPathDocument  doc      = new XPathDocument(filename);
                    XPathNavigator nav      = doc.CreateNavigator().SelectSingleNode("/*");
                    DataField      f        = null;
                    if (nav.Name == "note")
                    {
                        f            = new DataField();
                        f.Name       = "_Annotation_Note";
                        f.Type       = "String";
                        f.HeaderText = String.Format(Localizer.Replace("AnnotationNoteDynamicFieldHeaderText", "{0} written at {1}"), ReadNameAndEmail(nav), Convert.ToDateTime(nav.GetAttribute("timestamp", String.Empty)));
                        f.Columns    = 50;
                        f.Rows       = 7;
                        f.TextMode   = TextInputMode.Note;
                        values.Add(nav.Value);
                    }
                    else
                    if (nav.Name == "attachment")
                    {
                        f                 = new DataField();
                        f.Name            = "_Annotation_Attachment";
                        f.Type            = "Byte[]";
                        f.HeaderText      = String.Format(Localizer.Replace("AnnotationAttachmentDynamicFieldHeaderText", "{0} attached <b>{1}</b> at {2}"), ReadNameAndEmail(nav), nav.GetAttribute("fileName", String.Empty), Convert.ToDateTime(nav.GetAttribute("timestamp", String.Empty)));
                        f.OnDemand        = true;
                        f.OnDemandHandler = "AnnotationPlugIn";
                        f.OnDemandStyle   = OnDemandDisplayStyle.Link;
                        if (nav.GetAttribute("contentType", String.Empty).StartsWith("image/"))
                        {
                            f.OnDemandStyle = OnDemandDisplayStyle.Thumbnail;
                        }
                        f.CategoryIndex = (page.Categories.Count - 1);
                        values.Add(nav.GetAttribute("value", String.Empty));
                    }
                    if (f != null)
                    {
                        f.Name          = (f.Name + Path.GetFileNameWithoutExtension(filename));
                        f.AllowNulls    = true;
                        f.CategoryIndex = (page.Categories.Count - 1);
                        if (!(Controller.UserIsInRole("Administrators")))
                        {
                            f.ReadOnly = true;
                        }
                        page.Fields.Add(f);
                    }
                    i = (i - 1);
                }
                page.Rows[0] = values.ToArray();
                if (files.Length > 0)
                {
                    page.Categories[(page.Categories.Count - 1)].Tab = Localizer.Replace("AnnotationTab", "Notes & Attachments");
                    expressions.RemoveAt((expressions.Count - 1));
                    page.Expressions = expressions.ToArray();
                }
            }
            else
            {
                de.Test = "this.get_isEditing() && this.get_view()._displayAnnotations";
                ActionGroup g = new ActionGroup();
                page.ActionGroups.Add(g);
                g.Scope = "ActionBar";
                g.Flat  = true;
                Action a = new Action();
                g.Actions.Add(a);
                a.WhenLastCommandName = "Edit";
                a.WhenView            = page.View;
                a.CommandName         = "ClientScript";
                a.CommandArgument     = "this.get_view()._displayAnnotations=true;this._focusedFieldName = \'_Annotation_No" +
                                        "teNew\';this._raiseSelectedDelayed=false;";
                a.HeaderText       = Localizer.Replace("AnnotationActionHeaderText", "Annotate");
                a.CssClass         = "AttachIcon";
                a.WhenClientScript = "this.get_view()._displayAnnotations!=true;";
            }
        }