Updated Branches: refs/heads/master 53e056052 -> f40f4f7eb
Add ability to defer a change to the Palette until after a confirmation dialog Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/a9bdf414 Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/a9bdf414 Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/a9bdf414 Branch: refs/heads/master Commit: a9bdf414771678a6970e7459e955f6601e98e3e3 Parents: 53e0560 Author: Howard M. Lewis Ship <[email protected]> Authored: Tue Jun 11 07:49:03 2013 -0700 Committer: Howard M. Lewis Ship <[email protected]> Committed: Tue Jun 11 07:49:03 2013 -0700 ---------------------------------------------------------------------- .../META-INF/modules/t5/core/events.coffee | 2 + .../META-INF/modules/t5/core/palette.coffee | 62 ++++++++++++-------- 2 files changed, 38 insertions(+), 26 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a9bdf414/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/events.coffee ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/events.coffee b/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/events.coffee index 4054520..8d0efd3 100644 --- a/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/events.coffee +++ b/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/events.coffee @@ -130,6 +130,8 @@ define # * selectedValues - list of selected values (if change is allowed) # * reorder - if true, then the event represents changing the ordrer of the selections only # * cancel - function to invoke to prevent the change to the Palette from occurring + # * defer - like cancel, but returns a no-arguments function that will perform the update at a later date (e.g., + # after a confirmation panel) willChange: "t5:palette:willChange" # Event triggered after the selection has changed. The memo object has one property: # * selectedValues - list of selected values http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a9bdf414/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/palette.coffee ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/palette.coffee b/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/palette.coffee index 9f8cc4c..f119496 100644 --- a/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/palette.coffee +++ b/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/palette.coffee @@ -136,7 +136,7 @@ define ["./dom", "underscore", "./events"], # The element before the first selected element is the pivot; all the selected elements will # move before the pivot. If there is no pivot, the elements are shifted to the front of the list. - firstMoverIndex= _.first(movers).index + firstMoverIndex = _.first(movers).index pivot = options[firstMoverIndex - 1] options = _.reject options, isSelected @@ -178,15 +178,8 @@ define ["./dom", "underscore", "./events"], canceled = false - memo = - selectedValues: _.pluck options, "value" - reorder: true - cancel: -> canceled = true - - @selected.trigger events.palette.willChange, memo - - unless canceled + doUpdate = => @deleteOptions @selected for o in options @@ -196,6 +189,18 @@ define ["./dom", "underscore", "./events"], @updateAfterChange() + memo = + selectedValues: _.pluck options, "value" + reorder: true + cancel: -> canceled = true + defer: -> + canceled = true + return doUpdate + + @selected.trigger events.palette.willChange, memo + + doUpdate() unless canceled + # Deletes all options from a select (an ElementWrapper), prior to new options being populated in. deleteOptions: (select) -> @@ -223,32 +228,37 @@ define ["./dom", "underscore", "./events"], canceled = false + doUpdate = => + for i in [(from.element.length - 1)..0] by -1 + if from.element.options[i].selected + from.element.remove i + + # A bit ugly: update the to select by removing all, then adding back in. + + for i in [(to.element.length - 1)..0] by -1 + to.element.options[i].selected = false + to.element.remove i + + for o in toOptions + to.element.add o, null + + @selected.trigger events.palette.didChange, memo + + @updateAfterChange() + memo = selectedValues: _.pluck selectedOptions, "value" reorder: false cancel: -> canceled = true + defer: -> + canceled = true + return doUpdate @selected.trigger events.palette.willChange, memo - return if canceled + doUpdate() unless canceled # Remove the movers (the selected from elements): - for i in [(from.element.length - 1)..0] by -1 - if from.element.options[i].selected - from.element.remove i - - # A bit ugly: update the to select by removing all, then adding back in. - - for i in [(to.element.length - 1)..0] by -1 - to.element.options[i].selected = false - to.element.remove i - - for o in toOptions - to.element.add o, null - - @selected.trigger events.palette.didChange, memo - - @updateAfterChange() insertOption: (options, option, atEnd) ->
