Skip to content

Commit

Permalink
Resolved compatibility with Nette 2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtech-dobes committed Feb 26, 2015
1 parent 4bdb293 commit 8c1c959
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,12 @@ If the user doesn't support Javascript or gets offline, picker provides several
...

{gpspicker coords}
{label lat}Latitude:{/label} {input lat}
{label lng}Longitude:{/label} {input lng}
{gpspicker:label lat}Latitude:{/gpspicker:label} {gpspicker:input lat}
{gpspicker:label lng}Longitude:{/gpspicker:label} {gpspicker:input lng}
{/gpspicker}
{/form}
```

Keep in mind that you cannot render any other inputs inside of `{gpspicker}` macro.

### Search by address

Enabled by default, GpsPicker supports searching map by typing the address. Extra `<input>` element will be prepended to map,
Expand All @@ -143,7 +141,7 @@ If you like to render it manually, use `search` key:

```html
{gpspicker coords}
{label search /} {input search}
{gpspicker:label search /} {gpspicker:input search}
{/gpspicker}
```

Expand Down
8 changes: 4 additions & 4 deletions client/nette.gpsPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,16 +352,16 @@ var GpsPicker = function () {
}

if (Nette) {
Nette.validators.maxLat = function (elem, arg, value) {
Nette.validators.VojtechDobesNetteFormsGpsPositionPicker_validateMaxLat = function (elem, arg, value) {
return value <= arg;
};
Nette.validators.maxLng = function (elem, arg, value) {
Nette.validators.VojtechDobesNetteFormsGpsPositionPicker_validateMaxLng = function (elem, arg, value) {
return value <= arg;
};
Nette.validators.minLat = function (elem, arg, value) {
Nette.validators.VojtechDobesNetteFormsGpsPositionPicker_validateMinLat = function (elem, arg, value) {
return value >= arg;
};
Nette.validators.minLng = function (elem, arg, value) {
Nette.validators.VojtechDobesNetteFormsGpsPositionPicker_validateMinLng = function (elem, arg, value) {
return value >= arg;
};
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"require": {
"php": ">=5.3.2",
"nette/nette": ">=2.1.0,<2.3"
"nette/nette": ">=2.1.0,<2.4"
},
"autoload": {
"classmap": ["src/"]
Expand Down
19 changes: 12 additions & 7 deletions src/GpsPicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace VojtechDobes\NetteForms;

use Nette\Forms;
use Nette\Forms\Form;
use Nette\Forms\Container;
use Nette\Forms\Controls\BaseControl;
Expand All @@ -19,12 +20,12 @@ abstract class GpsPicker extends BaseControl
{

/** string validation rules */
const MAX_LAT = ':maxLat';
const MAX_LNG = ':maxLng';
const MIN_LAT = ':minLat';
const MIN_LNG = ':minLng';
const MAX_DISTANCE_FROM = ':maxDistanceFrom';
const MIN_DISTANCE_FROM = ':minDistanceFrom';
const MAX_LAT = 'VojtechDobes\NetteForms\GpsPositionPicker::validateMaxLat';
const MAX_LNG = 'VojtechDobes\NetteForms\GpsPositionPicker::validateMaxLng';
const MIN_LAT = 'VojtechDobes\NetteForms\GpsPositionPicker::validateMinLat';
const MIN_LNG = 'VojtechDobes\NetteForms\GpsPositionPicker::validateMinLng';
const MAX_DISTANCE_FROM = 'VojtechDobes\NetteForms\GpsPositionPicker::validateMaxDistanceFrom';
const MIN_DISTANCE_FROM = 'VojtechDobes\NetteForms\GpsPositionPicker::validateMinDistanceFrom';

/** float */
const GREAT_CIRCLE_RADIUS = 6372.795;
Expand Down Expand Up @@ -331,7 +332,11 @@ public function getSearchControlPrototype()
private function getExportedRules()
{
if (!isset($this->exportedRules)) {
$this->exportedRules = self::exportRules($this->rules);
if (method_exists('Nette\Forms\Helpers', 'exportRules')) {
$this->exportedRules = Forms\Helpers::exportRules($this->rules);
} else {
$this->exportedRules = self::exportRules($this->rules);
}
}
return $this->exportedRules;
}
Expand Down
10 changes: 6 additions & 4 deletions src/GpsPickerMacros.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public static function install(Latte\Compiler $compiler)
{
$me = new static($compiler);
$me->addMacro('gpspicker', '$_gpspicker = $_form[%node.word]; $_gpspickerControl = $_gpspicker->getControl(TRUE); echo $_gpspickerControl->addAttributes(%node.array)->startTag()', 'echo $_gpspickerControl->endTag(); unset($_gpspicker, $_gpspickerControl)');
$me->addMacro('input', array($me, 'macroInput'));
$me->addMacro('label', array($me, 'macroLabel'), '?></label><?php');
$me->addMacro('gpspicker:input', array($me, 'macroInput'));
$me->addMacro('gpspicker:label', array($me, 'macroLabel'), '?></label><?php');
}


Expand All @@ -35,7 +35,8 @@ public function macroInput(Latte\MacroNode $node, Latte\PhpWriter $writer)
}
$node = $node->parentNode;
}
return FALSE;

throw new CompileException('{gpspicker:input} can be used only within {gpspicker} macro.');
}


Expand All @@ -54,7 +55,8 @@ public function macroLabel(Latte\MacroNode $node, Latte\PhpWriter $writer)
}
$node = $node->parentNode;
}
return FALSE;

throw new CompileException('{gpspicker:label} can be used only within {gpspicker} macro.');
}

}

0 comments on commit 8c1c959

Please sign in to comment.