Exemplo n.º 1
0
        public static string GetFormTitle(FormInfo formInfo)
        {
            var text = "表单管理 (0)";

            if (formInfo == null)
            {
                return(text);
            }

            if (formInfo.TotalCount == 0)
            {
                formInfo.TotalCount = LogDao.GetCount(formInfo.Id);
                if (formInfo.TotalCount > 0)
                {
                    FormDao.Update(formInfo);
                }
            }

            text = $"{(formInfo.ContentId > 0 ? "表单管理" : formInfo.Title)} ({formInfo.TotalCount})";
            if (!formInfo.IsReply)
            {
                return(text);
            }

            if (formInfo.TotalCount - formInfo.RepliedCount > 0)
            {
                text = $@"<span class=""text-danger"">{text}</span>";
            }

            return(text);
        }
Exemplo n.º 2
0
        public IHttpActionResult Add()
        {
            try
            {
                var request = Context.GetCurrentRequest();
                var siteId  = request.GetPostInt("siteId");
                if (!request.IsAdminLoggin ||
                    !request.AdminPermissions.HasSitePermissions(siteId, FormUtils.PluginId))
                {
                    return(Unauthorized());
                }

                var formInfo = new FormInfo
                {
                    SiteId      = siteId,
                    AddDate     = DateTime.Now,
                    Title       = request.GetPostString("title"),
                    Description = request.GetPostString("description")
                };

                FormDao.Insert(formInfo);

                return(Ok(new
                {
                    Value = FormManager.GetFormInfoList(siteId, 0)
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Exemplo n.º 3
0
        public IHttpActionResult Delete()
        {
            try
            {
                var request = Context.GetCurrentRequest();
                var siteId  = request.GetPostInt("siteId");
                if (!request.IsAdminLoggin ||
                    !request.AdminPermissions.HasSitePermissions(siteId, FormUtils.PluginId))
                {
                    return(Unauthorized());
                }

                var formId = request.GetPostInt("formId");

                FormDao.Delete(siteId, formId);

                return(Ok(new
                {
                    Value = FormManager.GetFormInfoList(siteId, 0)
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Exemplo n.º 4
0
        private static void Service_ContentDeleteCompleted(object sender, ContentEventArgs e)
        {
            var formInfo = FormManager.GetFormInfoByContentId(e.SiteId, e.ChannelId, e.ContentId);

            if (formInfo != null)
            {
                FormDao.Delete(e.SiteId, formInfo.Id);
            }
        }
Exemplo n.º 5
0
        private void Service_ContentTranslateCompleted(object sender, ContentTranslateEventArgs e)
        {
            var formInfo = FormDao.GetFormInfoOrCreateIfNotExists(e.SiteId, e.ChannelId, e.ContentId);

            formInfo.SiteId      = e.TargetSiteId;
            formInfo.ChannelId   = e.TargetChannelId;
            formInfo.ContentId   = e.TargetContentId;
            formInfo.IsTimeout   = false;
            formInfo.TimeToStart = DateTime.Now;
            formInfo.TimeToEnd   = formInfo.TimeToStart.AddMonths(3);
            FormDao.Insert(formInfo);
        }
Exemplo n.º 6
0
        public override void Startup(IService service)
        {
            FormDao      = new FormDao(ConnectionString, DataApi);
            LogDao       = new LogDao(ConnectionString, DataApi);
            FieldDao     = new FieldDao(ConnectionString, DataApi);
            FieldItemDao = new FieldItemDao(ConnectionString, DataApi);

            service
            .AddSiteMenu(siteId =>
            {
                var formInfoList = FormDao.GetFormInfoListNotInChannel(siteId);
                var menus        = formInfoList.Select(formInfo => new Menu
                {
                    Text = $"{formInfo.Title}",
                    Href = $"{nameof(PageLogs)}.aspx?formId={formInfo.Id}"
                }).ToList();

                menus.Add(new Menu
                {
                    Text = "表单管理",
                    Href = $"{nameof(PageManagement)}.aspx"
                });

                return(new Menu
                {
                    Text = "表单",
                    IconClass = "ion-android-list",
                    Menus = menus
                });
            })
            .AddContentLink(new HyperLink
            {
                Text        = "表单管理",
                NavigateUrl = $"{nameof(PageLogs)}.aspx"
            })
            .AddDatabaseTable(FormDao.TableName, FormDao.Columns)
            .AddDatabaseTable(LogDao.TableName, LogDao.Columns)
            .AddDatabaseTable(FieldDao.TableName, FieldDao.Columns)
            .AddDatabaseTable(FieldItemDao.TableName, FieldItemDao.Columns)
            .AddStlElementParser(StlForm.ElementName, StlForm.Parse)
            ;

            service.ContentTranslateCompleted += Service_ContentTranslateCompleted;
            service.ContentDeleteCompleted    += Service_ContentDeleteCompleted;

            service.ApiPost += ServiceOnApiPost;
            service.ApiGet  += Service_ApiGet;

            Instance = this;
        }
Exemplo n.º 7
0
        public IHttpActionResult Get()
        {
            try
            {
                var request = Context.GetCurrentRequest();
                var siteId  = request.GetQueryInt("siteId");
                if (!request.IsAdminLoggin || !request.AdminPermissions.HasSitePermissions(siteId, FormUtils.PluginId))
                {
                    return(Unauthorized());
                }

                var templateType  = request.GetQueryString("templateType");
                var directoryPath = Context.PluginApi.GetPluginPath(FormUtils.PluginId, "templates");
                var templateUrl   = Context.PluginApi.GetPluginUrl(FormUtils.PluginId, "templates");

                var formInfo = FormManager.GetFormInfoByContentId(siteId, 0, 0) ?? FormDao.CreateDefaultForm(siteId, 0, 0);

                var templates = new List <object>();
                foreach (var directoryName in FormUtils.GetDirectoryNames(directoryPath).OrderBy(x => x.Length))
                {
                    if (FormUtils.StartsWithIgnoreCase(directoryName, templateType))
                    {
                        var html = FormManager.GetTemplateHtml(templateType, directoryName);
                        templates.Add(new
                        {
                            Id          = directoryName,
                            FormId      = formInfo.Id,
                            TemplateUrl = templateUrl,
                            Html        = html
                        });
                    }
                }

                return(Ok(new
                {
                    Value = templates
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Exemplo n.º 8
0
        public IHttpActionResult Visible()
        {
            try
            {
                var request  = Context.GetCurrentRequest();
                var formInfo = FormManager.GetFormInfoByPost(request);
                if (formInfo == null)
                {
                    return(NotFound());
                }
                if (!request.IsAdminLoggin || !request.AdminPermissions.HasSitePermissions(formInfo.SiteId, FormUtils.PluginId))
                {
                    return(Unauthorized());
                }

                var attributeName = request.GetPostString("attributeName");

                var attributeNames = FormUtils.StringCollectionToStringList(formInfo.Additional.ListAttributeNames);
                if (attributeNames.Contains(attributeName))
                {
                    attributeNames.Remove(attributeName);
                }
                else
                {
                    attributeNames.Add(attributeName);
                }

                formInfo.Additional.ListAttributeNames = FormUtils.ObjectCollectionToString(attributeNames);
                FormDao.Update(formInfo);

                return(Ok(new
                {
                    Value = attributeNames
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Exemplo n.º 9
0
            public static List <FormInfo> GetCacheFormInfoList(int siteId)
            {
                var cacheKey = GetCacheKey(siteId);
                var retval   = CacheUtils.Get <List <FormInfo> >(cacheKey);

                if (retval != null)
                {
                    return(retval);
                }

                lock (LockObject)
                {
                    retval = CacheUtils.Get <List <FormInfo> >(cacheKey);
                    if (retval == null)
                    {
                        retval = FormDao.GetFormInfoList(siteId);

                        CacheUtils.InsertHours(cacheKey, retval, 12);
                    }
                }

                return(retval);
            }
Exemplo n.º 10
0
 private static FormInfo GetFormInfoOrCreateIfNotExists(int siteId, int channelId, int contentId)
 {
     return(GetFormInfoByContentId(siteId, channelId, contentId) ?? FormDao.CreateDefaultForm(siteId, channelId, contentId));
 }
Exemplo n.º 11
0
        private void Service_ContentDeleteCompleted(object sender, ContentEventArgs e)
        {
            var formId = FormDao.GetFormIdByContentId(e.SiteId, e.ChannelId, e.ContentId);

            FormDao.Delete(formId);
        }
Exemplo n.º 12
0
        public IHttpActionResult Submit()
        {
            try
            {
                var request  = Context.GetCurrentRequest();
                var formInfo = FormManager.GetFormInfoByPost(request);
                if (formInfo == null)
                {
                    return(NotFound());
                }
                if (!request.IsAdminLoggin || !request.AdminPermissions.HasSitePermissions(formInfo.SiteId, FormUtils.PluginId))
                {
                    return(Unauthorized());
                }

                var type = request.GetPostString("type");
                if (FormUtils.EqualsIgnoreCase(type, nameof(FormSettings.IsClosed)))
                {
                    formInfo.Additional.IsClosed = request.GetPostBool(nameof(FormSettings.IsClosed).ToCamelCase());
                    FormDao.Update(formInfo);
                }
                else if (FormUtils.EqualsIgnoreCase(type, nameof(FormInfo.Title)))
                {
                    formInfo.Title = request.GetPostString(nameof(FormInfo.Title).ToCamelCase());
                    FormDao.Update(formInfo);
                }
                else if (FormUtils.EqualsIgnoreCase(type, nameof(FormInfo.Description)))
                {
                    formInfo.Description = request.GetPostString(nameof(FormInfo.Description).ToCamelCase());
                    FormDao.Update(formInfo);
                }
                else if (FormUtils.EqualsIgnoreCase(type, nameof(FormInfo.IsReply)))
                {
                    formInfo.IsReply = request.GetPostBool(nameof(FormInfo.IsReply).ToCamelCase());
                    FormDao.Update(formInfo);
                }
                else if (FormUtils.EqualsIgnoreCase(type, nameof(FormSettings.IsTimeout)))
                {
                    formInfo.Additional.IsTimeout   = request.GetPostBool(nameof(FormSettings.IsTimeout).ToCamelCase());
                    formInfo.Additional.TimeToStart = FormUtils.ToDateTime(request.GetPostString(nameof(FormSettings.TimeToStart).ToCamelCase()));
                    formInfo.Additional.TimeToEnd   = FormUtils.ToDateTime(request.GetPostString(nameof(FormSettings.TimeToEnd).ToCamelCase()));
                    FormDao.Update(formInfo);
                }
                else if (FormUtils.EqualsIgnoreCase(type, nameof(FormSettings.IsCaptcha)))
                {
                    formInfo.Additional.IsCaptcha = request.GetPostBool(nameof(FormSettings.IsCaptcha).ToCamelCase());
                    FormDao.Update(formInfo);
                }
                else if (FormUtils.EqualsIgnoreCase(type, nameof(FormSettings.IsAdministratorSmsNotify)))
                {
                    formInfo.Additional.IsAdministratorSmsNotify     = request.GetPostBool(nameof(FormSettings.IsAdministratorSmsNotify).ToCamelCase());
                    formInfo.Additional.AdministratorSmsNotifyTplId  = request.GetPostString(nameof(FormSettings.AdministratorSmsNotifyTplId).ToCamelCase());
                    formInfo.Additional.AdministratorSmsNotifyKeys   = request.GetPostString(nameof(FormSettings.AdministratorSmsNotifyKeys).ToCamelCase());
                    formInfo.Additional.AdministratorSmsNotifyMobile = request.GetPostString(nameof(FormSettings.AdministratorSmsNotifyMobile).ToCamelCase());

                    FormDao.Update(formInfo);
                }

                return(Ok(new{}));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Exemplo n.º 13
0
 public FormServiceImpl(FormDao formDao)
 {
     this.FormDao = formDao;
 }