internal override void ConstructDataSet(FormDataSet dataSet, IHtmlElement submitter)
 {
     if (_type.IsAppendingData(submitter))
     {
         _type.ConstructDataSet(dataSet);
     }
 }
 private void showDiagram()
 {
     try
     {
         if (provider == null)
         {
             return;
         }
         IDataSetDesktop desktop = provider.Desktop;
         IDataSetFactory factory = DataSetFactoryChooser.Chooser[provider.FactoryName];
         DataSetService.Forms.FormDataSet form = new FormDataSet(desktop,
                                                                 new DataSetSerializable.DataDesktopSerializable(), factory, provider.ConnecionString);
         form.ShowDialog(this);
         desktop = form.Desktop;
         if (desktop != null)
         {
             provider.Desktop = desktop;
             string st = factory.GenerateStatement(desktop);
             textBoxStatement.Text = st;
         }
     }
     catch (Exception ex)
     {
         ex.ShowError(10);
     }
 }
Beispiel #3
0
        public override void ConstructDataSet(FormDataSet dataSet)
        {
            if (_files.Length == 0)
                dataSet.Append(Input.Name, String.Empty, MimeTypes.Binary);

            foreach (var file in _files)
                dataSet.Append(Input.Name, file, Input.Type);
        }
Beispiel #4
0
 public override void ConstructDataSet(FormDataSet dataSet)
 {
     if (Input.IsChecked)
     {
         var value = Input.HasValue ? Input.Value : Keywords.On;
         dataSet.Append(Input.Name, value, Input.Type);
     }
 }
Beispiel #5
0
        public override void ConstructDataSet(FormDataSet dataSet)
        {
            if (_files.Length == 0)
                dataSet.Append(Input.Name, default(IFile), Input.Type);

            foreach (var file in _files)
                dataSet.Append(Input.Name, file, Input.Type);
        }
        public override void ConstructDataSet(FormDataSet dataSet)
        {
            base.ConstructDataSet(dataSet);
            var dirname = Input.GetAttribute(null, AttributeNames.DirName);

            if (!String.IsNullOrEmpty(dirname))
                dataSet.Append(dirname, Input.Direction.ToLowerInvariant(), "Direction");
        }
Beispiel #7
0
        internal override void ConstructDataSet(FormDataSet dataSet, IHtmlElement submitter)
        {
            var type = Type;

            if (Object.ReferenceEquals(this, submitter) && type.IsOneOf(InputTypeNames.Submit, InputTypeNames.Reset))
            {
                dataSet.Append(Name, Value, type);
            }
        }
Beispiel #8
0
        protected void ConstructDataSet(FormDataSet dataSet, String type)
        {
            dataSet.Append(Name, Value, type);
            var dirname = this.GetOwnAttribute(AttributeNames.DirName);

            if (!String.IsNullOrEmpty(dirname))
            {
                dataSet.Append(dirname, Direction.ToString().ToLowerInvariant(), "Direction");
            }
        }
Beispiel #9
0
        public override void ConstructDataSet(FormDataSet dataSet)
        {
            base.ConstructDataSet(dataSet);
            var dirname = Input.GetAttribute(null, AttributeNames.DirName);

            if (!String.IsNullOrEmpty(dirname))
            {
                dataSet.Append(dirname, Input.Direction.ToLowerInvariant(), "Direction");
            }
        }
Beispiel #10
0
        public override void ConstructDataSet(FormDataSet dataSet)
        {
            var name = Input.Name;
            var value = Input.Value;

            dataSet.Append(name + ".x", "0", Input.Type);
            dataSet.Append(name + ".y", "0", Input.Type);

            if (!String.IsNullOrEmpty(value))
                dataSet.Append(name, value, Input.Type);
        }
Beispiel #11
0
        private static byte[] ApplicationJsonEncode(FormDataSet formDataSet)
        {
            //1. Let resulting object be a new Object.
            var resultingObject = new JsonObject();

            //2. For each entry in the form data set, perform these substeps:
            foreach (var entry in formDataSet._entries)
            {
                //2.1. If the entry's type is file, set the is file flag.
                bool isFile = entry is FileDataSetEntry;

                TextDataSetEntry text = entry as TextDataSetEntry;
                FileDataSetEntry file = entry as FileDataSetEntry;
                JsonValue entryValue;
                if (text != null)
                {
                    entryValue = new JsonValue(text.Value);
                }
                else
                {
                    var stream = file.Value.Body;
                    MemoryStream ms = stream as MemoryStream;
                    if (ms == null)
                    {
                        ms = new MemoryStream();
                        stream.CopyTo(ms);
                    }
                    entryValue = new JsonValue(Convert.ToBase64String(ms.ToArray()));
                }

                //2.2. Let steps be the result of running the steps to parse a JSON encoding path on the entry's name.
                List<Step> steps = ParseJSONPath(entry.Name);

                //2.3. Let context be set to the value of resulting object.
                JsonElement context = resultingObject;

                //2.4. For each step in the list of steps, run the following subsubsteps:
                foreach (var step in steps)
                {
                    //2.4.1. Let the current value be the value obtained by getting the step's key from the current context.
                    JsonElement currentValue = context[step.Key];

                    //2.4.2. Run the steps to set a JSON encoding value with the current context, the step, the current value, the entry's value, and the is file flag.
                    //2.4.3. Update context to be the value returned by the steps to set a JSON encoding value ran above.
                    context = JsonEncodeValue(context, step, currentValue, entryValue, isFile);
                }
            }

            //3. Let result be the value returned from calling the stringify operation with resulting object as its first parameter and the two remaining parameters left undefined.
            string result = Stringify(resultingObject);

            //4. Encode result as UTF - 8 and return the resulting byte stream.
            return Encoding.UTF8.GetBytes(result);
        }
