Wire up double-click actions Remove some failures to move options to/from selected list Update the buttons when either select fires a "change" event
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/c2a7e3f8 Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/c2a7e3f8 Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/c2a7e3f8 Branch: refs/heads/5.4-js-rewrite Commit: c2a7e3f858ec5dc83bd55f3ccbb946d39fe38181 Parents: b48e83e Author: Howard M. Lewis Ship <[email protected]> Authored: Wed Nov 7 10:14:42 2012 -0800 Committer: Howard M. Lewis Ship <[email protected]> Committed: Wed Nov 7 10:14:42 2012 -0800 ---------------------------------------------------------------------- .../META-INF/modules/core/palette.coffee | 38 ++++++++++---- 1 files changed, 27 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/c2a7e3f8/tapestry-core/src/main/coffeescript/META-INF/modules/core/palette.coffee ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/coffeescript/META-INF/modules/core/palette.coffee b/tapestry-core/src/main/coffeescript/META-INF/modules/core/palette.coffee index c257eeb..9bbb85f 100644 --- a/tapestry-core/src/main/coffeescript/META-INF/modules/core/palette.coffee +++ b/tapestry-core/src/main/coffeescript/META-INF/modules/core/palette.coffee @@ -21,15 +21,15 @@ define ["core/dom", "_"], constructor: (id) -> @selected = (dom id) - container = @selected.findContainer ".t-palette" - @available = container.findFirst ".t-palette-available select" - @hidden = container.findFirst "input[type=hidden]" + @container = @selected.findContainer ".t-palette" + @available = @container.findFirst ".t-palette-available select" + @hidden = @container.findFirst "input[type=hidden]" - @select = container.findFirst "[data-action=select]" - @deselect = container.findFirst "[data-action=deselect]" + @select = @container.findFirst "[data-action=select]" + @deselect = @container.findFirst "[data-action=deselect]" - @moveUp = container.findFirst "[data-action=move-up]" - @moveDown = container.findFirst "[data-action=move-down]" + @moveUp = @container.findFirst "[data-action=move-up]" + @moveDown = @container.findFirst "[data-action=move-down]" # Track where reorder is allowed based on whether the buttons actually exist @reorder = @moveUp isnt null @@ -70,18 +70,30 @@ define ["core/dom", "_"], @selected.element.add option updateHidden: -> - values = _.pluck(this.selected, "value") - hidden.value JSON.stringify values + values = _.pluck(@selected.element.options, "value") + @hidden.value JSON.stringify values bindEvents: -> + @container.on "change", "select", => + @updateButtons() + return false + @select.on "click", => @doSelect() return false + @available.on "dblclick", => + @doSelect() + return false + @deselect.on "click", => @doDeselect() return false + @selected.on "dblclick", => + @doDeselect() + return false + updateButtons: -> @select.element.disabled = @available.element.selectedIndex < 0 @@ -93,6 +105,10 @@ define ["core/dom", "_"], @moveUp.disabled = nothingSelected or @allSelectionsAtTop() @moveDown.disabled = nothingSelected or @allSelectionsAtBottom() + doSelect: -> @transferOptions @available, @selected, @reorder + + doDeselect: -> @transferOptions @selected, @available, false + transferOptions: (from, to, atEnd) -> if from.element.selectedIndex is -1 return @@ -111,7 +127,7 @@ define ["core/dom", "_"], for i in [(e.length - 1)..(e.selectedIndex)] by -1 o = options[i] if o.selected - select.remove i + e.remove i movers.unshift o return movers @@ -123,7 +139,7 @@ define ["core/dom", "_"], @updateHidden() @updateButtons() - moveOptions: (option, to, atEnd) -> + moveOption: (option, to, atEnd) -> before = null unless atEnd
