mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 02:10:08 +00:00
experimenting...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
1fd1211f41
commit
0ace8dd7aa
@ -959,31 +959,154 @@ module.Dialogs = core.ImageGridFeatures.Feature({
|
|||||||
|
|
||||||
|
|
||||||
// XXX EXPERIMENT...
|
// XXX EXPERIMENT...
|
||||||
// - which is more logical the generic make.Field(..) or the
|
// Q: What should we use as context for the getters and callbacks?
|
||||||
// .makeEditor(..) and friends???
|
// ...there are several ways to go:
|
||||||
// or should we have both??
|
// - "this" generic make object + manual binding
|
||||||
// ...there is merit in having a "storable" dialog so regardless
|
// + generic, already implemented...
|
||||||
// of the final architecture, it would be logical to have:
|
// - requires manual binding...
|
||||||
// - simple generic Array / Object / JSON constructors...
|
// - explicit context in arguments or options
|
||||||
// - storable "full" format constructors...
|
// - breaks the general API...
|
||||||
// - the make(..) and friends API for custom stuff...
|
// - a context manager API...
|
||||||
// - how do we handle the ImageGrid context here (i.e. actions)???
|
// - complexity...
|
||||||
// ...one way would be to split the fields into two levels, the
|
// XXX Q: do we actually need .Field(..), it does everything make(..)
|
||||||
// generic and the domain-specific...
|
// does already???
|
||||||
// ...one way could be something like:
|
// XXX Q: should title/value args be optional???
|
||||||
// make.setGetterContext(context)
|
|
||||||
// and in all the getters use:
|
|
||||||
// getter.call(make.getterContext, ...)
|
|
||||||
// XXX REVISE...
|
// XXX REVISE...
|
||||||
browse.items.Field =
|
browse.items.Field =
|
||||||
function(actions, options){
|
function(title, value, options){
|
||||||
|
options = options || {}
|
||||||
|
Object.assign(
|
||||||
|
options,
|
||||||
|
{
|
||||||
|
title,
|
||||||
|
value,
|
||||||
|
})
|
||||||
return this([
|
return this([
|
||||||
options.title,
|
title,
|
||||||
options.value instanceof Function ?
|
options.value instanceof Function ?
|
||||||
options.value(actions)
|
options.value(this)
|
||||||
: options.value
|
: options.value
|
||||||
], options) }
|
], options) }
|
||||||
|
|
||||||
|
// XXX need to open a list dialog (currently context is used)...
|
||||||
|
browse.items.Toggle =
|
||||||
|
function(title, value, options){
|
||||||
|
var that = this
|
||||||
|
return this.Field(title, value,
|
||||||
|
Object.assign(
|
||||||
|
options,
|
||||||
|
{
|
||||||
|
type: 'toggle',
|
||||||
|
|
||||||
|
open: function(evt){
|
||||||
|
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(){
|
||||||
|
if(!(this.value instanceof Function)){
|
||||||
|
var values = options.values instanceof Function ?
|
||||||
|
options.values.call(actions)
|
||||||
|
: options.values ?
|
||||||
|
options.values
|
||||||
|
: ['off', 'on']
|
||||||
|
this.value =
|
||||||
|
this.value === undefined ?
|
||||||
|
values[0]
|
||||||
|
: values.includes(this.value) ?
|
||||||
|
this.value
|
||||||
|
: this.value ?
|
||||||
|
'on'
|
||||||
|
: 'off' } }))) }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user