In plugin default.htm
{% partial 'companies' %}
companies.htm partial
Name
Email address
{% for id, row in companies %}
{{ row.name }}
{{ row.email }}
[Block]
{% endfor %}
plugin Account.php
public function prepareVars()
{
$this->page['user'] = $this->user();
$this->page['canRegister'] = $this->canRegister();
$this->page['loginAttribute'] = $this->loginAttribute();
$this->page['loginAttributeLabel'] = $this->loginAttributeLabel();
$this->page['updateRequiresPassword'] = $this->updateRequiresPassword();
$this->page['rememberLoginMode'] = $this->rememberLoginMode();
#Log::info(json_encode($this->post_id));
if($this->page->id == 'users' && $this->user())
{
$this->onCompanies();
}
}
public function onCompanies()
{
$usr = Auth::User()->getAttributes();
$list = Array();
$all = Db::select('select * from users_allocation where slave_id = ? and blocked < 1', [$usr['id']]);
if (count($all) > 0) {
foreach ($all as $a) {
$company = Db::select('select * from users where id = ?', [$a->owner_id]);
if (count($company) > 0) {
foreach ($company as $cp) {
$cid = md5($cp->id);
$list[$cid]['user_id'] = md5($a->owner_id);
$list[$cid]['name'] = $cp->name;
$list[$cid]['email'] = $cp->email;
}
}
}
}
$this->page['companies'] = $list;
return [
'#tabs-1' => $this->renderPartial('companies')
];
}
jQuery('form').request('onUserBlock', {data: {alt: alt},});
calls onUserBlock function in Account.php
public function onUserBlock()
{
$data = post();
$id = $data['alt'];
$usr = Auth::User()->getAttributes();
$company = Db::select('select * from users_allocation where md5(owner_id) = ? and slave_id = ? and blocked = 1', [$id, $usr['id']]);
if (count($company) > 0) {
Flash::error('This company already blocked.');
return false;
}
else
{
Db::update('update users_allocation set blocked = 1 where md5(owner_id) = ? and slave_id = ?', [$id, $usr['id']]);
$this->onCompanies();
Flash::success(Lang::get(/**/'Company successfully blocked and will not able to send you invitation.'));
}
}
The problem is, that when prepareVars
calls onCompanies
on page load, then code is rendering HTML, but when onCompanies
is called from onUserBlock
, then code doesn’t re-render HTML.
Any idea why?
I tried to put $this->onCompanies();
before and after Flash::success
, but no luck.