basic editor dialog now working, still needs fields...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2019-11-11 04:18:04 +03:00
parent e65a1be292
commit 8b014c0e5b

View File

@ -964,6 +964,9 @@ var EditorActions = actions.Actions({
// ... // ...
// } // }
// //
// NOTE: we are not supporting aliases here as we need to pass strings
// as-is into .makeEditorBlock(..)'s spec to be able to create things
// like '---' -> <hr> and other stuff...
__editor_fields__: { __editor_fields__: {
// generic field... // generic field...
// //
@ -998,7 +1001,8 @@ var EditorActions = actions.Actions({
// - callback // - callback
// XXX Q: when do we get the data??? // XXX Q: when do we get the data???
field: function(actions, make, options){ field: function(actions, make, options){
console.log('>>>>', options.type, make, options) // XXX
make([options.title, options.value], options)
}, },
text: function(actions, make, options){ text: function(actions, make, options){
@ -1017,47 +1021,89 @@ var EditorActions = actions.Actions({
}, },
options)) options))
}, },
toggle: function(actions, make, options){
this.field(actions, make,
Object.assign(
{
type: 'toggle',
},
options))
},
// XXX todo: // XXX todo:
// - date // - date
// - ... // - ...
}, },
//
// Make an editor dialog...
// .makeEditor(spec, callback)
// -> dialog
//
// Make an editor dialog section...
// .makeEditor(make, spec, callback)
// -> make
//
// //
// spec format: // spec format:
// [ // [
// <text>, // <text>,
// //
// { // {
// type: <type> // type: <type>,
//
// id: <str>,
// title: <str>,
//
// value: <str>,
//
// ... // ...
// }, // },
// //
// ... // ...
// ] // ]
// //
// XXX does this need a callback??? makeEditor: ['- Interface/',
// XXX revise access to .__editor_fields__... makeUIDialog(function(spec, callback){
// ...should we merge the prototype set with the instance??? var _make = function(make, spec){
makeEditorBlock: ['- Interface/',
function(spec, make){
var that = this var that = this
var fields = this.__editor_fields__ var fields = this.__editor_fields__
|| EditorActions.__editor_fields__ || EditorActions.__editor_fields__
|| {} || {}
;(spec || []) ;(spec || [])
.map(function(field){ .forEach(function(field){
field instanceof Object ? // array...
field instanceof Array ?
make(...field)
// spec...
: field instanceof Object ?
fields[field.type](that, make, field) fields[field.type](that, make, field)
// other...
: make(field) }) : make(field) })
return make }], return make }
var _callback = callback
// XXX the callback is called to get initial data and to update/save it... && function(spec){
makeEditor: ['- Interface/', return callback(
makeUIDialog(function(spec, callback){ spec.reduce(function(res, e){
// XXX var id = e.id || e.title
})], id != undefined
&& (res[id] = e.value)
return res }, {}) ) }
return arguments[0] instanceof Function?
// inline...
_make.call(this, ...arguments)
// dialog...
: browse.makeLister(null,
function(p, make){
_make(make, spec)
}, {
cls: 'table-view',
})
// pass the results...
.close(function(){
_callback
&& _callback(spec) }) })],
}) })
var Editor = var Editor =