Skip to content

Commit

Permalink
#68 Multi-Checkbox mit pflegbaren Optionswerten für Many2Many
Browse files Browse the repository at this point in the history
  • Loading branch information
areanet-foschmid authored and areanet committed Sep 20, 2018
1 parent cd482e8 commit 05f1ddf
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -48,6 +52,7 @@
if(!permissions){
return;
}

scope.schema = localStorageService.get('schema')['PIM\\Option'];
if(scope.config.horizontalAlignment) {
scope.checkboxClass = 'checkbox-inline';
Expand All @@ -59,7 +64,6 @@
}

function loadData(){

var properties = ['id', 'modified', 'created', 'user'];
var where = {group: scope.config.group};

Expand All @@ -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 = [];
}
);



}



}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<pim-plugin key="TYPE_PREPEND" uiblocks="uiblocks"></pim-plugin>
<label for="{{key}}" class="col-sm-2 control-label optional">{{config.label}}<pim-plugin key="TYPE_LABEL_APPEND" uiblocks="uiblocks"></pim-plugin></label>
<div class="col-sm-10">
<div ng-class="checkboxClass" ng-repeat="option in options">
<div ng-class="checkboxClass" ng-repeat="option in checkboxObjects">
<label>
<input type="checkbox" id="{{option.id}}" name="{{config.group}}-{{option.id}}" ng-model="value">
<input type="checkbox" id="{{option.id}}" name="group-{{config.group}}[]" ng-model="option.selected">
{{option.value}}
</label>
</div>
Expand Down
30 changes: 30 additions & 0 deletions appcms/areanet/PIM/Classes/Types/CheckboxType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 0 additions & 8 deletions appcms/areanet/PIM/Entity/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 0 additions & 7 deletions appcms/areanet/PIM/Entity/OptionGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 05f1ddf

Please sign in to comment.