]> git.proxmox.com Git - proxmox-widget-toolkit.git/blobdiff - mixin/CBind.js
use eslint and execute as check target
[proxmox-widget-toolkit.git] / mixin / CBind.js
index 11531a64a23edbc0c207595c93b6f6ae55e8e29d..afef53aadc7a60645788d2d02c54f5b935e90e71 100644 (file)
@@ -8,20 +8,20 @@ Ext.define('Proxmox.Mixin.CBind', {
     },
 
     cloneTemplates: function() {
-       var me = this;
+       let me = this;
 
-       if (typeof me.cbindData == "function") {
+       if (typeof me.cbindData === "function") {
            me.cbindData = me.cbindData(me.initialConfig);
        }
        me.cbindData = me.cbindData || {};
 
-       var getConfigValue = function(cname) {
+       let getConfigValue = function(cname) {
            if (cname in me.initialConfig) {
                return me.initialConfig[cname];
            }
            if (cname in me.cbindData) {
                let res = me.cbindData[cname];
-               if (typeof res == "function") {
+               if (typeof res === "function") {
                    return res(me.initialConfig);
                } else {
                    return res;
@@ -33,25 +33,26 @@ Ext.define('Proxmox.Mixin.CBind', {
            throw "unable to get cbind data for '" + cname + "'";
        };
 
-       var applyCBind = function(obj) {
-           var cbind = obj.cbind, prop, cdata, cvalue, match, found;
+       let applyCBind = function(obj) {
+           let cbind = obj.cbind, cdata;
            if (!cbind) return;
 
-           for (prop in cbind) {
+           for (const prop in cbind) { // eslint-disable-line guard-for-in
+               let match, found;
                cdata = cbind[prop];
 
                found = false;
                if (typeof cdata === 'function') {
                    obj[prop] = cdata(getConfigValue, prop);
                    found = true;
-               } else if (match = /^\{(!)?([a-z_][a-z0-9_]*)\}$/i.exec(cdata)) {
-                   var cvalue = getConfigValue(match[2]);
+               } else if ((match = /^\{(!)?([a-z_][a-z0-9_]*)\}$/i.exec(cdata))) {
+                   let cvalue = getConfigValue(match[2]);
                    if (match[1]) cvalue = !cvalue;
                    obj[prop] = cvalue;
                    found = true;
-               } else if (match = /^\{(!)?([a-z_][a-z0-9_]*(\.[a-z_][a-z0-9_]*)+)\}$/i.exec(cdata)) {
-                   var keys = match[2].split('.');
-                   var cvalue = getConfigValue(keys.shift());
+               } else if ((match = /^\{(!)?([a-z_][a-z0-9_]*(\.[a-z_][a-z0-9_]*)+)\}$/i.exec(cdata))) {
+                   let keys = match[2].split('.');
+                   let cvalue = getConfigValue(keys.shift());
                    keys.forEach(function(k) {
                        if (k in cvalue) {
                            cvalue = cvalue[k];
@@ -63,8 +64,8 @@ Ext.define('Proxmox.Mixin.CBind', {
                    obj[prop] = cvalue;
                    found = true;
                } else {
-                   obj[prop] = cdata.replace(/{([a-z_][a-z0-9_]*)\}/ig, function(match, cname) {
-                       var cvalue = getConfigValue(cname);
+                   obj[prop] = cdata.replace(/{([a-z_][a-z0-9_]*)\}/ig, (_match, cname) => {
+                       let cvalue = getConfigValue(cname);
                        found = true;
                        return cvalue;
                    });
@@ -79,14 +80,15 @@ Ext.define('Proxmox.Mixin.CBind', {
            applyCBind(me);
        }
 
-       var cloneTemplateArray = function(org) {
-           var copy, i, found, el, elcopy, arrayLength;
+       let cloneTemplateObject;
+       let cloneTemplateArray = function(org) {
+           let copy, i, found, el, elcopy, arrayLength;
 
            arrayLength = org.length;
            found = false;
            for (i = 0; i < arrayLength; i++) {
                el = org[i];
-               if (el.constructor == Object && el.xtype) {
+               if (el.constructor === Object && el.xtype) {
                    found = true;
                    break;
                }
@@ -97,13 +99,13 @@ Ext.define('Proxmox.Mixin.CBind', {
            copy = [];
            for (i = 0; i < arrayLength; i++) {
                el = org[i];
-               if (el.constructor == Object && el.xtype) {
+               if (el.constructor === Object && el.xtype) {
                    elcopy = cloneTemplateObject(el);
                    if (elcopy.cbind) {
                        applyCBind(elcopy);
                    }
                    copy.push(elcopy);
-               } else if (el.constructor == Array) {
+               } else if (el.constructor === Array) {
                    elcopy = cloneTemplateArray(el);
                    copy.push(elcopy);
                } else {
@@ -113,21 +115,21 @@ Ext.define('Proxmox.Mixin.CBind', {
            return copy;
        };
 
-       var cloneTemplateObject = function(org) {
-           var res = {}, prop, el, copy;
-           for (prop in org) {
+       cloneTemplateObject = function(org) {
+           let res = {}, prop, el, copy;
+           for (prop in org) { // eslint-disable-line guard-for-in
                el = org[prop];
                if (el === undefined || el === null) {
                    res[prop] = el;
                    continue;
                }
-               if (el.constructor == Object && el.xtype) {
+               if (el.constructor === Object && el.xtype) {
                    copy = cloneTemplateObject(el);
                    if (copy.cbind) {
                        applyCBind(copy);
                    }
                    res[prop] = copy;
-               } else if (el.constructor == Array) {
+               } else if (el.constructor === Array) {
                    copy = cloneTemplateArray(el);
                    res[prop] = copy;
                } else {
@@ -137,17 +139,17 @@ Ext.define('Proxmox.Mixin.CBind', {
            return res;
        };
 
-       var condCloneProperties = function() {
-           var prop, el, i, tmp;
+       let condCloneProperties = function() {
+           let prop, el, tmp;
 
-           for (prop in me) {
+           for (prop in me) { // eslint-disable-line guard-for-in
                el = me[prop];
                if (el === undefined || el === null) continue;
-               if (typeof el === 'object' && el.constructor == Object) {
-                   if (el.xtype && prop != 'config') {
+               if (typeof el === 'object' && el.constructor === Object) {
+                   if (el.xtype && prop !== 'config') {
                        me[prop] = cloneTemplateObject(el);
                    }
-               } else if (el.constructor == Array) {
+               } else if (el.constructor === Array) {
                    tmp = cloneTemplateArray(el);
                    me[prop] = tmp;
                }