Ejemplo n.º 1
0
        public string GetIdentifierHtml(int siteId, int channelId, IDictionary <string, object> attributes)
        {
            var identifier = TranslateUtils.Get <string>(attributes, ContentAttribute.Identifier);

            return($@"
        <div class=""form-group"">
            <label class=""col-sm-1 control-label"">信息分类</label>
            <div class=""col-sm-6"">
                {GetCategoriesHtml(siteId, channelId, attributes)}
            </div>
            <div class=""col-sm-5"">
            </div>
        </div>
        <div class=""form-group"">
            <label class=""col-sm-1 control-label"">索引号</label>
            <div class=""col-sm-6"">
                <input id=""displayOnly{ContentAttribute.Identifier}"" name=""displayOnly{ContentAttribute.Identifier}"" type=""text"" class=""form-control"" disabled=""disabled"" value=""{identifier}"">
                <input id=""{ContentAttribute.Identifier}"" name=""{ContentAttribute.Identifier}"" type=""hidden"" value=""{identifier}"">
            </div>
            <div class=""col-sm-5"">
                <span class=""help-block"">索引号由系统自动生成</span>
            </div>
        </div>
        ");
        }
Ejemplo n.º 2
0
        public void ContentFormSubmited(int siteId, int channelId, IContentInfo contentInfo, IDictionary <string, object> form)
        {
            var categoryChannelId    = TranslateUtils.Get <int>(form, "categoryChannelId");
            var categoryDepartmentId = TranslateUtils.Get <int>(form, "categoryDepartmentId");

            if (categoryChannelId == 0)
            {
                throw new Exception("请选择正确的主题分类");
            }
            contentInfo.ChannelId = categoryChannelId;
            if (categoryDepartmentId == 0)
            {
                throw new Exception("请选择正确的机构分类");
            }
            contentInfo.Set(ContentAttribute.DepartmentId, categoryDepartmentId.ToString());

            var classInfoList = Main.CategoryClassRepository.GetCategoryClassInfoList(siteId);

            foreach (var classInfo in classInfoList)
            {
                if (classInfo.IsSystem || !classInfo.IsEnabled)
                {
                    continue;
                }

                var attributeName  = PublicManager.GetCategoryContentAttributeName(classInfo.ClassCode);
                var attributeValue = TranslateUtils.Get <int>(form, attributeName);

                contentInfo.Set(attributeName, attributeValue.ToString());

                //if (attributeValue > 0)
                //{
                //    CategoryDao.UpdateContentNum(PublishmentSystemInfo, categoryClassInfo.ContentAttributeName, categoryId);
                //}
            }

            if (contentInfo.Id == 0)
            {
                var identifier = PublicManager.GetIdentifier(siteId, categoryChannelId,
                                                             categoryDepartmentId, contentInfo);
                contentInfo.Set(nameof(ContentAttribute.Identifier), identifier);
            }
            else
            {
                var effectDate = contentInfo.Get <DateTime>(ContentAttribute.EffectDate);
                if (string.IsNullOrEmpty(contentInfo.Get <string>(ContentAttribute.Identifier)) || PublicManager.IsIdentifierChanged(siteId, categoryChannelId, categoryDepartmentId, effectDate, contentInfo))
                {
                    var identifier = PublicManager.GetIdentifier(siteId, categoryChannelId,
                                                                 categoryDepartmentId, contentInfo);
                    contentInfo.Set(nameof(ContentAttribute.Identifier), identifier);
                }
            }
        }
Ejemplo n.º 3
0
        public async Task <T> GetAsync <T>(string pluginId, int siteId, string name)
        {
            if (name == null)
            {
                name = string.Empty;
            }

            try
            {
                var value = await GetConfigValueAsync(pluginId, siteId, name);

                var typeCode = Type.GetTypeCode(typeof(T));
                if (typeCode == TypeCode.Int32)
                {
                    return(TranslateUtils.Get <T>(TranslateUtils.ToInt(value)));
                }
                if (typeCode == TypeCode.Decimal)
                {
                    return(TranslateUtils.Get <T>(TranslateUtils.ToDecimal(value)));
                }
                if (typeCode == TypeCode.DateTime)
                {
                    return(TranslateUtils.Get <T>(TranslateUtils.ToDateTime(value)));
                }
                if (typeCode == TypeCode.Boolean)
                {
                    return(TranslateUtils.Get <T>(TranslateUtils.ToBool(value)));
                }
                if (typeCode == TypeCode.String)
                {
                    return(TranslateUtils.Get <T>(value));
                }
                if (!string.IsNullOrEmpty(value))
                {
                    return(JsonConvert.DeserializeObject <T>(value, Settings));
                }
            }
            catch (Exception ex)
            {
                await _errorLogRepository.AddErrorLogAsync(pluginId, ex);
            }
            return(default);
Ejemplo n.º 4
0
 public T Get <T>(string key)
 {
     return(TranslateUtils.Get <T>(ParseManager.PageInfo.PluginItems, key));
 }
Ejemplo n.º 5
0
        public string GetCategoriesHtml(int siteId, int channelId, IDictionary <string, object> attributes)
        {
            var pairList = new List <KeyValuePair <string, DropDownList> >();

            var ddlChannelId = new DropDownList
            {
                ID       = "categoryChannelId",
                CssClass = "form-control"
            };
            var channelIdList   = Context.ChannelApi.GetChannelIdList(siteId);
            var nodeCount       = channelIdList.Count;
            var isLastNodeArray = new bool[nodeCount];

            foreach (var theChannelId in channelIdList)
            {
                var nodeInfo = Context.ChannelApi.GetChannelInfo(siteId, theChannelId);
                var listItem = new ListItem(Utils.GetSelectOptionText(nodeInfo.ChannelName, nodeInfo.ParentsCount, nodeInfo.LastNode, isLastNodeArray),
                                            nodeInfo.Id.ToString());
                if (nodeInfo.ContentModelPluginId != Utils.PluginId)
                {
                    listItem.Value = "0";
                    listItem.Attributes.Add("disabled", "disabled");
                    listItem.Attributes.Add("style", "background-color:#f0f0f0;color:#9e9e9e");
                }
                ddlChannelId.Items.Add(listItem);
            }
            Utils.SelectSingleItem(ddlChannelId, channelId.ToString());
            pairList.Add(new KeyValuePair <string, DropDownList>("主题", ddlChannelId));

            var ddlDepartmentId = new DropDownList
            {
                ID       = "categoryDepartmentId",
                CssClass = "form-control"
            };
            var departmentIdList = DepartmentManager.GetDepartmentIdList(siteId);

            foreach (var departmentId in departmentIdList)
            {
                var departmentInfo = DepartmentManager.GetDepartmentInfo(siteId, departmentId);
                var listItem       = new ListItem(departmentInfo.DepartmentName, departmentInfo.Id.ToString());
                ddlDepartmentId.Items.Add(listItem);
            }

            Utils.SelectSingleItem(ddlDepartmentId, TranslateUtils.Get <int>(attributes, ContentAttribute.DepartmentId).ToString());
            pairList.Add(new KeyValuePair <string, DropDownList>("机构", ddlDepartmentId));


            var classInfoList = Main.CategoryClassRepository.GetCategoryClassInfoList(siteId);

            foreach (var classInfo in classInfoList)
            {
                if (classInfo.IsSystem || !classInfo.IsEnabled)
                {
                    continue;
                }

                var attributeName  = PublicManager.GetCategoryContentAttributeName(classInfo.ClassCode);
                var attributeValue = TranslateUtils.Get <string>(attributes, attributeName);

                var ddlCategoryId = new DropDownList
                {
                    ID       = attributeName,
                    CssClass = "form-control"
                };
                var categoryIdList = Main.CategoryRepository.GetCategoryIdList(siteId, classInfo.ClassCode);
                isLastNodeArray = new bool[categoryIdList.Count];
                foreach (var categoryId in categoryIdList)
                {
                    var categoryInfo = Main.CategoryRepository.GetCategoryInfo(categoryId);
                    var listItem     = new ListItem(Utils.GetSelectOptionText(categoryInfo.CategoryName, categoryInfo.ParentsCount, categoryInfo.IsLastNode, isLastNodeArray), categoryInfo.Id.ToString());
                    ddlCategoryId.Items.Add(listItem);
                }
                Utils.SelectSingleItem(ddlCategoryId, attributeValue);
                pairList.Add(new KeyValuePair <string, DropDownList>(classInfo.ClassName, ddlCategoryId));
            }

            var builder = new StringBuilder();

            builder.Append(@"<div class=""row"">");
            var count = 0;

            foreach (var keyValuePair in pairList)
            {
                if (keyValuePair.Value.Items.Count == 0)
                {
                    continue;
                }

                if (count > 1)
                {
                    builder.Append(@"</div><div class=""row m-t-10"">");
                    count = 0;
                }
                builder.Append($@"
<div class=""col-xs-2 control-label mt-2"">{keyValuePair.Key}分类</div>
<div class=""col-xs-4"">
    {Utils.GetControlRenderHtml(keyValuePair.Value)}
</div>
");
                count++;
            }
            builder.Append("</div>");

            builder.Append(@"<script>
$(document).ready(function () {
    if ($('#Publisher').val().length == 0) $('#Publisher').val($('#categoryDepartmentId').find('option:selected').text().replace(/[ │└├]/g,''));
    $('#categoryDepartmentId').change(function(){
        $('#Publisher').val($(this).children('option:selected').text().replace(/[ │└├]/g,''));
    });
    $('input[type=""radio""][name=""IsAbolition""]').change(function(){
        var isAbolition = $('input[type=""radio""][name=""IsAbolition""]:checked').val();
        isAbolition == 'True' ? $('#AbolitionDate').parent().parent().show() : $('#AbolitionDate').parent().parent().hide();
    });
    var isAbolition = $('input[type=""radio""][name=""IsAbolition""]:checked').val();
    isAbolition == 'True' ? $('#AbolitionDate').parent().parent().show() : $('#AbolitionDate').parent().parent().hide();
});
</script>");

            return(builder.ToString());
        }
Ejemplo n.º 6
0
 public Option(Enum e)
 {
     Value = TranslateUtils.Get <T>(e.GetValue());
     Label = e.GetDisplayName();
 }
Ejemplo n.º 7
0
 public CheckBox(Enum e)
 {
     Label = TranslateUtils.Get <T>(e.GetValue());
     Text  = e.GetDisplayName();
 }
Ejemplo n.º 8
0
 public T Get <T>(string key)
 {
     return(TranslateUtils.Get <T>(_cacheManager.Get(key)));
 }