UNPKG

extjs-gpl

Version:

GPL licensed version of Sencha Ext JS

149 lines (121 loc) 4.62 kB
Ext.define('Admin.view.main.MainController', { extend: 'Ext.app.ViewController', alias: 'controller.main', listen : { controller : { '#' : { unmatchedroute : 'onRouteChange' } } }, routes: { ':node': 'onRouteChange' }, config: { showNavigation: true }, collapsedCls: 'main-nav-collapsed', init: function (view) { var me = this, refs = me.getReferences(); me.callParent([ view ]); me.nav = refs.navigation; me.navigationTree = refs.navigationTree; }, onNavigationItemClick: function () { // The phone profile's controller uses this event to slide out the navigation // tree. We don't need to do anything but must be present since we always have // the listener on the view... }, onNavigationTreeSelectionChange: function (tree, node) { var to = node && (node.get('routeId') || node.get('viewType')); if (to) { this.redirectTo(to); } }, onRouteChange: function (id) { this.setCurrentView(id); }, onSwitchToClassic: function () { Ext.Msg.confirm('Switch to Classic', 'Are you sure you want to switch toolkits?', this.onSwitchToClassicConfirmed, this); }, onSwitchToClassicConfirmed: function (choice) { if (choice === 'yes') { var s = location.search; // Strip "?modern" or "&modern" with optionally more "&foo" tokens following // and ensure we don't start with "?". s = s.replace(/(^\?|&)modern($|&)/, '').replace(/^\?/, ''); // Add "?classic&" before the remaining tokens and strip & if there are none. location.search = ('?classic&' + s).replace(/&$/, ''); } }, onToggleNavigationSize: function () { this.setShowNavigation(!this.getShowNavigation()); }, setCurrentView: function (hashTag) { hashTag = (hashTag || '').toLowerCase(); var me = this, refs = me.getReferences(), mainCard = refs.mainCard, navigationTree = me.navigationTree, store = navigationTree.getStore(), node = store.findNode('routeId', hashTag) || store.findNode('viewType', hashTag), item = mainCard.child('component[routeId=' + hashTag + ']'); if (!item) { item = mainCard.add({ xtype: node.get('viewType'), routeId: hashTag }); } mainCard.setActiveItem(item); navigationTree.setSelection(node); //if (newView.isFocusable(true)) { // newView.focus(); //} }, updateShowNavigation: function (showNavigation, oldValue) { // Ignore the first update since our initial state is managed specially. This // logic depends on view state that must be fully setup before we can toggle // things. // if (oldValue !== undefined) { var me = this, cls = me.collapsedCls, refs = me.getReferences(), logo = refs.logo, navigation = me.nav, navigationTree = refs.navigationTree, rootEl = navigationTree.rootItem.el; navigation.toggleCls(cls); logo.toggleCls(cls); if (showNavigation) { // Restore the text and other decorations before we expand so that they // will be revealed properly. The forced width is still in force from // the collapse so the items won't wrap. navigationTree.setMicro(false); } else { // Ensure the right-side decorations (they get munged by the animation) // get clipped by propping up the width of the tree's root item while we // are collapsed. rootEl.setWidth(rootEl.getWidth()); } logo.element.on({ transitionend: function () { if (showNavigation) { // after expanding, we should remove the forced width rootEl.setWidth(''); } else { navigationTree.setMicro(true); } }, single: true }); } }, toolbarButtonClick: function(btn){ var href = btn.config.href; this.redirectTo(href); } });