/** * Delete page * @param \Difra\Param\AnyInt $id * @param \Difra\Param\AjaxCheckbox $confirm */ public function deleteAjaxAction(\Difra\Param\AnyInt $id, \Difra\Param\AjaxCheckbox $confirm = null) { if ($confirm and $confirm->val()) { \Difra\Plugins\CMS\Page::get($id->val())->delete(); Ajaxer::close(); Ajaxer::redirect('/adm/content/pages'); return; } $page = \Difra\Plugins\CMS\Page::get($id->val()); Ajaxer::display('<span>' . \Difra\Locales::get('cms/adm/delete-page-confirm-1') . $page->getTitle() . \Difra\Locales::get('cms/adm/delete-page-confirm-2') . '</span>' . '<form action="/adm/content/pages/delete/' . $id . '" method="post" class="ajaxer">' . '<input type="hidden" name="confirm" value="1"/>' . '<input type="submit" value="Да"/>' . '<a href="#" onclick="ajaxer.close(this)" class="button">Нет</a>' . '</form>'); }
/** * @param \Difra\Param\AnyInt $id * @param \Difra\Param\AjaxInt $confirm */ public function delAjaxAction(\Difra\Param\AnyInt $id, \Difra\Param\AjaxInt $confirm = null) { if (!($snippet = \Difra\Plugins\CMS\Snippet::getById($id->val()))) { \Difra\Ajaxer::redirect('/adm/cms/snippets'); } if (!$confirm) { \Difra\Ajaxer::confirm(\Difra\Locales::get('cms/adm/snippet/del-confirm1') . $snippet->getName() . \Difra\Locales::get('cms/adm/snippet/del-confirm2')); return; } $snippet->del(); \Difra\Ajaxer::close(); \Difra\Ajaxer::redirect('/adm/content/snippets'); }
/** * @backupGlobals enabled */ public function test_actions() { \Difra\Debugger::disable(); \Difra\Ajaxer::clean(); $actions = []; \Difra\Ajaxer::notify('notification message'); $actions[] = ['action' => 'notify', 'message' => 'notification message', 'lang' => ['close' => \Difra\Locales::get('notifications/close')]]; \Difra\Ajaxer::display('<span>test</span>'); $actions[] = ['action' => 'display', 'html' => '<span>test</span>']; \Difra\Ajaxer::error('error message <span>test</span>'); $actions[] = ['action' => 'error', 'message' => 'error message <span>test</span>', 'lang' => ['close' => \Difra\Locales::get('notifications/close')]]; \Difra\Ajaxer::required('element'); $actions[] = ['action' => 'require', 'name' => 'element']; \Difra\Ajaxer::invalid('inv1'); $actions[] = ['action' => 'invalid', 'name' => 'inv1']; \Difra\Ajaxer::invalid('inv2'); $actions[] = ['action' => 'invalid', 'name' => 'inv2']; \Difra\Ajaxer::status('field1', 'bad value', 'problem'); $actions[] = ['action' => 'status', 'name' => 'field1', 'message' => 'bad value', 'classname' => 'problem']; \Difra\Ajaxer::redirect('/some/page'); $actions[] = ['action' => 'redirect', 'url' => '/some/page']; $_SERVER['HTTP_REFERER'] = '/current/page'; \Difra\Ajaxer::refresh(); $actions[] = ['action' => 'redirect', 'url' => '/current/page']; \Difra\Ajaxer::reload(); $actions[] = ['action' => 'reload']; \Difra\Ajaxer::load('someid', 'some <b>content</b>'); $actions[] = ['action' => 'load', 'target' => 'someid', 'html' => 'some <b>content</b>']; \Difra\Ajaxer::close(); $actions[] = ['action' => 'close']; \Difra\Ajaxer::reset(); $actions[] = ['action' => 'reset']; \Difra\Envi::setUri('/current/page'); \Difra\Ajaxer::confirm('Are you sure?'); $actions[] = ['action' => 'display', 'html' => '<form action="/current/page" class="ajaxer"><input type="hidden" name="confirm" value="1"/>' . '<div>Are you sure?</div>' . '<input type="submit" value="' . \Difra\Locales::get('ajaxer/confirm-yes') . '"/>' . '<input type="button" value="' . \Difra\Locales::get('ajaxer/confirm-no') . '" onclick="ajaxer.close(this)"/>' . '</form>']; $this->assertEquals(\Difra\Ajaxer::getResponse(), json_encode(['actions' => $actions], \Difra\Ajaxer::getJsonFlags())); \Difra\Ajaxer::clean(); $this->assertEquals(\Difra\Ajaxer::getResponse(), '[]'); $this->assertFalse(\Difra\Ajaxer::hasProblem()); \Difra\Ajaxer::reload(); \Difra\Ajaxer::clean(true); $this->assertEquals(\Difra\Ajaxer::getResponse(), '[]'); $this->assertTrue(\Difra\Ajaxer::hasProblem()); }
/** * Recover password (ajax) * @param AjaxString $login Login or e-mail * @param AjaxString $captcha * @throws Exception */ public function indexAjaxAction(AjaxString $login, AjaxString $captcha) { // show recover form if (is_null($login)) { $this->root->appendChild($this->xml->createElement('recover')); Ajaxer::display(View::render($this->xml, 'auth-ajax', true)); return; } $error = false; // login's empty if ($login->val() === '') { Ajaxer::required('login'); $error = true; } if (!$captcha or $captcha->val() == '') { Ajaxer::required('captcha'); $error = true; } /** @var \Difra\Plugins\Capcha $captchaClass */ $captchaClass = \Difra\Plugger::getClass('captcha'); if (!$captchaClass::getInstance()->verifyKey($captcha->val())) { Ajaxer::invalid('captcha'); $error = true; } if ($error) { return; } // recover try { Recover::send($login->val()); Ajaxer::close(); Ajaxer::notify(Locales::get('auth/login/recovered')); } catch (Exception $ex) { Ajaxer::status('email', Locales::get('auth/login/' . $ex->getMessage()), 'problem'); } }
/** * Delete menu element * @param Difra\Param\AnyInt $id * @param Difra\Param\AjaxCheckbox $confirm */ public function deleteAjaxAction(\Difra\Param\AnyInt $id, \Difra\Param\AjaxCheckbox $confirm = null) { if (!$confirm or !$confirm->val()) { \Difra\Ajaxer::display('<span>' . \Difra\Locales::get('cms/adm/menuitem/delete-item-confirm') . '</span>' . '<form action="/adm/content/menu/delete/' . $id . '" method="post" class="ajaxer">' . '<input type="hidden" name="confirm" value="1"/>' . '<input type="submit" value="Да"/>' . '<a href="#" onclick="ajaxer.close(this)" class="button">Нет</a>' . '</form>'); } else { \Difra\Plugins\CMS\MenuItem::get($id->val())->delete(); \Difra\Ajaxer::refresh(); \Difra\Ajaxer::close(); } }
/** * After success actions * @param $redirect */ protected function afterSuccess($redirect = false) { if ($redirect) { Cookies::getInstance()->notify(Locales::get('auth/register/complete-' . Users::getActivationMethod())); View::redirect('/'); } else { Ajaxer::notify(Locales::get('auth/register/complete-' . Users::getActivationMethod())); Ajaxer::close(); } }