repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
atk4/ui | src/FormField/Upload.php | Upload.addJSAction | public function addJSAction($action)
{
if (is_array($action)) {
$this->jsActions = array_merge($action, $this->jsActions);
} else {
$this->jsActions[] = $action;
}
} | php | public function addJSAction($action)
{
if (is_array($action)) {
$this->jsActions = array_merge($action, $this->jsActions);
} else {
$this->jsActions[] = $action;
}
} | [
"public",
"function",
"addJSAction",
"(",
"$",
"action",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"action",
")",
")",
"{",
"$",
"this",
"->",
"jsActions",
"=",
"array_merge",
"(",
"$",
"action",
",",
"$",
"this",
"->",
"jsActions",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"jsActions",
"[",
"]",
"=",
"$",
"action",
";",
"}",
"}"
] | Add a js action to be return to server on callback.
@param $action | [
"Add",
"a",
"js",
"action",
"to",
"be",
"return",
"to",
"server",
"on",
"callback",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/FormField/Upload.php#L154-L161 | train |
atk4/ui | src/FormField/Upload.php | Upload.onDelete | public function onDelete($fx = null)
{
if (is_callable($fx)) {
$this->hasDeleteCb = true;
if ($this->cb->triggered() && @$_POST['action'] === 'delete') {
$fileName = @$_POST['f_name'];
$this->cb->set(function () use ($fx, $fileName) {
$this->addJsAction(call_user_func_array($fx, [$fileName]));
return $this->jsActions;
});
}
}
} | php | public function onDelete($fx = null)
{
if (is_callable($fx)) {
$this->hasDeleteCb = true;
if ($this->cb->triggered() && @$_POST['action'] === 'delete') {
$fileName = @$_POST['f_name'];
$this->cb->set(function () use ($fx, $fileName) {
$this->addJsAction(call_user_func_array($fx, [$fileName]));
return $this->jsActions;
});
}
}
} | [
"public",
"function",
"onDelete",
"(",
"$",
"fx",
"=",
"null",
")",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"fx",
")",
")",
"{",
"$",
"this",
"->",
"hasDeleteCb",
"=",
"true",
";",
"if",
"(",
"$",
"this",
"->",
"cb",
"->",
"triggered",
"(",
")",
"&&",
"@",
"$",
"_POST",
"[",
"'action'",
"]",
"===",
"'delete'",
")",
"{",
"$",
"fileName",
"=",
"@",
"$",
"_POST",
"[",
"'f_name'",
"]",
";",
"$",
"this",
"->",
"cb",
"->",
"set",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"fx",
",",
"$",
"fileName",
")",
"{",
"$",
"this",
"->",
"addJsAction",
"(",
"call_user_func_array",
"(",
"$",
"fx",
",",
"[",
"$",
"fileName",
"]",
")",
")",
";",
"return",
"$",
"this",
"->",
"jsActions",
";",
"}",
")",
";",
"}",
"}",
"}"
] | onDelete callback.
Call when user is removing an already upload file.
@param callable $fx | [
"onDelete",
"callback",
".",
"Call",
"when",
"user",
"is",
"removing",
"an",
"already",
"upload",
"file",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/FormField/Upload.php#L169-L182 | train |
atk4/ui | src/FormField/Upload.php | Upload.onUpload | public function onUpload($fx = null)
{
if (is_callable($fx)) {
$this->hasUploadCb = true;
if ($this->cb->triggered()) {
$action = @$_POST['action'];
if ($files = @$_FILES) {
//set fileId to file name as default.
$this->fileId = $files['file']['name'];
// display file name to user as default.
$this->setInput($this->fileId);
}
if ($action === 'upload' && !$files['file']['error']) {
$this->cb->set(function () use ($fx, $files) {
$this->addJsAction(call_user_func_array($fx, $files));
//$value = $this->field ? $this->field->get() : $this->content;
$this->addJsAction([
$this->js()->atkFileUpload('updateField', [$this->fileId, $this->getInputValue()]),
]);
return $this->jsActions;
});
} elseif ($action === null || isset($files['file']['error'])) {
$this->cb->set(function () use ($fx, $files) {
return call_user_func($fx, 'error');
});
}
}
}
} | php | public function onUpload($fx = null)
{
if (is_callable($fx)) {
$this->hasUploadCb = true;
if ($this->cb->triggered()) {
$action = @$_POST['action'];
if ($files = @$_FILES) {
//set fileId to file name as default.
$this->fileId = $files['file']['name'];
// display file name to user as default.
$this->setInput($this->fileId);
}
if ($action === 'upload' && !$files['file']['error']) {
$this->cb->set(function () use ($fx, $files) {
$this->addJsAction(call_user_func_array($fx, $files));
//$value = $this->field ? $this->field->get() : $this->content;
$this->addJsAction([
$this->js()->atkFileUpload('updateField', [$this->fileId, $this->getInputValue()]),
]);
return $this->jsActions;
});
} elseif ($action === null || isset($files['file']['error'])) {
$this->cb->set(function () use ($fx, $files) {
return call_user_func($fx, 'error');
});
}
}
}
} | [
"public",
"function",
"onUpload",
"(",
"$",
"fx",
"=",
"null",
")",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"fx",
")",
")",
"{",
"$",
"this",
"->",
"hasUploadCb",
"=",
"true",
";",
"if",
"(",
"$",
"this",
"->",
"cb",
"->",
"triggered",
"(",
")",
")",
"{",
"$",
"action",
"=",
"@",
"$",
"_POST",
"[",
"'action'",
"]",
";",
"if",
"(",
"$",
"files",
"=",
"@",
"$",
"_FILES",
")",
"{",
"//set fileId to file name as default.",
"$",
"this",
"->",
"fileId",
"=",
"$",
"files",
"[",
"'file'",
"]",
"[",
"'name'",
"]",
";",
"// display file name to user as default.",
"$",
"this",
"->",
"setInput",
"(",
"$",
"this",
"->",
"fileId",
")",
";",
"}",
"if",
"(",
"$",
"action",
"===",
"'upload'",
"&&",
"!",
"$",
"files",
"[",
"'file'",
"]",
"[",
"'error'",
"]",
")",
"{",
"$",
"this",
"->",
"cb",
"->",
"set",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"fx",
",",
"$",
"files",
")",
"{",
"$",
"this",
"->",
"addJsAction",
"(",
"call_user_func_array",
"(",
"$",
"fx",
",",
"$",
"files",
")",
")",
";",
"//$value = $this->field ? $this->field->get() : $this->content;",
"$",
"this",
"->",
"addJsAction",
"(",
"[",
"$",
"this",
"->",
"js",
"(",
")",
"->",
"atkFileUpload",
"(",
"'updateField'",
",",
"[",
"$",
"this",
"->",
"fileId",
",",
"$",
"this",
"->",
"getInputValue",
"(",
")",
"]",
")",
",",
"]",
")",
";",
"return",
"$",
"this",
"->",
"jsActions",
";",
"}",
")",
";",
"}",
"elseif",
"(",
"$",
"action",
"===",
"null",
"||",
"isset",
"(",
"$",
"files",
"[",
"'file'",
"]",
"[",
"'error'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"cb",
"->",
"set",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"fx",
",",
"$",
"files",
")",
"{",
"return",
"call_user_func",
"(",
"$",
"fx",
",",
"'error'",
")",
";",
"}",
")",
";",
"}",
"}",
"}",
"}"
] | onUpload callback.
Call when user is uploading a file.
@param callable $fx | [
"onUpload",
"callback",
".",
"Call",
"when",
"user",
"is",
"uploading",
"a",
"file",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/FormField/Upload.php#L190-L219 | train |
atk4/ui | src/FormField/Upload.php | Upload.renderView | public function renderView()
{
//need before parent rendering.
if ($this->disabled) {
$this->addClass('disabled');
}
parent::renderView();
if (!$this->hasUploadCb || !$this->hasDeleteCb) {
throw new Exception('onUpload and onDelete callback must be called to use file upload');
}
if (!empty($this->accept)) {
$this->template->trySet('accept', implode(',', $this->accept));
}
if ($this->multiple) {
//$this->template->trySet('multiple', 'multiple');
}
if ($this->placeholder) {
$this->template->trySet('PlaceHolder', $this->placeholder);
}
//$value = $this->field ? $this->field->get() : $this->content;
$this->js(true)->atkFileUpload([
'uri' => $this->cb->getJSURL(),
'action' => $this->action->name,
'file' => ['id' => $this->fileId ?: $this->field->get(), 'name' => $this->getInputValue()],
'hasFocus' => $this->hasFocusEnable,
'submit' => ($this->form->buttonSave) ? $this->form->buttonSave->name : null,
]);
} | php | public function renderView()
{
//need before parent rendering.
if ($this->disabled) {
$this->addClass('disabled');
}
parent::renderView();
if (!$this->hasUploadCb || !$this->hasDeleteCb) {
throw new Exception('onUpload and onDelete callback must be called to use file upload');
}
if (!empty($this->accept)) {
$this->template->trySet('accept', implode(',', $this->accept));
}
if ($this->multiple) {
//$this->template->trySet('multiple', 'multiple');
}
if ($this->placeholder) {
$this->template->trySet('PlaceHolder', $this->placeholder);
}
//$value = $this->field ? $this->field->get() : $this->content;
$this->js(true)->atkFileUpload([
'uri' => $this->cb->getJSURL(),
'action' => $this->action->name,
'file' => ['id' => $this->fileId ?: $this->field->get(), 'name' => $this->getInputValue()],
'hasFocus' => $this->hasFocusEnable,
'submit' => ($this->form->buttonSave) ? $this->form->buttonSave->name : null,
]);
} | [
"public",
"function",
"renderView",
"(",
")",
"{",
"//need before parent rendering.",
"if",
"(",
"$",
"this",
"->",
"disabled",
")",
"{",
"$",
"this",
"->",
"addClass",
"(",
"'disabled'",
")",
";",
"}",
"parent",
"::",
"renderView",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"hasUploadCb",
"||",
"!",
"$",
"this",
"->",
"hasDeleteCb",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'onUpload and onDelete callback must be called to use file upload'",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"accept",
")",
")",
"{",
"$",
"this",
"->",
"template",
"->",
"trySet",
"(",
"'accept'",
",",
"implode",
"(",
"','",
",",
"$",
"this",
"->",
"accept",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"multiple",
")",
"{",
"//$this->template->trySet('multiple', 'multiple');",
"}",
"if",
"(",
"$",
"this",
"->",
"placeholder",
")",
"{",
"$",
"this",
"->",
"template",
"->",
"trySet",
"(",
"'PlaceHolder'",
",",
"$",
"this",
"->",
"placeholder",
")",
";",
"}",
"//$value = $this->field ? $this->field->get() : $this->content;",
"$",
"this",
"->",
"js",
"(",
"true",
")",
"->",
"atkFileUpload",
"(",
"[",
"'uri'",
"=>",
"$",
"this",
"->",
"cb",
"->",
"getJSURL",
"(",
")",
",",
"'action'",
"=>",
"$",
"this",
"->",
"action",
"->",
"name",
",",
"'file'",
"=>",
"[",
"'id'",
"=>",
"$",
"this",
"->",
"fileId",
"?",
":",
"$",
"this",
"->",
"field",
"->",
"get",
"(",
")",
",",
"'name'",
"=>",
"$",
"this",
"->",
"getInputValue",
"(",
")",
"]",
",",
"'hasFocus'",
"=>",
"$",
"this",
"->",
"hasFocusEnable",
",",
"'submit'",
"=>",
"(",
"$",
"this",
"->",
"form",
"->",
"buttonSave",
")",
"?",
"$",
"this",
"->",
"form",
"->",
"buttonSave",
"->",
"name",
":",
"null",
",",
"]",
")",
";",
"}"
] | Rendering view. | [
"Rendering",
"view",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/FormField/Upload.php#L224-L254 | train |
atk4/ui | src/FormField/Lookup.php | Lookup.addFilter | public function addFilter($field, $label = null)
{
if (!$this->model->hasElement($field) instanceof \atk4\data\Field) {
throw new \atk4\ui\Exception([
'Unable to filter by non-existant field',
'field'=> $field,
]);
}
$this->filters[] = ['field' => $field, 'label' => $label];
} | php | public function addFilter($field, $label = null)
{
if (!$this->model->hasElement($field) instanceof \atk4\data\Field) {
throw new \atk4\ui\Exception([
'Unable to filter by non-existant field',
'field'=> $field,
]);
}
$this->filters[] = ['field' => $field, 'label' => $label];
} | [
"public",
"function",
"addFilter",
"(",
"$",
"field",
",",
"$",
"label",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"model",
"->",
"hasElement",
"(",
"$",
"field",
")",
"instanceof",
"\\",
"atk4",
"\\",
"data",
"\\",
"Field",
")",
"{",
"throw",
"new",
"\\",
"atk4",
"\\",
"ui",
"\\",
"Exception",
"(",
"[",
"'Unable to filter by non-existant field'",
",",
"'field'",
"=>",
"$",
"field",
",",
"]",
")",
";",
"}",
"$",
"this",
"->",
"filters",
"[",
"]",
"=",
"[",
"'field'",
"=>",
"$",
"field",
",",
"'label'",
"=>",
"$",
"label",
"]",
";",
"}"
] | Add filter dropdown.
Ex: you need to restreint value available in city dropdown base on user input Country and language
$l = $form->addField('city',['Lookup']);
$l->addFilter('country_test', 'Country');
$l->addFilter('language', 'Lang');
This way, dropdown value will contains city corresponding to proper country and/or language.
@param $field
@param null $label | [
"Add",
"filter",
"dropdown",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/FormField/Lookup.php#L237-L246 | train |
atk4/ui | src/FormField/Lookup.php | Lookup.applyFilters | public function applyFilters()
{
if ($this->filters) {
foreach ($this->filters as $k => $filter) {
if (
isset($_GET[$filter['field']]) &&
!empty($_GET[$filter['field']]) &&
$_GET[$filter['field']] != $this->filterEmpty &&
@$_GET['filter'] != $filter['field']
) {
$this->model->addCondition($filter['field'], $_GET[$filter['field']]);
}
}
}
} | php | public function applyFilters()
{
if ($this->filters) {
foreach ($this->filters as $k => $filter) {
if (
isset($_GET[$filter['field']]) &&
!empty($_GET[$filter['field']]) &&
$_GET[$filter['field']] != $this->filterEmpty &&
@$_GET['filter'] != $filter['field']
) {
$this->model->addCondition($filter['field'], $_GET[$filter['field']]);
}
}
}
} | [
"public",
"function",
"applyFilters",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"filters",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"filters",
"as",
"$",
"k",
"=>",
"$",
"filter",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_GET",
"[",
"$",
"filter",
"[",
"'field'",
"]",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"_GET",
"[",
"$",
"filter",
"[",
"'field'",
"]",
"]",
")",
"&&",
"$",
"_GET",
"[",
"$",
"filter",
"[",
"'field'",
"]",
"]",
"!=",
"$",
"this",
"->",
"filterEmpty",
"&&",
"@",
"$",
"_GET",
"[",
"'filter'",
"]",
"!=",
"$",
"filter",
"[",
"'field'",
"]",
")",
"{",
"$",
"this",
"->",
"model",
"->",
"addCondition",
"(",
"$",
"filter",
"[",
"'field'",
"]",
",",
"$",
"_GET",
"[",
"$",
"filter",
"[",
"'field'",
"]",
"]",
")",
";",
"}",
"}",
"}",
"}"
] | Check if filtering is need. | [
"Check",
"if",
"filtering",
"is",
"need",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/FormField/Lookup.php#L251-L265 | train |
atk4/ui | src/FormField/Lookup.php | Lookup.renderFilters | public function renderFilters()
{
if (isset($_GET['filter'])) {
if (isset($_GET['q'])) {
$this->model->addCondition($_GET['filter'], 'like', '%'.$_GET['q'].'%');
}
// Apply filtering to filter.
$this->applyFilters();
$action = $this->model->action('field', [$_GET['filter']]);
$action->group($_GET['filter']);
$rows = $action->get();
$data = [];
foreach ($rows as $k => $v) {
$data[] = ['id' => $k, 'name' => $v[$_GET['filter']]];
}
array_unshift($data, ['id' => -1, 'name' => $this->filterEmpty]);
$this->app->terminate(json_encode([
'success' => true,
'results' => $data,
]));
}
} | php | public function renderFilters()
{
if (isset($_GET['filter'])) {
if (isset($_GET['q'])) {
$this->model->addCondition($_GET['filter'], 'like', '%'.$_GET['q'].'%');
}
// Apply filtering to filter.
$this->applyFilters();
$action = $this->model->action('field', [$_GET['filter']]);
$action->group($_GET['filter']);
$rows = $action->get();
$data = [];
foreach ($rows as $k => $v) {
$data[] = ['id' => $k, 'name' => $v[$_GET['filter']]];
}
array_unshift($data, ['id' => -1, 'name' => $this->filterEmpty]);
$this->app->terminate(json_encode([
'success' => true,
'results' => $data,
]));
}
} | [
"public",
"function",
"renderFilters",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_GET",
"[",
"'filter'",
"]",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_GET",
"[",
"'q'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"model",
"->",
"addCondition",
"(",
"$",
"_GET",
"[",
"'filter'",
"]",
",",
"'like'",
",",
"'%'",
".",
"$",
"_GET",
"[",
"'q'",
"]",
".",
"'%'",
")",
";",
"}",
"// Apply filtering to filter.",
"$",
"this",
"->",
"applyFilters",
"(",
")",
";",
"$",
"action",
"=",
"$",
"this",
"->",
"model",
"->",
"action",
"(",
"'field'",
",",
"[",
"$",
"_GET",
"[",
"'filter'",
"]",
"]",
")",
";",
"$",
"action",
"->",
"group",
"(",
"$",
"_GET",
"[",
"'filter'",
"]",
")",
";",
"$",
"rows",
"=",
"$",
"action",
"->",
"get",
"(",
")",
";",
"$",
"data",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"rows",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"data",
"[",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"k",
",",
"'name'",
"=>",
"$",
"v",
"[",
"$",
"_GET",
"[",
"'filter'",
"]",
"]",
"]",
";",
"}",
"array_unshift",
"(",
"$",
"data",
",",
"[",
"'id'",
"=>",
"-",
"1",
",",
"'name'",
"=>",
"$",
"this",
"->",
"filterEmpty",
"]",
")",
";",
"$",
"this",
"->",
"app",
"->",
"terminate",
"(",
"json_encode",
"(",
"[",
"'success'",
"=>",
"true",
",",
"'results'",
"=>",
"$",
"data",
",",
"]",
")",
")",
";",
"}",
"}"
] | Check if filtering is needed and terminate app execution. | [
"Check",
"if",
"filtering",
"is",
"needed",
"and",
"terminate",
"app",
"execution",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/FormField/Lookup.php#L270-L292 | train |
atk4/ui | src/FormField/Lookup.php | Lookup.createFilterJsDropdown | public function createFilterJsDropdown()
{
foreach ($this->filters as $k => $filter) {
$f_name = $this->name.'-ac_f'.$k;
$chain = new jQuery('#'.$f_name);
$options = [
'fields' => ['name' => 'name', 'value' => 'id'],
'match' => 'value',
'apiSettings' => ['url' => $this->getCallbackURL().'&q={query}',
'cache' => false,
'data' => array_merge($this->getFilterQuery(), ['filter' => $filter['field']]),
'onResponse' => new jsFunction(['resp'], [
new jsExpression('if (!resp.success){atk.apiService.atkSuccessTest(resp);}'),
]),
],
'onChange' => new jsFunction([
(new jQuery())->trigger('filterChanged'),
$this->getJsDropdown(),
]),
];
$this->js(true, $chain->dropdown($options));
}
//set filter value using $(this) context for onChange handler instead of filter name.
$options['apiSettings']['data']['filter'] = (new jQuery())->find('input')->attr('name');
$this->filterChain = $options;
} | php | public function createFilterJsDropdown()
{
foreach ($this->filters as $k => $filter) {
$f_name = $this->name.'-ac_f'.$k;
$chain = new jQuery('#'.$f_name);
$options = [
'fields' => ['name' => 'name', 'value' => 'id'],
'match' => 'value',
'apiSettings' => ['url' => $this->getCallbackURL().'&q={query}',
'cache' => false,
'data' => array_merge($this->getFilterQuery(), ['filter' => $filter['field']]),
'onResponse' => new jsFunction(['resp'], [
new jsExpression('if (!resp.success){atk.apiService.atkSuccessTest(resp);}'),
]),
],
'onChange' => new jsFunction([
(new jQuery())->trigger('filterChanged'),
$this->getJsDropdown(),
]),
];
$this->js(true, $chain->dropdown($options));
}
//set filter value using $(this) context for onChange handler instead of filter name.
$options['apiSettings']['data']['filter'] = (new jQuery())->find('input')->attr('name');
$this->filterChain = $options;
} | [
"public",
"function",
"createFilterJsDropdown",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"filters",
"as",
"$",
"k",
"=>",
"$",
"filter",
")",
"{",
"$",
"f_name",
"=",
"$",
"this",
"->",
"name",
".",
"'-ac_f'",
".",
"$",
"k",
";",
"$",
"chain",
"=",
"new",
"jQuery",
"(",
"'#'",
".",
"$",
"f_name",
")",
";",
"$",
"options",
"=",
"[",
"'fields'",
"=>",
"[",
"'name'",
"=>",
"'name'",
",",
"'value'",
"=>",
"'id'",
"]",
",",
"'match'",
"=>",
"'value'",
",",
"'apiSettings'",
"=>",
"[",
"'url'",
"=>",
"$",
"this",
"->",
"getCallbackURL",
"(",
")",
".",
"'&q={query}'",
",",
"'cache'",
"=>",
"false",
",",
"'data'",
"=>",
"array_merge",
"(",
"$",
"this",
"->",
"getFilterQuery",
"(",
")",
",",
"[",
"'filter'",
"=>",
"$",
"filter",
"[",
"'field'",
"]",
"]",
")",
",",
"'onResponse'",
"=>",
"new",
"jsFunction",
"(",
"[",
"'resp'",
"]",
",",
"[",
"new",
"jsExpression",
"(",
"'if (!resp.success){atk.apiService.atkSuccessTest(resp);}'",
")",
",",
"]",
")",
",",
"]",
",",
"'onChange'",
"=>",
"new",
"jsFunction",
"(",
"[",
"(",
"new",
"jQuery",
"(",
")",
")",
"->",
"trigger",
"(",
"'filterChanged'",
")",
",",
"$",
"this",
"->",
"getJsDropdown",
"(",
")",
",",
"]",
")",
",",
"]",
";",
"$",
"this",
"->",
"js",
"(",
"true",
",",
"$",
"chain",
"->",
"dropdown",
"(",
"$",
"options",
")",
")",
";",
"}",
"//set filter value using $(this) context for onChange handler instead of filter name.",
"$",
"options",
"[",
"'apiSettings'",
"]",
"[",
"'data'",
"]",
"[",
"'filter'",
"]",
"=",
"(",
"new",
"jQuery",
"(",
")",
")",
"->",
"find",
"(",
"'input'",
")",
"->",
"attr",
"(",
"'name'",
")",
";",
"$",
"this",
"->",
"filterChain",
"=",
"$",
"options",
";",
"}"
] | For each filters, we need to create js dropdown and setup proper api settings.
When changing value on any of the filter we need to set main dropdown
apiSettings again in order for main dropdown to send proper filter value.
This is done via the onChange function of the dropdown filter.
This function will generate js similar to this:
$("#filterName1").dropdown({
"fields":{
"name":"name",
"value":"id"
},
"apiSettings":{
"url":"autocomplete.php?atk_admin_form_generic_country2_callback=ajax\x26__atk_callback=1\x26q={query}",
"cache":false,
"data":{"filter":"city"}
},
"onChange":function() {
$("#mainDropdown").dropdown(
{"fields":{"name":"name","value":"id"},
"apiSettings":{"url":"autocomplete.php?atk_admin_form_generic_country2_callback=ajax\x26__atk_callback=1\x26q={query}",
"cache":false,
"data":{"filteName1":$("input[name=filteName1]").parent().find(".text").text(),"filteName2":$("input[name=filteName2]").parent().find(".text").text()}
}
});
}});
@throws \atk4\ui\Exception | [
"For",
"each",
"filters",
"we",
"need",
"to",
"create",
"js",
"dropdown",
"and",
"setup",
"proper",
"api",
"settings",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/FormField/Lookup.php#L380-L406 | train |
atk4/ui | src/FormField/Lookup.php | Lookup.getFilterQuery | public function getFilterQuery()
{
$q = [];
foreach ($this->filters as $key => $filter) {
$q[$filter['field']] = new jsExpression('$([input]).parent().dropdown("get text")', ['input' => 'input[name='.$filter['field'].']']);
}
return $q;
} | php | public function getFilterQuery()
{
$q = [];
foreach ($this->filters as $key => $filter) {
$q[$filter['field']] = new jsExpression('$([input]).parent().dropdown("get text")', ['input' => 'input[name='.$filter['field'].']']);
}
return $q;
} | [
"public",
"function",
"getFilterQuery",
"(",
")",
"{",
"$",
"q",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"filters",
"as",
"$",
"key",
"=>",
"$",
"filter",
")",
"{",
"$",
"q",
"[",
"$",
"filter",
"[",
"'field'",
"]",
"]",
"=",
"new",
"jsExpression",
"(",
"'$([input]).parent().dropdown(\"get text\")'",
",",
"[",
"'input'",
"=>",
"'input[name='",
".",
"$",
"filter",
"[",
"'field'",
"]",
".",
"']'",
"]",
")",
";",
"}",
"return",
"$",
"q",
";",
"}"
] | Will create jsExpression need to add to the dropdown apiSettings data when using filters.
ex: {"data":{"filterName1":$("input[name=filterName1]").parent().find(".text").text(),"filterName2":$("input[name=filterName2]").parent().find(".text").text()}}
@return array | [
"Will",
"create",
"jsExpression",
"need",
"to",
"add",
"to",
"the",
"dropdown",
"apiSettings",
"data",
"when",
"using",
"filters",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/FormField/Lookup.php#L428-L436 | train |
atk4/ui | src/FormLayout/Generic.php | Generic.addGroup | public function addGroup($label = null)
{
if (!is_array($label)) {
$label = ['label' => $label];
} elseif (isset($label[0])) {
$label['label'] = $label[0];
unset($label[0]);
}
$label['form'] = $this->form;
return $this->add(new static($label));
} | php | public function addGroup($label = null)
{
if (!is_array($label)) {
$label = ['label' => $label];
} elseif (isset($label[0])) {
$label['label'] = $label[0];
unset($label[0]);
}
$label['form'] = $this->form;
return $this->add(new static($label));
} | [
"public",
"function",
"addGroup",
"(",
"$",
"label",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"label",
")",
")",
"{",
"$",
"label",
"=",
"[",
"'label'",
"=>",
"$",
"label",
"]",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"label",
"[",
"0",
"]",
")",
")",
"{",
"$",
"label",
"[",
"'label'",
"]",
"=",
"$",
"label",
"[",
"0",
"]",
";",
"unset",
"(",
"$",
"label",
"[",
"0",
"]",
")",
";",
"}",
"$",
"label",
"[",
"'form'",
"]",
"=",
"$",
"this",
"->",
"form",
";",
"return",
"$",
"this",
"->",
"add",
"(",
"new",
"static",
"(",
"$",
"label",
")",
")",
";",
"}"
] | Adds field group in form layout.
@param string|array $label
@return static | [
"Adds",
"field",
"group",
"in",
"form",
"layout",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/FormLayout/Generic.php#L75-L87 | train |
atk4/ui | src/FormLayout/Generic.php | Generic.addSubLayout | public function addSubLayout($seed = 'Generic', $addDivider = true)
{
$v = $this->add($this->factory($seed, ['form' => $this->form], 'FormLayout/Section'));
if ($v instanceof \atk4\ui\FormLayout\Section\Generic) {
$v = $v->addSection();
}
if ($addDivider) {
$this->add(['ui' => 'hidden divider']);
}
return $v;
} | php | public function addSubLayout($seed = 'Generic', $addDivider = true)
{
$v = $this->add($this->factory($seed, ['form' => $this->form], 'FormLayout/Section'));
if ($v instanceof \atk4\ui\FormLayout\Section\Generic) {
$v = $v->addSection();
}
if ($addDivider) {
$this->add(['ui' => 'hidden divider']);
}
return $v;
} | [
"public",
"function",
"addSubLayout",
"(",
"$",
"seed",
"=",
"'Generic'",
",",
"$",
"addDivider",
"=",
"true",
")",
"{",
"$",
"v",
"=",
"$",
"this",
"->",
"add",
"(",
"$",
"this",
"->",
"factory",
"(",
"$",
"seed",
",",
"[",
"'form'",
"=>",
"$",
"this",
"->",
"form",
"]",
",",
"'FormLayout/Section'",
")",
")",
";",
"if",
"(",
"$",
"v",
"instanceof",
"\\",
"atk4",
"\\",
"ui",
"\\",
"FormLayout",
"\\",
"Section",
"\\",
"Generic",
")",
"{",
"$",
"v",
"=",
"$",
"v",
"->",
"addSection",
"(",
")",
";",
"}",
"if",
"(",
"$",
"addDivider",
")",
"{",
"$",
"this",
"->",
"add",
"(",
"[",
"'ui'",
"=>",
"'hidden divider'",
"]",
")",
";",
"}",
"return",
"$",
"v",
";",
"}"
] | Add a form layout section to this layout.
Each section may contain other section or group.
@param mixed $seed
@param bool $addDivider Should we add divider after this section
@throws \atk4\core\Exception
@throws \atk4\ui\Exception
@return static | [
"Add",
"a",
"form",
"layout",
"section",
"to",
"this",
"layout",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/FormLayout/Generic.php#L102-L114 | train |
atk4/ui | src/FormField/Generic.php | Generic.set | public function set($value = null, $junk = null)
{
if ($this->field) {
$this->field->set($value);
return $this;
}
$this->content = $value;
return $this;
} | php | public function set($value = null, $junk = null)
{
if ($this->field) {
$this->field->set($value);
return $this;
}
$this->content = $value;
return $this;
} | [
"public",
"function",
"set",
"(",
"$",
"value",
"=",
"null",
",",
"$",
"junk",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"field",
")",
"{",
"$",
"this",
"->",
"field",
"->",
"set",
"(",
"$",
"value",
")",
";",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"content",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the value of this field. If field is a part of the form and is associated with
the model, then the model's value will also be affected.
@param mixed $value
@param mixed $junk
@return $this | [
"Sets",
"the",
"value",
"of",
"this",
"field",
".",
"If",
"field",
"is",
"a",
"part",
"of",
"the",
"form",
"and",
"is",
"associated",
"with",
"the",
"model",
"then",
"the",
"model",
"s",
"value",
"will",
"also",
"be",
"affected",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/FormField/Generic.php#L93-L104 | train |
atk4/ui | src/FormField/Generic.php | Generic.renderView | public function renderView()
{
if ($this->form) {
$this->template->trySet('name', $this->short_name);
}
parent::renderView();
} | php | public function renderView()
{
if ($this->form) {
$this->template->trySet('name', $this->short_name);
}
parent::renderView();
} | [
"public",
"function",
"renderView",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"form",
")",
"{",
"$",
"this",
"->",
"template",
"->",
"trySet",
"(",
"'name'",
",",
"$",
"this",
"->",
"short_name",
")",
";",
"}",
"parent",
"::",
"renderView",
"(",
")",
";",
"}"
] | It only makes sense to have "name" property inside a field if
it was used inside a form. | [
"It",
"only",
"makes",
"sense",
"to",
"have",
"name",
"property",
"inside",
"a",
"field",
"if",
"it",
"was",
"used",
"inside",
"a",
"form",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/FormField/Generic.php#L110-L117 | train |
atk4/ui | src/Callback.php | Callback.getURL | public function getURL($mode = 'callback')
{
return $this->owner->url([$this->urlTrigger => $mode, '__atk_callback'=>1], (bool) $this->postTrigger);
} | php | public function getURL($mode = 'callback')
{
return $this->owner->url([$this->urlTrigger => $mode, '__atk_callback'=>1], (bool) $this->postTrigger);
} | [
"public",
"function",
"getURL",
"(",
"$",
"mode",
"=",
"'callback'",
")",
"{",
"return",
"$",
"this",
"->",
"owner",
"->",
"url",
"(",
"[",
"$",
"this",
"->",
"urlTrigger",
"=>",
"$",
"mode",
",",
"'__atk_callback'",
"=>",
"1",
"]",
",",
"(",
"bool",
")",
"$",
"this",
"->",
"postTrigger",
")",
";",
"}"
] | Return URL that will trigger action on this call-back. If you intend to request
the URL loading from inside JavaScript, it's always advised to use getJSURL instead.
@param string $mode
@return string | [
"Return",
"URL",
"that",
"will",
"trigger",
"action",
"on",
"this",
"call",
"-",
"back",
".",
"If",
"you",
"intend",
"to",
"request",
"the",
"URL",
"loading",
"from",
"inside",
"JavaScript",
"it",
"s",
"always",
"advised",
"to",
"use",
"getJSURL",
"instead",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Callback.php#L161-L164 | train |
atk4/ui | src/Wizard.php | Wizard.addStep | public function addStep($name, $callback)
{
$step = $this->factory([
'Step',
'wizard' => $this,
'template'=> clone $this->stepTemplate,
'sequence'=> count($this->steps),
], $name);
// add tabs menu item
$this->steps[] = $this->add($step, 'Step');
if (!$this->stepCallback->triggered()) {
$_GET[$this->stepCallback->urlTrigger] = 0;
}
if ($step->sequence == $this->currentStep) {
$step->addClass('active');
$this->stepCallback->set($callback, [$this]);
} elseif ($step->sequence < $this->currentStep) {
$step->addClass('completed');
}
if ($step->icon == null) {
$step->icon = $this->defaultIcon;
}
return $step;
} | php | public function addStep($name, $callback)
{
$step = $this->factory([
'Step',
'wizard' => $this,
'template'=> clone $this->stepTemplate,
'sequence'=> count($this->steps),
], $name);
// add tabs menu item
$this->steps[] = $this->add($step, 'Step');
if (!$this->stepCallback->triggered()) {
$_GET[$this->stepCallback->urlTrigger] = 0;
}
if ($step->sequence == $this->currentStep) {
$step->addClass('active');
$this->stepCallback->set($callback, [$this]);
} elseif ($step->sequence < $this->currentStep) {
$step->addClass('completed');
}
if ($step->icon == null) {
$step->icon = $this->defaultIcon;
}
return $step;
} | [
"public",
"function",
"addStep",
"(",
"$",
"name",
",",
"$",
"callback",
")",
"{",
"$",
"step",
"=",
"$",
"this",
"->",
"factory",
"(",
"[",
"'Step'",
",",
"'wizard'",
"=>",
"$",
"this",
",",
"'template'",
"=>",
"clone",
"$",
"this",
"->",
"stepTemplate",
",",
"'sequence'",
"=>",
"count",
"(",
"$",
"this",
"->",
"steps",
")",
",",
"]",
",",
"$",
"name",
")",
";",
"// add tabs menu item",
"$",
"this",
"->",
"steps",
"[",
"]",
"=",
"$",
"this",
"->",
"add",
"(",
"$",
"step",
",",
"'Step'",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"stepCallback",
"->",
"triggered",
"(",
")",
")",
"{",
"$",
"_GET",
"[",
"$",
"this",
"->",
"stepCallback",
"->",
"urlTrigger",
"]",
"=",
"0",
";",
"}",
"if",
"(",
"$",
"step",
"->",
"sequence",
"==",
"$",
"this",
"->",
"currentStep",
")",
"{",
"$",
"step",
"->",
"addClass",
"(",
"'active'",
")",
";",
"$",
"this",
"->",
"stepCallback",
"->",
"set",
"(",
"$",
"callback",
",",
"[",
"$",
"this",
"]",
")",
";",
"}",
"elseif",
"(",
"$",
"step",
"->",
"sequence",
"<",
"$",
"this",
"->",
"currentStep",
")",
"{",
"$",
"step",
"->",
"addClass",
"(",
"'completed'",
")",
";",
"}",
"if",
"(",
"$",
"step",
"->",
"icon",
"==",
"null",
")",
"{",
"$",
"step",
"->",
"icon",
"=",
"$",
"this",
"->",
"defaultIcon",
";",
"}",
"return",
"$",
"step",
";",
"}"
] | Adds step to the wizard.
@param mixed $name Name of tab or Tab object
@param mixed $callback Optional callback action or URL (or array with url + parameters)
@return View | [
"Adds",
"step",
"to",
"the",
"wizard",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Wizard.php#L92-L121 | train |
atk4/ui | src/Wizard.php | Wizard.addFinish | public function addFinish($callback)
{
if (count($this->steps) == $this->currentStep + 1) {
$this->buttonFinish->link($this->stepCallback->getURL(count($this->steps)));
} elseif ($this->currentStep == count($this->steps)) {
$this->buttonPrev->destroy();
$this->buttonNext->addClass('disabled')->set('Completed');
$this->buttonFinish->destroy();
$this->app->catch_runaway_callbacks = false;
call_user_func($callback, $this);
} else {
$this->buttonFinish->destroy();
}
} | php | public function addFinish($callback)
{
if (count($this->steps) == $this->currentStep + 1) {
$this->buttonFinish->link($this->stepCallback->getURL(count($this->steps)));
} elseif ($this->currentStep == count($this->steps)) {
$this->buttonPrev->destroy();
$this->buttonNext->addClass('disabled')->set('Completed');
$this->buttonFinish->destroy();
$this->app->catch_runaway_callbacks = false;
call_user_func($callback, $this);
} else {
$this->buttonFinish->destroy();
}
} | [
"public",
"function",
"addFinish",
"(",
"$",
"callback",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"steps",
")",
"==",
"$",
"this",
"->",
"currentStep",
"+",
"1",
")",
"{",
"$",
"this",
"->",
"buttonFinish",
"->",
"link",
"(",
"$",
"this",
"->",
"stepCallback",
"->",
"getURL",
"(",
"count",
"(",
"$",
"this",
"->",
"steps",
")",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"currentStep",
"==",
"count",
"(",
"$",
"this",
"->",
"steps",
")",
")",
"{",
"$",
"this",
"->",
"buttonPrev",
"->",
"destroy",
"(",
")",
";",
"$",
"this",
"->",
"buttonNext",
"->",
"addClass",
"(",
"'disabled'",
")",
"->",
"set",
"(",
"'Completed'",
")",
";",
"$",
"this",
"->",
"buttonFinish",
"->",
"destroy",
"(",
")",
";",
"$",
"this",
"->",
"app",
"->",
"catch_runaway_callbacks",
"=",
"false",
";",
"call_user_func",
"(",
"$",
"callback",
",",
"$",
"this",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"buttonFinish",
"->",
"destroy",
"(",
")",
";",
"}",
"}"
] | Adds an extra screen to show user when he goes beyond last step.
There won't be "back" button on this step anymore.
@param callable $callback Virtual page | [
"Adds",
"an",
"extra",
"screen",
"to",
"show",
"user",
"when",
"he",
"goes",
"beyond",
"last",
"step",
".",
"There",
"won",
"t",
"be",
"back",
"button",
"on",
"this",
"step",
"anymore",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Wizard.php#L129-L143 | train |
atk4/ui | src/jsExpression.php | jsExpression.jsRender | public function jsRender()
{
$namelessCount = 0;
$res = preg_replace_callback(
'/\[[a-z0-9_]*\]|{[a-z0-9_]*}/',
function ($matches) use (&$namelessCount) {
$identifier = substr($matches[0], 1, -1);
// Allow template to contain []
if ($identifier === '') {
$identifier = $namelessCount++;
}
if (!isset($this->args[$identifier])) {
throw new Exception([
'Tag not defined in template for jsExpression',
'tag' => $identifier,
'template' => $this->template,
]);
}
$value = $this->args[$identifier];
// No escaping for {}
if ($matches[0][0] === '{') {
return $value;
}
if (is_object($value) && $value instanceof jsExpressionable) {
$value = '('.$value->jsRender().')';
} elseif (is_object($value)) {
$value = $this->_json_encode($value->toString());
} else {
$value = $this->_json_encode($value);
}
return $value;
},
$this->template
);
return trim($res);
} | php | public function jsRender()
{
$namelessCount = 0;
$res = preg_replace_callback(
'/\[[a-z0-9_]*\]|{[a-z0-9_]*}/',
function ($matches) use (&$namelessCount) {
$identifier = substr($matches[0], 1, -1);
// Allow template to contain []
if ($identifier === '') {
$identifier = $namelessCount++;
}
if (!isset($this->args[$identifier])) {
throw new Exception([
'Tag not defined in template for jsExpression',
'tag' => $identifier,
'template' => $this->template,
]);
}
$value = $this->args[$identifier];
// No escaping for {}
if ($matches[0][0] === '{') {
return $value;
}
if (is_object($value) && $value instanceof jsExpressionable) {
$value = '('.$value->jsRender().')';
} elseif (is_object($value)) {
$value = $this->_json_encode($value->toString());
} else {
$value = $this->_json_encode($value);
}
return $value;
},
$this->template
);
return trim($res);
} | [
"public",
"function",
"jsRender",
"(",
")",
"{",
"$",
"namelessCount",
"=",
"0",
";",
"$",
"res",
"=",
"preg_replace_callback",
"(",
"'/\\[[a-z0-9_]*\\]|{[a-z0-9_]*}/'",
",",
"function",
"(",
"$",
"matches",
")",
"use",
"(",
"&",
"$",
"namelessCount",
")",
"{",
"$",
"identifier",
"=",
"substr",
"(",
"$",
"matches",
"[",
"0",
"]",
",",
"1",
",",
"-",
"1",
")",
";",
"// Allow template to contain []",
"if",
"(",
"$",
"identifier",
"===",
"''",
")",
"{",
"$",
"identifier",
"=",
"$",
"namelessCount",
"++",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"args",
"[",
"$",
"identifier",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"[",
"'Tag not defined in template for jsExpression'",
",",
"'tag'",
"=>",
"$",
"identifier",
",",
"'template'",
"=>",
"$",
"this",
"->",
"template",
",",
"]",
")",
";",
"}",
"$",
"value",
"=",
"$",
"this",
"->",
"args",
"[",
"$",
"identifier",
"]",
";",
"// No escaping for {}",
"if",
"(",
"$",
"matches",
"[",
"0",
"]",
"[",
"0",
"]",
"===",
"'{'",
")",
"{",
"return",
"$",
"value",
";",
"}",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
"&&",
"$",
"value",
"instanceof",
"jsExpressionable",
")",
"{",
"$",
"value",
"=",
"'('",
".",
"$",
"value",
"->",
"jsRender",
"(",
")",
".",
"')'",
";",
"}",
"elseif",
"(",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"_json_encode",
"(",
"$",
"value",
"->",
"toString",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"_json_encode",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"value",
";",
"}",
",",
"$",
"this",
"->",
"template",
")",
";",
"return",
"trim",
"(",
"$",
"res",
")",
";",
"}"
] | Converts this arbitrary JavaScript expression into string.
@return string | [
"Converts",
"this",
"arbitrary",
"JavaScript",
"expression",
"into",
"string",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/jsExpression.php#L39-L82 | train |
atk4/ui | src/TableColumn/Generic.php | Generic.addPopup | public function addPopup($popup = null, $icon = 'caret square down')
{
if (!$this->app) {
throw new Exception('Columns\'s popup need to have a layout.');
}
$popup = $this->app->add($popup ? $popup : 'Popup')->setHoverable();
$this->setHeaderPopup($popup, $icon);
return $popup;
} | php | public function addPopup($popup = null, $icon = 'caret square down')
{
if (!$this->app) {
throw new Exception('Columns\'s popup need to have a layout.');
}
$popup = $this->app->add($popup ? $popup : 'Popup')->setHoverable();
$this->setHeaderPopup($popup, $icon);
return $popup;
} | [
"public",
"function",
"addPopup",
"(",
"$",
"popup",
"=",
"null",
",",
"$",
"icon",
"=",
"'caret square down'",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"app",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Columns\\'s popup need to have a layout.'",
")",
";",
"}",
"$",
"popup",
"=",
"$",
"this",
"->",
"app",
"->",
"add",
"(",
"$",
"popup",
"?",
"$",
"popup",
":",
"'Popup'",
")",
"->",
"setHoverable",
"(",
")",
";",
"$",
"this",
"->",
"setHeaderPopup",
"(",
"$",
"popup",
",",
"$",
"icon",
")",
";",
"return",
"$",
"popup",
";",
"}"
] | Add popup to header.
@param Popup $popup
@param string $id
@param string $icon
@throws Exception
@return mixed | [
"Add",
"popup",
"to",
"header",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/TableColumn/Generic.php#L76-L87 | train |
atk4/ui | src/TableColumn/Generic.php | Generic.setHeaderPopup | public function setHeaderPopup($popup, $icon = 'caret square down')
{
$this->hasHeaderAction = true;
$id = $this->name.'_ac';
$this->headerActionTag = ['div', ['class'=>'atk-table-dropdown'],
[
['i', ['id' => $id, 'class' => $icon.' icon']],
],
];
$popup->triggerBy = '#'.$id;
$popup->popOptions = array_merge($popup->popOptions, ['on' =>'click', 'position' => 'bottom right', 'movePopup' => false]);
$popup->stopClickEvent = true;
if (@$_GET['__atk_reload']) {
//This is part of a reload, need to reactivate popup.
$this->table->js(true, $popup->jsPopup());
}
} | php | public function setHeaderPopup($popup, $icon = 'caret square down')
{
$this->hasHeaderAction = true;
$id = $this->name.'_ac';
$this->headerActionTag = ['div', ['class'=>'atk-table-dropdown'],
[
['i', ['id' => $id, 'class' => $icon.' icon']],
],
];
$popup->triggerBy = '#'.$id;
$popup->popOptions = array_merge($popup->popOptions, ['on' =>'click', 'position' => 'bottom right', 'movePopup' => false]);
$popup->stopClickEvent = true;
if (@$_GET['__atk_reload']) {
//This is part of a reload, need to reactivate popup.
$this->table->js(true, $popup->jsPopup());
}
} | [
"public",
"function",
"setHeaderPopup",
"(",
"$",
"popup",
",",
"$",
"icon",
"=",
"'caret square down'",
")",
"{",
"$",
"this",
"->",
"hasHeaderAction",
"=",
"true",
";",
"$",
"id",
"=",
"$",
"this",
"->",
"name",
".",
"'_ac'",
";",
"$",
"this",
"->",
"headerActionTag",
"=",
"[",
"'div'",
",",
"[",
"'class'",
"=>",
"'atk-table-dropdown'",
"]",
",",
"[",
"[",
"'i'",
",",
"[",
"'id'",
"=>",
"$",
"id",
",",
"'class'",
"=>",
"$",
"icon",
".",
"' icon'",
"]",
"]",
",",
"]",
",",
"]",
";",
"$",
"popup",
"->",
"triggerBy",
"=",
"'#'",
".",
"$",
"id",
";",
"$",
"popup",
"->",
"popOptions",
"=",
"array_merge",
"(",
"$",
"popup",
"->",
"popOptions",
",",
"[",
"'on'",
"=>",
"'click'",
",",
"'position'",
"=>",
"'bottom right'",
",",
"'movePopup'",
"=>",
"false",
"]",
")",
";",
"$",
"popup",
"->",
"stopClickEvent",
"=",
"true",
";",
"if",
"(",
"@",
"$",
"_GET",
"[",
"'__atk_reload'",
"]",
")",
"{",
"//This is part of a reload, need to reactivate popup.",
"$",
"this",
"->",
"table",
"->",
"js",
"(",
"true",
",",
"$",
"popup",
"->",
"jsPopup",
"(",
")",
")",
";",
"}",
"}"
] | Setup popup header action.
@param Popup $popup
@param $icon | [
"Setup",
"popup",
"header",
"action",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/TableColumn/Generic.php#L95-L113 | train |
atk4/ui | src/TableColumn/Generic.php | Generic.addDropdown | public function addDropdown($items, $fx, $icon = 'caret square down', $menuId = null)
{
$menuITems = [];
foreach ($items as $key => $item) {
if (is_int($key)) {
$menuITems[] = ['name' => $item, 'value' => $item];
} else {
$menuITems[] = ['name' => $key, 'value' => $item];
}
}
$cb = $this->setHeaderDropdown($menuITems, $icon, $menuId);
$cb->onSelectItem(function ($menu, $item) use ($fx) {
return call_user_func($fx, $item, $menu);
});
} | php | public function addDropdown($items, $fx, $icon = 'caret square down', $menuId = null)
{
$menuITems = [];
foreach ($items as $key => $item) {
if (is_int($key)) {
$menuITems[] = ['name' => $item, 'value' => $item];
} else {
$menuITems[] = ['name' => $key, 'value' => $item];
}
}
$cb = $this->setHeaderDropdown($menuITems, $icon, $menuId);
$cb->onSelectItem(function ($menu, $item) use ($fx) {
return call_user_func($fx, $item, $menu);
});
} | [
"public",
"function",
"addDropdown",
"(",
"$",
"items",
",",
"$",
"fx",
",",
"$",
"icon",
"=",
"'caret square down'",
",",
"$",
"menuId",
"=",
"null",
")",
"{",
"$",
"menuITems",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"key",
")",
")",
"{",
"$",
"menuITems",
"[",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"item",
",",
"'value'",
"=>",
"$",
"item",
"]",
";",
"}",
"else",
"{",
"$",
"menuITems",
"[",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"key",
",",
"'value'",
"=>",
"$",
"item",
"]",
";",
"}",
"}",
"$",
"cb",
"=",
"$",
"this",
"->",
"setHeaderDropdown",
"(",
"$",
"menuITems",
",",
"$",
"icon",
",",
"$",
"menuId",
")",
";",
"$",
"cb",
"->",
"onSelectItem",
"(",
"function",
"(",
"$",
"menu",
",",
"$",
"item",
")",
"use",
"(",
"$",
"fx",
")",
"{",
"return",
"call_user_func",
"(",
"$",
"fx",
",",
"$",
"item",
",",
"$",
"menu",
")",
";",
"}",
")",
";",
"}"
] | Add a dropdown header menu.
@param array $items
@param callable $fx
@param string $icon
@param string|null $menuId The menu name.
@throws Exception | [
"Add",
"a",
"dropdown",
"header",
"menu",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/TableColumn/Generic.php#L140-L156 | train |
atk4/ui | src/TableColumn/Generic.php | Generic.setAttr | public function setAttr($attr, $value, $position = 'body')
{
$this->attr[$position][$attr] = $value;
return $this;
} | php | public function setAttr($attr, $value, $position = 'body')
{
$this->attr[$position][$attr] = $value;
return $this;
} | [
"public",
"function",
"setAttr",
"(",
"$",
"attr",
",",
"$",
"value",
",",
"$",
"position",
"=",
"'body'",
")",
"{",
"$",
"this",
"->",
"attr",
"[",
"$",
"position",
"]",
"[",
"$",
"attr",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] | Adds a new attribute to the cells of this column. The optional second argument may be "head",
"body" or "foot". If position is not defined, then attribute will be applied on all cells.
You can also use the "{$name}" value if you wish to specific row value:
$table->column['name']->setAttr('data', '{$id}');
@param string $attr
@param string $value
@param string $position
@return $this | [
"Adds",
"a",
"new",
"attribute",
"to",
"the",
"cells",
"of",
"this",
"column",
".",
"The",
"optional",
"second",
"argument",
"may",
"be",
"head",
"body",
"or",
"foot",
".",
"If",
"position",
"is",
"not",
"defined",
"then",
"attribute",
"will",
"be",
"applied",
"on",
"all",
"cells",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/TableColumn/Generic.php#L242-L247 | train |
atk4/ui | src/TableColumn/Generic.php | Generic.getTag | public function getTag($position, $value, $attr = [])
{
$attr = $this->getTagAttributes($position, $attr);
if (isset($attr['class'])) {
$attr['class'] = implode(' ', $attr['class']);
}
return $this->app->getTag($position == 'body' ? 'td' : 'th', $attr, $value);
} | php | public function getTag($position, $value, $attr = [])
{
$attr = $this->getTagAttributes($position, $attr);
if (isset($attr['class'])) {
$attr['class'] = implode(' ', $attr['class']);
}
return $this->app->getTag($position == 'body' ? 'td' : 'th', $attr, $value);
} | [
"public",
"function",
"getTag",
"(",
"$",
"position",
",",
"$",
"value",
",",
"$",
"attr",
"=",
"[",
"]",
")",
"{",
"$",
"attr",
"=",
"$",
"this",
"->",
"getTagAttributes",
"(",
"$",
"position",
",",
"$",
"attr",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"attr",
"[",
"'class'",
"]",
")",
")",
"{",
"$",
"attr",
"[",
"'class'",
"]",
"=",
"implode",
"(",
"' '",
",",
"$",
"attr",
"[",
"'class'",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"app",
"->",
"getTag",
"(",
"$",
"position",
"==",
"'body'",
"?",
"'td'",
":",
"'th'",
",",
"$",
"attr",
",",
"$",
"value",
")",
";",
"}"
] | Returns a suitable cell tag with the supplied value. Applies modifiers
added through addClass and setAttr.
@param string $position - 'head', 'body' or 'tail'
@param string $value - what is inside? either html or array defining HTML structure, see App::getTag help
@param array $attr - extra attributes to apply on the tag
@return string | [
"Returns",
"a",
"suitable",
"cell",
"tag",
"with",
"the",
"supplied",
"value",
".",
"Applies",
"modifiers",
"added",
"through",
"addClass",
"and",
"setAttr",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/TableColumn/Generic.php#L274-L283 | train |
atk4/ui | src/TableColumn/Generic.php | Generic.getTotalsCellHTML | public function getTotalsCellHTML(\atk4\data\Field $f, $value)
{
return $this->getTag('foot', $this->app->ui_persistence->typecastSaveField($f, $value));
} | php | public function getTotalsCellHTML(\atk4\data\Field $f, $value)
{
return $this->getTag('foot', $this->app->ui_persistence->typecastSaveField($f, $value));
} | [
"public",
"function",
"getTotalsCellHTML",
"(",
"\\",
"atk4",
"\\",
"data",
"\\",
"Field",
"$",
"f",
",",
"$",
"value",
")",
"{",
"return",
"$",
"this",
"->",
"getTag",
"(",
"'foot'",
",",
"$",
"this",
"->",
"app",
"->",
"ui_persistence",
"->",
"typecastSaveField",
"(",
"$",
"f",
",",
"$",
"value",
")",
")",
";",
"}"
] | Return HTML for a total value of a specific field.
@param \atk4\data\Field $f
@param mixed $value
@return string | [
"Return",
"HTML",
"for",
"a",
"total",
"value",
"of",
"a",
"specific",
"field",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/TableColumn/Generic.php#L351-L354 | train |
atk4/ui | src/FormField/Input.php | Input.getValue | public function getValue()
{
return isset($this->field) ? $this->app->ui_persistence->typecastSaveField($this->field, $this->field->get()) : (isset($this->content) ? $this->content : '');
} | php | public function getValue()
{
return isset($this->field) ? $this->app->ui_persistence->typecastSaveField($this->field, $this->field->get()) : (isset($this->content) ? $this->content : '');
} | [
"public",
"function",
"getValue",
"(",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"field",
")",
"?",
"$",
"this",
"->",
"app",
"->",
"ui_persistence",
"->",
"typecastSaveField",
"(",
"$",
"this",
"->",
"field",
",",
"$",
"this",
"->",
"field",
"->",
"get",
"(",
")",
")",
":",
"(",
"isset",
"(",
"$",
"this",
"->",
"content",
")",
"?",
"$",
"this",
"->",
"content",
":",
"''",
")",
";",
"}"
] | Returns presentable value to be inserted into input tag.
@return mixed | [
"Returns",
"presentable",
"value",
"to",
"be",
"inserted",
"into",
"input",
"tag",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/FormField/Input.php#L75-L78 | train |
atk4/ui | src/FormField/Input.php | Input.addAction | public function addAction($defaults = [])
{
if (!is_array($defaults)) {
$defaults = [$defaults];
}
$this->action = $this->add(new Button($defaults), 'AfterInput');
$this->addClass('action');
return $this->action;
} | php | public function addAction($defaults = [])
{
if (!is_array($defaults)) {
$defaults = [$defaults];
}
$this->action = $this->add(new Button($defaults), 'AfterInput');
$this->addClass('action');
return $this->action;
} | [
"public",
"function",
"addAction",
"(",
"$",
"defaults",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"defaults",
")",
")",
"{",
"$",
"defaults",
"=",
"[",
"$",
"defaults",
"]",
";",
"}",
"$",
"this",
"->",
"action",
"=",
"$",
"this",
"->",
"add",
"(",
"new",
"Button",
"(",
"$",
"defaults",
")",
",",
"'AfterInput'",
")",
";",
"$",
"this",
"->",
"addClass",
"(",
"'action'",
")",
";",
"return",
"$",
"this",
"->",
"action",
";",
"}"
] | Adds new action button.
@param array $defaults
@return Button | [
"Adds",
"new",
"action",
"button",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/FormField/Input.php#L216-L226 | train |
atk4/ui | src/Component/InlineEdit.php | InlineEdit.setModel | public function setModel(\atk4\data\Model $model)
{
parent::setModel($model);
$this->field = $this->field ? $this->field : $this->model->title_field;
if ($this->autoSave && $this->model->loaded()) {
if ($this->cb->triggered()) {
$value = $_POST['value'] ? $_POST['value'] : null;
$this->cb->set(function () use ($value) {
try {
$this->model[$this->field] = $this->app->ui_persistence->typecastLoadField($this->model->getElement($this->field), $value);
$this->model->save();
return $this->jsSuccess('Update successfully');
} catch (ValidationException $e) {
$this->app->terminate(json_encode([
'success' => true,
'hasValidationError' => true,
'atkjs' => $this->jsError(call_user_func($this->formatErrorMsg, $e, $value))->jsRender(),
]));
}
});
}
}
return $this->model;
} | php | public function setModel(\atk4\data\Model $model)
{
parent::setModel($model);
$this->field = $this->field ? $this->field : $this->model->title_field;
if ($this->autoSave && $this->model->loaded()) {
if ($this->cb->triggered()) {
$value = $_POST['value'] ? $_POST['value'] : null;
$this->cb->set(function () use ($value) {
try {
$this->model[$this->field] = $this->app->ui_persistence->typecastLoadField($this->model->getElement($this->field), $value);
$this->model->save();
return $this->jsSuccess('Update successfully');
} catch (ValidationException $e) {
$this->app->terminate(json_encode([
'success' => true,
'hasValidationError' => true,
'atkjs' => $this->jsError(call_user_func($this->formatErrorMsg, $e, $value))->jsRender(),
]));
}
});
}
}
return $this->model;
} | [
"public",
"function",
"setModel",
"(",
"\\",
"atk4",
"\\",
"data",
"\\",
"Model",
"$",
"model",
")",
"{",
"parent",
"::",
"setModel",
"(",
"$",
"model",
")",
";",
"$",
"this",
"->",
"field",
"=",
"$",
"this",
"->",
"field",
"?",
"$",
"this",
"->",
"field",
":",
"$",
"this",
"->",
"model",
"->",
"title_field",
";",
"if",
"(",
"$",
"this",
"->",
"autoSave",
"&&",
"$",
"this",
"->",
"model",
"->",
"loaded",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"cb",
"->",
"triggered",
"(",
")",
")",
"{",
"$",
"value",
"=",
"$",
"_POST",
"[",
"'value'",
"]",
"?",
"$",
"_POST",
"[",
"'value'",
"]",
":",
"null",
";",
"$",
"this",
"->",
"cb",
"->",
"set",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"value",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"model",
"[",
"$",
"this",
"->",
"field",
"]",
"=",
"$",
"this",
"->",
"app",
"->",
"ui_persistence",
"->",
"typecastLoadField",
"(",
"$",
"this",
"->",
"model",
"->",
"getElement",
"(",
"$",
"this",
"->",
"field",
")",
",",
"$",
"value",
")",
";",
"$",
"this",
"->",
"model",
"->",
"save",
"(",
")",
";",
"return",
"$",
"this",
"->",
"jsSuccess",
"(",
"'Update successfully'",
")",
";",
"}",
"catch",
"(",
"ValidationException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"terminate",
"(",
"json_encode",
"(",
"[",
"'success'",
"=>",
"true",
",",
"'hasValidationError'",
"=>",
"true",
",",
"'atkjs'",
"=>",
"$",
"this",
"->",
"jsError",
"(",
"call_user_func",
"(",
"$",
"this",
"->",
"formatErrorMsg",
",",
"$",
"e",
",",
"$",
"value",
")",
")",
"->",
"jsRender",
"(",
")",
",",
"]",
")",
")",
";",
"}",
"}",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"model",
";",
"}"
] | Set Model of this View.
@param \atk4\data\Model $model
@return \atk4\data\Model | [
"Set",
"Model",
"of",
"this",
"View",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Component/InlineEdit.php#L107-L132 | train |
atk4/ui | src/Component/InlineEdit.php | InlineEdit.renderView | public function renderView()
{
parent::renderView();
$type = ($this->model && $this->field) ? $this->model->elements[$this->field]->type : 'text';
$type = ($type === 'string') ? 'text' : $type;
if ($type != 'text' && $type != 'number') {
throw new Exception('Error: Only string or number field can be edited inline. Field Type = '.$type);
}
if ($this->model && $this->model->loaded()) {
$initValue = $this->model->get($this->field);
} else {
$initValue = $this->initValue;
}
$fieldName = $this->field ? $this->field : 'name';
$this->template->set('inputCss', $this->inputCss);
$this->template->trySet('fieldName', $fieldName);
$this->template->trySet('fieldType', $type);
$this->vue('atk-inline-edit', [
'initValue' => $initValue,
'url' => $this->cb->getJSURL(),
'saveOnBlur' => $this->saveOnBlur,
]);
// $this->js(true, (new jsVueService())->createAtkVue(
// '#'.$this->name,
// 'atk-inline-edit',
// [
// 'initValue' => $initValue,
// 'url' => $this->cb->getJSURL(),
// 'saveOnBlur' => $this->saveOnBlur,
// ]
// ));
} | php | public function renderView()
{
parent::renderView();
$type = ($this->model && $this->field) ? $this->model->elements[$this->field]->type : 'text';
$type = ($type === 'string') ? 'text' : $type;
if ($type != 'text' && $type != 'number') {
throw new Exception('Error: Only string or number field can be edited inline. Field Type = '.$type);
}
if ($this->model && $this->model->loaded()) {
$initValue = $this->model->get($this->field);
} else {
$initValue = $this->initValue;
}
$fieldName = $this->field ? $this->field : 'name';
$this->template->set('inputCss', $this->inputCss);
$this->template->trySet('fieldName', $fieldName);
$this->template->trySet('fieldType', $type);
$this->vue('atk-inline-edit', [
'initValue' => $initValue,
'url' => $this->cb->getJSURL(),
'saveOnBlur' => $this->saveOnBlur,
]);
// $this->js(true, (new jsVueService())->createAtkVue(
// '#'.$this->name,
// 'atk-inline-edit',
// [
// 'initValue' => $initValue,
// 'url' => $this->cb->getJSURL(),
// 'saveOnBlur' => $this->saveOnBlur,
// ]
// ));
} | [
"public",
"function",
"renderView",
"(",
")",
"{",
"parent",
"::",
"renderView",
"(",
")",
";",
"$",
"type",
"=",
"(",
"$",
"this",
"->",
"model",
"&&",
"$",
"this",
"->",
"field",
")",
"?",
"$",
"this",
"->",
"model",
"->",
"elements",
"[",
"$",
"this",
"->",
"field",
"]",
"->",
"type",
":",
"'text'",
";",
"$",
"type",
"=",
"(",
"$",
"type",
"===",
"'string'",
")",
"?",
"'text'",
":",
"$",
"type",
";",
"if",
"(",
"$",
"type",
"!=",
"'text'",
"&&",
"$",
"type",
"!=",
"'number'",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Error: Only string or number field can be edited inline. Field Type = '",
".",
"$",
"type",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"model",
"&&",
"$",
"this",
"->",
"model",
"->",
"loaded",
"(",
")",
")",
"{",
"$",
"initValue",
"=",
"$",
"this",
"->",
"model",
"->",
"get",
"(",
"$",
"this",
"->",
"field",
")",
";",
"}",
"else",
"{",
"$",
"initValue",
"=",
"$",
"this",
"->",
"initValue",
";",
"}",
"$",
"fieldName",
"=",
"$",
"this",
"->",
"field",
"?",
"$",
"this",
"->",
"field",
":",
"'name'",
";",
"$",
"this",
"->",
"template",
"->",
"set",
"(",
"'inputCss'",
",",
"$",
"this",
"->",
"inputCss",
")",
";",
"$",
"this",
"->",
"template",
"->",
"trySet",
"(",
"'fieldName'",
",",
"$",
"fieldName",
")",
";",
"$",
"this",
"->",
"template",
"->",
"trySet",
"(",
"'fieldType'",
",",
"$",
"type",
")",
";",
"$",
"this",
"->",
"vue",
"(",
"'atk-inline-edit'",
",",
"[",
"'initValue'",
"=>",
"$",
"initValue",
",",
"'url'",
"=>",
"$",
"this",
"->",
"cb",
"->",
"getJSURL",
"(",
")",
",",
"'saveOnBlur'",
"=>",
"$",
"this",
"->",
"saveOnBlur",
",",
"]",
")",
";",
"// $this->js(true, (new jsVueService())->createAtkVue(",
"// '#'.$this->name,",
"// 'atk-inline-edit',",
"// [",
"// 'initValue' => $initValue,",
"// 'url' => $this->cb->getJSURL(),",
"// 'saveOnBlur' => $this->saveOnBlur,",
"// ]",
"// ));",
"}"
] | Renders View. | [
"Renders",
"View",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Component/InlineEdit.php#L191-L229 | train |
atk4/ui | src/Component/ItemSearch.php | ItemSearch.setModelCondition | public function setModelCondition($m)
{
$q = $this->getQuery();
if ($q && ($_GET['__atk_reload'] ? $_GET['__atk_reload'] : null) === $this->reload->name) {
$m->addCondition('name', 'like', '%'.$q.'%');
}
return $m;
} | php | public function setModelCondition($m)
{
$q = $this->getQuery();
if ($q && ($_GET['__atk_reload'] ? $_GET['__atk_reload'] : null) === $this->reload->name) {
$m->addCondition('name', 'like', '%'.$q.'%');
}
return $m;
} | [
"public",
"function",
"setModelCondition",
"(",
"$",
"m",
")",
"{",
"$",
"q",
"=",
"$",
"this",
"->",
"getQuery",
"(",
")",
";",
"if",
"(",
"$",
"q",
"&&",
"(",
"$",
"_GET",
"[",
"'__atk_reload'",
"]",
"?",
"$",
"_GET",
"[",
"'__atk_reload'",
"]",
":",
"null",
")",
"===",
"$",
"this",
"->",
"reload",
"->",
"name",
")",
"{",
"$",
"m",
"->",
"addCondition",
"(",
"'name'",
",",
"'like'",
",",
"'%'",
".",
"$",
"q",
".",
"'%'",
")",
";",
"}",
"return",
"$",
"m",
";",
"}"
] | Set model condition base on search request.
@param $m
@return mixed | [
"Set",
"model",
"condition",
"base",
"on",
"search",
"request",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Component/ItemSearch.php#L76-L84 | train |
atk4/ui | src/VirtualPage.php | VirtualPage.set | public function set($fx = [], $junk = null)
{
if (!$fx) {
return $this;
}
if ($this->fx) {
throw new Exception([
'Callback for this Virtual Page is already defined',
'vp' => $this,
'old_fx' => $this->fx,
'new_fx' => $fx,
]);
}
$this->fx = $fx;
return $this;
} | php | public function set($fx = [], $junk = null)
{
if (!$fx) {
return $this;
}
if ($this->fx) {
throw new Exception([
'Callback for this Virtual Page is already defined',
'vp' => $this,
'old_fx' => $this->fx,
'new_fx' => $fx,
]);
}
$this->fx = $fx;
return $this;
} | [
"public",
"function",
"set",
"(",
"$",
"fx",
"=",
"[",
"]",
",",
"$",
"junk",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"fx",
")",
"{",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"fx",
")",
"{",
"throw",
"new",
"Exception",
"(",
"[",
"'Callback for this Virtual Page is already defined'",
",",
"'vp'",
"=>",
"$",
"this",
",",
"'old_fx'",
"=>",
"$",
"this",
"->",
"fx",
",",
"'new_fx'",
"=>",
"$",
"fx",
",",
"]",
")",
";",
"}",
"$",
"this",
"->",
"fx",
"=",
"$",
"fx",
";",
"return",
"$",
"this",
";",
"}"
] | Set callback function of virtual page.
Note that only one callback function can be defined.
@param array $fx Need this to be defined as arrayotherwise we get warning in PHP7
@param mixed $junk
@return $this | [
"Set",
"callback",
"function",
"of",
"virtual",
"page",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/VirtualPage.php#L49-L66 | train |
atk4/ui | src/VirtualPage.php | VirtualPage.getHTML | public function getHTML()
{
$this->cb->set(function () {
// if virtual page callback is triggered
if ($type = $this->cb->triggered()) {
// process callback
if ($this->fx) {
call_user_func($this->fx, $this);
}
// special treatment for popup
if ($type == 'popup') {
$this->app->html->template->set('title', $this->app->title);
$this->app->html->template->setHTML('Content', parent::getHTML());
$this->app->html->template->appendHTML('HEAD', $this->getJS());
$this->app->terminate($this->app->html->template->render());
}
// render and terminate
if (isset($_GET['json'])) {
$this->app->terminate($this->renderJSON());
}
// do not terminate if callback supplied (no cutting)
if ($type != 'callback') {
$this->app->terminate($this->render());
}
}
// Remove all elements from inside the Content
foreach ($this->app->layout->elements as $key => $view) {
if ($view instanceof View && $view->region == 'Content') {
unset($this->app->layout->elements[$key]);
}
}
$this->app->layout->template->setHTML('Content', parent::getHTML());
$this->app->layout->_js_actions = array_merge($this->app->layout->_js_actions, $this->_js_actions);
$this->app->html->template->setHTML('Content', $this->app->layout->getHTML());
$this->app->html->template->appendHTML('HEAD', $this->app->layout->getJS());
$this->app->terminate($this->app->html->template->render());
});
} | php | public function getHTML()
{
$this->cb->set(function () {
// if virtual page callback is triggered
if ($type = $this->cb->triggered()) {
// process callback
if ($this->fx) {
call_user_func($this->fx, $this);
}
// special treatment for popup
if ($type == 'popup') {
$this->app->html->template->set('title', $this->app->title);
$this->app->html->template->setHTML('Content', parent::getHTML());
$this->app->html->template->appendHTML('HEAD', $this->getJS());
$this->app->terminate($this->app->html->template->render());
}
// render and terminate
if (isset($_GET['json'])) {
$this->app->terminate($this->renderJSON());
}
// do not terminate if callback supplied (no cutting)
if ($type != 'callback') {
$this->app->terminate($this->render());
}
}
// Remove all elements from inside the Content
foreach ($this->app->layout->elements as $key => $view) {
if ($view instanceof View && $view->region == 'Content') {
unset($this->app->layout->elements[$key]);
}
}
$this->app->layout->template->setHTML('Content', parent::getHTML());
$this->app->layout->_js_actions = array_merge($this->app->layout->_js_actions, $this->_js_actions);
$this->app->html->template->setHTML('Content', $this->app->layout->getHTML());
$this->app->html->template->appendHTML('HEAD', $this->app->layout->getJS());
$this->app->terminate($this->app->html->template->render());
});
} | [
"public",
"function",
"getHTML",
"(",
")",
"{",
"$",
"this",
"->",
"cb",
"->",
"set",
"(",
"function",
"(",
")",
"{",
"// if virtual page callback is triggered",
"if",
"(",
"$",
"type",
"=",
"$",
"this",
"->",
"cb",
"->",
"triggered",
"(",
")",
")",
"{",
"// process callback",
"if",
"(",
"$",
"this",
"->",
"fx",
")",
"{",
"call_user_func",
"(",
"$",
"this",
"->",
"fx",
",",
"$",
"this",
")",
";",
"}",
"// special treatment for popup",
"if",
"(",
"$",
"type",
"==",
"'popup'",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"html",
"->",
"template",
"->",
"set",
"(",
"'title'",
",",
"$",
"this",
"->",
"app",
"->",
"title",
")",
";",
"$",
"this",
"->",
"app",
"->",
"html",
"->",
"template",
"->",
"setHTML",
"(",
"'Content'",
",",
"parent",
"::",
"getHTML",
"(",
")",
")",
";",
"$",
"this",
"->",
"app",
"->",
"html",
"->",
"template",
"->",
"appendHTML",
"(",
"'HEAD'",
",",
"$",
"this",
"->",
"getJS",
"(",
")",
")",
";",
"$",
"this",
"->",
"app",
"->",
"terminate",
"(",
"$",
"this",
"->",
"app",
"->",
"html",
"->",
"template",
"->",
"render",
"(",
")",
")",
";",
"}",
"// render and terminate",
"if",
"(",
"isset",
"(",
"$",
"_GET",
"[",
"'json'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"terminate",
"(",
"$",
"this",
"->",
"renderJSON",
"(",
")",
")",
";",
"}",
"// do not terminate if callback supplied (no cutting)",
"if",
"(",
"$",
"type",
"!=",
"'callback'",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"terminate",
"(",
"$",
"this",
"->",
"render",
"(",
")",
")",
";",
"}",
"}",
"// Remove all elements from inside the Content",
"foreach",
"(",
"$",
"this",
"->",
"app",
"->",
"layout",
"->",
"elements",
"as",
"$",
"key",
"=>",
"$",
"view",
")",
"{",
"if",
"(",
"$",
"view",
"instanceof",
"View",
"&&",
"$",
"view",
"->",
"region",
"==",
"'Content'",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"app",
"->",
"layout",
"->",
"elements",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"$",
"this",
"->",
"app",
"->",
"layout",
"->",
"template",
"->",
"setHTML",
"(",
"'Content'",
",",
"parent",
"::",
"getHTML",
"(",
")",
")",
";",
"$",
"this",
"->",
"app",
"->",
"layout",
"->",
"_js_actions",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"app",
"->",
"layout",
"->",
"_js_actions",
",",
"$",
"this",
"->",
"_js_actions",
")",
";",
"$",
"this",
"->",
"app",
"->",
"html",
"->",
"template",
"->",
"setHTML",
"(",
"'Content'",
",",
"$",
"this",
"->",
"app",
"->",
"layout",
"->",
"getHTML",
"(",
")",
")",
";",
"$",
"this",
"->",
"app",
"->",
"html",
"->",
"template",
"->",
"appendHTML",
"(",
"'HEAD'",
",",
"$",
"this",
"->",
"app",
"->",
"layout",
"->",
"getJS",
"(",
")",
")",
";",
"$",
"this",
"->",
"app",
"->",
"terminate",
"(",
"$",
"this",
"->",
"app",
"->",
"html",
"->",
"template",
"->",
"render",
"(",
")",
")",
";",
"}",
")",
";",
"}"
] | VirtualPage is not rendered normally. It's invisible. Only when
it is triggered, it will exclusively output it's content. | [
"VirtualPage",
"is",
"not",
"rendered",
"normally",
".",
"It",
"s",
"invisible",
".",
"Only",
"when",
"it",
"is",
"triggered",
"it",
"will",
"exclusively",
"output",
"it",
"s",
"content",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/VirtualPage.php#L108-L155 | train |
atk4/ui | src/Grid.php | Grid.setIpp | public function setIpp($ipp, $label = 'Item per pages:')
{
if (is_array($ipp)) {
$this->addItemsPerPageSelector($ipp, $label);
if (@$_GET['ipp']) {
$this->ipp = $_GET['ipp'];
} else {
$this->ipp = $ipp[0];
}
} else {
$this->ipp = $ipp;
}
} | php | public function setIpp($ipp, $label = 'Item per pages:')
{
if (is_array($ipp)) {
$this->addItemsPerPageSelector($ipp, $label);
if (@$_GET['ipp']) {
$this->ipp = $_GET['ipp'];
} else {
$this->ipp = $ipp[0];
}
} else {
$this->ipp = $ipp;
}
} | [
"public",
"function",
"setIpp",
"(",
"$",
"ipp",
",",
"$",
"label",
"=",
"'Item per pages:'",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"ipp",
")",
")",
"{",
"$",
"this",
"->",
"addItemsPerPageSelector",
"(",
"$",
"ipp",
",",
"$",
"label",
")",
";",
"if",
"(",
"@",
"$",
"_GET",
"[",
"'ipp'",
"]",
")",
"{",
"$",
"this",
"->",
"ipp",
"=",
"$",
"_GET",
"[",
"'ipp'",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"ipp",
"=",
"$",
"ipp",
"[",
"0",
"]",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"ipp",
"=",
"$",
"ipp",
";",
"}",
"}"
] | Set item per page value.
if an array is passed, it will also add an ItemPerPageSelector to paginator.
@param int|array $ipp
@param string $label
@throws Exception | [
"Set",
"item",
"per",
"page",
"value",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Grid.php#L155-L167 | train |
atk4/ui | src/Grid.php | Grid.addItemsPerPageSelector | public function addItemsPerPageSelector($items = [10, 25, 50, 100], $label = 'Item per pages:')
{
if ($ipp = $this->container->stickyGet('ipp')) {
$this->ipp = $ipp;
} else {
$this->ipp = $items[0];
}
$pageLength = $this->paginator->add(['ItemsPerPageSelector', 'pageLengthItems' => $items, 'label' => $label, 'currentIpp' => $this->ipp], 'afterPaginator');
$this->paginator->template->trySet('PaginatorType', 'ui grid');
if ($sortBy = $this->getSortBy()) {
$pageLength->stickyGet($this->name.'_sort', $sortBy);
}
$pageLength->onPageLengthSelect(function ($ipp) use ($pageLength) {
$this->ipp = $ipp;
$this->setModelLimitFromPaginator();
//add ipp to quicksearch
if ($this->quickSearch instanceof jsSearch) {
$this->container->js(true, $this->quickSearch->js()->atkJsSearch('setUrlArgs', ['ipp', $this->ipp]));
}
$this->applySort();
//return the view to reload.
return $this->container;
});
return $this;
} | php | public function addItemsPerPageSelector($items = [10, 25, 50, 100], $label = 'Item per pages:')
{
if ($ipp = $this->container->stickyGet('ipp')) {
$this->ipp = $ipp;
} else {
$this->ipp = $items[0];
}
$pageLength = $this->paginator->add(['ItemsPerPageSelector', 'pageLengthItems' => $items, 'label' => $label, 'currentIpp' => $this->ipp], 'afterPaginator');
$this->paginator->template->trySet('PaginatorType', 'ui grid');
if ($sortBy = $this->getSortBy()) {
$pageLength->stickyGet($this->name.'_sort', $sortBy);
}
$pageLength->onPageLengthSelect(function ($ipp) use ($pageLength) {
$this->ipp = $ipp;
$this->setModelLimitFromPaginator();
//add ipp to quicksearch
if ($this->quickSearch instanceof jsSearch) {
$this->container->js(true, $this->quickSearch->js()->atkJsSearch('setUrlArgs', ['ipp', $this->ipp]));
}
$this->applySort();
//return the view to reload.
return $this->container;
});
return $this;
} | [
"public",
"function",
"addItemsPerPageSelector",
"(",
"$",
"items",
"=",
"[",
"10",
",",
"25",
",",
"50",
",",
"100",
"]",
",",
"$",
"label",
"=",
"'Item per pages:'",
")",
"{",
"if",
"(",
"$",
"ipp",
"=",
"$",
"this",
"->",
"container",
"->",
"stickyGet",
"(",
"'ipp'",
")",
")",
"{",
"$",
"this",
"->",
"ipp",
"=",
"$",
"ipp",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"ipp",
"=",
"$",
"items",
"[",
"0",
"]",
";",
"}",
"$",
"pageLength",
"=",
"$",
"this",
"->",
"paginator",
"->",
"add",
"(",
"[",
"'ItemsPerPageSelector'",
",",
"'pageLengthItems'",
"=>",
"$",
"items",
",",
"'label'",
"=>",
"$",
"label",
",",
"'currentIpp'",
"=>",
"$",
"this",
"->",
"ipp",
"]",
",",
"'afterPaginator'",
")",
";",
"$",
"this",
"->",
"paginator",
"->",
"template",
"->",
"trySet",
"(",
"'PaginatorType'",
",",
"'ui grid'",
")",
";",
"if",
"(",
"$",
"sortBy",
"=",
"$",
"this",
"->",
"getSortBy",
"(",
")",
")",
"{",
"$",
"pageLength",
"->",
"stickyGet",
"(",
"$",
"this",
"->",
"name",
".",
"'_sort'",
",",
"$",
"sortBy",
")",
";",
"}",
"$",
"pageLength",
"->",
"onPageLengthSelect",
"(",
"function",
"(",
"$",
"ipp",
")",
"use",
"(",
"$",
"pageLength",
")",
"{",
"$",
"this",
"->",
"ipp",
"=",
"$",
"ipp",
";",
"$",
"this",
"->",
"setModelLimitFromPaginator",
"(",
")",
";",
"//add ipp to quicksearch",
"if",
"(",
"$",
"this",
"->",
"quickSearch",
"instanceof",
"jsSearch",
")",
"{",
"$",
"this",
"->",
"container",
"->",
"js",
"(",
"true",
",",
"$",
"this",
"->",
"quickSearch",
"->",
"js",
"(",
")",
"->",
"atkJsSearch",
"(",
"'setUrlArgs'",
",",
"[",
"'ipp'",
",",
"$",
"this",
"->",
"ipp",
"]",
")",
")",
";",
"}",
"$",
"this",
"->",
"applySort",
"(",
")",
";",
"//return the view to reload.",
"return",
"$",
"this",
"->",
"container",
";",
"}",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Add ItemsPerPageSelector View in grid menu or paginator in order to dynamically setup number of item per page.
@param array $items An array of item's per page value.
@param string $label The memu item label.
@throws Exception
@return $this | [
"Add",
"ItemsPerPageSelector",
"View",
"in",
"grid",
"menu",
"or",
"paginator",
"in",
"order",
"to",
"dynamically",
"setup",
"number",
"of",
"item",
"per",
"page",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Grid.php#L179-L208 | train |
atk4/ui | src/Grid.php | Grid.addJsPaginator | public function addJsPaginator($ipp, $options = [], $container = null, $scrollRegion = 'Body')
{
if ($this->paginator) {
$this->paginator->destroy();
//prevent action(count) to be output twice.
$this->paginator = null;
}
if ($sortBy = $this->getSortBy()) {
$this->stickyGet($this->name.'_sort', $sortBy);
}
$this->applySort();
$this->table->addJsPaginator($ipp, $options, $container, $scrollRegion);
return $this;
} | php | public function addJsPaginator($ipp, $options = [], $container = null, $scrollRegion = 'Body')
{
if ($this->paginator) {
$this->paginator->destroy();
//prevent action(count) to be output twice.
$this->paginator = null;
}
if ($sortBy = $this->getSortBy()) {
$this->stickyGet($this->name.'_sort', $sortBy);
}
$this->applySort();
$this->table->addJsPaginator($ipp, $options, $container, $scrollRegion);
return $this;
} | [
"public",
"function",
"addJsPaginator",
"(",
"$",
"ipp",
",",
"$",
"options",
"=",
"[",
"]",
",",
"$",
"container",
"=",
"null",
",",
"$",
"scrollRegion",
"=",
"'Body'",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"paginator",
")",
"{",
"$",
"this",
"->",
"paginator",
"->",
"destroy",
"(",
")",
";",
"//prevent action(count) to be output twice.",
"$",
"this",
"->",
"paginator",
"=",
"null",
";",
"}",
"if",
"(",
"$",
"sortBy",
"=",
"$",
"this",
"->",
"getSortBy",
"(",
")",
")",
"{",
"$",
"this",
"->",
"stickyGet",
"(",
"$",
"this",
"->",
"name",
".",
"'_sort'",
",",
"$",
"sortBy",
")",
";",
"}",
"$",
"this",
"->",
"applySort",
"(",
")",
";",
"$",
"this",
"->",
"table",
"->",
"addJsPaginator",
"(",
"$",
"ipp",
",",
"$",
"options",
",",
"$",
"container",
",",
"$",
"scrollRegion",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Add dynamic scrolling paginator.
@param int $ipp Number of item per page to start with.
@param array $options An array with js Scroll plugin options.
@param View $container The container holding the lister for scrolling purpose. Default to view owner.
@param string $scrollRegion A specific template region to render. Render output is append to container html element.
@throws Exception
@return $this | [
"Add",
"dynamic",
"scrolling",
"paginator",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Grid.php#L222-L238 | train |
atk4/ui | src/Grid.php | Grid.addJsPaginatorInContainer | public function addJsPaginatorInContainer($ipp, $containerHeight, $options = [], $container = null, $scrollRegion = 'Body')
{
$this->table->hasCollapsingCssActionColumn = false;
$options = array_merge($options, [
'hasFixTableHeader' => true,
'tableContainerHeight' => $containerHeight,
]);
//adding a state context to js scroll plugin.
$options = array_merge(['stateContext' => '#'.$this->container->name], $options);
return $this->addJsPaginator($ipp, $options, $container, $scrollRegion);
} | php | public function addJsPaginatorInContainer($ipp, $containerHeight, $options = [], $container = null, $scrollRegion = 'Body')
{
$this->table->hasCollapsingCssActionColumn = false;
$options = array_merge($options, [
'hasFixTableHeader' => true,
'tableContainerHeight' => $containerHeight,
]);
//adding a state context to js scroll plugin.
$options = array_merge(['stateContext' => '#'.$this->container->name], $options);
return $this->addJsPaginator($ipp, $options, $container, $scrollRegion);
} | [
"public",
"function",
"addJsPaginatorInContainer",
"(",
"$",
"ipp",
",",
"$",
"containerHeight",
",",
"$",
"options",
"=",
"[",
"]",
",",
"$",
"container",
"=",
"null",
",",
"$",
"scrollRegion",
"=",
"'Body'",
")",
"{",
"$",
"this",
"->",
"table",
"->",
"hasCollapsingCssActionColumn",
"=",
"false",
";",
"$",
"options",
"=",
"array_merge",
"(",
"$",
"options",
",",
"[",
"'hasFixTableHeader'",
"=>",
"true",
",",
"'tableContainerHeight'",
"=>",
"$",
"containerHeight",
",",
"]",
")",
";",
"//adding a state context to js scroll plugin.",
"$",
"options",
"=",
"array_merge",
"(",
"[",
"'stateContext'",
"=>",
"'#'",
".",
"$",
"this",
"->",
"container",
"->",
"name",
"]",
",",
"$",
"options",
")",
";",
"return",
"$",
"this",
"->",
"addJsPaginator",
"(",
"$",
"ipp",
",",
"$",
"options",
",",
"$",
"container",
",",
"$",
"scrollRegion",
")",
";",
"}"
] | Add dynamic scrolling paginator in container.
Use this to make table headers fixed.
@param int $ipp Number of item per page to start with.
@param int $containerHeight Number of pixel the table container should be.
@param array $options An array with js Scroll plugin options.
@param View $container The container holding the lister for scrolling purpose. Default to view owner.
@param string $scrollRegion A specific template region to render. Render output is append to container html element.
@throws Exception
@return $this | [
"Add",
"dynamic",
"scrolling",
"paginator",
"in",
"container",
".",
"Use",
"this",
"to",
"make",
"table",
"headers",
"fixed",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Grid.php#L254-L265 | train |
atk4/ui | src/Grid.php | Grid.addAction | public function addAction($button, $action, $confirm = false)
{
if (!$this->actions) {
$this->actions = $this->table->addColumn(null, $this->actionDecorator);
}
return $this->actions->addAction($button, $action, $confirm);
} | php | public function addAction($button, $action, $confirm = false)
{
if (!$this->actions) {
$this->actions = $this->table->addColumn(null, $this->actionDecorator);
}
return $this->actions->addAction($button, $action, $confirm);
} | [
"public",
"function",
"addAction",
"(",
"$",
"button",
",",
"$",
"action",
",",
"$",
"confirm",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"actions",
")",
"{",
"$",
"this",
"->",
"actions",
"=",
"$",
"this",
"->",
"table",
"->",
"addColumn",
"(",
"null",
",",
"$",
"this",
"->",
"actionDecorator",
")",
";",
"}",
"return",
"$",
"this",
"->",
"actions",
"->",
"addAction",
"(",
"$",
"button",
",",
"$",
"action",
",",
"$",
"confirm",
")",
";",
"}"
] | Adds a new button into the action column on the right. For CRUD this
column will already contain "delete" and "edit" buttons.
@param string|array|View $button Label text, object or seed for the Button
@param jsExpressionable|callable $action JavaScript action or callback
@param bool|string $confirm Should we display confirmation "Are you sure?" | [
"Adds",
"a",
"new",
"button",
"into",
"the",
"action",
"column",
"on",
"the",
"right",
".",
"For",
"CRUD",
"this",
"column",
"will",
"already",
"contain",
"delete",
"and",
"edit",
"buttons",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Grid.php#L327-L334 | train |
atk4/ui | src/Grid.php | Grid.addFilterColumn | public function addFilterColumn($names = null)
{
$this->menu->addItem(['Clear Filters'], new \atk4\ui\jsReload($this->table->reload, ['atk_clear_filter' => 1]));
$this->table->setFilterColumn($names);
return $this;
} | php | public function addFilterColumn($names = null)
{
$this->menu->addItem(['Clear Filters'], new \atk4\ui\jsReload($this->table->reload, ['atk_clear_filter' => 1]));
$this->table->setFilterColumn($names);
return $this;
} | [
"public",
"function",
"addFilterColumn",
"(",
"$",
"names",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"menu",
"->",
"addItem",
"(",
"[",
"'Clear Filters'",
"]",
",",
"new",
"\\",
"atk4",
"\\",
"ui",
"\\",
"jsReload",
"(",
"$",
"this",
"->",
"table",
"->",
"reload",
",",
"[",
"'atk_clear_filter'",
"=>",
"1",
"]",
")",
")",
";",
"$",
"this",
"->",
"table",
"->",
"setFilterColumn",
"(",
"$",
"names",
")",
";",
"return",
"$",
"this",
";",
"}"
] | An array of column name where filter is needed.
Leave empty to include all column in grid.
@param array|null $names An array with the name of column.
@throws Exception
@throws \atk4\core\Exception
@return $this | [
"An",
"array",
"of",
"column",
"name",
"where",
"filter",
"is",
"needed",
".",
"Leave",
"empty",
"to",
"include",
"all",
"column",
"in",
"grid",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Grid.php#L347-L353 | train |
atk4/ui | src/Grid.php | Grid.addDropdown | public function addDropdown($columnName, $items, $fx, $icon = 'caret square down', $menuId = null)
{
$column = $this->table->columns[$columnName];
if (!isset($column)) {
throw new Exception('The column where you want to add dropdown does not exist: '.$columnName);
}
if (!$menuId) {
$menuId = $columnName;
}
$column->addDropdown($items, function ($item) use ($fx) {
return call_user_func($fx, [$item]);
}, $icon, $menuId);
} | php | public function addDropdown($columnName, $items, $fx, $icon = 'caret square down', $menuId = null)
{
$column = $this->table->columns[$columnName];
if (!isset($column)) {
throw new Exception('The column where you want to add dropdown does not exist: '.$columnName);
}
if (!$menuId) {
$menuId = $columnName;
}
$column->addDropdown($items, function ($item) use ($fx) {
return call_user_func($fx, [$item]);
}, $icon, $menuId);
} | [
"public",
"function",
"addDropdown",
"(",
"$",
"columnName",
",",
"$",
"items",
",",
"$",
"fx",
",",
"$",
"icon",
"=",
"'caret square down'",
",",
"$",
"menuId",
"=",
"null",
")",
"{",
"$",
"column",
"=",
"$",
"this",
"->",
"table",
"->",
"columns",
"[",
"$",
"columnName",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"column",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'The column where you want to add dropdown does not exist: '",
".",
"$",
"columnName",
")",
";",
"}",
"if",
"(",
"!",
"$",
"menuId",
")",
"{",
"$",
"menuId",
"=",
"$",
"columnName",
";",
"}",
"$",
"column",
"->",
"addDropdown",
"(",
"$",
"items",
",",
"function",
"(",
"$",
"item",
")",
"use",
"(",
"$",
"fx",
")",
"{",
"return",
"call_user_func",
"(",
"$",
"fx",
",",
"[",
"$",
"item",
"]",
")",
";",
"}",
",",
"$",
"icon",
",",
"$",
"menuId",
")",
";",
"}"
] | Add a dropdown menu to header column.
@param string $columnName The name of column where to add dropdown.
@param array $items The menu items to add.
@param callable $fx The callback function to execute when an item is selected.
@param string $icon The icon.
@param string $menuId The menu id return by callback.
@throws Exception | [
"Add",
"a",
"dropdown",
"menu",
"to",
"header",
"column",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Grid.php#L366-L379 | train |
atk4/ui | src/Grid.php | Grid.addPopup | public function addPopup($columnName, $popup = null, $icon = 'caret square down')
{
$column = $this->table->columns[$columnName];
if (!isset($column)) {
throw new Exception('The column where you want to add popup does not exist: '.$columnName);
}
return $column->addPopup($popup, $icon);
} | php | public function addPopup($columnName, $popup = null, $icon = 'caret square down')
{
$column = $this->table->columns[$columnName];
if (!isset($column)) {
throw new Exception('The column where you want to add popup does not exist: '.$columnName);
}
return $column->addPopup($popup, $icon);
} | [
"public",
"function",
"addPopup",
"(",
"$",
"columnName",
",",
"$",
"popup",
"=",
"null",
",",
"$",
"icon",
"=",
"'caret square down'",
")",
"{",
"$",
"column",
"=",
"$",
"this",
"->",
"table",
"->",
"columns",
"[",
"$",
"columnName",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"column",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'The column where you want to add popup does not exist: '",
".",
"$",
"columnName",
")",
";",
"}",
"return",
"$",
"column",
"->",
"addPopup",
"(",
"$",
"popup",
",",
"$",
"icon",
")",
";",
"}"
] | Add a popup to header column.
@param string $columnName The name of column where to add popup.
@param Popup $popup Popup view.
@param string $icon The icon.
@throws Exception
@return mixed | [
"Add",
"a",
"popup",
"to",
"header",
"column",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Grid.php#L392-L400 | train |
atk4/ui | src/Grid.php | Grid.setModel | public function setModel(\atk4\data\Model $model, $columns = null)
{
$this->model = $this->table->setModel($model, $columns);
if ($this->quickSearch && is_array($this->quickSearch)) {
$this->addQuickSearch($this->quickSearch);
}
return $this->model;
} | php | public function setModel(\atk4\data\Model $model, $columns = null)
{
$this->model = $this->table->setModel($model, $columns);
if ($this->quickSearch && is_array($this->quickSearch)) {
$this->addQuickSearch($this->quickSearch);
}
return $this->model;
} | [
"public",
"function",
"setModel",
"(",
"\\",
"atk4",
"\\",
"data",
"\\",
"Model",
"$",
"model",
",",
"$",
"columns",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"model",
"=",
"$",
"this",
"->",
"table",
"->",
"setModel",
"(",
"$",
"model",
",",
"$",
"columns",
")",
";",
"if",
"(",
"$",
"this",
"->",
"quickSearch",
"&&",
"is_array",
"(",
"$",
"this",
"->",
"quickSearch",
")",
")",
"{",
"$",
"this",
"->",
"addQuickSearch",
"(",
"$",
"this",
"->",
"quickSearch",
")",
";",
"}",
"return",
"$",
"this",
"->",
"model",
";",
"}"
] | Sets data Model of Grid.
If $columns is not defined, then automatically will add columns for all
visible model fields. If $columns is set to false, then will not add
columns at all.
@param \atk4\data\Model $m Data model
@param array|bool $columns
@return \atk4\data\Model | [
"Sets",
"data",
"Model",
"of",
"Grid",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Grid.php#L481-L490 | train |
atk4/ui | src/Grid.php | Grid.addSelection | public function addSelection()
{
$this->selection = $this->table->addColumn(null, 'CheckBox');
// Move element to the beginning
$k = array_search($this->selection, $this->table->columns);
$this->table->columns = [$k => $this->table->columns[$k]] + $this->table->columns;
return $this->selection;
} | php | public function addSelection()
{
$this->selection = $this->table->addColumn(null, 'CheckBox');
// Move element to the beginning
$k = array_search($this->selection, $this->table->columns);
$this->table->columns = [$k => $this->table->columns[$k]] + $this->table->columns;
return $this->selection;
} | [
"public",
"function",
"addSelection",
"(",
")",
"{",
"$",
"this",
"->",
"selection",
"=",
"$",
"this",
"->",
"table",
"->",
"addColumn",
"(",
"null",
",",
"'CheckBox'",
")",
";",
"// Move element to the beginning",
"$",
"k",
"=",
"array_search",
"(",
"$",
"this",
"->",
"selection",
",",
"$",
"this",
"->",
"table",
"->",
"columns",
")",
";",
"$",
"this",
"->",
"table",
"->",
"columns",
"=",
"[",
"$",
"k",
"=>",
"$",
"this",
"->",
"table",
"->",
"columns",
"[",
"$",
"k",
"]",
"]",
"+",
"$",
"this",
"->",
"table",
"->",
"columns",
";",
"return",
"$",
"this",
"->",
"selection",
";",
"}"
] | Makes rows of this grid selectable by creating new column on the left with
checkboxes.
@return TableColumn\CheckBox | [
"Makes",
"rows",
"of",
"this",
"grid",
"selectable",
"by",
"creating",
"new",
"column",
"on",
"the",
"left",
"with",
"checkboxes",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Grid.php#L498-L507 | train |
atk4/ui | src/Grid.php | Grid.addDragHandler | public function addDragHandler()
{
$handler = $this->table->addColumn(null, 'DragHandler');
// Move last column to the beginning in table column array.
array_unshift($this->table->columns, array_pop($this->table->columns));
return $handler;
} | php | public function addDragHandler()
{
$handler = $this->table->addColumn(null, 'DragHandler');
// Move last column to the beginning in table column array.
array_unshift($this->table->columns, array_pop($this->table->columns));
return $handler;
} | [
"public",
"function",
"addDragHandler",
"(",
")",
"{",
"$",
"handler",
"=",
"$",
"this",
"->",
"table",
"->",
"addColumn",
"(",
"null",
",",
"'DragHandler'",
")",
";",
"// Move last column to the beginning in table column array.",
"array_unshift",
"(",
"$",
"this",
"->",
"table",
"->",
"columns",
",",
"array_pop",
"(",
"$",
"this",
"->",
"table",
"->",
"columns",
")",
")",
";",
"return",
"$",
"handler",
";",
"}"
] | Add column with drag handler on each row.
Drag handler allow to reorder table via drag n drop.
@return TableColumn\Generic | [
"Add",
"column",
"with",
"drag",
"handler",
"on",
"each",
"row",
".",
"Drag",
"handler",
"allow",
"to",
"reorder",
"table",
"via",
"drag",
"n",
"drop",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Grid.php#L515-L522 | train |
atk4/ui | src/Grid.php | Grid.setModelLimitFromPaginator | private function setModelLimitFromPaginator()
{
$this->paginator->setTotal(ceil($this->model->action('count')->getOne() / $this->ipp));
$this->model->setLimit($this->ipp, ($this->paginator->page - 1) * $this->ipp);
} | php | private function setModelLimitFromPaginator()
{
$this->paginator->setTotal(ceil($this->model->action('count')->getOne() / $this->ipp));
$this->model->setLimit($this->ipp, ($this->paginator->page - 1) * $this->ipp);
} | [
"private",
"function",
"setModelLimitFromPaginator",
"(",
")",
"{",
"$",
"this",
"->",
"paginator",
"->",
"setTotal",
"(",
"ceil",
"(",
"$",
"this",
"->",
"model",
"->",
"action",
"(",
"'count'",
")",
"->",
"getOne",
"(",
")",
"/",
"$",
"this",
"->",
"ipp",
")",
")",
";",
"$",
"this",
"->",
"model",
"->",
"setLimit",
"(",
"$",
"this",
"->",
"ipp",
",",
"(",
"$",
"this",
"->",
"paginator",
"->",
"page",
"-",
"1",
")",
"*",
"$",
"this",
"->",
"ipp",
")",
";",
"}"
] | Will set model limit according to paginator value.
@throws \atk4\data\Exception
@throws \atk4\dsql\Exception | [
"Will",
"set",
"model",
"limit",
"according",
"to",
"paginator",
"value",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Grid.php#L530-L534 | train |
atk4/ui | src/Grid.php | Grid.recursiveRender | public function recursiveRender()
{
// bind with paginator
if ($this->paginator) {
$this->setModelLimitFromPaginator();
}
if ($this->quickSearch instanceof jsSearch) {
if ($sortBy = $this->getSortBy()) {
$this->container->js(true, $this->quickSearch->js()->atkJsSearch('setUrlArgs', [$this->name.'_sort', $sortBy]));
}
}
return parent::recursiveRender();
} | php | public function recursiveRender()
{
// bind with paginator
if ($this->paginator) {
$this->setModelLimitFromPaginator();
}
if ($this->quickSearch instanceof jsSearch) {
if ($sortBy = $this->getSortBy()) {
$this->container->js(true, $this->quickSearch->js()->atkJsSearch('setUrlArgs', [$this->name.'_sort', $sortBy]));
}
}
return parent::recursiveRender();
} | [
"public",
"function",
"recursiveRender",
"(",
")",
"{",
"// bind with paginator",
"if",
"(",
"$",
"this",
"->",
"paginator",
")",
"{",
"$",
"this",
"->",
"setModelLimitFromPaginator",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"quickSearch",
"instanceof",
"jsSearch",
")",
"{",
"if",
"(",
"$",
"sortBy",
"=",
"$",
"this",
"->",
"getSortBy",
"(",
")",
")",
"{",
"$",
"this",
"->",
"container",
"->",
"js",
"(",
"true",
",",
"$",
"this",
"->",
"quickSearch",
"->",
"js",
"(",
")",
"->",
"atkJsSearch",
"(",
"'setUrlArgs'",
",",
"[",
"$",
"this",
"->",
"name",
".",
"'_sort'",
",",
"$",
"sortBy",
"]",
")",
")",
";",
"}",
"}",
"return",
"parent",
"::",
"recursiveRender",
"(",
")",
";",
"}"
] | Recursively renders view. | [
"Recursively",
"renders",
"view",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Grid.php#L552-L566 | train |
atk4/ui | src/ItemsPerPageSelector.php | ItemsPerPageSelector.onPageLengthSelect | public function onPageLengthSelect($fx = null)
{
if (is_callable($fx)) {
if ($this->cb->triggered()) {
$this->cb->set(function () use ($fx) {
$ipp = @$_GET['ipp'];
//$this->pageLength->set(preg_replace("/\[ipp\]/", $ipp, $this->label));
$this->set($ipp);
$reload = call_user_func($fx, $ipp);
if ($reload) {
$this->app->terminate($reload->renderJSON());
}
});
}
}
} | php | public function onPageLengthSelect($fx = null)
{
if (is_callable($fx)) {
if ($this->cb->triggered()) {
$this->cb->set(function () use ($fx) {
$ipp = @$_GET['ipp'];
//$this->pageLength->set(preg_replace("/\[ipp\]/", $ipp, $this->label));
$this->set($ipp);
$reload = call_user_func($fx, $ipp);
if ($reload) {
$this->app->terminate($reload->renderJSON());
}
});
}
}
} | [
"public",
"function",
"onPageLengthSelect",
"(",
"$",
"fx",
"=",
"null",
")",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"fx",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"cb",
"->",
"triggered",
"(",
")",
")",
"{",
"$",
"this",
"->",
"cb",
"->",
"set",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"fx",
")",
"{",
"$",
"ipp",
"=",
"@",
"$",
"_GET",
"[",
"'ipp'",
"]",
";",
"//$this->pageLength->set(preg_replace(\"/\\[ipp\\]/\", $ipp, $this->label));",
"$",
"this",
"->",
"set",
"(",
"$",
"ipp",
")",
";",
"$",
"reload",
"=",
"call_user_func",
"(",
"$",
"fx",
",",
"$",
"ipp",
")",
";",
"if",
"(",
"$",
"reload",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"terminate",
"(",
"$",
"reload",
"->",
"renderJSON",
"(",
")",
")",
";",
"}",
"}",
")",
";",
"}",
"}",
"}"
] | Run callback when an item is select via dropdown menu.
The callback should return a View to be reload after an item
has been select.
@param null $fx | [
"Run",
"callback",
"when",
"an",
"item",
"is",
"select",
"via",
"dropdown",
"menu",
".",
"The",
"callback",
"should",
"return",
"a",
"View",
"to",
"be",
"reload",
"after",
"an",
"item",
"has",
"been",
"select",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/ItemsPerPageSelector.php#L78-L93 | train |
atk4/ui | src/App.php | App.isJsonRequest | protected function isJsonRequest()
{
$ajax = false;
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH'])
&& strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$ajax = true;
}
return $ajax && !isset($_GET['__atk_tab']);
} | php | protected function isJsonRequest()
{
$ajax = false;
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH'])
&& strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$ajax = true;
}
return $ajax && !isset($_GET['__atk_tab']);
} | [
"protected",
"function",
"isJsonRequest",
"(",
")",
"{",
"$",
"ajax",
"=",
"false",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"_SERVER",
"[",
"'HTTP_X_REQUESTED_WITH'",
"]",
")",
"&&",
"strtolower",
"(",
"$",
"_SERVER",
"[",
"'HTTP_X_REQUESTED_WITH'",
"]",
")",
"==",
"'xmlhttprequest'",
")",
"{",
"$",
"ajax",
"=",
"true",
";",
"}",
"return",
"$",
"ajax",
"&&",
"!",
"isset",
"(",
"$",
"_GET",
"[",
"'__atk_tab'",
"]",
")",
";",
"}"
] | Most of the ajax request will require sending exception in json
instead of html, except for tab.
@return bool | [
"Most",
"of",
"the",
"ajax",
"request",
"will",
"require",
"sending",
"exception",
"in",
"json",
"instead",
"of",
"html",
"except",
"for",
"tab",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/App.php#L269-L279 | train |
atk4/ui | src/App.php | App.terminate | public function terminate($output = null)
{
if ($output !== null) {
echo $output;
}
$this->run_called = true; // prevent shutdown function from triggering.
$this->callExit();
} | php | public function terminate($output = null)
{
if ($output !== null) {
echo $output;
}
$this->run_called = true; // prevent shutdown function from triggering.
$this->callExit();
} | [
"public",
"function",
"terminate",
"(",
"$",
"output",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"output",
"!==",
"null",
")",
"{",
"echo",
"$",
"output",
";",
"}",
"$",
"this",
"->",
"run_called",
"=",
"true",
";",
"// prevent shutdown function from triggering.",
"$",
"this",
"->",
"callExit",
"(",
")",
";",
"}"
] | Will perform a preemptive output and terminate. Do not use this
directly, instead call it form Callback, jsCallback or similar
other classes.
@param string $output | [
"Will",
"perform",
"a",
"preemptive",
"output",
"and",
"terminate",
".",
"Do",
"not",
"use",
"this",
"directly",
"instead",
"call",
"it",
"form",
"Callback",
"jsCallback",
"or",
"similar",
"other",
"classes",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/App.php#L298-L305 | train |
atk4/ui | src/App.php | App.initLayout | public function initLayout($seed)
{
$layout = $this->factory($seed, null, 'Layout');
$layout->app = $this;
if (!$this->html) {
$this->html = new View(['defaultTemplate' => 'html.html']);
$this->html->app = $this;
$this->html->init();
}
$this->layout = $this->html->add($layout);
$this->initIncludes();
return $this;
} | php | public function initLayout($seed)
{
$layout = $this->factory($seed, null, 'Layout');
$layout->app = $this;
if (!$this->html) {
$this->html = new View(['defaultTemplate' => 'html.html']);
$this->html->app = $this;
$this->html->init();
}
$this->layout = $this->html->add($layout);
$this->initIncludes();
return $this;
} | [
"public",
"function",
"initLayout",
"(",
"$",
"seed",
")",
"{",
"$",
"layout",
"=",
"$",
"this",
"->",
"factory",
"(",
"$",
"seed",
",",
"null",
",",
"'Layout'",
")",
";",
"$",
"layout",
"->",
"app",
"=",
"$",
"this",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"html",
")",
"{",
"$",
"this",
"->",
"html",
"=",
"new",
"View",
"(",
"[",
"'defaultTemplate'",
"=>",
"'html.html'",
"]",
")",
";",
"$",
"this",
"->",
"html",
"->",
"app",
"=",
"$",
"this",
";",
"$",
"this",
"->",
"html",
"->",
"init",
"(",
")",
";",
"}",
"$",
"this",
"->",
"layout",
"=",
"$",
"this",
"->",
"html",
"->",
"add",
"(",
"$",
"layout",
")",
";",
"$",
"this",
"->",
"initIncludes",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Initializes layout.
@param string|Layout\Generic|array $seed
@return $this | [
"Initializes",
"layout",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/App.php#L314-L330 | train |
atk4/ui | src/App.php | App.initIncludes | public function initIncludes()
{
// jQuery
$url = isset($this->cdn['jquery']) ? $this->cdn['jquery'] : '../public';
$this->requireJS($url.'/jquery.min.js');
// Semantic UI
$url = isset($this->cdn['semantic-ui']) ? $this->cdn['semantic-ui'] : '../public';
$this->requireJS($url.'/semantic.min.js');
$this->requireCSS($url.'/semantic.min.css');
// Serialize Object
$url = isset($this->cdn['serialize-object']) ? $this->cdn['serialize-object'] : '../public';
$this->requireJS($url.'/jquery.serialize-object.min.js');
// Agile UI
$url = isset($this->cdn['atk']) ? $this->cdn['atk'] : '../public';
$this->requireJS($url.'/atkjs-ui.min.js');
$this->requireCSS($url.'/agileui.css');
} | php | public function initIncludes()
{
// jQuery
$url = isset($this->cdn['jquery']) ? $this->cdn['jquery'] : '../public';
$this->requireJS($url.'/jquery.min.js');
// Semantic UI
$url = isset($this->cdn['semantic-ui']) ? $this->cdn['semantic-ui'] : '../public';
$this->requireJS($url.'/semantic.min.js');
$this->requireCSS($url.'/semantic.min.css');
// Serialize Object
$url = isset($this->cdn['serialize-object']) ? $this->cdn['serialize-object'] : '../public';
$this->requireJS($url.'/jquery.serialize-object.min.js');
// Agile UI
$url = isset($this->cdn['atk']) ? $this->cdn['atk'] : '../public';
$this->requireJS($url.'/atkjs-ui.min.js');
$this->requireCSS($url.'/agileui.css');
} | [
"public",
"function",
"initIncludes",
"(",
")",
"{",
"// jQuery",
"$",
"url",
"=",
"isset",
"(",
"$",
"this",
"->",
"cdn",
"[",
"'jquery'",
"]",
")",
"?",
"$",
"this",
"->",
"cdn",
"[",
"'jquery'",
"]",
":",
"'../public'",
";",
"$",
"this",
"->",
"requireJS",
"(",
"$",
"url",
".",
"'/jquery.min.js'",
")",
";",
"// Semantic UI",
"$",
"url",
"=",
"isset",
"(",
"$",
"this",
"->",
"cdn",
"[",
"'semantic-ui'",
"]",
")",
"?",
"$",
"this",
"->",
"cdn",
"[",
"'semantic-ui'",
"]",
":",
"'../public'",
";",
"$",
"this",
"->",
"requireJS",
"(",
"$",
"url",
".",
"'/semantic.min.js'",
")",
";",
"$",
"this",
"->",
"requireCSS",
"(",
"$",
"url",
".",
"'/semantic.min.css'",
")",
";",
"// Serialize Object",
"$",
"url",
"=",
"isset",
"(",
"$",
"this",
"->",
"cdn",
"[",
"'serialize-object'",
"]",
")",
"?",
"$",
"this",
"->",
"cdn",
"[",
"'serialize-object'",
"]",
":",
"'../public'",
";",
"$",
"this",
"->",
"requireJS",
"(",
"$",
"url",
".",
"'/jquery.serialize-object.min.js'",
")",
";",
"// Agile UI",
"$",
"url",
"=",
"isset",
"(",
"$",
"this",
"->",
"cdn",
"[",
"'atk'",
"]",
")",
"?",
"$",
"this",
"->",
"cdn",
"[",
"'atk'",
"]",
":",
"'../public'",
";",
"$",
"this",
"->",
"requireJS",
"(",
"$",
"url",
".",
"'/atkjs-ui.min.js'",
")",
";",
"$",
"this",
"->",
"requireCSS",
"(",
"$",
"url",
".",
"'/agileui.css'",
")",
";",
"}"
] | Initialize JS and CSS includes. | [
"Initialize",
"JS",
"and",
"CSS",
"includes",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/App.php#L335-L354 | train |
atk4/ui | src/App.php | App.add | public function add($seed, $region = null)
{
if (!$this->layout) {
throw new Exception(['If you use $app->add() you should first call $app->setLayout()']);
}
return $this->layout->add($seed, $region);
} | php | public function add($seed, $region = null)
{
if (!$this->layout) {
throw new Exception(['If you use $app->add() you should first call $app->setLayout()']);
}
return $this->layout->add($seed, $region);
} | [
"public",
"function",
"add",
"(",
"$",
"seed",
",",
"$",
"region",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"layout",
")",
"{",
"throw",
"new",
"Exception",
"(",
"[",
"'If you use $app->add() you should first call $app->setLayout()'",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"layout",
"->",
"add",
"(",
"$",
"seed",
",",
"$",
"region",
")",
";",
"}"
] | Add a new object into the app. You will need to have Layout first.
@param mixed $seed New object to add
@param string $region
@return object | [
"Add",
"a",
"new",
"object",
"into",
"the",
"app",
".",
"You",
"will",
"need",
"to",
"have",
"Layout",
"first",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/App.php#L390-L397 | train |
atk4/ui | src/App.php | App.run | public function run()
{
$this->run_called = true;
$this->hook('beforeRender');
$this->is_rendering = true;
// if no App layout set
if (!isset($this->html)) {
throw new Exception(['App layout should be set.']);
}
$this->html->template->set('title', $this->title);
$this->html->renderAll();
$this->html->template->appendHTML('HEAD', $this->html->getJS());
$this->is_rendering = false;
$this->hook('beforeOutput');
if (isset($_GET['__atk_callback']) && $this->catch_runaway_callbacks) {
$this->terminate('!! Callback requested, but never reached. You may be missing some arguments in '.$_SERVER['REQUEST_URI']);
}
echo $this->html->template->render();
} | php | public function run()
{
$this->run_called = true;
$this->hook('beforeRender');
$this->is_rendering = true;
// if no App layout set
if (!isset($this->html)) {
throw new Exception(['App layout should be set.']);
}
$this->html->template->set('title', $this->title);
$this->html->renderAll();
$this->html->template->appendHTML('HEAD', $this->html->getJS());
$this->is_rendering = false;
$this->hook('beforeOutput');
if (isset($_GET['__atk_callback']) && $this->catch_runaway_callbacks) {
$this->terminate('!! Callback requested, but never reached. You may be missing some arguments in '.$_SERVER['REQUEST_URI']);
}
echo $this->html->template->render();
} | [
"public",
"function",
"run",
"(",
")",
"{",
"$",
"this",
"->",
"run_called",
"=",
"true",
";",
"$",
"this",
"->",
"hook",
"(",
"'beforeRender'",
")",
";",
"$",
"this",
"->",
"is_rendering",
"=",
"true",
";",
"// if no App layout set",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"html",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"[",
"'App layout should be set.'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"html",
"->",
"template",
"->",
"set",
"(",
"'title'",
",",
"$",
"this",
"->",
"title",
")",
";",
"$",
"this",
"->",
"html",
"->",
"renderAll",
"(",
")",
";",
"$",
"this",
"->",
"html",
"->",
"template",
"->",
"appendHTML",
"(",
"'HEAD'",
",",
"$",
"this",
"->",
"html",
"->",
"getJS",
"(",
")",
")",
";",
"$",
"this",
"->",
"is_rendering",
"=",
"false",
";",
"$",
"this",
"->",
"hook",
"(",
"'beforeOutput'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"_GET",
"[",
"'__atk_callback'",
"]",
")",
"&&",
"$",
"this",
"->",
"catch_runaway_callbacks",
")",
"{",
"$",
"this",
"->",
"terminate",
"(",
"'!! Callback requested, but never reached. You may be missing some arguments in '",
".",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
")",
";",
"}",
"echo",
"$",
"this",
"->",
"html",
"->",
"template",
"->",
"render",
"(",
")",
";",
"}"
] | Runs app and echo rendered template. | [
"Runs",
"app",
"and",
"echo",
"rendered",
"template",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/App.php#L402-L424 | train |
atk4/ui | src/App.php | App.loadTemplate | public function loadTemplate($name)
{
$template = new Template();
$template->app = $this;
if (in_array($name[0], ['.', '/', '\\']) || strpos($name, ':\\') !== false) {
return $template->load($name);
} else {
$dir = is_array($this->template_dir) ? $this->template_dir : [$this->template_dir];
foreach ($dir as $td) {
if ($t = $template->tryLoad($td.'/'.$name)) {
return $t;
}
}
}
throw new Exception(['Can not find template file', 'name'=>$name, 'template_dir'=>$this->template_dir]);
} | php | public function loadTemplate($name)
{
$template = new Template();
$template->app = $this;
if (in_array($name[0], ['.', '/', '\\']) || strpos($name, ':\\') !== false) {
return $template->load($name);
} else {
$dir = is_array($this->template_dir) ? $this->template_dir : [$this->template_dir];
foreach ($dir as $td) {
if ($t = $template->tryLoad($td.'/'.$name)) {
return $t;
}
}
}
throw new Exception(['Can not find template file', 'name'=>$name, 'template_dir'=>$this->template_dir]);
} | [
"public",
"function",
"loadTemplate",
"(",
"$",
"name",
")",
"{",
"$",
"template",
"=",
"new",
"Template",
"(",
")",
";",
"$",
"template",
"->",
"app",
"=",
"$",
"this",
";",
"if",
"(",
"in_array",
"(",
"$",
"name",
"[",
"0",
"]",
",",
"[",
"'.'",
",",
"'/'",
",",
"'\\\\'",
"]",
")",
"||",
"strpos",
"(",
"$",
"name",
",",
"':\\\\'",
")",
"!==",
"false",
")",
"{",
"return",
"$",
"template",
"->",
"load",
"(",
"$",
"name",
")",
";",
"}",
"else",
"{",
"$",
"dir",
"=",
"is_array",
"(",
"$",
"this",
"->",
"template_dir",
")",
"?",
"$",
"this",
"->",
"template_dir",
":",
"[",
"$",
"this",
"->",
"template_dir",
"]",
";",
"foreach",
"(",
"$",
"dir",
"as",
"$",
"td",
")",
"{",
"if",
"(",
"$",
"t",
"=",
"$",
"template",
"->",
"tryLoad",
"(",
"$",
"td",
".",
"'/'",
".",
"$",
"name",
")",
")",
"{",
"return",
"$",
"t",
";",
"}",
"}",
"}",
"throw",
"new",
"Exception",
"(",
"[",
"'Can not find template file'",
",",
"'name'",
"=>",
"$",
"name",
",",
"'template_dir'",
"=>",
"$",
"this",
"->",
"template_dir",
"]",
")",
";",
"}"
] | Load template by template file name.
@param string $name
@throws Exception
@return Template | [
"Load",
"template",
"by",
"template",
"file",
"name",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/App.php#L443-L460 | train |
atk4/ui | src/App.php | App.jsURL | public function jsURL($page = [], $needRequestUri = false, $extra_args = [])
{
return $this->url($page, $needRequestUri, $extra_args);
} | php | public function jsURL($page = [], $needRequestUri = false, $extra_args = [])
{
return $this->url($page, $needRequestUri, $extra_args);
} | [
"public",
"function",
"jsURL",
"(",
"$",
"page",
"=",
"[",
"]",
",",
"$",
"needRequestUri",
"=",
"false",
",",
"$",
"extra_args",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"url",
"(",
"$",
"page",
",",
"$",
"needRequestUri",
",",
"$",
"extra_args",
")",
";",
"}"
] | Build a URL that application can use for js call-backs. Some framework integration will use a different routing
mechanism for NON-HTML response.
@param array|string $page URL as string or array with page name as first element and other GET arguments
@param bool $needRequestUri Simply return $_SERVER['REQUEST_URI'] if needed
@param array $extra_args Additional URL arguments
@return string | [
"Build",
"a",
"URL",
"that",
"application",
"can",
"use",
"for",
"js",
"call",
"-",
"backs",
".",
"Some",
"framework",
"integration",
"will",
"use",
"a",
"different",
"routing",
"mechanism",
"for",
"NON",
"-",
"HTML",
"response",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/App.php#L512-L515 | train |
atk4/ui | src/App.php | App.url | public function url($page = [], $needRequestUri = false, $extra_args = [])
{
if ($needRequestUri) {
return $_SERVER['REQUEST_URI'];
}
$sticky = $this->sticky_get_arguments;
$result = $extra_args;
if ($this->page === null) {
$uri = $this->getRequestURI();
if (substr($uri, -1, 1) == '/') {
$this->page = 'index';
} else {
$this->page = basename($uri, '.php');
}
}
// if page passed as string, then simply use it
if (is_string($page)) {
return $page;
}
// use current page by default
if (!isset($page[0])) {
$page[0] = $this->page;
}
//add sticky arguments
if (is_array($sticky) && !empty($sticky)) {
foreach ($sticky as $key => $val) {
if ($val === true) {
if (isset($_GET[$key])) {
$val = $_GET[$key];
} else {
continue;
}
}
if (!isset($result[$key])) {
$result[$key] = $val;
}
}
}
// add arguments
foreach ($page as $arg => $val) {
if ($arg === 0) {
continue;
}
if ($val === null || $val === false) {
unset($result[$arg]);
} else {
$result[$arg] = $val;
}
}
// put URL together
$args = http_build_query($result);
$url = ($page[0] ? $page[0].'.php' : '').($args ? '?'.$args : '');
return $url;
} | php | public function url($page = [], $needRequestUri = false, $extra_args = [])
{
if ($needRequestUri) {
return $_SERVER['REQUEST_URI'];
}
$sticky = $this->sticky_get_arguments;
$result = $extra_args;
if ($this->page === null) {
$uri = $this->getRequestURI();
if (substr($uri, -1, 1) == '/') {
$this->page = 'index';
} else {
$this->page = basename($uri, '.php');
}
}
// if page passed as string, then simply use it
if (is_string($page)) {
return $page;
}
// use current page by default
if (!isset($page[0])) {
$page[0] = $this->page;
}
//add sticky arguments
if (is_array($sticky) && !empty($sticky)) {
foreach ($sticky as $key => $val) {
if ($val === true) {
if (isset($_GET[$key])) {
$val = $_GET[$key];
} else {
continue;
}
}
if (!isset($result[$key])) {
$result[$key] = $val;
}
}
}
// add arguments
foreach ($page as $arg => $val) {
if ($arg === 0) {
continue;
}
if ($val === null || $val === false) {
unset($result[$arg]);
} else {
$result[$arg] = $val;
}
}
// put URL together
$args = http_build_query($result);
$url = ($page[0] ? $page[0].'.php' : '').($args ? '?'.$args : '');
return $url;
} | [
"public",
"function",
"url",
"(",
"$",
"page",
"=",
"[",
"]",
",",
"$",
"needRequestUri",
"=",
"false",
",",
"$",
"extra_args",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"needRequestUri",
")",
"{",
"return",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
";",
"}",
"$",
"sticky",
"=",
"$",
"this",
"->",
"sticky_get_arguments",
";",
"$",
"result",
"=",
"$",
"extra_args",
";",
"if",
"(",
"$",
"this",
"->",
"page",
"===",
"null",
")",
"{",
"$",
"uri",
"=",
"$",
"this",
"->",
"getRequestURI",
"(",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"uri",
",",
"-",
"1",
",",
"1",
")",
"==",
"'/'",
")",
"{",
"$",
"this",
"->",
"page",
"=",
"'index'",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"page",
"=",
"basename",
"(",
"$",
"uri",
",",
"'.php'",
")",
";",
"}",
"}",
"// if page passed as string, then simply use it",
"if",
"(",
"is_string",
"(",
"$",
"page",
")",
")",
"{",
"return",
"$",
"page",
";",
"}",
"// use current page by default",
"if",
"(",
"!",
"isset",
"(",
"$",
"page",
"[",
"0",
"]",
")",
")",
"{",
"$",
"page",
"[",
"0",
"]",
"=",
"$",
"this",
"->",
"page",
";",
"}",
"//add sticky arguments",
"if",
"(",
"is_array",
"(",
"$",
"sticky",
")",
"&&",
"!",
"empty",
"(",
"$",
"sticky",
")",
")",
"{",
"foreach",
"(",
"$",
"sticky",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"$",
"val",
"===",
"true",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_GET",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"val",
"=",
"$",
"_GET",
"[",
"$",
"key",
"]",
";",
"}",
"else",
"{",
"continue",
";",
"}",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"result",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"result",
"[",
"$",
"key",
"]",
"=",
"$",
"val",
";",
"}",
"}",
"}",
"// add arguments",
"foreach",
"(",
"$",
"page",
"as",
"$",
"arg",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"$",
"arg",
"===",
"0",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"val",
"===",
"null",
"||",
"$",
"val",
"===",
"false",
")",
"{",
"unset",
"(",
"$",
"result",
"[",
"$",
"arg",
"]",
")",
";",
"}",
"else",
"{",
"$",
"result",
"[",
"$",
"arg",
"]",
"=",
"$",
"val",
";",
"}",
"}",
"// put URL together",
"$",
"args",
"=",
"http_build_query",
"(",
"$",
"result",
")",
";",
"$",
"url",
"=",
"(",
"$",
"page",
"[",
"0",
"]",
"?",
"$",
"page",
"[",
"0",
"]",
".",
"'.php'",
":",
"''",
")",
".",
"(",
"$",
"args",
"?",
"'?'",
".",
"$",
"args",
":",
"''",
")",
";",
"return",
"$",
"url",
";",
"}"
] | Build a URL that application can use for loading HTML data.
@param array|string $page URL as string or array with page name as first element and other GET arguments
@param bool $needRequestUri Simply return $_SERVER['REQUEST_URI'] if needed
@param array $extra_args Additional URL arguments
@return string | [
"Build",
"a",
"URL",
"that",
"application",
"can",
"use",
"for",
"loading",
"HTML",
"data",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/App.php#L526-L589 | train |
atk4/ui | src/App.php | App.stickyGet | public function stickyGet($name)
{
if (isset($_GET[$name])) {
$this->sticky_get_arguments[$name] = $_GET[$name];
return $_GET[$name];
}
} | php | public function stickyGet($name)
{
if (isset($_GET[$name])) {
$this->sticky_get_arguments[$name] = $_GET[$name];
return $_GET[$name];
}
} | [
"public",
"function",
"stickyGet",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_GET",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"this",
"->",
"sticky_get_arguments",
"[",
"$",
"name",
"]",
"=",
"$",
"_GET",
"[",
"$",
"name",
"]",
";",
"return",
"$",
"_GET",
"[",
"$",
"name",
"]",
";",
"}",
"}"
] | Make current get argument with specified name automatically appended to all generated URLs.
@param string $name
@return string|null | [
"Make",
"current",
"get",
"argument",
"with",
"specified",
"name",
"automatically",
"appended",
"to",
"all",
"generated",
"URLs",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/App.php#L598-L605 | train |
atk4/ui | src/App.php | App.requireJS | public function requireJS($url, $isAsync = false, $isDefer = false)
{
$this->html->template->appendHTML('HEAD', $this->getTag('script', ['src' => $url, 'defer' => $isDefer, 'async' => $isAsync], '')."\n");
return $this;
} | php | public function requireJS($url, $isAsync = false, $isDefer = false)
{
$this->html->template->appendHTML('HEAD', $this->getTag('script', ['src' => $url, 'defer' => $isDefer, 'async' => $isAsync], '')."\n");
return $this;
} | [
"public",
"function",
"requireJS",
"(",
"$",
"url",
",",
"$",
"isAsync",
"=",
"false",
",",
"$",
"isDefer",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"html",
"->",
"template",
"->",
"appendHTML",
"(",
"'HEAD'",
",",
"$",
"this",
"->",
"getTag",
"(",
"'script'",
",",
"[",
"'src'",
"=>",
"$",
"url",
",",
"'defer'",
"=>",
"$",
"isDefer",
",",
"'async'",
"=>",
"$",
"isAsync",
"]",
",",
"''",
")",
".",
"\"\\n\"",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Adds additional JS script include in aplication template.
@param string $url
@param bool $isAsync Whether or not you want Async loading.
@param bool $isDefer Whether or not you want Defer loading.
@return $this | [
"Adds",
"additional",
"JS",
"script",
"include",
"in",
"aplication",
"template",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/App.php#L631-L636 | train |
atk4/ui | src/App.php | App.requireCSS | public function requireCSS($url)
{
$this->html->template->appendHTML('HEAD', $this->getTag('link/', ['rel' => 'stylesheet', 'type' => 'text/css', 'href' => $url])."\n");
return $this;
} | php | public function requireCSS($url)
{
$this->html->template->appendHTML('HEAD', $this->getTag('link/', ['rel' => 'stylesheet', 'type' => 'text/css', 'href' => $url])."\n");
return $this;
} | [
"public",
"function",
"requireCSS",
"(",
"$",
"url",
")",
"{",
"$",
"this",
"->",
"html",
"->",
"template",
"->",
"appendHTML",
"(",
"'HEAD'",
",",
"$",
"this",
"->",
"getTag",
"(",
"'link/'",
",",
"[",
"'rel'",
"=>",
"'stylesheet'",
",",
"'type'",
"=>",
"'text/css'",
",",
"'href'",
"=>",
"$",
"url",
"]",
")",
".",
"\"\\n\"",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Adds additional CSS stylesheet include in aplication template.
@param string $url
@return $this | [
"Adds",
"additional",
"CSS",
"stylesheet",
"include",
"in",
"aplication",
"template",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/App.php#L645-L650 | train |
atk4/ui | src/App.php | App.redirect | public function redirect($page)
{
header('Location: '.$this->url($page));
$this->run_called = true; // prevent shutdown function from triggering.
$this->callExit();
} | php | public function redirect($page)
{
header('Location: '.$this->url($page));
$this->run_called = true; // prevent shutdown function from triggering.
$this->callExit();
} | [
"public",
"function",
"redirect",
"(",
"$",
"page",
")",
"{",
"header",
"(",
"'Location: '",
".",
"$",
"this",
"->",
"url",
"(",
"$",
"page",
")",
")",
";",
"$",
"this",
"->",
"run_called",
"=",
"true",
";",
"// prevent shutdown function from triggering.",
"$",
"this",
"->",
"callExit",
"(",
")",
";",
"}"
] | A convenient wrapper for sending user to another page.
@param array|string $page Destination page | [
"A",
"convenient",
"wrapper",
"for",
"sending",
"user",
"to",
"another",
"page",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/App.php#L657-L663 | train |
atk4/ui | src/App.php | App.useSuiVue | public function useSuiVue()
{
if (!$this->is_sui_init) {
$this->requireJS('https://unpkg.com/semantic-ui-vue/dist/umd/semantic-ui-vue.min.js');
$this->layout->js(true, (new jsVueService())->useComponent('SemanticUIVue'));
$this->is_sui_init = true;
}
} | php | public function useSuiVue()
{
if (!$this->is_sui_init) {
$this->requireJS('https://unpkg.com/semantic-ui-vue/dist/umd/semantic-ui-vue.min.js');
$this->layout->js(true, (new jsVueService())->useComponent('SemanticUIVue'));
$this->is_sui_init = true;
}
} | [
"public",
"function",
"useSuiVue",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"is_sui_init",
")",
"{",
"$",
"this",
"->",
"requireJS",
"(",
"'https://unpkg.com/semantic-ui-vue/dist/umd/semantic-ui-vue.min.js'",
")",
";",
"$",
"this",
"->",
"layout",
"->",
"js",
"(",
"true",
",",
"(",
"new",
"jsVueService",
"(",
")",
")",
"->",
"useComponent",
"(",
"'SemanticUIVue'",
")",
")",
";",
"$",
"this",
"->",
"is_sui_init",
"=",
"true",
";",
"}",
"}"
] | Allow to use semantic-ui-vue components.
https://semantic-ui-vue.github.io | [
"Allow",
"to",
"use",
"semantic",
"-",
"ui",
"-",
"vue",
"components",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/App.php#L852-L859 | train |
atk4/ui | src/CallbackLater.php | CallbackLater.set | public function set($callback, $args = [])
{
if (!$this->app) {
throw new Exception(['Call-back must be part of a RenderTree']);
}
if ($this->app->is_rendering) {
return parent::set($callback, $args);
}
$this->app->addHook('beforeRender', function (...$args) use ($callback) {
array_shift($args); // Hook will have first argument pointing to the app. We don't need that.
return parent::set($callback, $args);
}, $args);
} | php | public function set($callback, $args = [])
{
if (!$this->app) {
throw new Exception(['Call-back must be part of a RenderTree']);
}
if ($this->app->is_rendering) {
return parent::set($callback, $args);
}
$this->app->addHook('beforeRender', function (...$args) use ($callback) {
array_shift($args); // Hook will have first argument pointing to the app. We don't need that.
return parent::set($callback, $args);
}, $args);
} | [
"public",
"function",
"set",
"(",
"$",
"callback",
",",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"app",
")",
"{",
"throw",
"new",
"Exception",
"(",
"[",
"'Call-back must be part of a RenderTree'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"app",
"->",
"is_rendering",
")",
"{",
"return",
"parent",
"::",
"set",
"(",
"$",
"callback",
",",
"$",
"args",
")",
";",
"}",
"$",
"this",
"->",
"app",
"->",
"addHook",
"(",
"'beforeRender'",
",",
"function",
"(",
"...",
"$",
"args",
")",
"use",
"(",
"$",
"callback",
")",
"{",
"array_shift",
"(",
"$",
"args",
")",
";",
"// Hook will have first argument pointing to the app. We don't need that.",
"return",
"parent",
"::",
"set",
"(",
"$",
"callback",
",",
"$",
"args",
")",
";",
"}",
",",
"$",
"args",
")",
";",
"}"
] | Executes user-specified action before rendering or if App is
already in rendering state, then before output.
@param callable $callback
@param array $args
@return mixed|null | [
"Executes",
"user",
"-",
"specified",
"action",
"before",
"rendering",
"or",
"if",
"App",
"is",
"already",
"in",
"rendering",
"state",
"then",
"before",
"output",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/CallbackLater.php#L22-L36 | train |
atk4/ui | src/Tab.php | Tab.setPath | public function setPath($path)
{
if (!is_string($path)) {
$path = $this->app->url($path);
}
$this->path = $path.'#';
return $this;
} | php | public function setPath($path)
{
if (!is_string($path)) {
$path = $this->app->url($path);
}
$this->path = $path.'#';
return $this;
} | [
"public",
"function",
"setPath",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"path",
")",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"app",
"->",
"url",
"(",
"$",
"path",
")",
";",
"}",
"$",
"this",
"->",
"path",
"=",
"$",
"path",
".",
"'#'",
";",
"return",
"$",
"this",
";",
"}"
] | Sets path for tab.
@param string $path
@return $this | [
"Sets",
"path",
"for",
"tab",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Tab.php#L22-L30 | train |
atk4/ui | src/Tab.php | Tab.renderView | public function renderView()
{
if ($this->path) {
$this->js(true)->tab(
['cache' => false, 'auto' => true, 'path' => $this->path, 'apiSettings' => ['data' => ['__atk_tab' => 1]]]
);
} else {
$this->js(true)->tab();
}
if ($this->owner->activeTabName == $this->name) {
$this->js(true)->click();
}
parent::renderView();
} | php | public function renderView()
{
if ($this->path) {
$this->js(true)->tab(
['cache' => false, 'auto' => true, 'path' => $this->path, 'apiSettings' => ['data' => ['__atk_tab' => 1]]]
);
} else {
$this->js(true)->tab();
}
if ($this->owner->activeTabName == $this->name) {
$this->js(true)->click();
}
parent::renderView();
} | [
"public",
"function",
"renderView",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"path",
")",
"{",
"$",
"this",
"->",
"js",
"(",
"true",
")",
"->",
"tab",
"(",
"[",
"'cache'",
"=>",
"false",
",",
"'auto'",
"=>",
"true",
",",
"'path'",
"=>",
"$",
"this",
"->",
"path",
",",
"'apiSettings'",
"=>",
"[",
"'data'",
"=>",
"[",
"'__atk_tab'",
"=>",
"1",
"]",
"]",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"js",
"(",
"true",
")",
"->",
"tab",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"owner",
"->",
"activeTabName",
"==",
"$",
"this",
"->",
"name",
")",
"{",
"$",
"this",
"->",
"js",
"(",
"true",
")",
"->",
"click",
"(",
")",
";",
"}",
"parent",
"::",
"renderView",
"(",
")",
";",
"}"
] | Rendering one tab view. | [
"Rendering",
"one",
"tab",
"view",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Tab.php#L35-L50 | train |
atk4/ui | src/View.php | View.setSource | public function setSource(array $data, $fields = null)
{
$this->setModel(new \atk4\data\Model(new \atk4\data\Persistence_Static($data)), $fields);
} | php | public function setSource(array $data, $fields = null)
{
$this->setModel(new \atk4\data\Model(new \atk4\data\Persistence_Static($data)), $fields);
} | [
"public",
"function",
"setSource",
"(",
"array",
"$",
"data",
",",
"$",
"fields",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"setModel",
"(",
"new",
"\\",
"atk4",
"\\",
"data",
"\\",
"Model",
"(",
"new",
"\\",
"atk4",
"\\",
"data",
"\\",
"Persistence_Static",
"(",
"$",
"data",
")",
")",
",",
"$",
"fields",
")",
";",
"}"
] | Sets source of the View.
@param array $data Array of data
@param array $fields Limit model to particular fields
@return \atk4\data\Model | [
"Sets",
"source",
"of",
"the",
"View",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/View.php#L216-L219 | train |
atk4/ui | src/View.php | View.init | public function init()
{
// set name and id of view
if (!$this->name) {
if (!$this->id) {
$this->id = $this->name = 'atk';
} else {
$this->name = $this->id;
}
} elseif (!$this->id) {
$this->id = $this->name;
}
// initialize
$this->_init();
if (!$this->app) {
$this->initDefaultApp();
}
if ($this->region && !$this->template && !$this->defaultTemplate && $this->owner && $this->owner->template) {
$this->template = $this->owner->template->cloneRegion($this->region);
$this->owner->template->del($this->region);
} else {
// set up template
if (is_string($this->defaultTemplate) && is_null($this->template)) {
$this->template = $this->app->loadTemplate($this->defaultTemplate);
}
if (!$this->region) {
$this->region = 'Content';
}
}
if ($this->template && !isset($this->template->app) && isset($this->app)) {
$this->template->app = $this->app;
}
// add default objects
foreach ($this->_add_later as list($object, $region)) {
$this->add($object, $region);
}
$this->_add_later = [];
} | php | public function init()
{
// set name and id of view
if (!$this->name) {
if (!$this->id) {
$this->id = $this->name = 'atk';
} else {
$this->name = $this->id;
}
} elseif (!$this->id) {
$this->id = $this->name;
}
// initialize
$this->_init();
if (!$this->app) {
$this->initDefaultApp();
}
if ($this->region && !$this->template && !$this->defaultTemplate && $this->owner && $this->owner->template) {
$this->template = $this->owner->template->cloneRegion($this->region);
$this->owner->template->del($this->region);
} else {
// set up template
if (is_string($this->defaultTemplate) && is_null($this->template)) {
$this->template = $this->app->loadTemplate($this->defaultTemplate);
}
if (!$this->region) {
$this->region = 'Content';
}
}
if ($this->template && !isset($this->template->app) && isset($this->app)) {
$this->template->app = $this->app;
}
// add default objects
foreach ($this->_add_later as list($object, $region)) {
$this->add($object, $region);
}
$this->_add_later = [];
} | [
"public",
"function",
"init",
"(",
")",
"{",
"// set name and id of view",
"if",
"(",
"!",
"$",
"this",
"->",
"name",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"id",
")",
"{",
"$",
"this",
"->",
"id",
"=",
"$",
"this",
"->",
"name",
"=",
"'atk'",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"name",
"=",
"$",
"this",
"->",
"id",
";",
"}",
"}",
"elseif",
"(",
"!",
"$",
"this",
"->",
"id",
")",
"{",
"$",
"this",
"->",
"id",
"=",
"$",
"this",
"->",
"name",
";",
"}",
"// initialize",
"$",
"this",
"->",
"_init",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"app",
")",
"{",
"$",
"this",
"->",
"initDefaultApp",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"region",
"&&",
"!",
"$",
"this",
"->",
"template",
"&&",
"!",
"$",
"this",
"->",
"defaultTemplate",
"&&",
"$",
"this",
"->",
"owner",
"&&",
"$",
"this",
"->",
"owner",
"->",
"template",
")",
"{",
"$",
"this",
"->",
"template",
"=",
"$",
"this",
"->",
"owner",
"->",
"template",
"->",
"cloneRegion",
"(",
"$",
"this",
"->",
"region",
")",
";",
"$",
"this",
"->",
"owner",
"->",
"template",
"->",
"del",
"(",
"$",
"this",
"->",
"region",
")",
";",
"}",
"else",
"{",
"// set up template",
"if",
"(",
"is_string",
"(",
"$",
"this",
"->",
"defaultTemplate",
")",
"&&",
"is_null",
"(",
"$",
"this",
"->",
"template",
")",
")",
"{",
"$",
"this",
"->",
"template",
"=",
"$",
"this",
"->",
"app",
"->",
"loadTemplate",
"(",
"$",
"this",
"->",
"defaultTemplate",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"region",
")",
"{",
"$",
"this",
"->",
"region",
"=",
"'Content'",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"template",
"&&",
"!",
"isset",
"(",
"$",
"this",
"->",
"template",
"->",
"app",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"app",
")",
")",
"{",
"$",
"this",
"->",
"template",
"->",
"app",
"=",
"$",
"this",
"->",
"app",
";",
"}",
"// add default objects",
"foreach",
"(",
"$",
"this",
"->",
"_add_later",
"as",
"list",
"(",
"$",
"object",
",",
"$",
"region",
")",
")",
"{",
"$",
"this",
"->",
"add",
"(",
"$",
"object",
",",
"$",
"region",
")",
";",
"}",
"$",
"this",
"->",
"_add_later",
"=",
"[",
"]",
";",
"}"
] | 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",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/View.php#L296-L341 | train |
atk4/ui | src/View.php | View.initDefaultApp | protected function initDefaultApp()
{
$this->app = new App([
'skin' => $this->skin,
'catch_exceptions' => false,
'always_run' => false,
'catch_runaway_callbacks' => false,
]);
$this->app->init();
} | php | protected function initDefaultApp()
{
$this->app = new App([
'skin' => $this->skin,
'catch_exceptions' => false,
'always_run' => false,
'catch_runaway_callbacks' => false,
]);
$this->app->init();
} | [
"protected",
"function",
"initDefaultApp",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"=",
"new",
"App",
"(",
"[",
"'skin'",
"=>",
"$",
"this",
"->",
"skin",
",",
"'catch_exceptions'",
"=>",
"false",
",",
"'always_run'",
"=>",
"false",
",",
"'catch_runaway_callbacks'",
"=>",
"false",
",",
"]",
")",
";",
"$",
"this",
"->",
"app",
"->",
"init",
"(",
")",
";",
"}"
] | For the absence of the application, we would add a very
simple one. | [
"For",
"the",
"absence",
"of",
"the",
"application",
"we",
"would",
"add",
"a",
"very",
"simple",
"one",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/View.php#L347-L356 | train |
atk4/ui | src/View.php | View.add | public function add($seed, $region = null)
{
if ($this->_rendered) {
throw new Exception('You cannot add anything into the view after it was rendered');
}
if (!$this->app) {
$this->_add_later[] = [$seed, $region];
return $seed;
}
if (is_array($region)) {
$args = $region;
if (isset($args['region'])) {
$region = ['region'=>$args['region']];
unset($args['region']);
}
} elseif ($region) {
$args = null;
$region = ['region'=>$region];
} else {
$args = null;
$region = null;
}
// Create object first
$object = $this->factory($this->mergeSeeds($seed, ['View']), $region);
// Will call init() of the object
$object = $this->_add($object, $args);
return $object;
} | php | public function add($seed, $region = null)
{
if ($this->_rendered) {
throw new Exception('You cannot add anything into the view after it was rendered');
}
if (!$this->app) {
$this->_add_later[] = [$seed, $region];
return $seed;
}
if (is_array($region)) {
$args = $region;
if (isset($args['region'])) {
$region = ['region'=>$args['region']];
unset($args['region']);
}
} elseif ($region) {
$args = null;
$region = ['region'=>$region];
} else {
$args = null;
$region = null;
}
// Create object first
$object = $this->factory($this->mergeSeeds($seed, ['View']), $region);
// Will call init() of the object
$object = $this->_add($object, $args);
return $object;
} | [
"public",
"function",
"add",
"(",
"$",
"seed",
",",
"$",
"region",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_rendered",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'You cannot add anything into the view after it was rendered'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"app",
")",
"{",
"$",
"this",
"->",
"_add_later",
"[",
"]",
"=",
"[",
"$",
"seed",
",",
"$",
"region",
"]",
";",
"return",
"$",
"seed",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"region",
")",
")",
"{",
"$",
"args",
"=",
"$",
"region",
";",
"if",
"(",
"isset",
"(",
"$",
"args",
"[",
"'region'",
"]",
")",
")",
"{",
"$",
"region",
"=",
"[",
"'region'",
"=>",
"$",
"args",
"[",
"'region'",
"]",
"]",
";",
"unset",
"(",
"$",
"args",
"[",
"'region'",
"]",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"region",
")",
"{",
"$",
"args",
"=",
"null",
";",
"$",
"region",
"=",
"[",
"'region'",
"=>",
"$",
"region",
"]",
";",
"}",
"else",
"{",
"$",
"args",
"=",
"null",
";",
"$",
"region",
"=",
"null",
";",
"}",
"// Create object first",
"$",
"object",
"=",
"$",
"this",
"->",
"factory",
"(",
"$",
"this",
"->",
"mergeSeeds",
"(",
"$",
"seed",
",",
"[",
"'View'",
"]",
")",
",",
"$",
"region",
")",
";",
"// Will call init() of the object",
"$",
"object",
"=",
"$",
"this",
"->",
"_add",
"(",
"$",
"object",
",",
"$",
"args",
")",
";",
"return",
"$",
"object",
";",
"}"
] | In addition to adding a child object, sets up it's template
and associate it's output with the region in our template.
@param mixed $seed New object to add
@param string $region
@throws Exception
@return View | [
"In",
"addition",
"to",
"adding",
"a",
"child",
"object",
"sets",
"up",
"it",
"s",
"template",
"and",
"associate",
"it",
"s",
"output",
"with",
"the",
"region",
"in",
"our",
"template",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/View.php#L369-L401 | train |
atk4/ui | src/View.php | View.getClosestOwner | public function getClosestOwner($object, $class)
{
if (!isset($object->owner)) {
return;
}
if ($object->owner instanceof $class) {
return $object->owner;
}
return $this->getClosestOwner($object->owner, $class);
} | php | public function getClosestOwner($object, $class)
{
if (!isset($object->owner)) {
return;
}
if ($object->owner instanceof $class) {
return $object->owner;
}
return $this->getClosestOwner($object->owner, $class);
} | [
"public",
"function",
"getClosestOwner",
"(",
"$",
"object",
",",
"$",
"class",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"object",
"->",
"owner",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"object",
"->",
"owner",
"instanceof",
"$",
"class",
")",
"{",
"return",
"$",
"object",
"->",
"owner",
";",
"}",
"return",
"$",
"this",
"->",
"getClosestOwner",
"(",
"$",
"object",
"->",
"owner",
",",
"$",
"class",
")",
";",
"}"
] | Get objects closest owner which is instance of particular class.
If there are no such owner (or grand-owner etc.) object, then return.
Note: this is internal method, but should be public because other objects
should be able to call it.
@param \atk4\ui\View $object
@param string $class
@return null|\atk4\ui\View | [
"Get",
"objects",
"closest",
"owner",
"which",
"is",
"instance",
"of",
"particular",
"class",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/View.php#L416-L427 | train |
atk4/ui | src/View.php | View.set | public function set($arg1 = null, $arg2 = null)
{
if (is_string($arg1) && $arg2 !== null) {
// must be initialized
$this->template->set($arg1, $arg2);
return $this;
}
if ($arg2 !== null) {
throw new Exception([
'Second argument to set() can be only passed if the first one is a string',
'arg1' => $arg1,
'arg2' => $arg2,
]);
}
if (is_scalar($arg1)) {
$this->content = $arg1;
return $this;
}
if (is_array($arg1)) {
if (isset($arg1[0])) {
$this->content = $arg1[0];
}
$this->setDefaults($arg1);
return $this;
}
throw new Exception([
'Not sure what to do with argument',
'this' => $this,
'arg1' => $arg1,
'arg2' => $arg2,
]);
} | php | public function set($arg1 = null, $arg2 = null)
{
if (is_string($arg1) && $arg2 !== null) {
// must be initialized
$this->template->set($arg1, $arg2);
return $this;
}
if ($arg2 !== null) {
throw new Exception([
'Second argument to set() can be only passed if the first one is a string',
'arg1' => $arg1,
'arg2' => $arg2,
]);
}
if (is_scalar($arg1)) {
$this->content = $arg1;
return $this;
}
if (is_array($arg1)) {
if (isset($arg1[0])) {
$this->content = $arg1[0];
}
$this->setDefaults($arg1);
return $this;
}
throw new Exception([
'Not sure what to do with argument',
'this' => $this,
'arg1' => $arg1,
'arg2' => $arg2,
]);
} | [
"public",
"function",
"set",
"(",
"$",
"arg1",
"=",
"null",
",",
"$",
"arg2",
"=",
"null",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"arg1",
")",
"&&",
"$",
"arg2",
"!==",
"null",
")",
"{",
"// must be initialized",
"$",
"this",
"->",
"template",
"->",
"set",
"(",
"$",
"arg1",
",",
"$",
"arg2",
")",
";",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"$",
"arg2",
"!==",
"null",
")",
"{",
"throw",
"new",
"Exception",
"(",
"[",
"'Second argument to set() can be only passed if the first one is a string'",
",",
"'arg1'",
"=>",
"$",
"arg1",
",",
"'arg2'",
"=>",
"$",
"arg2",
",",
"]",
")",
";",
"}",
"if",
"(",
"is_scalar",
"(",
"$",
"arg1",
")",
")",
"{",
"$",
"this",
"->",
"content",
"=",
"$",
"arg1",
";",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"arg1",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"arg1",
"[",
"0",
"]",
")",
")",
"{",
"$",
"this",
"->",
"content",
"=",
"$",
"arg1",
"[",
"0",
"]",
";",
"}",
"$",
"this",
"->",
"setDefaults",
"(",
"$",
"arg1",
")",
";",
"return",
"$",
"this",
";",
"}",
"throw",
"new",
"Exception",
"(",
"[",
"'Not sure what to do with argument'",
",",
"'this'",
"=>",
"$",
"this",
",",
"'arg1'",
"=>",
"$",
"arg1",
",",
"'arg2'",
"=>",
"$",
"arg2",
",",
"]",
")",
";",
"}"
] | Override this method without compatibility with parent, if you wish
to set your own things your own way for your view.
@param string|array $arg1
@param string|null $arg2
@throws Exception
@return $this | [
"Override",
"this",
"method",
"without",
"compatibility",
"with",
"parent",
"if",
"you",
"wish",
"to",
"set",
"your",
"own",
"things",
"your",
"own",
"way",
"for",
"your",
"view",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/View.php#L444-L483 | train |
atk4/ui | src/View.php | View.removeAttr | public function removeAttr($property)
{
if (is_array($property)) {
foreach ($property as $v) {
unset($this->attr[$v]);
}
return $this;
}
unset($this->attr[$property]);
return $this;
} | php | public function removeAttr($property)
{
if (is_array($property)) {
foreach ($property as $v) {
unset($this->attr[$v]);
}
return $this;
}
unset($this->attr[$property]);
return $this;
} | [
"public",
"function",
"removeAttr",
"(",
"$",
"property",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"property",
")",
")",
"{",
"foreach",
"(",
"$",
"property",
"as",
"$",
"v",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"attr",
"[",
"$",
"v",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"attr",
"[",
"$",
"property",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Remove attribute.
@param string|array $property Attribute name or hash
@return $this | [
"Remove",
"attribute",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/View.php#L613-L626 | train |
atk4/ui | src/View.php | View.recursiveRender | public function recursiveRender()
{
foreach ($this->elements as $view) {
if (!$view instanceof self) {
continue;
}
$this->template->appendHTML($view->region, $view->getHTML());
if ($view->_js_actions) {
$this->_js_actions = array_merge_recursive($this->_js_actions, $view->_js_actions);
}
}
if (isset($this->content) && $this->content !== false) {
$this->template->append('Content', $this->content);
}
} | php | public function recursiveRender()
{
foreach ($this->elements as $view) {
if (!$view instanceof self) {
continue;
}
$this->template->appendHTML($view->region, $view->getHTML());
if ($view->_js_actions) {
$this->_js_actions = array_merge_recursive($this->_js_actions, $view->_js_actions);
}
}
if (isset($this->content) && $this->content !== false) {
$this->template->append('Content', $this->content);
}
} | [
"public",
"function",
"recursiveRender",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"elements",
"as",
"$",
"view",
")",
"{",
"if",
"(",
"!",
"$",
"view",
"instanceof",
"self",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"template",
"->",
"appendHTML",
"(",
"$",
"view",
"->",
"region",
",",
"$",
"view",
"->",
"getHTML",
"(",
")",
")",
";",
"if",
"(",
"$",
"view",
"->",
"_js_actions",
")",
"{",
"$",
"this",
"->",
"_js_actions",
"=",
"array_merge_recursive",
"(",
"$",
"this",
"->",
"_js_actions",
",",
"$",
"view",
"->",
"_js_actions",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"content",
")",
"&&",
"$",
"this",
"->",
"content",
"!==",
"false",
")",
"{",
"$",
"this",
"->",
"template",
"->",
"append",
"(",
"'Content'",
",",
"$",
"this",
"->",
"content",
")",
";",
"}",
"}"
] | Recursively render all children, placing their
output in our template. | [
"Recursively",
"render",
"all",
"children",
"placing",
"their",
"output",
"in",
"our",
"template",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/View.php#L686-L703 | train |
atk4/ui | src/View.php | View.renderAll | public function renderAll()
{
if (!$this->_initialized) {
$this->init();
}
if (!$this->_rendered) {
$this->renderView();
$this->recursiveRender();
$this->_rendered = true;
}
} | php | public function renderAll()
{
if (!$this->_initialized) {
$this->init();
}
if (!$this->_rendered) {
$this->renderView();
$this->recursiveRender();
$this->_rendered = true;
}
} | [
"public",
"function",
"renderAll",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_initialized",
")",
"{",
"$",
"this",
"->",
"init",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"_rendered",
")",
"{",
"$",
"this",
"->",
"renderView",
"(",
")",
";",
"$",
"this",
"->",
"recursiveRender",
"(",
")",
";",
"$",
"this",
"->",
"_rendered",
"=",
"true",
";",
"}",
"}"
] | Render everything recursively, render ourselves but don't return
anything just yet. | [
"Render",
"everything",
"recursively",
"render",
"ourselves",
"but",
"don",
"t",
"return",
"anything",
"just",
"yet",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/View.php#L709-L721 | train |
atk4/ui | src/View.php | View.render | public function render($force_echo = true)
{
$this->renderAll();
return
$this->getJS($force_echo).
$this->template->render();
} | php | public function render($force_echo = true)
{
$this->renderAll();
return
$this->getJS($force_echo).
$this->template->render();
} | [
"public",
"function",
"render",
"(",
"$",
"force_echo",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"renderAll",
"(",
")",
";",
"return",
"$",
"this",
"->",
"getJS",
"(",
"$",
"force_echo",
")",
".",
"$",
"this",
"->",
"template",
"->",
"render",
"(",
")",
";",
"}"
] | This method is for those cases when developer want to simply render his
view and grab HTML himself.
@param bool $force_echo
@return string | [
"This",
"method",
"is",
"for",
"those",
"cases",
"when",
"developer",
"want",
"to",
"simply",
"render",
"his",
"view",
"and",
"grab",
"HTML",
"himself",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/View.php#L731-L738 | train |
atk4/ui | src/View.php | View.renderJSON | public function renderJSON($force_echo = true, $region = null)
{
try {
$this->renderAll();
return json_encode(['success' => true,
'message' => 'Success',
'atkjs' => $this->getJS($force_echo),
'html' => $this->template->render($region),
'id' => $this->name, ]);
} catch (\Exception $exception) {
$this->_rendered = false;
$l = $this->add(new self());
if ($exception instanceof \atk4\core\Exception) {
$l->template->setHTML('Content', $exception->getHTML());
} elseif ($exception instanceof \Error) {
$l->add(new self(['ui' => 'message', get_class($exception).': '.
$exception->getMessage().' (in '.$exception->getFile().':'.$exception->getLine().')',
'error', ]));
$l->add(new Text())->set(nl2br($exception->getTraceAsString()));
} else {
$l->add(new self(['ui' => 'message', get_class($exception).': '.$exception->getMessage(), 'error']));
}
return json_encode(['success' => false,
'message' => $l->getHTML(), ]);
}
} | php | public function renderJSON($force_echo = true, $region = null)
{
try {
$this->renderAll();
return json_encode(['success' => true,
'message' => 'Success',
'atkjs' => $this->getJS($force_echo),
'html' => $this->template->render($region),
'id' => $this->name, ]);
} catch (\Exception $exception) {
$this->_rendered = false;
$l = $this->add(new self());
if ($exception instanceof \atk4\core\Exception) {
$l->template->setHTML('Content', $exception->getHTML());
} elseif ($exception instanceof \Error) {
$l->add(new self(['ui' => 'message', get_class($exception).': '.
$exception->getMessage().' (in '.$exception->getFile().':'.$exception->getLine().')',
'error', ]));
$l->add(new Text())->set(nl2br($exception->getTraceAsString()));
} else {
$l->add(new self(['ui' => 'message', get_class($exception).': '.$exception->getMessage(), 'error']));
}
return json_encode(['success' => false,
'message' => $l->getHTML(), ]);
}
} | [
"public",
"function",
"renderJSON",
"(",
"$",
"force_echo",
"=",
"true",
",",
"$",
"region",
"=",
"null",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"renderAll",
"(",
")",
";",
"return",
"json_encode",
"(",
"[",
"'success'",
"=>",
"true",
",",
"'message'",
"=>",
"'Success'",
",",
"'atkjs'",
"=>",
"$",
"this",
"->",
"getJS",
"(",
"$",
"force_echo",
")",
",",
"'html'",
"=>",
"$",
"this",
"->",
"template",
"->",
"render",
"(",
"$",
"region",
")",
",",
"'id'",
"=>",
"$",
"this",
"->",
"name",
",",
"]",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"exception",
")",
"{",
"$",
"this",
"->",
"_rendered",
"=",
"false",
";",
"$",
"l",
"=",
"$",
"this",
"->",
"add",
"(",
"new",
"self",
"(",
")",
")",
";",
"if",
"(",
"$",
"exception",
"instanceof",
"\\",
"atk4",
"\\",
"core",
"\\",
"Exception",
")",
"{",
"$",
"l",
"->",
"template",
"->",
"setHTML",
"(",
"'Content'",
",",
"$",
"exception",
"->",
"getHTML",
"(",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"exception",
"instanceof",
"\\",
"Error",
")",
"{",
"$",
"l",
"->",
"add",
"(",
"new",
"self",
"(",
"[",
"'ui'",
"=>",
"'message'",
",",
"get_class",
"(",
"$",
"exception",
")",
".",
"': '",
".",
"$",
"exception",
"->",
"getMessage",
"(",
")",
".",
"' (in '",
".",
"$",
"exception",
"->",
"getFile",
"(",
")",
".",
"':'",
".",
"$",
"exception",
"->",
"getLine",
"(",
")",
".",
"')'",
",",
"'error'",
",",
"]",
")",
")",
";",
"$",
"l",
"->",
"add",
"(",
"new",
"Text",
"(",
")",
")",
"->",
"set",
"(",
"nl2br",
"(",
"$",
"exception",
"->",
"getTraceAsString",
"(",
")",
")",
")",
";",
"}",
"else",
"{",
"$",
"l",
"->",
"add",
"(",
"new",
"self",
"(",
"[",
"'ui'",
"=>",
"'message'",
",",
"get_class",
"(",
"$",
"exception",
")",
".",
"': '",
".",
"$",
"exception",
"->",
"getMessage",
"(",
")",
",",
"'error'",
"]",
")",
")",
";",
"}",
"return",
"json_encode",
"(",
"[",
"'success'",
"=>",
"false",
",",
"'message'",
"=>",
"$",
"l",
"->",
"getHTML",
"(",
")",
",",
"]",
")",
";",
"}",
"}"
] | Render View using json format.
@param bool $force_echo
@param string $region A specific template region to render.
@throws Exception
@return string | [
"Render",
"View",
"using",
"json",
"format",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/View.php#L750-L777 | train |
atk4/ui | src/View.php | View.vue | public function vue($component, $initData = [], $componentDefinition = null, $selector = null)
{
if (!$selector) {
$selector = '#'.$this->name;
}
if ($componentDefinition) {
$chain = (new jsVueService())->createVue($selector, $component, $componentDefinition, $initData);
} else {
$chain = (new jsVueService())->createAtkVue($selector, $component, $initData);
}
$this->_js_actions[true][] = $chain;
return $this;
} | php | public function vue($component, $initData = [], $componentDefinition = null, $selector = null)
{
if (!$selector) {
$selector = '#'.$this->name;
}
if ($componentDefinition) {
$chain = (new jsVueService())->createVue($selector, $component, $componentDefinition, $initData);
} else {
$chain = (new jsVueService())->createAtkVue($selector, $component, $initData);
}
$this->_js_actions[true][] = $chain;
return $this;
} | [
"public",
"function",
"vue",
"(",
"$",
"component",
",",
"$",
"initData",
"=",
"[",
"]",
",",
"$",
"componentDefinition",
"=",
"null",
",",
"$",
"selector",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"selector",
")",
"{",
"$",
"selector",
"=",
"'#'",
".",
"$",
"this",
"->",
"name",
";",
"}",
"if",
"(",
"$",
"componentDefinition",
")",
"{",
"$",
"chain",
"=",
"(",
"new",
"jsVueService",
"(",
")",
")",
"->",
"createVue",
"(",
"$",
"selector",
",",
"$",
"component",
",",
"$",
"componentDefinition",
",",
"$",
"initData",
")",
";",
"}",
"else",
"{",
"$",
"chain",
"=",
"(",
"new",
"jsVueService",
"(",
")",
")",
"->",
"createAtkVue",
"(",
"$",
"selector",
",",
"$",
"component",
",",
"$",
"initData",
")",
";",
"}",
"$",
"this",
"->",
"_js_actions",
"[",
"true",
"]",
"[",
"]",
"=",
"$",
"chain",
";",
"return",
"$",
"this",
";",
"}"
] | Create Vue.js instance.
Vue.js instance can be create 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.
@param string $component The component name;
@param array $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.
@param null|string $componentDefinition The name of the js var holding a component definition object.
This var must be defined and accessible in window object. window['var_name']
@param null $selector The selector for creating the base root object in Vue.
@return $this | [
"Create",
"Vue",
".",
"js",
"instance",
".",
"Vue",
".",
"js",
"instance",
"can",
"be",
"create",
"from",
"atk4",
"\\",
"ui",
"\\",
"View",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/View.php#L908-L923 | train |
atk4/ui | src/View.php | View.jsVueEmit | public function jsVueEmit($eventName, $eventData = [])
{
// adding this view id to data.
// Usually, you would check if the event is emit for the right component.
if (!$eventData['id']) {
$eventData['id'] = $this->name;
}
return (new jsVueService())->emitEvent($eventName, $eventData);
} | php | public function jsVueEmit($eventName, $eventData = [])
{
// adding this view id to data.
// Usually, you would check if the event is emit for the right component.
if (!$eventData['id']) {
$eventData['id'] = $this->name;
}
return (new jsVueService())->emitEvent($eventName, $eventData);
} | [
"public",
"function",
"jsVueEmit",
"(",
"$",
"eventName",
",",
"$",
"eventData",
"=",
"[",
"]",
")",
"{",
"// adding this view id to data.",
"// Usually, you would check if the event is emit for the right component.",
"if",
"(",
"!",
"$",
"eventData",
"[",
"'id'",
"]",
")",
"{",
"$",
"eventData",
"[",
"'id'",
"]",
"=",
"$",
"this",
"->",
"name",
";",
"}",
"return",
"(",
"new",
"jsVueService",
"(",
")",
")",
"->",
"emitEvent",
"(",
"$",
"eventName",
",",
"$",
"eventData",
")",
";",
"}"
] | Emit an event on the Vue event bus.
vueService has a dedicated Vue instance for registering
event that allow communication between external view like button,
or even separate vue component, in order to communicate to each other.
Once a component is set for listening to a particular event,
you can emit the event using this function.
Adding a listener is generally done via the created component method.
example of adding a listener inside the created method.
atk.vueService.eventBus.$on('eventName', (data) => {
// make sure we are talking to the right component.
if (this.$parent.$el.id === data.id) {
this.doSomething();
}
});
@param string $eventName The event name the will be emit.
@param array $eventData $eventData The data passed with the event.
@return mixed | [
"Emit",
"an",
"event",
"on",
"the",
"Vue",
"event",
"bus",
".",
"vueService",
"has",
"a",
"dedicated",
"Vue",
"instance",
"for",
"registering",
"event",
"that",
"allow",
"communication",
"between",
"external",
"view",
"like",
"button",
"or",
"even",
"separate",
"vue",
"component",
"in",
"order",
"to",
"communicate",
"to",
"each",
"other",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/View.php#L951-L960 | train |
atk4/ui | src/View.php | View.getJS | public function getJS($force_echo = false)
{
$actions = [];
foreach ($this->_js_actions as $eventActions) {
foreach ($eventActions as $action) {
$actions[] = $action;
}
}
if (!$actions) {
return '';
}
$actions['indent'] = '';
if (!$force_echo && $this->app && $this->app->hasMethod('jsReady')) {
$this->app->jsReady($actions);
return '';
}
// delegate $action rendering in hosting app if exist.
if ($this->app && $this->app->hasMethod('getViewJS')) {
return $this->app->getViewJS($actions);
}
$ready = new jsFunction($actions);
return "<script>\n".
(new jQuery($ready))->jsRender().
'</script>';
} | php | public function getJS($force_echo = false)
{
$actions = [];
foreach ($this->_js_actions as $eventActions) {
foreach ($eventActions as $action) {
$actions[] = $action;
}
}
if (!$actions) {
return '';
}
$actions['indent'] = '';
if (!$force_echo && $this->app && $this->app->hasMethod('jsReady')) {
$this->app->jsReady($actions);
return '';
}
// delegate $action rendering in hosting app if exist.
if ($this->app && $this->app->hasMethod('getViewJS')) {
return $this->app->getViewJS($actions);
}
$ready = new jsFunction($actions);
return "<script>\n".
(new jQuery($ready))->jsRender().
'</script>';
} | [
"public",
"function",
"getJS",
"(",
"$",
"force_echo",
"=",
"false",
")",
"{",
"$",
"actions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"_js_actions",
"as",
"$",
"eventActions",
")",
"{",
"foreach",
"(",
"$",
"eventActions",
"as",
"$",
"action",
")",
"{",
"$",
"actions",
"[",
"]",
"=",
"$",
"action",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"actions",
")",
"{",
"return",
"''",
";",
"}",
"$",
"actions",
"[",
"'indent'",
"]",
"=",
"''",
";",
"if",
"(",
"!",
"$",
"force_echo",
"&&",
"$",
"this",
"->",
"app",
"&&",
"$",
"this",
"->",
"app",
"->",
"hasMethod",
"(",
"'jsReady'",
")",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"jsReady",
"(",
"$",
"actions",
")",
";",
"return",
"''",
";",
"}",
"// delegate $action rendering in hosting app if exist.",
"if",
"(",
"$",
"this",
"->",
"app",
"&&",
"$",
"this",
"->",
"app",
"->",
"hasMethod",
"(",
"'getViewJS'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"app",
"->",
"getViewJS",
"(",
"$",
"actions",
")",
";",
"}",
"$",
"ready",
"=",
"new",
"jsFunction",
"(",
"$",
"actions",
")",
";",
"return",
"\"<script>\\n\"",
".",
"(",
"new",
"jQuery",
"(",
"$",
"ready",
")",
")",
"->",
"jsRender",
"(",
")",
".",
"'</script>'",
";",
"}"
] | Get JavaScript objects from this render tree.
@param bool $force_echo
@return string | [
"Get",
"JavaScript",
"objects",
"from",
"this",
"render",
"tree",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/View.php#L1123-L1155 | train |
atk4/ui | src/Form.php | Form.initLayout | protected function initLayout()
{
if ($this->layout === null) {
$this->layout = 'Generic';
}
if (is_string($this->layout) || is_array($this->layout)) {
$this->layout = $this->factory($this->layout, ['form'=>$this], 'FormLayout');
$this->layout = $this->add($this->layout);
} elseif (is_object($this->layout)) {
$this->layout->form = $this;
$this->add($this->layout);
} else {
throw new Exception(['Unsupported specification of form layout. Can be array, string or object', 'layout' => $this->layout]);
}
// Add save button in layout
if ($this->buttonSave) {
$this->buttonSave = $this->layout->addButton($this->buttonSave);
$this->buttonSave->setAttr('tabindex', 0);
$this->buttonSave->on('click', $this->js()->form('submit'));
$this->buttonSave->on('keypress', new jsExpression('if (event.keyCode === 13){$([name]).form("submit");}', ['name' => '#'.$this->name]));
}
} | php | protected function initLayout()
{
if ($this->layout === null) {
$this->layout = 'Generic';
}
if (is_string($this->layout) || is_array($this->layout)) {
$this->layout = $this->factory($this->layout, ['form'=>$this], 'FormLayout');
$this->layout = $this->add($this->layout);
} elseif (is_object($this->layout)) {
$this->layout->form = $this;
$this->add($this->layout);
} else {
throw new Exception(['Unsupported specification of form layout. Can be array, string or object', 'layout' => $this->layout]);
}
// Add save button in layout
if ($this->buttonSave) {
$this->buttonSave = $this->layout->addButton($this->buttonSave);
$this->buttonSave->setAttr('tabindex', 0);
$this->buttonSave->on('click', $this->js()->form('submit'));
$this->buttonSave->on('keypress', new jsExpression('if (event.keyCode === 13){$([name]).form("submit");}', ['name' => '#'.$this->name]));
}
} | [
"protected",
"function",
"initLayout",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"layout",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"layout",
"=",
"'Generic'",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"this",
"->",
"layout",
")",
"||",
"is_array",
"(",
"$",
"this",
"->",
"layout",
")",
")",
"{",
"$",
"this",
"->",
"layout",
"=",
"$",
"this",
"->",
"factory",
"(",
"$",
"this",
"->",
"layout",
",",
"[",
"'form'",
"=>",
"$",
"this",
"]",
",",
"'FormLayout'",
")",
";",
"$",
"this",
"->",
"layout",
"=",
"$",
"this",
"->",
"add",
"(",
"$",
"this",
"->",
"layout",
")",
";",
"}",
"elseif",
"(",
"is_object",
"(",
"$",
"this",
"->",
"layout",
")",
")",
"{",
"$",
"this",
"->",
"layout",
"->",
"form",
"=",
"$",
"this",
";",
"$",
"this",
"->",
"add",
"(",
"$",
"this",
"->",
"layout",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"[",
"'Unsupported specification of form layout. Can be array, string or object'",
",",
"'layout'",
"=>",
"$",
"this",
"->",
"layout",
"]",
")",
";",
"}",
"// Add save button in layout",
"if",
"(",
"$",
"this",
"->",
"buttonSave",
")",
"{",
"$",
"this",
"->",
"buttonSave",
"=",
"$",
"this",
"->",
"layout",
"->",
"addButton",
"(",
"$",
"this",
"->",
"buttonSave",
")",
";",
"$",
"this",
"->",
"buttonSave",
"->",
"setAttr",
"(",
"'tabindex'",
",",
"0",
")",
";",
"$",
"this",
"->",
"buttonSave",
"->",
"on",
"(",
"'click'",
",",
"$",
"this",
"->",
"js",
"(",
")",
"->",
"form",
"(",
"'submit'",
")",
")",
";",
"$",
"this",
"->",
"buttonSave",
"->",
"on",
"(",
"'keypress'",
",",
"new",
"jsExpression",
"(",
"'if (event.keyCode === 13){$([name]).form(\"submit\");}'",
",",
"[",
"'name'",
"=>",
"'#'",
".",
"$",
"this",
"->",
"name",
"]",
")",
")",
";",
"}",
"}"
] | initialize form layout. You can inject custom layout
if you 'layout'=>.. to constructor. | [
"initialize",
"form",
"layout",
".",
"You",
"can",
"inject",
"custom",
"layout",
"if",
"you",
"layout",
"=",
">",
"..",
"to",
"constructor",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Form.php#L141-L164 | train |
atk4/ui | src/Form.php | Form.setGroupDisplayRules | public function setGroupDisplayRules($rules = [], $selector = '.atk-form-group')
{
if (is_object($selector) && isset($selector->name)) {
$selector = '#'.$selector->name;
}
$this->fieldsDisplayRules = $rules;
$this->fieldDisplaySelector = $selector;
return $this;
} | php | public function setGroupDisplayRules($rules = [], $selector = '.atk-form-group')
{
if (is_object($selector) && isset($selector->name)) {
$selector = '#'.$selector->name;
}
$this->fieldsDisplayRules = $rules;
$this->fieldDisplaySelector = $selector;
return $this;
} | [
"public",
"function",
"setGroupDisplayRules",
"(",
"$",
"rules",
"=",
"[",
"]",
",",
"$",
"selector",
"=",
"'.atk-form-group'",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"selector",
")",
"&&",
"isset",
"(",
"$",
"selector",
"->",
"name",
")",
")",
"{",
"$",
"selector",
"=",
"'#'",
".",
"$",
"selector",
"->",
"name",
";",
"}",
"$",
"this",
"->",
"fieldsDisplayRules",
"=",
"$",
"rules",
";",
"$",
"this",
"->",
"fieldDisplaySelector",
"=",
"$",
"selector",
";",
"return",
"$",
"this",
";",
"}"
] | Set display rule for a group collection.
@param array $rules
@param string|object $selector
@return $this | [
"Set",
"display",
"rule",
"for",
"a",
"group",
"collection",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Form.php#L188-L198 | train |
atk4/ui | src/Form.php | Form.setModel | public function setModel(\atk4\data\Model $model, $fields = null)
{
// Model is set for the form and also for the current layout
try {
$model = parent::setModel($model);
$this->layout->setModel($model, $fields);
return $model;
} catch (Exception $e) {
throw $e->addMoreInfo('model', $model);
}
} | php | public function setModel(\atk4\data\Model $model, $fields = null)
{
// Model is set for the form and also for the current layout
try {
$model = parent::setModel($model);
$this->layout->setModel($model, $fields);
return $model;
} catch (Exception $e) {
throw $e->addMoreInfo('model', $model);
}
} | [
"public",
"function",
"setModel",
"(",
"\\",
"atk4",
"\\",
"data",
"\\",
"Model",
"$",
"model",
",",
"$",
"fields",
"=",
"null",
")",
"{",
"// Model is set for the form and also for the current layout",
"try",
"{",
"$",
"model",
"=",
"parent",
"::",
"setModel",
"(",
"$",
"model",
")",
";",
"$",
"this",
"->",
"layout",
"->",
"setModel",
"(",
"$",
"model",
",",
"$",
"fields",
")",
";",
"return",
"$",
"model",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"throw",
"$",
"e",
"->",
"addMoreInfo",
"(",
"'model'",
",",
"$",
"model",
")",
";",
"}",
"}"
] | Associates form with the model but also specifies which of Model
fields should be added automatically.
If $actualFields are not specified, then all "editable" fields
will be added.
@param \atk4\data\Model $model
@param array $fields
@return \atk4\data\Model | [
"Associates",
"form",
"with",
"the",
"model",
"but",
"also",
"specifies",
"which",
"of",
"Model",
"fields",
"should",
"be",
"added",
"automatically",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Form.php#L212-L223 | train |
atk4/ui | src/Form.php | Form.error | public function error($fieldName, $str)
{
// by using this hook you can overwrite default behavior of this method
if ($this->hookHasCallbacks('displayError')) {
return $this->hook('displayError', [$fieldName, $str]);
}
$jsError = [$this->js()->form('add prompt', $fieldName, $str)];
return $jsError;
} | php | public function error($fieldName, $str)
{
// by using this hook you can overwrite default behavior of this method
if ($this->hookHasCallbacks('displayError')) {
return $this->hook('displayError', [$fieldName, $str]);
}
$jsError = [$this->js()->form('add prompt', $fieldName, $str)];
return $jsError;
} | [
"public",
"function",
"error",
"(",
"$",
"fieldName",
",",
"$",
"str",
")",
"{",
"// by using this hook you can overwrite default behavior of this method",
"if",
"(",
"$",
"this",
"->",
"hookHasCallbacks",
"(",
"'displayError'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"hook",
"(",
"'displayError'",
",",
"[",
"$",
"fieldName",
",",
"$",
"str",
"]",
")",
";",
"}",
"$",
"jsError",
"=",
"[",
"$",
"this",
"->",
"js",
"(",
")",
"->",
"form",
"(",
"'add prompt'",
",",
"$",
"fieldName",
",",
"$",
"str",
")",
"]",
";",
"return",
"$",
"jsError",
";",
"}"
] | Causes form to generate error.
@param string $fieldName Field name
@param string $str Error message
@return jsChain|array | [
"Causes",
"form",
"to",
"generate",
"error",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Form.php#L256-L266 | train |
atk4/ui | src/Form.php | Form.success | public function success($str = 'Success', $sub_header = null)
{
// by using this hook you can overwrite default behavior of this method
if ($this->hookHasCallbacks('displaySuccess')) {
return $this->hook('displaySuccess', [$str, $sub_header]);
}
/* below code works, but pollutes output with bad id=xx
$success = new Message([$str, 'id'=>false, 'type'=>'success', 'icon'=>'check']);
$success->app = $this->app;
$success->init();
$success->text->addParagraph($sub_header);
*/
$success = $this->app->loadTemplate($this->successTemplate);
$success['header'] = $str;
if ($sub_header) {
$success['message'] = $sub_header;
} else {
$success->del('p');
}
$js = $this->js()
->html($success->render());
return $js;
} | php | public function success($str = 'Success', $sub_header = null)
{
// by using this hook you can overwrite default behavior of this method
if ($this->hookHasCallbacks('displaySuccess')) {
return $this->hook('displaySuccess', [$str, $sub_header]);
}
/* below code works, but pollutes output with bad id=xx
$success = new Message([$str, 'id'=>false, 'type'=>'success', 'icon'=>'check']);
$success->app = $this->app;
$success->init();
$success->text->addParagraph($sub_header);
*/
$success = $this->app->loadTemplate($this->successTemplate);
$success['header'] = $str;
if ($sub_header) {
$success['message'] = $sub_header;
} else {
$success->del('p');
}
$js = $this->js()
->html($success->render());
return $js;
} | [
"public",
"function",
"success",
"(",
"$",
"str",
"=",
"'Success'",
",",
"$",
"sub_header",
"=",
"null",
")",
"{",
"// by using this hook you can overwrite default behavior of this method",
"if",
"(",
"$",
"this",
"->",
"hookHasCallbacks",
"(",
"'displaySuccess'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"hook",
"(",
"'displaySuccess'",
",",
"[",
"$",
"str",
",",
"$",
"sub_header",
"]",
")",
";",
"}",
"/* below code works, but pollutes output with bad id=xx\n $success = new Message([$str, 'id'=>false, 'type'=>'success', 'icon'=>'check']);\n $success->app = $this->app;\n $success->init();\n $success->text->addParagraph($sub_header);\n */",
"$",
"success",
"=",
"$",
"this",
"->",
"app",
"->",
"loadTemplate",
"(",
"$",
"this",
"->",
"successTemplate",
")",
";",
"$",
"success",
"[",
"'header'",
"]",
"=",
"$",
"str",
";",
"if",
"(",
"$",
"sub_header",
")",
"{",
"$",
"success",
"[",
"'message'",
"]",
"=",
"$",
"sub_header",
";",
"}",
"else",
"{",
"$",
"success",
"->",
"del",
"(",
"'p'",
")",
";",
"}",
"$",
"js",
"=",
"$",
"this",
"->",
"js",
"(",
")",
"->",
"html",
"(",
"$",
"success",
"->",
"render",
"(",
")",
")",
";",
"return",
"$",
"js",
";",
"}"
] | Causes form to generate success message.
@param string $str Success message
@param string $sub_header Sub-header
@return jsChain | [
"Causes",
"form",
"to",
"generate",
"success",
"message",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Form.php#L276-L302 | train |
atk4/ui | src/Form.php | Form.addField | public function addField($name, $decorator = null, $field = null)
{
if (!$this->model) {
$this->model = new \atk4\ui\misc\ProxyModel();
}
return $this->layout->addField($name, $decorator, $field);
} | php | public function addField($name, $decorator = null, $field = null)
{
if (!$this->model) {
$this->model = new \atk4\ui\misc\ProxyModel();
}
return $this->layout->addField($name, $decorator, $field);
} | [
"public",
"function",
"addField",
"(",
"$",
"name",
",",
"$",
"decorator",
"=",
"null",
",",
"$",
"field",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"model",
")",
"{",
"$",
"this",
"->",
"model",
"=",
"new",
"\\",
"atk4",
"\\",
"ui",
"\\",
"misc",
"\\",
"ProxyModel",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"layout",
"->",
"addField",
"(",
"$",
"name",
",",
"$",
"decorator",
",",
"$",
"field",
")",
";",
"}"
] | Add field into current layout. If no layout, create one. If no model, create blank one.
@param string|null $name
@param array|string|object|null $decorator
@param array|string|object|null $field
@return FormField\Generic | [
"Add",
"field",
"into",
"current",
"layout",
".",
"If",
"no",
"layout",
"create",
"one",
".",
"If",
"no",
"model",
"create",
"blank",
"one",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Form.php#L317-L324 | train |
atk4/ui | src/Form.php | Form.addFields | public function addFields($fields)
{
foreach ($fields as $field) {
if (is_array($field)) {
$this->addField(...$field);
} else {
$this->addField($field);
}
}
return $this;
} | php | public function addFields($fields)
{
foreach ($fields as $field) {
if (is_array($field)) {
$this->addField(...$field);
} else {
$this->addField($field);
}
}
return $this;
} | [
"public",
"function",
"addFields",
"(",
"$",
"fields",
")",
"{",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"field",
")",
")",
"{",
"$",
"this",
"->",
"addField",
"(",
"...",
"$",
"field",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"addField",
"(",
"$",
"field",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Add more than one field in one shot.
@param array $fields
@return $this | [
"Add",
"more",
"than",
"one",
"field",
"in",
"one",
"shot",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Form.php#L333-L344 | train |
atk4/ui | src/Form.php | Form.loadPOST | public function loadPOST()
{
$post = $_POST;
$this->hook('loadPOST', [&$post]);
$errors = [];
foreach ($this->fields as $key => $field) {
try {
$value = isset($post[$key]) ? $post[$key] : null;
// save field value only if field was editable in form at all
if (!$field->readonly && !$field->disabled) {
$this->model[$key] = $this->app->ui_persistence->typecastLoadField($field->field, $value);
}
} catch (\atk4\core\Exception $e) {
$errors[$key] = $e->getMessage();
}
}
if ($errors) {
throw new \atk4\data\ValidationException($errors);
}
} | php | public function loadPOST()
{
$post = $_POST;
$this->hook('loadPOST', [&$post]);
$errors = [];
foreach ($this->fields as $key => $field) {
try {
$value = isset($post[$key]) ? $post[$key] : null;
// save field value only if field was editable in form at all
if (!$field->readonly && !$field->disabled) {
$this->model[$key] = $this->app->ui_persistence->typecastLoadField($field->field, $value);
}
} catch (\atk4\core\Exception $e) {
$errors[$key] = $e->getMessage();
}
}
if ($errors) {
throw new \atk4\data\ValidationException($errors);
}
} | [
"public",
"function",
"loadPOST",
"(",
")",
"{",
"$",
"post",
"=",
"$",
"_POST",
";",
"$",
"this",
"->",
"hook",
"(",
"'loadPOST'",
",",
"[",
"&",
"$",
"post",
"]",
")",
";",
"$",
"errors",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"fields",
"as",
"$",
"key",
"=>",
"$",
"field",
")",
"{",
"try",
"{",
"$",
"value",
"=",
"isset",
"(",
"$",
"post",
"[",
"$",
"key",
"]",
")",
"?",
"$",
"post",
"[",
"$",
"key",
"]",
":",
"null",
";",
"// save field value only if field was editable in form at all",
"if",
"(",
"!",
"$",
"field",
"->",
"readonly",
"&&",
"!",
"$",
"field",
"->",
"disabled",
")",
"{",
"$",
"this",
"->",
"model",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"app",
"->",
"ui_persistence",
"->",
"typecastLoadField",
"(",
"$",
"field",
"->",
"field",
",",
"$",
"value",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"atk4",
"\\",
"core",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"errors",
"[",
"$",
"key",
"]",
"=",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"}",
"}",
"if",
"(",
"$",
"errors",
")",
"{",
"throw",
"new",
"\\",
"atk4",
"\\",
"data",
"\\",
"ValidationException",
"(",
"$",
"errors",
")",
";",
"}",
"}"
] | Looks inside the POST of the request and loads it into a current model. | [
"Looks",
"inside",
"the",
"POST",
"of",
"the",
"request",
"and",
"loads",
"it",
"into",
"a",
"current",
"model",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Form.php#L476-L499 | train |
atk4/ui | src/Form.php | Form.ajaxSubmit | public function ajaxSubmit()
{
$this->_add($cb = new jsCallback(), ['desired_name' => 'submit', 'postTrigger' => true]);
$this->add(new View(['element' => 'input']))
->setAttr('name', $cb->postTrigger)
->setAttr('value', 'submit')
->setStyle(['display' => 'none']);
$cb->set(function () {
$caught = function ($e, $useWindow) {
$html = '<div class="header"> '.
htmlspecialchars(get_class($e)).
' </div> <div class="content"> '.
($e instanceof \atk4\core\Exception ? $e->getHTML() : nl2br(htmlspecialchars($e->getMessage()))).
' </div>';
$this->app->terminate(json_encode(['success' => false, 'message' => $html, 'useWindow' => $useWindow]));
};
try {
$this->loadPOST();
ob_start();
$response = $this->hook('submit');
$output = ob_get_clean();
if ($output) {
$message = new Message('Direct Output Detected');
$message->init();
$message->addClass('error');
$message->text->set($output);
return $message;
}
if (!$response) {
if (!$this->model instanceof \atk4\ui\misc\ProxyModel) {
$this->model->save();
return $this->success('Form data has been saved');
}
return new jsExpression('console.log([])', ['Form submission is not handled']);
}
} catch (\atk4\data\ValidationException $val) {
$response = [];
foreach ($val->errors as $field => $error) {
$response[] = $this->error($field, $error);
}
return $response;
} catch (\Error $e) {
return $caught($e, false);
} catch (\Exception $e) {
return $caught($e, true);
}
return $response;
});
//var_dump($cb->getURL());
$this->js(true)
->api(array_merge(['url' => $cb->getJSURL(), 'method' => 'POST', 'serializeForm' => true], $this->apiConfig))
->form(array_merge(['inline' => true, 'on' => 'blur'], $this->formConfig));
$this->on('change', 'input', $this->js()->form('remove prompt', new jsExpression('$(this).attr("name")')));
} | php | public function ajaxSubmit()
{
$this->_add($cb = new jsCallback(), ['desired_name' => 'submit', 'postTrigger' => true]);
$this->add(new View(['element' => 'input']))
->setAttr('name', $cb->postTrigger)
->setAttr('value', 'submit')
->setStyle(['display' => 'none']);
$cb->set(function () {
$caught = function ($e, $useWindow) {
$html = '<div class="header"> '.
htmlspecialchars(get_class($e)).
' </div> <div class="content"> '.
($e instanceof \atk4\core\Exception ? $e->getHTML() : nl2br(htmlspecialchars($e->getMessage()))).
' </div>';
$this->app->terminate(json_encode(['success' => false, 'message' => $html, 'useWindow' => $useWindow]));
};
try {
$this->loadPOST();
ob_start();
$response = $this->hook('submit');
$output = ob_get_clean();
if ($output) {
$message = new Message('Direct Output Detected');
$message->init();
$message->addClass('error');
$message->text->set($output);
return $message;
}
if (!$response) {
if (!$this->model instanceof \atk4\ui\misc\ProxyModel) {
$this->model->save();
return $this->success('Form data has been saved');
}
return new jsExpression('console.log([])', ['Form submission is not handled']);
}
} catch (\atk4\data\ValidationException $val) {
$response = [];
foreach ($val->errors as $field => $error) {
$response[] = $this->error($field, $error);
}
return $response;
} catch (\Error $e) {
return $caught($e, false);
} catch (\Exception $e) {
return $caught($e, true);
}
return $response;
});
//var_dump($cb->getURL());
$this->js(true)
->api(array_merge(['url' => $cb->getJSURL(), 'method' => 'POST', 'serializeForm' => true], $this->apiConfig))
->form(array_merge(['inline' => true, 'on' => 'blur'], $this->formConfig));
$this->on('change', 'input', $this->js()->form('remove prompt', new jsExpression('$(this).attr("name")')));
} | [
"public",
"function",
"ajaxSubmit",
"(",
")",
"{",
"$",
"this",
"->",
"_add",
"(",
"$",
"cb",
"=",
"new",
"jsCallback",
"(",
")",
",",
"[",
"'desired_name'",
"=>",
"'submit'",
",",
"'postTrigger'",
"=>",
"true",
"]",
")",
";",
"$",
"this",
"->",
"add",
"(",
"new",
"View",
"(",
"[",
"'element'",
"=>",
"'input'",
"]",
")",
")",
"->",
"setAttr",
"(",
"'name'",
",",
"$",
"cb",
"->",
"postTrigger",
")",
"->",
"setAttr",
"(",
"'value'",
",",
"'submit'",
")",
"->",
"setStyle",
"(",
"[",
"'display'",
"=>",
"'none'",
"]",
")",
";",
"$",
"cb",
"->",
"set",
"(",
"function",
"(",
")",
"{",
"$",
"caught",
"=",
"function",
"(",
"$",
"e",
",",
"$",
"useWindow",
")",
"{",
"$",
"html",
"=",
"'<div class=\"header\"> '",
".",
"htmlspecialchars",
"(",
"get_class",
"(",
"$",
"e",
")",
")",
".",
"' </div> <div class=\"content\"> '",
".",
"(",
"$",
"e",
"instanceof",
"\\",
"atk4",
"\\",
"core",
"\\",
"Exception",
"?",
"$",
"e",
"->",
"getHTML",
"(",
")",
":",
"nl2br",
"(",
"htmlspecialchars",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
")",
")",
".",
"' </div>'",
";",
"$",
"this",
"->",
"app",
"->",
"terminate",
"(",
"json_encode",
"(",
"[",
"'success'",
"=>",
"false",
",",
"'message'",
"=>",
"$",
"html",
",",
"'useWindow'",
"=>",
"$",
"useWindow",
"]",
")",
")",
";",
"}",
";",
"try",
"{",
"$",
"this",
"->",
"loadPOST",
"(",
")",
";",
"ob_start",
"(",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"hook",
"(",
"'submit'",
")",
";",
"$",
"output",
"=",
"ob_get_clean",
"(",
")",
";",
"if",
"(",
"$",
"output",
")",
"{",
"$",
"message",
"=",
"new",
"Message",
"(",
"'Direct Output Detected'",
")",
";",
"$",
"message",
"->",
"init",
"(",
")",
";",
"$",
"message",
"->",
"addClass",
"(",
"'error'",
")",
";",
"$",
"message",
"->",
"text",
"->",
"set",
"(",
"$",
"output",
")",
";",
"return",
"$",
"message",
";",
"}",
"if",
"(",
"!",
"$",
"response",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"model",
"instanceof",
"\\",
"atk4",
"\\",
"ui",
"\\",
"misc",
"\\",
"ProxyModel",
")",
"{",
"$",
"this",
"->",
"model",
"->",
"save",
"(",
")",
";",
"return",
"$",
"this",
"->",
"success",
"(",
"'Form data has been saved'",
")",
";",
"}",
"return",
"new",
"jsExpression",
"(",
"'console.log([])'",
",",
"[",
"'Form submission is not handled'",
"]",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"atk4",
"\\",
"data",
"\\",
"ValidationException",
"$",
"val",
")",
"{",
"$",
"response",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"val",
"->",
"errors",
"as",
"$",
"field",
"=>",
"$",
"error",
")",
"{",
"$",
"response",
"[",
"]",
"=",
"$",
"this",
"->",
"error",
"(",
"$",
"field",
",",
"$",
"error",
")",
";",
"}",
"return",
"$",
"response",
";",
"}",
"catch",
"(",
"\\",
"Error",
"$",
"e",
")",
"{",
"return",
"$",
"caught",
"(",
"$",
"e",
",",
"false",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"return",
"$",
"caught",
"(",
"$",
"e",
",",
"true",
")",
";",
"}",
"return",
"$",
"response",
";",
"}",
")",
";",
"//var_dump($cb->getURL());",
"$",
"this",
"->",
"js",
"(",
"true",
")",
"->",
"api",
"(",
"array_merge",
"(",
"[",
"'url'",
"=>",
"$",
"cb",
"->",
"getJSURL",
"(",
")",
",",
"'method'",
"=>",
"'POST'",
",",
"'serializeForm'",
"=>",
"true",
"]",
",",
"$",
"this",
"->",
"apiConfig",
")",
")",
"->",
"form",
"(",
"array_merge",
"(",
"[",
"'inline'",
"=>",
"true",
",",
"'on'",
"=>",
"'blur'",
"]",
",",
"$",
"this",
"->",
"formConfig",
")",
")",
";",
"$",
"this",
"->",
"on",
"(",
"'change'",
",",
"'input'",
",",
"$",
"this",
"->",
"js",
"(",
")",
"->",
"form",
"(",
"'remove prompt'",
",",
"new",
"jsExpression",
"(",
"'$(this).attr(\"name\")'",
")",
")",
")",
";",
"}"
] | Does ajax submit. | [
"Does",
"ajax",
"submit",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Form.php#L547-L612 | train |
atk4/ui | src/Text.php | Text.addParagraph | public function addParagraph($text)
{
$this->content .= isset($this->app)
? $this->app->getTag('p', $text)
: '<p>'.htmlspecialchars($text).'</p>';
return $this;
} | php | public function addParagraph($text)
{
$this->content .= isset($this->app)
? $this->app->getTag('p', $text)
: '<p>'.htmlspecialchars($text).'</p>';
return $this;
} | [
"public",
"function",
"addParagraph",
"(",
"$",
"text",
")",
"{",
"$",
"this",
"->",
"content",
".=",
"isset",
"(",
"$",
"this",
"->",
"app",
")",
"?",
"$",
"this",
"->",
"app",
"->",
"getTag",
"(",
"'p'",
",",
"$",
"text",
")",
":",
"'<p>'",
".",
"htmlspecialchars",
"(",
"$",
"text",
")",
".",
"'</p>'",
";",
"return",
"$",
"this",
";",
"}"
] | Adds HTML paragraph.
@param string $text
@return $this | [
"Adds",
"HTML",
"paragraph",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/Text.php#L31-L38 | train |
atk4/ui | src/TableColumn/Image.php | Image.getDataCellTemplate | public function getDataCellTemplate(\atk4\data\Field $f = null)
{
$caption = $f ? $f->getCaption() : $this->short_name;
return '<img src="'.parent::getDataCellTemplate($f).'" alt="'.$caption.'" border="0" />';
} | php | public function getDataCellTemplate(\atk4\data\Field $f = null)
{
$caption = $f ? $f->getCaption() : $this->short_name;
return '<img src="'.parent::getDataCellTemplate($f).'" alt="'.$caption.'" border="0" />';
} | [
"public",
"function",
"getDataCellTemplate",
"(",
"\\",
"atk4",
"\\",
"data",
"\\",
"Field",
"$",
"f",
"=",
"null",
")",
"{",
"$",
"caption",
"=",
"$",
"f",
"?",
"$",
"f",
"->",
"getCaption",
"(",
")",
":",
"$",
"this",
"->",
"short_name",
";",
"return",
"'<img src=\"'",
".",
"parent",
"::",
"getDataCellTemplate",
"(",
"$",
"f",
")",
".",
"'\" alt=\"'",
".",
"$",
"caption",
".",
"'\" border=\"0\" />'",
";",
"}"
] | Extend parent method.
@param \atk4\data\Field $f
@return string | [
"Extend",
"parent",
"method",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/TableColumn/Image.php#L24-L29 | train |
atk4/ui | src/jsModal.php | jsModal.setOption | public function setOption($options, $value = null)
{
if (is_array($options)) {
foreach ($options as $key => $value) {
$this->args['arg'][$key] = $value;
}
} else {
$this->args['arg'][$options] = $value;
}
return $this;
} | php | public function setOption($options, $value = null)
{
if (is_array($options)) {
foreach ($options as $key => $value) {
$this->args['arg'][$key] = $value;
}
} else {
$this->args['arg'][$options] = $value;
}
return $this;
} | [
"public",
"function",
"setOption",
"(",
"$",
"options",
",",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"options",
")",
")",
"{",
"foreach",
"(",
"$",
"options",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"args",
"[",
"'arg'",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"args",
"[",
"'arg'",
"]",
"[",
"$",
"options",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set additionnal option for this jsModal.
Valuable option are headerCss and label:
'headerCss' -> customize css class name for the header.
ex: changing color text for header
$jsModal->setOption('headerCss', 'ui blue header');
'label' -> set the text loader value.
ex: changing default 'Loading...' for no text
$jsModal->setOption('label', '');
You can set option individually or supply an array.
@param $options
@param null $value
@return $this | [
"Set",
"additionnal",
"option",
"for",
"this",
"jsModal",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/jsModal.php#L50-L61 | train |
atk4/ui | demos/popup.php | ItemShelf.linkCart | public function linkCart(Cart $cart, $jsAction = null)
{
$this->on('click', '.item', function ($a, $b) use ($cart, $jsAction) {
$cart->addItem($b);
return $jsAction;
}, [(new \atk4\ui\jQuery())->text()]);
} | php | public function linkCart(Cart $cart, $jsAction = null)
{
$this->on('click', '.item', function ($a, $b) use ($cart, $jsAction) {
$cart->addItem($b);
return $jsAction;
}, [(new \atk4\ui\jQuery())->text()]);
} | [
"public",
"function",
"linkCart",
"(",
"Cart",
"$",
"cart",
",",
"$",
"jsAction",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"on",
"(",
"'click'",
",",
"'.item'",
",",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"use",
"(",
"$",
"cart",
",",
"$",
"jsAction",
")",
"{",
"$",
"cart",
"->",
"addItem",
"(",
"$",
"b",
")",
";",
"return",
"$",
"jsAction",
";",
"}",
",",
"[",
"(",
"new",
"\\",
"atk4",
"\\",
"ui",
"\\",
"jQuery",
"(",
")",
")",
"->",
"text",
"(",
")",
"]",
")",
";",
"}"
] | Associate your shelf with cart, so that when item is clicked, the content of a
cart is updated.
Also - you can supply jsAction to execute when this happens. | [
"Associate",
"your",
"shelf",
"with",
"cart",
"so",
"that",
"when",
"item",
"is",
"clicked",
"the",
"content",
"of",
"a",
"cart",
"is",
"updated",
"."
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/demos/popup.php#L117-L124 | train |
atk4/ui | src/SSE.php | SSE.init | public function init()
{
if ($this->runEvent) {
$chain = new jsChain();
$this->app->html->js(true, $chain->atkServerEvent(
['uri' => $this->getUrl()]
));
$this->isRunning = true;
}
$this->_initialized = true;
} | php | public function init()
{
if ($this->runEvent) {
$chain = new jsChain();
$this->app->html->js(true, $chain->atkServerEvent(
['uri' => $this->getUrl()]
));
$this->isRunning = true;
}
$this->_initialized = true;
} | [
"public",
"function",
"init",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"runEvent",
")",
"{",
"$",
"chain",
"=",
"new",
"jsChain",
"(",
")",
";",
"$",
"this",
"->",
"app",
"->",
"html",
"->",
"js",
"(",
"true",
",",
"$",
"chain",
"->",
"atkServerEvent",
"(",
"[",
"'uri'",
"=>",
"$",
"this",
"->",
"getUrl",
"(",
")",
"]",
")",
")",
";",
"$",
"this",
"->",
"isRunning",
"=",
"true",
";",
"}",
"$",
"this",
"->",
"_initialized",
"=",
"true",
";",
"}"
] | Allow chunked encoding | [
"Allow",
"chunked",
"encoding"
] | f31c6674ff80999e29dd95375d4f3588bfdbad00 | https://github.com/atk4/ui/blob/f31c6674ff80999e29dd95375d4f3588bfdbad00/src/SSE.php#L34-L45 | train |
mdmsoft/yii2-admin | controllers/UserController.php | UserController.actionRequestPasswordReset | public function actionRequestPasswordReset()
{
$model = new PasswordResetRequest();
if ($model->load(Yii::$app->getRequest()->post()) && $model->validate()) {
if ($model->sendEmail()) {
Yii::$app->getSession()->setFlash('success', 'Check your email for further instructions.');
return $this->goHome();
} else {
Yii::$app->getSession()->setFlash('error', 'Sorry, we are unable to reset password for email provided.');
}
}
return $this->render('requestPasswordResetToken', [
'model' => $model,
]);
} | php | public function actionRequestPasswordReset()
{
$model = new PasswordResetRequest();
if ($model->load(Yii::$app->getRequest()->post()) && $model->validate()) {
if ($model->sendEmail()) {
Yii::$app->getSession()->setFlash('success', 'Check your email for further instructions.');
return $this->goHome();
} else {
Yii::$app->getSession()->setFlash('error', 'Sorry, we are unable to reset password for email provided.');
}
}
return $this->render('requestPasswordResetToken', [
'model' => $model,
]);
} | [
"public",
"function",
"actionRequestPasswordReset",
"(",
")",
"{",
"$",
"model",
"=",
"new",
"PasswordResetRequest",
"(",
")",
";",
"if",
"(",
"$",
"model",
"->",
"load",
"(",
"Yii",
"::",
"$",
"app",
"->",
"getRequest",
"(",
")",
"->",
"post",
"(",
")",
")",
"&&",
"$",
"model",
"->",
"validate",
"(",
")",
")",
"{",
"if",
"(",
"$",
"model",
"->",
"sendEmail",
"(",
")",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"getSession",
"(",
")",
"->",
"setFlash",
"(",
"'success'",
",",
"'Check your email for further instructions.'",
")",
";",
"return",
"$",
"this",
"->",
"goHome",
"(",
")",
";",
"}",
"else",
"{",
"Yii",
"::",
"$",
"app",
"->",
"getSession",
"(",
")",
"->",
"setFlash",
"(",
"'error'",
",",
"'Sorry, we are unable to reset password for email provided.'",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"render",
"(",
"'requestPasswordResetToken'",
",",
"[",
"'model'",
"=>",
"$",
"model",
",",
"]",
")",
";",
"}"
] | Request reset password
@return string | [
"Request",
"reset",
"password"
] | 59e65542b1dc1abcf14c62588ea4ae128e08036c | https://github.com/mdmsoft/yii2-admin/blob/59e65542b1dc1abcf14c62588ea4ae128e08036c/controllers/UserController.php#L166-L182 | train |
mdmsoft/yii2-admin | models/Route.php | Route.getRoutePrefix | public function getRoutePrefix()
{
if (!$this->_routePrefix) {
$this->_routePrefix = Configs::instance()->advanced ? self::PREFIX_ADVANCED : self::PREFIX_BASIC;
}
return $this->_routePrefix;
} | php | public function getRoutePrefix()
{
if (!$this->_routePrefix) {
$this->_routePrefix = Configs::instance()->advanced ? self::PREFIX_ADVANCED : self::PREFIX_BASIC;
}
return $this->_routePrefix;
} | [
"public",
"function",
"getRoutePrefix",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_routePrefix",
")",
"{",
"$",
"this",
"->",
"_routePrefix",
"=",
"Configs",
"::",
"instance",
"(",
")",
"->",
"advanced",
"?",
"self",
"::",
"PREFIX_ADVANCED",
":",
"self",
"::",
"PREFIX_BASIC",
";",
"}",
"return",
"$",
"this",
"->",
"_routePrefix",
";",
"}"
] | Returns route prefix depending on the configuration.
@return string Route prefix | [
"Returns",
"route",
"prefix",
"depending",
"on",
"the",
"configuration",
"."
] | 59e65542b1dc1abcf14c62588ea4ae128e08036c | https://github.com/mdmsoft/yii2-admin/blob/59e65542b1dc1abcf14c62588ea4ae128e08036c/models/Route.php#L88-L94 | train |
mdmsoft/yii2-admin | models/Route.php | Route.getPermissionName | public function getPermissionName($route)
{
if (self::PREFIX_BASIC == $this->routePrefix) {
return self::PREFIX_BASIC . trim($route, self::PREFIX_BASIC);
} else {
return self::PREFIX_ADVANCED . ltrim(trim($route, self::PREFIX_BASIC), self::PREFIX_ADVANCED);
}
} | php | public function getPermissionName($route)
{
if (self::PREFIX_BASIC == $this->routePrefix) {
return self::PREFIX_BASIC . trim($route, self::PREFIX_BASIC);
} else {
return self::PREFIX_ADVANCED . ltrim(trim($route, self::PREFIX_BASIC), self::PREFIX_ADVANCED);
}
} | [
"public",
"function",
"getPermissionName",
"(",
"$",
"route",
")",
"{",
"if",
"(",
"self",
"::",
"PREFIX_BASIC",
"==",
"$",
"this",
"->",
"routePrefix",
")",
"{",
"return",
"self",
"::",
"PREFIX_BASIC",
".",
"trim",
"(",
"$",
"route",
",",
"self",
"::",
"PREFIX_BASIC",
")",
";",
"}",
"else",
"{",
"return",
"self",
"::",
"PREFIX_ADVANCED",
".",
"ltrim",
"(",
"trim",
"(",
"$",
"route",
",",
"self",
"::",
"PREFIX_BASIC",
")",
",",
"self",
"::",
"PREFIX_ADVANCED",
")",
";",
"}",
"}"
] | Returns the correct permission name depending on the configuration.
@param string $route Route
@return string Permission name | [
"Returns",
"the",
"correct",
"permission",
"name",
"depending",
"on",
"the",
"configuration",
"."
] | 59e65542b1dc1abcf14c62588ea4ae128e08036c | https://github.com/mdmsoft/yii2-admin/blob/59e65542b1dc1abcf14c62588ea4ae128e08036c/models/Route.php#L101-L108 | train |
mdmsoft/yii2-admin | models/Route.php | Route.getControllerActions | protected function getControllerActions($type, $id, $module, &$result)
{
$token = "Create controller with cofig=" . VarDumper::dumpAsString($type) . " and id='$id'";
Yii::beginProfile($token, __METHOD__);
try {
/* @var $controller \yii\base\Controller */
$controller = Yii::createObject($type, [$id, $module]);
$this->getActionRoutes($controller, $result);
$all = "/{$controller->uniqueId}/*";
$result[$all] = $all;
} catch (\Exception $exc) {
Yii::error($exc->getMessage(), __METHOD__);
}
Yii::endProfile($token, __METHOD__);
} | php | protected function getControllerActions($type, $id, $module, &$result)
{
$token = "Create controller with cofig=" . VarDumper::dumpAsString($type) . " and id='$id'";
Yii::beginProfile($token, __METHOD__);
try {
/* @var $controller \yii\base\Controller */
$controller = Yii::createObject($type, [$id, $module]);
$this->getActionRoutes($controller, $result);
$all = "/{$controller->uniqueId}/*";
$result[$all] = $all;
} catch (\Exception $exc) {
Yii::error($exc->getMessage(), __METHOD__);
}
Yii::endProfile($token, __METHOD__);
} | [
"protected",
"function",
"getControllerActions",
"(",
"$",
"type",
",",
"$",
"id",
",",
"$",
"module",
",",
"&",
"$",
"result",
")",
"{",
"$",
"token",
"=",
"\"Create controller with cofig=\"",
".",
"VarDumper",
"::",
"dumpAsString",
"(",
"$",
"type",
")",
".",
"\" and id='$id'\"",
";",
"Yii",
"::",
"beginProfile",
"(",
"$",
"token",
",",
"__METHOD__",
")",
";",
"try",
"{",
"/* @var $controller \\yii\\base\\Controller */",
"$",
"controller",
"=",
"Yii",
"::",
"createObject",
"(",
"$",
"type",
",",
"[",
"$",
"id",
",",
"$",
"module",
"]",
")",
";",
"$",
"this",
"->",
"getActionRoutes",
"(",
"$",
"controller",
",",
"$",
"result",
")",
";",
"$",
"all",
"=",
"\"/{$controller->uniqueId}/*\"",
";",
"$",
"result",
"[",
"$",
"all",
"]",
"=",
"$",
"all",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"exc",
")",
"{",
"Yii",
"::",
"error",
"(",
"$",
"exc",
"->",
"getMessage",
"(",
")",
",",
"__METHOD__",
")",
";",
"}",
"Yii",
"::",
"endProfile",
"(",
"$",
"token",
",",
"__METHOD__",
")",
";",
"}"
] | Get list action of controller
@param mixed $type
@param string $id
@param \yii\base\Module $module
@param string $result | [
"Get",
"list",
"action",
"of",
"controller"
] | 59e65542b1dc1abcf14c62588ea4ae128e08036c | https://github.com/mdmsoft/yii2-admin/blob/59e65542b1dc1abcf14c62588ea4ae128e08036c/models/Route.php#L276-L290 | train |
mdmsoft/yii2-admin | models/Route.php | Route.getActionRoutes | protected function getActionRoutes($controller, &$result)
{
$token = "Get actions of controller '" . $controller->uniqueId . "'";
Yii::beginProfile($token, __METHOD__);
try {
$prefix = '/' . $controller->uniqueId . '/';
foreach ($controller->actions() as $id => $value) {
$result[$prefix . $id] = $prefix . $id;
}
$class = new \ReflectionClass($controller);
foreach ($class->getMethods() as $method) {
$name = $method->getName();
if ($method->isPublic() && !$method->isStatic() && strpos($name, 'action') === 0 && $name !== 'actions') {
$name = strtolower(preg_replace('/(?<![A-Z])[A-Z]/', ' \0', substr($name, 6)));
$id = $prefix . ltrim(str_replace(' ', '-', $name), '-');
$result[$id] = $id;
}
}
} catch (\Exception $exc) {
Yii::error($exc->getMessage(), __METHOD__);
}
Yii::endProfile($token, __METHOD__);
} | php | protected function getActionRoutes($controller, &$result)
{
$token = "Get actions of controller '" . $controller->uniqueId . "'";
Yii::beginProfile($token, __METHOD__);
try {
$prefix = '/' . $controller->uniqueId . '/';
foreach ($controller->actions() as $id => $value) {
$result[$prefix . $id] = $prefix . $id;
}
$class = new \ReflectionClass($controller);
foreach ($class->getMethods() as $method) {
$name = $method->getName();
if ($method->isPublic() && !$method->isStatic() && strpos($name, 'action') === 0 && $name !== 'actions') {
$name = strtolower(preg_replace('/(?<![A-Z])[A-Z]/', ' \0', substr($name, 6)));
$id = $prefix . ltrim(str_replace(' ', '-', $name), '-');
$result[$id] = $id;
}
}
} catch (\Exception $exc) {
Yii::error($exc->getMessage(), __METHOD__);
}
Yii::endProfile($token, __METHOD__);
} | [
"protected",
"function",
"getActionRoutes",
"(",
"$",
"controller",
",",
"&",
"$",
"result",
")",
"{",
"$",
"token",
"=",
"\"Get actions of controller '\"",
".",
"$",
"controller",
"->",
"uniqueId",
".",
"\"'\"",
";",
"Yii",
"::",
"beginProfile",
"(",
"$",
"token",
",",
"__METHOD__",
")",
";",
"try",
"{",
"$",
"prefix",
"=",
"'/'",
".",
"$",
"controller",
"->",
"uniqueId",
".",
"'/'",
";",
"foreach",
"(",
"$",
"controller",
"->",
"actions",
"(",
")",
"as",
"$",
"id",
"=>",
"$",
"value",
")",
"{",
"$",
"result",
"[",
"$",
"prefix",
".",
"$",
"id",
"]",
"=",
"$",
"prefix",
".",
"$",
"id",
";",
"}",
"$",
"class",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"controller",
")",
";",
"foreach",
"(",
"$",
"class",
"->",
"getMethods",
"(",
")",
"as",
"$",
"method",
")",
"{",
"$",
"name",
"=",
"$",
"method",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"$",
"method",
"->",
"isPublic",
"(",
")",
"&&",
"!",
"$",
"method",
"->",
"isStatic",
"(",
")",
"&&",
"strpos",
"(",
"$",
"name",
",",
"'action'",
")",
"===",
"0",
"&&",
"$",
"name",
"!==",
"'actions'",
")",
"{",
"$",
"name",
"=",
"strtolower",
"(",
"preg_replace",
"(",
"'/(?<![A-Z])[A-Z]/'",
",",
"' \\0'",
",",
"substr",
"(",
"$",
"name",
",",
"6",
")",
")",
")",
";",
"$",
"id",
"=",
"$",
"prefix",
".",
"ltrim",
"(",
"str_replace",
"(",
"' '",
",",
"'-'",
",",
"$",
"name",
")",
",",
"'-'",
")",
";",
"$",
"result",
"[",
"$",
"id",
"]",
"=",
"$",
"id",
";",
"}",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"exc",
")",
"{",
"Yii",
"::",
"error",
"(",
"$",
"exc",
"->",
"getMessage",
"(",
")",
",",
"__METHOD__",
")",
";",
"}",
"Yii",
"::",
"endProfile",
"(",
"$",
"token",
",",
"__METHOD__",
")",
";",
"}"
] | Get route of action
@param \yii\base\Controller $controller
@param array $result all controller action. | [
"Get",
"route",
"of",
"action"
] | 59e65542b1dc1abcf14c62588ea4ae128e08036c | https://github.com/mdmsoft/yii2-admin/blob/59e65542b1dc1abcf14c62588ea4ae128e08036c/models/Route.php#L297-L319 | train |
mdmsoft/yii2-admin | Module.php | Module.getMenus | public function getMenus()
{
if ($this->_normalizeMenus === null) {
$mid = '/' . $this->getUniqueId() . '/';
// resolve core menus
$this->_normalizeMenus = [];
$config = components\Configs::instance();
$conditions = [
'user' => $config->db && $config->db->schema->getTableSchema($config->userTable),
'assignment' => ($userClass = Yii::$app->getUser()->identityClass) && is_subclass_of($userClass, 'yii\db\BaseActiveRecord'),
'menu' => $config->db && $config->db->schema->getTableSchema($config->menuTable),
];
foreach ($this->_coreItems as $id => $lable) {
if (!isset($conditions[$id]) || $conditions[$id]) {
$this->_normalizeMenus[$id] = ['label' => Yii::t('rbac-admin', $lable), 'url' => [$mid . $id]];
}
}
foreach (array_keys($this->controllerMap) as $id) {
$this->_normalizeMenus[$id] = ['label' => Yii::t('rbac-admin', Inflector::humanize($id)), 'url' => [$mid . $id]];
}
// user configure menus
foreach ($this->_menus as $id => $value) {
if (empty($value)) {
unset($this->_normalizeMenus[$id]);
continue;
}
if (is_string($value)) {
$value = ['label' => $value];
}
$this->_normalizeMenus[$id] = isset($this->_normalizeMenus[$id]) ? array_merge($this->_normalizeMenus[$id], $value)
: $value;
if (!isset($this->_normalizeMenus[$id]['url'])) {
$this->_normalizeMenus[$id]['url'] = [$mid . $id];
}
}
}
return $this->_normalizeMenus;
} | php | public function getMenus()
{
if ($this->_normalizeMenus === null) {
$mid = '/' . $this->getUniqueId() . '/';
// resolve core menus
$this->_normalizeMenus = [];
$config = components\Configs::instance();
$conditions = [
'user' => $config->db && $config->db->schema->getTableSchema($config->userTable),
'assignment' => ($userClass = Yii::$app->getUser()->identityClass) && is_subclass_of($userClass, 'yii\db\BaseActiveRecord'),
'menu' => $config->db && $config->db->schema->getTableSchema($config->menuTable),
];
foreach ($this->_coreItems as $id => $lable) {
if (!isset($conditions[$id]) || $conditions[$id]) {
$this->_normalizeMenus[$id] = ['label' => Yii::t('rbac-admin', $lable), 'url' => [$mid . $id]];
}
}
foreach (array_keys($this->controllerMap) as $id) {
$this->_normalizeMenus[$id] = ['label' => Yii::t('rbac-admin', Inflector::humanize($id)), 'url' => [$mid . $id]];
}
// user configure menus
foreach ($this->_menus as $id => $value) {
if (empty($value)) {
unset($this->_normalizeMenus[$id]);
continue;
}
if (is_string($value)) {
$value = ['label' => $value];
}
$this->_normalizeMenus[$id] = isset($this->_normalizeMenus[$id]) ? array_merge($this->_normalizeMenus[$id], $value)
: $value;
if (!isset($this->_normalizeMenus[$id]['url'])) {
$this->_normalizeMenus[$id]['url'] = [$mid . $id];
}
}
}
return $this->_normalizeMenus;
} | [
"public",
"function",
"getMenus",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_normalizeMenus",
"===",
"null",
")",
"{",
"$",
"mid",
"=",
"'/'",
".",
"$",
"this",
"->",
"getUniqueId",
"(",
")",
".",
"'/'",
";",
"// resolve core menus",
"$",
"this",
"->",
"_normalizeMenus",
"=",
"[",
"]",
";",
"$",
"config",
"=",
"components",
"\\",
"Configs",
"::",
"instance",
"(",
")",
";",
"$",
"conditions",
"=",
"[",
"'user'",
"=>",
"$",
"config",
"->",
"db",
"&&",
"$",
"config",
"->",
"db",
"->",
"schema",
"->",
"getTableSchema",
"(",
"$",
"config",
"->",
"userTable",
")",
",",
"'assignment'",
"=>",
"(",
"$",
"userClass",
"=",
"Yii",
"::",
"$",
"app",
"->",
"getUser",
"(",
")",
"->",
"identityClass",
")",
"&&",
"is_subclass_of",
"(",
"$",
"userClass",
",",
"'yii\\db\\BaseActiveRecord'",
")",
",",
"'menu'",
"=>",
"$",
"config",
"->",
"db",
"&&",
"$",
"config",
"->",
"db",
"->",
"schema",
"->",
"getTableSchema",
"(",
"$",
"config",
"->",
"menuTable",
")",
",",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"_coreItems",
"as",
"$",
"id",
"=>",
"$",
"lable",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"conditions",
"[",
"$",
"id",
"]",
")",
"||",
"$",
"conditions",
"[",
"$",
"id",
"]",
")",
"{",
"$",
"this",
"->",
"_normalizeMenus",
"[",
"$",
"id",
"]",
"=",
"[",
"'label'",
"=>",
"Yii",
"::",
"t",
"(",
"'rbac-admin'",
",",
"$",
"lable",
")",
",",
"'url'",
"=>",
"[",
"$",
"mid",
".",
"$",
"id",
"]",
"]",
";",
"}",
"}",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"controllerMap",
")",
"as",
"$",
"id",
")",
"{",
"$",
"this",
"->",
"_normalizeMenus",
"[",
"$",
"id",
"]",
"=",
"[",
"'label'",
"=>",
"Yii",
"::",
"t",
"(",
"'rbac-admin'",
",",
"Inflector",
"::",
"humanize",
"(",
"$",
"id",
")",
")",
",",
"'url'",
"=>",
"[",
"$",
"mid",
".",
"$",
"id",
"]",
"]",
";",
"}",
"// user configure menus",
"foreach",
"(",
"$",
"this",
"->",
"_menus",
"as",
"$",
"id",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"_normalizeMenus",
"[",
"$",
"id",
"]",
")",
";",
"continue",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"[",
"'label'",
"=>",
"$",
"value",
"]",
";",
"}",
"$",
"this",
"->",
"_normalizeMenus",
"[",
"$",
"id",
"]",
"=",
"isset",
"(",
"$",
"this",
"->",
"_normalizeMenus",
"[",
"$",
"id",
"]",
")",
"?",
"array_merge",
"(",
"$",
"this",
"->",
"_normalizeMenus",
"[",
"$",
"id",
"]",
",",
"$",
"value",
")",
":",
"$",
"value",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_normalizeMenus",
"[",
"$",
"id",
"]",
"[",
"'url'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_normalizeMenus",
"[",
"$",
"id",
"]",
"[",
"'url'",
"]",
"=",
"[",
"$",
"mid",
".",
"$",
"id",
"]",
";",
"}",
"}",
"}",
"return",
"$",
"this",
"->",
"_normalizeMenus",
";",
"}"
] | Get available menu.
@return array | [
"Get",
"available",
"menu",
"."
] | 59e65542b1dc1abcf14c62588ea4ae128e08036c | https://github.com/mdmsoft/yii2-admin/blob/59e65542b1dc1abcf14c62588ea4ae128e08036c/Module.php#L118-L157 | train |
mdmsoft/yii2-admin | Module.php | Module.setMenus | public function setMenus($menus)
{
$this->_menus = array_merge($this->_menus, $menus);
$this->_normalizeMenus = null;
} | php | public function setMenus($menus)
{
$this->_menus = array_merge($this->_menus, $menus);
$this->_normalizeMenus = null;
} | [
"public",
"function",
"setMenus",
"(",
"$",
"menus",
")",
"{",
"$",
"this",
"->",
"_menus",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"_menus",
",",
"$",
"menus",
")",
";",
"$",
"this",
"->",
"_normalizeMenus",
"=",
"null",
";",
"}"
] | Set or add available menu.
@param array $menus | [
"Set",
"or",
"add",
"available",
"menu",
"."
] | 59e65542b1dc1abcf14c62588ea4ae128e08036c | https://github.com/mdmsoft/yii2-admin/blob/59e65542b1dc1abcf14c62588ea4ae128e08036c/Module.php#L163-L167 | train |
mdmsoft/yii2-admin | models/Assignment.php | Assignment.assign | public function assign($items)
{
$manager = Configs::authManager();
$success = 0;
foreach ($items as $name) {
try {
$item = $manager->getRole($name);
$item = $item ?: $manager->getPermission($name);
$manager->assign($item, $this->id);
$success++;
} catch (\Exception $exc) {
Yii::error($exc->getMessage(), __METHOD__);
}
}
Helper::invalidate();
return $success;
} | php | public function assign($items)
{
$manager = Configs::authManager();
$success = 0;
foreach ($items as $name) {
try {
$item = $manager->getRole($name);
$item = $item ?: $manager->getPermission($name);
$manager->assign($item, $this->id);
$success++;
} catch (\Exception $exc) {
Yii::error($exc->getMessage(), __METHOD__);
}
}
Helper::invalidate();
return $success;
} | [
"public",
"function",
"assign",
"(",
"$",
"items",
")",
"{",
"$",
"manager",
"=",
"Configs",
"::",
"authManager",
"(",
")",
";",
"$",
"success",
"=",
"0",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"name",
")",
"{",
"try",
"{",
"$",
"item",
"=",
"$",
"manager",
"->",
"getRole",
"(",
"$",
"name",
")",
";",
"$",
"item",
"=",
"$",
"item",
"?",
":",
"$",
"manager",
"->",
"getPermission",
"(",
"$",
"name",
")",
";",
"$",
"manager",
"->",
"assign",
"(",
"$",
"item",
",",
"$",
"this",
"->",
"id",
")",
";",
"$",
"success",
"++",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"exc",
")",
"{",
"Yii",
"::",
"error",
"(",
"$",
"exc",
"->",
"getMessage",
"(",
")",
",",
"__METHOD__",
")",
";",
"}",
"}",
"Helper",
"::",
"invalidate",
"(",
")",
";",
"return",
"$",
"success",
";",
"}"
] | Grands a roles from a user.
@param array $items
@return integer number of successful grand | [
"Grands",
"a",
"roles",
"from",
"a",
"user",
"."
] | 59e65542b1dc1abcf14c62588ea4ae128e08036c | https://github.com/mdmsoft/yii2-admin/blob/59e65542b1dc1abcf14c62588ea4ae128e08036c/models/Assignment.php#L41-L57 | train |
mdmsoft/yii2-admin | components/MenuHelper.php | MenuHelper.requiredParent | private static function requiredParent($assigned, &$menus)
{
$l = count($assigned);
for ($i = 0; $i < $l; $i++) {
$id = $assigned[$i];
$parent_id = $menus[$id]['parent'];
if ($parent_id !== null && !in_array($parent_id, $assigned)) {
$assigned[$l++] = $parent_id;
}
}
return $assigned;
} | php | private static function requiredParent($assigned, &$menus)
{
$l = count($assigned);
for ($i = 0; $i < $l; $i++) {
$id = $assigned[$i];
$parent_id = $menus[$id]['parent'];
if ($parent_id !== null && !in_array($parent_id, $assigned)) {
$assigned[$l++] = $parent_id;
}
}
return $assigned;
} | [
"private",
"static",
"function",
"requiredParent",
"(",
"$",
"assigned",
",",
"&",
"$",
"menus",
")",
"{",
"$",
"l",
"=",
"count",
"(",
"$",
"assigned",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"l",
";",
"$",
"i",
"++",
")",
"{",
"$",
"id",
"=",
"$",
"assigned",
"[",
"$",
"i",
"]",
";",
"$",
"parent_id",
"=",
"$",
"menus",
"[",
"$",
"id",
"]",
"[",
"'parent'",
"]",
";",
"if",
"(",
"$",
"parent_id",
"!==",
"null",
"&&",
"!",
"in_array",
"(",
"$",
"parent_id",
",",
"$",
"assigned",
")",
")",
"{",
"$",
"assigned",
"[",
"$",
"l",
"++",
"]",
"=",
"$",
"parent_id",
";",
"}",
"}",
"return",
"$",
"assigned",
";",
"}"
] | Ensure all item menu has parent.
@param array $assigned
@param array $menus
@return array | [
"Ensure",
"all",
"item",
"menu",
"has",
"parent",
"."
] | 59e65542b1dc1abcf14c62588ea4ae128e08036c | https://github.com/mdmsoft/yii2-admin/blob/59e65542b1dc1abcf14c62588ea4ae128e08036c/components/MenuHelper.php#L148-L160 | train |
mdmsoft/yii2-admin | components/Helper.php | Helper.filter | public static function filter($items, $user = null)
{
if ($user === null) {
$user = Yii::$app->getUser();
}
return static::filterRecursive($items, $user);
} | php | public static function filter($items, $user = null)
{
if ($user === null) {
$user = Yii::$app->getUser();
}
return static::filterRecursive($items, $user);
} | [
"public",
"static",
"function",
"filter",
"(",
"$",
"items",
",",
"$",
"user",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"user",
"===",
"null",
")",
"{",
"$",
"user",
"=",
"Yii",
"::",
"$",
"app",
"->",
"getUser",
"(",
")",
";",
"}",
"return",
"static",
"::",
"filterRecursive",
"(",
"$",
"items",
",",
"$",
"user",
")",
";",
"}"
] | Filter menu items
@param array $items
@param integer|User $user | [
"Filter",
"menu",
"items"
] | 59e65542b1dc1abcf14c62588ea4ae128e08036c | https://github.com/mdmsoft/yii2-admin/blob/59e65542b1dc1abcf14c62588ea4ae128e08036c/components/Helper.php#L175-L181 | train |
mdmsoft/yii2-admin | models/AuthItem.php | AuthItem.getTypeName | public static function getTypeName($type = null)
{
$result = [
Item::TYPE_PERMISSION => 'Permission',
Item::TYPE_ROLE => 'Role',
];
if ($type === null) {
return $result;
}
return $result[$type];
} | php | public static function getTypeName($type = null)
{
$result = [
Item::TYPE_PERMISSION => 'Permission',
Item::TYPE_ROLE => 'Role',
];
if ($type === null) {
return $result;
}
return $result[$type];
} | [
"public",
"static",
"function",
"getTypeName",
"(",
"$",
"type",
"=",
"null",
")",
"{",
"$",
"result",
"=",
"[",
"Item",
"::",
"TYPE_PERMISSION",
"=>",
"'Permission'",
",",
"Item",
"::",
"TYPE_ROLE",
"=>",
"'Role'",
",",
"]",
";",
"if",
"(",
"$",
"type",
"===",
"null",
")",
"{",
"return",
"$",
"result",
";",
"}",
"return",
"$",
"result",
"[",
"$",
"type",
"]",
";",
"}"
] | Get type name
@param mixed $type
@return string|array | [
"Get",
"type",
"name"
] | 59e65542b1dc1abcf14c62588ea4ae128e08036c | https://github.com/mdmsoft/yii2-admin/blob/59e65542b1dc1abcf14c62588ea4ae128e08036c/models/AuthItem.php#L285-L296 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.