Beispiel #12
0
        public override void ConstructDataSet(FormDataSet dataSet)
        {
            if (Input.IsChecked)
            {
                var value = Keywords.On;

                if (!String.IsNullOrEmpty(Input.Value))
                    value = Input.Value;

                dataSet.Append(Input.Name, value, Input.Type);
            }
        }
Beispiel #13
0
        public override void ConstructDataSet(FormDataSet dataSet)
        {
            if (_files.Length == 0)
            {
                dataSet.Append(Input.Name, String.Empty, MimeTypes.Binary);
            }

            foreach (var file in _files)
            {
                dataSet.Append(Input.Name, file, Input.Type);
            }
        }
Beispiel #14
0
        internal override void ConstructDataSet(FormDataSet dataSet, HtmlElement submitter)
        {
            for (int i = 0; i < _options.Length; i++)
            {
                var option = _options.GetOptionAt(i);

                if (option.IsSelected && !option.IsDisabled)
                {
                    dataSet.Append(Name, option.Value, Type);
                }
            }
        }
        public override void ConstructDataSet(FormDataSet dataSet)
        {
            if (_files.Length == 0)
            {
                dataSet.Append(Input.Name, default(IFile), Input.Type);
            }

            foreach (var file in _files)
            {
                dataSet.Append(Input.Name, file, Input.Type);
            }
        }
Beispiel #16
0
        public override void ConstructDataSet(FormDataSet dataSet)
        {
            var name  = Input.Name;
            var value = Input.Value;

            dataSet.Append(name + ".x", "0", Input.Type);
            dataSet.Append(name + ".y", "0", Input.Type);

            if (!String.IsNullOrEmpty(value))
            {
                dataSet.Append(name !, value, Input.Type);
            }
        }
        public override void ConstructDataSet(FormDataSet dataSet)
        {
            if (!String.IsNullOrEmpty(Input.Name))
            {
                var name = String.Empty;

                if (!String.IsNullOrEmpty(Input.Value))
                    name = Input.Value + ".";

                dataSet.Append(name + "x", "0", Input.Type);
                dataSet.Append(name + "y", "0", Input.Type);
            }
        }
Beispiel #18
0
        FormDataSet ConstructDataSet(IHtmlElement submitter)
        {
            var formDataSet = new FormDataSet();

            foreach (var field in Elements)
            {
                if (field.ParentElement is IHtmlDataListElement == false && field.IsDisabled == false)
                {
                    field.ConstructDataSet(formDataSet, submitter);
                }
            }

            return(formDataSet);
        }
Beispiel #19
0
        public override void ConstructDataSet(FormDataSet dataSet)
        {
            if (Input.IsChecked)
            {
                var value = Keywords.On;

                if (!String.IsNullOrEmpty(Input.Value))
                {
                    value = Input.Value;
                }

                dataSet.Append(Input.Name, value, Input.Type);
            }
        }
Beispiel #20
0
        /// <summary>
        /// Constucts the data set (called from a form).
        /// </summary>
        /// <param name="dataSet">The dataset to construct.</param>
        /// <param name="submitter">The given submitter.</param>
        internal override void ConstructDataSet(FormDataSet dataSet, HtmlElement submitter)
        {
            if (this == submitter)
            {
                return;
            }

            var type = Type.ToEnum(ButtonType.Submit);

            if (type == ButtonType.Submit || type == ButtonType.Reset)
            {
                dataSet.Append(Name, Value, Type.ToString());
            }
        }
        private FormDataSet ConstructDataSet(IHtmlElement submitter)
        {
            var formDataSet = new FormDataSet();
            var fields      = this.GetNodes <HtmlFormControlElement>();

            foreach (var field in fields)
            {
                if (!field.IsDisabled && field.ParentElement is IHtmlDataListElement == false && Object.ReferenceEquals(field.Form, this))
                {
                    field.ConstructDataSet(formDataSet, submitter);
                }
            }

            return(formDataSet);
        }
Beispiel #22
0
        public override void ConstructDataSet(FormDataSet dataSet)
        {
            if (!String.IsNullOrEmpty(Input.Name))
            {
                var name = String.Empty;

                if (!String.IsNullOrEmpty(Input.Value))
                {
                    name = Input.Value + ".";
                }

                dataSet.Append(name + "x", "0", Input.Type);
                dataSet.Append(name + "y", "0", Input.Type);
            }
        }
