Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-01-18 00:26:38 +03:00
commit d637b00c16
2 changed files with 112 additions and 108 deletions

View File

@ -946,15 +946,15 @@ var ExampleUIActions = actions.Actions({
{title: 'foo', value: 123}, {title: 'foo', value: 123},
{type: 'field.Toggle', title: 'Batch toggle 1: '}, {type: 'field.Toggle', title: 'Batch toggle 1: '},
]) ])
make.field.batch(b2 = b2 || [ make.field.batch(
'---', b2 = b2 || [
['X', 'Y'], '---',
{type: 'Toggle', title: 'foo', values: ['1','2','3'], list: false}, ['X', 'Y'],
{type: 'Toggle', title: 'Batch toggle 2: '}, {type: 'Toggle', title: 'foo', values: ['1','2','3'], list: false},
], function(){ {type: 'Toggle', title: 'Batch toggle 2: '},
console.log('---', ...arguments) ],
}) function(){
console.log('-- (2nd batch) --', ...arguments) })
}, { }, {
cls: 'table-view', cls: 'table-view',
}) })], }) })],

View File

@ -1045,7 +1045,6 @@ browse.items.makeSubContext = function(name, obj){
// ...this can be problematic as the wrapper is external to the browser... // ...this can be problematic as the wrapper is external to the browser...
// - as a sub-path... // - as a sub-path...
// ...this is hard without side-effects... // ...this is hard without side-effects...
// XXX need to make this handle updates correctly...
browse.items.makeSubContext('field', browse.items.makeSubContext('field',
function(title, value, options){ function(title, value, options){
// parse arguments... // parse arguments...
@ -1087,7 +1086,9 @@ browse.items.makeSubContext('field',
// - a way to define defaults -- global options? // - a way to define defaults -- global options?
// - access to the .app -- should be configurable... // - access to the .app -- should be configurable...
// - default methods .showEditableList(..) / .showList(..) on make(..) // - default methods .showEditableList(..) / .showList(..) on make(..)
// XXX need to make this handle updates correctly... // 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...
browse.items.field.Toggle = browse.items.field.Toggle =
function(title, options){ function(title, options){
var that = this var that = this
@ -1103,107 +1104,107 @@ function(title, options){
return this.field(title, value, return this.field(title, value,
Object.assign( Object.assign(
options, options,
{ options.__toggle_setup ?
// XXX do we need a .type ??? {}
//type: options.type || 'toggle', : {
__toggler_setup: true,
// XXX need to: // XXX do we need a .type ???
// - call options.open if it exists... //type: options.type || 'toggle',
// - do not define this if we already did...
open: function(evt){
// XXX CONTEXT...
var actions = options.app || that.app
var getValues = function(){ open: function(evt){
return options.values instanceof Function ? // XXX CONTEXT...
options.values.call(actions) var actions = options.app || that.app
: options.values ?
options.values var getValues = function(){
: ['off', 'on'] } return options.values instanceof Function ?
var set = function(v){ options.values.call(actions)
// get current value... : options.values ?
v = arguments.length > 0 ? options.values
v : ['off', 'on'] }
: options.value instanceof Function ? var set = function(v){
options.value.call(actions) // get current value...
: options.value v = arguments.length > 0 ?
// normalize... v
// NOTE: we are re-getting the values here : options.value instanceof Function ?
// as it can get updated in options.list(..) options.value.call(actions)
// or via options.values(..)... : options.value
if(!options.nonstrict){ // normalize...
var values = getValues() // NOTE: we are re-getting the values here
v = values.includes(v) ? // as it can get updated in options.list(..)
v // or via options.values(..)...
: values[0] } if(!options.nonstrict){
// update the value... var values = getValues()
// NOTE: we update the local value iff set(..) v = values.includes(v) ?
// got an explicit value argument... v
// calling set(..) will not store anything, : values[0] }
// just update the current state, either to // update the value...
// the already stored value or to the output // NOTE: we update the local value iff set(..)
// of .value(..)... // got an explicit value argument...
arguments.length > 0 // calling set(..) will not store anything,
&& (options.value instanceof Function ? // just update the current state, either to
(v = options.value.call(actions, v)) // the already stored value or to the output
: (options.value = v)) // of .value(..)...
elem.text(v) arguments.length > 0
// update dialog... && (options.value instanceof Function ?
options.doNotAutoUpdateDialog (v = options.value.call(actions, v))
|| that.dialog.update() } : (options.value = v))
elem.text(v)
// update dialog...
options.doNotAutoUpdateDialog
|| that.dialog.update() }
var elem = $(this).find('.text').last() var elem = $(this).find('.text').last()
var current = elem.text() var current = elem.text()
var values = getValues() var values = getValues()
// editable list or more than 2 values -> show value list... // editable list or more than 2 values -> show value list...
if(options.list_editable if(options.list_editable
|| (values.length > 2 || (values.length > 2
&& options.list !== false)){ && options.list !== false)){
// call options.list(..) // call options.list(..)
if(options.list instanceof Function){ if(options.list instanceof Function){
options.list.call(actions, current, set) 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 { } else {
// XXX where do we get these when context in make(..) // XXX should we be able to toggle values back???
// XXX mark the current value??? set(values[(values.indexOf(current) + 1) % values.length]) }
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 options
// normalize value... // normalize value...
.run(function(){ .run(function(){
@ -1232,7 +1233,7 @@ browse.items.batch =
function(spec, callback){ function(spec, callback){
var that = this var that = this
// build the fields... // build the fields...
;(spec || []) spec
.forEach(function(field){ .forEach(function(field){
// array... // array...
field instanceof Array ? field instanceof Array ?
@ -1250,6 +1251,8 @@ function(spec, callback){
: that(field) }) : that(field) })
// batch callback... // batch callback...
callback callback
// only setup events once...
&& !spec.__batch_setup
&& this.dialog && this.dialog
.close(function(mode){ .close(function(mode){
// XXX get the field data and pass it to the callback... // XXX get the field data and pass it to the callback...
@ -1269,8 +1272,9 @@ function(spec, callback){
// the user to get it via closure... // the user to get it via closure...
spec, spec,
// XXX is this the right spot for this??? // XXX is this the right spot for this???
mode) mode) })
}) // XXX is this a good way to do this???
spec.__batch_setup = true
return this } return this }