예제 #1
0
        public async Task <string> ParseAsync(IParseStlContext context)
        {
            var formName = string.Empty;
            var type     = string.Empty;

            foreach (var name in context.StlAttributes.AllKeys)
            {
                var value = context.StlAttributes[name];

                if (StringUtils.EqualsIgnoreCase(name, AttributeTitle) || StringUtils.EqualsIgnoreCase(name, AttributeName))
                {
                    formName = await context.ParseAsync(value);
                }
                else if (StringUtils.EqualsIgnoreCase(name, AttributeType))
                {
                    type = await context.ParseAsync(value);
                }
            }

            var formInfo = !string.IsNullOrEmpty(formName) ? await _formRepository.GetFormInfoByTitleAsync(context.SiteId, formName) : null;

            if (formInfo == null)
            {
                var formInfoList = await _formRepository.GetFormInfoListAsync(context.SiteId);

                if (formInfoList != null && formInfoList.Count > 0)
                {
                    formInfo = formInfoList[0];
                }
            }

            if (formInfo == null)
            {
                return(string.Empty);
            }

            var apiUrl = _pathManager.GetApiUrl();

            if (string.IsNullOrEmpty(context.StlInnerHtml))
            {
                var elementId = $"iframe_{StringUtils.GetShortGuid(false)}";
                var libUrl    = _pathManager.GetRootUrl("assets/form/lib/iframe-resizer-3.6.3/iframeResizer.min.js");
                var pageUrl   = _pathManager.GetRootUrl($"assets/form/templates/{type}/index.html?siteId={context.SiteId}&formId={formInfo.Id}&apiUrl={HttpUtility.UrlEncode(apiUrl)}");

                return($@"
<iframe id=""{elementId}"" frameborder=""0"" scrolling=""no"" src=""{pageUrl}"" style=""width: 1px;min-width: 100%;""></iframe>
<script type=""text/javascript"" src=""{libUrl}""></script>
<script type=""text/javascript"">iFrameResize({{log: false}}, '#{elementId}')</script>
");
            }

            return($@"
<script>
var $formConfigApiUrl = '{apiUrl}';
var $formConfigSiteId = {context.SiteId};
var $formConfigFormId = {formInfo.Id};
</script>
{context.StlInnerHtml}
");
        }