Skip to content

Commit

Permalink
Merge pull request sonata-project#329 from WouterJ/resource
Browse files Browse the repository at this point in the history
Use ResourceBundle as tree backend
  • Loading branch information
dbu committed Apr 19, 2015
2 parents b878a49 + 6f1d238 commit 8f6c6e1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 31 deletions.
3 changes: 3 additions & 0 deletions Form/Type/TreeModelType.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$builder->addViewTransformer(new ModelToIdTransformer($options['model_manager'], $options['class']), true);
$builder->setAttribute('root_node', $options['root_node']);
$builder->setAttribute('select_root_node', $options['select_root_node']);
$builder->setAttribute('repository_name', $options['repository_name']);
}

/**
Expand All @@ -71,6 +72,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)
$view->vars['tree'] = $this->tree;
$view->vars['root_node'] = $form->getConfig()->getAttribute('root_node');
$view->vars['select_root_node'] = $form->getConfig()->getAttribute('select_root_node');
$view->vars['repository_name'] = $form->getConfig()->getAttribute('repository_name');
$view->vars['routing_defaults'] = $this->defaults;
}

Expand All @@ -90,6 +92,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
'root_node' => '/',
'select_root_node' => false,
'parent' => 'choice',
'repository_name' => 'default',
'preferred_choices' => array(),
'choice_list' => function (Options $options, $previousValue) {
return new ModelChoiceList(
Expand Down
12 changes: 11 additions & 1 deletion Resources/views/Form/form_admin_fields.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,17 @@ file that was distributed with this source code.
var defaults = {% include 'SonataDoctrinePHPCRAdminBundle:Tree:routing_defaults.html.twig' with {'routing_defaults': routing_defaults} %};
$('#{{ id }}-tree-selector').cmfTree({
data_url: Routing.generate('_cmf_tree_{{ tree.alias }}_children', defaults),
request: {
load: function (nodePath) {
return {
url: '{{ path('_cmf_resource', {
repositoryName: repository_name,
path: '__path__'
}) }}'.replace('__path__', nodePath)
{# todo: include routing defaults #}
};
},
},
path_output: '#{{ id }}-tree-selector-output'
});
});
Expand Down
40 changes: 11 additions & 29 deletions Resources/views/Tree/tree.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,21 @@ file that was distributed with this source code.

{% include 'CmfTreeBrowserBundle:Base:tree.html.twig' %}
<script type="text/javascript">
$(document).ready(function() {
var treeState = AdminTree.generateTreeStateArray("{{ selected_node }}");
jQuery(function($) {
var defaults = {% include 'SonataDoctrinePHPCRAdminBundle:Tree:routing_defaults.html.twig' with {'routing_defaults': routing_defaults} %};
AdminTree.initTree({
"selector": "#tree",
"rootNode": "{{ root_node }}",
"selected": "{{ selected_node }}",
"labels": {{ tree.labels | json_encode() | raw}},
"ajax": {
"children_url": Routing.generate("_cmf_tree_{{ tree.alias }}_children", defaults),
"move_url": Routing.generate("_cmf_tree_{{ tree.alias }}_move", defaults),
"reorder_url": Routing.generate("_cmf_tree_{{ tree.alias }}_reorder", defaults)
$('#tree').cmfTree({
request: {
load: function (nodePath) {
return {
url: Routing.generate('_cmf_resource', jQuery.extend(defaults, {
repositoryName: 'phpcrodm_repo',
path: nodePath
}))
};
},
},
"path": {
"expanded": treeState,
"preloaded": treeState
},
"types": {{ tree.nodeTypes | json_encode() | raw}},
"routing_defaults": defaults,
"createInOverlay": "{{ create_in_overlay }}",
"editInOverlay": "{{ edit_in_overlay }}",
"deleteInOverlay": "{{ delete_in_overlay }}"
});
{% if confirm_move is defined and confirm_move %}
$('#tree').on('cmf_tree.move', function(e) {
if (!confirm('{{ 'confirm_move_node' | trans({}, 'SonataDoctrinePHPCRAdmin') }}')) {
e.preventDefault();
}
});
{% endif %}
});
</script>

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"symfony/property-access": "~2.2",
"doctrine/phpcr-odm": "~1.1",
"doctrine/phpcr-bundle": "~1.1",
"symfony-cmf/tree-browser-bundle": "~2.0"
"symfony-cmf/tree-browser-bundle": "~2.0",
"symfony-cmf/resource-rest-bundle": "~1.0"
},
"require-dev": {
"jackalope/jackalope-jackrabbit": "~1.0"
Expand Down

0 comments on commit 8f6c6e1

Please sign in to comment.