diff --git a/appcms/areanet/PIM-UI/default/assets/types/checkbox/checkbox.directive.js b/appcms/areanet/PIM-UI/default/assets/types/checkbox/checkbox.directive.js index efce6c9..fb8bace 100644 --- a/appcms/areanet/PIM-UI/default/assets/types/checkbox/checkbox.directive.js +++ b/appcms/areanet/PIM-UI/default/assets/types/checkbox/checkbox.directive.js @@ -18,20 +18,24 @@ link: function(scope, element, attrs){ var entity = null; - scope.$watch('value',function(data){ - - console.log(scope.value); - - + scope.$watch('checkboxObjects|filter:{selected:true}',function(data){ + var values = []; + for(var i = 0; i < scope.checkboxObjects.length; i++) { + if(scope.checkboxObjects[i].selected) { + values.push(scope.checkboxObjects[i].id.toString()); + } + } + scope.onChangeCallback({key: scope.key, value: values}); },true); //Properties - scope.hide = false; - scope.readonly = false; - scope.schema = null; - scope.value = scope.value ? scope.value : []; - scope.checkboxClass = null; - scope.options = []; + scope.hide = false; + scope.readonly = false; + scope.schema = null; + scope.value = scope.value ? scope.value : []; + scope.checkboxClass = null; + scope.options = []; + scope.checkboxObjects = []; //Functions scope.loadData = loadData; @@ -48,6 +52,7 @@ if(!permissions){ return; } + scope.schema = localStorageService.get('schema')['PIM\\Option']; if(scope.config.horizontalAlignment) { scope.checkboxClass = 'checkbox-inline'; @@ -59,7 +64,6 @@ } function loadData(){ - var properties = ['id', 'modified', 'created', 'user']; var where = {group: scope.config.group}; @@ -76,15 +80,33 @@ EntityService.list(data).then( function successCallback(response) { scope.options = response.data.data; - console.log(scope.options); + var compareArr = []; + for(var n = 0; n < scope.value.length; n++){ + compareArr.push(scope.value[n].id.toString()) + } + for(var i = 0; i < scope.options.length; i++) { + if(scope.value.length > 0) { + if($.inArray( scope.options[i].id.toString(), compareArr ) !== -1) { + scope.checkboxObjects.push({id: scope.options[i].id, value: scope.options[i].value, selected: true}); + } else { + scope.checkboxObjects.push({id: scope.options[i].id, value: scope.options[i].value, selected: false}); + } + } else { + scope.checkboxObjects.push({id: scope.options[i].id, value: scope.options[i].value, selected: false}); + } + } }, function errorCallback(response) { scope.options = []; } ); + + + } + } } } diff --git a/appcms/areanet/PIM-UI/default/assets/types/checkbox/checkbox.html b/appcms/areanet/PIM-UI/default/assets/types/checkbox/checkbox.html index f630700..ec077e2 100644 --- a/appcms/areanet/PIM-UI/default/assets/types/checkbox/checkbox.html +++ b/appcms/areanet/PIM-UI/default/assets/types/checkbox/checkbox.html @@ -2,9 +2,9 @@
-
+
diff --git a/appcms/areanet/PIM/Classes/Types/CheckboxType.php b/appcms/areanet/PIM/Classes/Types/CheckboxType.php index 9d77621..752ae23 100644 --- a/appcms/areanet/PIM/Classes/Types/CheckboxType.php +++ b/appcms/areanet/PIM/Classes/Types/CheckboxType.php @@ -42,6 +42,16 @@ public function processSchema($key, $defaultValue, $propertyAnnotations, $entity $schema['dbtype'] = null; $schema['sortable'] = false; + if(isset($propertyAnnotations['Doctrine\\ORM\\Mapping\\ManyToMany'])) { + $annotations = $propertyAnnotations['Doctrine\\ORM\\Mapping\\ManyToMany']; + $schema['accept'] = $annotations->targetEntity; + + if(isset($propertyAnnotations['Doctrine\\ORM\\Mapping\\JoinTable'])) { + $annotations = $propertyAnnotations['Doctrine\\ORM\\Mapping\\JoinTable']; + $schema['foreign'] = $annotations->name; + } + } + $propertyAnnotations = $propertyAnnotations['Areanet\\PIM\\Classes\\Annotations\\Checkbox']; $optionsGroupName = isset($propertyAnnotations->group) ? $propertyAnnotations->group : $key; @@ -73,6 +83,26 @@ public function fromDatabase(Base $object, $entityName, $property, $flatten = fa $data = array(); $permission = \Areanet\PIM\Entity\Permission::ALL; + $subEntity = null; + + if(isset($config['accept'])){ + $config['accept'] = str_replace(array('Custom\\Entity\\', 'Areanet\\PIM\\Entity\\'), array('', 'PIM\\'), $config['accept']); + $subEntity = $config['accept']; + + if (!($permission = Permission::isReadable($this->app['auth.user'], $config['accept']))) { + return null; + } + + if (isset($config['acceptFrom'])) { + $config['acceptFrom'] = str_replace(array('Custom\\Entity\\', 'Areanet\\PIM\\Entity\\'), array('', 'PIM\\'), $config['acceptFrom']); + $subEntity = $config['acceptFrom']; + + if(!($permission = Permission::isReadable($this->app['auth.user'], $config['acceptFrom']))){ + return null; + } + + } + } if (in_array($property, $propertiesToLoad)) { foreach ($object->$getter() as $objectToLoad) { diff --git a/appcms/areanet/PIM/Entity/Option.php b/appcms/areanet/PIM/Entity/Option.php index aee547e..b43c0b3 100644 --- a/appcms/areanet/PIM/Entity/Option.php +++ b/appcms/areanet/PIM/Entity/Option.php @@ -12,14 +12,6 @@ class Option extends Base { - /** - * @ORM\Column(type="integer") - * @ORM\Id - * @ORM\GeneratedValue(strategy="AUTO") - * @PIM\Config(hide=true) - */ - protected $id; - /** * @ORM\Column(type="string", nullable=false) * @PIM\Config(label="Wert", showInList=20) diff --git a/appcms/areanet/PIM/Entity/OptionGroup.php b/appcms/areanet/PIM/Entity/OptionGroup.php index 7c8ae2c..fd13eac 100644 --- a/appcms/areanet/PIM/Entity/OptionGroup.php +++ b/appcms/areanet/PIM/Entity/OptionGroup.php @@ -12,13 +12,6 @@ class OptionGroup extends Base { - /** - * @ORM\Column(type="integer") - * @ORM\Id - * @ORM\GeneratedValue(strategy="AUTO") - */ - protected $id; - /** * @ORM\Column(type="string", nullable=false, unique=true) * @PIM\Config(label="name", showInList=20)