Esempio n. 1
0
 /**
  * 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>');
 }
Esempio n. 2
0
 /**
  * @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');
 }
Esempio n. 3
0
 /**
  * @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 &lt;span&gt;test&lt;/span&gt;', '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());
 }
Esempio n. 4
0
 /**
  * Change password using recovery link
  * @param AnyString $code
  * @param AjaxString $password1
  * @param AjaxString $password2
  * @throws Exception
  */
 public function submitAjaxAction(AnyString $code, AjaxString $password1, AjaxString $password2)
 {
     try {
         Recover::verify($code->val());
     } catch (\Difra\Plugins\Users\UsersException $ex) {
         Ajaxer::notify(Locales::get('auth/recover/' . $ex->getMessage()));
         return;
     }
     // verify passwords
     $register = new \Difra\Plugins\Users\Register();
     $register->setPassword1($password1->val());
     $register->setPassword2($password2->val());
     if (!$register->validatePasswords()) {
         $register->callAjaxerEvents();
         return;
     }
     Recover::recoverSetPassword($code->val(), $password1->val());
     Cookies::getInstance()->notify(Locales::get('auth/recover/done'));
     Ajaxer::redirect('/');
 }
Esempio n. 5
0
 /**
  * Save empty menu element
  * @param \Difra\Param\AjaxInt $menu
  * @param \Difra\Param\AjaxString $label
  * @param \Difra\Param\AjaxInt|null $id
  * @param \Difra\Param\AjaxInt $parent
  */
 public function saveemptyAjaxAction(\Difra\Param\AjaxInt $menu, \Difra\Param\AjaxString $label, \Difra\Param\AjaxInt $id = null, \Difra\Param\AjaxInt $parent = null)
 {
     if ($id) {
         $item = \Difra\Plugins\CMS\MenuItem::get($id->val());
     } else {
         $item = \Difra\Plugins\CMS\MenuItem::create();
     }
     $item->setMenu($menu->val());
     $item->setParent($parent ? $parent->val() : null);
     $item->setLinkLabel($label);
     \Difra\Ajaxer::redirect('/adm/content/menu/view/' . $menu->val());
 }