function FieldHolder() {
		
		
		Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/prototype/prototype.js');
		Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/behaviour/behaviour.js');
		Requirements::javascript(SAPPHIRE_DIR . '/javascript/prototype_improvements.js');
		Requirements::javascript(THIRDPARTY_DIR . '/scriptaculous/effects.js');
		Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang');
		Requirements::javascript(SAPPHIRE_DIR . '/javascript/TableListField.js');
		
		// swap the js file
		Requirements::block(SAPPHIRE_DIR . '/javascript/TableField.js');
		Requirements::javascript('modifiedtablefield/javascript/ModifiedTableField.js');
		
		
		Requirements::css(SAPPHIRE_DIR . '/css/TableListField.css');
		

		$defaults = $this->fieldDefaults;
		if ($this->fieldDefaults == null && !is_array($this->fieldDefaults)) {
			$sourceClass = $this->sourceClass;
			
			$defaults = singleton($sourceClass)->stat('defaults');
		}
		
		if (count($defaults) > 0) {
			Requirements::customScript("var ".$this->name."_fieldDefaults = ".Convert::array2json($defaults));
		}
		
		
		return $this->renderWith($this->template);
	}
    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())
    {
        Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery/jquery.min.js');
        Requirements::javascript('geoform/javascript/jquery.geocomplete.js');
        if (GoogleMaps::getApiKey()) {
            Requirements::javascript('//maps.googleapis.com/maps/api/js?sensor=false&libraries=places&language=' . i18n::get_tinymce_lang() . '&key=' . GoogleMaps::getApiKey());
        } else {
            Requirements::javascript('//maps.googleapis.com/maps/api/js?sensor=false&libraries=places&language=' . i18n::get_tinymce_lang());
        }
        $name = $this->getName();
        $this->fieldAddress->setPlaceholder(_t('GeoLocationField.ADDRESSPLACEHOLDER', 'Address'));
        // set caption if required
        $js = <<<JS
(function(\$){
    \$(function(){
        \$("#{$name}-Address").geocomplete().bind("geocode:result", function(event, result){
            \$("#{$name}-Latitude").val(result.geometry.location.lat());
            \$("#{$name}-Longditude").val(result.geometry.location.lng());
        });
    });
})(jQuery);
JS;
        Requirements::customScript($js, 'BootstrapGeoLocationField_Js_' . $this->ID());
        $css = <<<CSS
/* make the location suggest dropdown appear above dialog */
.pac-container {
    z-index: 2000 !important;
}
CSS;
        Requirements::customCSS($css, 'BootstrapGeoLocationField_Css_' . $this->ID());
        return $this->fieldLatitude->Field() . $this->fieldLongditude->Field() . '<div class="row">' . '<div class="col-sm-12">' . $this->fieldAddress->Field() . '</div>' . '</div>';
    }
Esempio n. 4
0
    function jsValidation()
    {
        $formID = $this->form->FormName();
        $error = _t('DateField.VALIDATIONJS', 'Please enter a valid date format (DD/MM/YYYY).');
        $jsFunc = <<<JS
Behaviour.register({
\t"#{$formID}": {
\t\tvalidateDate: function(fieldName) {
\t\t\tvar el = _CURRENT_FORM.elements[fieldName];
\t\t\tvar value = \$F(el);
\t\t\t
\t\t\tif(value && value.length > 0 && !value.match(/^[0-9]{1,2}\\/[0-9]{1,2}\\/[0-90-9]{2,4}\$/)) {
\t\t\t\tvalidationError(el,"{$error}","validation",false);
\t\t\t\treturn false;
\t\t\t}
\t\t\treturn true;
\t\t}
\t}
});
JS;
        Requirements::customScript($jsFunc, 'func_validateDate_' . $formID);
        //		return "\$('$formID').validateDate('$this->name');";
        return <<<JS
if(\$('{$formID}')){
\tif(typeof fromAnOnBlur != 'undefined'){
\t\tif(fromAnOnBlur.name == '{$this->name}')
\t\t\t\$('{$formID}').validateDate('{$this->name}');
\t}else{
\t\t\$('{$formID}').validateDate('{$this->name}');
\t}
}
JS;
    }
    function jsValidation()
    {
        $formID = $this->form->FormName();
        $error = _t('EmailField.VALIDATIONJS', 'Please enter an email address.');
        $jsFunc = <<<JS
Behaviour.register({
\t"#{$formID}": {
\t\tvalidateEmailField: function(fieldName) {
\t\t\tvar el = _CURRENT_FORM.elements[fieldName];
\t\t\tif(!el || !el.value) return true;

\t\t \tif(el.value.match(/^[a-z0-9!#\$%&'*+\\/=?^_`{|}~-]+(?:\\.[a-z0-9!#\$%&'*+\\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\$/i)) {
\t\t \t\treturn true;
\t\t \t} else {
\t\t\t\tvalidationError(el, "{$error}","validation");
\t\t \t\treturn false;
\t\t \t} \t
\t\t}
\t}
});
JS;
        //fix for the problem with more than one form on a page.
        Requirements::customScript($jsFunc, 'func_validateEmailField' . '_' . $formID);
        //return "\$('$formID').validateEmailField('$this->name');";
        return <<<JS
if(typeof fromAnOnBlur != 'undefined'){
\tif(fromAnOnBlur.name == '{$this->name}')
\t\t\$('{$formID}').validateEmailField('{$this->name}');
}else{
\t\$('{$formID}').validateEmailField('{$this->name}');
}
JS;
    }
 public function init()
 {
     parent::init();
     $themeDir = SSViewer::get_theme_folder();
     Requirements::javascript('framework/thirdparty/jquery/jquery.js');
     if (Locator::getLocations()) {
         Requirements::javascript('http://maps.google.com/maps/api/js?sensor=false');
         Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js');
         Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js');
     }
     Requirements::css('locator/css/map.css');
     $featured = Locator::getLocations(array('Featured' => 1))->count() > 0 ? 'featuredLocations: true' : 'featuredLocations: false';
     // map config based on user input in Settings tab
     // AutoGeocode or Full Map
     $load = $this->data()->AutoGeocode ? 'autoGeocode: true, fullMapStart: false,' : 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,';
     $base = Director::baseFolder();
     $themePath = $base . '/' . $themeDir;
     $listTemplatePath = file_exists($themePath . '/templates/location-list-description.html') ? $themeDir . '/templates/location-list-description.html' : 'locator/templates/location-list-description.html';
     $infowindowTemplatePath = file_exists($themePath . '/templates/infowindow-description.html') ? $themeDir . '/templates/infowindow-description.html' : 'locator/templates/infowindow-description.html';
     // in page or modal
     $modal = $this->data()->ModalWindow ? 'modalWindow: true' : 'modalWindow: false';
     $kilometer = $this->data()->Unit == 'km' ? 'lengthUnit: "km"' : 'lengthUnit: "m"';
     $link = $this->Link() . 'xml.xml';
     // init map
     if (Locator::getLocations()) {
         Requirements::customScript("\n                \$(function(\$) {\n                    \$('#map-container').storeLocator({\n                        " . $load . "\n                        dataLocation: '" . $link . "',\n                        listTemplatePath: '" . $listTemplatePath . "',\n                        infowindowTemplatePath: '" . $infowindowTemplatePath . "',\n                        originMarker: true,\n                        " . $modal . ',
                     ' . $featured . ",\n                        slideMap: false,\n                        zoomLevel: 0,\n                        distanceAlert: 120,\n                        formID: 'Form_LocationSearch',\n                        inputID: 'Form_LocationSearch_address',\n                        categoryID: 'Form_LocationSearch_category',\n                        distanceAlert: -1,\n                        " . $kilometer . '
                 });
             });
         ');
     }
 }
