Ignore:
Timestamp:
03/10/14 00:47:38 (11 years ago)
Author:
hendrikvanantwerpen
Message:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/trunk/src/client/qed-client/widgets/Selector.js

    r494 r495  
    6464            var actions = {};
    6565            var action = null;
    66             if ( this.selectedActions !== null ) {
    67                 for (var actionName in this.selectedActions) {
    68                     if ( this.selectedActions.hasOwnProperty(actionName) ) {
    69                         action = this.selectedActions[actionName];
     66            var userActions =
     67                    lang.isFunction(this.selectedActions) ?
     68                    this.selectedActions() :
     69                    this.selectedActions;
     70            if ( userActions ) {
     71                for (var actionName in userActions) {
     72                    if ( userActions.hasOwnProperty(actionName) ) {
     73                        action = userActions[actionName];
    7074                        actions[actionName] = {
    7175                            callback: action.callback &&
    72                                     lang.hitch(this,this._onSelectedAction,
    73                                             action.callback),
     76                                      lang.hitch(this,this._onSelectedAction,
     77                                                 action.callback),
    7478                            properties: {
    7579                                blockButton: true,
     
    135139        _onSelectedAction: function(callback) {
    136140            if (this._selectedItem && callback) {
    137                 callback(this._selectedItem);
     141                callback(this._selectedItem,this);
    138142            }
    139143        },
     
    171175            }
    172176        },
     177        removeItem: function(item) {
     178            var nodes = this._source ?
     179                        this._source.getAllNodes() :
     180                        this.optionsNode.childNodes;
     181            baseArray.forEach(nodes, function(node) {
     182                var widget = registry.byNode(node);
     183                if ( widget && this.itemEquals ?
     184                               this.itemEquals(widget.__item,item) :
     185                               widget.__item === item ) {
     186                    widget.destroyRecursive();
     187                    if ( this._source ) { this._source.delItem(widget.id); }
     188                }
     189            }, this);
     190        },
    173191        _createNode: function(item, hint) {
    174192            var node = hint === "avatar" ?
     
    188206        _createLineNode: function(item) {
    189207            var actions = {};
    190             var action;
    191             if (this.itemActions) {
    192                 for (var actionName in this.itemActions) {
    193                     if ( this.itemActions.hasOwnProperty(actionName) ) {
    194                         action = this.itemActions[actionName];
     208            var userActions =
     209                    lang.isFunction(this.itemActions) ?
     210                    this.itemActions(item) :
     211                    this.itemActions;
     212            if (userActions) {
     213                for (var actionName in userActions) {
     214                    if ( userActions.hasOwnProperty(actionName) ) {
     215                        var action = userActions[actionName];
    195216                        actions[actionName] = {
    196                             callback: action.callback && lang.partial(action.callback,item),
     217                            callback: action.callback &&
     218                                      lang.partial(action.callback,item,this),
    197219                            properties: {
    198220                                blockButton: false,
     
    207229            var w = new LineWithActionsWidget({
    208230                title: get(this.itemTitle,item),
    209                 actions: actions
     231                actions: actions,
     232                __item: item
    210233            });
    211234            w.startup();
     
    214237        },
    215238
    216         onSelect: function(/*item*/) {}
     239        onSelect: function(/*item*/) {},
     240
     241        destroy: function() {
     242            if ( this._source ) { this._source.destroy(); }
     243            this.inherited(arguments);
     244        }
    217245    });
    218246});
Note: See TracChangeset for help on using the changeset viewer.