Skip to content

Instantly share code, notes, and snippets.

@ttdonovan
Created October 2, 2008 21:35
Show Gist options
  • Save ttdonovan/14450 to your computer and use it in GitHub Desktop.
Save ttdonovan/14450 to your computer and use it in GitHub Desktop.
// ==========================================================================
// myApp.MainMenuController
// ==========================================================================
require('core');
/** @class
(Document Your View Here)
@extends SC.Object
@author AuthorName
@version 0.1
@static
*/
myApp.mainMenuController = SC.ObjectController.create(
/** @scope myApp.mainMenuController */ {
isContentForUI: null,
isContentForUIObserver: function () {
if (this.isContentForUI) {
this._buildMenuUI();
}
}.observes('isContentForUI'),
_buildMenuUI: function () {
var menuButtons = this.content.get('elements'),
mainMenuView = SC.page.desktopView.header.mainMenu,
params = null;
for (var i = 0; i < menuButtons.length; i += 1 ) {
// popup menu and menu items
var menulist = menuButtons[i].children || [];
var popupmenu = SC.PopupMenuView.create();
popupmenu.setAttribute('id', 'popup_menu_' + i);
for (var j = 0; j < menulist.length; j += 1) {
params = { target: 'myApp.mainMenuController', action: 'execute' };
var menuitem = SC.MenuItemView.create(params);
menuitem.set('title', menulist[j].label); // bug? - SC.ButtonView title is a computed property
popupmenu.appendChild(menuitem); // now where do i place popmenu ?
};
// menu buttons
params = { menu: popupmenu.getAttribute('id') };
var menuButton = SC.ButtonView.create(params);
menuButton.set('title', menuButtons[i].label); // bug? - SC.ButtonView title is a computed property
mainMenuView.appendChild(menuButton);
};
},
execute: function (menuItem) {
console.log('ive been executed, says', menuItem);
}
}) ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment