예제 #1
0
        public static string RemoveQuotesForJavaScriptMethods(string input, JQGrid grid)
        {
            string str = input;

            foreach (JQGridColumn column in grid.Columns)
            {
                if (column.Formatter != null)
                {
                    JQGridColumnFormatter formatter = column.Formatter;
                    if (formatter is CustomFormatter)
                    {
                        CustomFormatter formatter2 = (CustomFormatter)formatter;
                        string          oldValue   = string.Format("\"formatter\":\"{0}\"", formatter2.FormatFunction);
                        string          newValue   = string.Format("\"formatter\":{0}", formatter2.FormatFunction);
                        str      = str.Replace(oldValue, newValue);
                        oldValue = string.Format("\"unformat\":\"{0}\"", formatter2.UnFormatFunction);
                        newValue = string.Format("\"unformat\":{0}", formatter2.UnFormatFunction);
                        str      = str.Replace(oldValue, newValue);
                    }
                }
                foreach (JQGridEditClientSideValidator validator in column.EditClientSideValidators)
                {
                    if (validator is CustomValidator)
                    {
                        CustomValidator validator2 = (CustomValidator)validator;
                        string          str4       = string.Format("\"custom_func\":\"{0}\"", validator2.ValidationFunction);
                        string          str5       = string.Format("\"custom_func\":{0}", validator2.ValidationFunction);
                        str = str.Replace(str4, str5);
                    }
                }
                if (column.EditType == EditType.Custom)
                {
                    string str6 = string.Format("\"custom_element\":\"{0}\"", column.EditTypeCustomCreateElement);
                    string str7 = string.Format("\"custom_element\":{0}", column.EditTypeCustomCreateElement);
                    str  = str.Replace(str6, str7);
                    str6 = string.Format("\"custom_value\":\"{0}\"", column.EditTypeCustomGetValue);
                    str7 = string.Format("\"custom_value\":{0}", column.EditTypeCustomGetValue);
                    str  = str.Replace(str6, str7);
                }
                if ((column.Editable && (column.EditType == EditType.DatePicker)) || (column.EditType == EditType.AutoComplete))
                {
                    string str8 = GridUtil.GetAttachEditorsFunction(grid, column.EditType.ToString().ToLower(), column.EditorControlID);
                    str = str.Replace(string.Concat(new object[] { '"', "attachEditControlsScript", column.DataField, '"' }), str8);
                    str = str.Replace('"' + "dataInit" + '"', "dataInit");
                }
                if ((column.Searchable && (column.SearchType == SearchType.DatePicker)) || (column.SearchType == SearchType.AutoComplete))
                {
                    string str9 = GridUtil.GetAttachEditorsFunction(grid, column.SearchType.ToString().ToLower(), column.SearchControlID);
                    str = str.Replace(string.Concat(new object[] { '"', "attachSearchControlsScript", column.DataField, '"' }), str9);
                    str = str.Replace('"' + "dataInit" + '"', "dataInit");
                }
            }
            return(str);
        }
