reworked button placement...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-02-08 02:49:15 +03:00
parent a6628c42b8
commit fd4b663c1e
2 changed files with 92 additions and 98 deletions

View File

@ -1684,11 +1684,6 @@ var WidgetTestActions = actions.Actions({
make.EditableList(letters, { make.EditableList(letters, {
list_id: 'letters', list_id: 'letters',
sortable: 'y', sortable: 'y',
buttons: [
'TO_TOP',
'UP',
],
}) })
// NOTE: the dialog's .parent is not yet set at this point... // NOTE: the dialog's .parent is not yet set at this point...
@ -1726,11 +1721,10 @@ var WidgetTestActions = actions.Actions({
make.EditablePinnedList(letters, pins, { make.EditablePinnedList(letters, pins, {
list_id: 'letters', list_id: 'letters',
//pins_sortable: false, //pins_sortable: false,
/*buttons: [ buttons: [
'PIN', 'UP',
'REMOVE', 'TO_BOTTOM',
], ],
//*/
}) })
// NOTE: the dialog's .parent is not yet set at this point... // NOTE: the dialog's .parent is not yet set at this point...

View File

@ -690,10 +690,32 @@ function(list, options){
} }
var buttons = options.buttons = (options.buttons || []).slice() var buttons = options.buttons = (options.buttons || []).slice()
var _buttons = {}
// manual sorting buttons... // options buttons...
// NOTE: the order here is important...
if(editable && !options.sort){ if(editable && !options.sort){
// up/down...
options.item_order_buttons
&& buttons.indexOf('UP') < 0
&& buttons.push('UP')
options.item_order_buttons
&& buttons.indexOf('DOWN') < 0
&& buttons.push('DOWN')
// top/bottom...
options.to_top_button
&& buttons.indexOf('TO_TOP') < 0
&& buttons.push('TO_TOP')
options.to_bottom_button
&& buttons.indexOf('TO_BOTTOM') < 0
&& buttons.push('TO_BOTTOM')
}
// 'x' button...
editable
&& options.delete_button !== false
&& buttons.indexOf('REMOVE') < 0
&& buttons.push('REMOVE')
var move = function(p, offset){ var move = function(p, offset){
var l = dialog.__list[id] var l = dialog.__list[id]
var i = l.indexOf(p) var i = l.indexOf(p)
@ -718,75 +740,51 @@ function(list, options){
// return the shift distance... // return the shift distance...
return j - i return j - i
} }
var __buttons = {
// up/down... UP: [options.shift_up_button || '&#9206;',
if(options.item_order_buttons
|| buttons.indexOf('UP') >= 0){
_buttons['UP'] = [
options.shift_up_button || '&#9206;',
function(p, e){ function(p, e){
move(p, -1) move(p, -1)
&& e.prev().before(e) } && e.prev().before(e) }],
] DOWN: [options.shift_down_button || '&#9207;',
}
if(options.item_order_buttons
|| buttons.indexOf('DOWN') >= 0){
_buttons['DOWN'] = [
options.shift_down_button || '&#9207;',
function(p, e){ function(p, e){
move(p, 1) move(p, 1)
&& e.next().after(e) } && e.next().after(e) }],
] TO_TOP: [
} (options.to_top_button === true
|| buttons.indexOf('TO_TOP') >= 0) ?
// top...
var i = buttons.indexOf('TO_TOP')
if(options.to_top_button || i >= 0){
_buttons['TO_TOP'] = [
(options.to_top_button === true || i >= 0) ?
'&#10514;' '&#10514;'
: options.to_top_button, : options.to_top_button,
function(p, e){ function(p, e){
var d = move(p, -dialog.__list[id].length) var d = move(p, -dialog.__list[id].length)
d && e.prevAll().eq(Math.abs(d+1)).before(e) d && e.prevAll().eq(Math.abs(d+1)).before(e)
} }],
] TO_BOTTOM: [
} (options.to_bottom_button === true
|| buttons.indexOf('TO_BOTTOM') >= 0) ?
// bottom...
var i = buttons.indexOf('TO_BOTTOM')
if(options.to_bottom_button || i >= 0){
_buttons['TO_BOTTOM'] = [
(options.to_bottom_button === true || i >= 0) ?
'&#10515;' '&#10515;'
: options.to_bottom_button, : options.to_bottom_button,
function(p, e){ function(p, e){
var d = move(p, dialog.__list[id].length) var d = move(p, dialog.__list[id].length)
d && e.nextAll().eq(Math.abs(d)).before(e) d && e.nextAll().eq(Math.abs(d)).before(e)
} }],
] REMOVE: Buttons.markForRemoval(
}
}
// 'x' button if not disabled...
editable
&& options.delete_button !== false
&& (_buttons['REMOVE'] = Buttons.markForRemoval(
to_remove, to_remove,
options.delete_button !== true ? options.delete_button !== true ?
options.delete_button options.delete_button
: undefined)) : undefined)
}
// add the buttons... // replace the button placeholders...
Object.keys(_buttons).forEach(function(key){
var i = buttons.indexOf(key)
i < 0 ?
buttons.push(_buttons[key])
: buttons.splice(i, 1, _buttons[key])
})
// clear out the unused button placeholders...
buttons = options.buttons = buttons = options.buttons =
buttons.filter(function(b){ buttons
.map(function(button){
return button in __buttons ?
__buttons[button]
: button[1] in __buttons ?
[button[0], __buttons[button[1]][1]]
: button.slice() })
// clear out the unused button placeholders...
.filter(function(b){
return ['UP', 'DOWN', 'TO_TOP', 'TO_BOTTOM', 'REMOVE'].indexOf(b) < 0 }) return ['UP', 'DOWN', 'TO_TOP', 'TO_BOTTOM', 'REMOVE'].indexOf(b) < 0 })
// if we are sortable then we will need to also be grouped... // if we are sortable then we will need to also be grouped...
@ -1037,6 +1035,8 @@ function(list, pins, options){
length_limit: options.pins_length_limit || 10, length_limit: options.pins_length_limit || 10,
isItemHidden: null, isItemHidden: null,
buttons: options.buttons.slice(),
} }
pins_options.__proto__ = options pins_options.__proto__ = options
var sortable = pins_options.sortable = var sortable = pins_options.sortable =