forms-angular 0.12.0-beta.29 → 0.12.0-beta.290

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,17 +198,35 @@ 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
151
220
  */
152
221
  customSubDoc?: string; // Allows you to specify custom HTML (which may include directives) for the sub doc
222
+ customHeader?: string; // Allows you to specify custom HTML (which may include directives) for the header of a group of sub docs
153
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;
154
230
  }
155
231
 
156
232
  // Schema passed from server - derived from Mongoose schema
@@ -158,30 +234,56 @@ declare module fng {
158
234
  name: string;
159
235
  schema?: Array<IFieldViewInfo>;
160
236
  array?: boolean;
161
- showIf? : any;
237
+ showIf?: any;
162
238
  required?: boolean;
163
- step? : number;
239
+ step?: number;
164
240
  }
165
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
+
166
254
  // Schema used internally on client - often derived from IFieldViewInfo passed from server
167
255
  export interface IFormInstruction extends IFieldViewInfo {
168
- id? : string; // id of generated DOM element
169
- type?: 'string' | 'text' | 'textarea' | 'number' | 'select' | 'link' | 'date' | 'checkbox' | 'password';
170
- rows? : number
171
- 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;
172
262
  options?: any;
173
263
  ids?: any;
174
264
  hidden?: boolean;
175
265
  tab?: string;
176
- add? : string;
177
- ref? : any;
178
- link? : any;
179
- linkText?: string;
180
- form?: string; // the form that is linked to
181
- select2? : any; // deprecated
182
- schema?: Array<IFormInstruction>;
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;
183
283
  }
184
284
 
285
+ export type HiddenTabReintroductionMethod = "none" | "tab";
286
+
185
287
  export interface IContainer {
186
288
  /*
187
289
  Type of container, which determines markup. This is currently only available when the schema is generated by
@@ -189,14 +291,25 @@ declare module fng {
189
291
  In the case of a string which does not match one of the predefined options
190
292
  the generated container div is given the class of the name
191
293
  */
192
- 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);
193
295
  title?: string;
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;
194
307
  /*
195
308
  h1...h6 will use a header style
196
309
  anything else will be used as a paragraph stype
197
310
  */
198
- titleTagOrClass? : string;
199
- content: IFormInstruction[];
311
+ titleTagOrClass?: string;
312
+ content: IFormSchemaElement[];
200
313
  }
201
314
 
202
315
  export type IFormSchemaElement = IFormInstruction | IContainer;
