Пример #1
0
        protected void RegisterContactFields()
        {
            var columnSelectorData = new[]
            {
                new
                {
                    name  = "firstName",
                    title = CRMContactResource.FirstName
                },
                new
                {
                    name  = "lastName",
                    title = CRMContactResource.LastName
                },
                new
                {
                    name  = "jobTitle",
                    title = CRMContactResource.JobTitle
                },
                new
                {
                    name  = "companyName",
                    title = CRMContactResource.CompanyName
                },
                new
                {
                    name  = "about",
                    title = CRMContactResource.About
                }
            }.ToList();

            foreach (ContactInfoType infoTypeEnum in Enum.GetValues(typeof(ContactInfoType)))
            {
                var localName  = String.Format("contactInfo_{0}_{1}", infoTypeEnum, ContactInfo.GetDefaultCategory(infoTypeEnum));
                var localTitle = infoTypeEnum.ToLocalizedString();

                if (infoTypeEnum == ContactInfoType.Address)
                {
                    foreach (AddressPart addressPartEnum in Enum.GetValues(typeof(AddressPart)))
                    {
                        columnSelectorData.Add(new
                        {
                            name  = String.Format(localName + "_{0}_{1}", addressPartEnum, (int)AddressCategory.Work),
                            title = String.Format(localTitle + " {0}", addressPartEnum.ToLocalizedString().ToLower())
                        });
                    }
                }
                else
                {
                    columnSelectorData.Add(new
                    {
                        name  = localName,
                        title = localTitle
                    });
                }
            }

            columnSelectorData.AddRange(Global.DaoFactory.GetCustomFieldDao().GetFieldsDescription(EntityType.Contact)
                                        .FindAll(customField => customField.FieldType == CustomFieldType.TextField || customField.FieldType == CustomFieldType.TextArea)
                                        .ConvertAll(customField => new
            {
                name  = "customField_" + customField.ID,
                title = customField.Label.HtmlEncode()
            }));

            var tagList = Global.DaoFactory.GetTagDao().GetAllTags(EntityType.Contact);

            if (tagList.Length > 0)
            {
                TagList = tagList.ToList();

                Page.RegisterInlineScript(String.Format(" var tagList = {0}; ",
                                                        JavaScriptSerializer.Serialize(TagList.Select(tagName =>
                                                                                                      new
                {
                    name  = "tag_" + tagName.HtmlEncode(),
                    title = tagName.HtmlEncode()
                }))), onReady: false);
            }

            Page.RegisterInlineScript(String.Format(" var columnSelectorData = {0}; ", JavaScriptSerializer.Serialize(columnSelectorData)), onReady: false);
        }
Пример #2
0
        public List <MailTemplateTag> GetTags(bool isCompany)
        {
            var result = new List <MailTemplateTag>();

            if (isCompany)
            {
                result.Add(new MailTemplateTag
                {
                    DisplayName = CRMContactResource.CompanyName,
                    SysName     = "common_companyName",
                    Category    = CRMContactResource.GeneralInformation,
                    isCompany   = isCompany,
                    Name        = ToTagName("Company Name", isCompany)
                });
            }
            else
            {
                result.Add(new MailTemplateTag
                {
                    DisplayName = CRMContactResource.FirstName,
                    SysName     = "common_firstName",
                    Category    = CRMContactResource.GeneralInformation,
                    isCompany   = false,
                    Name        = ToTagName("First Name", isCompany)
                });

                result.Add(new MailTemplateTag
                {
                    DisplayName = CRMContactResource.LastName,
                    SysName     = "common_lastName",
                    Category    = CRMContactResource.GeneralInformation,
                    isCompany   = false,
                    Name        = ToTagName("Last Name", isCompany)
                });

                result.Add(new MailTemplateTag
                {
                    DisplayName = CRMContactResource.JobTitle,
                    SysName     = "common_jobTitle",
                    Category    = CRMContactResource.GeneralInformation,
                    isCompany   = false,
                    Name        = ToTagName("Job Title", isCompany)
                });


                result.Add(new MailTemplateTag
                {
                    DisplayName = CRMContactResource.CompanyName,
                    SysName     = "common_companyName",
                    Category    = CRMContactResource.GeneralInformation,
                    isCompany   = false,
                    Name        = ToTagName("Company Name", isCompany)
                });
            }

            foreach (ContactInfoType infoTypeEnum in Enum.GetValues(typeof(ContactInfoType)))
            {
                var localName  = String.Format("contactInfo_{0}_{1}", infoTypeEnum, ContactInfo.GetDefaultCategory(infoTypeEnum));
                var localTitle = infoTypeEnum.ToLocalizedString();

                if (infoTypeEnum == ContactInfoType.Address)
                {
                    foreach (AddressPart addressPartEnum in Enum.GetValues(typeof(AddressPart)))
                    {
                        result.Add(new MailTemplateTag
                        {
                            SysName     = String.Format(localName + "_{0}_{1}", addressPartEnum, (int)AddressCategory.Work),
                            DisplayName = String.Format(localTitle + " {0}", addressPartEnum.ToLocalizedString()),
                            Category    = CRMContactResource.GeneralInformation,
                            isCompany   = isCompany,
                            Name        = ToTagName(String.Format("{0} {1}", infoTypeEnum.ToString(), addressPartEnum.ToString()), isCompany)
                        });
                    }
                }
                else
                {
                    result.Add(new MailTemplateTag
                    {
                        SysName     = localName,
                        DisplayName = localTitle,
                        Category    = CRMContactResource.GeneralInformation,
                        isCompany   = isCompany,
                        Name        = ToTagName(infoTypeEnum.ToString(), isCompany)
                    });
                }
            }

            var entityType = isCompany ? EntityType.Company : EntityType.Person;

            var customFieldsDao = _daoFactory.GetCustomFieldDao();

            var customFields = customFieldsDao.GetFieldsDescription(entityType);

            var category = CRMContactResource.GeneralInformation;

            foreach (var customField in customFields)
            {
                if (customField.Type == CustomFieldType.SelectBox)
                {
                    continue;
                }
                if (customField.Type == CustomFieldType.CheckBox)
                {
                    continue;
                }

                if (customField.Type == CustomFieldType.Heading)
                {
                    if (!String.IsNullOrEmpty(customField.Label))
                    {
                        category = customField.Label;
                    }

                    continue;
                }

                result.Add(new MailTemplateTag
                {
                    SysName     = "customField_" + customField.ID,
                    DisplayName = customField.Label.HtmlEncode(),
                    Category    = category,
                    isCompany   = isCompany,
                    Name        = ToTagName(customField.Label, isCompany)
                });
            }

            return(result);
        }
