forms-angular 0.12.0-beta.26 → 0.12.0-beta.260

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