예제 #2
0
        internal static string GetAttachEditorsFunction(JQGrid grid, string editorType, string editorControlID)
        {
            new JavaScriptSerializer();
            GridUtil.GetListOfColumns(grid);
            GridUtil.GetListOfEditors(grid);
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("function(el) {");
            stringBuilder.Append("setTimeout(function() {");
            stringBuilder.AppendFormat("var ec = '{0}';", editorControlID);
            if (editorType == "datepicker")
            {
                stringBuilder.Append("if (typeof(jQuery(el).datepicker) !== 'function')");
                stringBuilder.Append("alert('JQDatePicker javascript not present on the page. Please, include jquery.jqDatePicker.min.js');");
                stringBuilder.Append("jQuery(el).datepicker( eval(ec + '_dpid') );");
            }
            if (editorType == "autocomplete")
            {
                stringBuilder.Append("if (typeof(jQuery(el).autocomplete) !== 'function')");
                stringBuilder.Append("alert('JQAutoComplete javascript not present on the page. Please, include jquery.jqAutoComplete.min.js');");
                stringBuilder.Append("jQuery(el).autocomplete( eval(ec + '_acid') );");
            }
            if (editorType == "datetimepicker")
            {
                stringBuilder.Append("if (typeof(jQuery(el).datetimepicker) !== 'function')");
                stringBuilder.Append("alert('datetimepicker javascript not present on the page. Please, include jquery.datetimepicker.min.js');");
                stringBuilder.Append("jQuery(el).datetimepicker( eval(ec + '_dtpid') );");
            }
            if (editorType == "timepicker")
            {
                stringBuilder.Append("if (typeof(jQuery(el).datetimepicker) !== 'function')");
                stringBuilder.Append("alert('datetimepicker javascript not present on the page. Please, include jquery.datetimepicker.min.js');");
                stringBuilder.Append("jQuery(el).timepicker( eval(ec + '_tpid') );");
            }
            if (editorType == "chosen")
            {
                stringBuilder.Append("if (typeof(jQuery(el).chosen) !== 'function')");
                stringBuilder.Append("alert('chosen javascript not present on the page. Please, include chosen.jquery.min.js');");
                stringBuilder.Append("jQuery(el).chosen( eval(ec + '_cnid') );");
            }
            stringBuilder.Append("},200);");
            stringBuilder.Append("}");
            return(stringBuilder.ToString());
        }
