FIX Re-implement jquery validate localisation, move thirdparty JS libs to client dir

This commit is contained in:
Robbie Averill 2017-08-21 14:35:31 +12:00
parent c0873e1706
commit d3d2ae591f
126 changed files with 33 additions and 14 deletions

BIN
client/dist/images/editablecheckbox.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

BIN
client/dist/images/editabledatefield.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

BIN
client/dist/images/editabledropdown.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

BIN
client/dist/images/editablefilefield.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 525 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

BIN
client/dist/images/editabletextfield.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

BIN
client/dist/images/sitetree_icon.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -8,6 +8,7 @@ use SilverStripe\Assets\Upload;
use SilverStripe\Control\Controller;
use SilverStripe\Control\Email\Email;
use SilverStripe\Control\HTTP;
use SilverStripe\Core\Manifest\Module;
use SilverStripe\Core\Manifest\ModuleLoader;
use SilverStripe\Forms\Form;
use SilverStripe\i18n\i18n;
@ -48,37 +49,55 @@ class UserDefinedFormController extends PageController
$admin = ModuleLoader::getModule('silverstripe/admin');
// load the css
if (!$page->config()->get('block_default_userforms_css')) {
Requirements::css($userforms->getRelativeResourcePath('css/UserForm.css'));
Requirements::css($userforms->getRelativeResourcePath('client/dist/styles/userforms.css'));
}
// load the jquery
if (!$page->config()->get('block_default_userforms_js')) {
$lang = i18n::getData()->languageName(i18n::get_locale());
Requirements::javascript($admin->getRelativeResourcePath('thirdparty/jquery/jquery.js'));
Requirements::javascript('//code.jquery.com/jquery-1.7.2.min.js');
Requirements::javascript(
$userforms->getRelativeResourcePath('thirdparty/jquery-validate/jquery.validate.min.js')
$userforms->getRelativeResourcePath('client/thirdparty/jquery-validate/jquery.validate.min.js')
);
Requirements::add_i18n_javascript($userforms->getRelativeResourcePath('javascript/lang'));
Requirements::javascript($userforms->getRelativeResourcePath('javascript/UserForm.js'));
Requirements::javascript($userforms->getRelativeResourcePath('client/dist/js/userforms.js'));
// @todo implement the $lang correctly
// Requirements::javascript(
// $userforms->getRelativeResourcePath("thirdparty/jquery-validate/localization/messages_{$lang}.min.js")
// );
// Requirements::javascript(
// $userforms->getRelativeResourcePath("thirdparty/jquery-validate/localization/methods_{$lang}.min.js")
// );
$this->addUserFormsValidatei18n($userforms);
// Bind a confirmation message when navigating away from a partially completed form.
if ($page::config()->get('enable_are_you_sure')) {
Requirements::javascript(
$userforms->getRelativeResourcePath('thirdparty/jquery.are-you-sure/jquery.are-you-sure.js')
$userforms->getRelativeResourcePath('client/thirdparty/jquery.are-you-sure/jquery.are-you-sure.js')
);
}
}
}
/**
* Add the necessary jQuery validate i18n translation files, either by locale or by langauge,
* e.g. 'en_NZ' or 'en'. This adds "methods_abc.min.js" as well as "messages_abc.min.js" from the
* jQuery validate thirdparty library.
*
* @param Module $module
*/
protected function addUserFormsValidatei18n(Module $module)
{
$candidates = [
i18n::getData()->langFromLocale(i18n::config()->get('default_locale')),
i18n::config()->get('default_locale'),
i18n::getData()->langFromLocale(i18n::get_locale()),
i18n::get_locale(),
];
foreach ($candidates as $candidate) {
foreach (['messages', 'methods'] as $candidateType) {
$localisationCandidate = "client/thirdparty/jquery-validate/localization/{$candidateType}_{$candidate}.min.js";
if ($module->hasResource($localisationCandidate)) {
Requirements::javascript($module->getRelativeResourcePath($localisationCandidate));
}
}
}
}
/**
* Using $UserDefinedForm in the Content area of the page shows
* where the form should be rendered into. If it does not exist