pict-section-form 1.0.75 → 1.0.76

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.
@@ -127,6 +127,33 @@ class PostcardTheme extends libPictFormSection.PictFormTemplateProvider
127
127
  let tmpOptions = Object.assign({}, pOptions, {MetaTemplateSet:_Theme});
128
128
  super(pFable, tmpOptions, pServiceHash);
129
129
  }
130
+
131
+ /**
132
+ * Injects a template set into Pict for the Dynamic Form Section Provider.
133
+ *
134
+ * The TemplateSet object expects to have a `TemplatePrefix` and `Templates` property.
135
+ *
136
+ * The `TemplatePrefix` is used to prefix the hash of the template.
137
+ *
138
+ * The `Templates` property is an array of objects with the following properties:
139
+ * - `HashPostfix` - The postfix to be added to the template hash. This defines which dynamic template in the Layout it represents.
140
+ * - `Template` - The template string to be injected.
141
+ * - `DefaultInputExtensions` - An optional array of default input extensions to be added to the Dynamic Input provider.
142
+ *
143
+ * The context of the template *is not the data*. The template context is one of these five things depending on the layout layer:
144
+ * - `Form` - The form object.
145
+ * - `Section` - The section object.
146
+ * - `Group` - The group object.
147
+ * - `Row` - The row object.
148
+ * - `Input` - The input object.
149
+ *
150
+ * @param {Object} pTemplateSet - The template set to be injected.
151
+ */
152
+ injectTemplateSet(pTemplateSet)
153
+ {
154
+ this.pict.TemplateProvider.addTemplate('CustomTemplateField1', '<div id="customTemplate">{~D:Record.Value~} ({~D:Record.View.Hash~})</div>');
155
+ return super.injectTemplateSet(pTemplateSet);
156
+ }
130
157
  }
131
158
 
132
159
  module.exports = PostcardTheme;
@@ -42,7 +42,7 @@
42
42
  "Hash": "Custom1",
43
43
  "Description": "The message and recipient of your postcard.",
44
44
  "Layout": "Custom",
45
- "CustomLayoutTemplate": "<div id=\"custom\"><h5>I AM CUSTOM</h5>{~DI:Custom.CustomField1~}<div>{~SV:Custom.CustomField1~}</div> <div id=\"custom2\">{~DIH:CustomField2~}</div><div>{~SVH:CustomField2~}</div></div>"
45
+ "CustomLayoutTemplate": "<div id=\"custom\"><h5>I AM CUSTOM</h5>{~DI:Custom.CustomField1~}<div>{~SV:Custom.CustomField1^CustomTemplateField1~}</div> <div id=\"custom2\">{~DIH:CustomField2~}</div><div>{~SVH:CustomField2~}</div></div>"
46
46
  }
47
47
  ]
48
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pict-section-form",
3
- "version": "1.0.75",
3
+ "version": "1.0.76",
4
4
  "description": "Pict dynamic form sections",
5
5
  "main": "source/Pict-Section-Form.js",
