Maslosoft Framework Logo Maslosoft Framework Documentation
Flexible Application Foundation


Widget Activities

Widget activities, are mostly the same as actions, except that URL's use hash scheme, and are meant to be used on actions that do not reach server.

The resulting URL's are similar too: #ms_8.addGroup=below.

Reacting on activity

To make widget react on activity, it need to have dispatcher initialized with third parameter:

class MyWidget

    constructor: (@id) ->
        @dispatcher = new Maslosoft.Widgets.Dispatcher @, @, @

    #
    # Will be called as activity or action URL
    # #ms_8.addGroup=below
    # ?ms_8.addGroup=below
    #
    addGroup: (position, e) =>
        # Do something

If third parameter contains different object, activities will be called on this object, while action will be called on MyWidget instance. Also the second parameter of dispatcher can be different object holding actions. This might be useful for large widgets:

class MyActions
    #
    # Will be called as action only
    # Will react on example on URL: ?ms_8.sort=name:desc
    #
    sort: (directions) =>
        # Do sort

class MyActivities
    #
    # Will be called as activity only
    # Will react on example on URL: #ms_8.addGroup=below
    #
    addGroup: (position, e) =>
        # Do something

class MyWidget

    constructor: (@id) ->
        # Assume @id ms_8
        @actions = new MyActions
        @activities = new MyActivities
        @dispatcher = new Maslosoft.Widgets.Dispatcher @, @actions, @activities

Creating URL's

To create URL, echo ActivityUrl with apropriate parameters, for example to sort with name desc, let's assume widget ID users:

echo new ActivityUrl($widget, 'sort', ['name' => 'dest']);

Will result in URL:

#user.sort=name:desc

Creating link

The class ActivityLink will create whole tag, with rel="virtual" attribute, so that it will call javascript widget activity method.

echo new ActivityLink($widget, 'sort', 'Sort by name', ['name' => 'dest']);

Will result in link:

<a href="?user.sort=name:desc" rel="virtual">Sort by name</a>