forms-angular 0.12.0-beta.19 → 0.12.0-beta.190

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,19 @@
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
+ }
6
+ var formsAngular: IFng;
3
7
 
4
8
  /*
5
9
  Type definitions for types that are used on both the client and the server
6
10
  */
11
+ type formStyle = 'inline' | 'vertical' | 'horizontal' | 'horizontalCompact' | 'stacked';
7
12
 
8
- export interface IFngLookupReference {
9
- type: 'lookup';
10
- collection: string
13
+ export interface IBaseArrayLookupReference {
14
+ property: string;
15
+ value: string;
11
16
  }
12
-
13
17
  /*
14
18
  IInternalLookupreference makes it possible to look up from a list (of key / value pairs) in the current record. For example
15
19
 
@@ -20,13 +24,11 @@ declare module fng {
20
24
  var ESchema = new Schema({
21
25
  warehouse_name: {type: String, list: {}},
22
26
  shelves: {type: [ShelfSchema]},
23
- favouriteShelf: {type: Schema.Types.ObjectId, ref: {type: 'internal', property: 'shelves', value:'location'};
27
+ favouriteShelf: {type: Schema.Types.ObjectId, internalRef: {property: 'shelves', value:'location'};
24
28
  });
25
29
  */
26
- export interface IFngInternalLookupReference {
27
- type: 'internal';
28
- property: string;
29
- value: string;
30
+ export interface IFngInternalLookupReference extends IBaseArrayLookupReference {
31
+ noConvert? : boolean; // can be used by a tricksy hack to get around nesting limitations
30
32
  }
31
33
 
32
34
  /*
@@ -36,18 +38,15 @@ declare module fng {
36
38
  const LSchemaDef : IFngSchemaDefinition = {
37
39
  descriptin: {type: String, required: true, list: {}},
38
40
  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'}},
41
+ shelf: {type: Schema.Types.ObjectId, lookupListRef: {collection:'k_referencing_self_collection', id:'$warehouse', property: 'shelves', value:'location'}},
40
42
  };
41
43
  */
42
- export interface IFngLookupListReference {
43
- type: 'lookupList';
44
+ export interface IFngLookupListReference extends IBaseArrayLookupReference {
44
45
  collection: string; // collection that contains the list
45
46
  /*
46
47
  Some means of calculating _id in collection. If it starts with $ then it is property in record
47
48
  */
48
49
  id: string;
49
- property: string;
50
- value: string;
51
50
  }
52
51
 
53
52
  /*
@@ -74,11 +73,15 @@ declare module fng {
74
73
  link allows the setting up of hyperlinks for lookup reference fields
75
74
  */
76
75
  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.
76
+ linkOnly?: boolean; // if true then the input element is not generated (this overrides label)
77
+ label?: boolean; // Make a link out of the label (causes text to be overridden) (this overrides text)
78
78
  form?: string; // can be used to generate a link to a custom schema
79
+ linktab?: string; // can be used to generate a link to a tab on a form
79
80
  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
81
  }
81
82
 
83
+ export type FieldSizeString = 'mini' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge' | 'block-level'; // sets control width. Default is 'medium''
84
+
82
85
  export interface IFngSchemaTypeFormOpts {
83
86
  /*
84
87
  The input type to be generated - which must be compatible with the Mongoose type.
@@ -97,19 +100,21 @@ declare module fng {
97
100
  */
98
101
  type?: string;
99
102
 
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
-
103
+ hidden?: boolean; // inhibits this schema key from appearing on the generated form.
104
+ label?: string | null; // overrides the default input label. label:null suppresses the label altogether.
105
+ ref?: string; // reference to another collection
106
+ internalRef? : IFngInternalLookupReference;
107
+ lookupListRef?: IFngLookupListReference;
104
108
  id?: string; // specifies the id of the input field (which defaults to f_name)
105
109
 
106
110
  placeHolder?: string // adds placeholder text to the input (depending on data type).
107
111
  help?: string; // adds help text under the input.
108
112
  helpInline?: string; // adds help to the right of the input.
109
- popup?: string; // adds popup help as specified.
113
+ popup?: string; // adds title (popup help) as specified.
114
+ ariaLabel?: string; // adds aria-label as specified.
110
115
  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).
116
+ size?: FieldSizeString;
117
+ readonly?: boolean | string; // adds the readonly or ng-readonly attribute to the generated input (currently doesn't work with date - and perhaps other types).
113
118
  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
119
  tab?: string; // Used to divide a large form up into a tabset with multiple tabs
115
120
  showWhen?: IFngShowWhen | string; // allows conditional display of fields based on values elsewhere. string must be an abular expression.
@@ -123,7 +128,7 @@ declare module fng {
123
128
 
124
129
  class?: string; // allows arbitrary classes to be added to the input tag.
125
130
  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
131
+ link?: IFngLinkSetup; // handles displaying links for ref lookups
127
132
 
128
133
  /*
129
134
  With a select / radio type you can specify the options.
@@ -146,17 +151,28 @@ declare module fng {
146
151
  /*
147
152
  The next few options relate to the handling and display of arrays (including arrays of subdocuments)
148
153
  */
149
- noAdd?: boolean; // inhibits an Add button being generated for arrays.
154
+ noAdd?: boolean | string; // inhibits an Add button being generated for arrays.
155
+ noneIndicator?: boolean; // show "None" where there's no add button and no array items
150
156
  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
157
+ noRemove?: boolean | string; // inhibits a Remove button being generated for array elements.
158
+ formstyle?: formStyle; // (only valid on a sub schema) sets style of sub form.
159
+ sortable? : boolean | string; // Allows drag and drop sorting of arrays - requires angular-ui-sortable
160
+ 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
161
+ subDocContainerType?: 'fieldset' | 'well' | 'well-large' | 'well-small' | string | ((info) => {before: '', after: ''}); // allows each element in the array to be nested in a container
162
+ subDocContainerProps?: any; // the parameters that will be passed if subDocContainerType is a function
154
163
 
155
164
  /*
156
165
  The next section relates to the display of sub documents
157
166
  */
158
167
  customSubDoc?: string; // Allows you to specify custom HTML (which may include directives) for the sub doc
168
+ customHeader?: string; // Allows you to specify custom HTML (which may include directives) for the header of a group of sub docs
159
169
  customFooter?: string; // Allows you to specify custom HTML (which may include directives) for the footer of a group of sub docs
170
+
171
+ /*
172
+ Suppresses warnings about attenpting deep nesting which would be logged to console in some circumstances when a
173
+ directive fakes deep nesting
174
+ */
175
+ suppressNestingWarning? : boolean;
160
176
  }
161
177
 
162
178
  // Schema passed from server - derived from Mongoose schema
@@ -169,12 +185,15 @@ declare module fng {
169
185
  step? : number;
170
186
  }
171
187
 
188
+ export type fieldType = 'string' | 'text' | 'textarea' | 'number' | 'select' | 'link' | 'date' | 'checkbox' | 'password' | 'radio';
189
+
172
190
  // Schema used internally on client - often derived from IFieldViewInfo passed from server
173
191
  export interface IFormInstruction extends IFieldViewInfo {
174
192
  id? : string; // id of generated DOM element
175
- type?: 'string' | 'text' | 'textarea' | 'number' | 'select' | 'link' | 'date' | 'checkbox' | 'password';
176
- rows? : number
177
- label: string;
193
+ type?: fieldType;
194
+ defaultValue? : any;
195
+ rows? : number;
196
+ label?: string;
178
197
  options?: any;
179
198
  ids?: any;
180
199
  hidden?: boolean;
@@ -182,11 +201,38 @@ declare module fng {
182
201
  add? : string;
183
202
  ref? : any;
184
203
  link? : any;
185
- linkText?: string;
204
+ linktext?: string;
205
+ linklabel?: boolean;
186
206
  form?: string; // the form that is linked to
187
207
  select2? : any; // deprecated
208
+ schema?: IFormInstruction[]; // If the field is an array of fields
209
+ intType? : 'date';
210
+ [ directiveOptions: string] : any;
211
+ }
212
+
213
+ export interface IContainer {
214
+ /*
215
+ Type of container, which determines markup. This is currently only available when the schema is generated by
216
+ the client for use independent of the BaseController
217
+ In the case of a string which does not match one of the predefined options
218
+ the generated container div is given the class of the name
219
+ */
220
+ containerType: 'fieldset' | 'well' | 'tabset' | 'tab' | 'well-large' | 'well-small' | string;
221
+ title?: string;
222
+
223
+ /*
224
+ h1...h6 will use a header style
225
+ anything else will be used as a paragraph stype
226
+ */
227
+ titleTagOrClass? : string;
228
+ content: IFormInstruction[];
188
229
  }
189
230
 
231
+ export type IFormSchemaElement = IFormInstruction | IContainer;
232
+
233
+ export type IFormSchema = IFormSchemaElement[];
234
+ export type IControlledFormSchema = IFormInstruction[];
235
+
190
236
  export interface IEnumInstruction {
191
237
  repeat: string;
192
238
  value: string;
@@ -198,13 +244,13 @@ declare module fng {
198
244
  allowLocationChange: boolean; // Do we allow location change or prompt for permission
199
245
  }
200
246
  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;
247
+ convertToMongoModel(schema: IControlledFormSchema, anObject: any, prefixLength: number, scope: IFormScope): any;
248
+ createNew(dataToSave: any, options: any, scope: IFormScope, ctrlState: IFngCtrlState): void;
249
+ deleteRecord(id: string, scope: IFormScope, ctrlState: IFngCtrlState): void;
250
+ updateDocument(dataToSave : any, options: any, scope: IFormScope, ctrlState: IFngCtrlState) : void;
205
251
  readRecord($scope: IFormScope, ctrlState);
206
252
  scrollTheList($scope: IFormScope);
207
- getListData($scope: IFormScope, record, fieldName, listSchema);
253
+ getListData(record, fieldName, listSchema?, $scope?: IFormScope);
208
254
  suffixCleanId(inst, suffix);
209
255
  setData(object, fieldname, element, value);
210
256
  setUpLookupOptions(lookupCollection, schemaElement, $scope: IFormScope, ctrlState, handleSchema);
@@ -220,13 +266,14 @@ declare module fng {
220
266
 
221
267
  export interface IFormGenerator {
222
268
  generateEditUrl(obj, $scope:IFormScope): string;
269
+ generateViewUrl(obj, $scope:IFormScope): string;
223
270
  generateNewUrl($scope: IFormScope): string;
224
271
  handleFieldType(formInstructions, mongooseType, mongooseOptions, $scope: IFormScope, ctrlState);
225
272
  handleSchema(description: string, source, destForm, destList, prefix, doRecursion: boolean, $scope: IFormScope, ctrlState);
226
273
  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);
274
+ add(fieldName: string, $event, $scope: IFormScope, modelOverride?: any);
275
+ unshift(fieldName: string, $event, $scope: IFormScope, modelOverride?: any);
276
+ remove(fieldName: string, value, $event, $scope: IFormScope, modelOverride?: any);
230
277
  hasError(formName, name, index, $scope: IFormScope);
231
278
  decorateScope($scope: IFormScope, formGeneratorInstance, recordHandlerInstance: IRecordHandler, sharedStuff);
232
279
  }
@@ -235,6 +282,9 @@ declare module fng {
235
282
  formInstructions: IFormInstruction;
236
283
  lastPart: string;
237
284
  possibleArray: string;
285
+ // If the looked-up record changes, we use these fields to see if the old lookup value also exists in the new lookup record
286
+ oldValue?: string | string[];
287
+ oldId?: string | string[];
238
288
  }
239
289
 
240
290
  export interface IFngLookupHandler {
@@ -260,7 +310,9 @@ declare module fng {
260
310
  modelName: string;
261
311
  formName: string;
262
312
  alertTitle: any;
313
+ errorVisible: boolean;
263
314
  errorMessage: any;
315
+ errorHideTimer: number;
264
316
  save: any;
265
317
  newRecord: boolean;
266
318
  initialiseNewRecord?: any;
@@ -271,11 +323,10 @@ declare module fng {
271
323
  isCancelDisabled: any;
272
324
  isNewDisabled: any;
273
325
  isSaveDisabled: any;
274
- disabledText: any;
326
+ whyDisabled: string;
275
327
  unconfirmedDelete: boolean;
276
328
  getVal: any;
277
329
  sortableOptions: any;
278
- tabDeselect: any;
279
330
  tabs?: Array<any>; // In the case of forms that contain a tab set
280
331
  tab?: string; // title of the active tab - from the route
281
332
  activeTabNo?: number;
@@ -296,7 +347,8 @@ declare module fng {
296
347
  cancel: () => any;
297
348
  showError: (error: any, alertTitle? : string) => void;
298
349
  prepareForSave: (cb: (error: string, dataToSave?: any) => void) => void;
299
- formSchema: IFormInstruction[];
350
+ setDefaults: (formSchema: IFormSchema, base?: string) => any;
351
+ formSchema: IControlledFormSchema;
300
352
  baseSchema: () => Array<any>;
301
353
  setFormDirty: any;
302
354
  add: any;
@@ -308,24 +360,37 @@ declare module fng {
308
360
  skipCols: any;
309
361
  setPristine: any;
310
362
  generateEditUrl: any;
363
+ generateViewUrl: any;
311
364
  generateNewUrl: any;
312
365
  scrollTheList: any;
313
366
  getListData: any;
314
- dismissError: any;
367
+ phaseWatcher: any;
368
+ dismissError: () => void;
369
+ stickError: () => void;
370
+ clearTimeout: () => void;
315
371
  handleHttpError: (response: any) => void;
316
372
  dropConversionWatcher: () => void;
373
+ readingRecord?: Promise<any>;
374
+ onSchemaFetch?: (description: string, source: IFieldViewInfo[]) => void;
375
+ onSchemaProcessed?: (description: string, formSchema: IFormInstruction[]) => void;
376
+ updateQueryForTab?: (tab: string) => void;
377
+ tabDeselect?: ($event: any, $selectedIndex: number) => void;
378
+ setUpCustomLookupOptions?: (schemaElement: IFormInstruction, ids: string[], options: string[], baseScope: any) => void;
317
379
  }
318
380
 
319
381
  export interface IContextMenuDivider {
320
382
  divider: boolean;
321
383
  }
322
384
  export interface IContextMenuOption {
323
- // For it to make any sense, a menu option needs one of the next two properties
385
+ // For it to make any sense, a menu option needs one of the next three properties
324
386
  url?: string;
325
387
  fn?: () => void;
388
+ urlFunc?: () => string;
326
389
 
327
- text: string;
390
+ text?: string;
391
+ textFunc?: () => string;
328
392
  isDisabled?: () => boolean;
393
+ isHidden?: () => boolean;
329
394
 
330
395
  // Does the option appear in the following contexts?
331
396
  listing: boolean;
@@ -336,7 +401,8 @@ declare module fng {
336
401
  export interface IModelController extends IFormScope {
337
402
  onBaseCtrlReady? : (baseScope: IFormScope) => void; // Optional callback after form is instantiated
338
403
  onAllReady? : (baseScope: IFormScope) => void; // Optional callback after form is instantiated and populated
339
- contextMenu? : Array<IContextMenuOption | IContextMenuDivider>
404
+ contextMenu? : Array<IContextMenuOption | IContextMenuDivider>;
405
+ contextMenuPromise? : Promise<Array<IContextMenuOption | IContextMenuDivider>>;
340
406
  }
341
407
 
342
408
  export interface IBaseFormOptions {
@@ -344,7 +410,7 @@ declare module fng {
344
410
  * The style of the form layout. Supported values are horizontalcompact, horizontal, vertical, inline
345
411
  */
346
412
  //TODO supported values should be in an enum
347
- formstyle?: string;
413
+ formstyle?: formStyle;
348
414
  /**
349
415
  * Model on form scope (defaults to record).
350
416
  * <li><strong>model</strong> the object in the scope to be bound to the model controller. Specifying
@@ -359,6 +425,11 @@ declare module fng {
359
425
  * Normally first field in a form gets autofocus set. Use this to prevent this
360
426
  */
361
427
  noautofocus?: string;
428
+ /*
429
+ Suppress the generation of element ids
430
+ (sometimes required when using nested form-inputs in a directive)
431
+ */
432
+ noid? : boolean;
362
433
  }
363
434
 
364
435
  export interface IFormAttrs extends IFormOptions, angular.IAttributes {
@@ -367,6 +438,7 @@ declare module fng {
367
438
  */
368
439
  schema : string;
369
440
  forceform?: string; // Must be true or omitted. Forces generation of the <strong>form</strong> tag when model is specified
441
+ noid? : boolean;
370
442
  }
371
443
 
372
444
  export interface IFormOptions extends IBaseFormOptions {
@@ -375,6 +447,8 @@ declare module fng {
375
447
  subkeyno?: number;
376
448
  subschema? : string;
377
449
  subschemaroot? : string;
450
+ viewform? : boolean;
451
+ suppressNestingWarning? : boolean;
378
452
  }
379
453
 
380
454
  export interface IBuiltInRoute {
@@ -400,6 +474,7 @@ declare module fng {
400
474
 
401
475
  variantsForDemoWebsite? : any; // Just for demo website
402
476
  variants?: any; // Just for demo website
477
+ 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
403
478
  }
404
479
 
405
480
  export interface IFngRoute {
@@ -415,4 +490,4 @@ declare module fng {
415
490
 
416
491
  }
417
492
 
418
- declare var formsAngular: angular.IModule;
493
+ declare var formsAngular: fng.IFng;