Esempio n. 7
0
    public function init()
    {
        parent::init();
        // Concatenate CSS
        Requirements::combine_files('style.css', array('mysite/css/layout.css', 'mysite/css/userstyles.css'));
        // Concatenate JavaScript
        Requirements::combine_files('scripts.js', array('mysite/javascript/lib/top-nav.js', 'mysite/javascript/vanilla.js'));
        // Google Analytics
        $config = SiteConfig::current_site_config();
        $google = $config->GACode;
        $gaJS = <<<JS
            (function(i, s, o, g, r, a, m) {
                i['GoogleAnalyticsObject'] = r;
                i[r] = i[r] || function() {
                    (i[r].q = i[r].q || []).push(arguments)
                }, i[r].l = 1 * new Date();
                a = s.createElement(o), m = s.getElementsByTagName(o)[0];
                a.async = 1;
                a.src = g;
                m.parentNode.insertBefore(a, m)
            })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
            ga('create', '{$google}', 'auto');
            ga('send', 'pageview');
JS;
        Requirements::customScript($gaJS);
    }
    /**
     * Constructor.
     *
     * @param Controller $controller
     * @param string $name method on the $controller
     * @param FieldList $fields
     * @param FieldList $actions
     * @param bool $checkCurrentUser - show logout button if logged in
     */
    public function __construct($controller, $name, $fields = null, $actions = null, $checkCurrentUser = true)
    {
        parent::__construct($controller, $name, $fields, $actions, $checkCurrentUser);
        // will be used to get correct Link()
        $this->ldapSecController = Injector::inst()->create('LDAPSecurityController');
        $usernameField = new TextField('Username', _t('Member.USERNAME', 'Username'), null, null, $this);
        $this->Fields()->replaceField('Email', $usernameField);
        $this->setValidator(new RequiredFields('Username', 'Password'));
        if (Security::config()->remember_username) {
            $usernameField->setValue(Session::get('SessionForms.MemberLoginForm.Email'));
        } else {
            // Some browsers won't respect this attribute unless it's added to the form
            $this->setAttribute('autocomplete', 'off');
            $usernameField->setAttribute('autocomplete', 'off');
        }
        // Users can't change passwords unless appropriate a LDAP user with write permissions is
        // configured the LDAP connection binding
        $this->Actions()->remove($this->Actions()->fieldByName('forgotPassword'));
        $allowPasswordChange = Config::inst()->get('LDAPService', 'allow_password_change');
        if ($allowPasswordChange && $name != 'LostPasswordForm' && !Member::currentUser()) {
            $forgotPasswordLink = sprintf('<p id="ForgotPassword"><a href="%s">%s</a></p>', $this->ldapSecController->Link('lostpassword'), _t('Member.BUTTONLOSTPASSWORD', "I've lost my password"));
            $forgotPassword = new LiteralField('forgotPassword', $forgotPasswordLink);
            $this->Actions()->add($forgotPassword);
        }
        // Focus on the Username field when the page is loaded
        Requirements::block('MemberLoginFormFieldFocus');
        $js = <<<JS
\t\t\t(function() {
\t\t\t\tvar el = document.getElementById("Username");
\t\t\t\tif(el && el.focus && (typeof jQuery == 'undefined' || jQuery(el).is(':visible'))) el.focus();
\t\t\t})();
JS;
        Requirements::customScript($js, 'LDAPLoginFormFieldFocus');
    }
 /**
  * returns the form
  * @return Form
  */
 public function getGoogleSiteSearchForm($name = "GoogleSiteSearchForm")
 {
     $formIDinHTML = "Form_" . $name;
     if ($page = GoogleCustomSearchPage::get()->first()) {
         Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
         Requirements::javascript('googlecustomsearch/javascript/GoogleCustomSearch.js');
         $apiKey = Config::inst()->get("GoogleCustomSearchExt", "api_key");
         $cxKey = Config::inst()->get("GoogleCustomSearchExt", "cx_key");
         if ($apiKey && $cxKey) {
             Requirements::customScript("\n\t\t\t\t\t\tGoogleCustomSearch.apiKey = '" . $apiKey . "';\n\t\t\t\t\t\tGoogleCustomSearch.cxKey = '" . $cxKey . "';\n\t\t\t\t\t\tGoogleCustomSearch.formSelector = '#" . $formIDinHTML . "';\n\t\t\t\t\t\tGoogleCustomSearch.inputFieldSelector = '#" . $formIDinHTML . "_search';\n\t\t\t\t\t\tGoogleCustomSearch.resultsSelector = '#" . $formIDinHTML . "_Results';\n\t\t\t\t\t", "GoogleCustomSearchExt");
             $form = new Form($this->owner, 'GoogleSiteSearchForm', new FieldList($searchField = new TextField('search'), $resultField = new LiteralField($name . "_Results", "<div id=\"" . $formIDinHTML . "_Results\"></div>")), new FieldList(new FormAction('doSearch', _t("GoogleCustomSearchExt.GO", "Full Results"))));
             $form->setFormMethod('GET');
             if ($page = GoogleCustomSearchPage::get()->first()) {
                 $form->setFormAction($page->Link());
             }
             $form->disableSecurityToken();
             $form->loadDataFrom($_GET);
             $searchField->setAttribute("autocomplete", "off");
             $form->setAttribute("autocomplete", "off");
             return $form;
         } else {
             user_error("You must set an API Key and a CX key in your configs to use the Google Custom Search Form", E_USER_NOTICE);
         }
     } else {
         user_error("You must create a GoogleCustomSearchPage first.", E_USER_NOTICE);
     }
 }
