partkeepr

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

DatabaseParametersCard.js (3662B)


      1 /**
      2  * This card displays the database parameters.
      3  *
      4  * This card supports multiple database types along with their special parameters.
      5  */
      6 Ext.define('PartKeeprSetup.DatabaseParametersCard', {
      7     extend: 'Ext.form.Panel',
      8 
      9     /**
     10      * Various Style Settings
     11      */
     12     margin: 20,
     13     border: false,
     14     bodyStyle: 'background: none;',
     15     autoScroll: true,
     16     breadCrumbTitle: 'Database Parameters',
     17 
     18     /**
     19      * Inits the component
     20      */
     21     initComponent: function ()
     22     {
     23 
     24         this.createDatabaseDropdown();
     25 
     26         this.databaseSettings = Ext.create("Ext.panel.Panel", {
     27             layout: 'card',
     28             border: false,
     29             bodyStyle: {
     30                 background: "none"
     31             },
     32             items: [
     33                 {
     34                     border: false,
     35                     bodyStyle: {
     36                         background: "none"
     37                     },
     38                     html: 'Please select a database driver'
     39                 },
     40                 Ext.create("PartKeeprSetup.DatabaseParametersCard.MySQL"),
     41                 Ext.create("PartKeeprSetup.DatabaseParametersCard.PostgreSQL")
     42             ]
     43         });
     44 
     45         this.items = [
     46             {
     47                 border: false,
     48                 bodyStyle: 'background:none;padding-bottom: 10px;',
     49                 html: 'Please enter your database parameters below:'
     50             },
     51             this.databaseDropdown,
     52             this.databaseSettings
     53         ];
     54 
     55         this.callParent();
     56         this.on("activate", this.onActivate, this);
     57     },
     58     /**
     59      * Creates the dropdown with all available database types.
     60      */
     61     createDatabaseDropdown: function ()
     62     {
     63         var databaseTypes = Ext.create('Ext.data.Store', {
     64             fields: ['type', 'name'],
     65             data: [
     66                 {"type": "pdo_mysql", "name": "MySQL"},
     67                 {"type": "pdo_pgsql", "name": "PostgreSQL"}
     68             ]
     69         });
     70 
     71         this.databaseDropdown = Ext.create('Ext.form.ComboBox', {
     72             labelWidth: 120,
     73             fieldLabel: 'Database Type',
     74             store: databaseTypes,
     75             queryMode: 'local',
     76             displayField: 'name',
     77             valueField: 'type',
     78             triggerAction: 'all',
     79             editable: false,
     80             value: PartKeeprSetup.getApplication().getSetupConfig().values.database_driver
     81         });
     82 
     83         this.databaseDropdown.on("change", this.onDriverSelect, this);
     84     },
     85     /**
     86      * This method is a callback from the database dropdown and displays
     87      * the correct database settings page.
     88      */
     89     onDriverSelect: function (a, value)
     90     {
     91         Ext.ComponentQuery.query('#nextBtn')[0].disable();
     92 
     93         switch (value) {
     94             case "pdo_mysql":
     95                 this.databaseSettings.layout.setActiveItem(1);
     96                 break;
     97             case "pdo_pgsql":
     98                 this.databaseSettings.layout.setActiveItem(2);
     99                 break;
    100             default:
    101                 this.databaseSettings.layout.setActiveItem(0);
    102                 break;
    103         }
    104     },
    105     /**
    106      * Gets called when the card is activated
    107      */
    108     onActivate: function ()
    109     {
    110         this.databaseDropdown.setValue(PartKeeprSetup.getApplication().getSetupConfig().values.database_driver);
    111         this.onDriverSelect(null, this.databaseDropdown.getValue());
    112 
    113         // Disable the "next" button, this needs to get enabled by the database cards
    114         Ext.ComponentQuery.query('#nextBtn')[0].disable();
    115 
    116         // Manually fire the activate event, in case the user switched cards back/forth.
    117         this.databaseSettings.layout.getActiveItem().fireEvent("activate");
    118     }
    119 });