Esempio n. 1
0
        private static string ParseImpl(PageInfo pageInfo, ContextInfo contextInfo, InputInfo inputInfo, NameValueCollection pageScripts, List <TableStyleInfo> styleInfoList, string template, string loading, string yes, string no)
        {
            pageInfo.AddPageScriptsIfNotExists(PageInfo.Components.Jquery);
            var stlContainerId = $"stl_input_{inputInfo.InputId}";
            var stlFormId      = $"stl_form_{inputInfo.InputId}";

            template = StlParserManager.ParseInnerContent(template, pageInfo, contextInfo);
            loading  = StlParserManager.ParseInnerContent(loading, pageInfo, contextInfo);
            yes      = StlParserManager.ParseInnerContent(yes, pageInfo, contextInfo);
            no       = StlParserManager.ParseInnerContent(no, pageInfo, contextInfo);

            var templateBuilder = new StringBuilder();

            templateBuilder.Append($@"
<script type=""text/javascript"" src=""{SiteFilesAssets.Input.GetScriptUrl(pageInfo.ApiUrl)}""></script>
<form id=""{stlFormId}"" name=""{stlFormId}"" style=""margin:0;padding:0"" method=""post"" enctype=""multipart/form-data"" action=""{ActionsInputAdd.GetUrl(pageInfo.ApiUrl, pageInfo.PublishmentSystemId, inputInfo.InputId)}"" target=""stl_iframe_{inputInfo.InputId}"">
    {template}
</form>
<iframe id=""stl_iframe_{inputInfo.InputId}"" name=""stl_iframe_{inputInfo.InputId}"" width=""0"" height=""0"" frameborder=""0""></iframe>
");

            foreach (string key in pageScripts.Keys)
            {
                templateBuilder.Append(pageScripts[key]);
            }

            var idList       = new List <string>();
            var formElements = StlHtmlUtility.GetHtmlFormElements(templateBuilder.ToString());

            if (formElements != null && formElements.Count > 0)
            {
                foreach (var formElement in formElements)
                {
                    string tagName;
                    string innerXml;
                    NameValueCollection attributes;
                    StlHtmlUtility.ParseHtmlElement(formElement, out tagName, out innerXml, out attributes);

                    if (string.IsNullOrEmpty(attributes["id"]))
                    {
                        continue;
                    }

                    foreach (var styleInfo in styleInfoList)
                    {
                        if (!StringUtils.EqualsIgnoreCase(styleInfo.AttributeName, attributes["id"]))
                        {
                            continue;
                        }

                        string validateAttributes;
                        var    validateHtmlString = GetValidateHtmlString(styleInfo, out validateAttributes);
                        attributes["id"]   = styleInfo.AttributeName;
                        attributes["name"] = styleInfo.AttributeName;

                        var replace = StringUtils.EqualsIgnoreCase(tagName, "input")
                            ? $@"<{tagName} {TranslateUtils.ToAttributesString(attributes)} {validateAttributes} />{validateHtmlString}"
                            : $@"<{tagName} {TranslateUtils.ToAttributesString(attributes)} {validateAttributes} >{innerXml}</{tagName}>{validateHtmlString}";

                        templateBuilder.Replace(formElement, replace);

                        idList.Add(styleInfo.AttributeName);
                    }
                }
            }

            StlHtmlUtility.RewriteSubmitButton(templateBuilder, $"inputSubmit(this, '{stlFormId}', '{stlContainerId}', [{TranslateUtils.ToSqlInStringWithQuote(idList)}]);return false;");

            StlParserManager.ParseInnerContent(templateBuilder, pageInfo, contextInfo);

            return($@"
<div id=""{stlContainerId}"">
    <div class=""stl_input_template"">{templateBuilder}</div>
    <div class=""stl_input_loading"" style=""display:none"">{loading}</div>
    <div class=""stl_input_yes"" style=""display:none"">{yes}</div>
    <div class=""stl_input_no"" style=""display:none"">{no}</div>
</div>
");
        }
Esempio n. 2
0
        public string ReplacePlaceHolder(string template, bool isLoadValues, string successTemplateString, string failureTemplateString)
        {
            var parsedContent = new StringBuilder();

            parsedContent.Append($@"
<div id=""inputSuccess_{_inputInfo.InputId}"" class=""is_success"" style=""display:none""></div>
<div id=""inputFailure_{_inputInfo.InputId}"" class=""is_failure"" style=""display:none""></div>
<div id=""inputContainer_{_inputInfo.InputId}"">");

            //添加遮罩层
            parsedContent.Append($@"
<div id=""inputModal_{_inputInfo.InputId}"" times=""2"" id=""xubox_shade2"" class=""xubox_shade"" style=""z-index:19891016; background-color: #FFF; opacity: 0.5; filter:alpha(opacity=10);top: 0;left: 0;width: 100%;height: 100%;position: fixed;display:none;""></div>
<div id=""inputModalMsg_{_inputInfo.InputId}"" times=""2"" showtime=""0"" style=""z-index: 19891016; left: 50%; top: 206px; width: 500px; height: 360px; margin-left: -250px;position: fixed;text-align: center;display:none;"" id=""xubox_layer2"" class=""xubox_layer"" type=""iframe""><img src = ""{SiteFilesAssets.GetUrl(_publishmentSystemInfo.Additional.ApiUrl, SiteFilesAssets.FileWaiting)}"" style="""">
<br>
<span style=""font-size:10px;font-family:Microsoft Yahei"">正在提交...</span>
</div>
<script>
		function openModal()
        {{
			document.getElementById(""inputModal_{_inputInfo.InputId}"").style.display = '';
            document.getElementById(""inputModalMsg_{_inputInfo.InputId}"").style.display = '';
        }}
        function closeModal()
        {{
			document.getElementById(""inputModal_{_inputInfo.InputId}"").style.display = 'none';
            document.getElementById(""inputModalMsg_{_inputInfo.InputId}"").style.display = 'none';
        }}
</script>");

            var actionUrl = ActionsInputAdd.GetUrl(_publishmentSystemInfo.Additional.ApiUrl, _publishmentSystemInfo.PublishmentSystemId, _inputInfo.InputId);

            parsedContent.Append($@"
<form id=""frmInput_{_inputInfo.InputId}"" name=""frmInput_{_inputInfo.InputId}"" style=""margin:0;padding:0"" method=""post"" enctype=""multipart/form-data"" action=""{actionUrl}"" target=""loadInput_{_inputInfo.InputId}"">
");

            if (!string.IsNullOrEmpty(successTemplateString))
            {
                parsedContent.AppendFormat(@"<input type=""hidden"" id=""successTemplateString"" value=""{0}"" />", TranslateUtils.EncryptStringBySecretKey(successTemplateString));
            }
            if (!string.IsNullOrEmpty(failureTemplateString))
            {
                parsedContent.AppendFormat(@"<input type=""hidden"" id=""failureTemplateString"" value=""{0}"" />", TranslateUtils.EncryptStringBySecretKey(failureTemplateString));
            }

            parsedContent.Append(template);

            parsedContent.AppendFormat(@"
</form>
<iframe id=""loadInput_{0}"" name=""loadInput_{0}"" width=""0"" height=""0"" frameborder=""0""></iframe>
</div>", _inputInfo.InputId);

            var pageScripts = new NameValueCollection();

            GetAttributesHtml(pageScripts, _publishmentSystemInfo, _styleInfoList);

            foreach (string key in pageScripts.Keys)
            {
                parsedContent.Append(pageScripts[key]);
            }

            if (_inputInfo.Additional.IsCtrlEnter)
            {
                parsedContent.AppendFormat(@"
<script>document.body.onkeydown=function(e)
{{e=e?e:window.event;var tagname=e.srcElement?e.srcElement.tagName:e.target.tagName;if(tagname=='INPUT'||tagname=='TEXTAREA'){{if(e!=null&&e.ctrlKey&&e.keyCode==13){{document.getElementById('submit_{0}').click();}}}}}}</script>", _inputInfo.InputId);
            }

            string clickString =
                $@"if (checkFormValueById('frmInput_{HolderInputId}')){{openModal(); document.getElementById('frmInput_{HolderInputId}').submit();}}";

            StlHtmlUtility.ReWriteSubmitButton(parsedContent, clickString);

            var stlFormElements = StlHtmlUtility.GetStlFormElementsArrayList(parsedContent.ToString());

            if (stlFormElements != null && stlFormElements.Count > 0)
            {
                foreach (string stlFormElement in stlFormElements)
                {
                    XmlNode             elementNode;
                    NameValueCollection attributes;
                    StlHtmlUtility.ReWriteFormElements(stlFormElement, out elementNode, out attributes);

                    var validateAttributes = string.Empty;
                    var validateHtmlString = string.Empty;

                    if (!string.IsNullOrEmpty(attributes["id"]))
                    {
                        foreach (var styleInfo in _styleInfoList)
                        {
                            if (StringUtils.EqualsIgnoreCase(styleInfo.AttributeName, attributes["id"]))
                            {
                                validateHtmlString = InputParserUtility.GetValidateHtmlString(styleInfo, out validateAttributes);
                                attributes["id"]   = styleInfo.AttributeName;
                            }
                        }
                    }

                    if (StringUtils.EqualsIgnoreCase(elementNode.Name, "input"))
                    {
                        parsedContent.Replace(stlFormElement,
                                              $@"<{elementNode.Name} {TranslateUtils.ToAttributesString(attributes)} {validateAttributes}/>{validateHtmlString}");
                    }
                    else
                    {
                        parsedContent.Replace(stlFormElement,
                                              $@"<{elementNode.Name} {TranslateUtils.ToAttributesString(attributes)} {validateAttributes}>{elementNode
                                .InnerXml}</{elementNode.Name}>{validateHtmlString}");
                    }
                }
            }

            parsedContent.Replace(HolderInputId, _inputInfo.InputId.ToString());

            if (isLoadValues)
            {
                parsedContent.AppendFormat(@"
<script type=""text/javascript"">stlInputLoadValues('frmInput_{0}');</script>
", _inputInfo.InputId);
            }

            return(parsedContent.ToString());
        }