forms-angular 0.12.0-beta.23 → 0.12.0-beta.231

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