Client actions

Most Dynamix UI controls can respond to client events. Buttons can be clicked, drop downs or text inputs can have their values changed, and so on. You can connect actions from server side code to respond to these actions:

var firstName = new StringTextEditor { };
new FormField( firstName ) { Label = { Text = "First name" } }.AppendTo( myForm );

var lastName = new StringTextEditor { };
new FormField( lastName ) { Label = { Text = "Last name" } }.AppendTo( myForm );

var fullName = new Label { };
new FormField( fullName ) { Label = { Text = "Full name" } }.AppendTo( myForm );

var refreshFullName = fullName.Client.SetText(
    firstName.Client.GetValue() + " " + lastName.Client.GetValue()
);

firstName.Client.OnChange.AddListener( refreshFullName );
lastName.Client.OnChange.AddListener( refreshFullName );

Client actions can also call server side code, using Ui operations or server methods:

var refreshFullName =
    CallUiOperation<string>( UiOperationToUpper,
        firstName.Client.GetValue() + " " + lastName.Client.GetValue() )
        .Then( u => fullName.Client.SetText( u ) );

[UiOperation()]
private ServerMethodResult UiOperationToUpper( string val )
{
    return ServerMethodResult.Success( val.ToUpper() );
}

Note that server calls are asynchronous, so you need to use Then to chain the operations.

What can be used as a client action?

Dynamix can convert the following types to ClientAction automatically:

  • string

  • decimal

  • int

  • bool

  • System.Type

  • Dynamix.Object

  • Dynamix.Object[]

  • Dynamix.ObjectType

  • Dynamix.Ui6.Controls.ClientControl - will be interpreted as a variable reference to the control

Combining actions

You can combine and chain client actions

Operators: +, -, *, /, <, >, <=, >=

Logical operators: |, & (Note! Not || or &&), myAction.Or( myAction2 )

Arrays: myAction[ 0 ], myAction[ "property" ], myAction.Count(), myAction.Any()

Async:

  • myAction.Then( x => myAction2( x ) )

  • myAction.Done( myAction2 )

  • myAction.Fail( myAction2 )

  • myAction.Always( myAction2 )

Call: myAction.call( "myMethod", ... )

ClientUtil

The ClientUtil class defines client actions for some common situations:

Object management

// Shows edit dialog, then saves the object
ClientUtil.EditAndSaveObject( myObject );

// Shows edit dialog, then returns the edited object
ClientUtil.EditObject( myObject );

// Shows edit dialog for a new object, then saves it
ClientUtil.CreateObject( typeof( MyNewsItem ) );

// Deletes objects
ClientUtil.DeleteObjects( new Array( myObj1, myObj2 ) );

// Checks if the objects are deletable and optionally asks
// the user to confirm the deletion.
// Use .Then to chain actual object delete or other actions
ClientUtil.CheckDeleteObjects( new Array( myObj1, myObj2 ), true );

Interfacing with the content area

// Loads a new page in the Dynamix interface
ClientUtil.LoadContent( navigationItem );
ClientUtil.LoadContent( myUrl );

// Reloads the current page
ClientUtil.ReloadContent();

// Get information about the currently loaded content
ClientUtil.GetCurrentNavigationItem();
ClientUtil.GetCurrentSite();
ClientUtil.GetCurrentUiContext();

Interfacing with controls and UI

// Display a message
ClientUtil.Alert( "My message" );

// Ask the user to confirm
ClientUtil.Confirm( "My message" );

// Check if something is "selected" in any of the supplied controls 
ClientUtil.HasSelected( myList1, myList2 );

// Check if something is "selected" and that the same
// control also has the primary focus
ClientUtil.HasPrimarySelected( myList1, myList2 );

// Get the items that are selected in the control that has the primary focus
ClientUtil.GetPrimarySelected( myList1, myList2 );

// Get the control that has the primary focus
ClientUtil.GetPrimary( myList1, myList2 );

// Refresh all the supplied controls
ClientUtil.Refresh( myList1, myList2 );

// Make all the supplied controls visible
ClientUtil.Show( myList1, myList2 );

// Make all the supplied controls invisible
ClientUtil.Hide( myList1, myList2 );

Last updated 2016-01-15