6
6
  "directories": {
@@ -45,28 +45,52 @@ class PictTemplateGetViewSchemaValue extends libPictTemplate
45
45
  * @param {object} pRecord - The record object.
46
46
  * @param {function} fCallback - The callback function.
47
47
  * @param {array} pContextArray - The context array.
48
- * @returns {string} - The rendered template.
48
+ * @returns {string?} - The rendered template.
49
49
  */
50
50
  renderAsync(pTemplateHash, pRecord, fCallback, pContextArray)
51
51
  {
52
- const tmpMetatemplateGenerator = this.pict.providers.MetatemplateGenerator;
53
- const tmpHash = pTemplateHash.trim();
52
+ const [ tmpSchemaAddress, tmpTemplateHash ] = pTemplateHash.trim().split('^');
54
53
  /** @type{import('../views/Pict-View-Form-Metacontroller.js')} */
55
54
  const metacontroller = this.pict.views.PictFormMetacontroller;
56
55
  /** @type {import('./Pict-Template-ControlFromDynamicManifest.js').Manyfest} */
57
56
  const manifest = metacontroller.manifest;
58
- const descriptor = manifest.getDescriptor(tmpHash);
57
+ const descriptor = manifest.getDescriptor(tmpSchemaAddress);
59
58
  if (!descriptor)
60
59
  {
61
- this.log.error(`PictTemplateGetViewSchemaValue: Cannot find descriptor for address [${tmpHash}]`);
60
+ this.log.error(`PictTemplateGetViewSchemaValue: Cannot find descriptor for address [${tmpSchemaAddress}]`);
62
61
  return '';
63
62
  }
64
63
  /** @type {import('../views/Pict-View-DynamicForm.js')} */
65
64
  const tmpView = this.pict.views[descriptor.PictForm.ViewHash];
66
65
 
67
- const value = tmpView.getValueByHash(tmpHash);
66
+ const value = tmpView.getValueByHash(tmpSchemaAddress);
67
+
68
+ if (tmpTemplateHash)
69
+ {
70
+ const tmpRecord = { Value: value, ParentRecord: pRecord, View: tmpView, Descriptor: descriptor };
71
+ if (typeof fCallback !== 'function')
72
+ {
73
+ return this.pict.parseTemplateByHash(tmpTemplateHash, tmpRecord, null, pContextArray);
74
+ }
75
+ return this.pict.parseTemplateByHash(tmpTemplateHash, tmpRecord,
76
+ (pError, pValue) =>
77
+ {
78
+ if (pError)
79
+ {
80
+ return fCallback(pError, '');
81
+ }
82
+ return fCallback(null, pValue);
83
+ }, pContextArray);
84
+ }
68
85
 
69
- return value ? String(value) : '';
86
+ if (typeof(fCallback) === 'function')
87
+ {
88
+ fCallback(null, value ? String(value) : '');
89
+ }
90
+ else
91
+ {
92
+ return value ? String(value) : '';
93
+ }
70
94
  }
71
95
  }
72
96
 
@@ -49,24 +49,48 @@ class PictTemplateGetViewSchemaValueByHash extends libPictTemplate
49
49
  */
50
50
  renderAsync(pTemplateHash, pRecord, fCallback, pContextArray)
51
51
  {
52
- const tmpMetatemplateGenerator = this.pict.providers.MetatemplateGenerator;
53
- const tmpHash = pTemplateHash.trim();
52
+ const [ tmpSchemaHash, tmpTemplateHash ] = pTemplateHash.trim().split('^');
54
53
  /** @type{import('../views/Pict-View-Form-Metacontroller.js')} */
55
54
  const metacontroller = this.pict.views.PictFormMetacontroller;
56
55
  /** @type {import('./Pict-Template-ControlFromDynamicManifest.js').Manyfest} */
57
56
  const manifest = metacontroller.manifest;
58
- const descriptor = manifest.getDescriptorByHash(tmpHash);
57
+ const descriptor = manifest.getDescriptorByHash(tmpSchemaHash);
59
58
  if (!descriptor)
60
59
  {
61
- this.log.error(`PictTemplateGetViewSchemaValueByHash: Cannot find descriptor for hash [${tmpHash}]`);
60
+ this.log.error(`PictTemplateGetViewSchemaValueByHash: Cannot find descriptor for address [${tmpSchemaHash}]`);
62
61
  return '';
63
62
  }
64
63
  /** @type {import('../views/Pict-View-DynamicForm.js')} */
65
64
  const tmpView = this.pict.views[descriptor.PictForm.ViewHash];
66
65
 
67
- const value = tmpView.getValueByHash(tmpHash);
66
+ const value = tmpView.getValueByHash(tmpSchemaHash);
68
67
 
69
- return value ? String(value) : '';
68
+ if (tmpTemplateHash)
69
+ {
70
+ const tmpRecord = { Value: value, ParentRecord: pRecord, View: tmpView, Descriptor: descriptor };
71
+ if (typeof fCallback !== 'function')
72
+ {
73
+ return this.pict.parseTemplateByHash(tmpTemplateHash, tmpRecord, null, pContextArray);
74
+ }
75
+ return this.pict.parseTemplateByHash(tmpTemplateHash, tmpRecord,
76
+ (pError, pValue) =>
77
+ {
78
+ if (pError)
79
+ {
80
+ return fCallback(pError, '');
81
+ }
82
+ return fCallback(null, pValue);
83
+ }, pContextArray);
84
+ }
85
+
86
+ if (typeof(fCallback) === 'function')
87
+ {
88
+ fCallback(null, value ? String(value) : '');
89
+ }
90
+ else
91
+ {
92
+ return value ? String(value) : '';
93
+ }
70
94
  }
71
95
  }
72
96
 
