AdminUserCard.js (6257B)
1 /** 2 * This card displays the admin user parameters 3 */ 4 Ext.define('PartKeeprSetup.AdminUserCard', { 5 extend: 'Ext.form.Panel', 6 7 /** 8 * Various Style Settings 9 */ 10 margin: 20, 11 border: false, 12 bodyStyle: 'background: none;', 13 14 autoScroll: true, 15 breadCrumbTitle: 'User Data', 16 layout: { 17 type: 'vbox', 18 pack: 'start', 19 align: 'stretch' 20 }, 21 defaults: { 22 labelWidth: 150 23 }, 24 25 /** 26 * Inits the component 27 */ 28 initComponent: function () 29 { 30 this.username = Ext.create("Ext.form.field.Text", { 31 fieldLabel: 'Username', 32 labelWidth: this.defaults.labelWidth, 33 allowBlank: false, 34 regex: /^[a-zA-Za0-9.\-_\/\\]{3,50}$/, 35 regexText: "The username must be 3-50 characters in length and may only contain the following characters: a-z, A-Z, 0-9, an underscore (_), a backslash (\), a slash (/), a dot (.) or a dash (-)", 36 value: PartKeeprSetup.getApplication().getSetupConfig().adminuser.username 37 }); 38 39 this.username.on("change", this.onUpdateParameters, this); 40 41 this.password = Ext.create("Ext.form.field.Text", { 42 fieldLabel: 'Password', 43 inputType: "password", 44 allowBlank: false, 45 labelWidth: this.defaults.labelWidth, 46 value: PartKeeprSetup.getApplication().getSetupConfig().adminuser.password 47 48 }); 49 50 this.password.on("change", this.onUpdateParameters, this); 51 52 this.email = Ext.create("Ext.form.field.Text", { 53 fieldLabel: 'E-Mail', 54 labelWidth: this.defaults.labelWidth, 55 vtype: 'email', 56 allowBlank: false, 57 value: PartKeeprSetup.getApplication().getSetupConfig().adminuser.email 58 59 }); 60 61 this.email.on("change", this.onUpdateParameters, this); 62 63 this.createNewUserRadioGroup = Ext.create("Ext.form.RadioGroup", { 64 columns: 1, 65 items: [ 66 { 67 boxLabel: 'Leave existing users untouched', name: 'create', inputValue: false, columnWidth: .4 68 }, 69 { 70 boxLabel: 'Create new user', name: 'create', inputValue: true 71 } 72 ] 73 }); 74 75 this.createNewUserRadioGroup.on("change", this.onUserModeChanged, this); 76 77 this.authenticationMethodRadioGroup = Ext.create("Ext.form.RadioGroup", { 78 labelAlign: 'top', 79 height: 75, 80 fieldLabel: 'Authentication Method', 81 columns: 1, 82 items: [ 83 { 84 boxLabel: 'HTTP Basic', name: 'authentication_provider', inputValue: 'PartKeepr.Auth.HTTPBasicAuthenticationProvider' 85 }, 86 { 87 boxLabel: 'WSSE', name: 'authentication_provider', inputValue: 'PartKeepr.Auth.WSSEAuthenticationProvider' 88 } 89 ] 90 }); 91 92 this.authenticationMethodRadioGroup.on("change", this.onAuthenticationMethodChanged, this); 93 94 this.userInputForm = Ext.create("Ext.Panel", { 95 bodyStyle: 'background:none;padding-bottom: 10px;', 96 border: false, 97 items: [ 98 { 99 border: false, 100 bodyStyle: 'background:none;padding-bottom: 10px;', 101 html: 'Please enter the user which will become the administrator:' 102 }, 103 this.username, 104 this.password, 105 this.email 106 ], 107 flex: 1 108 }); 109 this.items = [ 110 this.createNewUserRadioGroup, 111 this.userInputForm, 112 this.authenticationMethodRadioGroup, 113 { 114 xtype: 'fieldcontainer', 115 hideEmptyLabel: true, 116 height: 20, 117 border: false, 118 bodyStyle: 'background: none;', 119 html: '<a href="https://wiki.partkeepr.org/wiki/KB00006:Authentication_Provider" target="_blank">Help me decide</a>' 120 } 121 ]; 122 123 this.callParent(); 124 this.on("activate", this.onActivate, this); 125 }, 126 onAuthenticationMethodChanged: function () { 127 var values = this.authenticationMethodRadioGroup.getValue(); 128 PartKeeprSetup.getApplication().getSetupConfig().values.authentication_provider = values.authentication_provider; 129 }, 130 onUserModeChanged: function () 131 { 132 var values = this.createNewUserRadioGroup.getValue(); 133 134 if (values.create === true) { 135 Ext.ComponentQuery.query('#nextBtn')[0].disable(); 136 this.userInputForm.show(); 137 } else { 138 Ext.ComponentQuery.query('#nextBtn')[0].enable(); 139 this.userInputForm.hide(); 140 } 141 142 PartKeeprSetup.getApplication().getSetupConfig().createUser = values.create; 143 }, 144 /** 145 * Gets called when the card is activated 146 */ 147 onActivate: function () 148 { 149 if (PartKeeprSetup.getApplication().getSetupConfig().createUser === false) { 150 this.createNewUserRadioGroup.setValue({ create: false}); 151 } else { 152 this.createNewUserRadioGroup.setValue({ create: true}); 153 } 154 155 this.authenticationMethodRadioGroup.setValue({ authentication_provider: PartKeeprSetup.getApplication().getSetupConfig().values.authentication_provider}); 156 157 if (PartKeeprSetup.getApplication().getSetupConfig().existingUsers === 0) { 158 this.createNewUserRadioGroup.hide(); 159 Ext.ComponentQuery.query('#nextBtn')[0].disable(); 160 } 161 }, 162 onUpdateParameters: function () 163 { 164 if (this.username.isValid() && this.password.isValid() && this.email.isValid()) { 165 var config = PartKeeprSetup.getApplication().getSetupConfig(); 166 167 Ext.apply(config, { 168 adminuser: { 169 username: this.username.getValue(), 170 password: this.password.getValue(), 171 email: this.email.getValue() 172 } 173 }); 174 175 Ext.ComponentQuery.query('#nextBtn')[0].enable(); 176 } else { 177 Ext.ComponentQuery.query('#nextBtn')[0].disable(); 178 } 179 180 } 181 });