Beispiel #23
0
        /// <summary>
        /// Creates a POST request for the given target with the fields being
        /// used to generate the body and encoding type plaintext.
        /// </summary>
        /// <param name="target">The target to use.</param>
        /// <param name="fields">The fields to send.</param>
        /// <returns>The new document request.</returns>
        public static DocumentRequest PostAsPlaintext(Url target, IDictionary <String, String> fields)
        {
            if (fields == null)
            {
                throw new ArgumentNullException("fields");
            }

            var fds = new FormDataSet();

            foreach (var field in fields)
            {
                fds.Append(field.Key, field.Value, InputTypeNames.Text);
            }

            return(Post(target, fds.AsPlaintext(), MimeTypes.Plain));
        }
        public static ResponseCollection ClearItemDataResponse(
            Context context, SiteSettings ss, long id)
        {
            var formDataSet = new FormDataSet(
                context: context,
                ss: ss);
            var res = new ResponseCollection().ClearFormData("Id");

            formDataSet
            .Where(o => !o.Suffix.IsNullOrEmpty())
            .Where(o => o.Id == id)
            .ForEach(formData =>
                     formData.Data.Keys.ForEach(controlId =>
                                                res.ClearFormData(controlId + formData.Suffix)));
            return(res);
        }
Beispiel #25
0
        public static Stream Encode(FormDataSet formDataSet, Encoding[] supportedEncodings, string acceptCharset, Encoding documentEncoding)
        {
            var result = new StringBuilder();

            var selectedEncoding = SelectEncoding(formDataSet, supportedEncodings, acceptCharset, documentEncoding);

            var charset = GetPreferredMimeName(selectedEncoding);

            var entryIndex = -1;

            foreach (var entry in formDataSet)
            {
                SubSteps(entry, entryIndex++, selectedEncoding, ref result);
            }

            return(new MemoryStream(Encoding.ASCII.GetBytes(result.ToString())));
        }
Beispiel #26
0
        static Stream CreateBody(String enctype, Encoding encoding, FormDataSet formDataSet)
        {
            if (enctype.Equals(MimeTypes.UrlencodedForm, StringComparison.OrdinalIgnoreCase))
            {
                return(formDataSet.AsUrlEncoded(encoding));
            }
            else if (enctype.Equals(MimeTypes.MultipartForm, StringComparison.OrdinalIgnoreCase))
            {
                return(formDataSet.AsMultipart(encoding));
            }
            else if (enctype.Equals(MimeTypes.Plain, StringComparison.OrdinalIgnoreCase))
            {
                return(formDataSet.AsPlaintext(encoding));
            }

            return(MemoryStream.Null);
        }
Beispiel #27
0
        public override void ConstructDataSet(FormDataSet dataSet)
        {
            if (!String.IsNullOrEmpty(Input.Name))
            {
                var name = String.Empty;

                if (!String.IsNullOrEmpty(Input.Value))
                {
                    name = Input.Value + ".";
                }

                var namex = name + "x";
                var namey = name + "y";

                //TODO get x and y of submitter and save those
                dataSet.Append(namex, "0", Input.Type);
                dataSet.Append(namey, "0", Input.Type);
            }
        }
Beispiel #28
0
        /// <summary>
        /// Constructs the form data set with the given submitter.
        /// </summary>
        /// <param name="submitter">[Optional] The submitter to use.</param>
        /// <returns>The constructed form data set.</returns>
        FormDataSet ConstructDataSet(HtmlElement submitter = null)
        {
            var formDataSet = new FormDataSet();

            foreach (var field in Elements)
            {
                if (field.ParentElement is IHtmlDataListElement)
                {
                    continue;
                }
                else if (field.IsDisabled)
                {
                    continue;
                }

                field.ConstructDataSet(formDataSet, submitter);
            }

            return(formDataSet);
        }
        public static Stream CreateBody(this FormDataSet formDataSet, String enctype, Encoding encoding)
        {
            if (enctype.Isi(MimeTypeNames.UrlencodedForm))
            {
                return(formDataSet.AsUrlEncoded(encoding));
            }
            else if (enctype.Isi(MimeTypeNames.MultipartForm))
            {
                return(formDataSet.AsMultipart(encoding));
            }
            else if (enctype.Isi(MimeTypeNames.Plain))
            {
                return(formDataSet.AsPlaintext(encoding));
            }
            else if (enctype.Isi(MimeTypeNames.ApplicationJson))
            {
                return(formDataSet.AsJson());
            }

            return(MemoryStream.Null);
        }
Beispiel #30
0
        private static Encoding SelectEncoding(FormDataSet formDataSet, IEnumerable <Encoding> supportedEncodings, string acceptCharset, Encoding documentEncoding)
        {
            if (acceptCharset != null)
            {
                string[] tokens = Html5Utility.SplitStringOnSpaces(acceptCharset);

                var encodings = tokens.Select(Encoding.GetEncoding)
                                .Where(e => e != null)
                                .Where(e => supportedEncodings == null || supportedEncodings.Any(se => e.GetType() == se.GetType()))
                                .Where(IsAsciiCompatible);

                return(encodings.FirstOrDefault() ?? Encoding.UTF8);
            }
            else if (IsAsciiCompatible(documentEncoding))
            {
                return(documentEncoding);
            }
            else
            {
                return(Encoding.UTF8);
            }
        }
