Thursday, 17 January 2013

Coding Physical Model (Part -2 )



Now let’s take a look in to the code( that posted in lastpost) one by one.  
I have given three color for code. Red indicated that it is mandatory. Black indicates comment and green indicates custom code.


Physical Model
/*---------------------------Coding starts------------------------*/
if( typeof( SiebelAppFacade.ValidatePM ) === "undefined" ){
 /* No Need to worry about this line. This line make sure that the same definition is not yet defined. */
                SiebelJS.Namespace( "SiebelAppFacade.ValidatePM" );
/* SiebelJS.Namespace( "SiebelAppFacade.ValidatePM" ); This will create new name space called ValidatePM. */
                SiebelApp.S_App.RegisterConstructorAgainstKey("ValidatePModel","SiebelAppFacade.ValidatePM" );
/*Above code will register our constructor It s format is
RegisterConstructorAgainstKey (key, constructor)”. This is very important because we need this key to map our customized file in many places.
*/
                SiebelAppFacade.ValidatePM = ( function(){
                /*we just started to define our class. Its name is ValidatePM */
                                function ValidatePM( proxy ){
                                                SiebelAppFacade.ValidatePM.superclass.constructor.call( this, proxy);
                                }
                /*Calling super class*/
                                SiebelJS.Extend( ValidatePM, SiebelAppFacade.PresentationModel );
                /* Above line add  our class to frame work, now our class can access many prebuilt functions. */               
                                ValidatePM.prototype.Init = function(){
                                                /*Init method will initialize, we can initialize properties, methods etc.. */
                                                SiebelAppFacade.ValidatePM.superclass.Init.call( this );
                                                this.AddProperty( "isEmailSet", "" );       
                                                this.AddMethod( "FieldChange",  OnFieldChange, { sequence : false, scope: this } );
                                };
                                
                                function OnFieldChange( control, value ){
                                                if( control.GetName() === "EmailAddress" ){
                                                                this.SetProperty( "isEmailSet", ( value ? true: false ) );
                                                }
                                }
                                return ValidatePM;
                }());

}

/*-------------------------------Coding Ends--------------------------------------*/

 
Now lets take a look in to Init function.


ValidatePM.prototype.Init = function(){
                        SiebelAppFacade.ValidatePM.superclass.Init.call( this );
                         this.AddProperty( "isEmailSet", "" );                                                             this.AddMethod( "FieldChange",  OnFieldChange, { sequence : false, scope: this } );
                                };
Here  this.AddProperty( "isEmailSet", "" );       created a property called  isEmailSet” and initialized this value as null. Now I initialized a method this.AddMethod( "FieldChange",  OnFieldChange, { sequence : false, scope: this } );     read more


Now lets discuss our custom method
function OnFieldChange( control, value ){
                    if( control.GetName() === "EmailAddress" ){
                               this.SetProperty( "isEmailSet", ( value ? true: false ) );
                         }
 }

Every field change will trigger this method. And this will check for changed  control name. In our case, we are listening to changes in email field. So if email address has any  change, then we will set isEmailset to true.
This change will trigger our PhysicalRender file. Because in physical render file we will listen this property (That we will discuss later).  So any change in this property (isEmailSet) will trigger our custom methods in physical render file.


3 comments :

  1. Hi..i want to validate a form applet containing a few fields in open ui..i created a custom JS..in order to modify PM..but how to proceed further??

    ReplyDelete
  2. Hi,
    thanks for post
    please check "read more" link, it's not valid

    ReplyDelete