| Methods |
public
|
__construct(array<0|string, mixed>|string $label = [])
|
#
|
public
|
setModel(Model $model): void
Associate this view with a model. Do not place any logic in this class, instead take it
to renderView().
Associate this view with a model. Do not place any logic in this class, instead take it
to renderView().
Do not try to create your own "Model" implementation, instead you must be looking for
your own "Persistence" implementation.
Overriden by
|
#
|
public
|
setSource(array $data, array $fields = null): Model
Sets source of the View.
Parameters
| $fields |
Limit model to particular fields
|
|
#
|
protected
|
setMissingProperty(string $propertyName, $value): void
|
#
|
public
|
setElement(string $element): $this
|
#
|
public
|
link(string|array<0|string, string|int|false> $url, string $target = null): $this
Makes view into a "<a>" element with a link.
|
#
|
protected
|
init(): void
Called when view becomes part of render tree. You can override it but avoid
placing any "heavy processing" here.
Called when view becomes part of render tree. You can override it but avoid
placing any "heavy processing" here.
Overrides
Overriden by
|
#
|
public
|
getExecutorFactory(): ExecutorFactory
|
#
|
public
|
add(AbstractView $object, string|array|null $region = null): AbstractView
In addition to adding a child object, sets up it's template
and associate it's output with the region in our template.
In addition to adding a child object, sets up it's template
and associate it's output with the region in our template.
Overrides
Overriden by
|
#
|
public
|
getClosestOwner<T is View>(class-string<T> $class): T|null
Get closest owner which is instance of particular class.
Get closest owner which is instance of particular class.
|
#
|
public
|
set(string $content): $this
TODO this method is hard to override, drop it from View.
TODO this method is hard to override, drop it from View.
Overriden by
|
#
|
public
|
addClass(string|array<int, string> $class): $this
Add CSS class to element. Previously added classes are not affected.
Multiple CSS classes can also be added if passed…
Add CSS class to element. Previously added classes are not affected.
Multiple CSS classes can also be added if passed as space separated
string or array of class names.
|
#
|
public
|
removeClass(string|array<int, string> $class): $this
Remove one or several CSS classes from the element.
Remove one or several CSS classes from the element.
|
#
|
public
|
setStyle(string|array<string, string> $property, ($property is array ? never : string) $value = null): $this
Add inline CSS style to element.
Multiple CSS styles can also be set if passed as array.
Add inline CSS style to element.
Multiple CSS styles can also be set if passed as array.
|
#
|
public
|
removeStyle(string $property): $this
Remove inline CSS style from element.
Remove inline CSS style from element.
|
#
|
public
|
setAttr(string|int|array<string, string|int> $name, ($name is array ? never : string|int) $value = null): $this
Set attribute.
|
#
|
public
|
removeAttr(string|array<int, string> $name): $this
Remove attribute.
|
#
|
public
|
url(string|array<0|string, string|int|false> $page = []): string
Build an URL which this view can use for callbacks.
Build an URL which this view can use for callbacks.
Parameters
| $page |
URL as string or array with page path as first element and other GET arguments
|
|
#
|
public
|
jsUrl(string|array<0|string, string|int|false> $page = []): string
Build an URL which this view can use for JS callbacks.
Build an URL which this view can use for JS callbacks.
Parameters
| $page |
URL as string or array with page path as first element and other GET arguments
|
|
#
|
protected
|
_getStickyArgs(): array
Get sticky arguments defined by the view and parents (including API).
Get sticky arguments defined by the view and parents (including API).
|
#
|
public
|
stickyGet(string $name, string $newValue = null): ?string
Mark GET argument as sticky. Calling url() on this view or any
sub-views will embed the value of this GET argument.
Mark GET argument as sticky. Calling url() on this view or any
sub-views will embed the value of this GET argument.
If GET argument is empty or false, it won't make into URL.
If GET argument is not presently set you can specify a 2nd argument
to forge-set the GET argument for current view and it's sub-views.
|
#
|
protected
|
renderView(): void
View-specific rendering stuff. Feel free to replace this method with
your own. View::renderView contains some logic…
View-specific rendering stuff. Feel free to replace this method with
your own. View::renderView contains some logic that integrates with
Fomantic-UI.
Overriden by
|
#
|
protected
|
recursiveRender(): void
Recursively render all children, placing their output in our template.
Recursively render all children, placing their output in our template.
Overriden by
|
#
|
public
|
renderAll(): void
Render everything recursively, render ourselves but don't return anything just yet.
Render everything recursively, render ourselves but don't return anything just yet.
|
#
|
protected
|
renderTemplateToHtml(): string
For Form::renderTemplateToHtml() only.
For Form::renderTemplateToHtml() only.
Overriden by
|
#
|
public
|
render(): string
This method is for those cases when developer want to simply render his
view and grab HTML himself.
This method is for those cases when developer want to simply render his
view and grab HTML himself.
Overriden by
|
#
|
public
|
renderToTab(): array
This method is to render view to place inside a Fomantic-UI Tab.
This method is to render view to place inside a Fomantic-UI Tab.
|
#
|
public
|
renderToJsonArr(): array
Render View using JSON format.
Render View using JSON format.
Overriden by
|
#
|
public
|
getHtml(): string
Created for recursive rendering or when you want to only get HTML of
this object (not javascript).
Created for recursive rendering or when you want to only get HTML of
this object (not javascript).
Overriden by
|
#
|
public
|
js(
bool|string $when = false,
($when is false ? null : JsExpressionable|null) $action = null,
string|self|null $selector = null,
): ($action is null ? Jquery : null)
Views in Agile UI can assign javascript actions to themselves. This
is done by calling $view->js() method which returns…
Views in Agile UI can assign javascript actions to themselves. This
is done by calling $view->js() method which returns instance of JsChain
object that is initialized to the object itself. Normally this chain
will map into $('#object_id') and calling additional methods will map
into additional calls.
Action can represent javascript event, such as "click" or "mouseenter".
If you specify action = true, then the event will ALWAYS be executed on
documentReady. It will also be executed if respective view is being reloaded
by js()->reload()
(Do not make mistake by specifying "true" instead of true)
action = false will still return JsChain but will not bind it.
You can bind it by passing object into on() method.
-
Calling with arguments:
$view->js(); // technically does nothing
$a = $view->js()->hide(); // creates chain for hiding $view but does not bind to event yet
-
Binding existing chains
$img->on('mouseenter', $a); // binds previously defined chain to event on event of $img
Produced code: $('#img_id').on('mouseenter', function (event) {
event.preventDefault();
event.stopPropagation();
$('#view1').hide();
});
-
$button->on('click', $form->js()->submit()); // clicking button will result in form submit
-
$view->js(true)->find('.current')->text($text);
Will convert calls to jQuery chain into JavaScript string:
$('#view').find('.current').text('abc'); // the text will be JSON encoded to avoid JS injection
Parameters
| $when |
Event when chain will be executed
|
| $action |
JavaScript action
|
| $selector |
If you wish to override jQuery($selector)
|
|
#
|
public
|
vue(
string $component,
array $initData = [],
JsExpressionable|null $componentDefinition = null,
string|self|null $selector = null,
): $this
Create Vue.js instance.
Vue.js instance can be created from Atk4\Ui\View.
Create Vue.js instance.
Vue.js instance can be created from Atk4\Ui\View.
Component managed and defined by atk does not need componentDefinition variable name
because these are already loaded within the atk js namespace.
When creating your own component externally, you must supply the variable name holding
your Vue component definition. This definition must be also accessible within the window javascript
object. This way, you do not need to load Vue js file since it has already being include within
atkjs-ui.js build.
If the external component use other components, it is possible to register them using
vueService getVue() method. This method return the current Vue object.
ex: atk.vueService.getVue().component('external_component', externalComponent). This is the same
as Vue.component() method.
Parameters
| $component |
The component name
|
| $initData |
The component properties passed as the initData prop.
This is the initial data pass to your main component via the initData bind property
of the vue component instance created via the vueService.
|
| $componentDefinition |
component definition object
|
| $selector |
the selector for creating the base root object in Vue
|
|
#
|
public
|
jsEmitEvent(string $eventName, array $eventData = []): JsChain
Emit an event on atkEvent bus.
Emit an event on atkEvent bus.
example of adding a listener on for an emit event.
atk.eventBus.on('eventName', (data) => {
console.log(data)
});
Note: In order to make sure your event is unique within atk, you can
use the view name in it.
$this->jsEmitEvent($this->name . '-my-event', $data)
|
#
|
public
|
jsGetStoreData(): array
Get Local and Session web storage associated with this view.
Web storage can be retrieved using a $view->jsReload()…
Get Local and Session web storage associated with this view.
Web storage can be retrieved using a $view->jsReload() request.
|
#
|
public
|
jsClearStoreData(bool $useSession = false): JsExpressionable
Clear Web storage data associated with this view.
Clear Web storage data associated with this view.
|
#
|
public
|
jsAddStoreData(array $data, bool $useSession = false): JsExpressionable
Add Web storage for this specific view.
Data will be store as json value where key name
will be the name of this view.
Add Web storage for this specific view.
Data will be store as json value where key name
will be the name of this view.
Data added to web storage is merge against previous value.
$v->jsAddStoreData(['args' => ['path' => '.']]);
$v->jsAddStoreData(['args' => ['path' => '/'], 'fields' => ['name' => 'test']]]);
Final store value will be: ['args' => ['path' => '/'], 'fields' => ['name' => 'test']];
|
#
|
public
|
jsReload(array $args = [], JsExpressionable|null $afterSuccess = null, array $apiConfig = []): JsReload
Returns JS for reloading View.
Returns JS for reloading View.
Overriden by
|
#
|
public
|
on(
string $event,
($action is object ? string : ($action is null ? string : never)|JsExpressionable|JsCallback|JsCallbackSetClosure|array{JsCallbackSetClosure}|ExecutorInterface|UserAction) $selector = null,
($selector is string|null ? JsExpressionable|JsCallback|JsCallbackSetClosure|array{JsCallbackSetClosure}|ExecutorInterface|UserAction : array) $action = null,
array $defaults = [],
): ($selector is string|null ? ($action is null ? Jquery : null) : ($action is array|null ? Jquery : null))
Views in Agile Toolkit can assign javascript actions to themselves. This
is done by calling $view->js() or $view->on().
Views in Agile Toolkit can assign javascript actions to themselves. This
is done by calling $view->js() or $view->on().
on() method is similar to jQuery on(event, [selector, ] action) method.
When no $action is passed, the on() method returns a chain corresponding to the affected element.
Here are some ways to use on():
// clicking on button will make the $view disappear
$button->on('click', $view->js()->hide());
// clicking on will make it's parent disappear
$view->on('click', 'a[data=clickable]')->parent()->hide();
Finally, it's also possible to use PHP closure as an action:
$view->on('click', 'a', function (Jquery $js, $data) {
if (!$data['clickable']) {
return new JsExpression('alert([])', ['This record is not clickable'])
}
return $js->parent()->hide();
});
Parameters
| $event |
JavaScript event
|
| $selector |
Optional jQuery-style selector
|
| $action |
code to execute
|
|
#
|
public
|
getHtmlId(): string
|
#
|
public
|
getJsRenderActions(): string
Return rendered js actions as a string.
Return rendered js actions as a string.
|
#
|
public
|
getJs(): string
Get JavaScript objects from this render tree.
Get JavaScript objects from this render tree.
TODO dedup with getJsRenderActions()
|
#
|