PDA

View Full Version : Mapping array contents to default controller



wasima
12 Nov 2012, 1:52 AM
hi all,
i have a method here i do mapping of a tab name to a specific controller, for some tabs i have mapped corresponding controller , i want something like " for all the other tabs map 'Summary.DynamicTabController' as the default controller " .
something like : this.controllerNameMap['all_other_tabs'] = Summary.DynamicTabController';


createControllerMap: function() {
this.controllerNameMap = new Array();
this.controllerNameMap['Summary'] = 'Summary.SummaryController';
this.controllerNameMap['Equipment'] = 'Equipment.EquipmentController';
this.controllerNameMap['Traffic'] = 'Traffic.TrafficController';
this.controllerNameMap['Client'] = 'Client.ClientController';
this.controllerNameMap['RF'] = 'RF.RFController';
this.controllerNameMap['NewTab1'] = 'Summary.DynamicTabController';

},


Pls help me .Thanks in advance

mitchellsimoens
13 Nov 2012, 5:44 PM
So why don't you just have a default mapping? I'm sorry, not really understanding what you are doing or why you can't have a default?

wasima
13 Nov 2012, 9:33 PM
Hi, Mitchell Simoens,
Let me try explaining the problem.

What i mean is i have 5 tabs(Summary,Equipment,Traffic,Client,RF) in my tab panel which are static , now i have an add button in tab panel on clicking which new tabs get added dynamically like NewTab1,NewTab2 etc, to these newly added tabs i need to specify which controller they are mapped to , for all the dynamically added tabs the controller is same 'Summary.DynamicTabController' for all the other 5 static tabs i have specified their controller names manually in this function, so i need to tell this function that if you don't get tab names from one of these 5 static tab names you map the tab name to the default controller that is 'Summary.DynamicTabController'.

Hope you understood the issue now.

evant
13 Nov 2012, 10:09 PM
You can just check if the name exists:



var map = {
summary: 'foo',
equipment: 'bar'
};

var a = 'summary';
var b = 'notthere';
if (map[a]) {
console.log(map[a]);
}

if (!map[b]) {
//default;
}

wasima
13 Nov 2012, 11:26 PM
Thanks evant,
but newly added tabs have different names like NewTab1,NewTab2 etc.that are generated dynamically .. I cant fix it to just 'nothere' and do mapping .


createControllerMap: function() {
this.controllerNameMap = new Array();
var map = {
Summary: 'Summary.SummaryController',
Equipment: 'Equipment.EquipmentController',
Traffic : 'Traffic.TrafficController',
Client : 'Client.ClientController',
RF : 'RF.RFController'
};
var a = 'Summary';
var b = 'notthere';
if (map[a]) {
console.log(map[a]);
this.controllerNameMap['Summary'] = 'Summary.SummaryController';
this.controllerNameMap['Equipment'] = 'Equipment.EquipmentController';
this.controllerNameMap['Traffic'] = 'Traffic.TrafficController';
this.controllerNameMap['Client'] = 'Client.ClientController';
this.controllerNameMap['RF'] = 'RF.RFController';
}
else {
this.controllernamemap['nothere'] = 'summary.DynamicTabController'; // cant do this 'nothere' can be NewTab1,NewTab2 etc
}

tvanzoelen
14 Nov 2012, 12:25 AM
I do not see what you want. What is createControllerMap? When is it called?

But...when registering dynamically new items the most common way is. First register your static stuff in a register

like you did initial,


createControllerMap: function() {
this.controllerNameMap = new Array();
this.controllerNameMap['Summary'] = 'Summary.SummaryController';
this.controllerNameMap['Equipment'] = 'Equipment.EquipmentController';
this.controllerNameMap['Traffic'] = 'Traffic.TrafficController';
this.controllerNameMap['Client'] = 'Client.ClientController';
this.controllerNameMap['RF'] = 'RF.RFController';

},


do you have new items like a tab. Then on render or creation register the controller


tab.on('render', function(c){
registerNewTab(c);
});



registerNewTab: function(tab) {
this.controllerNameMap[tab.itemId] = 'Summary.DynamicTabController';
},

evant
14 Nov 2012, 12:55 AM
That's the point. You declare a map of existing names/controllers.

If it doesn't exist in the map, then you know to use the default controller.