zet-lib 1.2.99 → 1.2.100
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/Form.js +6 -0
- package/lib/moduleLib.js +93 -0
- package/lib/zRoute.js +64 -5
- package/package.json +1 -1
package/lib/Form.js
CHANGED
|
@@ -448,6 +448,12 @@ Form.field = (obj) => {
|
|
|
448
448
|
displayForm = obj.html
|
|
449
449
|
break
|
|
450
450
|
|
|
451
|
+
case 'location':
|
|
452
|
+
displayForm = `${prepend}<input type="text" class="form-control" id="search_map_location" placeholder="type a place" ${required} value="" ${htmlOptions}>${information}${append}
|
|
453
|
+
<textarea ${id} ${name} style="display: none" ${readonly} rows="2">${JSON.stringify(obj.value)}</textarea>
|
|
454
|
+
<div id="map_${obj.id}" style="width: 100%;height: ${obj.height || 200}px"></div>`
|
|
455
|
+
break
|
|
456
|
+
|
|
451
457
|
case 'dropzone':
|
|
452
458
|
displayForm = `${prepend}<div ${tabindex} ${style} type="text" ${classview} ${id} ${htmlOptions}><label for="files" class="dropzone-container">
|
|
453
459
|
<div class="dz-message" data-dz-message><div class="file-icon"><span class="icon-small icons-primary"><img class="icons-bg-white icon-image-large" src="/assets/icons/file-plus.svg"></span></div>
|
package/lib/moduleLib.js
CHANGED
|
@@ -78,6 +78,99 @@ m.dropzone = function (req, res, elem) {
|
|
|
78
78
|
script: script,
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
+
|
|
82
|
+
//module for google map
|
|
83
|
+
m.location = function (req, res, key) {
|
|
84
|
+
let script = ``
|
|
85
|
+
let head = ``
|
|
86
|
+
let end = ``
|
|
87
|
+
end += `<script src="https://maps.googleapis.com/maps/api/js?key=${process.env.GOOGLE_KEY}&callback=initAutocompleteZmap&libraries=places&language=ID" defer></script>`
|
|
88
|
+
script += `let searchAddressMap;
|
|
89
|
+
let autocompleteMap;
|
|
90
|
+
function initAutocompleteZmap() {
|
|
91
|
+
if(mapLocationJSON && mapLocationJSON.lat) {
|
|
92
|
+
$("#search_map_location").val(mapLocationJSON.address1);
|
|
93
|
+
initMap(mapLocationJSON.lat,mapLocationJSON.lon);
|
|
94
|
+
}
|
|
95
|
+
searchAddressMap = document.querySelector("#search_map_location");
|
|
96
|
+
autocompleteMap = new google.maps.places.Autocomplete(searchAddressMap, {
|
|
97
|
+
componentRestrictions: {country: ["ID"]},
|
|
98
|
+
fields: ["address_component", "geometry"],
|
|
99
|
+
});
|
|
100
|
+
searchAddressMap.focus();
|
|
101
|
+
autocompleteMap.addListener("place_changed", fillInAddress);
|
|
102
|
+
}
|
|
103
|
+
function fillInAddress() {
|
|
104
|
+
const place = autocompleteMap.getPlace();
|
|
105
|
+
let lat = place.geometry.location.lat();
|
|
106
|
+
let lon = place.geometry.location.lng();
|
|
107
|
+
initMap(lat, lon);
|
|
108
|
+
mapLocationJSON = {
|
|
109
|
+
lat:lat,
|
|
110
|
+
lon:lon,
|
|
111
|
+
address1: $("#search_map_location").val(),
|
|
112
|
+
address2:place.address_components,
|
|
113
|
+
}
|
|
114
|
+
setAddress();
|
|
115
|
+
}
|
|
116
|
+
function setAddress() {
|
|
117
|
+
$("#${key}").val(JSON.stringify(mapLocationJSON));
|
|
118
|
+
}
|
|
119
|
+
function initMap(lat, lon) {
|
|
120
|
+
let position = {lat: lat, lng: lon}
|
|
121
|
+
const map = new google.maps.Map(document.getElementById("map_${key}"), {
|
|
122
|
+
zoom: 13,
|
|
123
|
+
center: position,
|
|
124
|
+
draggable: true
|
|
125
|
+
});
|
|
126
|
+
var marker;
|
|
127
|
+
placeMarker(position, map);
|
|
128
|
+
var infowindow = new google.maps.InfoWindow();
|
|
129
|
+
function placeMarker(position, map) {
|
|
130
|
+
marker = new google.maps.Marker({
|
|
131
|
+
position: position,
|
|
132
|
+
map: map,
|
|
133
|
+
draggable: true,
|
|
134
|
+
animation: google.maps.Animation.DROP,
|
|
135
|
+
});
|
|
136
|
+
map.panTo(position);
|
|
137
|
+
}
|
|
138
|
+
google.maps.event.addListener(marker, 'dragend', function () {
|
|
139
|
+
geocodePosition(marker.getPosition());
|
|
140
|
+
});
|
|
141
|
+
google.maps.event.addListener(marker, 'click', function() {
|
|
142
|
+
infowindow.setContent($("#search_map_location").val());
|
|
143
|
+
infowindow.open(map, this)
|
|
144
|
+
});
|
|
145
|
+
function geocodePosition(pos) {
|
|
146
|
+
mapLocationJSON.lat=pos.lat();
|
|
147
|
+
mapLocationJSON.lon=pos.lng();
|
|
148
|
+
var geocoder = new google.maps.Geocoder();
|
|
149
|
+
geocoder.geocode
|
|
150
|
+
({
|
|
151
|
+
latLng: pos
|
|
152
|
+
},
|
|
153
|
+
function (results, status) {
|
|
154
|
+
if (status == google.maps.GeocoderStatus.OK) {
|
|
155
|
+
$("#search_map_location").val(results[0].formatted_address);
|
|
156
|
+
$("#mapErrorMsg").hide(100);
|
|
157
|
+
mapLocationJSON.address2=results[0].formatted_address;
|
|
158
|
+
mapLocationJSON.address1=$("#search_map_location").val();
|
|
159
|
+
setAddress();
|
|
160
|
+
} else {
|
|
161
|
+
$("#mapErrorMsg").html('Cannot determine address at this location.' + status).show(100);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
}`
|
|
167
|
+
return {
|
|
168
|
+
head: head,
|
|
169
|
+
end: end,
|
|
170
|
+
script: script,
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
81
174
|
//module for datepicker
|
|
82
175
|
m.datetimepicker = function (req, res, elem) {
|
|
83
176
|
let script = ''
|
package/lib/zRoute.js
CHANGED
|
@@ -691,14 +691,39 @@ zRoute.relations = async (req, res, table) => {
|
|
|
691
691
|
/*
|
|
692
692
|
Function to create filter elements on data table grid
|
|
693
693
|
*/
|
|
694
|
-
|
|
695
694
|
zRoute.dataTableFilterSync = async (req, res, MYMODEL, filter) => {
|
|
696
695
|
const relations = await zRoute.relations(req, res, MYMODEL.table)
|
|
697
|
-
zRoute.moduleLib(req, res, MYMODEL, relations)
|
|
696
|
+
//zRoute.moduleLib(req, res, MYMODEL, relations)
|
|
697
|
+
zRoute.moduleLibGrid(req, res, MYMODEL)
|
|
698
698
|
const dataTable = zRoute.dataTableFilter(MYMODEL, relations, filter)
|
|
699
699
|
return dataTable
|
|
700
700
|
}
|
|
701
701
|
|
|
702
|
+
zRoute.moduleLibGrid = (req, res, MYMODEL) => {
|
|
703
|
+
let autompletes = []
|
|
704
|
+
for (const key in MYMODEL.widgets) {
|
|
705
|
+
if (MYMODEL.widgets[key].name == 'typeahead') {
|
|
706
|
+
autompletes.push(key)
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
if (autompletes.length > 0) {
|
|
710
|
+
let scriptForm = ''
|
|
711
|
+
let head = ''
|
|
712
|
+
let end = ''
|
|
713
|
+
for (key of autompletes) {
|
|
714
|
+
let typeaheadObj = moduleLib.typeahead(req, res, MYMODEL.table, `#${key}Typeahead`)
|
|
715
|
+
scriptForm += typeaheadObj.script
|
|
716
|
+
head = typeaheadObj.head
|
|
717
|
+
end = typeaheadObj.end
|
|
718
|
+
}
|
|
719
|
+
if (end) {
|
|
720
|
+
moduleLib.addModule(req, res, end)
|
|
721
|
+
let contentScript = scriptForm
|
|
722
|
+
moduleLib.addScript(req, res, contentScript)
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
|
|
702
727
|
zRoute.dataTableFilter = (MYMODEL, relations, filter) => {
|
|
703
728
|
filter = filter || {}
|
|
704
729
|
let filterColumns = filter.hasOwnProperty('columns') ? filter.columns : []
|
|
@@ -983,6 +1008,10 @@ zRoute.dataTableData = (key, value, MYMODEL, relations, myid = '') => {
|
|
|
983
1008
|
myvalue = value ? JSON.stringify(value).replaceAll('","', '", "') : ''
|
|
984
1009
|
break
|
|
985
1010
|
|
|
1011
|
+
case 'location':
|
|
1012
|
+
myvalue = value ? value.address1 : ''
|
|
1013
|
+
break
|
|
1014
|
+
|
|
986
1015
|
case 'json_array':
|
|
987
1016
|
myvalue = value ? JSON.stringify(value).replaceAll('","', '", "') : ''
|
|
988
1017
|
break
|
|
@@ -2426,6 +2455,16 @@ zRoute.forms = (req, res, MYMODEL, relations, data = {}) => {
|
|
|
2426
2455
|
obj.type = 'textarea'
|
|
2427
2456
|
obj.class = 'form-control editor'
|
|
2428
2457
|
break
|
|
2458
|
+
case 'location':
|
|
2459
|
+
obj.type = 'location'
|
|
2460
|
+
obj.class = 'form-control'
|
|
2461
|
+
obj.height = obj.attributes.height || 200
|
|
2462
|
+
let objLocation = { lat: '', lon: '', address1: '', address2: '' }
|
|
2463
|
+
if (obj.value) {
|
|
2464
|
+
objLocation = obj.value
|
|
2465
|
+
}
|
|
2466
|
+
script += `let mapLocationJSON = ${JSON.stringify(objLocation)}`
|
|
2467
|
+
break
|
|
2429
2468
|
case 'tinymce':
|
|
2430
2469
|
obj.type = 'textarea'
|
|
2431
2470
|
obj.class = 'form-control tinymce'
|
|
@@ -2498,14 +2537,23 @@ zRoute.viewFormsSync = async (req, res, MYMODEL, data = {}) => {
|
|
|
2498
2537
|
const relations = await zRoute.relations(req, res, MYMODEL.table)
|
|
2499
2538
|
let forms = zRoute.viewForm(req, res, MYMODEL, relations, data)
|
|
2500
2539
|
let hasEditors = false
|
|
2540
|
+
let hasLocation = false
|
|
2541
|
+
let mapKey = ''
|
|
2501
2542
|
for (let key in MYMODEL.widgets) {
|
|
2502
2543
|
if (MYMODEL.widgets[key].name == 'editor') {
|
|
2503
2544
|
hasEditors = true
|
|
2504
2545
|
}
|
|
2546
|
+
if (MYMODEL.widgets[key].name == 'location') {
|
|
2547
|
+
hasLocation = true
|
|
2548
|
+
mapKey = key
|
|
2549
|
+
}
|
|
2505
2550
|
}
|
|
2506
2551
|
if (hasEditors) {
|
|
2507
2552
|
moduleLib.build(req, res, moduleLib.editor(req, res))
|
|
2508
2553
|
}
|
|
2554
|
+
if (hasLocation) {
|
|
2555
|
+
moduleLib.build(req, res, moduleLib.location(req, res, mapKey))
|
|
2556
|
+
}
|
|
2509
2557
|
//add tabs role
|
|
2510
2558
|
if (MYMODEL.hasOwnProperty('hasTabs') && MYMODEL.hasTabs) {
|
|
2511
2559
|
let script = ''
|
|
@@ -3015,9 +3063,6 @@ zRoute.moduleLib = (req, res, MYMODEL, relations, zForms = '', data = {}) => {
|
|
|
3015
3063
|
}
|
|
3016
3064
|
}
|
|
3017
3065
|
} else if (MYMODEL.widgets[keys].name == 'typeahead') {
|
|
3018
|
-
//employee_payroll_salary___employee_id_1
|
|
3019
|
-
//let name = `${MYMODEL.widgets[keys].table}_${MYMODEL.table}___${keys}_${res.locals.companyId}`
|
|
3020
|
-
//scriptTemp += `<script>const ${keys}TypeaheadData = ${JSON.stringify(myCache.get(name))}</script>`
|
|
3021
3066
|
}
|
|
3022
3067
|
}
|
|
3023
3068
|
|
|
@@ -3064,7 +3109,9 @@ zRoute.generateJS = (req, res, MYMODEL, relations, zForms = '', data = {}) => {
|
|
|
3064
3109
|
let defaultScript = ''
|
|
3065
3110
|
let hasTags = false
|
|
3066
3111
|
let hasLexical = false
|
|
3112
|
+
let hasLocation = false
|
|
3067
3113
|
let lexicals = []
|
|
3114
|
+
let mapKey = ''
|
|
3068
3115
|
let hasAttributes = []
|
|
3069
3116
|
for (let key in widgets) {
|
|
3070
3117
|
if (widgets[key].name == 'datepicker') {
|
|
@@ -3087,6 +3134,12 @@ zRoute.generateJS = (req, res, MYMODEL, relations, zForms = '', data = {}) => {
|
|
|
3087
3134
|
scriptForm += typeaheadObj.script
|
|
3088
3135
|
headObj.typeahead = typeaheadObj.head
|
|
3089
3136
|
endObj.typeahead = typeaheadObj.end
|
|
3137
|
+
} else if (widgets[key].name == 'location') {
|
|
3138
|
+
let locationObj = moduleLib.location(req, res, key)
|
|
3139
|
+
scriptForm += locationObj.script
|
|
3140
|
+
endObj.location = locationObj.end
|
|
3141
|
+
hasLocation = true
|
|
3142
|
+
mapKey = key
|
|
3090
3143
|
} else if (widgets[key].name == 'datetime') {
|
|
3091
3144
|
hasDateTimePicker = true
|
|
3092
3145
|
} else if (widgets[key].name == 'table') {
|
|
@@ -3240,6 +3293,12 @@ zRoute.generateJS = (req, res, MYMODEL, relations, zForms = '', data = {}) => {
|
|
|
3240
3293
|
`
|
|
3241
3294
|
}
|
|
3242
3295
|
|
|
3296
|
+
if (hasLocation) {
|
|
3297
|
+
scriptForm += `
|
|
3298
|
+
|
|
3299
|
+
`
|
|
3300
|
+
}
|
|
3301
|
+
|
|
3243
3302
|
if (hasDropzone) {
|
|
3244
3303
|
dropzones.map((item) => {
|
|
3245
3304
|
scriptForm += `$("div#${item}").dropzone({
|