@@ -24,9 +24,9 @@ declare class PictTemplateGetViewSchemaValue extends libPictTemplate {
24
24
  * @param {object} pRecord - The record object.
25
25
  * @param {function} fCallback - The callback function.
26
26
  * @param {array} pContextArray - The context array.
27
- * @returns {string} - The rendered template.
27
+ * @returns {string?} - The rendered template.
28
28
  */
29
- renderAsync(pTemplateHash: string, pRecord: object, fCallback: Function, pContextArray: any[]): string;
29
+ renderAsync(pTemplateHash: string, pRecord: object, fCallback: Function, pContextArray: any[]): string | null;
30
30
  }
31
31
  import libPictTemplate = require("pict-template");
32
32
  //# sourceMappingURL=Pict-Template-DyanmicView-Value.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Pict-Template-DyanmicView-Value.d.ts","sourceRoot":"","sources":["../../../source/templates/Pict-Template-DyanmicView-Value.js"],"names":[],"mappings":";AAEA;;GAEG;AACH;IAEC;;;;OAIG;IACH,8DAaC;IATA,6BAA6B;IAC7B,MADW,OAAO,MAAM,CAAC,CAChB;IACT,6FAA6F;IAC7F,OADW,OAAO,MAAM,CAAC,GAAG;QAAE,eAAe,EAAE,OAAO,gCAAgC,CAAC,CAAA;KAAE,CAC/E;IACV,kBAAkB;IAClB,KADW,GAAG,CACN;IAmBT;;;;;;;;OAQG;IACH,2BANW,MAAM,WACN,MAAM,8CAGJ,MAAM,CAsBlB;CACD"}
1
+ {"version":3,"file":"Pict-Template-DyanmicView-Value.d.ts","sourceRoot":"","sources":["../../../source/templates/Pict-Template-DyanmicView-Value.js"],"names":[],"mappings":";AAEA;;GAEG;AACH;IAEC;;;;OAIG;IACH,8DAaC;IATA,6BAA6B;IAC7B,MADW,OAAO,MAAM,CAAC,CAChB;IACT,6FAA6F;IAC7F,OADW,OAAO,MAAM,CAAC,GAAG;QAAE,eAAe,EAAE,OAAO,gCAAgC,CAAC,CAAA;KAAE,CAC/E;IACV,kBAAkB;IAClB,KADW,GAAG,CACN;IAmBT;;;;;;;;OAQG;IACH,2BANW,MAAM,WACN,MAAM,8CAGJ,MAAM,OAAC,CA8CnB;CACD"}
@@ -1 +1 @@
1
- {"version":3,"file":"Pict-Template-DyanmicView-ValueByHash.d.ts","sourceRoot":"","sources":["../../../source/templates/Pict-Template-DyanmicView-ValueByHash.js"],"names":[],"mappings":";AAEA;;GAEG;AACH;IAEC;;;;OAIG;IACH,8DAaC;IATA,6BAA6B;IAC7B,MADW,OAAO,MAAM,CAAC,CAChB;IACT,6FAA6F;IAC7F,OADW,OAAO,MAAM,CAAC,GAAG;QAAE,eAAe,EAAE,OAAO,gCAAgC,CAAC,CAAA;KAAE,CAC/E;IACV,kBAAkB;IAClB,KADW,GAAG,CACN;IAmBT;;;;;;;;OAQG;IACH,2BANW,MAAM,WACN,MAAM,8CAGJ,MAAM,CAsBlB;CACD"}
1
+ {"version":3,"file":"Pict-Template-DyanmicView-ValueByHash.d.ts","sourceRoot":"","sources":["../../../source/templates/Pict-Template-DyanmicView-ValueByHash.js"],"names":[],"mappings":";AAEA;;GAEG;AACH;IAEC;;;;OAIG;IACH,8DAaC;IATA,6BAA6B;IAC7B,MADW,OAAO,MAAM,CAAC,CAChB;IACT,6FAA6F;IAC7F,OADW,OAAO,MAAM,CAAC,GAAG;QAAE,eAAe,EAAE,OAAO,gCAAgC,CAAC,CAAA;KAAE,CAC/E;IACV,kBAAkB;IAClB,KADW,GAAG,CACN;IAmBT;;;;;;;;OAQG;IACH,2BANW,MAAM,WACN,MAAM,8CAGJ,MAAM,CA8ClB;CACD"}