예제 #3
0
        public static string RemoveQuotesForJavaScriptMethods(string input, JQGrid grid)
        {
            string text = input;

            foreach (JQGridColumn current in grid.Columns)
            {
                if (current.Formatter != null)
                {
                    JQGridColumnFormatter formatter = current.Formatter;
                    if (formatter is CustomFormatter)
                    {
                        CustomFormatter customFormatter = (CustomFormatter)formatter;
                        string          oldValue        = string.Format("\"formatter\":\"{0}\"", customFormatter.FormatFunction);
                        string          newValue        = string.Format("\"formatter\":{0}", customFormatter.FormatFunction);
                        text     = text.Replace(oldValue, newValue);
                        oldValue = string.Format("\"unformat\":\"{0}\"", customFormatter.UnFormatFunction);
                        newValue = string.Format("\"unformat\":{0}", customFormatter.UnFormatFunction);
                        text     = text.Replace(oldValue, newValue);
                    }
                }
                foreach (JQGridEditClientSideValidator current2 in current.EditClientSideValidators)
                {
                    if (current2 is CustomValidator)
                    {
                        CustomValidator customValidator = (CustomValidator)current2;
                        string          oldValue2       = string.Format("\"custom_func\":\"{0}\"", customValidator.ValidationFunction);
                        string          newValue2       = string.Format("\"custom_func\":{0}", customValidator.ValidationFunction);
                        text = text.Replace(oldValue2, newValue2);
                    }
                }
                if (current.EditType == EditType.Custom)
                {
                    string oldValue3 = string.Format("\"custom_element\":\"{0}\"", current.EditTypeCustomCreateElement);
                    string newValue3 = string.Format("\"custom_element\":{0}", current.EditTypeCustomCreateElement);
                    text      = text.Replace(oldValue3, newValue3);
                    oldValue3 = string.Format("\"custom_value\":\"{0}\"", current.EditTypeCustomGetValue);
                    newValue3 = string.Format("\"custom_value\":{0}", current.EditTypeCustomGetValue);
                    text      = text.Replace(oldValue3, newValue3);
                }
                if (current.Editable && (
                        current.EditType == EditType.DatePicker ||
                        current.EditType == EditType.DateTimePicker ||
                        current.EditType == EditType.TimePicker ||
                        current.EditType == EditType.AutoComplete ||
                        current.EditType == EditType.Chosen))
                {
                    string attachEditorsFunction = GridUtil.GetAttachEditorsFunction(grid, current.EditType.ToString().ToLower(), current.EditorControlID);
                    text = text.Replace(string.Concat(new object[]
                    {
                        '"',
                        "attachEditControlsScript",
                        current.DataField,
                        '"'
                    }), attachEditorsFunction);
                }
                if (current.Searchable && (current.SearchType == SearchType.DatePicker ||
                                           current.SearchType == SearchType.AutoComplete ||
                                           current.SearchType == SearchType.DateTimePicker ||
                                           current.SearchType == SearchType.TimePicker))
                {
                    string attachEditorsFunction2 = GridUtil.GetAttachEditorsFunction(grid, current.SearchType.ToString().ToLower(), current.SearchControlID);
                    text = text.Replace(string.Concat(new object[]
                    {
                        '"',
                        "attachSearchControlsScript",
                        current.DataField,
                        '"'
                    }), attachEditorsFunction2);
                }
                if (current.DataEvents.Count > 0)
                {
                    List <DataEvent> lde = current.DataEvents.FindAll(f => f.Type != DataEventType.No);
                    if (lde.Count > 0)
                    {
                        foreach (DataEvent de in lde)
                        {
                            string oldValue = string.Format("\"fn\":\"{0}\"", de.Function);
                            string newValue = string.Format("\"fn\":{0}", de.Function);
                            text = text.Replace(oldValue, newValue);
                        }
                    }
                }
                if (!string.IsNullOrEmpty(current.DataUrl))
                {
                    string oldValue = string.Format("\"dataUrl\":\"{0}\"", current.DataUrl);
                    string newValue = string.Format("\"dataUrl\":{0}", current.DataUrl);
                    text = text.Replace(oldValue, newValue);
                }
                if (!string.IsNullOrEmpty(current.BuildSelect))
                {
                    string oldValue = string.Format("\"buildSelect\":\"{0}\"", current.BuildSelect);
                    string newValue = string.Format("\"buildSelect\":{0}", current.BuildSelect);
                    text = text.Replace(oldValue, newValue);
                }
                if (!string.IsNullOrEmpty(current.SerializeColumnData))
                {
                    string oldValue = string.Format("\"postData\":\"{0}\"", current.SerializeColumnData);
                    string newValue = string.Format("\"postData\":{0}", current.SerializeColumnData);
                    text = text.Replace(oldValue, newValue);
                }
                if (!string.IsNullOrEmpty(current.DataInit))
                {
                    string oldValue = string.Format("\"dataInit\":\"{0}\"", current.DataInit);
                    string newValue = string.Format("\"dataInit\":{0}", current.DataInit);
                    text = text.Replace(oldValue, newValue);
                }
                //if (!string.IsNullOrEmpty(current.Complete))
                //{
                //    string oldValue = string.Format("\"complete\":\"{0}\"", current.Complete);
                //    string newValue = string.Format("\"complete\":{0}", current.Complete);
                //    text = text.Replace(oldValue, newValue);
                //}
                if (current.EditActionIconsColumn)
                {
                    if (current.EditActionIconsSettings.ShowEditIcon && !string.IsNullOrEmpty(current.EditActionIconsSettings.onEdit))
                    {
                        string oldValue = string.Format("\"onEdit\":\"{0}\"", current.EditActionIconsSettings.onEdit);
                        string newValue = string.Format("\"onEdit\":{0}", current.EditActionIconsSettings.onEdit);
                        text = text.Replace(oldValue, newValue);
                    }
                    if (current.EditActionIconsSettings.ShowDeleteIcon)
                    {
                        if (!string.IsNullOrEmpty(current.EditActionIconsSettings.DelErrorTextFormat))
                        {
                            string oldValue = string.Format("\"errorTextFormat\":\"{0}\"", current.EditActionIconsSettings.DelErrorTextFormat);
                            string newValue = string.Format("\"errorTextFormat\":{0}", current.EditActionIconsSettings.DelErrorTextFormat);
                            text = text.Replace(oldValue, newValue);
                        }
                        if (!string.IsNullOrEmpty(grid.ClientSideEvents.SerializeDelData))
                        {
                            string oldValue = string.Format("\"serializeDelData\":\"{0}\"", grid.ClientSideEvents.SerializeDelData);
                            string newValue = string.Format("\"serializeDelData\":{0}", grid.ClientSideEvents.SerializeDelData);
                            text = text.Replace(oldValue, newValue);
                        }
                    }
                }
            }
            text = text.Replace('"' + "dataInit" + '"', "dataInit");
            return(text);
        }