Letractively / jxlib

Automatically exported from code.google.com/p/jxlib
0 stars 0 forks source link

Jx.TabSet #170

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I have to retreive existing tab on a tabset, and there is no function for
that purpose. Then I coded one. Here is the code.

/**
     * Method: findByLabel
     * find tab with the name passed to this method
     *
     * Parameters:
     * name - {<string>} the tab to find.
    */
    findByLabel: function(name) 
    {
        var foundTab = false;

        this.tabs.each(
            function(tab)
            {
                if (tab.options.label == name){
                    foundTab = tab;
                }
            }.bind(name)
        );

        return foundTab;
    }

Original issue reported on code.google.com by hugues.gauthier@gmail.com on 5 Apr 2010 at 1:29

GoogleCodeExporter commented 8 years ago
Hugues, can you explain your usecase a little bit more?  I understand what this 
does but I'm not sure if I 
understand why it is necessary?

Original comment by pagameba on 16 Apr 2010 at 11:46

GoogleCodeExporter commented 8 years ago
For me this sounds useful. 
But it might be that a label exists twice or is localized. Also it could be 
useful if
the tab could be returned by the index (instead of using myTabSet.tabs[4] -> 
better
use a method myTabSet.getTab(4).

I tested it with anything that came to my mind and works well. I would add it 
to the
trunk that way this evening if no one declines:

/**
 * Method: getTab
 * get tab with the index or label passed to this method
 * label can either be a String or the object to localize
 * (depending on what is used to set the label of the tab)
 *
 * Parameters:
 * value - {<multiple>} the tab to find.
 */
getTab: function(value)  {
  var foundTabs = [], type = Jx.type(value);

  if(type == 'number' && $defined(this.tabs[value])) {
    return this.tabs[value];
  }else if(type == 'string') {
    this.tabs.each(function(tab) {
      if(tab.options.label == value){
        foundTabs.push(tab);
      }
    });
  }else if(type == 'object') {
    this.tabs.each(function(tab) {
      // comparing both objects regular did not work for some reason...
      if(JSON.encode(tab.options.label) == JSON.encode(value)){
        foundTabs.push(tab);
      }
    });
  }
  return foundTabs.length == 0 ? false : foundTabs;
}

Original comment by conrad.b...@gmail.com on 16 Apr 2010 at 12:19

GoogleCodeExporter commented 8 years ago
Hi,

Here is more explication on it.

We have a grid with a column name, and when we click on a row for editing, we 
create
on the fly a new tab with this name. So our need was a function to find the tab 
by
name, but like conrad said, find by id sounds better.

Original comment by hugues.gauthier@gmail.com on 16 Apr 2010 at 1:59

GoogleCodeExporter commented 8 years ago
Personally, I would set a reference to the tab on the row when the row is 
selected, if the reference doesn't exist 
then you need to make a tab and set the reference.  Or create a tab with an id 
(pass id: 'tabForRow'+rowId 
perhaps) and then use $jx('tabForRow'+rowId) to get a reference to the Jx.Tab 
instance?

Finding a tab by label is just not reliable enough for my taste, and I'm not 
really in favour of bloating the API with 
code that encourages unreliable programming.

Original comment by pagameba on 16 Apr 2010 at 2:06

GoogleCodeExporter commented 8 years ago
referencing the tab is a good idea.. I think I would do the same if I had the 
idea ;)
Maybe a shorter method that only returns a tab by index and does not look after 
the
(localized) label is useful -> to at least get this reference? (I like using
getter/setter methods than working with instance variables)

Original comment by conrad.b...@gmail.com on 17 Apr 2010 at 12:53

GoogleCodeExporter commented 8 years ago
Hugues,

is my suggestion to use tabs with ids or storing a reference to the tab on the 
row acceptable?  I really think this 
can be accomplished using the existing API.  Please close or describe why this 
won't work for you.

Original comment by pagameba on 23 Apr 2010 at 12:21

GoogleCodeExporter commented 8 years ago
I think storing a reference to the tab on the row is perfect. Like conrad I 
think I
would do the same if I had the idea ;)

Can you explain the step to do that. Show me the way !! :)

Original comment by hugues.gauthier@gmail.com on 23 Apr 2010 at 1:01

GoogleCodeExporter commented 8 years ago
I did like you said in your comment #4, and it works well.

You can close this enhancement.

Original comment by hugues.gauthier@gmail.com on 30 Apr 2010 at 3:16

GoogleCodeExporter commented 8 years ago

Original comment by pagameba on 30 Apr 2010 at 3:29