forms-angular 0.12.0-beta.31 → 0.12.0-beta.310

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,65 @@
1
1
  declare module fng {
2
- var formsAngular: angular.IModule;
2
+ export interface IFng extends angular.IModule {
3
+ beforeProcess?: (scope: IFormScope, cb: (err?: Error) => void) => void;
4
+ beforeHandleIncomingDataPromises?: () => angular.IPromise<any>[];
5
+ pseudo?: (token: string, upperFirst: boolean) => string;
6
+ title?: { prefix?: string; suffix?: string };
7
+ // when provided, the named function (assumed to be present on $rootscope) will be used to determine the visibility
8
+ // of menu items and control groups
9
+ hiddenSecurityFuncName?: string;
10
+ // when provided, the named function (assumed to be present on $rootscope) will be used to determine the disabled
11
+ // state of menu items and individual form input controls
12
+ disabledSecurityFuncName?: string;
13
+ // when provided, the named function (assumed to be present on $rootscope) will be called each time a new page
14
+ // or popup is accessed, providing the host app with the opportunity to confirm whether there are ANY hidden elements
15
+ // at all on that page. where there are not, we can optimise by skipping logic relating to DOM element visibility.
16
+ skipHiddenSecurityFuncName?: string;
17
+ // when provided, the named function (assumed to be present on $rootscope) will be called each time a new page
18
+ // or popup is accessed, providing the host app with the opportunity to confirm whether there are ANY disabled elements
19
+ // at all on that page. where there are not, we can optimise by skipping logic relating to disabling DOM elements.
20
+ skipDisabledSecurityFuncName?: string;
21
+ // when provided, the named function (assumed to be present on $rootscope) will be called each time a new page
22
+ // or popup is accessed, providing the host app with the opportunity to confirm whether there are ANY elements on that
23
+ // page that require their child elements to be disabled. where there are not, we can optimise by skipping
24
+ // disabled ancestor checks.
25
+ skipDisabledAncestorSecurityFuncName?: string;
26
+ // how the function identified by elemSecurityFuncName should be bound. "instant" means that it will be called
27
+ // as the markup is being constructed, with 'hidden' elements not included in the markup at all, and disabled elements
28
+ // given a simple DISABLED attribute. this is the most efficient approach. "one-time" will add ng-hide and
29
+ // ng-disabled directives to the relevant elements, with one-time binding to the security function. this is
30
+ // also reasonably efficient (but not as efficient as "instant", due to the need for watches). "normal" will not use
31
+ // one-time binding, which has the potential to be highly resource-intensive on large forms. which
32
+ // option is chosen will depend upon when the function identified by elemSecurityFuncName will be ready to
33
+ // make the necessary determination.
34
+ elemSecurityFuncBinding?: "instant" | "one-time" | "normal";
35
+ hideableAttr?: string; // an attribute to mark all elements that can be hidden using security
36
+ disableableAttr?: string; // an attribute to mark all elements that can be disabled using security
37
+ disableableAncestorAttr?: string; // an attribute to mark all elements whose children can all be disabled using "disabled + children" security
38
+ // if an element's id is a partial match on any of this array's contents, it will never be marked with hideableAttr/disableableAttr
39
+ ignoreIdsForHideableOrDisableableAttrs?: string[];
40
+ keyboardShortCuts? : {
41
+ letter: string;
42
+ keycode: number;
43
+ id: string;
44
+ desc: string;
45
+ } [];
46
+ }
47
+ var formsAngular: IFng;
3
48
 
4
49
  /*
5
50
  Type definitions for types that are used on both the client and the server
6
51
  */
52
+ type formStyle = "inline" | "vertical" | "horizontal" | "horizontalCompact" | "stacked";
53
+
54
+ export interface IBaseArrayLookupReference {
55
+ property: string;
56
+ value: string;
57
+ }
7
58
 
59
+ interface ILookupItem {
60
+ id: string;
61
+ text: string;
62
+ }
8
63
  /*
9
64
  IInternalLookupreference makes it possible to look up from a list (of key / value pairs) in the current record. For example
10
65
 
@@ -18,9 +73,8 @@ declare module fng {
18
73
  favouriteShelf: {type: Schema.Types.ObjectId, internalRef: {property: 'shelves', value:'location'};
19
74
  });
20
75
  */
21
- export interface IFngInternalLookupReference {
22
- property: string;
23
- value: string;
76
+ export interface IFngInternalLookupReference extends IBaseArrayLookupReference {
77
+ noConvert?: boolean; // can be used by a tricksy hack to get around nesting limitations
24
78
  }
25
79
 
26
80
  /*
@@ -33,14 +87,12 @@ declare module fng {
33
87
  shelf: {type: Schema.Types.ObjectId, lookupListRef: {collection:'k_referencing_self_collection', id:'$warehouse', property: 'shelves', value:'location'}},
34
88
  };
35
89
  */
36
- export interface IFngLookupListReference {
37
- collection: string; // collection that contains the list
90
+ export interface IFngLookupListReference extends IBaseArrayLookupReference {
91
+ collection: string; // collection that contains the list
38
92
  /*
39
93
  Some means of calculating _id in collection. If it starts with $ then it is property in record
40
94
  */
41
95
  id: string;
42
- property: string;
43
- value: string;
44
96
  }
45
97
 
46
98
  /*
@@ -59,7 +111,7 @@ declare module fng {
59
111
  */
60
112
  export interface IFngShowWhen {
61
113
  lhs: any;
62
- comp: 'eq' | 'ne' | 'gt' | 'gte' | 'lt' | 'lte';
114
+ comp: "eq" | "ne" | "gt" | "gte" | "lt" | "lte";
63
115
  rhs: any;
64
116
  }
65
117
 
@@ -67,11 +119,15 @@ declare module fng {
67
119
  link allows the setting up of hyperlinks for lookup reference fields
68
120
  */
69
121
  export interface IFngLinkSetup {
70
- linkOnly?: boolean; // if true (which at the time of writing is the only option supported) then the input element is not generated.
71
- form?: string; // can be used to generate a link to a custom schema
72
- text?: string; // the literal value used for the link. If this property is omitted then text is generated from the field values of the document referred to by the link.
122
+ linkOnly?: boolean; // if true then the input element is not generated (this overrides label)
123
+ label?: boolean; // Make a link out of the label (causes text to be overridden) (this overrides text)
124
+ form?: string; // can be used to generate a link to a custom schema
125
+ linktab?: string; // can be used to generate a link to a tab on a form
126
+ text?: string; // the literal value used for the link. If this property is omitted then text is generated from the field values of the document referred to by the link.
73
127
  }
74
128
 
129
+ export type FieldSizeString = "mini" | "small" | "medium" | "large" | "xlarge" | "xxlarge" | "block-level"; // sets control width. Default is 'medium''
130
+
75
131
  export interface IFngSchemaTypeFormOpts {
76
132
  /*
77
133
  The input type to be generated - which must be compatible with the Mongoose type.
@@ -90,34 +146,36 @@ declare module fng {
90
146
  */
91
147
  type?: string;
92
148
 
93
- hidden?: boolean; // inhibits this schema key from appearing on the generated form.
94
- label?: string | null; // overrides the default input label. label:null suppresses the label altogether.
95
- ref?: string; // reference to another collection
96
- internalRef? : IFngInternalLookupReference;
149
+ hidden?: boolean; // inhibits this schema key from appearing on the generated form.
150
+ label?: string | null; // overrides the default input label. label:null suppresses the label altogether.
151
+ ref?: string; // reference to another collection
152
+ internalRef?: IFngInternalLookupReference;
97
153
  lookupListRef?: IFngLookupListReference;
98
154
  id?: string; // specifies the id of the input field (which defaults to f_name)
99
155
 
100
- placeHolder?: string // adds placeholder text to the input (depending on data type).
101
- help?: string; // adds help text under the input.
102
- helpInline?: string; // adds help to the right of the input.
103
- popup?: string; // adds popup help as specified.
104
- order?: number; // allows user to specify the order / tab order of this field in the form. This overrides the position in the Mongoose schema.
105
- size?: 'mini' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge' | 'block-level'; // sets control width. Default is 'medium''
106
- readonly?: boolean; // adds the readonly attribute to the generated input (currently doesn't work with date - and perhaps other types).
107
- rows?: number | 'auto'; // sets the number of rows in inputs (such as textarea) that support this. Setting rows to "auto" makes the textarea expand to fit the content, rather than create a scrollbar.
108
- tab?: string; // Used to divide a large form up into a tabset with multiple tabs
109
- showWhen?: IFngShowWhen | string; // allows conditional display of fields based on values elsewhere. string must be an abular expression.
156
+ placeHolder?: string; // adds placeholder text to the input (depending on data type).
157
+ help?: string; // adds help text under the input.
158
+ helpInline?: string; // adds help to the right of the input.
159
+ popup?: string; // adds title (popup help) as specified.
160
+ ariaLabel?: string; // adds aria-label as specified.
161
+ order?: number; // allows user to specify the order / tab order of this field in the form. This overrides the position in the Mongoose schema.
162
+ size?: FieldSizeString;
163
+ readonly?: boolean | string; // adds the readonly or ng-readonly attribute to the generated input (currently doesn't work with date - and perhaps other types).
164
+ rows?: number | "auto"; // sets the number of rows in inputs (such as textarea) that support this. Setting rows to "auto" makes the textarea expand to fit the content, rather than create a scrollbar.
165
+ tab?: string; // Used to divide a large form up into a tabset with multiple tabs
166
+ showWhen?: IFngShowWhen | string; // allows conditional display of fields based on values elsewhere. string must be an abular expression.
110
167
 
111
168
  /*
112
169
  add: 'class="myClass"' allows custom styling of a specific input
113
170
  Angular model options can be used - for example add: 'ng-model-options="{updateOn: \'default blur\', debounce: { \'default\': 500, \'blur\': 0 }}" '
114
171
  custom validation directives, such as the timezone validation in this schema
115
172
  */
116
- add?: string; // allows arbitrary attributes to be added to the input tag.
173
+ add?: string; // allows arbitrary attributes to be added to the input tag.
117
174
 
118
- class?: string; // allows arbitrary classes to be added to the input tag.
119
- inlineRadio?: boolean; // (only valid when type is radio) should be set to true to present all radio button options in a single line
175
+ class?: string; // allows arbitrary classes to be added to the input tag.
176
+ inlineRadio?: boolean; // (only valid when type is radio) should be set to true to present all radio button options in a single line
120
177
  link?: IFngLinkSetup; // handles displaying links for ref lookups
178
+ asText?: boolean; // (only valid when type is ObjectId) should be set to true to force a simple text input rather than a select. presumed for advanced cases where the objectid is going to be pasted in.
121
179
 
122
180
  /*
123
181
  With a select / radio type you can specify the options.
@@ -140,11 +198,22 @@ declare module fng {
140
198
  /*
141
199
  The next few options relate to the handling and display of arrays (including arrays of subdocuments)
142
200
  */
143
- noAdd?: boolean; // inhibits an Add button being generated for arrays.
201
+ noAdd?: boolean | string; // inhibits an Add button being generated for arrays.
202
+ noneIndicator?: boolean; // show "None" where there's no add button and no array items
144
203
  unshift?: boolean; // (for arrays of sub documents) puts an add button in the sub schema header which allows insertion of new sub documents at the beginning of the array.
145
- noRemove?: boolean; // inhibits a Remove button being generated for array elements.
146
- formstyle?: 'inline' | 'vertical' | 'horizontal' | 'horizontalCompact'; // (only valid on a sub schema) sets style of sub form.
147
- sortable? : boolean; // Allows drag and drop sorting of arrays - requires angular-ui-sortable
204
+ noRemove?: boolean | string; // inhibits a Remove button being generated for array elements.
205
+ formstyle?: formStyle; // (only valid on a sub schema) sets style of sub form.
206
+ sortable?: boolean | string; // Allows drag and drop sorting of arrays - requires angular-ui-sortable
207
+ ngClass?: string; // Allows for conditional per-item styling through the addition of an ng-class expression to the class list of li elements created for each item in the array
208
+ filterable?: boolean; // Add a data-ng-hide to all array elements, referring to subDoc._hidden. Does not actually (yet) provide a UI for managing this property, however (which needs to be done via an external directive)
209
+ subDocContainerType?:
210
+ | "fieldset"
211
+ | "well"
212
+ | "well-large"
213
+ | "well-small"
214
+ | string
215
+ | ((info) => { before: ""; after: "" }); // allows each element in the array to be nested in a container
216
+ subDocContainerProps?: any; // the parameters that will be passed if subDocContainerType is a function
148
217
 
149
218
  /*
150
219
  The next section relates to the display of sub documents
@@ -152,6 +221,12 @@ declare module fng {
152
221
  customSubDoc?: string; // Allows you to specify custom HTML (which may include directives) for the sub doc
153
222
  customHeader?: string; // Allows you to specify custom HTML (which may include directives) for the header of a group of sub docs
154
223
  customFooter?: string; // Allows you to specify custom HTML (which may include directives) for the footer of a group of sub docs
224
+
225
+ /*
226
+ Suppresses warnings about attenpting deep nesting which would be logged to console in some circumstances when a
227
+ directive fakes deep nesting
228
+ */
229
+ suppressNestingWarning?: boolean;
155
230
  }
156
231
 
157
232
  // Schema passed from server - derived from Mongoose schema
@@ -159,30 +234,56 @@ declare module fng {
159
234
  name: string;
160
235
  schema?: Array<IFieldViewInfo>;
161
236
  array?: boolean;
162
- showIf? : any;
237
+ showIf?: any;
163
238
  required?: boolean;
164
- step? : number;
239
+ step?: number;
165
240
  }
166
241
 
242
+ export type fieldType =
243
+ | "string"
244
+ | "text"
245
+ | "textarea"
246
+ | "number"
247
+ | "select"
248
+ | "link"
249
+ | "date"
250
+ | "checkbox"
251
+ | "password"
252
+ | "radio";
253
+
167
254
  // Schema used internally on client - often derived from IFieldViewInfo passed from server
168
255
  export interface IFormInstruction extends IFieldViewInfo {
169
- id? : string; // id of generated DOM element
170
- type?: 'string' | 'text' | 'textarea' | 'number' | 'select' | 'link' | 'date' | 'checkbox' | 'password';
171
- rows? : number
172
- label: string;
256
+ id?: string; // id of generated DOM element
257
+ nonUniqueId?: string; // where this field is part of a sub-sub-schema, id is likely to include $index from the sub-schema, to ensure uniqueness. provide it here without reference to $parent.$index for use in security evaluations.
258
+ type?: fieldType;
259
+ defaultValue?: any;
260
+ rows?: number;
261
+ label?: string;
173
262
  options?: any;
174
263
  ids?: any;
175
264
  hidden?: boolean;
176
265
  tab?: string;
177
- add? : string;
178
- ref? : any;
179
- link? : any;
180
- linkText?: string;
181
- form?: string; // the form that is linked to
182
- select2? : any; // deprecated
183
- schema?: IFormInstruction[]; // If the field is an array of fields
266
+ add?: string;
267
+ ref?: any;
268
+ link?: any;
269
+ linktext?: string;
270
+ linklabel?: boolean;
271
+ form?: string; // the form that is linked to
272
+ select2?: any; // deprecated
273
+ schema?: IFormInstruction[]; // If the field is an array of fields
274
+ intType?: "date";
275
+ coloffset?: number;
276
+ [directiveOptions: string]: any;
277
+ }
278
+
279
+ interface IContainerInstructions {
280
+ before?: string;
281
+ after?: string;
282
+ omit?: boolean;
184
283
  }
185
284
 
285
+ export type HiddenTabReintroductionMethod = "none" | "tab";
286
+
186
287
  export interface IContainer {
187
288
  /*
188
289
  Type of container, which determines markup. This is currently only available when the schema is generated by
@@ -190,15 +291,25 @@ declare module fng {
190
291
  In the case of a string which does not match one of the predefined options
191
292
  the generated container div is given the class of the name
192
293
  */
193
- containerType: 'fieldset' | 'well' | 'tabset' | 'tab' | 'well-large' | 'well-small' | string;
294
+ containerType: "fieldset" | "well" | "tabset" | "tab" | "+tab" | "well-large" | "well-small" | string | ((info: IContainer) => IContainerInstructions);
194
295
  title?: string;
195
-
296
+ /*
297
+ Applies only to tabs - causing them to be rendered with a x for closing ('hiding') the tab in question.
298
+ Where hideable is true, hiddenTabArrayProp can be used to specify a property name (which can include ".", and which
299
+ will be assumed to identiy an array) that should be used to store the ids of closed ('hidden') tabs.
300
+ Where this is not specified, record.hiddenTabs will be used.
301
+ If hiddenTabReintroductionMethod is set to "tab", an additional tab will be added to the end of the tabset
302
+ with a + heading, and clicking on this will provide a UI for re-introducing hidden tabs.
303
+ */
304
+ hideable?: boolean;
305
+ hiddenTabArrayProp?: string;
306
+ hiddenTabReintroductionMethod?: HiddenTabReintroductionMethod;
196
307
  /*
197
308
  h1...h6 will use a header style
198
309
  anything else will be used as a paragraph stype
199
310
  */
200
- titleTagOrClass? : string;
201
- content: IFormInstruction[];
311
+ titleTagOrClass?: string;
312
+ content: IFormSchemaElement[];
202
313
  }
203
314
 
204
315
  export type IFormSchemaElement = IFormInstruction | IContainer;
@@ -209,57 +320,85 @@ declare module fng {
209
320
  export interface IEnumInstruction {
210
321
  repeat: string;
211
322
  value: string;
212
- label? : string;
323
+ label?: string;
213
324
  }
214
325
 
215
326
  export interface IFngCtrlState {
216
327
  master: any;
217
- allowLocationChange: boolean; // Do we allow location change or prompt for permission
328
+ allowLocationChange: boolean; // Do we allow location change or prompt for permission
218
329
  }
219
- export interface IRecordHandler {
330
+ export interface IRecordHandlerService {
220
331
  convertToMongoModel(schema: IControlledFormSchema, anObject: any, prefixLength: number, scope: IFormScope): any;
221
332
  createNew(dataToSave: any, options: any, scope: IFormScope, ctrlState: IFngCtrlState): void;
222
- deleteRecord(model: any, id: any, scope: IFormScope, ctrlState: any): void;
223
- updateDocument(dataToSave : any, options: any, scope: IFormScope, ctrlState: IFngCtrlState) : void;
224
- readRecord($scope: IFormScope, ctrlState);
333
+ deleteRecord(id: string, scope: IFormScope, ctrlState: IFngCtrlState): void;
334
+ updateDocument(dataToSave: any, options: any, scope: IFormScope, ctrlState: IFngCtrlState): void;
335
+ beginReadingRecord($scope: IFormScope): void;
336
+ finishReadingThenProcessRecord($scope: IFormScope, ctrlState): void;
225
337
  scrollTheList($scope: IFormScope);
226
338
  getListData(record, fieldName, listSchema?, $scope?: IFormScope);
227
339
  suffixCleanId(inst, suffix);
228
- setData(object, fieldname, element, value);
340
+ setData(object, fieldname: string, element, value);
341
+ getData(object, fieldname: string, element?: any);
229
342
  setUpLookupOptions(lookupCollection, schemaElement, $scope: IFormScope, ctrlState, handleSchema);
230
- setUpLookupListOptions: (ref: IFngLookupListReference, formInstructions: IFormInstruction, $scope: IFormScope, ctrlState: IFngCtrlState) => void;
343
+ setUpLookupListOptions: (
344
+ ref: IFngLookupListReference,
345
+ formInstructions: IFormInstruction,
346
+ $scope: IFormScope,
347
+ ctrlState: IFngCtrlState
348
+ ) => void;
231
349
  handleInternalLookup($scope: IFormScope, formInstructions, ref): void;
232
350
  preservePristine(element, fn): void;
233
351
  convertIdToListValue(id, idsArray, valuesArray, fname);
234
- decorateScope($scope:IFormScope, $uibModal, recordHandlerInstance : IRecordHandler, ctrlState);
235
- fillFormFromBackendCustomSchema(schema, $scope:IFormScope, formGeneratorInstance, recordHandlerInstance, ctrlState);
352
+ decorateScope($scope: IFormScope, $uibModal, recordHandlerInstance: IRecordHandlerService, ctrlState);
353
+ fillFormFromBackendCustomSchema(
354
+ schema,
355
+ $scope: IFormScope,
356
+ formGeneratorInstance,
357
+ recordHandlerInstance,
358
+ ctrlState
359
+ );
236
360
  fillFormWithBackendSchema($scope: IFormScope, formGeneratorInstance, recordHandlerInstance, ctrlState);
237
361
  handleError($scope: IFormScope);
362
+ convertToAngularModel($scope: IFormScope);
363
+ convertToAngularModelWithSchema(schema: IControlledFormSchema, data, $scope: IFormScope)
238
364
  }
239
365
 
240
- export interface IFormGenerator {
241
- generateEditUrl(obj, $scope:IFormScope): string;
366
+ export interface IFormGeneratorService {
367
+ generateEditUrl(obj, $scope: IFormScope): string;
368
+ generateViewUrl(obj, $scope: IFormScope): string;
242
369
  generateNewUrl($scope: IFormScope): string;
243
370
  handleFieldType(formInstructions, mongooseType, mongooseOptions, $scope: IFormScope, ctrlState);
244
- handleSchema(description: string, source, destForm, destList, prefix, doRecursion: boolean, $scope: IFormScope, ctrlState);
371
+ handleSchema(
372
+ description: string,
373
+ source,
374
+ destForm,
375
+ destList,
376
+ prefix,
377
+ doRecursion: boolean,
378
+ $scope: IFormScope,
379
+ ctrlState
380
+ );
245
381
  updateDataDependentDisplay(curValue, oldValue, force, $scope: IFormScope);
246
- add(fieldName, $event, $scope: IFormScope);
247
- unshift(fieldName, $event, $scope: IFormScope);
248
- remove(fieldName, value, $event, $scope: IFormScope);
382
+ add(fieldName: string, $event, $scope: IFormScope, modelOverride?: any);
383
+ unshift(fieldName: string, $event, $scope: IFormScope, modelOverride?: any);
384
+ remove(fieldName: string, value, $event, $scope: IFormScope, modelOverride?: any);
249
385
  hasError(formName, name, index, $scope: IFormScope);
250
- decorateScope($scope: IFormScope, formGeneratorInstance, recordHandlerInstance: IRecordHandler, sharedStuff);
386
+ decorateScope($scope: IFormScope, formGeneratorInstance: IFormGeneratorService, recordHandlerInstance: IRecordHandlerService, sharedStuff, pseudoUrl?: string);
251
387
  }
252
388
 
253
389
  export interface IFngSingleLookupHandler {
254
390
  formInstructions: IFormInstruction;
255
391
  lastPart: string;
256
392
  possibleArray: string;
393
+ // If the looked-up record changes, we use these fields to see if the old lookup value also exists in the new lookup record
394
+ oldValue?: string | string[];
395
+ oldId?: string | string[];
257
396
  }
258
397
 
259
398
  export interface IFngLookupHandler {
260
399
  lookupOptions: string[];
261
400
  lookupIds: string[];
262
- handlers: IFngSingleLookupHandler[]
401
+ handlers: IFngSingleLookupHandler[];
263
402
  }
264
403
 
265
404
  export interface IFngInternalLookupHandlerInfo extends IFngLookupHandler {
@@ -270,16 +409,32 @@ declare module fng {
270
409
  ref: IFngLookupListReference;
271
410
  }
272
411
 
412
+ // we cannot use an enum here, so this will have to do. these are the values expected to be returned by the
413
+ // function on $rootScope with the name formsAngular.disabledSecurityFuncName.
414
+ // false = not disabled,
415
+ // true = disabled,
416
+ // "+" = this and all child elements disabled
417
+ export type DisabledOutcome = boolean | "+";
418
+
419
+ export interface ISecurableScope extends angular.IScope {
420
+ // added by ISecurityService
421
+ isSecurelyHidden: (elemId: string) => boolean;
422
+ isSecurelyDisabled: (elemId: string) => boolean;
423
+ requiresDisabledChildren: (elemId: string) => boolean;
424
+ }
425
+
273
426
  /*
274
427
  The scope which contains form data
275
428
  */
276
- export interface IFormScope extends angular.IScope {
429
+ export interface IFormScope extends ISecurableScope {
277
430
  sharedData: any;
278
- modelNameDisplay : string;
431
+ modelNameDisplay: string;
279
432
  modelName: string;
280
433
  formName: string;
281
434
  alertTitle: any;
435
+ errorVisible: boolean;
282
436
  errorMessage: any;
437
+ errorHideTimer: number;
283
438
  save: any;
284
439
  newRecord: boolean;
285
440
  initialiseNewRecord?: any;
@@ -290,17 +445,16 @@ declare module fng {
290
445
  isCancelDisabled: any;
291
446
  isNewDisabled: any;
292
447
  isSaveDisabled: any;
293
- disabledText: any;
448
+ whyDisabled: string;
294
449
  unconfirmedDelete: boolean;
295
450
  getVal: any;
296
451
  sortableOptions: any;
297
- tabDeselect: any;
298
- tabs?: Array<any>; // In the case of forms that contain a tab set
299
- tab?: string; // title of the active tab - from the route
452
+ tabs?: Array<any>; // In the case of forms that contain a tab set
453
+ tab?: string; // title of the active tab - from the route
300
454
  activeTabNo?: number;
301
- topLevelFormName: string; // The name of the form
455
+ topLevelFormName: string; // The name of the form
302
456
  record: any;
303
- originalData: any; // the unconverted data read from the server
457
+ originalData: any; // the unconverted data read from the server
304
458
  phase: any;
305
459
  disableFunctions: any;
306
460
  dataEventFunctions: any;
@@ -312,13 +466,18 @@ declare module fng {
312
466
  conversions: any;
313
467
  pageSize: any;
314
468
  pagesLoaded: any;
469
+ redirectOptions?: { redirect?: string; allowChange?: boolean };
315
470
  cancel: () => any;
316
- showError: (error: any, alertTitle? : string) => void;
471
+ showError: (error: any, alertTitle?: string) => void;
317
472
  prepareForSave: (cb: (error: string, dataToSave?: any) => void) => void;
473
+ setDefaults: (formSchema: IFormSchema, base?: string) => any;
318
474
  formSchema: IControlledFormSchema;
319
475
  baseSchema: () => Array<any>;
320
476
  setFormDirty: any;
477
+ dirtyChecked?: boolean;
321
478
  add: any;
479
+ hideTab: (event, tabTitle: string, hiddenTabArrayProp: string) => void;
480
+ addTab: (event, tabTitle: string, hiddenTabArrayProp: string) => void;
322
481
  hasError: any;
323
482
  unshift: any;
324
483
  remove: any;
@@ -327,23 +486,40 @@ declare module fng {
327
486
  skipCols: any;
328
487
  setPristine: any;
329
488
  generateEditUrl: any;
489
+ generateViewUrl: any;
330
490
  generateNewUrl: any;
331
491
  scrollTheList: any;
332
492
  getListData: any;
333
- dismissError: any;
493
+ phaseWatcher: any;
494
+ dismissError: () => void;
495
+ stickError: () => void;
496
+ clearTimeout: () => void;
334
497
  handleHttpError: (response: any) => void;
335
498
  dropConversionWatcher: () => void;
499
+ readingRecord?: angular.IPromise<any>;
500
+ onSchemaFetch?: (description: string, source: IFieldViewInfo[]) => void;
501
+ onSchemaProcessed?: (description: string, formSchema: IFormInstruction[]) => void;
502
+ updateQueryForTab?: (tab: string) => void;
503
+ showLoading? : boolean; // a spinner that fades in
504
+ showSpinner? : boolean; // an immediate spinner
505
+ tabDeselect?: ($event: any, $selectedIndex: number) => void;
506
+ setUpCustomLookupOptions?: (
507
+ schemaElement: IFormInstruction,
508
+ ids: string[],
509
+ options: string[],
510
+ baseScope: any
511
+ ) => void;
336
512
  }
337
513
 
338
514
  export interface IContextMenuDivider {
339
515
  divider: boolean;
340
516
  }
341
- export interface IContextMenuOption {
342
- // For it to make any sense, a menu option needs one of the next two properties
343
- url?: string;
344
- fn?: () => void;
517
+ export interface IContextMenuBaseOption {
518
+ // provided to the security hook (see elemSecurityFuncName) - optional where that is not being used
519
+ id?: string;
345
520
 
346
- text: string;
521
+ text?: string;
522
+ textFunc?: () => string;
347
523
  isDisabled?: () => boolean;
348
524
  isHidden?: () => boolean;
349
525
 
@@ -352,11 +528,28 @@ declare module fng {
352
528
  creating: boolean;
353
529
  editing: boolean;
354
530
  }
531
+ export interface IContextSubMenuOption extends IContextMenuBaseOption {
532
+ items: ContextMenuItem[];
533
+ }
534
+ export interface IContextMenuOption extends IContextMenuBaseOption{
535
+ // For it to make any sense, a menu option needs one of the next three properties
536
+ url?: string;
537
+ fn?: (...args: any) => void;
538
+ urlFunc?: () => string;
539
+ broadcast?: string;
540
+ args?: any[];
541
+ }
542
+ export type ContextMenuItem = IContextMenuOption | IContextSubMenuOption | IContextMenuDivider;
543
+
544
+ export interface IModelCtrlService {
545
+ loadControllerAndMenu: (sharedData: any, titleCaseModelName: string, level: number, needDivider: boolean, scope: angular.IScope) => void;
546
+ }
355
547
 
356
548
  export interface IModelController extends IFormScope {
357
- onBaseCtrlReady? : (baseScope: IFormScope) => void; // Optional callback after form is instantiated
358
- onAllReady? : (baseScope: IFormScope) => void; // Optional callback after form is instantiated and populated
359
- contextMenu? : Array<IContextMenuOption | IContextMenuDivider>
549
+ onBaseCtrlReady?: (baseScope: IFormScope) => void; // Optional callback after form is instantiated
550
+ onAllReady?: (baseScope: IFormScope) => void; // Optional callback after form is instantiated and populated
551
+ contextMenu?: ContextMenuItem[];
552
+ contextMenuPromise?: Promise<ContextMenuItem[]>;
360
553
  }
361
554
 
362
555
  export interface IBaseFormOptions {
@@ -364,13 +557,13 @@ declare module fng {
364
557
  * The style of the form layout. Supported values are horizontalcompact, horizontal, vertical, inline
365
558
  */
366
559
  //TODO supported values should be in an enum
367
- formstyle?: string;
560
+ formstyle?: formStyle;
368
561
  /**
369
562
  * Model on form scope (defaults to record).
370
563
  * <li><strong>model</strong> the object in the scope to be bound to the model controller. Specifying
371
564
  * the model inhibits the generation of the <strong>form</strong> tag unless the <strong>forceform</strong> attribute is set to true</li>
372
565
  */
373
- model? : string;
566
+ model?: string;
374
567
  /**
375
568
  * The name to be given to the form - defaults to myForm
376
569
  */
@@ -379,60 +572,272 @@ declare module fng {
379
572
  * Normally first field in a form gets autofocus set. Use this to prevent this
380
573
  */
381
574
  noautofocus?: string;
575
+ /*
576
+ Suppress the generation of element ids
577
+ (sometimes required when using nested form-inputs in a directive)
578
+ */
579
+ noid?: boolean;
382
580
  }
383
581
 
384
582
  export interface IFormAttrs extends IFormOptions, angular.IAttributes {
385
583
  /**
386
584
  * Schema used by the form
387
585
  */
388
- schema : string;
389
- forceform?: string; // Must be true or omitted. Forces generation of the <strong>form</strong> tag when model is specified
586
+ schema: string;
587
+ forceform?: string; // Must be true or omitted. Forces generation of the <strong>form</strong> tag when model is specified
588
+ noid?: boolean;
390
589
  }
391
590
 
392
591
  export interface IFormOptions extends IBaseFormOptions {
393
- schema? : string;
592
+ schema?: string;
394
593
  subkey?: string;
395
594
  subkeyno?: number;
396
- subschema? : string;
397
- subschemaroot? : string;
595
+ subschema?: string;
596
+ subschemaroot?: string;
597
+ viewform?: boolean;
598
+ suppressNestingWarning?: boolean;
398
599
  }
399
600
 
400
601
  export interface IBuiltInRoute {
401
602
  route: string;
402
- state: string;
403
- templateUrl: string;
404
- options? : any;
603
+ state?: string;
604
+ templateUrl?: string;
605
+ options?: {
606
+ authenticate?: boolean;
607
+ templateUrl?: string | (() => void);
608
+ template?: string;
609
+ controller?: string;
610
+ }
405
611
  }
406
612
 
407
613
  export interface IRoutingConfig {
408
- hashPrefix: string;
614
+ hashPrefix?: string;
409
615
  html5Mode: boolean;
410
- routing: string; // What sort of routing do we want? ngroute or uirouter.
411
- // TODO Should be enum
412
- prefix: string; // How do we want to prefix out routes? If not empty string then first character must be slash (which is added if not)
413
- // for example '/db' that gets prepended to all the generated routes. This can be used to
414
- // prevent generated routes (which have a lot of parameters) from clashing with other routes in
415
- // the web app that have nothing to do with CRUD forms
616
+ routing: string; // What sort of routing do we want? ngroute or uirouter.
617
+ // TODO Should be enum
618
+ prefix: string; // How do we want to prefix out routes? If not empty string then first character must be slash (which is added if not)
619
+ // for example '/db' that gets prepended to all the generated routes. This can be used to
620
+ // prevent generated routes (which have a lot of parameters) from clashing with other routes in
621
+ // the web app that have nothing to do with CRUD forms
416
622
  fixedRoutes?: Array<IBuiltInRoute>;
417
- templateFolder?: string; // The folder where the templates for base-list, base-edit and base-analysis live. Internal templates used by default. For pre 0.7.0 behaviour use 'partials/'
418
- add2fngRoutes?: any; // An object to add to the generated routes. One use case would be to add {authenticate: true}
419
- // so that the client authenticates for certain routes
623
+ templateFolder?: string; // The folder where the templates for base-list, base-edit and base-analysis live. Internal templates used by default. For pre 0.7.0 behaviour use 'partials/'
624
+ add2fngRoutes?: any; // An object to add to the generated routes. One use case would be to add {authenticate: true}
625
+ // so that the client authenticates for certain routes
420
626
 
421
- variantsForDemoWebsite? : any; // Just for demo website
422
- variants?: any; // Just for demo website
627
+ variantsForDemoWebsite?: any; // Just for demo website
628
+ variants?: any; // Just for demo website
629
+ onDelete?: string; // Supports literal (such as '/') or 'new' (which will go to a /new of the model) default is to go to the list view
423
630
  }
424
631
 
425
632
  export interface IFngRoute {
426
- newRecord?: boolean;
427
- analyse?: boolean;
428
- modelName?: string;
429
- reportSchemaName? : string;
430
- id? : string;
431
- formName? : string;
432
- tab? : string;
433
- variant? : string; // TODO should be enum of supported frameworks
633
+ newRecord?: boolean;
634
+ analyse?: boolean;
635
+ modelName?: string;
636
+ reportSchemaName?: string;
637
+ id?: string;
638
+ formName?: string;
639
+ tab?: string;
640
+ variant?: string; // TODO should be enum of supported frameworks
641
+ }
642
+
643
+ interface IBuildingBlocks {
644
+ common: string;
645
+ sizeClassBS3: string;
646
+ sizeClassBS2: string;
647
+ compactClass: string;
648
+ formControl: string;
649
+ modelString: string;
650
+ disableableAncestorStr: string;
651
+ }
652
+
653
+ interface IProcessedAttrs {
654
+ info: IFormInstruction;
655
+ options: IFormOptions;
656
+ directiveOptions: any;
657
+ }
658
+
659
+ interface IGenDisableStrParams {
660
+ forceNg?: boolean;
661
+ nonUniqueIdSuffix?: string;
662
+ }
663
+
664
+
665
+ interface IPluginHelperService {
666
+ extractFromAttr: (
667
+ attr: any,
668
+ directiveName: string,
669
+ scope: fng.IFormScope
670
+ ) => { info: IFormInstruction; options: IFormOptions; directiveOptions: any };
671
+ buildInputMarkup: (
672
+ scope: angular.IScope,
673
+ attrs: any,
674
+ params: {
675
+ processedAttrs?: IProcessedAttrs;
676
+ fieldInfoOverrides?: Partial<IFormInstruction>;
677
+ optionOverrides?: Partial<IFormOptions>;
678
+ addButtons?: boolean;
679
+ needsX?: boolean;
680
+ },
681
+ generateInputControl: (buildingBlocks: IBuildingBlocks) => string
682
+ ) => string;
683
+ genIdString: (scope: angular.IScope, processedAttrs: IProcessedAttrs, idSuffix: string) => string;
684
+ genDisabledStr: (
685
+ scope: angular.IScope,
686
+ processedAttrs: IProcessedAttrs,
687
+ idSuffix: string,
688
+ params?: fng.IGenDisableStrParams
689
+ ) => string;
690
+ genIdAndDisabledStr: (
691
+ scope: angular.IScope,
692
+ processedAttrs: IProcessedAttrs,
693
+ idSuffix: string,
694
+ params?: fng.IGenDisableStrParams
695
+ ) => string;
696
+ genDateTimePickerDisabledStr: (scope: angular.IScope, processedAttrs: IProcessedAttrs, idSuffix: string) => string;
697
+ genDateTimePickerIdAndDisabledStr: (
698
+ scope: angular.IScope,
699
+ processedAttrs: IProcessedAttrs,
700
+ idSuffix: string
701
+ ) => string;
702
+ genUiSelectIdAndDisabledStr: (
703
+ scope: angular.IScope,
704
+ processedAttrs: IProcessedAttrs,
705
+ idSuffix: string
706
+ ) => string;
707
+ handlePseudos: (scope: fng.IFormScope, str: string) => string;
708
+ genDisableableAncestorStr: (processedAttrs: IProcessedAttrs) => string;
709
+ }
710
+
711
+ interface ISecurityVisibility {
712
+ omit?: boolean;
713
+ visibilityAttr?: string;
714
+ }
715
+
716
+ interface IGenerateDisableAttrParams {
717
+ attr?: string;
718
+ attrRequiresValue?: boolean;
719
+ forceNg?: boolean;
720
+ }
721
+
722
+ type SecurityType = "hidden" | "disabled";
723
+
724
+ interface ISecurityService {
725
+ canDoSecurity: (type: SecurityType) => boolean;
726
+ canDoSecurityNow: (scope: fng.ISecurableScope, type: SecurityType) => boolean;
727
+ isSecurelyHidden: (elemId: string, pseudoUrl?: string) => boolean;
728
+ isSecurelyDisabled: (elemId: string, pseudoUrl?: string) => boolean;
729
+ decorateSecurableScope: (securableScope: ISecurableScope, params?: { pseudoUrl?: string, overrideSkipping?: boolean }) => void;
730
+ doSecurityWhenReady: (cb: () => void) => void;
731
+ considerVisibility: (id: string, scope: fng.ISecurableScope) => ISecurityVisibility;
732
+ considerContainerVisibility: (contentIds: string[], scope: fng.ISecurableScope) => fng.ISecurityVisibility;
733
+ getDisableableAttrs: (id: string) => string;
734
+ getHideableAttrs: (id: string) => string;
735
+ getDisableableAncestorAttrs: (id: string) => string;
736
+ generateDisabledAttr: (id: string, scope: fng.ISecurableScope, params?: IGenerateDisableAttrParams) => string;
434
737
  }
435
738
 
739
+ interface IListQueryOptions {
740
+ limit?: number;
741
+ find?: any; // e.g., { "careWorker.isCareWorker": true }
742
+ aggregate?: any;
743
+ projection?: any;
744
+ order?: any; // e.g., { familyName: -1, givenName: -1 }
745
+ skip?: number;
746
+ concatenate?: boolean; // whether the list fields should be concatenated into a single .text property
747
+ }
748
+
749
+ interface ISubmissionsService {
750
+ // return all of the list attributes of the record from db.<modelName>.<id>
751
+ // where returnRaw is true, the document (albeit with only its list attributes present) will be returned without transformation
752
+ // otherwise, the list fields will be concatenated (space-seperated) and returned as the list property of a record { list: string }
753
+ // e.g., "John Doe", in the case of a person
754
+ getListAttributes: (
755
+ modelName: string,
756
+ id: string,
757
+ returnRaw?: boolean
758
+ ) => angular.IHttpPromise<{ list: string } | any>;
759
+ readRecord: (modelName: string, id: string, formName?: string) => angular.IHttpPromise<any>;
760
+ getAll: (modelName: string, _options: any) => angular.IHttpPromise<any[]>;
761
+ getAllListAttributes: (ref: string) => angular.IHttpPromise<ILookupItem[]>;
762
+ getPagedAndFilteredList: (
763
+ modelName: string,
764
+ options: IListQueryOptions
765
+ ) => angular.IHttpPromise<any[]>;
766
+ getPagedAndFilteredListFull: (
767
+ modelName: string,
768
+ options: IListQueryOptions
769
+ ) => angular.IHttpPromise<any[]>;
770
+ deleteRecord: (model: string, id: string, formName: string) => angular.IHttpPromise<void>;
771
+ updateRecord: (modelName: string, id: string, dataToSave: any, formName?: string) => angular.IHttpPromise<any>;
772
+ createRecord: (modelName: string, dataToSave: any, formName?: string) => angular.IHttpPromise<any>;
773
+ useCache: (val: boolean) => void;
774
+ clearCache: () => void;
775
+ getCache: () => boolean;
776
+ }
777
+
778
+ interface IRoutingServiceProvider {
779
+ start: (options: IRoutingConfig) => void;
780
+ addRoutes: (fixedRoutes: Array<IBuiltInRoute>, fngRoutes:Array<IBuiltInRoute>) => void;
781
+ registerAction: (action: string) => void;
782
+ $get: () => IRoutingService;
783
+ }
784
+
785
+ interface IRoutingService {
786
+ router: () => string;
787
+ prefix: () => string;
788
+ parsePathFunc: () => (location: string) => void;
789
+ html5hash: () => string;
790
+ buildUrl: (path: string) => string;
791
+ buildOperationUrl: (
792
+ prefix: string,
793
+ operation: string,
794
+ modelName: string,
795
+ formName: string,
796
+ id: string,
797
+ tabName?: string
798
+ ) => string;
799
+ redirectTo: () => (operation: string, scope: IFormScope, LocationService: angular.ILocationService, id?: string, tab?: string) => void;
800
+ }
801
+
802
+ interface ICssFrameworkServiceProvider {
803
+ setOptions: (options: { framework: string }) => void;
804
+ $get: () => ICssFrameworkService;
805
+ }
806
+
807
+ interface ICssFrameworkService {
808
+ framework: () => string;
809
+ span: (cols: number) => string;
810
+ offset: (cols: number) => string;
811
+ rowFluid: () => string;
812
+ }
813
+
814
+ interface IFngUiSelectHelperService {
815
+ windowChanged: (width: number, height: number) => boolean;
816
+ addClientLookup: (lkpName: string, lkpData: any) => void;
817
+ clearCache: () => void;
818
+ lookupFunc: (value: string, formSchema: IFormInstruction, cb: (formSchema: IFormInstruction, value: ILookupItem ) => void) => void;
819
+ doOwnConversion: (scope: IFormScope, processedAttrs: any, ref: string) => void;
820
+ }
821
+
822
+ interface IFormMarkupHelperService {
823
+ isHorizontalStyle: (formStyle: string, includeStacked: boolean) => boolean;
824
+ isArrayElement: (scope: angular.IScope, info: fng.IFormInstruction, options: fng.IFormOptions) => boolean;
825
+ fieldChrome: (scope: fng.IFormScope, info: fng.IFormInstruction, options: fng.IFormOptions) => { omit?: boolean, template?: string, closeTag?: string };
826
+ label: (scope: fng.IFormScope, fieldInfo: fng.IFormInstruction, addButtonMarkup: boolean, options: fng.IFormOptions) => string;
827
+ glyphClass: () => string;
828
+ allInputsVars: (scope: angular.IScope, fieldInfo: fng.IFormInstruction, options: fng.IFormOptions, modelString: string, idString: string, nameString: string) => Partial<fng.IBuildingBlocks>;
829
+ inputChrome: (value: string, fieldInfo: fng.IFormInstruction, options: fng.IFormOptions, markupVars) => string;
830
+ generateSimpleInput: (common: string, fieldInfo: fng.IFormInstruction, options: fng.IFormOptions) => string;
831
+ controlDivClasses: (options: fng.IFormOptions, fieldInfo: fng.IFormInstruction) => string[];
832
+ handleInputAndControlDiv: (inputMarkup: string, controlDivClasses: string[]) => string;
833
+ handleArrayInputAndControlDiv: (inputMarkup: string, controlDivClasses: string[], scope: fng.IFormScope, info: fng.IFormInstruction, options: fng.IFormOptions) => string;
834
+ addTextInputMarkup: (allInputsVars: Partial<fng.IBuildingBlocks>, fieldInfo: fng.IFormInstruction, requiredStr: string) => string;
835
+ handleReadOnlyDisabled: (partialFieldInfo: { name: string, id?: string, nonUniqueId?: string, readonly?: boolean | string }, scope: fng.IFormScope) => string[];
836
+ generateArrayElementIdString: (idString: string, info: fng.IFormInstruction, options: fng.IFormOptions) => string;
837
+ genDisableableAncestorStr: (id: string) => string;
838
+ generateNgShow: (showWhen: IFngShowWhen, model: string) => string;
839
+ handlePseudos: (scope: fng.IFormScope, str: string, dynamicFuncName?: string) => string;
840
+ }
436
841
  }
437
842
 
438
- declare var formsAngular: angular.IModule;
843
+ declare var formsAngular: fng.IFng;