All files / sn-client-js/src FieldSettings.ts

100% Statements 103/103
100% Branches 16/16
100% Functions 21/21
100% Lines 80/80
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339                                      1x       1x       1x       1x       1x       1x       1x   1x                                 210x 210x 210x 210x 210x 210x 210x 210x 210x 210x 210x 210x 210x                                               1x             24x 24x 24x 24x 24x                       1x         84x 84x 84x                   1x       66x 66x                 1x     32x               1x           16x 16x 16x 16x                     1x       5x 5x                 1x               29x 29x 29x 29x 29x 29x                         1x         18x 18x 18x                   1x               20x 20x 20x 20x 20x 20x                         1x               6x 6x 6x 6x 6x 6x                         1x         1x 1x 1x                   1x           2x 2x 2x 2x                     1x     2x            
/**
 * @module FieldSettings
 * @preferred
 * 
 * @description Module for FieldSettings.
 *
 * FieldSetting object is the implementation of the configuration element in a Sense/Net Content Type Definition.
 * The FieldSetting of a Field contains properties that define the behavior of the Field - for example a Field can be configured as read only or compulsory to fill.
 * FieldSettings helps us to autogenerate type and schema TS files from Sense/Net CTDs and use these files to reach all the configuration options of the Content Types fields on
 * client-side e.g. for validation.
 *
 * This module also contains some FieldSetting related enums to use them as types in properties e.g. visibitily or datetime mode options.
 */ /** */
 