@@ -207,57 +320,84 @@ declare module fng {
207
320
  export interface IEnumInstruction {
208
321
  repeat: string;
209
322
  value: string;
210
- label? : string;
323
+ label?: string;
211
324
  }
212
325
 
213
326
  export interface IFngCtrlState {
214
327
  master: any;
215
- allowLocationChange: boolean; // Do we allow location change or prompt for permission
328
+ allowLocationChange: boolean; // Do we allow location change or prompt for permission
216
329
  }
217
- export interface IRecordHandler {
330
+ export interface IRecordHandlerService {
218
331
  convertToMongoModel(schema: IControlledFormSchema, anObject: any, prefixLength: number, scope: IFormScope): any;
219
332
  createNew(dataToSave: any, options: any, scope: IFormScope, ctrlState: IFngCtrlState): void;
220
- deleteRecord(model: any, id: any, scope: IFormScope, ctrlState: any): void;
221
- updateDocument(dataToSave : any, options: any, scope: IFormScope, ctrlState: IFngCtrlState) : void;
222
- 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;
223
337
  scrollTheList($scope: IFormScope);
224
338
  getListData(record, fieldName, listSchema?, $scope?: IFormScope);
225
339
  suffixCleanId(inst, suffix);
226
- setData(object, fieldname, element, value);
340
+ setData(object, fieldname: string, element, value);
341
+ getData(object, fieldname: string, element?: any);
227
342
  setUpLookupOptions(lookupCollection, schemaElement, $scope: IFormScope, ctrlState, handleSchema);
228
- 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;
229
349
  handleInternalLookup($scope: IFormScope, formInstructions, ref): void;
230
350
  preservePristine(element, fn): void;
231
351
  convertIdToListValue(id, idsArray, valuesArray, fname);
232
- decorateScope($scope:IFormScope, $uibModal, recordHandlerInstance : IRecordHandler, ctrlState);
233
- 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
+ );
234
360
  fillFormWithBackendSchema($scope: IFormScope, formGeneratorInstance, recordHandlerInstance, ctrlState);
235
361
  handleError($scope: IFormScope);
362
+ convertToAngularModel($scope: IFormScope);
236
363
  }
237
364
 
238
- export interface IFormGenerator {
239
- generateEditUrl(obj, $scope:IFormScope): string;
365
+ export interface IFormGeneratorService {
366
+ generateEditUrl(obj, $scope: IFormScope): string;
367
+ generateViewUrl(obj, $scope: IFormScope): string;
240
368
  generateNewUrl($scope: IFormScope): string;
241
369
  handleFieldType(formInstructions, mongooseType, mongooseOptions, $scope: IFormScope, ctrlState);
242
- handleSchema(description: string, source, destForm, destList, prefix, doRecursion: boolean, $scope: IFormScope, ctrlState);
370
+ handleSchema(
371
+ description: string,
372
+ source,
373
+ destForm,
374
+ destList,
375
+ prefix,
376
+ doRecursion: boolean,
377
+ $scope: IFormScope,
378
+ ctrlState
379
+ );
243
380
  updateDataDependentDisplay(curValue, oldValue, force, $scope: IFormScope);
244
- add(fieldName, $event, $scope: IFormScope);
245
- unshift(fieldName, $event, $scope: IFormScope);
246
- remove(fieldName, value, $event, $scope: IFormScope);
381
+ add(fieldName: string, $event, $scope: IFormScope, modelOverride?: any);
382
+ unshift(fieldName: string, $event, $scope: IFormScope, modelOverride?: any);
383
+ remove(fieldName: string, value, $event, $scope: IFormScope, modelOverride?: any);
247
384
  hasError(formName, name, index, $scope: IFormScope);
248
- decorateScope($scope: IFormScope, formGeneratorInstance, recordHandlerInstance: IRecordHandler, sharedStuff);
385
+ decorateScope($scope: IFormScope, formGeneratorInstance: IFormGeneratorService, recordHandlerInstance: IRecordHandlerService, sharedStuff, pseudoUrl?: string);
249
386
  }
250
387
 
251
388
  export interface IFngSingleLookupHandler {
252
389
  formInstructions: IFormInstruction;
253
390
  lastPart: string;
254
391
  possibleArray: string;
392
+ // If the looked-up record changes, we use these fields to see if the old lookup value also exists in the new lookup record
393
+ oldValue?: string | string[];
394
+ oldId?: string | string[];
255
395
  }
256
396
 
257
397
  export interface IFngLookupHandler {
258
398
  lookupOptions: string[];
259
399
  lookupIds: string[];
260
- handlers: IFngSingleLookupHandler[]
400
+ handlers: IFngSingleLookupHandler[];
261
401
  }
262
402
 
263
403
  export interface IFngInternalLookupHandlerInfo extends IFngLookupHandler {
@@ -268,16 +408,32 @@ declare module fng {
268
408
  ref: IFngLookupListReference;
269
409
  }
270
410
 
411
+ // we cannot use an enum here, so this will have to do. these are the values expected to be returned by the
412
+ // function on $rootScope with the name formsAngular.disabledSecurityFuncName.
413
+ // false = not disabled,
414
+ // true = disabled,
415
+ // "+" = this and all child elements disabled
416
+ export type DisabledOutcome = boolean | "+";
417
+
418
+ export interface ISecurableScope extends angular.IScope {
419
+ // added by ISecurityService
420
+ isSecurelyHidden: (elemId: string) => boolean;
421
+ isSecurelyDisabled: (elemId: string) => boolean;
422
+ requiresDisabledChildren: (elemId: string) => boolean;
423
+ }
424
+
271
425
  /*
272
426
  The scope which contains form data
273
427
  */
274
- export interface IFormScope extends angular.IScope {
428
+ export interface IFormScope extends ISecurableScope {
275
429
  sharedData: any;
276
- modelNameDisplay : string;
430
+ modelNameDisplay: string;
277
431
  modelName: string;
278
432
  formName: string;
279
433
  alertTitle: any;
434
+ errorVisible: boolean;
280
435
  errorMessage: any;
436
+ errorHideTimer: number;
281
437
  save: any;
282
438
  newRecord: boolean;
283
439
  initialiseNewRecord?: any;
@@ -288,17 +444,16 @@ declare module fng {
288
444
  isCancelDisabled: any;
289
445
  isNewDisabled: any;
290
446
  isSaveDisabled: any;
291
- disabledText: any;
447
+ whyDisabled: string;
292
448
  unconfirmedDelete: boolean;
293
449
  getVal: any;
294
450
  sortableOptions: any;
295
- tabDeselect: any;
296
- tabs?: Array<any>; // In the case of forms that contain a tab set
297
- tab?: string; // title of the active tab - from the route
451
+ tabs?: Array<any>; // In the case of forms that contain a tab set
452
+ tab?: string; // title of the active tab - from the route
298
453
  activeTabNo?: number;
299
- topLevelFormName: string; // The name of the form
454
+ topLevelFormName: string; // The name of the form
300
455
  record: any;
301
- originalData: any; // the unconverted data read from the server
456
+ originalData: any; // the unconverted data read from the server
302
457
  phase: any;
303
458
  disableFunctions: any;
304
459
  dataEventFunctions: any;
@@ -310,13 +465,17 @@ declare module fng {
310
465
  conversions: any;
311
466
  pageSize: any;
312
467
  pagesLoaded: any;
468
+ redirectOptions?: { redirect?: string; allowChange?: boolean };
313
469
  cancel: () => any;
314
- showError: (error: any, alertTitle? : string) => void;
470
+ showError: (error: any, alertTitle?: string) => void;
315
471
  prepareForSave: (cb: (error: string, dataToSave?: any) => void) => void;
472
+ setDefaults: (formSchema: IFormSchema, base?: string) => any;
316
473
  formSchema: IControlledFormSchema;
317
474
  baseSchema: () => Array<any>;
318
475
  setFormDirty: any;
319
476
  add: any;
477
+ hideTab: (event, tabTitle: string, hiddenTabArrayProp: string) => void;
478
+ addTab: (event, tabTitle: string, hiddenTabArrayProp: string) => void;
320
479
  hasError: any;
321
480
  unshift: any;
322
481
  remove: any;
@@ -325,23 +484,39 @@ declare module fng {
325
484
  skipCols: any;
326
485
  setPristine: any;
327
486
  generateEditUrl: any;
487
+ generateViewUrl: any;
328
488
  generateNewUrl: any;
329
489
  scrollTheList: any;
330
490
  getListData: any;
331
- dismissError: any;
491
+ phaseWatcher: any;
492
+ dismissError: () => void;
493
+ stickError: () => void;
494
+ clearTimeout: () => void;
332
495
  handleHttpError: (response: any) => void;
333
496
  dropConversionWatcher: () => void;
497
+ readingRecord?: angular.IPromise<any>;
498
+ onSchemaFetch?: (description: string, source: IFieldViewInfo[]) => void;
499
+ onSchemaProcessed?: (description: string, formSchema: IFormInstruction[]) => void;
500
+ updateQueryForTab?: (tab: string) => void;
501
+ showLoading? : boolean;
502
+ tabDeselect?: ($event: any, $selectedIndex: number) => void;
503
+ setUpCustomLookupOptions?: (
504
+ schemaElement: IFormInstruction,
505
+ ids: string[],
506
+ options: string[],
507
+ baseScope: any
508
+ ) => void;
334
509
  }
335
510
 
336
511
  export interface IContextMenuDivider {
337
512
  divider: boolean;
338
513
  }
339
- export interface IContextMenuOption {
340
- // For it to make any sense, a menu option needs one of the next two properties
341
- url?: string;
342
- fn?: () => void;
514
+ export interface IContextMenuBaseOption {
515
+ // provided to the security hook (see elemSecurityFuncName) - optional where that is not being used
516
+ id?: string;
343
517
 
344
- text: string;
518
+ text?: string;
519
+ textFunc?: () => string;
345
520
  isDisabled?: () => boolean;
346
521
  isHidden?: () => boolean;
347
522
 
@@ -350,11 +525,28 @@ declare module fng {
350
525
  creating: boolean;
351
526
  editing: boolean;
352
527
  }
528
+ export interface IContextSubMenuOption extends IContextMenuBaseOption {
529
+ items: ContextMenuItem[];
530
+ }
531
+ export interface IContextMenuOption extends IContextMenuBaseOption{
532
+ // For it to make any sense, a menu option needs one of the next three properties
533
+ url?: string;
534
+ fn?: (...args: any) => void;
535
+ urlFunc?: () => string;
536
+ broadcast?: string;
537
+ args?: any[];
538
+ }
539
+ export type ContextMenuItem = IContextMenuOption | IContextSubMenuOption | IContextMenuDivider;
540
+
541
+ export interface IModelCtrlService {
542
+ loadControllerAndMenu: (sharedData: any, titleCaseModelName: string, level: number, needDivider: boolean, scope: angular.IScope) => void;
543
+ }
353
544
 
354
545
  export interface IModelController extends IFormScope {
355
- onBaseCtrlReady? : (baseScope: IFormScope) => void; // Optional callback after form is instantiated
356
- onAllReady? : (baseScope: IFormScope) => void; // Optional callback after form is instantiated and populated
357
- contextMenu? : Array<IContextMenuOption | IContextMenuDivider>
546
+ onBaseCtrlReady?: (baseScope: IFormScope) => void; // Optional callback after form is instantiated
547
+ onAllReady?: (baseScope: IFormScope) => void; // Optional callback after form is instantiated and populated
548
+ contextMenu?: ContextMenuItem[];
549
+ contextMenuPromise?: Promise<ContextMenuItem[]>;
358
550
  }
359
551
 
360
552
  export interface IBaseFormOptions {
@@ -362,13 +554,13 @@ declare module fng {
362
554
  * The style of the form layout. Supported values are horizontalcompact, horizontal, vertical, inline
363
555
  */
364
556
  //TODO supported values should be in an enum
365
- formstyle?: string;
557
+ formstyle?: formStyle;
366
558
  /**
367
559
  * Model on form scope (defaults to record).
368
560
  * <li><strong>model</strong> the object in the scope to be bound to the model controller. Specifying
369
561
  * the model inhibits the generation of the <strong>form</strong> tag unless the <strong>forceform</strong> attribute is set to true</li>
370
562
  */
371
- model? : string;
563
+ model?: string;
372
564
  /**
373
565
  * The name to be given to the form - defaults to myForm
374
566
  */
@@ -377,60 +569,272 @@ declare module fng {
377
569
  * Normally first field in a form gets autofocus set. Use this to prevent this
378
570
  */
379
571
  noautofocus?: string;
572
+ /*
573
+ Suppress the generation of element ids
574
+ (sometimes required when using nested form-inputs in a directive)
575
+ */
576
+ noid?: boolean;
380
577
  }
381
578
 
382
579
  export interface IFormAttrs extends IFormOptions, angular.IAttributes {
383
580
  /**
384
581
  * Schema used by the form
385
582
  */
386
- schema : string;
387
- forceform?: string; // Must be true or omitted. Forces generation of the <strong>form</strong> tag when model is specified
583
+ schema: string;
584
+ forceform?: string; // Must be true or omitted. Forces generation of the <strong>form</strong> tag when model is specified
585
+ noid?: boolean;
388
586
  }
389
587
 
390
588
  export interface IFormOptions extends IBaseFormOptions {
391
- schema? : string;
589
+ schema?: string;
392
590
  subkey?: string;
393
591
  subkeyno?: number;
394
- subschema? : string;
395
- subschemaroot? : string;
592
+ subschema?: string;
593
+ subschemaroot?: string;
594
+ viewform?: boolean;
595
+ suppressNestingWarning?: boolean;
396
596
  }
397
597
 
398
598
  export interface IBuiltInRoute {
399
599
  route: string;
400
- state: string;
401
- templateUrl: string;
402
- options? : any;
600
+ state?: string;
601
+ templateUrl?: string;
602
+ options?: {
603
+ authenticate?: boolean;
604
+ templateUrl?: string | (() => void);
605
+ template?: string;
606
+ controller?: string;
607
+ }
403
608
  }
404
609
 
405
610
  export interface IRoutingConfig {
406
- hashPrefix: string;
611
+ hashPrefix?: string;
407
612
  html5Mode: boolean;
408
- routing: string; // What sort of routing do we want? ngroute or uirouter.
409
- // TODO Should be enum
410
- 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)
411
- // for example '/db' that gets prepended to all the generated routes. This can be used to
412
- // prevent generated routes (which have a lot of parameters) from clashing with other routes in
413
- // the web app that have nothing to do with CRUD forms
613
+ routing: string; // What sort of routing do we want? ngroute or uirouter.
614
+ // TODO Should be enum
615
+ 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)
616
+ // for example '/db' that gets prepended to all the generated routes. This can be used to
617
+ // prevent generated routes (which have a lot of parameters) from clashing with other routes in
618
+ // the web app that have nothing to do with CRUD forms
414
619
  fixedRoutes?: Array<IBuiltInRoute>;
415
- 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/'
416
- add2fngRoutes?: any; // An object to add to the generated routes. One use case would be to add {authenticate: true}
417
- // so that the client authenticates for certain routes
620
+ 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/'
621
+ add2fngRoutes?: any; // An object to add to the generated routes. One use case would be to add {authenticate: true}
622
+ // so that the client authenticates for certain routes
418
623
 
419
- variantsForDemoWebsite? : any; // Just for demo website
420
- variants?: any; // Just for demo website
624
+ variantsForDemoWebsite?: any; // Just for demo website
625
+ variants?: any; // Just for demo website
626
+ 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
421
627
  }
422
628
 
423
629
  export interface IFngRoute {
424
- newRecord?: boolean;
425
- analyse?: boolean;
426
- modelName?: string;
427
- reportSchemaName? : string;
428
- id? : string;
429
- formName? : string;
430
- tab? : string;
431
- variant? : string; // TODO should be enum of supported frameworks
630
+ newRecord?: boolean;
631
+ analyse?: boolean;
632
+ modelName?: string;
633
+ reportSchemaName?: string;
634
+ id?: string;
635
+ formName?: string;
636
+ tab?: string;
637
+ variant?: string; // TODO should be enum of supported frameworks
638
+ }
639
+
640
+ interface IBuildingBlocks {
641
+ common: string;
642
+ sizeClassBS3: string;
643
+ sizeClassBS2: string;
644
+ compactClass: string;
645
+ formControl: string;
646
+ modelString: string;
647
+ disableableAncestorStr: string;
648
+ }
649
+
650
+ interface IProcessedAttrs {
651
+ info: IFormInstruction;
652
+ options: IFormOptions;
653
+ directiveOptions: any;
654
+ }
655
+
656
+ interface IGenDisableStrParams {
657
+ forceNg?: boolean;
658
+ nonUniqueIdSuffix?: string;
659
+ }
660
+
661
+
662
+ interface IPluginHelperService {
663
+ extractFromAttr: (
664
+ attr: any,
665
+ directiveName: string,
666
+ scope: fng.IFormScope
667
+ ) => { info: IFormInstruction; options: IFormOptions; directiveOptions: any };
668
+ buildInputMarkup: (
669
+ scope: angular.IScope,
670
+ attrs: any,
671
+ params: {
672
+ processedAttrs?: IProcessedAttrs;
673
+ fieldInfoOverrides?: Partial<IFormInstruction>;
674
+ optionOverrides?: Partial<IFormOptions>;
675
+ addButtons?: boolean;
676
+ needsX?: boolean;
677
+ },
678
+ generateInputControl: (buildingBlocks: IBuildingBlocks) => string
679
+ ) => string;
680
+ genIdString: (scope: angular.IScope, processedAttrs: IProcessedAttrs, idSuffix: string) => string;
681
+ genDisabledStr: (
682
+ scope: angular.IScope,
683
+ processedAttrs: IProcessedAttrs,
684
+ idSuffix: string,
685
+ params?: fng.IGenDisableStrParams
686
+ ) => string;
687
+ genIdAndDisabledStr: (
688
+ scope: angular.IScope,
689
+ processedAttrs: IProcessedAttrs,
690
+ idSuffix: string,
691
+ params?: fng.IGenDisableStrParams
692
+ ) => string;
693
+ genDateTimePickerDisabledStr: (scope: angular.IScope, processedAttrs: IProcessedAttrs, idSuffix: string) => string;
694
+ genDateTimePickerIdAndDisabledStr: (
695
+ scope: angular.IScope,
696
+ processedAttrs: IProcessedAttrs,
697
+ idSuffix: string
698
+ ) => string;
699
+ genUiSelectIdAndDisabledStr: (
700
+ scope: angular.IScope,
701
+ processedAttrs: IProcessedAttrs,
702
+ idSuffix: string
703
+ ) => string;
704
+ handlePseudos: (scope: fng.IFormScope, str: string) => string;
705
+ genDisableableAncestorStr: (processedAttrs: IProcessedAttrs) => string;
706
+ }
707
+
708
+ interface ISecurityVisibility {
709
+ omit?: boolean;
710
+ visibilityAttr?: string;
711
+ }
712
+
713
+ interface IGenerateDisableAttrParams {
714
+ attr?: string;
715
+ attrRequiresValue?: boolean;
716
+ forceNg?: boolean;
717
+ }
718
+
719
+ type SecurityType = "hidden" | "disabled";
720
+
721
+ interface ISecurityService {
722
+ canDoSecurity: (type: SecurityType) => boolean;
723
+ canDoSecurityNow: (scope: fng.ISecurableScope, type: SecurityType) => boolean;
724
+ isSecurelyHidden: (elemId: string, pseudoUrl?: string) => boolean;
725
+ isSecurelyDisabled: (elemId: string, pseudoUrl?: string) => boolean;
726
+ decorateSecurableScope: (securableScope: ISecurableScope, params?: { pseudoUrl?: string, overrideSkipping?: boolean }) => void;
727
+ doSecurityWhenReady: (cb: () => void) => void;
728
+ considerVisibility: (id: string, scope: fng.ISecurableScope) => ISecurityVisibility;
729
+ considerContainerVisibility: (contentIds: string[], scope: fng.ISecurableScope) => fng.ISecurityVisibility;
730
+ getDisableableAttrs: (id: string) => string;
731
+ getHideableAttrs: (id: string) => string;
732
+ getDisableableAncestorAttrs: (id: string) => string;
733
+ generateDisabledAttr: (id: string, scope: fng.ISecurableScope, params?: IGenerateDisableAttrParams) => string;
432
734
  }
433
735
 
736
+ interface IListQueryOptions {
737
+ limit?: number;
738
+ find?: any; // e.g., { "careWorker.isCareWorker": true }
739
+ aggregate?: any;
740
+ projection?: any;
741
+ order?: any; // e.g., { familyName: -1, givenName: -1 }
742
+ skip?: number;
743
+ concatenate?: boolean; // whether the list fields should be concatenated into a single .text property
744
+ }
745
+
746
+ interface ISubmissionsService {
747
+ // return all of the list attributes of the record from db.<modelName>.<id>
748
+ // where returnRaw is true, the document (albeit with only its list attributes present) will be returned without transformation
749
+ // otherwise, the list fields will be concatenated (space-seperated) and returned as the list property of a record { list: string }
750
+ // e.g., "John Doe", in the case of a person
751
+ getListAttributes: (
752
+ modelName: string,
753
+ id: string,
754
+ returnRaw?: boolean
755
+ ) => angular.IHttpPromise<{ list: string } | any>;
756
+ readRecord: (modelName: string, id: string, formName?: string) => angular.IHttpPromise<any>;
757
+ getAll: (modelName: string, _options: any) => angular.IHttpPromise<any[]>;
758
+ getAllListAttributes: (ref: string) => angular.IHttpPromise<ILookupItem[]>;
759
+ getPagedAndFilteredList: (
760
+ modelName: string,
761
+ options: IListQueryOptions
762
+ ) => angular.IHttpPromise<any[]>;
763
+ getPagedAndFilteredListFull: (
764
+ modelName: string,
765
+ options: IListQueryOptions
766
+ ) => angular.IHttpPromise<any[]>;
767
+ deleteRecord: (model: string, id: string, formName: string) => angular.IHttpPromise<void>;
768
+ updateRecord: (modelName: string, id: string, dataToSave: any, formName?: string) => angular.IHttpPromise<any>;
769
+ createRecord: (modelName: string, dataToSave: any, formName?: string) => angular.IHttpPromise<any>;
770
+ useCache: (val: boolean) => void;
771
+ clearCache: () => void;
772
+ getCache: () => boolean;
773
+ }
774
+
775
+ interface IRoutingServiceProvider {
776
+ start: (options: IRoutingConfig) => void;
777
+ addRoutes: (fixedRoutes: Array<IBuiltInRoute>, fngRoutes:Array<IBuiltInRoute>) => void;
778
+ registerAction: (action: string) => void;
779
+ $get: () => IRoutingService;
780
+ }
781
+
782
+ interface IRoutingService {
783
+ router: () => string;
784
+ prefix: () => string;
785
+ parsePathFunc: () => (location: string) => void;
786
+ html5hash: () => string;
787
+ buildUrl: (path: string) => string;
788
+ buildOperationUrl: (
789
+ prefix: string,
790
+ operation: string,
791
+ modelName: string,
792
+ formName: string,
793
+ id: string,
794
+ tabName?: string
795
+ ) => string;
796
+ redirectTo: () => (operation: string, scope: IFormScope, LocationService: angular.ILocationService, id?: string, tab?: string) => void;
797
+ }
798
+
799
+ interface ICssFrameworkServiceProvider {
800
+ setOptions: (options: { framework: string }) => void;
801
+ $get: () => ICssFrameworkService;
802
+ }
803
+
804
+ interface ICssFrameworkService {
805
+ framework: () => string;
806
+ span: (cols: number) => string;
807
+ offset: (cols: number) => string;
808
+ rowFluid: () => string;
809
+ }
810
+
811
+ interface IFngUiSelectHelperService {
812
+ windowChanged: (width: number, height: number) => boolean;
813
+ addClientLookup: (lkpName: string, lkpData: any) => void;
814
+ clearCache: () => void;
815
+ lookupFunc: (value: string, formSchema: IFormInstruction, cb: (formSchema: IFormInstruction, value: ILookupItem ) => void) => void;
816
+ doOwnConversion: (scope: IFormScope, processedAttrs: any, ref: string) => void;
817
+ }
818
+
819
+ interface IFormMarkupHelperService {
820
+ isHorizontalStyle: (formStyle: string, includeStacked: boolean) => boolean;
821
+ isArrayElement: (scope: angular.IScope, info: fng.IFormInstruction, options: fng.IFormOptions) => boolean;
822
+ fieldChrome: (scope: fng.IFormScope, info: fng.IFormInstruction, options: fng.IFormOptions) => { omit?: boolean, template?: string, closeTag?: string };
823
+ label: (scope: fng.IFormScope, fieldInfo: fng.IFormInstruction, addButtonMarkup: boolean, options: fng.IFormOptions) => string;
824
+ glyphClass: () => string;
825
+ allInputsVars: (scope: angular.IScope, fieldInfo: fng.IFormInstruction, options: fng.IFormOptions, modelString: string, idString: string, nameString: string) => Partial<fng.IBuildingBlocks>;
826
+ inputChrome: (value: string, fieldInfo: fng.IFormInstruction, options: fng.IFormOptions, markupVars) => string;
827
+ generateSimpleInput: (common: string, fieldInfo: fng.IFormInstruction, options: fng.IFormOptions) => string;
828
+ controlDivClasses: (options: fng.IFormOptions, fieldInfo: fng.IFormInstruction) => string[];
829
+ handleInputAndControlDiv: (inputMarkup: string, controlDivClasses: string[]) => string;
830
+ handleArrayInputAndControlDiv: (inputMarkup: string, controlDivClasses: string[], scope: fng.IFormScope, info: fng.IFormInstruction, options: fng.IFormOptions) => string;
831
+ addTextInputMarkup: (allInputsVars: Partial<fng.IBuildingBlocks>, fieldInfo: fng.IFormInstruction, requiredStr: string) => string;
832
+ handleReadOnlyDisabled: (partialFieldInfo: { name: string, id?: string, nonUniqueId?: string, readonly?: boolean | string }, scope: fng.IFormScope) => string[];
833
+ generateArrayElementIdString: (idString: string, info: fng.IFormInstruction, options: fng.IFormOptions) => string;
834
+ genDisableableAncestorStr: (id: string) => string;
835
+ generateNgShow: (showWhen: IFngShowWhen, model: string) => string;
836
+ handlePseudos: (scope: fng.IFormScope, str: string, dynamicFuncName?: string) => string;
837
+ }
434
838
  }
435
839
 
436
- declare var formsAngular: angular.IModule;
840
+ declare var formsAngular: fng.IFng;