public function init()
    {
        // Send default settings according to locale
        $locale = i18n::get_locale();
        $symbols = Zend_Locale_Data::getList($locale, 'symbols');
        $currency = Currency::config()->currency_symbol;
        $decimals = $symbols['decimal'];
        $thousands = $decimals == ',' ? ' ' : ',';
        // Accouting needs to be initialized globally
        FormExtraJquery::include_accounting();
        Requirements::customScript(<<<EOT
    window.accounting.settings = {
        currency: {
            symbol : "{$currency}",
            format: "%s%v",
            decimal : "{$decimals}",
            thousand: "{$thousands}",
            precision : 2
        },
        number: {
            precision : 0,
            thousand: "{$thousands}",
            decimal : "{$decimals}"
        }
    }
EOT
, 'accountingInit');
    }
 public function Field($properties = array())
 {
     FormExtraJquery::include_jquery();
     FormExtraJquery::include_accounting();
     Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/AccountingField.js');
     return parent::Field($properties);
 }
 public function Field($properties = array())
 {
     FormExtraJquery::include_jquery();
     // Use updated version of Chosen
     Requirements::block(FRAMEWORK_ADMIN_DIR . '/thirdparty/chosen/chosen/chosen.css');
     Requirements::block(FRAMEWORK_ADMIN_DIR . '/thirdparty/chosen/chosen/chosen.jquery.js');
     Requirements::css(FORM_EXTRAS_PATH . '/javascript/chosen/chosen.min.css');
     Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/chosen/chosen.jquery.js');
     if ($this->use_order) {
         Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/chosen_order/chosen.order.jquery.js');
     }
     // Init
     $opts = array('no_results_text' => $this->no_results_text, 'allow_single_deselect' => $this->allow_single_deselect ? true : false);
     if (self::config()->rtl) {
         $this->addExtraClass('chosen-rtl');
     }
     if ($this->allow_max_selected) {
         $opts['allow_max_selected'] = $this->allow_max_selected;
     }
     if ($this->use_order) {
         $stringValue = $this->value;
         if (is_array($stringValue)) {
             $stringValue = implode(',', $stringValue);
         }
         $this->setAttribute('data-chosen-order', $stringValue);
     }
     $this->setAttribute('data-chosen', json_encode($opts));
     Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/ChosenField.js');
     return parent::Field($properties);
 }
 public function Field($properties = array())
 {
     FormExtraJquery::include_jquery();
     Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js');
     Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/minicolors/jquery.minicolors.min.js');
     Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/MiniColorsField.js');
     Requirements::css(FORM_EXTRAS_PATH . '/javascript/minicolors/jquery.minicolors.css');
     return parent::Field($properties);
 }
 public function __construct($name, $title = null, $source = array(), $value = '', $form = null, $emptyString = null)
 {
     parent::__construct($name, $title, $source, $value, $form, $emptyString);
     if ($emptyString) {
         $this->freeTextItem = $emptyString;
     } else {
         $this->freeTextItem = _t('ComboField.FREETEXT', 'Enter a new value');
     }
     FormExtraJquery::include_jquery();
     Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/ComboField.js');
 }
 public function __construct($name, $title = null, $value = null)
 {
     parent::__construct($name, $title, $value);
     if ($this->getFileManager()) {
         FormExtraJquery::include_jquery();
     }
     Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/tinymce/tinymce.min.js');
     $lang = i18n::get_lang_from_locale(i18n::get_locale());
     if ($lang != 'en') {
         Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/tinymce/langs/' . $lang . '.js');
     }
 }
 public function Field($properties = array())
 {
     FormExtraJquery::include_jquery();
     Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/inputmask/min/jquery.inputmask.bundle.min.js');
     // Set default options once
     $defaultOpts = self::config()->get('default_options');
     if (!empty($defaultOpts)) {
         Requirements::customScript('jQuery.extend($.inputmask.defaults, ' . json_encode($defaultOpts) . ');', 'MaskedInputFieldDefault');
     }
     // Initialize on all input fields once
     Requirements::customScript('jQuery(document).ready(function(){jQuery(":input").inputmask();});', 'MaskedInputFieldInit');
     return parent::Field($properties);
 }
 public function Field($properties = array())
 {
     $image = $this->getImage();
     if (!$image) {
         return false;
     }
     FormExtraJquery::include_jquery();
     if (self::config()->use_hammer) {
         FormExtraJquery::include_hammer();
     }
     if (self::config()->use_mousewheel) {
         FormExtraJquery::include_mousewheel();
     }
     Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/cropbox/jquery.cropbox.js');
     Requirements::css(FORM_EXTRAS_PATH . '/javascript/cropbox/jquery.cropbox.css');
     Requirements::customScript("jQuery( '.cropbox-field' ).each( function () {\n\t\t\tvar t = jQuery(this),\n\t\t\timage = t.find('img'),\n            cropwidth = image.data('cropwidth'),\n            cropheight = image.data('cropheight'),\n\t\t\tx       = jQuery('[name=CropX]', t),\n            y       = jQuery('[name=CropY]', t),\n            w       = jQuery('[name=CropWidth]', t),\n            h       = jQuery('[name=CropHeight]', t)\n\t\t;\n\n          image.cropbox( {width: cropwidth, height: cropheight, result: {cropX:x.val(), cropY:y.val(), cropW:w.val(), cropH:h.val()} })\n            .on('cropbox', function( event, results, img ) {\n\t\t\t\tx.val(results.cropX);\n\t\t\t\ty.val(results.cropY);\n\t\t\t\tw.val(results.cropW);\n\t\t\t\th.val(results.cropH);\n            })\n\t\t\t;\n      } );", 'cropboxFieldInit');
     return parent::Field($properties);
 }
 public function Field($properties = array())
 {
     FormExtraJquery::include_jquery();
     if ($this->requireAccounting) {
         FormExtraJquery::include_accounting();
     }
     FormExtraJquery::include_jquery_ui();
     if (Director::isDev()) {
         Requirements::css(FORM_EXTRAS_PATH . '/javascript/appendgrid/jquery.appendGrid-1.6.0.css');
         Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/appendgrid/jquery.appendGrid-1.6.0.js');
     } else {
         Requirements::css(FORM_EXTRAS_PATH . '/javascript/appendgrid/jquery.appendGrid-1.6.0.min.css');
         Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/appendgrid/jquery.appendGrid-1.6.0.min.js');
     }
     if (!FormExtraJquery::isAdminBackend()) {
         Requirements::customScript('var appendgrid_' . $this->ID() . ' = ' . $this->buildJsonOpts(true));
     } else {
         Requirements::css(FORM_EXTRAS_PATH . '/javascript/appendgrid/silverstripe.css');
     }
     Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/AppendGridField.js');
     return parent::Field($properties);
 }
 public function Field($properties = array())
 {
     if (!$this->isReadonly()) {
         FormExtraJquery::include_jquery();
         if ($this->requireAccounting) {
             FormExtraJquery::include_accounting();
         }
         Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/TableField.js');
     }
     return parent::Field($properties);
 }
 public function __construct($name, $title = null, $value = "")
 {
     FormExtraJquery::include_jquery();
     Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/SexyPasswordField.js');
     parent::__construct($name, $title, $value);
 }
 public function Field($properties = array())
 {
     FormExtraJquery::include_jquery();
     $use_v3 = self::config()->use_v3;
     if ($use_v3) {
         Requirements::css(FORM_EXTRAS_PATH . '/javascript/select2-v3/select2.css');
         Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/select2-v3/select2.min.js');
         // Locale support
         $lang = i18n::get_lang_from_locale(i18n::get_locale());
         if ($lang != 'en') {
             Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/select2-v3/select2_locale_' . $lang . '.js');
         }
     } else {
         // Locale support
         $lang = i18n::get_lang_from_locale(i18n::get_locale());
         if ($lang != 'en') {
             Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/select2-v4/i18n/' . $lang . '.js');
         }
         // Use full release
         Requirements::css(FORM_EXTRAS_PATH . '/javascript/select2-v4/css/select2.min.css');
         FormExtraJquery::include_mousewheel();
         Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/select2-v4/js/select2.full.min.js');
     }
     // Build options
     $opts = array();
     if ($this->allow_single_deselect) {
         if ($use_v3) {
             $opts['allowClear'] = $this->allow_single_deselect;
         } else {
             $opts['allow_clear'] = $this->allow_single_deselect;
         }
     }
     if ($this->allow_max_selected) {
         if ($use_v3) {
             $opts['maximumSelectionSize'] = $this->allow_max_selected;
         } else {
             $opts['maximumSelectionLength'] = $this->allow_max_selected;
         }
     }
     if ($this->tags) {
         if ($use_v3) {
             if (is_array($this->source)) {
                 $source = array_values($this->source);
             } else {
                 $source = array();
             }
             // Tags is an array
             $opts['tags'] = $source;
             $opts['tokenSeparators'] = $this->token_separators;
             // Not compatible with select
             $this->multiple = false;
             $this->template = 'HiddenField';
         } else {
             // Tags are calculated from options
             $opts['tags'] = $this->tags;
             $opts['token_separators'] = $this->token_separators;
             $opts['free_order'] = $this->free_order;
         }
     }
     if (self::config()->rtl && !$use_v3) {
         $opts['dir'] = 'rtl';
     }
     if ($this->ajax) {
         $opts['ajax'] = $this->ajax;
     }
     if (FormExtraJquery::isAdminBackend()) {
         Requirements::customScript('var select2_' . $this->ID() . ' = ' . json_encode($opts));
         Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/Select2Field.js');
     } else {
         Requirements::customScript('jQuery("#' . $this->ID() . '").select2(' . json_encode($opts) . ');');
     }
     if ($use_v3) {
         // If you need to adjust the size, it's better to use the field container instead
         $this->setAttribute('style', 'width:100%');
     }
     return parent::Field($properties);
 }
    public function onBeforeInit()
    {
        // Theme is not yet defined properly at this time
        /* @var $request SS_HttpRequest */
        $request = $this->owner->getRequest();
        $url = $request->getURL();
        if (strpos($url, 'dev/build') === 0) {
            return;
        }
        if ($this->isAdminBackend()) {
            $member = Member::currentUser();
            // Silverstripe does not redirect if invalid login to the /admin section so layout will be broken
            if ($member && $member->ID) {
                if (class_exists('Subsite')) {
                    Subsite::$disable_subsite_filter = true;
                }
                $access = Permission::checkMember($member, 'CMS_ACCESS');
                if (class_exists('Subsite')) {
                    Subsite::$disable_subsite_filter = false;
                }
                if (!$access) {
                    $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : Director::baseURL();
                    Session::set("Security.Message.message", _t('Security.ALREADYLOGGEDIN'));
                    Session::set("Security.Message.type", 'warning');
                    Session::set("BackURL", $uri);
                    Session::save();
                    header('Location:' . Director::absoluteBaseURL() . '/Security/login' . "?BackURL=" . urlencode($uri));
                    exit;
                }
            }
            return;
        }
        $conf = $this->config();
        if ($iframe = $request->getVar('iframe')) {
            if (!$iframe || $iframe == 'disabled') {
                Cookie::force_expiry('iframe');
            } else {
                Cookie::set('iframe', true);
            }
        }
        $outdated = $conf->outdated_browser;
        if ($outdated && $outdated['enabled']) {
            if (Director::isDev()) {
                ThemeHeadRequirements::javascript(THEME_FRAMEWORK_PATH . '/javascript/outdatedbrowser/outdatedbrowser.js');
                Requirements::css(THEME_FRAMEWORK_PATH . '/javascript/outdatedbrowser/outdatedbrowser.css');
            } else {
                ThemeHeadRequirements::javascript(THEME_FRAMEWORK_PATH . '/javascript/outdatedbrowser/outdatedbrowser.min.js');
                Requirements::css(THEME_FRAMEWORK_PATH . '/javascript/outdatedbrowser/outdatedbrowser.min.css');
            }
            ThemeHeadRequirements::javascriptTemplate(THEME_FRAMEWORK_PATH . '/javascript/outdated.js', array('BgColor' => $outdated['bg_color'], 'Color' => $outdated['color'], 'LowerThan' => $outdated['lower_than'], 'Lang' => i18n::get_lang_from_locale(i18n::get_locale())));
        }
        if ($conf->include_jquery) {
            FormExtraJquery::include_jquery();
        }
        if ($conf->include_jquery_ui) {
            FormExtraJquery::include_jquery_ui();
        }
        $uikit = $conf->uikit;
        if ($uikit && $uikit['enabled']) {
            $uikitTheme = 'uikit';
            if ($uikit['theme']) {
                $uikitTheme .= '.' . $uikit['theme'];
            }
            $uikitComponents = $uikit['components'];
            if (Director::isDev()) {
                Requirements::javascript(THEME_FRAMEWORK_PATH . '/uikit/js/uikit.js');
                if ($uikit['theme_enabled']) {
                    Requirements::css(THEME_FRAMEWORK_PATH . '/uikit/css/' . $uikitTheme . '.css');
                }
                foreach ($uikitComponents as $component) {
                    Requirements::javascript(THEME_FRAMEWORK_PATH . '/uikit/js/components/' . $component . '.js');
                    if ($uikit['theme_enabled']) {
                        $componentTheme = '';
                        if ($uikit['theme']) {
                            $componentTheme = '.' . $uikit['theme'];
                        }
                        Requirements::css(THEME_FRAMEWORK_PATH . '/uikit/css/components/' . $component . $componentTheme . '.css');
                    }
                }
            } else {
                Requirements::javascript(THEME_FRAMEWORK_PATH . '/uikit/js/uikit.min.js');
                if ($uikit['theme_enabled']) {
                    Requirements::css(THEME_FRAMEWORK_PATH . '/uikit/css/' . $uikitTheme . '.min.css');
                }
                foreach ($uikitComponents as $component) {
                    Requirements::javascript(THEME_FRAMEWORK_PATH . '/uikit/js/components/' . $component . '.min.js');
                    if ($uikit['theme_enabled']) {
                        $componentTheme = '';
                        if ($uikit['theme']) {
                            $componentTheme = '.' . $uikit['theme'];
                        }
                        Requirements::css(THEME_FRAMEWORK_PATH . '/uikit/css/components/' . $component . $componentTheme . '.min.css');
                    }
                }
            }
            // If we loaded notify
            if (in_array('notify', $uikitComponents)) {
                if ($this->owner->hasMethod('SessionMessage') && $this->owner->SessionMessage(false)) {
                    $this->sessionMessage = $message = $this->owner->SessionMessage();
                    $content = Convert::raw2js($message->Content);
                    $type = Convert::raw2js($message->Type);
                    // Convert default Silverstripe types
                    switch ($type) {
                        case self::MESSAGE_BAD:
                            $type = self::NOTIFY_DANGER;
                            break;
                        case self::MESSAGE_GOOD:
                            $type = self::NOTIFY_SUCCESS;
                            break;
                        case self::MESSAGE_WARNING:
                            $type = self::NOTIFY_WARNING;
                            break;
                        case self::MESSAGE_INFO:
                            $type = self::NOTIFY_INFO;
                            break;
                    }
                    Requirements::customScript(<<<JS
UIkit.notify('{$content}',{
  status: '{$type}',
  timeout: 0
});
JS
);
                }
            }
        }
        $noty = $conf->noty;
        if ($noty && $noty['enabled']) {
            if (Director::isDev()) {
                Requirements::javascript(THEME_FRAMEWORK_PATH . '/javascript/noty/packaged/jquery.noty.packaged.js');
            } else {
                Requirements::javascript(THEME_FRAMEWORK_PATH . '/javascript/noty/packaged/jquery.noty.packaged.min.js');
            }
            $theme = $noty['theme'];
            $layout = $noty['layout'];
            Requirements::css(THEME_FRAMEWORK_PATH . '/javascript/noty/themes/' . $theme . '.css');
            Requirements::customScript(<<<JS
jQuery.extend(jQuery.noty.defaults,{
  theme: '{$theme}',
  layout: '{$layout}',
  closeWith: ['click','button']
});
JS
);
            // Flash messages
            if ($this->owner->hasMethod('SessionMessage') && $this->owner->SessionMessage(false)) {
                $this->sessionMessage = $message = $this->owner->SessionMessage();
                $content = Convert::raw2js($message->Content);
                $type = Convert::raw2js($message->Type);
                // Convert default Silverstripe types
                switch ($type) {
                    case self::MESSAGE_BAD:
                        $type = self::NOTY_ERROR;
                        break;
                    case self::MESSAGE_GOOD:
                        $type = self::NOTY_SUCCESS;
                        break;
                    case self::MESSAGE_WARNING:
                        $type = self::NOTY_ALERT;
                        break;
                    case self::MESSAGE_INFO:
                        $type = self::NOTY_INFO;
                        break;
                }
                Requirements::customScript(<<<JS
noty({
  text: '{$content}',
  type: '{$type}',
  timeout: false
});
JS
);
            }
        }
        // Forcing js to bottom allow to put some scripts tags in the head if we want to
        Requirements::set_force_js_to_bottom(true);
    }
 public static function setDisabled($disabled)
 {
     self::$disabled = $disabled;
 }