import { ComplexTypes } from './SN';
 
    /**
     * Enum for Field visibility values.
     */
    export enum FieldVisibility { Show, Hide, Advanced }
    /**
     * Enum for Field output method values.
     */
    export enum OutputMethod { Default, Raw, Text, Html }
    /**
     * Enum for Choice Field control values.
     */
    export enum DisplayChoice { DropDown, RadioButtons, CheckBoxes }
    /**
     * Enum for DateTime Field mode values.
     */
    export enum DateTimeMode { None, Date, DateAndTime }
    /**
     * Enum for DateTime Field precision values.
     */
    export enum DateTimePrecision { Millisecond, Second, Minute, Hour, Day }
    /**
     * Enum for LongText field editor values.
     */
    export enum TextType { LongText, RichText, AdvancedRichText }
    /**
     * Enum for HyperLink field href values.
     */
    export enum UrlFormat { Hyperlink, Picture }
 
    export class FieldSetting {
        Name: string;
        DisplayName?: string;
        Description?: string;
        Icon?: string;
        ReadOnly?: boolean;
        Compulsory?: boolean;
        DefaultValue?: string;
        OutputMethod?: OutputMethod;
        VisibleBrowse?: FieldVisibility;
        VisibleNew?: FieldVisibility;
        VisibleEdit?: FieldVisibility;
        FieldIndex?: number;
        DefaultOrder?: number;
        ControlHint?: string;
 
        constructor(options: IFieldSettingOptions) {
            this.Name = options.name || 'Content';
            this.DisplayName = options.displayName;
            this.Icon = options.icon;
            this.ReadOnly = options.readOnly;
            this.Compulsory = options.compulsory;
            this.DefaultValue = options.defaultValue;
            this.OutputMethod = options.outputMethod;
            this.VisibleBrowse = options.visibleBrowse;
            this.VisibleEdit = options.visibleEdit;
            this.VisibleNew = options.visibleNew;
            this.FieldIndex = options.fieldIndex;
            this.DefaultOrder = options.defaultOrder;
            this.ControlHint = options.controlHint;
 
        }
    }
 
    export interface IFieldSettingOptions {
        name?: string;
        displayName?: string;
        description?: string;
        icon?: string;
        readOnly?: boolean;
        compulsory?: boolean;
        defaultValue?: string;
        outputMethod?: OutputMethod;
        visibleBrowse?: FieldVisibility;
        visibleNew?: FieldVisibility;
        visibleEdit?: FieldVisibility;
        fieldIndex?: number;
        defaultOrder?: number;
        controlHint?: string;
    }
 
 
    // Used in ContentType, GenericContent, File, Image, TrashBag, TrashBin, Task
    export class IntegerFieldSetting extends FieldSetting {
        MinValue?: number;
        MaxValue?: number;
        ShowAsPercentage?: boolean;
        Step?: number;
 
        constructor(options: IIntegerFieldSettingOptions) {
            super(options);
            this.MinValue = options.minValue;
            this.MaxValue = options.maxValue;
            this.ShowAsPercentage = options.showAsPercentage;
            this.Step = options.step;
        }
    }
 
    export interface IIntegerFieldSettingOptions extends IFieldSettingOptions {
        minValue?: number;
        maxValue?: number;
        showAsPercentage?: boolean;
        step?: number;
    }
 
    // 
    export class TextFieldSetting extends FieldSetting {
        MinLength?: number;
        MaxLength?: number;
 
        constructor(options: ITextFieldSettingOptions) {
            super(options);
            this.MinLength = options.minLength;
            this.MaxLength = options.maxLength;
        }
    }
 
    export interface ITextFieldSettingOptions extends IFieldSettingOptions {
        minLength?: number;
        maxLength?: number;
    }
 
    // Used in ContentType, GenericContent, File, ContentList, Device, Domain, Email, OrganizationalUnit, TrashBag, Group, Task, User
    export class ShortTextFieldSetting extends TextFieldSetting {
        Regex?: string;
 
        constructor(options: IShortTextFieldSettingOptions) {
            super(options);
            this.Regex = options.regex;
        }
    }
 
    export interface IShortTextFieldSettingOptions extends ITextFieldSettingOptions {
        regex?: string;
    }
 
    // Used in ContentType, GenericContent, Settings, IndexingSettings, ContentList, Workspace, Site, CustomListItem, User
    export class NullFieldSetting extends FieldSetting {
 
        constructor(options: INullFieldSettingOptions) {
            super(options);
        }
    }
 
    export interface INullFieldSettingOptions extends IFieldSettingOptions {
    }
 
    // Used in ContentType, GenericContent, File, HtmlTemplate, Image, ContentList, Aspect, Email, SmartFolder, Query, User
    export class LongTextFieldSetting extends TextFieldSetting {
        Rows?: number;
        TextType?: TextType;
        AppendModifications?: boolean;
 
        constructor(options: ILongTextFieldSettingOptions) {
            super(options);
            this.Rows = options.rows;
            this.TextType = options.textType;
            this.AppendModifications = options.appendModifications;
        }
    }
 
    export interface ILongTextFieldSettingOptions extends ITextFieldSettingOptions {
        rows?: number;
        textType?: TextType;
        appendModifications?: boolean;
    }
 
    // Used in ContentType, File, User
    export class BinaryFieldSetting extends FieldSetting {
        IsText?: boolean;
 
        constructor(options: IBinaryFieldSettingOptions) {
            super(options);
            this.IsText = options.isText;
        }
    }
 
    export interface IBinaryFieldSettingOptions extends IFieldSettingOptions {
        isText?: boolean;
    }
 
    // Used in ContentType, GenericContent, ContentLink, ContentList, ImageLibrary, TrashBag, Workspace, Site, UserProfile, Group, Memo, Task, User
    export class ReferenceFieldSetting extends FieldSetting {
        AllowMultiple?: boolean;
        AllowedTypes?: string[];
        SelectionRoots?: string[];
        Query?: string;
        FieldName?: string;
 
        constructor(options: IReferenceFieldSettingOptions) {
            super(options);
            this.AllowMultiple = options.allowMultiple;
            this.AllowedTypes = options.allowedTypes;
            this.SelectionRoots = options.selectionRoots;
            this.Query = options.query;
            this.FieldName = options.fieldName;
        }
    }
 
    export interface IReferenceFieldSettingOptions extends IFieldSettingOptions {
        allowMultiple?: boolean;
        allowedTypes?: string[];
        selectionRoots?: string[];
        query?: string;
        fieldName?: string;
    }
 
    // Used in ContentType, GenericContent, Image, Domain, Email, OrganizationalUnit, TrashBag, Workspace, Group, Memo, Task, User
    export class DateTimeFieldSetting extends FieldSetting {
        DateTimeMode?: DateTimeMode;
        Precision?: DateTimePrecision;
 
        constructor(options: IDateTimeFieldSettingOptions) {
            super(options);
            this.DateTimeMode = options.dateTimeMode;
            this.Precision = options.precision;
        }
    }
 
    export interface IDateTimeFieldSettingOptions extends IFieldSettingOptions {
        dateTimeMode?: DateTimeMode;
        precision?: DateTimePrecision;
    }
 
    // Used in GenericContent, ContentList, SmartFolder, Site, Memo, Task, Query, User
    export class ChoiceFieldSetting extends ShortTextFieldSetting {
        AllowExtraValue?: boolean;
        AllowMultiple?: boolean;
        Options?: ComplexTypes.ChoiceOption[];
        DisplayChoice?: DisplayChoice;
        EnumTypeName?: string;
 
        constructor(options: IChoiceFieldSettingOptions) {
            super(options);
            this.AllowExtraValue = options.allowExtraValue;
            this.AllowMultiple = options.allowMultiple;
            this.Options = options.options;
            this.DisplayChoice = options.displayChoice;
            this.EnumTypeName = options.enumTypeName;
        }
    }
 
    export interface IChoiceFieldSettingOptions extends IShortTextFieldSettingOptions {
        allowExtraValue?: boolean;
        allowMultiple?: boolean;
        options?: ComplexTypes.ChoiceOption[];
        displayChoice?: DisplayChoice;
        enumTypeName?: string;
    }
 
    // Used in GenericContent, File, Resource
    export class NumberFieldSetting extends FieldSetting {
        MinValue?: number;
        MaxValue?: number;
        Digits?: number;
        ShowAsPercentage?: boolean;
        Step?: number;
 
        constructor(options: INumberFieldSettingOptions) {
            super(options);
            this.MinValue = options.minValue;
            this.MaxValue = options.maxValue;
            this.Digits = options.digits;
            this.ShowAsPercentage = options.showAsPercentage;
            this.Step = options.step;
        }
    }
 
    export interface INumberFieldSettingOptions extends IFieldSettingOptions {
        minValue?: number;
        maxValue?: number;
        digits?: number;
        showAsPercentage?: boolean;
        step?: number;
    }
 
    // Used in GenericContent
    export class RatingFieldSetting extends ShortTextFieldSetting {
        Range?: number;
        Split?: number;
 
        constructor(options: IRatingFieldSettingOptions) {
            super(options);
            this.Range = options.range;
            this.Split = options.split;
        }
    }
 
    export interface IRatingFieldSettingOptions extends IShortTextFieldSettingOptions {
        range?: number;
        split?: number;
    }
 
    // Used in User
    export class PasswordFieldSetting extends ShortTextFieldSetting {
        ReenterTitle?: string;
        ReenterDescription?: string;
        PasswordHistoryLength?: number;
 
        constructor(options: IPasswordFieldSettingOptions) {
            super(options);
            this.ReenterTitle = options.reenterTitle;
            this.ReenterDescription = options.reenterDescription;
            this.PasswordHistoryLength = options.passwordHistoryLength;
        }
    }
 
    export interface IPasswordFieldSettingOptions extends IShortTextFieldSettingOptions {
        reenterTitle?: string;
        reenterDescription?: string;
        passwordHistoryLength?: number;
    }
 
    // Used in User
    export class CaptchaFieldSetting extends FieldSetting {
 
        constructor(options: ICaptchaFieldSettingOptions) {
            super(options);
        }
    }
 
    export interface ICaptchaFieldSettingOptions extends IFieldSettingOptions {
    }