Beispiel #31
0
 public static HtmlBuilder GridRows(
     this HtmlBuilder hb,
     Context context,
     SiteSettings ss,
     List <Column> columns,
     EnumerableRowCollection <DataRow> dataRows,
     FormDataSet formDataSet = null,
     bool editRow            = false,
     bool checkRow           = true)
 {
     dataRows.ForEach(dataRow =>
                      hb.Tr(
                          context: context,
                          ss: ss,
                          columns: columns,
                          dataRow: dataRow,
                          recordSelector: new RecordSelector(context),
                          editRow: editRow,
                          checkRow: checkRow,
                          idColumn: Rds.IdColumn(ss.ReferenceType),
                          formDataSet: formDataSet));
     return(hb);
 }
        FormDataSet ConstructDataSet(IHtmlElement submitter)
        {
            var formDataSet = new FormDataSet();
            var fields = this.GetElements<HtmlFormControlElement>();

            foreach (var field in fields)
            {
                if (!field.IsDisabled && field.ParentElement is IHtmlDataListElement == false && Object.ReferenceEquals(field.Form, this))
                {
                    field.ConstructDataSet(formDataSet, submitter);
                }
            }

            return formDataSet;
        }
Beispiel #33
0
 /// <summary>
 /// Constucts the data set (called from a form).
 /// </summary>
 /// <param name="dataSet">The dataset to construct.</param>
 /// <param name="submitter">The given submitter.</param>
 internal override void ConstructDataSet(FormDataSet dataSet, HtmlElement submitter)
 {
     ConstructDataSet(dataSet, Type);
 }
Beispiel #34
0
 static void Example5()
 {
     FormDataSet set = new FormDataSet();
     set.Append("pet[0][species]", "Dahut", "text");
     set.Append("pet[0][name]", "Hypatia", "text");
     set.Append("pet[1][species]", "Felis Stultus", "text");
     set.Append("pet[1][name]", "Billie", "text");
     var result = Encoding.UTF8.GetString(ApplicationJsonEncode(set));
     Debug.Assert("{\"pet\":[{\"species\":\"Dahut\",\"name\":\"Hypatia\"},{\"species\":\"Felis Stultus\",\"name\":\"Billie\"}]}" == result);
 }
        public static Stream CreateBody(this FormDataSet formDataSet, String enctype, String charset)
        {
            var encoding = TextEncoding.Resolve(charset);

            return(formDataSet.CreateBody(enctype, encoding));
        }
Beispiel #36
0
        internal override void ConstructDataSet(FormDataSet dataSet, HTMLElement submitter)
        {
            var options = _options.Elements;

            foreach (var option in options)
            {
                if (option.Selected && !option.Disabled)
                    dataSet.Append(Name, option.Value, Multiple ? "select-one" : "select-multiple");
            }
        }
Beispiel #37
0
 static void Example8()
 {
     FormDataSet set = new FormDataSet();
     set.Append("highlander[]", "one", "text");
     var result = Encoding.UTF8.GetString(ApplicationJsonEncode(set));
     Debug.Assert("{\"highlander\":[\"one\"]}" == result);
 }
        protected void ConstructDataSet(FormDataSet dataSet, String type)
        {
            dataSet.Append(Name, Value, type);
            var dirname = this.GetOwnAttribute(AttributeNames.DirName);

            if (!String.IsNullOrEmpty(dirname))
                dataSet.Append(dirname, Direction.ToString().ToLowerInvariant(), "Direction");
        }
Beispiel #39
0
        static Stream CreateBody(String enctype, Encoding encoding, FormDataSet formDataSet)
        {
            if (enctype.Equals(MimeTypes.UrlencodedForm, StringComparison.OrdinalIgnoreCase))
                return formDataSet.AsUrlEncoded(encoding);
            else if (enctype.Equals(MimeTypes.MultipartForm, StringComparison.OrdinalIgnoreCase))
                return formDataSet.AsMultipart(encoding);
            else if (enctype.Equals(MimeTypes.Plain, StringComparison.OrdinalIgnoreCase))
                return formDataSet.AsPlaintext(encoding);
            else if (enctype.Equals(MimeTypes.ApplicationJson, StringComparison.OrdinalIgnoreCase))
                return formDataSet.AsJson();

            return MemoryStream.Null;
        }
Beispiel #40
0
        public static Stream CreateBody(this FormDataSet formDataSet, String enctype, String?charset, IHtmlEncoder?htmlEncoder)
        {
            var encoding = TextEncoding.Resolve(charset);

            return(formDataSet.CreateBody(enctype, encoding, htmlEncoder ?? new DefaultHtmlEncoder()));
        }
Beispiel #41
0
        /// <summary>
        /// Creates a POST request for the given target with the fields being
        /// used to generate the body and encoding type multipart.
        /// </summary>
        /// <param name="target">The target to use.</param>
        /// <param name="fields">The fields to send.</param>
        /// <returns>The new document request.</returns>
        public static DocumentRequest PostAsMultipart(Url target, IDictionary<String, object> fields)
        {
            if (fields == null)
                throw new ArgumentNullException("fields");

            var fds = new FormDataSet();

            foreach (var field in fields)
            {
                if (field.Value is AngleSharp.Dom.Io.IFile)
                    fds.Append(field.Key, (AngleSharp.Dom.Io.IFile)field.Value, InputTypeNames.File);
                else
                    fds.Append(field.Key, (String)field.Value, InputTypeNames.Text);
            }

            var enctype = String.Concat(MimeTypes.MultipartForm, "; boundary=", fds.Boundary);
            return Post(target, fds.AsMultipart(), enctype);
        }
