461
462 calc (field) {
463 if (field.split('.').length == 2) {
464 var subform_name = field.split('.')[0]465 var field_name = field.split('.')[1]
466 } else {
467 const o = $('#' + field)
462 calc (field) {
463 if (field.split('.').length == 2) {
464 var subform_name = field.split('.')[0]
465 var field_name = field.split('.')[1]466 } else {
467 const o = $('#' + field)
468 var f = o.attr('data-nu-format')
465 var field_name = field.split('.')[1]
466 } else {
467 const o = $('#' + field)
468 var f = o.attr('data-nu-format')469 var v = o.val()
470
471 return nuFORM.removeFormatting(v, f)
466 } else {
467 const o = $('#' + field)
468 var f = o.attr('data-nu-format')
469 var v = o.val()470
471 return nuFORM.removeFormatting(v, f)
472 }
472 }
473
474 const d = this.data() // -- an array of all data as subforms (the mainform is the first element)
475 var v = 0476 let u = 0
477
478 for (let i = 0; i < d.length; i++) {
479 const SF = d[i]
480 if (SF.id == subform_name) { // -- i've got the right subform
481 // var fmt = $("[id$='" + field_name + "']input[id^='" + subform_name + "']").attr('data-nu-format')
482 var f = SF.fields.indexOf(field_name) // -- check for valid field(column)483 if (f == -1) { return 0 }
484 for (let c = 0; c < SF.rows.length; c++) {
485 if (SF.deleted[c] == 0) { // -- add up only stuff not being deleted
540 pk = $('#nuRECORD').attr('data-nu-primary-key-name')
541 table = $('#nuRECORD').attr('data-nu-table')
542 sel = '#nuRECORD'
543 var sf = 'nuRECORD'544
545 if (table === undefined) {
546 oi = parent.nuFORM === undefined ? undefined : parent.nuFORM.getCurrent().form_id
631 o.columns.push(c)
632 }
633
634 for (var i = 0; i < o.rows.length; i++) {635 var row = JSON.parse(JSON.stringify(o.rows[i]))
636
637 row.shift()
632 }
633
634 for (var i = 0; i < o.rows.length; i++) {
635 var row = JSON.parse(JSON.stringify(o.rows[i]))636
637 row.shift()
638 row.pop()
651 titles.shift()
652 o.chartData.splice(0, 0, titles)
653
654 for (var i = 0; i < o.chartData[0].length; i++) {655 row = []
656
657 for (let p = 0; p < o.chartData.length; p++) {
662 }
663
664 if (nd == 0) { // -- no deleting allowed
665 for (var i = 0; i < o.rows.length; i++) {666 o.deleted[i] = 0
667 }
668
761 const FMT = this.setFormats()
762
763 if (v.includes('-')) {
764 var d = String(v.split(' ')[0]).split('-')765 var t = String(v.split(' ')[1]).split(':')
766 } else {
767 var d = [0, 0, 0]
762
763 if (v.includes('-')) {
764 var d = String(v.split(' ')[0]).split('-')
765 var t = String(v.split(' ')[1]).split(':')766 } else {
767 var d = [0, 0, 0]
768 var t = String(v.split(' ')[0]).split(':')
764 var d = String(v.split(' ')[0]).split('-')
765 var t = String(v.split(' ')[1]).split(':')
766 } else {
767 var d = [0, 0, 0]768 var t = String(v.split(' ')[0]).split(':')
769 }
770
765 var t = String(v.split(' ')[1]).split(':')
766 } else {
767 var d = [0, 0, 0]
768 var t = String(v.split(' ')[0]).split(':')769 }
770
771 if (t[0] == 'undefined') {
769 }
770
771 if (t[0] == 'undefined') {
772 var t = [0, 0, 0]773 }
774
775 const o = new Date(d[0], d[1] - 1, d[2], t[0], t[1], t[2], 0) // -- (year, month, day, hours, minutes, seconds, milliseconds)
859 .nuReplaceAll(',', ' ')
860 .split(' ')
861
862 var o = Date().toString().split(' ', 6) // -- Tue Sep 07 2004 11:11:12 GMT+0930 (Cen. Australia Standard Time)863 const time = String(o[4]).split(':')
864
865 const d = { y: o[3], m: FMT[nuTranslateToEnglish(o[1])].jsmonth, d: o[2], h: time[0], n: time[1], s: time[2] } // -- today's date time[2]}; //-- today's date
884 if (l == 's') { d.s = v[i] }
885 }
886
887 var o = new Date(d.y, Number(d.m) - 1, d.d, Number(d.h), Number(d.n), Number(d.s), 0)888 const y = String(o.getFullYear()) + '-'
889 const m = nuPad2(o.getMonth() + 1) + '-'
890 const a = nuPad2(o.getDate()) + ' '
4336
4337 if (c === null) return
4338
4339 for (var i = 0; i < c.length; i++) {4340 if (c[i].subform) {
4341 $('#' + c[i].id + 'scrollDiv' + ' > .nuSubform1').remove()
4342 $('#' + c[i].id + 'scrollDiv' + ' > .nuSubform0').each(function () {
4578 .html('<span style="font-weight:bold"> ' + nuTranslate('Include When Searching') + '<\span>')
4579 .addClass('nuOptionsList')
4580
4581 for (var i = 0; i < c.length; i++) {4582 let isChecked = true
4583
4584 if ($.inArray(i, nuFORM.getCurrent().nosearch_columns) != '-1') {
5190 const lw = columns == 1 ? 0 : nuPortraitLabelWidth(obj)
5191 let top = 0
5192 let b = -1
5193 var width = 05194 let oWidth = 0
5195 let oTop = 0
5196
2590}
2591
2592function nuSetStorageItem (key, value, storage, ttl) {
2593 var storage = storage === undefined || storage === 'session' ? window.sessionStorage : window.localStorage2594
2595 const now = new Date()
2596 const item = {
2571}
2572
2573function nuGetStorageItem (key, storage) {
2574 var storage = storage === undefined || storage === 'session' ? window.sessionStorage : window.localStorage2575
2576 const itemStr = storage.getItem(key)
2577
2421 if (i === undefined || nuDebugOut(obj, i)) return false
2422
2423 if (d === undefined) {
2424 var d = new Date()2425 }
2426
2427 const df = d.getFullYear() + '-' + nuPad2(d.getMonth() + 1) + '-' + nuPad2(d.getDate())
2205}
2206
2207function nuSelectSelectAll (id, value) {
2208 if (value === undefined) var value = true2209
2210 $('#' + id).find('option:not(:empty)').prop('selected', value)
2211 $('#' + id).change()
It is recommended to use let
or const
over var
.
This will help prevent re-declaration of variables that are in the global scope when using var
.
ES6 allows programmers to create variables with block scope instead of function scope using the let
and const
keywords.
Block scope is common in many other programming languages and helps programmers avoid mistakes such as this one:
var count = people.length;
var enoughFood = count > sandwiches.length;
if (enoughFood) {
var count = sandwiches.length; // accidentally overriding the count variable
console.log("We have " + count + " sandwiches for everyone. Plenty for all!");
}
// our count variable is no longer accurate
console.log("We have " + count + " people and " + sandwiches.length + " sandwiches!");
Block scoped variables shadow outer declarations instead of writing to them.
NOTE: There are certain edge cases where users might want to consider var. Consider this example:
var lib = lib || { run: () => {} }
Here, lib
might be a library that is exposed to an HTML file using a <script>
tag.
The var
keyword helps avoid re-writing lib
if it has already been declared via an injected script that was executed before this one.
Ideally, you should let bundlers worry about cases like this.
But if you want to use var
anyway, consider using a skipcq comment, or disabling the issue altogether.
Bad Practice
var x = "y";
var CONFIG = {};
Recommended
let x = "y";
const CONFIG = {};