Пример #3
0
        protected override IEnumerable <KeyValuePair <string, object> > GetClientVariables(HttpContext context)
        {
            Func <string, string, int, string, object> defaultConverter = (name, title, type, mask) =>
                                                                          new
            {
                type = -1,
                name,
                title,
                mask = ""
            };

            Func <string, string, object> converter = (name, title) => defaultConverter(name, title, -1, "");

            var columnSelectorData = new List <object>
            {
                converter("firstName", CRMContactResource.FirstName),
                converter("lastName", CRMContactResource.LastName),
                converter("jobTitle", CRMContactResource.JobTitle),
                converter("companyName", CRMContactResource.CompanyName),
                converter("about", CRMContactResource.About)
            };

            foreach (ContactInfoType infoTypeEnum in Enum.GetValues(typeof(ContactInfoType)))
            {
                var localName  = string.Format("contactInfo_{0}_{1}", infoTypeEnum, ContactInfo.GetDefaultCategory(infoTypeEnum));
                var localTitle = infoTypeEnum.ToLocalizedString();

                if (infoTypeEnum == ContactInfoType.Address)
                {
                    foreach (AddressPart addressPartEnum in Enum.GetValues(typeof(AddressPart)))
                    {
                        columnSelectorData.Add(converter(
                                                   string.Format(localName + "_{0}_{1}", addressPartEnum, (int)AddressCategory.Work),
                                                   string.Format(localTitle + " {0}", addressPartEnum.ToLocalizedString().ToLower())));
                    }
                }
                else
                {
                    columnSelectorData.Add(converter(localName, localTitle));
                }
            }

            using (var scope = DIHelper.Resolve())
            {
                var daoFactory = scope.Resolve <DaoFactory>();
                var columnSelectorDataCompany = columnSelectorData.ToList();
                var columnSelectorDataPerson  = columnSelectorData.ToList();
                var customFieldDao            = daoFactory.CustomFieldDao;

                Predicate <CustomField> customFieldPredicate = customField =>
                                                               customField.FieldType == CustomFieldType.TextField ||
                                                               customField.FieldType == CustomFieldType.TextArea ||
                                                               customField.FieldType == CustomFieldType.CheckBox ||
                                                               customField.FieldType == CustomFieldType.SelectBox;

                Converter <CustomField, object> customFieldConverter =
                    customField =>
                    defaultConverter("customField_" + customField.ID, customField.Label, (int)customField.FieldType,
                                     customField.Mask);

                Func <EntityType, List <object> > getFieldsDescription = entityType =>
                                                                         customFieldDao.GetFieldsDescription(entityType)
                                                                         .FindAll(customFieldPredicate)
                                                                         .ConvertAll(customFieldConverter);

                columnSelectorDataCompany.AddRange(getFieldsDescription(EntityType.Company));
                columnSelectorDataPerson.AddRange(getFieldsDescription(EntityType.Person));

                var tagList = daoFactory.TagDao.GetAllTags(EntityType.Contact).ToList();

                return(new List <KeyValuePair <string, object> >(1)
                {
                    RegisterObject(
                        new
                    {
                        tagList,
                        columnSelectorDataCompany,
                        columnSelectorDataPerson
                    })
                });
            }
        }