How to override config

Discuss about Group-Office development here

Moderator: Developers

Thomas
Posts: 57
Joined: Fri Jul 24, 2009 1:52 pm

How to override config

Postby Thomas » Wed Sep 09, 2015 12:47 pm

Hi @ all,

i have to customize some Modules in GO. Previously i done it directly in the code. This is obviously the worst way if you want to update your GO.

Actually i write my own module for it and use

Code: Select all

Ext.override()

for JS-Functions. This works so far. Now i have to modify some configs (Fields in it). For example in AccountPanel.js:

Original

Code: Select all

this.usernameField = new Ext.form.TextField({
         fieldLabel: GO.lang['strUsername'],
         name: 'username'
      });


Modification

Code: Select all

this.usernameField = new Ext.form.TextField({
         fieldLabel: GO.lang['strUsername'],
         name: 'username',
         panel: this,
         listeners: {
            blur: function(){
               if (this.panel.usernameField.getValue()) {
                  if (this.panel.usernameField.getValue().lastIndexOf(".")<0) {
                     alert("Der Benutzername muss einen Punkt enthalten (vorname.nachname).");
                  }
                  else {
                     var name=this.panel.usernameField.getValue().split('.');
                     this.panel.firstNameField.setValue(name[0].substr(0, 1).toUpperCase() + name[0].substr(1));
                     this.panel.lastNameField.setValue(name[1].substr(0, 1).toUpperCase() + name[1].substr(1));
                     var mail=name[0].substr(0,1)+'.'+name[1]+'@mydomain.net';
                     this.panel.emailField.setValue(mail);
                  }
               }
            },
         }
      });


How can i modify this without hacking the code directly?


Regards
Thomas
Thomas
Posts: 57
Joined: Fri Jul 24, 2009 1:52 pm

Re: How to override config

Postby Thomas » Thu Sep 10, 2015 10:08 am

Got it finally:

Code: Select all

GO.moduleManager.onModuleReady("users",function(){
            Ext.override(GO.users.AccountPanel, {
               initComponent : GO.users.AccountPanel.prototype.initComponent.createSequence(function(){
                  this.usernameField.panel=this
                  this.usernameField.addListener("blur",function(){
                     if (this.panel.usernameField.getValue()) {
                        if (this.panel.usernameField.getValue().lastIndexOf(".")<0) {
                           alert("Der Benutzername muss einen Punkt enthalten (vorname.nachname).");
                        }
                        else {
                           var name=this.panel.usernameField.getValue().split(".");
                           document.getElementsByName("first_name")[0].value=name[0].substr(0, 1).toUpperCase() + name[0].substr(1);
                           document.getElementsByName("last_name")[0].value=name[1].substr(0, 1).toUpperCase() + name[1].substr(1);
                           var mail=name[0].substr(0,1)+"."+name[1]+"@mydomain.net";
                           document.getElementsByName("email")[0].value=mail;
                        }
                     }
                  })
               })   
            })
         });


Not really nice is to use

Code: Select all

document.getElementsByName()


But it works.
Thomas
Posts: 57
Joined: Fri Jul 24, 2009 1:52 pm

Re: How to override config

Postby Thomas » Fri Sep 11, 2015 10:11 am

Another problem on this:

i have to add a button to the Toolbar of the E-Mail-Client (EmailClient.js). Normally i would use

Code: Select all

Ext.getCmp(id_of_tbar).addButton(myButton);


The Problem here is that the Toolbar in EmailClient.js dont have a ID so i cant access it. Is there another way to add my Button from my own module (using the same technique like decribed above "initComponent")?

To add the ID in EmailClient.js is not a solution. I dont want touch it.
mcharvat
Posts: 59
Joined: Thu Jul 03, 2014 10:36 pm
Contact:

Re: How to override config

Postby mcharvat » Wed Sep 23, 2015 8:58 am

Code: Select all

Ext.getCmp('go-module-panel-email').topToolbar.addButton


go-module-panel-email is unique module name so dont worry to use it

Depend on when you add this button call doLayout() on topToolbar.
Thomas
Posts: 57
Joined: Fri Jul 24, 2009 1:52 pm

Re: How to override config

Postby Thomas » Wed Sep 23, 2015 10:20 am

Hi mcharvat,

great! Thank you. Will try this, but from the first sight its must be working :)

Return to “Development Chats”

Who is online

Users browsing this forum: No registered users and 2 guests

cron