Beispiel #42
0
 /// <summary>
 /// Constucts the data set (called from a form).
 /// </summary>
 /// <param name="dataSet">The dataset to construct.</param>
 /// <param name="submitter">The given submitter.</param>
 internal virtual void ConstructDataSet(FormDataSet dataSet, HtmlElement submitter)
 {
 }
Beispiel #43
0
 internal override void ConstructDataSet(FormDataSet dataSet, IHtmlElement submitter)
 {
     if (_type.IsAppendingData(submitter))
     {
         _type.ConstructDataSet(dataSet);
     }
 }
Beispiel #44
0
        internal override void ConstructDataSet(FormDataSet dataSet, IHtmlElement submitter)
        {
            var options = Options;

            for (int i = 0; i < options.Length; i++)
            {
                var option = options.GetOptionAt(i);

                if (option.IsSelected && !option.IsDisabled)
                    dataSet.Append(Name, option.Value, Type);
            }
        }
Beispiel #45
0
        /// <summary>
        /// Constucts the data set (called from a form).
        /// </summary>
        /// <param name="dataSet">The dataset to construct.</param>
        /// <param name="submitter">The given submitter.</param>
        internal override void ConstructDataSet(FormDataSet dataSet, HTMLElement submitter)
        {
            switch (Type)
            {
                case InputType.Radio:
                case InputType.Checkbox:
                {
                    if (Checked)
                    {
                        var value = "on";

                        if (!String.IsNullOrEmpty(Value))
                            value = Value;

                        dataSet.Append(Name, value, Type.ToString());
                    }

                    break;
                }
                case InputType.Image:
                {
                    if (!String.IsNullOrEmpty(Name))
                    {
                        var name = String.Empty;

                        if (!String.IsNullOrEmpty(Value))
                            name = Value + ".";

                        var namex = name + "x";
                        var namey = name + "y";

                        //TODO get x and y of submitter and save those
                        dataSet.Append(namex, "0", Type.ToString());
                        dataSet.Append(namey, "0", Type.ToString());
                    }

                    break;
                }
                case InputType.File:
                {
                    if(_files.Length == 0)
                        dataSet.Append(Name, String.Empty, "application/octet-stream");

                    foreach (var file in _files)
                        dataSet.Append(Name, file, Type.ToString());

                    break;
                }
                case InputType.Text:
                case InputType.Search:
                {
                    dataSet.Append(Name, Value, Type.ToString());

                    if (_attributes[AttributeNames.DIRNAME] != null)
                    {
                        var dirname = _attributes[AttributeNames.DIRNAME].Value;

                        if (String.IsNullOrEmpty(dirname))
                            break;

                        dataSet.Append(dirname, Dir.ToString().ToLower(), "Direction");
                    }

                    break;
                }
                default:
                {
                    dataSet.Append(Name, Value, Type.ToString());
                    break;
                }
            }
        }
        static Stream CreateBody(String enctype, Encoding encoding, FormDataSet formDataSet)
        {
            if (enctype.Isi(MimeTypeNames.UrlencodedForm))
            {
                return formDataSet.AsUrlEncoded(encoding);
            }
            else if (enctype.Isi(MimeTypeNames.MultipartForm))
            {
                return formDataSet.AsMultipart(encoding);
            }
            else if (enctype.Isi(MimeTypeNames.Plain))
            {
                return formDataSet.AsPlaintext(encoding);
            }
            else if (enctype.Isi(MimeTypeNames.ApplicationJson))
            {
                return formDataSet.AsJson();
            }

            return MemoryStream.Null;
        }
Beispiel #47
0
        /// <summary>
        /// Constucts the data set (called from a form).
        /// </summary>
        /// <param name="dataSet">The dataset to construct.</param>
        /// <param name="submitter">The given submitter.</param>
        internal override void ConstructDataSet(FormDataSet dataSet, HTMLElement submitter)
        {
            dataSet.Append(Name, Value, Type.ToString());

            if (_attributes[AttributeNames.DIRNAME] != null)
            {
                var dirname = _attributes[AttributeNames.DIRNAME].Value;

                if (String.IsNullOrEmpty(dirname))
                    return;

                dataSet.Append(dirname, Dir.ToString().ToLower(), "Direction");
            }
        }
 /// <summary>
 /// Constucts the data set (called from a form).
 /// </summary>
 /// <param name="dataSet">The dataset to construct.</param>
 /// <param name="submitter">The given submitter.</param>
 internal override void ConstructDataSet(FormDataSet dataSet, IHtmlElement submitter)
 {
     ConstructDataSet(dataSet, Type);
 }
