Adding block_default_userforms_css and block_default_userforms_ js config variables to control whether to load css and JavaScript files or not. (#562)

This commit is contained in:
3Dgoo 2017-04-01 20:32:18 +10:30 committed by Damian Mooyman
parent 84eecb0b76
commit d16692d9c1

View File

@ -6,7 +6,7 @@
class UserDefinedForm extends Page class UserDefinedForm extends Page
{ {
/** /**
* @var string * @var string
*/ */
@ -35,6 +35,20 @@ class UserDefinedForm extends Page
*/ */
private static $upgrade_on_build = true; private static $upgrade_on_build = true;
/**
* Set this to true to disable automatic inclusion of CSS files
* @config
* @var bool
*/
private static $block_default_userforms_css = false;
/**
* Set this to true to disable automatic inclusion of JavaScript files
* @config
* @var bool
*/
private static $block_default_userforms_js = false;
/** /**
* Built in extensions required by this page * Built in extensions required by this page
* @config * @config
@ -216,9 +230,9 @@ SQL;
$summaryarray[$eff->Name] = $eff->Title ?: $eff->Name; $summaryarray[$eff->Name] = $eff->Title ?: $eff->Name;
} }
} }
$config->getComponentByType('GridFieldDataColumns')->setDisplayFields($summaryarray); $config->getComponentByType('GridFieldDataColumns')->setDisplayFields($summaryarray);
/** /**
* Support for {@link https://github.com/colymba/GridFieldBulkEditingTools} * Support for {@link https://github.com/colymba/GridFieldBulkEditingTools}
*/ */
@ -369,28 +383,35 @@ class UserDefinedForm_Controller extends Page_Controller
{ {
parent::init(); parent::init();
// load the jquery $page = $this->data();
$lang = i18n::get_lang_from_locale(i18n::get_locale());
Requirements::css(USERFORMS_DIR . '/css/UserForm.css');
Requirements::javascript(FRAMEWORK_DIR .'/thirdparty/jquery/jquery.js');
Requirements::javascript(USERFORMS_DIR . '/thirdparty/jquery-validate/jquery.validate.min.js');
Requirements::add_i18n_javascript(USERFORMS_DIR . '/javascript/lang');
Requirements::javascript(USERFORMS_DIR . '/javascript/UserForm.js');
Requirements::javascript( // load the css
USERFORMS_DIR . "/thirdparty/jquery-validate/localization/messages_{$lang}.min.js" if (!$page->config()->block_default_userforms_css) {
); Requirements::css(USERFORMS_DIR . '/css/UserForm.css');
Requirements::javascript(
USERFORMS_DIR . "/thirdparty/jquery-validate/localization/methods_{$lang}.min.js"
);
if ($this->HideFieldLabels) {
Requirements::javascript(USERFORMS_DIR . '/thirdparty/Placeholders.js/Placeholders.min.js');
} }
// Bind a confirmation message when navigating away from a partially completed form. // load the jquery
$page = $this->data(); if (!$page->config()->block_default_userforms_js) {
if ($page::config()->enable_are_you_sure) { $lang = i18n::get_lang_from_locale(i18n::get_locale());
Requirements::javascript(USERFORMS_DIR . '/thirdparty/jquery.are-you-sure/jquery.are-you-sure.js'); Requirements::javascript(FRAMEWORK_DIR .'/thirdparty/jquery/jquery.js');
Requirements::javascript(USERFORMS_DIR . '/thirdparty/jquery-validate/jquery.validate.min.js');
Requirements::add_i18n_javascript(USERFORMS_DIR . '/javascript/lang');
Requirements::javascript(USERFORMS_DIR . '/javascript/UserForm.js');
Requirements::javascript(
USERFORMS_DIR . "/thirdparty/jquery-validate/localization/messages_{$lang}.min.js"
);
Requirements::javascript(
USERFORMS_DIR . "/thirdparty/jquery-validate/localization/methods_{$lang}.min.js"
);
if ($this->HideFieldLabels) {
Requirements::javascript(USERFORMS_DIR . '/thirdparty/Placeholders.js/Placeholders.min.js');
}
// Bind a confirmation message when navigating away from a partially completed form.
if ($page::config()->enable_are_you_sure) {
Requirements::javascript(USERFORMS_DIR . '/thirdparty/jquery.are-you-sure/jquery.are-you-sure.js');
}
} }
} }
@ -727,7 +748,7 @@ JS
foreach ($recipients as $recipient) { foreach ($recipients as $recipient) {
$email = new UserFormRecipientEmail($submittedFields); $email = new UserFormRecipientEmail($submittedFields);
$mergeFields = $this->getMergeFieldsMap($emailData['Fields']); $mergeFields = $this->getMergeFieldsMap($emailData['Fields']);
if ($attachments) { if ($attachments) {
foreach ($attachments as $file) { foreach ($attachments as $file) {
if ($file->ID != 0) { if ($file->ID != 0) {
@ -739,7 +760,7 @@ JS
} }
} }
} }
$parsedBody = SSViewer::execute_string($recipient->getEmailBodyContent(), $mergeFields); $parsedBody = SSViewer::execute_string($recipient->getEmailBodyContent(), $mergeFields);
if (!$recipient->SendPlain && $recipient->emailTemplateExists()) { if (!$recipient->SendPlain && $recipient->emailTemplateExists()) {