partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

MenuBar.js (4915B)


      1 Ext.define('PartKeepr.MenuBar', {
      2     extend: 'Ext.toolbar.Toolbar',
      3     alias: "widget.MenuBar",
      4 
      5     baseCls: Ext.baseCSSPrefix + 'toolbar mainMenu',
      6 
      7     menu: {
      8         text: "Root",
      9         menu: []
     10     },
     11 
     12     createMenu: function (target, menuPath, root) {
     13         var item = menuPath.shift(), newItem;
     14 
     15         if (item === undefined) {
     16             newItem = {text: target.title, iconCls: target.iconCls, target: target};
     17 
     18             root.menu.push(newItem);
     19             return root;
     20         }
     21 
     22         var foundItem = false;
     23 
     24         for (var i = 0; i < root.menu.length; i++) {
     25             if (root.menu[i].text === item.text) {
     26                 Ext.applyIf(root.menu[i], item);
     27                 foundItem = i;
     28             }
     29         }
     30 
     31         if (foundItem === false) {
     32             newItem = {menu: []};
     33 
     34             Ext.applyIf(newItem, item);
     35 
     36             var data = this.createMenu(target, menuPath, newItem);
     37             root.menu.push(data);
     38         } else {
     39             this.createMenu(target, menuPath, root.menu[foundItem]);
     40 
     41         }
     42 
     43         return root;
     44     },
     45     initComponent: function () {
     46         var target, menuItemIterator;
     47 
     48         this.ui = "mainmenu";
     49 
     50         var menuItems = [
     51             // System Menu
     52             "PartKeepr.Components.UserPreferences.Panel",
     53             "PartKeepr.Components.SystemPreferences.Panel",
     54             "PartKeepr.Actions.LogoutAction",
     55 
     56             // Edit Menu
     57             "PartKeepr.ProjectEditorComponent",
     58             "PartKeepr.FootprintEditorComponent",
     59             "PartKeepr.ManufacturerEditorComponent",
     60             "PartKeepr.StorageLocationEditorComponent",
     61             "PartKeepr.DistributorEditorComponent",
     62             "PartKeepr.UserEditorComponent",
     63             "PartKeepr.PartMeasurementUnitEditorComponent",
     64             "PartKeepr.UnitEditorComponent",
     65             "PartKeepr.BatchJobEditorComponent",
     66 
     67             // View Menu
     68             "PartKeepr.SummaryStatisticsPanel",
     69             "PartKeepr.StatisticsChartPanel",
     70             "PartKeepr.SystemInformationGrid",
     71             "PartKeepr.ProjectReportView",
     72             'PartKeepr.ProjectRunEditorComponent',
     73             "PartKeepr.SystemNoticeEditorComponent",
     74             "PartKeepr.StockHistoryGrid",
     75             "PartKeepr.ThemeTester"
     76         ];
     77 
     78         this.menu.menu.push({xtype: 'tbspacer'});
     79 
     80         for (menuItemIterator = 0; menuItemIterator < menuItems.length; menuItemIterator++) {
     81             target = Ext.ClassManager.get(menuItems[menuItemIterator]);
     82 
     83             if (!target) {
     84                 Ext.raise("Error: " + menuItems[menuItemIterator] + " not found!");
     85             }
     86 
     87             if (!target.menuPath) {
     88                 Ext.raise("Error: " + menuItems[menuItemIterator] + " has no menuPath defined!");
     89             }
     90             this.createMenu(target, target.menuPath, this.menu);
     91         }
     92 
     93         this.themesMenu = [];
     94         var checked;
     95 
     96         this.themesMenu.push({
     97             text: "Warning: Theme support is a beta-feature!",
     98             disabled: true
     99         });
    100 
    101         for (var i in window.themes) {
    102             checked = window.theme === i;
    103             this.themesMenu.push({
    104                 text: window.themes[i].themeName,
    105                 theme: i,
    106                 group: 'theme',
    107                 checked: checked
    108             });
    109         }
    110 
    111 
    112         this.menu.menu.push({text: i18n("Theme"), type: 'themes', menu: this.themesMenu});
    113         this.menu.menu.push({xtype: 'tbspacer', width: 50});
    114 
    115         this.menu.menu.push({
    116             xtype: 'button',
    117             text: i18n("Patreon Status"),
    118             iconCls: 'patreonLogo',
    119             handler: this.showPatreonStatusDialog,
    120             scope: this
    121         });
    122         if (Ext.isObject(window.parameters.patreonStatus)) {
    123             this.menu.menu.push({
    124                 xtype: 'progressbar',
    125                 value: (window.parameters.patreonStatus.pledgeSum / window.parameters.patreonStatus.goal),
    126                 width: 50
    127             });
    128         }
    129 
    130         this.menu.menu.push({xtype: 'tbfill'});
    131         this.menu.menu.push({xtype: 'button', iconCls: 'partkeeprLogo'});
    132         this.menu.menu.push({xtype: 'tbspacer', width: 10});
    133 
    134         this.items = this.menu.menu;
    135 
    136         this.callParent();
    137     },
    138     showPatreonStatusDialog: function () {
    139         var window = Ext.create("PartKeepr.Components.PatreonStatusDialog");
    140         window.show();
    141     },
    142     selectTheme: function (theme) {
    143         var i, j, menuItem;
    144 
    145         for (i = 0; i < this.items.getCount(); i++) {
    146             if (this.items.getAt(i).type === "themes") {
    147                 for (j = 0; j < this.items.getAt(i).menu.items.getCount(); j++) {
    148                     menuItem = this.items.getAt(i).menu.items.getAt(j);
    149 
    150                     if (menuItem.theme === theme) {
    151                         menuItem.setChecked(true);
    152                     }
    153                 }
    154 
    155             }
    156         }
    157     }
    158 });