Beispiel #49
0
        FormDataSet ConstructDataSet(HTMLElement submitter = null)
        {
            var formDataSet = new FormDataSet();
            var fields = _elements.Elements;

            foreach (var field in fields)
            {
                if (field.ParentElement is HTMLDataListElement)
                    continue;
                else if (field.Disabled)
                    continue;

                field.ConstructDataSet(formDataSet, submitter);
            }

            return formDataSet;
        }
Beispiel #50
0
 /// <summary>
 /// Constucts the data set (called from a form).
 /// </summary>
 /// <param name="dataSet">The dataset to construct.</param>
 /// <param name="submitter">The given submitter.</param>
 internal override void ConstructDataSet(FormDataSet dataSet, HTMLElement submitter)
 {
     if (this == submitter)
         return;
     else if (Type == ButtonType.Submit || Type == ButtonType.Reset)
         dataSet.Append(Name, Value, Type.ToString());
 }
Beispiel #51
0
 static void Example7()
 {
     FormDataSet set = new FormDataSet();
     set.Append("mix", "scalar", "text");
     set.Append("mix[0]", "array 1", "text");
     set.Append("mix[2]", "array 2", "text");
     set.Append("mix[key]", "key key", "text");
     set.Append("mix[car]", "car key", "text");
     var result = Encoding.UTF8.GetString(ApplicationJsonEncode(set));
     Debug.Assert("{\"mix\":{\"\":\"scalar\",\"0\":\"array 1\",\"2\":\"array 2\",\"key\":\"key key\",\"car\":\"car key\"}}" == result);
 }
Beispiel #52
0
 static void Example6()
 {
     FormDataSet set = new FormDataSet();
     set.Append("wow[such][deep][3][much][power][!]", "Amaze", "text");
     var result = Encoding.UTF8.GetString(ApplicationJsonEncode(set));
     Debug.Assert("{\"wow\":{\"such\":{\"deep\":[null,null,null,{\"much\":{\"power\":{\"!\":\"Amaze\"}}}]}}}" == result);
 }
Beispiel #53
0
        /// <summary>
        /// Creates a POST request for the given target with the fields being
        /// used to generate the body and encoding type plaintext.
        /// </summary>
        /// <param name="target">The target to use.</param>
        /// <param name="fields">The fields to send.</param>
        /// <returns>The new document request.</returns>
        public static DocumentRequest PostAsPlaintext(Url target, IDictionary<String, String> fields)
        {
            if (fields == null)
                throw new ArgumentNullException(nameof(fields));

            var fds = new FormDataSet();

            foreach (var field in fields)
            {
                fds.Append(field.Key, field.Value, InputTypeNames.Text);
            }

            return Post(target, fds.AsPlaintext(), MimeTypeNames.Plain);
        }
Beispiel #54
0
 public virtual void ConstructDataSet(FormDataSet dataSet)
 {
     dataSet.Append(_input.Name, _input.Value, _input.Type);
 }
Beispiel #55
0
        /// <summary>
        /// Creates a POST request for the given target with the fields being
        /// used to generate the body and encoding type url encoded.
        /// </summary>
        /// <param name="target">The target to use.</param>
        /// <param name="fields">The fields to send.</param>
        /// <returns>The new document request.</returns>
        public static DocumentRequest PostAsUrlencoded(Url target, IDictionary<String, String> fields)
        {
            if (fields == null)
                throw new ArgumentNullException("fields");

            var fds = new FormDataSet();

            foreach (var field in fields)
                fds.Append(field.Key, field.Value, InputTypeNames.Text);

            return Post(target, fds.AsUrlEncoded(), MimeTypes.UrlencodedForm);
        }
