From abb20706ae354d28bc825d6158cfaa55dea10873 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Mon, 13 Jan 2020 18:53:26 +0300 Subject: [PATCH 1/5] notes... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/ui-widgets.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ui (gen4)/features/ui-widgets.js b/ui (gen4)/features/ui-widgets.js index 62ac8863..28f78214 100755 --- a/ui (gen4)/features/ui-widgets.js +++ b/ui (gen4)/features/ui-widgets.js @@ -1110,6 +1110,8 @@ function(title, options){ // XXX need to: // - call options.open if it exists... // - do not define this if we already did... + // ...currently this is added to handlers on + // every .dialog.update(..)... open: function(evt){ // XXX CONTEXT... var actions = options.app || that.app From 509924db53f2ee6e3db8a3004d392c4baa5e980b Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Tue, 14 Jan 2020 18:41:22 +0300 Subject: [PATCH 2/5] tweaking... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/ui-widgets.js | 215 ++++++++++++++++--------------- 1 file changed, 110 insertions(+), 105 deletions(-) diff --git a/ui (gen4)/features/ui-widgets.js b/ui (gen4)/features/ui-widgets.js index 28f78214..02de9dbd 100755 --- a/ui (gen4)/features/ui-widgets.js +++ b/ui (gen4)/features/ui-widgets.js @@ -1100,112 +1100,118 @@ function(title, options){ : args.shift() options = args.shift() || {} + // user open handler... + var open = options.open + // toggler default settings... + var toggler_defaults = options.__toggle_setup ? + {} + : { + __toggler_setup: true, + + // XXX do we need a .type ??? + //type: options.type || 'toggle', + + open: function(evt){ + open + && open.call(this, ...arguments) + + // XXX CONTEXT... + var actions = options.app || that.app + + var getValues = function(){ + return options.values instanceof Function ? + options.values.call(actions) + : options.values ? + options.values + : ['off', 'on'] } + var set = function(v){ + // get current value... + v = arguments.length > 0 ? + v + : options.value instanceof Function ? + options.value.call(actions) + : options.value + // normalize... + // NOTE: we are re-getting the values here + // as it can get updated in options.list(..) + // or via options.values(..)... + if(!options.nonstrict){ + var values = getValues() + v = values.includes(v) ? + v + : values[0] } + // update the value... + // NOTE: we update the local value iff set(..) + // got an explicit value argument... + // calling set(..) will not store anything, + // just update the current state, either to + // the already stored value or to the output + // of .value(..)... + arguments.length > 0 + && (options.value instanceof Function ? + (v = options.value.call(actions, v)) + : (options.value = v)) + elem.text(v) + // update dialog... + options.doNotAutoUpdateDialog + || that.dialog.update() } + + + var elem = $(this).find('.text').last() + var current = elem.text() + var values = getValues() + + // editable list or more than 2 values -> show value list... + if(options.list_editable + || (values.length > 2 + && options.list !== false)){ + // call options.list(..) + if(options.list instanceof Function){ + options.list.call(actions, current, set) + + // normal list... + } else { + // XXX where do we get these when context in make(..) + // XXX mark the current value??? + var o = actions[ + options.list_editable ? + 'showEditableList' + : 'showList']( + values, + Object.assign({ + path: current, + open: function(v){ + // update value... + // XXX current is [[value]], check + // the upstream if this is correct... + current = v[0][0] + // NOTE: this is done first + // to update values... + o.close() + // update callable values... + options.list_editable + && options.values instanceof Function + && options.values.call(actions, values) }, + close: function(){ + // NOTE: set(..) should be + // called after all the + // dialog stuff is done... + setTimeout(function(){ set(current) }) }, + }, + options.list !== true ? + options.list + : {}) ) } + + // directly toggle next value... + } else { + // XXX should we be able to toggle values back??? + set(values[(values.indexOf(current) + 1) % values.length]) } + } } + return this.field(title, value, Object.assign( options, - { - // XXX do we need a .type ??? - //type: options.type || 'toggle', - - // XXX need to: - // - call options.open if it exists... - // - do not define this if we already did... - // ...currently this is added to handlers on - // every .dialog.update(..)... - open: function(evt){ - // XXX CONTEXT... - var actions = options.app || that.app - - var getValues = function(){ - return options.values instanceof Function ? - options.values.call(actions) - : options.values ? - options.values - : ['off', 'on'] } - var set = function(v){ - // get current value... - v = arguments.length > 0 ? - v - : options.value instanceof Function ? - options.value.call(actions) - : options.value - // normalize... - // NOTE: we are re-getting the values here - // as it can get updated in options.list(..) - // or via options.values(..)... - if(!options.nonstrict){ - var values = getValues() - v = values.includes(v) ? - v - : values[0] } - // update the value... - // NOTE: we update the local value iff set(..) - // got an explicit value argument... - // calling set(..) will not store anything, - // just update the current state, either to - // the already stored value or to the output - // of .value(..)... - arguments.length > 0 - && (options.value instanceof Function ? - (v = options.value.call(actions, v)) - : (options.value = v)) - elem.text(v) - // update dialog... - options.doNotAutoUpdateDialog - || that.dialog.update() } - - - var elem = $(this).find('.text').last() - var current = elem.text() - var values = getValues() - - // editable list or more than 2 values -> show value list... - if(options.list_editable - || (values.length > 2 - && options.list !== false)){ - // call options.list(..) - if(options.list instanceof Function){ - options.list.call(actions, current, set) - - // normal list... - } else { - // XXX where do we get these when context in make(..) - // XXX mark the current value??? - var o = actions[ - options.list_editable ? - 'showEditableList' - : 'showList']( - values, - Object.assign({ - path: current, - open: function(v){ - // update value... - // XXX current is [[value]], check - // the upstream if this is correct... - current = v[0][0] - // NOTE: this is done first - // to update values... - o.close() - // update callable values... - options.list_editable - && options.values instanceof Function - && options.values.call(actions, values) }, - close: function(){ - // NOTE: set(..) should be - // called after all the - // dialog stuff is done... - setTimeout(function(){ set(current) }) }, - }, - options.list !== true ? - options.list - : {}) ) } - - // directly toggle next value... - } else { - // XXX should we be able to toggle values back??? - set(values[(values.indexOf(current) + 1) % values.length]) } - }, - }, + toggler_defaults, options // normalize value... .run(function(){ @@ -1271,8 +1277,7 @@ function(spec, callback){ // the user to get it via closure... spec, // XXX is this the right spot for this??? - mode) - }) + mode) }) return this } From 487eb5c1674bf7b7cf78ffd5a8e177a672f5012c Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Tue, 14 Jan 2020 21:29:50 +0300 Subject: [PATCH 3/5] refactoring from elements... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/ui-widgets.js | 202 ++++++++++++++++--------------- 1 file changed, 102 insertions(+), 100 deletions(-) diff --git a/ui (gen4)/features/ui-widgets.js b/ui (gen4)/features/ui-widgets.js index 02de9dbd..bac1dbe9 100755 --- a/ui (gen4)/features/ui-widgets.js +++ b/ui (gen4)/features/ui-widgets.js @@ -1087,7 +1087,6 @@ browse.items.makeSubContext('field', // - a way to define defaults -- global options? // - access to the .app -- should be configurable... // - default methods .showEditableList(..) / .showList(..) on make(..) -// XXX need to make this handle updates correctly... browse.items.field.Toggle = function(title, options){ var that = this @@ -1100,113 +1099,113 @@ function(title, options){ : args.shift() options = args.shift() || {} - // user open handler... var open = options.open - // toggler default settings... - var toggler_defaults = options.__toggle_setup ? - {} - : { - __toggler_setup: true, + var toggler_defaults = + // only setup once... + options.__toggle_setup ? + {} + : { + __toggler_setup: true, - // XXX do we need a .type ??? - //type: options.type || 'toggle', + // XXX do we need a .type ??? + //type: options.type || 'toggle', - open: function(evt){ - open - && open.call(this, ...arguments) + open: function(evt){ + open + && open.call(this, ...arguments) - // XXX CONTEXT... - var actions = options.app || that.app + // XXX CONTEXT... + var actions = options.app || that.app - var getValues = function(){ - return options.values instanceof Function ? - options.values.call(actions) - : options.values ? - options.values - : ['off', 'on'] } - var set = function(v){ - // get current value... - v = arguments.length > 0 ? - v - : options.value instanceof Function ? - options.value.call(actions) - : options.value - // normalize... - // NOTE: we are re-getting the values here - // as it can get updated in options.list(..) - // or via options.values(..)... - if(!options.nonstrict){ - var values = getValues() - v = values.includes(v) ? - v - : values[0] } - // update the value... - // NOTE: we update the local value iff set(..) - // got an explicit value argument... - // calling set(..) will not store anything, - // just update the current state, either to - // the already stored value or to the output - // of .value(..)... - arguments.length > 0 - && (options.value instanceof Function ? - (v = options.value.call(actions, v)) - : (options.value = v)) - elem.text(v) - // update dialog... - options.doNotAutoUpdateDialog - || that.dialog.update() } + var getValues = function(){ + return options.values instanceof Function ? + options.values.call(actions) + : options.values ? + options.values + : ['off', 'on'] } + var set = function(v){ + // get current value... + v = arguments.length > 0 ? + v + : options.value instanceof Function ? + options.value.call(actions) + : options.value + // normalize... + // NOTE: we are re-getting the values here + // as it can get updated in options.list(..) + // or via options.values(..)... + if(!options.nonstrict){ + var values = getValues() + v = values.includes(v) ? + v + : values[0] } + // update the value... + // NOTE: we update the local value iff set(..) + // got an explicit value argument... + // calling set(..) will not store anything, + // just update the current state, either to + // the already stored value or to the output + // of .value(..)... + arguments.length > 0 + && (options.value instanceof Function ? + (v = options.value.call(actions, v)) + : (options.value = v)) + elem.text(v) + // update dialog... + options.doNotAutoUpdateDialog + || that.dialog.update() } - var elem = $(this).find('.text').last() - var current = elem.text() - var values = getValues() + var elem = $(this).find('.text').last() + var current = elem.text() + var values = getValues() - // editable list or more than 2 values -> show value list... - if(options.list_editable - || (values.length > 2 - && options.list !== false)){ - // call options.list(..) - if(options.list instanceof Function){ - options.list.call(actions, current, set) + // editable list or more than 2 values -> show value list... + if(options.list_editable + || (values.length > 2 + && options.list !== false)){ + // call options.list(..) + if(options.list instanceof Function){ + options.list.call(actions, current, set) - // normal list... + // normal list... + } else { + // XXX where do we get these when context in make(..) + // XXX mark the current value??? + var o = actions[ + options.list_editable ? + 'showEditableList' + : 'showList']( + values, + Object.assign({ + path: current, + open: function(v){ + // update value... + // XXX current is [[value]], check + // the upstream if this is correct... + current = v[0][0] + // NOTE: this is done first + // to update values... + o.close() + // update callable values... + options.list_editable + && options.values instanceof Function + && options.values.call(actions, values) }, + close: function(){ + // NOTE: set(..) should be + // called after all the + // dialog stuff is done... + setTimeout(function(){ set(current) }) }, + }, + options.list !== true ? + options.list + : {}) ) } + + // directly toggle next value... } else { - // XXX where do we get these when context in make(..) - // XXX mark the current value??? - var o = actions[ - options.list_editable ? - 'showEditableList' - : 'showList']( - values, - Object.assign({ - path: current, - open: function(v){ - // update value... - // XXX current is [[value]], check - // the upstream if this is correct... - current = v[0][0] - // NOTE: this is done first - // to update values... - o.close() - // update callable values... - options.list_editable - && options.values instanceof Function - && options.values.call(actions, values) }, - close: function(){ - // NOTE: set(..) should be - // called after all the - // dialog stuff is done... - setTimeout(function(){ set(current) }) }, - }, - options.list !== true ? - options.list - : {}) ) } - - // directly toggle next value... - } else { - // XXX should we be able to toggle values back??? - set(values[(values.indexOf(current) + 1) % values.length]) } - } } + // XXX should we be able to toggle values back??? + set(values[(values.indexOf(current) + 1) % values.length]) } + } } return this.field(title, value, Object.assign( @@ -1235,12 +1234,11 @@ function(title, options){ // XXX should this also take batch options??? -// XXX need to make this handle updates correctly... browse.items.batch = function(spec, callback){ var that = this // build the fields... - ;(spec || []) + spec .forEach(function(field){ // array... field instanceof Array ? @@ -1258,6 +1256,8 @@ function(spec, callback){ : that(field) }) // batch callback... callback + // only setup events once... + && !spec.__batch_setup && this.dialog .close(function(mode){ // XXX get the field data and pass it to the callback... @@ -1278,6 +1278,8 @@ function(spec, callback){ spec, // XXX is this the right spot for this??? mode) }) + // XXX is this a good way to do this??? + spec.__batch_setup = true return this } From b162bbacb06c5ccd2bf1bf5350875869455aafa3 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 15 Jan 2020 02:31:55 +0300 Subject: [PATCH 4/5] refactoring and experimenting... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/examples.js | 18 +-- ui (gen4)/features/ui-widgets.js | 216 +++++++++++++++---------------- 2 files changed, 115 insertions(+), 119 deletions(-) diff --git a/ui (gen4)/features/examples.js b/ui (gen4)/features/examples.js index ab7a92cf..ff22efe6 100755 --- a/ui (gen4)/features/examples.js +++ b/ui (gen4)/features/examples.js @@ -946,15 +946,15 @@ var ExampleUIActions = actions.Actions({ {title: 'foo', value: 123}, {type: 'field.Toggle', title: 'Batch toggle 1: '}, ]) - make.field.batch(b2 = b2 || [ - '---', - ['X', 'Y'], - {type: 'Toggle', title: 'foo', values: ['1','2','3'], list: false}, - {type: 'Toggle', title: 'Batch toggle 2: '}, - ], function(){ - console.log('---', ...arguments) - }) - + make.field.batch( + b2 = b2 || [ + '---', + ['X', 'Y'], + {type: 'Toggle', title: 'foo', values: ['1','2','3'], list: false}, + {type: 'Toggle', title: 'Batch toggle 2: '}, + ], + function(){ + console.log('-- (2nd batch) --', ...arguments) }) }, { cls: 'table-view', }) })], diff --git a/ui (gen4)/features/ui-widgets.js b/ui (gen4)/features/ui-widgets.js index bac1dbe9..bb3b3cfa 100755 --- a/ui (gen4)/features/ui-widgets.js +++ b/ui (gen4)/features/ui-widgets.js @@ -1045,7 +1045,6 @@ browse.items.makeSubContext = function(name, obj){ // ...this can be problematic as the wrapper is external to the browser... // - as a sub-path... // ...this is hard without side-effects... -// XXX need to make this handle updates correctly... browse.items.makeSubContext('field', function(title, value, options){ // parse arguments... @@ -1087,6 +1086,10 @@ browse.items.makeSubContext('field', // - a way to define defaults -- global options? // - access to the .app -- should be configurable... // - default methods .showEditableList(..) / .showList(..) on make(..) +// XXX currently if a user defines options.open it will fully override +// the default open behavior... +// ...need a way to deal with this, preferably automatically... +// ......test! browse.items.field.Toggle = function(title, options){ var that = this @@ -1099,118 +1102,110 @@ function(title, options){ : args.shift() options = args.shift() || {} - var open = options.open - var toggler_defaults = - // only setup once... - options.__toggle_setup ? - {} - : { - __toggler_setup: true, - - // XXX do we need a .type ??? - //type: options.type || 'toggle', - - open: function(evt){ - open - && open.call(this, ...arguments) - - // XXX CONTEXT... - var actions = options.app || that.app - - var getValues = function(){ - return options.values instanceof Function ? - options.values.call(actions) - : options.values ? - options.values - : ['off', 'on'] } - var set = function(v){ - // get current value... - v = arguments.length > 0 ? - v - : options.value instanceof Function ? - options.value.call(actions) - : options.value - // normalize... - // NOTE: we are re-getting the values here - // as it can get updated in options.list(..) - // or via options.values(..)... - if(!options.nonstrict){ - var values = getValues() - v = values.includes(v) ? - v - : values[0] } - // update the value... - // NOTE: we update the local value iff set(..) - // got an explicit value argument... - // calling set(..) will not store anything, - // just update the current state, either to - // the already stored value or to the output - // of .value(..)... - arguments.length > 0 - && (options.value instanceof Function ? - (v = options.value.call(actions, v)) - : (options.value = v)) - elem.text(v) - // update dialog... - options.doNotAutoUpdateDialog - || that.dialog.update() } - - - var elem = $(this).find('.text').last() - var current = elem.text() - var values = getValues() - - // editable list or more than 2 values -> show value list... - if(options.list_editable - || (values.length > 2 - && options.list !== false)){ - // call options.list(..) - if(options.list instanceof Function){ - options.list.call(actions, current, set) - - // normal list... - } else { - // XXX where do we get these when context in make(..) - // XXX mark the current value??? - var o = actions[ - options.list_editable ? - 'showEditableList' - : 'showList']( - values, - Object.assign({ - path: current, - open: function(v){ - // update value... - // XXX current is [[value]], check - // the upstream if this is correct... - current = v[0][0] - // NOTE: this is done first - // to update values... - o.close() - // update callable values... - options.list_editable - && options.values instanceof Function - && options.values.call(actions, values) }, - close: function(){ - // NOTE: set(..) should be - // called after all the - // dialog stuff is done... - setTimeout(function(){ set(current) }) }, - }, - options.list !== true ? - options.list - : {}) ) } - - // directly toggle next value... - } else { - // XXX should we be able to toggle values back??? - set(values[(values.indexOf(current) + 1) % values.length]) } - } } - return this.field(title, value, Object.assign( options, - toggler_defaults, + options.__toggle_setup ? + {} + : { + __toggler_setup: true, + + // XXX do we need a .type ??? + //type: options.type || 'toggle', + + open: function(evt){ + // XXX CONTEXT... + var actions = options.app || that.app + + var getValues = function(){ + return options.values instanceof Function ? + options.values.call(actions) + : options.values ? + options.values + : ['off', 'on'] } + var set = function(v){ + // get current value... + v = arguments.length > 0 ? + v + : options.value instanceof Function ? + options.value.call(actions) + : options.value + // normalize... + // NOTE: we are re-getting the values here + // as it can get updated in options.list(..) + // or via options.values(..)... + if(!options.nonstrict){ + var values = getValues() + v = values.includes(v) ? + v + : values[0] } + // update the value... + // NOTE: we update the local value iff set(..) + // got an explicit value argument... + // calling set(..) will not store anything, + // just update the current state, either to + // the already stored value or to the output + // of .value(..)... + arguments.length > 0 + && (options.value instanceof Function ? + (v = options.value.call(actions, v)) + : (options.value = v)) + elem.text(v) + // update dialog... + options.doNotAutoUpdateDialog + || that.dialog.update() } + + + var elem = $(this).find('.text').last() + var current = elem.text() + var values = getValues() + + // editable list or more than 2 values -> show value list... + if(options.list_editable + || (values.length > 2 + && options.list !== false)){ + // call options.list(..) + if(options.list instanceof Function){ + options.list.call(actions, current, set) + + // normal list... + } else { + // XXX where do we get these when context in make(..) + // XXX mark the current value??? + var o = actions[ + options.list_editable ? + 'showEditableList' + : 'showList']( + values, + Object.assign({ + path: current, + open: function(v){ + // update value... + // XXX current is [[value]], check + // the upstream if this is correct... + current = v[0][0] + // NOTE: this is done first + // to update values... + o.close() + // update callable values... + options.list_editable + && options.values instanceof Function + && options.values.call(actions, values) }, + close: function(){ + // NOTE: set(..) should be + // called after all the + // dialog stuff is done... + setTimeout(function(){ set(current) }) }, + }, + options.list !== true ? + options.list + : {}) ) } + + // directly toggle next value... + } else { + // XXX should we be able to toggle values back??? + set(values[(values.indexOf(current) + 1) % values.length]) } + } }, options // normalize value... .run(function(){ @@ -1234,6 +1229,7 @@ function(title, options){ // XXX should this also take batch options??? +// XXX close event is sometimes triggered twice... browse.items.batch = function(spec, callback){ var that = this From bc3e7c9946ddf1a3ecd9dc3e29a076c6c889ec5b Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Thu, 16 Jan 2020 09:28:46 +0300 Subject: [PATCH 5/5] ... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/ui-widgets.js | 1 - 1 file changed, 1 deletion(-) diff --git a/ui (gen4)/features/ui-widgets.js b/ui (gen4)/features/ui-widgets.js index bb3b3cfa..d30ca746 100755 --- a/ui (gen4)/features/ui-widgets.js +++ b/ui (gen4)/features/ui-widgets.js @@ -1089,7 +1089,6 @@ browse.items.makeSubContext('field', // XXX currently if a user defines options.open it will fully override // the default open behavior... // ...need a way to deal with this, preferably automatically... -// ......test! browse.items.field.Toggle = function(title, options){ var that = this