mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 02:10:08 +00:00
refactoring from elements...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
509924db53
commit
487eb5c167
@ -1087,7 +1087,6 @@ 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...
|
|
||||||
browse.items.field.Toggle =
|
browse.items.field.Toggle =
|
||||||
function(title, options){
|
function(title, options){
|
||||||
var that = this
|
var that = this
|
||||||
@ -1100,113 +1099,113 @@ function(title, options){
|
|||||||
: args.shift()
|
: args.shift()
|
||||||
options = args.shift() || {}
|
options = args.shift() || {}
|
||||||
|
|
||||||
// user open handler...
|
|
||||||
var open = options.open
|
var open = options.open
|
||||||
// toggler default settings...
|
var toggler_defaults =
|
||||||
var toggler_defaults = options.__toggle_setup ?
|
// only setup once...
|
||||||
{}
|
options.__toggle_setup ?
|
||||||
: {
|
{}
|
||||||
__toggler_setup: true,
|
: {
|
||||||
|
__toggler_setup: true,
|
||||||
|
|
||||||
// XXX do we need a .type ???
|
// XXX do we need a .type ???
|
||||||
//type: options.type || 'toggle',
|
//type: options.type || 'toggle',
|
||||||
|
|
||||||
open: function(evt){
|
open: function(evt){
|
||||||
open
|
open
|
||||||
&& open.call(this, ...arguments)
|
&& open.call(this, ...arguments)
|
||||||
|
|
||||||
// XXX CONTEXT...
|
// XXX CONTEXT...
|
||||||
var actions = options.app || that.app
|
var actions = options.app || that.app
|
||||||
|
|
||||||
var getValues = function(){
|
var getValues = function(){
|
||||||
return options.values instanceof Function ?
|
return options.values instanceof Function ?
|
||||||
options.values.call(actions)
|
options.values.call(actions)
|
||||||
: options.values ?
|
: options.values ?
|
||||||
options.values
|
options.values
|
||||||
: ['off', 'on'] }
|
: ['off', 'on'] }
|
||||||
var set = function(v){
|
var set = function(v){
|
||||||
// get current value...
|
// get current value...
|
||||||
v = arguments.length > 0 ?
|
v = arguments.length > 0 ?
|
||||||
v
|
v
|
||||||
: options.value instanceof Function ?
|
: options.value instanceof Function ?
|
||||||
options.value.call(actions)
|
options.value.call(actions)
|
||||||
: options.value
|
: options.value
|
||||||
// normalize...
|
// normalize...
|
||||||
// NOTE: we are re-getting the values here
|
// NOTE: we are re-getting the values here
|
||||||
// as it can get updated in options.list(..)
|
// as it can get updated in options.list(..)
|
||||||
// or via options.values(..)...
|
// or via options.values(..)...
|
||||||
if(!options.nonstrict){
|
if(!options.nonstrict){
|
||||||
var values = getValues()
|
var values = getValues()
|
||||||
v = values.includes(v) ?
|
v = values.includes(v) ?
|
||||||
v
|
v
|
||||||
: values[0] }
|
: values[0] }
|
||||||
// update the value...
|
// update the value...
|
||||||
// NOTE: we update the local value iff set(..)
|
// NOTE: we update the local value iff set(..)
|
||||||
// got an explicit value argument...
|
// got an explicit value argument...
|
||||||
// calling set(..) will not store anything,
|
// calling set(..) will not store anything,
|
||||||
// just update the current state, either to
|
// just update the current state, either to
|
||||||
// the already stored value or to the output
|
// the already stored value or to the output
|
||||||
// of .value(..)...
|
// of .value(..)...
|
||||||
arguments.length > 0
|
arguments.length > 0
|
||||||
&& (options.value instanceof Function ?
|
&& (options.value instanceof Function ?
|
||||||
(v = options.value.call(actions, v))
|
(v = options.value.call(actions, v))
|
||||||
: (options.value = v))
|
: (options.value = v))
|
||||||
elem.text(v)
|
elem.text(v)
|
||||||
// update dialog...
|
// update dialog...
|
||||||
options.doNotAutoUpdateDialog
|
options.doNotAutoUpdateDialog
|
||||||
|| that.dialog.update() }
|
|| 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]) }
|
|
||||||
} }
|
|
||||||
|
|
||||||
return this.field(title, value,
|
return this.field(title, value,
|
||||||
Object.assign(
|
Object.assign(
|
||||||
@ -1235,12 +1234,11 @@ function(title, options){
|
|||||||
|
|
||||||
|
|
||||||
// XXX should this also take batch options???
|
// XXX should this also take batch options???
|
||||||
// XXX need to make this handle updates correctly...
|
|
||||||
browse.items.batch =
|
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 ?
|
||||||
@ -1258,6 +1256,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...
|
||||||
@ -1278,6 +1278,8 @@ function(spec, callback){
|
|||||||
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 }
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user