Compare commits
3 Commits
ecf6afd33a
...
3e8828bdbd
Author | SHA1 | Date |
---|---|---|
Tony Air | 3e8828bdbd | |
Tony Air | 170afbaa73 | |
Tony Air | abcca72aa3 |
|
@ -17,6 +17,10 @@ PageController:
|
|||
- A2nt\CMSNiceties\Extensions\PageControllerEx
|
||||
- A2nt\CMSNiceties\Ajax\Ex\AjaxControllerEx
|
||||
|
||||
SilverStripe\Security\Security:
|
||||
extensions:
|
||||
- A2nt\CMSNiceties\Ajax\Ex\AjaxControllerEx
|
||||
|
||||
SilverStripe\CMS\Model\SiteTree:
|
||||
default_container_class: 'container'
|
||||
extensions:
|
||||
|
|
|
@ -22,6 +22,7 @@ class AjaxControllerEx extends Extension
|
|||
{
|
||||
private static $no_placeholders = false;
|
||||
private static $show_labels = false;
|
||||
private static $add_asteriks = false;
|
||||
|
||||
private static $allowed_actions = [
|
||||
'LoginFormEx',
|
||||
|
@ -48,12 +49,13 @@ class AjaxControllerEx extends Extension
|
|||
* A2nt\CMSNiceties\Ajax\Ex\AjaxControllerEx:
|
||||
* show_labels: false
|
||||
* no_placeholders: false
|
||||
* add_asteriks: false
|
||||
*/
|
||||
if (!$cfg['no_placeholders']) {
|
||||
$placeholder = $field->Title();
|
||||
$field->setAttribute(
|
||||
'placeholder',
|
||||
$placeholder
|
||||
$placeholder.($cfg['add_asteriks'] ? ' *' : '')
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -68,12 +70,17 @@ class AjaxControllerEx extends Extension
|
|||
$ctrl = $this->owner;
|
||||
|
||||
/* @var Form $form */
|
||||
$form = $ctrl->LoginForm();
|
||||
if (method_exists($ctrl, 'LoginForm')) {
|
||||
$form = $ctrl->LoginForm();
|
||||
} else {
|
||||
$form = $ctrl->getLoginForms()['default'][0];
|
||||
}
|
||||
|
||||
self::_processFields($form);
|
||||
|
||||
//$form->addExtraClass('ajax-form');
|
||||
|
||||
if ($form->get_protector()) {
|
||||
if (Director::isLive() && $form->get_protector()) {
|
||||
$form->enableSpamProtection();
|
||||
}
|
||||
|
||||
|
@ -108,7 +115,7 @@ class AjaxControllerEx extends Extension
|
|||
)
|
||||
);
|
||||
|
||||
if ($form->get_protector()) {
|
||||
if (Director::isLive() && $form->get_protector()) {
|
||||
$form->enableSpamProtection();
|
||||
}
|
||||
|
||||
|
@ -181,6 +188,12 @@ class AjaxControllerEx extends Extension
|
|||
return SSViewer::create($tpl);
|
||||
}
|
||||
|
||||
private static function isJson($str)
|
||||
{
|
||||
$json = json_decode($str);
|
||||
return $json && $str != $json;
|
||||
}
|
||||
|
||||
public function prepareAjaxResponse($response)
|
||||
{
|
||||
$ctrl = $this->owner;
|
||||
|
@ -196,16 +209,22 @@ class AjaxControllerEx extends Extension
|
|||
$ctrl->config()->get('ajax_resources')
|
||||
);
|
||||
|
||||
$response->setBody(json_encode([
|
||||
'ID' => $record->ID,
|
||||
'Title' => $record->Title,
|
||||
'Link' => $ctrl->Link(),
|
||||
'CSSClass' => $ctrl->CSSClass(),
|
||||
'Resources' => $resources,
|
||||
'RequestLink' => $url,
|
||||
'MainContent' => $ctrl->customise([
|
||||
'Layout' => DBHTMLText::create()->setValue($response->getBody()),
|
||||
])->renderWith('Includes/MainContent')->RAW(),
|
||||
]));
|
||||
$body = $response->getBody();
|
||||
|
||||
if (!self::isJson($body)) {
|
||||
$body = json_encode([
|
||||
'ID' => $record->ID,
|
||||
'Title' => $record->Title,
|
||||
'Link' => $ctrl->Link(),
|
||||
'CSSClass' => $ctrl->CSSClass(),
|
||||
'Resources' => $resources,
|
||||
'RequestLink' => $url,
|
||||
'MainContent' => $ctrl->customise([
|
||||
'Layout' => DBHTMLText::create()->setValue($response->getBody()),
|
||||
])->renderWith('Includes/MainContent')->RAW(),
|
||||
]);
|
||||
}
|
||||
|
||||
$response->setBody($body);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue