zet-lib 1.2.24 → 1.2.25

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.
package/lib/moduleLib.js CHANGED
@@ -254,7 +254,51 @@ m.number = (req, res, elem) => {
254
254
  }
255
255
  }
256
256
 
257
- m.typeahead = (req, res, elem, data) => {
257
+ m.typeahead = (req, res, table, elem) => {
258
+ let script = ''
259
+ let head = ``
260
+ let end = ``
261
+ elem = elem || '.typeahead'
262
+ end += '<script type="text/javascript" src="/modules/typeahead/typeahead.js"></script>' + newLine
263
+
264
+ let elemData = elem.replace('.', '').replace('#', '')
265
+ let element = elem.replace('Typeahead', '')
266
+ let key = element.replace('#', '').replace('.', '')
267
+ // var script using existing cache
268
+ script += `$("body").on("click", "${element}Clear", function(){
269
+ $("${elem}").val("");
270
+ $("${element}").val("");
271
+ $("${element}").change();
272
+ });${Util.newLine}`
273
+ script += `$("${elem}").typeahead({highlight: true,source: function (query, asyncprocess) {
274
+ jQuery.ajax({
275
+ url : "/ztypeahead/${table}/${key}",
276
+ type : 'GET',
277
+ data : {
278
+ "query" : query
279
+ },
280
+ dataType : 'json',
281
+ success : function(json) {
282
+ asyncprocess(json);
283
+ }
284
+ });
285
+ }, items: 50, displayText: function (item) {
286
+ return item.zname.toString();
287
+ },
288
+ updater:function (item) {
289
+ $("${element}").val(item.id);
290
+ $("${element}").change();
291
+ return item;
292
+ }
293
+ }); ${Util.newLine}`
294
+ return {
295
+ head: head,
296
+ end: end,
297
+ script: script,
298
+ }
299
+ }
300
+
301
+ m.typeaheadFile = (req, res, elem, data) => {
258
302
  let script = ''
259
303
  let head = ``
260
304
  let end = ``
package/lib/zRoute.js CHANGED
@@ -662,6 +662,24 @@ zRoute.relations = async (req, res, table) => {
662
662
  zRoute.dataTableFilterSync = async (req, res, MYMODEL, filter) => {
663
663
  const relations = await zRoute.relations(req, res, MYMODEL.table)
664
664
  zRoute.moduleLib(req, res, MYMODEL, relations)
665
+ /*let typeaheads = [];
666
+ let scriptForm = '';
667
+ let head = '';
668
+ let end ='';
669
+ for(let key in MYMODEL.widgets){
670
+ if(MYMODEL.widgets[key].name == "typeahead") {
671
+ typeaheads.push(key)
672
+ let typeaheadObj = moduleLib.typeahead(req, res, `#${key}Typeahead`)
673
+ scriptForm += typeaheadObj.script
674
+ head = typeaheadObj.head
675
+ end = typeaheadObj.end
676
+ }
677
+ }
678
+ if(typeaheads.length > 0) {
679
+ res.locals.moduleHead = head
680
+ res.locals.moduleEnd = end
681
+ moduleLib.addScript(req,res,scriptForm)
682
+ }*/
665
683
  const dataTable = zRoute.dataTableFilter(MYMODEL, relations, filter)
666
684
  return dataTable
667
685
  }
@@ -2760,8 +2778,8 @@ zRoute.moduleLib = (req, res, MYMODEL, relations, zForms = '', data = {}) => {
2760
2778
  }
2761
2779
  } else if (MYMODEL.widgets[keys].name == 'typeahead') {
2762
2780
  //employee_payroll_salary___employee_id_1
2763
- let name = `${MYMODEL.widgets[keys].table}_${MYMODEL.table}___${keys}_${res.locals.companyId}`
2764
- scriptTemp += `<script>const ${keys}TypeaheadData = ${JSON.stringify(myCache.get(name))}</script>`
2781
+ //let name = `${MYMODEL.widgets[keys].table}_${MYMODEL.table}___${keys}_${res.locals.companyId}`
2782
+ //scriptTemp += `<script>const ${keys}TypeaheadData = ${JSON.stringify(myCache.get(name))}</script>`
2765
2783
  }
2766
2784
  }
2767
2785
 
@@ -2825,7 +2843,7 @@ zRoute.generateJS = (req, res, MYMODEL, relations, zForms = '', data = {}) => {
2825
2843
  headObj.switch = switchObj.head
2826
2844
  endObj.switch = switchObj.end
2827
2845
  } else if (widgets[key].name == 'typeahead') {
2828
- let typeaheadObj = moduleLib.typeahead(req, res, `#${key}Typeahead`, relations[key])
2846
+ let typeaheadObj = moduleLib.typeahead(req, res, MYMODEL.table, `#${key}Typeahead`)
2829
2847
  scriptForm += typeaheadObj.script
2830
2848
  headObj.typeahead = typeaheadObj.head
2831
2849
  endObj.typeahead = typeaheadObj.end
@@ -3843,4 +3861,17 @@ module.exports = (req, res, next) => {`
3843
3861
  }
3844
3862
  }
3845
3863
 
3864
+ zRoute.typeahead = async (req, res) => {
3865
+ let table = req.params.table
3866
+ let keys = req.params.field
3867
+ const MYMODELS = myCache.get('MYMODELS')
3868
+ let MYMODEL = MYMODELS[table]
3869
+ let WIDGET = MYMODEL.widgets
3870
+ let query = {}
3871
+ //employee_payroll_salary___employee_id_1
3872
+ let name = `${MYMODEL.widgets[keys].table}_${MYMODEL.table}___${keys}_${res.locals.companyId}`
3873
+ let json = myCache.get(name)
3874
+ res.json(json)
3875
+ }
3876
+
3846
3877
  module.exports = zRoute
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zet-lib",
3
- "version": "1.2.24",
3
+ "version": "1.2.25",
4
4
  "description": "zet is a library that part of zet generator.",
5
5
  "engines": {
6
6
  "node": ">=18"