Beispiel #56
0
 public virtual void ConstructDataSet(FormDataSet dataSet)
 {
     dataSet.Append(_input.Name, _input.Value, _input.Type);
 }
 internal virtual void ConstructDataSet(FormDataSet dataSet, IHtmlElement submitter)
 { }
        public static HtmlBuilder Tr(
            this HtmlBuilder hb,
            Context context,
            SiteSettings ss,
            DataRow dataRow,
            IEnumerable <Column> columns,
            bool editRow,
            bool checkRow,
            string idColumn,
            RecordSelector recordSelector = null,
            FormDataSet formDataSet       = null)
        {
            var dataId      = dataRow.Long(idColumn);
            var dataVersion = dataRow.Int("Ver");
            var isHistory   = dataRow.Bool("IsHistory");
            var EditColumns = !isHistory
                ? columns.ToDictionary(
                column => column.ColumnName,
                column => EditColumn(
                    context: context,
                    column: column))
                : new Dictionary <string, bool>();

            BaseItemModel rowModel = null;

            switch (ss.ReferenceType)
            {
            case "Issues":
                var issueModel = new IssueModel(
                    context: context,
                    ss: ss,
                    dataRow: dataRow,
                    formData: editRow
                            ? formDataSet?.FirstOrDefault(o =>
                                                          o.Id == dataRow.Long("IssueId"))?.Data
                            : null);
                ss.SetColumnAccessControls(
                    context: context,
                    mine: issueModel.Mine(context: context));
                rowModel = issueModel;
                break;

            case "Results":
                var resultModel = new ResultModel(
                    context: context,
                    ss: ss,
                    dataRow: dataRow,
                    formData: editRow
                            ? formDataSet?.FirstOrDefault(o =>
                                                          o.Id == dataRow.Long("ResultId"))?.Data
                            : null);
                ss.SetColumnAccessControls(
                    context: context,
                    mine: resultModel.Mine(context: context));
                rowModel = resultModel;
                break;
            }
            ;
            var serverScriptRowValues = rowModel?.SetByBeforeOpeningPageServerScript(
                context: context,
                ss: ss);
            var extendedRowCss = serverScriptRowValues?.ExtendedRowCss;

            extendedRowCss = extendedRowCss.IsNullOrEmpty() ? string.Empty : " " + extendedRowCss;
            return(hb.Tr(
                       attributes: new HtmlAttributes()
                       .Class("grid-row" + extendedRowCss)
                       .DataId(dataId.ToString())
                       .DataVer(dataVersion)
                       .DataLatest(1, _using: !isHistory)
                       .Add(name: "data-history", value: "1", _using: isHistory)
                       .Add(name: "data-locked", value: "1", _using: dataRow.Bool("Locked")),
                       action: () =>
            {
                if (editRow)
                {
                    hb.Td(action: () => hb
                          .Button(
                              title: Displays.Reload(context: context),
                              controlCss: "button-icon",
                              onClick: $"$p.getData($(this)).Id={dataId};$p.send($(this));",
                              icon: "ui-icon-refresh",
                              action: "ReloadRow",
                              method: "post",
                              _using: !isHistory)
                          .Button(
                              title: Displays.Copy(context: context),
                              controlCss: "button-icon",
                              onClick: $"$p.getData($(this)).OriginalId={dataId};$p.send($(this));",
                              icon: "ui-icon-copy",
                              action: "CopyRow",
                              method: "post",
                              _using: !isHistory && context.CanCreate(ss: ss))
                          .Hidden(
                              controlId: $"{ss.ReferenceType}_Timestamp_{ss.SiteId}_{dataId}",
                              css: "timestamp",
                              value: dataRow
                              .Field <DateTime>("UpdatedTime")
                              .ToString("yyyy/M/d H:m:s.fff")));
                }
                else if (checkRow)
                {
                    hb.Td(action: () => hb
                          .CheckBox(
                              controlCss: "grid-check",
                              _checked: recordSelector.Checked(dataId),
                              dataId: dataId.ToString(),
                              _using: !isHistory));
                }
                var depts = new Dictionary <string, DeptModel>();
                var groups = new Dictionary <string, GroupModel>();
                var registrations = new Dictionary <string, RegistrationModel>();
                var users = new Dictionary <string, UserModel>();
                var sites = new Dictionary <string, SiteModel>();
                var issues = new Dictionary <string, IssueModel>();
                var results = new Dictionary <string, ResultModel>();
                ServerScriptModelRow serverScriptValues = null;
                columns.ForEach(column =>
                {
                    var key = column.TableName();
                    switch (column.SiteSettings?.ReferenceType)
                    {
                    case "Depts":
                        var deptModel = depts.Get(key);
                        if (deptModel == null)
                        {
                            deptModel = new DeptModel(
                                context: context,
                                ss: column.SiteSettings,
                                dataRow: dataRow,
                                tableAlias: column.TableAlias);
                            depts.Add(key, deptModel);
                            ss.SetColumnAccessControls(
                                context: context,
                                mine: deptModel.Mine(context: context));
                            serverScriptValues = deptModel.SetByBeforeOpeningPageServerScript(
                                context: context,
                                ss: ss);
                        }
                        hb.TdValue(
                            context: context,
                            ss: column.SiteSettings,
                            column: column,
                            deptModel: deptModel);
                        break;

                    case "Groups":
                        var groupModel = groups.Get(key);
                        if (groupModel == null)
                        {
                            groupModel = new GroupModel(
                                context: context,
                                ss: column.SiteSettings,
                                dataRow: dataRow,
                                tableAlias: column.TableAlias);
                            groups.Add(key, groupModel);
                            ss.SetColumnAccessControls(
                                context: context,
                                mine: groupModel.Mine(context: context));
                            serverScriptValues = groupModel.SetByBeforeOpeningPageServerScript(
                                context: context,
                                ss: ss);
                        }
                        hb.TdValue(
                            context: context,
                            ss: column.SiteSettings,
                            column: column,
                            groupModel: groupModel);
                        break;

                    case "Registrations":
                        var registrationModel = registrations.Get(key);
                        if (registrationModel == null)
                        {
                            registrationModel = new RegistrationModel(
                                context: context,
                                ss: column.SiteSettings,
                                dataRow: dataRow,
                                tableAlias: column.TableAlias);
                            registrations.Add(key, registrationModel);
                            ss.SetColumnAccessControls(
                                context: context,
                                mine: registrationModel.Mine(context: context));
                            serverScriptValues = registrationModel.SetByBeforeOpeningPageServerScript(
                                context: context,
                                ss: ss);
                        }
                        hb.TdValue(
                            context: context,
                            ss: column.SiteSettings,
                            column: column,
                            registrationModel: registrationModel);
                        break;

                    case "Users":
                        var userModel = users.Get(key);
                        if (userModel == null)
                        {
                            userModel = new UserModel(
                                context: context,
                                ss: column.SiteSettings,
                                dataRow: dataRow,
                                tableAlias: column.TableAlias);
                            users.Add(key, userModel);
                            ss.SetColumnAccessControls(
                                context: context,
                                mine: userModel.Mine(context: context));
                            serverScriptValues = userModel.SetByBeforeOpeningPageServerScript(
                                context: context,
                                ss: ss);
                        }
                        hb.TdValue(
                            context: context,
                            ss: column.SiteSettings,
                            column: column,
                            userModel: userModel);
                        break;

                    case "Sites":
                        var siteModel = sites.Get(key);
                        if (siteModel == null)
                        {
                            siteModel = new SiteModel(
                                context: context,
                                dataRow: dataRow,
                                formData: editRow
                                            ? formDataSet?.FirstOrDefault(o =>
                                                                          o.Id == dataRow.Long("SiteId"))?.Data
                                            : null,
                                tableAlias: column.TableAlias);
                            sites.Add(key, siteModel);
                            ss.SetColumnAccessControls(
                                context: context,
                                mine: siteModel.Mine(context: context));
                            serverScriptValues = siteModel.SetByBeforeOpeningPageServerScript(
                                context: context,
                                ss: ss);
                        }
                        hb.TdValue(
                            context: context,
                            ss: column.SiteSettings,
                            column: column,
                            siteModel: siteModel);
                        break;

                    case "Issues":
                        var issueModel = issues.Get(key);
                        if (issueModel == null)
                        {
                            issueModel = new IssueModel(
                                context: context,
                                ss: column.SiteSettings,
                                dataRow: dataRow,
                                formData: editRow
                                            ? formDataSet?.FirstOrDefault(o =>
                                                                          o.Id == dataRow.Long("IssueId"))?.Data
                                            : null,
                                tableAlias: column.TableAlias);
                            issues.Add(key, issueModel);
                            ss.SetColumnAccessControls(
                                context: context,
                                mine: issueModel.Mine(context: context));
                            serverScriptValues = issueModel.SetByBeforeOpeningPageServerScript(
                                context: context,
                                ss: ss);
                        }
                        if (!issueModel.Locked && EditColumns.Get(column.ColumnName) && column.CanUpdate(baseModel: issueModel))
                        {
                            hb.Td(
                                css: column.TextAlign == SiteSettings.TextAlignTypes.Right
                                            ? " right-align"
                                            : string.Empty,
                                action: () => hb.Field(
                                    context: context,
                                    column: column,
                                    issueModel: issueModel,
                                    ss: column.SiteSettings,
                                    controlOnly: true,
                                    idSuffix: issueModel.IdSuffix()));
                        }
                        else
                        {
                            hb.TdValue(
                                context: context,
                                ss: column.SiteSettings,
                                column: column,
                                issueModel: issueModel,
                                serverScriptValues: serverScriptValues
                                ?.Columns
                                ?.Get(column?.ColumnName));
                        }
                        break;

                    case "Results":
                        var resultModel = results.Get(key);
                        if (resultModel == null)
                        {
                            resultModel = new ResultModel(
                                context: context,
                                ss: column.SiteSettings,
                                dataRow: dataRow,
                                formData: editRow
                                            ? formDataSet?.FirstOrDefault(o =>
                                                                          o.Id == dataRow.Long("ResultId"))?.Data
                                            : null,
                                tableAlias: column.TableAlias);
                            results.Add(key, resultModel);
                            ss.SetColumnAccessControls(
                                context: context,
                                mine: resultModel.Mine(context: context));
                            serverScriptValues = resultModel.SetByBeforeOpeningPageServerScript(
                                context: context,
                                ss: ss);
                        }
                        if (!resultModel.Locked && EditColumns.Get(column.ColumnName) && column.CanUpdate(baseModel: resultModel))
                        {
                            hb.Td(
                                css: column.TextAlign == SiteSettings.TextAlignTypes.Right
                                            ? " right-align"
                                            : string.Empty,
                                action: () => hb.Field(
                                    context: context,
                                    column: column,
                                    resultModel: resultModel,
                                    ss: column.SiteSettings,
                                    controlOnly: true,
                                    idSuffix: resultModel.IdSuffix()));
                        }
                        else
                        {
                            hb.TdValue(
                                context: context,
                                ss: column.SiteSettings,
                                column: column,
                                resultModel: resultModel,
                                serverScriptValues: serverScriptValues
                                ?.Columns
                                ?.Get(column?.ColumnName));
                        }
                        break;
                    }
                });
            }));
        }
Beispiel #59
0
        /// <summary>
        /// Constucts the data set (called from a form).
        /// </summary>
        /// <param name="dataSet">The dataset to construct.</param>
        /// <param name="submitter">The given submitter.</param>
        internal override void ConstructDataSet(FormDataSet dataSet, IHtmlElement submitter)
        {
            var type = Type;

            if (Object.ReferenceEquals(this, submitter) && type.IsOneOf(InputTypeNames.Submit, InputTypeNames.Reset))
                dataSet.Append(Name, Value, type);
        }