zet-lib 1.0.56 → 1.0.58
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 +666 -649
- package/lib/zRoleRouter.js +6 -6
- package/lib/zRoute.js +87 -2
- package/package.json +1 -1
package/lib/zRoleRouter.js
CHANGED
|
@@ -300,6 +300,7 @@ const body = `<div class="">
|
|
|
300
300
|
<% for(var i = 0;i < actions.length;i++) { %>
|
|
301
301
|
<th><%= actions[i] %> <input onclick='checkthis("<%= actions[i] %>")' type="checkbox" id="all<%= actions[i] %>"></th>
|
|
302
302
|
<% } %>
|
|
303
|
+
<th>Tabs</th>
|
|
303
304
|
</tr>
|
|
304
305
|
</thead>
|
|
305
306
|
<tbody>
|
|
@@ -307,14 +308,16 @@ const body = `<div class="">
|
|
|
307
308
|
<tr>
|
|
308
309
|
<td>
|
|
309
310
|
<% var ename = routes[i];
|
|
310
|
-
var
|
|
311
|
-
|
|
311
|
+
var handleTag = "handleAccess('"+routes[i]+"')";
|
|
312
|
+
var spanRole = tabs.includes(routes[i]) ? '<span class="handle-access icon-small icons-light" onclick="'+handleTag+'" data-bs-toggle="modal" data-bs-target="#tabaccess" ><img class="icons-bg-blue gridview icon-image" src="/assets/icons/lock-access.svg"></span>' : '' %>
|
|
313
|
+
<a href="/<%- ename %>" target="_blank"><%- ename %></a>
|
|
312
314
|
</td>
|
|
313
315
|
<% for(var x = 0;x < actions.length;x++) { %>
|
|
314
316
|
<td><input name="params[<%= ename %>][<%= actions[x] %>]" class="<%= actions[x] %>"
|
|
315
317
|
<% if(json && json.hasOwnProperty(ename) && json[ename].indexOf(actions[x]) >= 0) { %> <%= 'checked="checked"' %> <% } %> title="Role for <%= routes[i] %> <%= actions[x] %>" type="checkbox">
|
|
316
318
|
</td>
|
|
317
319
|
<% } %>
|
|
320
|
+
<td><%- spanRole %></td>
|
|
318
321
|
</tr>
|
|
319
322
|
<% } %>
|
|
320
323
|
</tbody>
|
|
@@ -456,7 +459,6 @@ const js = `<script>
|
|
|
456
459
|
$(".body-access").html(data);
|
|
457
460
|
}))
|
|
458
461
|
}
|
|
459
|
-
$(".handle-access").on("click", (e)=> handleAccess(e.target.text));
|
|
460
462
|
$(".btn-save-tab").on("click",(e) => {
|
|
461
463
|
let queryform = $("#tabform").serializeArray();
|
|
462
464
|
ajaxPost('/zrole/post-access', {
|
|
@@ -466,9 +468,7 @@ const js = `<script>
|
|
|
466
468
|
table : e.target.getAttribute('data-table')
|
|
467
469
|
},((data) => {
|
|
468
470
|
toastrForm(data);
|
|
469
|
-
|
|
470
|
-
setTimeout(() => {location.href= '';},2000);
|
|
471
|
-
}
|
|
471
|
+
$(".btn-close").click();
|
|
472
472
|
}))
|
|
473
473
|
})
|
|
474
474
|
</script>
|
package/lib/zRoute.js
CHANGED
|
@@ -2092,7 +2092,41 @@ zRoute.viewFormsSync = async (req, res, MYMODEL, data = {}) => {
|
|
|
2092
2092
|
const MYMODELS = myCache.get('MYMODELS')
|
|
2093
2093
|
const relations = await zRoute.relations(req, res, MYMODEL.table)
|
|
2094
2094
|
let forms = zRoute.viewForm(req, res, MYMODEL, relations, data)
|
|
2095
|
-
//
|
|
2095
|
+
//add tabs role
|
|
2096
|
+
if (MYMODEL.hasOwnProperty('hasTabs') && MYMODEL.hasTabs) {
|
|
2097
|
+
let script = ''
|
|
2098
|
+
//MYMODEL.tabs.map((table))
|
|
2099
|
+
script += `$(()=> {
|
|
2100
|
+
ajaxPost('/ztab-access',{table:"${MYMODEL.table}"},(data)=> {
|
|
2101
|
+
let dataTabs = ${MYMODEL.hasOwnProperty('tabs') ? JSON.stringify(MYMODEL.tabs) : []};
|
|
2102
|
+
let viewAccess = data.view || [];
|
|
2103
|
+
let createAccess = data.create || [];
|
|
2104
|
+
let editAccess = data.edit || [];
|
|
2105
|
+
let deleteAccess = data.delete || [];
|
|
2106
|
+
dataTabs.map((_, index)=> {
|
|
2107
|
+
if(!deleteAccess[index]) {
|
|
2108
|
+
setTimeout(function () {$("#arr"+index).find(".icons-danger").remove();},1000)
|
|
2109
|
+
}
|
|
2110
|
+
if(!editAccess[index]) {
|
|
2111
|
+
$("#arr"+index).find("input").attr("disabled",true);
|
|
2112
|
+
$("#arr"+index).find("select").attr("disabled",true);
|
|
2113
|
+
}
|
|
2114
|
+
if(!createAccess[index]) {
|
|
2115
|
+
$("#arr"+index).find(".btn-plus").remove();
|
|
2116
|
+
$("#arr"+index).find("input").attr("disabled",true);
|
|
2117
|
+
$("#arr"+index).find("select").attr("disabled",true);
|
|
2118
|
+
}
|
|
2119
|
+
if(!viewAccess[index]) {
|
|
2120
|
+
$("#arr"+index).remove();
|
|
2121
|
+
$(".arr"+index).remove();
|
|
2122
|
+
}
|
|
2123
|
+
})
|
|
2124
|
+
});
|
|
2125
|
+
});
|
|
2126
|
+
`
|
|
2127
|
+
moduleLib.addScript(req, res, script)
|
|
2128
|
+
}
|
|
2129
|
+
|
|
2096
2130
|
let tables = []
|
|
2097
2131
|
for (let key in forms.obj) {
|
|
2098
2132
|
if (forms.obj[key].type == 'table') {
|
|
@@ -2494,6 +2528,7 @@ zRoute.moduleLib = (req, res, MYMODEL, relations, zForms = '', data = {}) => {
|
|
|
2494
2528
|
|
|
2495
2529
|
/*
|
|
2496
2530
|
Generate javascript code into runtime folder
|
|
2531
|
+
make it static js
|
|
2497
2532
|
*/
|
|
2498
2533
|
zRoute.generateJS = (req, res, MYMODEL, relations, zForms = '', data = {}) => {
|
|
2499
2534
|
//add additional script
|
|
@@ -2510,6 +2545,8 @@ zRoute.generateJS = (req, res, MYMODEL, relations, zForms = '', data = {}) => {
|
|
|
2510
2545
|
const MYMODELS = myCache.get('MYMODELS')
|
|
2511
2546
|
let widgets = MYMODEL.widgets,
|
|
2512
2547
|
widgetsArray = Object.keys(widgets) || []
|
|
2548
|
+
|
|
2549
|
+
let hasTabs = MYMODEL.hasOwnProperty('hasTabs') ? MYMODEL.hasTabs : false
|
|
2513
2550
|
let hasDatePicker = false
|
|
2514
2551
|
let hasNumber = false
|
|
2515
2552
|
let hasClockPicker = false
|
|
@@ -2658,6 +2695,39 @@ zRoute.generateJS = (req, res, MYMODEL, relations, zForms = '', data = {}) => {
|
|
|
2658
2695
|
}
|
|
2659
2696
|
}
|
|
2660
2697
|
|
|
2698
|
+
//if this module has tabs than call access
|
|
2699
|
+
if (hasTabs) {
|
|
2700
|
+
scriptForm += `$(()=> {
|
|
2701
|
+
ajaxPost('/ztab-access',{table:"${MYMODEL.table}"},(data)=> {
|
|
2702
|
+
let dataTabs = ${MYMODEL.hasOwnProperty('tabs') ? JSON.stringify(MYMODEL.tabs) : []};
|
|
2703
|
+
let viewAccess = data.view || [];
|
|
2704
|
+
let createAccess = data.create || [];
|
|
2705
|
+
let editAccess = data.edit || [];
|
|
2706
|
+
let deleteAccess = data.delete || [];
|
|
2707
|
+
dataTabs.map((_, index)=> {
|
|
2708
|
+
if(!deleteAccess[index]) {
|
|
2709
|
+
setTimeout(function () {$("#arr"+index).find(".icons-danger").remove();},1000)
|
|
2710
|
+
}
|
|
2711
|
+
if(!editAccess[index]) {
|
|
2712
|
+
$("#arr"+index).find("input").attr("disabled",true);
|
|
2713
|
+
$("#arr"+index).find("select").attr("disabled",true);
|
|
2714
|
+
}
|
|
2715
|
+
if(!createAccess[index]) {
|
|
2716
|
+
$("#arr"+index).find(".btn-plus").remove();
|
|
2717
|
+
$("#arr"+index).find("input").attr("disabled",true);
|
|
2718
|
+
$("#arr"+index).find("select").attr("disabled",true);
|
|
2719
|
+
}
|
|
2720
|
+
if(!viewAccess[index]) {
|
|
2721
|
+
$("#arr"+index).remove();
|
|
2722
|
+
$(".arr"+index).remove();
|
|
2723
|
+
}
|
|
2724
|
+
})
|
|
2725
|
+
});
|
|
2726
|
+
})
|
|
2727
|
+
|
|
2728
|
+
`
|
|
2729
|
+
}
|
|
2730
|
+
|
|
2661
2731
|
defaultScript = `${Util.newLine} $(function () {
|
|
2662
2732
|
$(".isfile").each(function (index, value) {
|
|
2663
2733
|
let filename = $(this).attr("data-filename") || "";
|
|
@@ -3164,6 +3234,21 @@ zRoute.buildForm = async (req, res) => {
|
|
|
3164
3234
|
res.send(tabledata)
|
|
3165
3235
|
}
|
|
3166
3236
|
|
|
3237
|
+
/*
|
|
3238
|
+
get tab access from table
|
|
3239
|
+
*/
|
|
3240
|
+
zRoute.tabAccess = async (req, res) => {
|
|
3241
|
+
try {
|
|
3242
|
+
let table = req.body.table
|
|
3243
|
+
let roles = myCache.get('ROLES')
|
|
3244
|
+
let roleId = res.locals.roleId
|
|
3245
|
+
let tabs = roles[roleId].tabs[table] || []
|
|
3246
|
+
res.json(tabs)
|
|
3247
|
+
} catch (e) {
|
|
3248
|
+
console.log(e)
|
|
3249
|
+
}
|
|
3250
|
+
}
|
|
3251
|
+
|
|
3167
3252
|
zRoute.buildFileModel = (json, index = 0) => {
|
|
3168
3253
|
//let text = `module.exports = { ${Util.newLine}`;
|
|
3169
3254
|
let text = ''
|
|
@@ -3351,7 +3436,7 @@ zRoute.modelsCache = async () => {
|
|
|
3351
3436
|
}
|
|
3352
3437
|
} catch (e) {
|
|
3353
3438
|
//debug(req,res,e.toString());
|
|
3354
|
-
console.log('modelsCache :', e
|
|
3439
|
+
console.log('modelsCache :', e + '')
|
|
3355
3440
|
}
|
|
3356
3441
|
|
|
3357
3442
|
return obj
|