Esempio n. 10
0
 public function init()
 {
     parent::init();
     // Note: you should use SS template require tags inside your templates
     // instead of putting Requirements calls here.  However these are
     // included so that our older themes still work
     Requirements::css('themes/simple/css/homepage.css');
     Requirements::customScript('
             $("a.scroll-arrow").mousedown( function(e) {
                          e.preventDefault();              
           			var container = $(this).parent().attr("id");                              
                            var direction = $(this).is("#scroll-right") ? "+=" : "-=";
                            var totalWidth = -$(".row__inner").width();
                            $(".row__inner .tile").each(function() {
                                totalWidth += $(this).outerWidth(true);
                            });
                            
                            $("#"+ container + " .row__inner").animate({
                                scrollLeft: direction + Math.min(totalWidth, 3000)
                                
                            },{
                                duration: 2500,
                                easing: "swing", 
                                queue: false }
                            );
                        }).mouseup(function(e) {
                          $(".row__inner").stop();
            });');
 }
Esempio n. 11
0
    function jsValidation()
    {
        $formID = $this->form->FormName();
        $error = _t('NumericField.VALIDATIONJS', 'is not a number, only numbers can be accepted for this field');
        $jsFunc = <<<JS
Behaviour.register({
\t"#{$formID}": {
\t\tvalidateNumericField: function(fieldName) {\t
\t\t\t\tel = _CURRENT_FORM.elements[fieldName];
\t\t\t\tif(!el || !el.value) return true;
\t\t\t\t
\t\t\t \tif(el.value.match(/^\\s*(\\-?[0-9]+(\\.[0-9]+)?\\s*\$)/)) { 
\t\t\t \t\treturn true;
\t\t\t \t} else {
\t\t\t\t\tvalidationError(el, "'" + el.value + "' {$error}","validation");
\t\t\t \t\treturn false;
\t\t\t \t}
\t\t\t}
\t}
});
JS;
        Requirements::customScript($jsFunc, 'func_validateNumericField');
        //return "\$('$formID').validateNumericField('$this->name');";
        return <<<JS
if(typeof fromAnOnBlur != 'undefined'){
\tif(fromAnOnBlur.name == '{$this->name}')
\t\t\$('{$formID}').validateNumericField('{$this->name}');
}else{
\t\$('{$formID}').validateNumericField('{$this->name}');
}
JS;
    }
    public function init()
    {
        parent::init();
        // Page Specific Includes
        Requirements::customScript('
		 
		  //VITALSCRIPT!!!
		  jQuery("a.sendmessage").bind("click", function(){
			 var myval = $(this).attr("id");
			 jQuery("#SendForm_SendForm_CleanupID").attr("value", myval);
		  });


		  jQuery(".invite").fancybox({
			  "titleShow"		: "false",
			  "transitionIn"		: "elastic",
			  "transitionOut"		: "elastic"
			});

		  //VITALSCRIPT!!!
		  jQuery("a.invite").bind("click", function(){
			 var myval = $(this).attr("id");
			 jQuery("#InviteForm_InviteForm_CleanupID").attr("value", myval);
		  });

		  ');
    }
    function getPaymentFormFields()
    {
        $site_currency = Payment::site_currency();
        $paymentsList = '<div id="SecurePayTechCardsAvailable">';
        $count = 0;
        foreach (self::$credit_cards as $name => $image) {
            $count++;
            $class = '';
            if ($count == 1) {
                $class = "first";
            }
            if ($count % 2) {
                $class .= " even";
            } else {
                $class .= " odd";
            }
            $paymentsList .= '<img src="' . $image . '" alt="' . $name . '" class="SecurePayTechCardImage' . $count . '" />';
        }
        Requirements::customScript('
			function paymark_verify(merchant) {
				window.open ("http://www.paymark.co.nz/dart/darthttp.dll?etsl&tn=verify&merchantid=" + merchant, "verify", "scrollbars=yes, width=400, height=400");
			}
		', 'paymark_verify');
        $paymentsList .= '
			<img height="30" src="payment_securatech/images/paymark_small.png" alt="Paymark Certified" onclick="paymark_verify (' . "'" . self::get_spt_merchant_id() . "'" . ')" class="last" />
			</div>';
        $fieldSet = new FieldSet();
        $fieldSet->push(new LiteralField('SPTInfo', $paymentsList));
        return $fieldSet;
    }
Esempio n. 14
0
	function jsValidation() {
		$formID = $this->form->FormName();
		$error = _t('NumericField.VALIDATIONJS', 'is not a number, only numbers can be accepted for this field');
		$jsFunc =<<<JS
Behaviour.register({
	"#$formID": {
		validateNumericField: function(fieldName) {	
				el = _CURRENT_FORM.elements[fieldName];
				if(!el || !el.value) return true;
				
			 	if(el.value.match(/^([0-9]+(\.[0-9]+)?$)/)) { 
			 		return true;
			 	} else {
					validationError(el, "'" + el.value + "' $error","validation");
			 		return false;
			 	}
			}
	}
});
JS;

		Requirements::customScript($jsFunc, 'func_validateNumericField');

		//return "\$('$formID').validateNumericField('$this->name');";
		return <<<JS
if(typeof fromAnOnBlur != 'undefined'){
	if(fromAnOnBlur.name == '$this->name')
		$('$formID').validateNumericField('$this->name');
}else{
	$('$formID').validateNumericField('$this->name');
}
JS;
	}
 /**
  *
  */
 public function onAfterInit()
 {
     if ($code = PageProoferConfig::get_page_proofer()) {
         $data = ArrayData::create(array('Code' => $code->Code));
         Requirements::customScript($data->renderWith('PageProofer'));
     }
 }
Esempio n. 16
0
	/**
	 * @see http://regexlib.com/REDetails.aspx?regexp_id=126
	 */
	function jsValidation() {
		$formID = $this->form->FormName();
		$error = _t('CurrencyField.VALIDATIONJS', 'Please enter a valid currency.');
		$jsFunc =<<<JS
Behaviour.register({
	"#$formID": {
		validateCurrency: function(fieldName) {
			var el = _CURRENT_FORM.elements[fieldName];
			if(!el || !el.value) return true;
			
			var value = \$F(el);
			if(value.length > 0 && !value.match(/^\\$?(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?\$/)) {
				validationError(el,"$error","validation",false);
				return false;
			}
			return true;			
		}
	}
});
JS;

		Requirements::customScript($jsFunc, 'func_validateCurrency_' .$formID);

		return <<<JS
		if(\$('$formID')) \$('$formID').validateCurrency('$this->name');
JS;
	}
    public function getAJAXJS()
    {
        //Ajax for the filter
        Requirements::customScript(<<<JS
\t
\t\t\tjQuery(document).ready(function(){
\t\t\t\t\t
\t\t\t\t//Container for inserting template
\t\t\t\tContainer = jQuery('.main > .inner');
\t\t\t\t\t
\t\t\t\tjQuery('.filter a').on('click', function(ev){
\t\t\t\t\t
\t\t\t\t\tev.preventDefault();
\t\t\t\t\t
\t\t\t\t\thref = jQuery(this).attr('href');
\t\t\t\t\t
\t\t\t\t\tjQuery.ajax({
\t\t\t\t\t\t  url: href,
\t\t\t\t\t\t  beforeSend: function(){
\t\t\t\t\t\t  \tContainer.addClass('loading');
\t\t\t\t\t\t  },
\t\t\t\t\t\t  success: function(data) {
\t\t\t\t\t\t    Container.html(data).removeClass('loading');
\t\t\t\t\t\t  }
\t\t\t\t\t});
\t\t\t\t\t
\t\t\t\t\treturn false;
\t\t\t\t});
\t\t\t});
JS
);
    }
Esempio n. 18
0
 function init()
 {
     parent::init();
     Requirements::CSS('themes/openstack/css/learn.css');
     Requirements::javascript('themes/openstack/javascript/filetracking.jquery.js');
     Requirements::customScript("jQuery(document).ready(function(\$) {\n\n\n            \$('body').filetracking();\n\n             \$(document).on('click', '.outbound-link', function(event){\n                var href = \$(this).attr('href');\n                recordOutboundLink(this,'Outbound Links',href);\n                event.preventDefault();\n                event.stopPropagation()\n                return false;\n            });\n\n        });");
 }
 /**
  * Get form fields for manipulating the current order,
  * according to the responsibilty of this component.
  *
  * @param Order $order
  * @param Form  $form
  *
  * @return FieldList
  */
 public function getFormFields(Order $order, Form $form = null)
 {
     $gateway = $this->getGateway($order);
     if (!$this->isBraintree) {
         return parent::getFormFields($order);
     }
     // Generate the token for the javascript to use
     $clientToken = $gateway->clientToken()->send()->getToken();
     // Generate the standard set of fields and allow it to be customised
     $fields = FieldList::create([BraintreeHostedField::create('number', _t('BraintreePaymentCheckoutComponent.CardNumber', 'Debit/Credit Card Number')), BraintreeHostedField::create('cvv', _t('BraintreePaymentCheckoutComponent.CVV', 'Security Code')), BraintreeHostedField::create('expirationDate', _t('BraintreePaymentCheckoutComponent.ExpirationDate', 'Expiration Date (MM/YYYY)'))]);
     if ($this->config()->use_placeholders) {
         foreach ($fields as $field) {
             if ($field->Title()) {
                 $field->setAttribute('placeholder', $field->Title())->setTitle(null);
             }
         }
     }
     $this->extend('updateFormFields', $fields);
     // Generate a basic config and allow it to be customised
     $config = ['id' => $form ? $form->getHTMLID() : 'PaymentForm_OrderForm', 'hostedFields' => $this->getFieldConfig($fields)];
     $this->extend('updateBraintreeConfig', $config);
     $rawConfig = json_encode($config);
     $rawConfig = $this->injectCallbacks($rawConfig);
     $this->extend('updateRawBraintreeConfig', $rawConfig);
     // Finally, add the javascript to the page
     Requirements::javascript('https://js.braintreegateway.com/js/braintree-2.20.0.min.js');
     Requirements::customScript("braintree.setup('{$clientToken}', 'custom', {$rawConfig});", 'BrainTreeJS');
     return $fields;
 }
    public function FieldHolder($attributes = array())
    {
        Requirements::css(THIRDPARTY_DIR . '/jquery-ui-themes/smoothness/jquery-ui.css');
        Requirements::css("registration/css/affiliations.css");
        Requirements::javascript(Director::protocol() . "ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js");
        Requirements::javascript(Director::protocol() . "ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/additional-methods.min.js");
        Requirements::javascript(THIRDPARTY_DIR . '/jquery-ui/jquery-ui.js');
        $js_scripts = array("themes/openstack/javascript/pure.min.js", "themes/openstack/javascript/jquery.serialize.js", "themes/openstack/javascript/jquery.cleanform.js", "themes/openstack/javascript/jquery.ui.datepicker.validation.package-1.0.1/jquery.ui.datepicker.validation.js", "themes/openstack/javascript/jquery.validate.custom.methods.js", 'registration/javascript/affiliations.js');
        foreach ($js_scripts as $js) {
            Requirements::javascript($js);
        }
        $arrayData = new ArrayData(array('Title' => 'Edit Affiliation'));
        $modal = $arrayData->renderWith('AffiliationModalForm');
        $modal = trim(preg_replace('/\\s\\s+/', ' ', $modal));
        $script = <<<JS

        (function( \$ ){

            \$(document).ready(function() {
                \$('{$modal}').appendTo(\$('body'));
                \$("#edit-affiliation-form").affiliations({
                    storage:'{$this->mode}'
                });
            });


        }( jQuery ));
JS;
        Requirements::customScript($script);
        return parent::FieldHolder($attributes);
    }
    public function jsValidation()
    {
        $formID = $this->form->FormName();
        $jsFunc = <<<JS
Behaviour.register({
\t"#{$formID}": {
\t\tvalidateDriversLicenseNumber: function(fieldName) {
\t\t\tvar value = \$F(_CURRENT_FORM.elements[fieldName]);

\t\t\tif(value.length > 0 && !value.match(/^[A-z]{2}[0-9]{6}\$/)) {
\t\t\t\tvalidationError(el,"{$error}","validation",false);
\t\t\t\treturn false;
\t\t\t}
\t\t\t
\t\t\treturn true;
\t\t}
\t}
});
JS;
        Requirements::customScript($jsFunc, 'func_validateDriver_' . $formID);
        return <<<JS
\tif(\$('{$formID}')){
\t\tif(typeof fromAnOnBlur != 'undefined'){
\t\t\tif(fromAnOnBlur.name == '{$this->name}')
\t\t\t\t\$('{$formID}').validateDriversLicenseNumber('{$this->name}');
\t\t}else{
\t\t\t\$('{$formID}').validateDriversLicenseNumber('{$this->name}');
\t\t}
\t}
JS;
    }
    public function Field($properties = array())
    {
        Requirements::javascript('ajaxuploadfield/thirdparty/valums/client/fileuploader.min.js', 'fileuploader');
        //configure javascript
        $htmlid = $this->XML_val('Name') . "_uploader";
        $thislink = $this->Link('save');
        $options = array('action' => $thislink, 'multiple' => false);
        $allowedextensions = $this->getValidator()->getAllowedExtensions();
        if (is_array($allowedextensions)) {
            $options['allowedExtensions'] = $allowedextensions;
        }
        if ($maxfilesize = $this->getValidator()->getAllowedMaxFileSize()) {
            $options['sizeLimit'] = $maxfilesize;
        }
        if (Director::isDev()) {
            $options['debug'] = true;
        }
        $options = array_merge($options, $this->config);
        $encodedoptions = json_encode($options);
        $extraclasses = count($this->buttonClasses) ? 'class=\\"' . implode(" ", $this->buttonClasses) . '\\"' : "";
        $replacementhtml = '<span id=\\"' . $htmlid . '\\"><input type=\\"submit\\" ' . $extraclasses . ' value=\\"' . $this->title . '\\" /></span>';
        //store globally reachable js reference, to allow later customisations
        $script = <<<JS
\t\t\tqq.instances = qq.instances ? qq.instances : {};
\t\t\t\$("#{$htmlid}").html("{$replacementhtml}").each(function(){
\t\t\t\tvar el = \$(this);
\t\t\t\tvar options = {$encodedoptions};
\t\t\t\toptions['button'] = el[0];
\t\t\t\tvar uploader = new qq.FileUploaderBasic(options);
\t\t\t\tel.data('uploader',uploader);
\t\t\t\tqq.instances['{$htmlid}'] = uploader;
\t\t\t});
JS;
        Requirements::customScript($script, 'uploader' . $this->id());
        if ($this->form) {
            $record = $this->form->getRecord();
        }
        $fieldName = $this->name;
        if (isset($record) && $record) {
            $imageField = $record->{$fieldName}();
        } else {
            $imageField = "";
        }
        $html = "<div id=\"{$htmlid}\">";
        if ($imageField && $imageField->exists()) {
            $html .= '<div class="thumbnail">';
            if ($imageField->hasMethod('Thumbnail') && $imageField->Thumbnail()) {
                $html .= "<img src=\"" . $imageField->Thumbnail()->getURL() . "\" />";
            } else {
                if ($imageField->CMSThumbnail()) {
                    $html .= "<img src=\"" . $imageField->CMSThumbnail()->getURL() . "\" />";
                }
            }
            $html .= '</div>';
        }
        $html .= $this->createTag("input", array("type" => "file", "name" => $this->name, "id" => $this->id(), 'disabled' => $this->disabled));
        $html .= $this->createTag("input", array("type" => "hidden", "name" => "MAX_FILE_SIZE", "value" => $maxfilesize));
        $html .= "</div>";
        return $html;
    }
    /**
     * Init
     * 	Include the javascript we will need
     *
     * @return void
     * @author Andrew Lowther <*****@*****.**>
     **/
    public function init()
    {
        parent::init();
        // Get the config variables we'll need
        $config = Config::inst()->get('MediaManager', 'Cloudinary');
        // Inject them into the global scope
        Requirements::customScript(<<<JS
\t\t\t;(function (window, undefined) {
\t\t\t\twindow.mediamanager = window.mediamanager || {};
\t\t\t\twindow.mediamanager.cloudinary = {
\t\t\t\t\tcloud_name: "{$config['cloud_name']}",
\t\t\t\t\tapi_key: "{$config['api_key']}"
\t\t\t\t}
\t\t\t}/)(window);
JS
);
        // Get the base javascript path
        $BaseJsPath = MEDIAMANAGER_CORE_PATH . '/javascript';
        // Combine the cloudinary files into one super file
        Requirements::combine_files('cloudinary.js', array("{$BaseJsPath}/cloudinary/js/load-image.min.js", "{$BaseJsPath}/cloudinary/js/canvas-to-blob.min.js", "{$BaseJsPath}/cloudinary/js/jquery.fileupload.js", "{$BaseJsPath}/cloudinary/js/jquery.ui.widget.js", "{$BaseJsPath}/cloudinary/js/jquery.fileupload-process.js", "{$BaseJsPath}/cloudinary/js/jquery.fileupload-image.js", "{$BaseJsPath}/cloudinary/js/jquery.fileupload-validate.js", "{$BaseJsPath}/cloudinary/js/jquery.cloudinary.js"));
        // Same again for our files
        Requirements::combine_files('mediamanager.js', array("{$BaseJsPath}/mediamanager/mediamanager.core.js"));
        // Set the cloudinary config
        \Cloudinary::config($config);
    }
    public function Field($properties = array())
    {
        Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery/jquery.min.js');
        Requirements::javascript('bootstrap_extra_fields/javascript/moment.min.js');
        Requirements::javascript('bootstrap_extra_fields/javascript/bootstrap-datetimepicker.min.js');
        Requirements::css('bootstrap_extra_fields/css/bootstrap-datetimepicker.min.css');
        $language = '';
        if (array_key_exists(i18n::get_locale(), $this->supported_locales)) {
            Requirements::javascript('bootstrap_extra_fields/javascript/locales/bootstrap-datetimepicker.' . $this->supported_locales[i18n::get_locale()] . '.js');
            $language = "language: '{$this->supported_locales[i18n::get_locale()]}'";
        } else {
            if ($this->locale) {
                Requirements::javascript('bootstrap_extra_fields/javascript/locales/bootstrap-datetimepicker.' . $this->locale . '.js');
                $language = "language: '{$this->locale}'";
            }
        }
        $name = $this->ID();
        // set caption if required
        $js = <<<JS
\$(function () {
    \$('#{$name}').datetimepicker({{$language}});
});
JS;
        Requirements::customScript($js, 'BootstrapDatetimepickerForm_Js_' . $this->ID());
        return parent::Field($properties);
    }
 /**
  * @return string|void
  */
 public function mergeAccount()
 {
     $token = $this->request->param('CONFIRMATION_TOKEN');
     try {
         $current_member = Member::currentUser();
         if (is_null($current_member)) {
             return Controller::curr()->redirect("Security/login?BackURL=" . urlencode($_SERVER['REQUEST_URI']));
         }
         $request = $this->merge_request_repository->findByConfirmationToken($token);
         if (is_null($request) || $request->isVoid()) {
             throw new DuperMemberActionRequestVoid();
         }
         $dupe_account = $request->getDupeAccount();
         if ($dupe_account->getEmail() != $current_member->getEmail()) {
             throw new AccountActionBelongsToAnotherMemberException();
         }
         $any_account_has_gerrit = $request->getDupeAccount()->isGerritUser() || $request->getPrimaryAccount()->isGerritUser();
         $any_account_has_gerrit = $any_account_has_gerrit ? 'true' : 'false';
         Requirements::customScript('var any_account_has_gerrit = ' . $any_account_has_gerrit . ';');
         Requirements::javascript('dupe_members/javascript/dupe.members.merge.action.js');
         return $this->renderWith(array('DupesMembers_MergeAccountConfirm', 'Page'), array('DupeAccount' => $request->getDupeAccount(), 'CurrentAccount' => $request->getPrimaryAccount(), 'ConfirmationToken' => $token));
     } catch (AccountActionBelongsToAnotherMemberException $ex1) {
         SS_Log::log($ex1, SS_Log::WARN);
         $request = $this->merge_request_repository->findByConfirmationToken($token);
         return $this->renderWith(array('DupesMembers_belongs_2_another_user', 'Page'), array('UserName' => $request->getDupeAccount()->getEmail()));
     } catch (Exception $ex) {
         SS_Log::log($ex, SS_Log::ERR);
         return $this->renderWith(array('DupesMembers_error', 'Page'));
     }
 }
    function jsValidation()
    {
        $formID = $this->form->FormName();
        $jsFunc = <<<JS
Behaviour.register({
\t"#{$formID}": {
\t\tvalidateNZGovtPasswordValidatorPasswordField: function(fieldName) {
\t\t\tvar string = '';
\t\t\tvar test1 = false;
\t\t\tvar test2 = false;
\t\t\tvar test3 = false;
\t\t\tvar test4 = false;
\t\t\tvar test5 = false;
\t\t\tvar error = new Array;
\t\t\tvar errorString = '';
\t\t\tel = _CURRENT_FORM.elements[fieldName];
\t\t\tstring = el.value;
\t\t\tif(!string) {
\t\t\t\terrorString = "Please enter a Password.";
\t\t\t\tvalidationError(el, errorString,"validation");
\t\t\t\treturn false;
\t\t\t}
\t\t\tif (string.length > 6)                    {test1 = true;} else {error[1] = "seven characters";}
\t\t\tif (string.match(/[a-z]/))                {test2 = true;} else {error[2] = "one lowercase letter (e.g. h, j, or u)";}
\t\t\tif (string.match(/[A-Z]/))                {test3 = true;} else {error[3] = "one uppercase letter (e.g. H, J or U)";}
\t\t\tif (string.match(/\\d+/))                  {test4 = true;} else {error[4] = "one digit (e.g. 1, 2, 3 or 4)";}
\t\t\tif (string.match(/.[!,@,#,\$,%,^,&,*,?,_,~]/))  {test5 = true;} else {error[5] = "one punctuation character (e.g. ~, @, #, or \$)";}
\t\t\tif(test1 && test2 && test3 && test4 && test5) {
\t\t\t\treturn true;
\t\t\t}
\t\t\telse {
\t\t\t\tfor(var i = 0; i < error.length; i++) {
\t\t\t\t\tif(errorString.length > 0 && error[i] && i > 0) {
\t\t\t\t\t\terrorString += ", ";
\t\t\t\t\t}
\t\t\t\t\tif(i + 1 == error.length) {
\t\t\t\t\t\terrorString += " and "
\t\t\t\t\t}
\t\t\t\t\tif(error[i]) {
\t\t\t\t\t\terrorString += error[i];
\t\t\t\t\t}
\t\t\t\t}
\t\t\t\terrorString = "There was an error with your Password. It should have at least " + errorString + ".";
\t\t\t\tvalidationError(el, errorString,"validation");
\t\t\t\treturn false;
\t\t\t}
\t\t}
\t}
});
JS;
        Requirements::customScript($jsFunc, 'func_validateNZGovtPasswordValidatorPasswordField');
        return <<<JS
if(typeof fromAnOnBlur != 'undefined'){
\tif(fromAnOnBlur.name == '{$this->name}')
\t\t\$('{$formID}').validateNZGovtPasswordValidatorPasswordField('{$this->name}');
}else{
\t\$('{$formID}').validateNZGovtPasswordValidatorPasswordField('{$this->name}');
}
JS;
    }
 public function FieldHolder()
 {
     Requirements::javascript('dataobject_manager/javascript/jquery.wysiwyg.js');
     Requirements::css('dataobject_manager/css/jquery.wysiwyg.css');
     Requirements::customScript("\n\t\t\t\$(function() {\n\t\t\t\t\$('#{$this->id()}').wysiwyg({\n\t\t\t\t\t{$this->getConfig()}\n\t\t\t\t}).parents('.simplehtmleditor').removeClass('hidden');\n\t\t\t\t\n\t\t\t});\n\t\t");
     return parent::FieldHolder();
 }
 function requirements()
 {
     Requirements::javascript("https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false");
     Requirements::javascript(WIDGETS_GOOGLEMAP_DIR . "/MapWidget.js");
     $options = json_encode(array("latitude" => (double) $this->Latitude, "longitude" => (double) $this->Longitude, "zoom" => (int) $this->Zoom, "canvasid" => $this->CanvasID, "disableUI" => (bool) $this->DisableUI));
     Requirements::customScript("google.maps.event.addDomListener(window, 'load', GoogleMapWidget.createmap({$options}));");
 }
Esempio n. 29
0
    function jsValidation()
    {
        $formID = $this->form->FormName();
        $error = _t('EmailField.VALIDATIONJS', 'Please enter an email address.');
        $jsFunc = <<<JS
Behaviour.register({
\t"#{$formID}": {
\t\tvalidateEmailField: function(fieldName) {
\t\t\tvar el = _CURRENT_FORM.elements[fieldName];
\t\t\tif(!el || !el.value) return true;

\t\t \tif(el.value.match(/^([a-zA-Z0-9_+\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)\$/)) {
\t\t \t\treturn true;
\t\t \t} else {
\t\t\t\tvalidationError(el, "{$error}","validation");
\t\t \t\treturn false;
\t\t \t} \t
\t\t}
\t}
});
JS;
        Requirements::customScript($jsFunc, 'func_validateEmailField');
        //return "\$('$formID').validateEmailField('$this->name');";
        return <<<JS
if(typeof fromAnOnBlur != 'undefined'){
\tif(fromAnOnBlur.name == '{$this->name}')
\t\t\$('{$formID}').validateEmailField('{$this->name}');
}else{
\t\$('{$formID}').validateEmailField('{$this->name}');
}
JS;
    }
 function init()
 {
     parent::init();
     Requirements::css(THIRDPARTY_DIR . '/jquery-ui-themes/smoothness/jquery-ui.css');
     Requirements::javascript(THIRDPARTY_DIR . '/jquery-ui/jquery-ui.js');
     Requirements::customScript("jQuery(document).ready(function(\$) {\n            \$('#consulting','.marketplace-nav').addClass('current');\n        });");
     Requirements::css("themes/openstack/css/chosen.css", "screen,projection");
     Requirements::javascript(Director::protocol() . "maps.googleapis.com/maps/api/js?sensor=false");
     Requirements::combine_files('marketplace_consultants_directory_page.js', array("marketplace/code/ui/frontend/js/markerclusterer.js", "marketplace/code/ui/frontend/js/oms.min.js", "marketplace/code/ui/frontend/js/infobubble-compiled.js", "marketplace/code/ui/frontend/js/google.maps.jquery.js", "themes/openstack/javascript/chosen.jquery.min.js", "marketplace/code/ui/frontend/js/consultants.directory.page.js"));
     Requirements::customScript($this->GATrackingCode());
     $this->consultant_repository = new SapphireConsultantRepository();
     $this->region_repository = new SapphireRegionRepository();
     $this->consultants_locations_query = new ConsultantsOfficesLocationsQueryHandler();
     $this->consultants_service_query = new ConsultantsServicesQueryHandler();
     $google_geo_coding_api_key = null;
     $google_geo_coding_client_id = null;
     $google_geo_coding_private_key = null;
     if (defined('GOOGLE_GEO_CODING_API_KEY')) {
         $google_geo_coding_api_key = GOOGLE_GEO_CODING_API_KEY;
     } else {
         if (defined('GOOGLE_GEO_CODING_CLIENT_ID') && defined('GOOGLE_GEO_CODING_PRIVATE_KEY')) {
             $google_geo_coding_client_id = GOOGLE_GEO_CODING_CLIENT_ID;
             $google_geo_coding_private_key = GOOGLE_GEO_CODING_PRIVATE_KEY;
         }
     }
     $this->manager = new ConsultantManager($this->consultant_repository, new SapphireMarketPlaceVideoTypeRepository(), new SapphireMarketPlaceTypeRepository(), new SapphireOpenStackApiVersionRepository(), new SapphireOpenStackComponentRepository(), new SapphireOpenStackReleaseRepository(), new SapphireRegionRepository(), new SapphireSupportChannelTypeRepository(), new SapphireSpokenLanguageRepository(), new SapphireConfigurationManagementTypeRepository(), new SapphireConsultantServiceOfferedTypeRepository(), new ConsultantAddPolicy($this->consultant_repository, new SapphireMarketPlaceTypeRepository()), new CompanyServiceCanAddResourcePolicy(), new CompanyServiceCanAddVideoPolicy(), new ConsultantFactory(), new MarketplaceFactory(), new ValidatorFactory(), new OpenStackApiFactory(), new GoogleGeoCodingService(new SapphireGeoCodingQueryRepository(), new UtilFactory(), SapphireTransactionManager::getInstance(), $google_geo_coding_api_key, $google_geo_coding_client_id, $google_geo_coding_private_key), null, new SessionCacheService(), SapphireTransactionManager::getInstance());
 }