parent
f27a4b8212
commit
75ce93ceca
@ -0,0 +1,138 @@ |
||||
<script> |
||||
(function ($) { |
||||
'use strict'; |
||||
|
||||
var methods = { |
||||
init: function(options) { |
||||
var settings = $.extend({ |
||||
'prototypePrefix': false, |
||||
'prototypeElementPrefix': '<hr />', |
||||
'containerSelector': false |
||||
}, options); |
||||
|
||||
return this.each(function() { |
||||
show($(this), false); |
||||
$(this).change(function() { |
||||
show($(this), true); |
||||
}); |
||||
|
||||
function show(element, replace) { |
||||
var id = element.attr('id'); |
||||
var selectedValue = element.val(); |
||||
var prototypePrefix = id; |
||||
if (false != settings.prototypePrefix) { |
||||
prototypePrefix = settings.prototypePrefix; |
||||
} |
||||
|
||||
var prototypeElement = $('#' + prototypePrefix + '_' + selectedValue); |
||||
var container; |
||||
|
||||
if (settings.containerSelector) { |
||||
container = $(settings.containerSelector); |
||||
} else { |
||||
container = $(prototypeElement.data('container')); |
||||
} |
||||
|
||||
if (!container.length) { |
||||
return; |
||||
} |
||||
|
||||
if (!prototypeElement.length) { |
||||
container.empty(); |
||||
return; |
||||
} |
||||
|
||||
if (replace || !container.html().trim()) { |
||||
container.html(settings.prototypeElementPrefix + prototypeElement.data('prototype')); |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
}; |
||||
|
||||
$.fn.handlePrototypes = function(method) { |
||||
if (methods[method]) { |
||||
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); |
||||
} else if (typeof method === 'object' || !method) { |
||||
return methods.init.apply(this, arguments); |
||||
} else { |
||||
$.error( 'Method ' + method + ' does not exist on jQuery.handlePrototypes' ); |
||||
} |
||||
}; |
||||
})(jQuery); |
||||
|
||||
var $collectionHolder; |
||||
|
||||
// setup an "add a tag" link |
||||
var $addTagLink = $('<a href="#" class="add_tag_link">Add a tag</a>'); |
||||
var $newLinkLi = $('<li></li>').append($addTagLink); |
||||
|
||||
jQuery(document).ready(function() { |
||||
// Get the ul that holds the collection of tags |
||||
$collectionHolder = $('ul.tags'); |
||||
|
||||
// add the "add a tag" anchor and li to the tags ul |
||||
$collectionHolder.append($newLinkLi); |
||||
|
||||
// count the current form inputs we have (e.g. 2), use that as the new |
||||
// index when inserting a new item (e.g. 2) |
||||
$collectionHolder.data('index', $collectionHolder.find(':input').length); |
||||
|
||||
$addTagLink.on('click', function(e) { |
||||
// prevent the link from creating a "#" on the URL |
||||
e.preventDefault(); |
||||
|
||||
// add a new tag form (see next code block) |
||||
addTagForm($collectionHolder, $newLinkLi); |
||||
}); |
||||
}); |
||||
|
||||
function addTagForm($collectionHolder, $newLinkLi) { |
||||
// Get the data-prototype explained earlier |
||||
var prototype = $collectionHolder.data('prototype'); |
||||
|
||||
// get the new index |
||||
var index = $collectionHolder.data('index'); |
||||
|
||||
// Replace '__name__' in the prototype's HTML to |
||||
// instead be a number based on how many items we have |
||||
var newForm = prototype.replace(/__name__/g, index); |
||||
|
||||
// increase the index with one for the next item |
||||
$collectionHolder.data('index', index + 1); |
||||
|
||||
// Display the form in the page in an li, before the "Add a tag" link li |
||||
var $newFormLi = $('<li></li>').append(newForm); |
||||
$newLinkLi.before($newFormLi); |
||||
} |
||||
|
||||
</script> |
||||
|
||||
<div class="tab-pane" id="attributes"> |
||||
|
||||
<ul class="tags" data-prototype="{{ form_widget(form.extraFields.vars.prototype)|e }}"> |
||||
</ul> |
||||
|
||||
{#<div id="sylius-assortment-product-attributes" class="collection-container" data-prototype="{{ ('<div id="sylius_product_attributes___name__">' ~ form_row(form.extraFields.vars.prototype.attribute, {'attr': {'class': 'attribute-chooser'}}))|e }}{{ (form_row(form.extraFields.vars.prototype.value) ~ '</div>')|e }}">#} |
||||
|
||||
{#{% for attributeForm in form.extraFields %}#} |
||||
{#<div class="sylius-assortment-product-attributes-attribute row">#} |
||||
{#<div class="col-md-10">#} |
||||
{#{{ form_widget(attributeForm) }}#} |
||||
{#</div>#} |
||||
{#<div class="col-md-2">#} |
||||
{#<a href="#" class="btn btn-danger" data-collection-button="delete" data-collection="sylius-assortment-product-attributes" data-collection-item="attribute">#} |
||||
{#<i class="glyphicon glyphicon-trash"></i> {{ 'sylius.product.remove_attribute'|trans }}#} |
||||
{#</a>#} |
||||
{#</div>#} |
||||
{#</div>#} |
||||
{#{% endfor %}#} |
||||
{#{% for key, prototype in form.extraFields.vars.prototype.vars.prototypes %}#} |
||||
{#<div id="attribute-prototype_{{ key }}" class="attribute-prototypes" data-prototype="{{ form_widget(prototype)|e }}"></div>#} |
||||
{#{% endfor %}#} |
||||
{#</div>#} |
||||
|
||||
<a href="#" class="btn btn-success btn-block" data-collection-button="add" data-prototype="sylius-assortment-product-attributes" data-collection="sylius-assortment-product-attributes"> |
||||
{{ 'sylius.product.add_attribute'|trans }} |
||||
</a> |
||||
</div> |
@ -0,0 +1,22 @@ |
||||
|
||||
<div class="tab-pane active" id="main"> |
||||
{{ form_row(form.username) }} |
||||
{{ form_row(form.email) }} |
||||
{{ form_row(form.firstname) }} |
||||
{{ form_row(form.lastname) }} |
||||
{{ form_row(form.phone) }} |
||||
{{ form_row(form.official_code) }} |
||||
{{ form_row(form.timezone) }} |
||||
{{ form_row(form.locale) }} |
||||
{{ form_row(form.picture_uri) }} |
||||
<hr /> |
||||
<div class="row"> |
||||
<div class="col-md-6"> |
||||
<hr /> |
||||
|
||||
</div> |
||||
<div class="col-md-6"> |
||||
|
||||
</div> |
||||
</div> |
||||
</div> |
@ -0,0 +1,4 @@ |
||||
<ul class="nav nav-tabs"> |
||||
<li class="active"><a href="#main" data-toggle="tab">{{ 'User'|trans }}</a></li> |
||||
<li><a href="#attributes" data-toggle="tab">{{ 'Extra fields'|trans }}</a></li> |
||||
</ul> |
@ -0,0 +1,12 @@ |
||||
{% form_theme form '@ChamiloCore/User/forms.html.twig' %} |
||||
|
||||
{{ form_errors(form) }} |
||||
{% include '@ChamiloCore/User/Form/_tabs.html.twig' %} |
||||
<br> |
||||
<div class="tab-content"> |
||||
{% include '@ChamiloCore/User/Form/_main.html.twig' %} |
||||
{% include '@ChamiloCore/User/Form/_attributes.html.twig' %} |
||||
</div> |
||||
<hr> |
||||
|
||||
{{ form_widget(form._token) }} |
@ -0,0 +1,8 @@ |
||||
{% from 'SyliusResourceBundle:Macros:actions.html.twig' import create %} |
||||
|
||||
{{ form_errors(form) }} |
||||
|
||||
<form action="{{ url }}" method="post" class="form-horizontal" {{ form_enctype(form) }} novalidate> |
||||
{% include '@ChamiloCore/User/_form.html.twig' %} |
||||
{{ create() }} |
||||
</form> |
@ -0,0 +1,135 @@ |
||||
{% extends 'form_div_layout.html.twig' %} |
||||
|
||||
{% block choice_widget_collapsed %} |
||||
{% set attr = attr|merge({'class': attr.class|default('') ~ ' form-control'}) %} |
||||
{{ parent() }} |
||||
{% endblock choice_widget_collapsed %} |
||||
|
||||
{% block textarea_widget %} |
||||
{% set attr = attr|merge({'class': attr.class|default('') ~ ' form-control'}) %} |
||||
{{ parent() }} |
||||
{% endblock textarea_widget %} |
||||
|
||||
{% block form_widget_simple %} |
||||
{% spaceless %} |
||||
{% set attr = attr|merge({'class': attr.class|default('') ~ ' form-control'}) %} |
||||
{% set type = type|default('text') %} |
||||
|
||||
{% if 'file' == type %} |
||||
<span class="btn-primary btn-lg file-overlay"><i class="icon-folder-open"></i> {{ 'sylius.form.choose_file'|trans }}</span> |
||||
{% endif %} |
||||
{{ parent() }} |
||||
{% endspaceless %} |
||||
{% endblock form_widget_simple %} |
||||
|
||||
{% block form_label %} |
||||
{% spaceless %} |
||||
{% set label_attr = label_attr|merge({'class': label_attr.class|default('col-lg-2') ~ ' control-label'}) %} |
||||
{{ parent() }} |
||||
{% endspaceless %} |
||||
{% endblock form_label %} |
||||
|
||||
{% block money_widget %} |
||||
{% spaceless %} |
||||
<div class="input-group"> |
||||
<span class="input-group-addon">{{ money_pattern|replace({'{{ widget }}': ''}) }}</span> |
||||
{{ block('form_widget_simple') }} |
||||
</div> |
||||
{% endspaceless %} |
||||
{% endblock money_widget %} |
||||
|
||||
{% block percent_widget %} |
||||
{% spaceless %} |
||||
<div class="input-group"> |
||||
<span class="input-group-addon">%</span> |
||||
{{ block('form_widget_simple') }} |
||||
</div> |
||||
{% endspaceless %} |
||||
{% endblock percent_widget %} |
||||
|
||||
{% block datetime_widget %} |
||||
{% spaceless %} |
||||
{% if widget == 'single_text' %} |
||||
{{ block('form_widget_simple') }} |
||||
{% else %} |
||||
<div class="form-group"> |
||||
{{ form_widget(form.date) }} |
||||
{{ form_widget(form.time) }} |
||||
</div> |
||||
{% endif %} |
||||
{% endspaceless %} |
||||
{% endblock datetime_widget %} |
||||
|
||||
{% block date_widget %} |
||||
{% spaceless %} |
||||
{% if widget == 'single_text' %} |
||||
{{ block('form_widget_simple') }} |
||||
{% else %} |
||||
{{ '{{ year }} / {{ month }} / {{ day }}'|replace({ |
||||
'{{ year }}': form_widget(form.year, {'attr': {'style': 'display: inline; width: 100px;'}}), |
||||
'{{ month }}': form_widget(form.month, {'attr': {'style': 'display: inline; width: 100px;'}}), |
||||
'{{ day }}': form_widget(form.day, {'attr': {'style': 'display: inline; width: 100px;'}}), |
||||
})|raw }} |
||||
{% endif %} |
||||
{% endspaceless %} |
||||
{% endblock date_widget %} |
||||
|
||||
{% block time_widget %} |
||||
{% spaceless %} |
||||
{% if widget == 'single_text' %} |
||||
{{ block('form_widget_simple') }} |
||||
{% else %} |
||||
{% set vars = widget == 'text' ? { 'attr': { 'size': 1, 'style': 'width: 60px; display: inline;' }} : {} %} |
||||
{{ form_widget(form.hour, vars) }}{% if with_minutes %}:{{ form_widget(form.minute, vars) }}{% endif %}{% if with_seconds %} {{ form_widget(form.second, vars) }}{% endif %} |
||||
{% endif %} |
||||
{% endspaceless %} |
||||
{% endblock time_widget %} |
||||
|
||||
{% block form_row %} |
||||
{% spaceless %} |
||||
<div class="form-group{% if errors|length > 0 %} has-error{% endif %}"> |
||||
{{ form_label(form) }} |
||||
<div class="col-lg-10"> |
||||
{{ form_widget(form) }} |
||||
{% for error in errors %} |
||||
<span class="help-block form-error"> |
||||
{{ |
||||
error.messagePluralization is null |
||||
? error.messageTemplate|trans(error.messageParameters, 'validators') |
||||
: error.messageTemplate|transchoice(error.messagePluralization, error.messageParameters, 'validators') |
||||
}} |
||||
</span> |
||||
{% endfor %} |
||||
</div> |
||||
</div> |
||||
{% endspaceless %} |
||||
{% endblock form_row %} |
||||
|
||||
{% block sonata_media_type_widget %} |
||||
<div class="col-xs-3 pull-left"> |
||||
{% if value is not empty and value.providerReference %} |
||||
<div class="pull-left" style="margin-right: 5px"> |
||||
{% thumbnail value, 'admin' with {'class': 'img-polaroid media-object'} %} |
||||
</div> |
||||
|
||||
{% if sonata_admin_enabled is defined and sonata_admin_enabled %} |
||||
<a href="{{ url('admin_sonata_media_media_edit', {id: value.id}) }}"><strong>{{ value.name }}</strong></a> |
||||
{% else %} |
||||
<strong>{{ value.name }}</strong> |
||||
{% endif %} |
||||
<br /> |
||||
<span type="label">{{ value.providerName|trans({}, 'SonataMediaBundle') }}</span> ~ {{ value.context }} |
||||
{% else %} |
||||
<div class="pull-left" style="margin-right: 5px"> |
||||
<img src="{{ asset('bundles/sonatamedia/grey.png') }}" class="img-polaroid media-object" style="width: 85px; height: 85px"/> |
||||
</div> |
||||
<strong>{{ 'no_linked_media'|trans({}, 'SonataMediaBundle') }}</strong> <br /> |
||||
<span type="label">{{ form.vars['provider']|trans({}, 'SonataMediaBundle') }} ~ {{ form.vars['context']|trans({}, 'SonataMediaBundle') }}</span> |
||||
{% endif %} |
||||
</div> |
||||
|
||||
<div class="span3 pull-left"> |
||||
{{ 'link_media'|trans({}, 'SonataMediaBundle') }} |
||||
{{ block('form_widget') }} |
||||
</div> |
||||
{% endblock sonata_media_type_widget %} |
@ -0,0 +1,61 @@ |
||||
<?php |
||||
|
||||
|
||||
namespace Chamilo\UserBundle\Form\Type; |
||||
|
||||
use Symfony\Component\Form\AbstractType; |
||||
use Symfony\Component\OptionsResolver\OptionsResolverInterface; |
||||
|
||||
/** |
||||
* Attribute choice form type. |
||||
* |
||||
* @author Paweł Jędrzejewski <pawel@sylius.org> |
||||
*/ |
||||
abstract class AttributeChoiceType extends AbstractType |
||||
{ |
||||
/** |
||||
* Name of the attributes subject. |
||||
* |
||||
* @var string |
||||
*/ |
||||
protected $subjectName; |
||||
|
||||
/** |
||||
* Attribute class name. |
||||
* |
||||
* @var string |
||||
*/ |
||||
protected $className; |
||||
|
||||
/** |
||||
* Constructor. |
||||
* |
||||
* @param string $subjectName |
||||
* @param string $className |
||||
*/ |
||||
public function __construct($subjectName, $className) |
||||
{ |
||||
$this->subjectName = $subjectName; |
||||
$this->className = $className; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritdoc} |
||||
*/ |
||||
public function setDefaultOptions(OptionsResolverInterface $resolver) |
||||
{ |
||||
$resolver |
||||
->setDefaults(array( |
||||
'class' => $this->className |
||||
)) |
||||
; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritdoc} |
||||
*/ |
||||
public function getName() |
||||
{ |
||||
return sprintf('chamilo_%s_extra_field_choice', $this->subjectName); |
||||
} |
||||
} |
@ -0,0 +1,28 @@ |
||||
<?php |
||||
|
||||
/* |
||||
* This file is part of the Sylius package. |
||||
* |
||||
* (c) Paweł Jędrzejewski |
||||
* |
||||
* For the full copyright and license information, please view the LICENSE |
||||
* file that was distributed with this source code. |
||||
*/ |
||||
|
||||
namespace Chamilo\UserBundle\Form\Type; |
||||
|
||||
/** |
||||
* Attribute choice form type. |
||||
* |
||||
* @author Paweł Jędrzejewski <pawel@sylius.org> |
||||
*/ |
||||
class AttributeEntityChoiceType extends AttributeChoiceType |
||||
{ |
||||
/** |
||||
* {@inheritdoc} |
||||
*/ |
||||
public function getParent() |
||||
{ |
||||
return 'entity'; |
||||
} |
||||
} |
@ -0,0 +1,65 @@ |
||||
<?php |
||||
|
||||
namespace Chamilo\UserBundle\Form; |
||||
|
||||
use Sylius\Bundle\AttributeBundle\Form\EventListener\BuildAttributeFormChoicesListener; |
||||
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType; |
||||
use Sylius\Component\Attribute\Model\AttributeTypes; |
||||
use Symfony\Component\Form\FormBuilderInterface; |
||||
|
||||
/** |
||||
* Attribute type. |
||||
* |
||||
* @author Paweł Jędrzejewski <pawel@sylius.org> |
||||
* @author Leszek Prabucki <leszek.prabucki@gmail.com> |
||||
*/ |
||||
class AttributeType extends AbstractResourceType |
||||
{ |
||||
/** |
||||
* Subject name. |
||||
* |
||||
* @var string |
||||
*/ |
||||
protected $subjectName; |
||||
|
||||
/** |
||||
* Constructor. |
||||
* |
||||
* @param string $dataClass |
||||
* @param array $validationGroups |
||||
* @param string $subjectName |
||||
*/ |
||||
public function __construct($dataClass, array $validationGroups, $subjectName) |
||||
{ |
||||
parent::__construct($dataClass, $validationGroups); |
||||
|
||||
$this->subjectName = $subjectName; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritdoc} |
||||
*/ |
||||
public function buildForm(FormBuilderInterface $builder, array $options) |
||||
{ |
||||
$builder |
||||
->add('name', 'text', array( |
||||
'label' => 'sylius.form.attribute.name' |
||||
)) |
||||
->add('presentation', 'text', array( |
||||
'label' => 'sylius.form.attribute.presentation' |
||||
)) |
||||
->add('type', 'choice', array( |
||||
'choices' => AttributeTypes::getChoices() |
||||
)) |
||||
->addEventSubscriber(new BuildAttributeFormChoicesListener($builder->getFormFactory())) |
||||
; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritdoc} |
||||
*/ |
||||
public function getName() |
||||
{ |
||||
return sprintf('%s_extra_field', $this->subjectName); |
||||
} |
||||
} |
@ -0,0 +1,105 @@ |
||||
<?php |
||||
|
||||
namespace Chamilo\UserBundle\Form\Type; |
||||
|
||||
use Sylius\Bundle\AttributeBundle\Form\EventListener\BuildAttributeValueFormListener; |
||||
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType; |
||||
//use Sylius\Component\Product\Model\AttributeInterface; |
||||
use Symfony\Component\Form\FormBuilderInterface; |
||||
use Symfony\Component\Form\FormInterface; |
||||
use Symfony\Component\Form\FormView; |
||||
|
||||
/** |
||||
* Attribute value form type. |
||||
* |
||||
* @author Paweł Jędrzejewski <pawel@sylius.org> |
||||
*/ |
||||
class AttributeValueType extends AbstractResourceType |
||||
{ |
||||
/** |
||||
* Attributes subject name. |
||||
* |
||||
* @var string |
||||
*/ |
||||
protected $subjectName; |
||||
|
||||
/** |
||||
* Constructor. |
||||
* |
||||
* @param string $dataClass |
||||
* @param array $validationGroups |
||||
* @param string $subjectName |
||||
*/ |
||||
public function __construct($dataClass, array $validationGroups, $subjectName) |
||||
{ |
||||
parent::__construct($dataClass, $validationGroups); |
||||
|
||||
$this->subjectName = $subjectName; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritdoc} |
||||
*/ |
||||
public function buildForm(FormBuilderInterface $builder, array $options) |
||||
{ |
||||
$builder |
||||
->add('extraField', sprintf('chamilo_%s_extra_field_choice', $this->subjectName)) |
||||
->addEventSubscriber(new BuildAttributeValueFormListener($builder->getFormFactory())) |
||||
; |
||||
|
||||
$prototypes = array(); |
||||
foreach ($this->getAttributes($builder) as $attribute) { |
||||
$configuration = $attribute->getConfiguration(); |
||||
$type = $attribute->getFieldTypeToString(); |
||||
|
||||
if (!is_array($configuration)) { |
||||
$configuration = array(); |
||||
} |
||||
|
||||
if (empty($type)) { |
||||
continue; |
||||
} |
||||
|
||||
$prototypes[] = $builder->create( |
||||
'value', |
||||
$type, |
||||
$configuration |
||||
)->getForm(); |
||||
} |
||||
|
||||
$builder->setAttribute('prototypes', $prototypes); |
||||
} |
||||
|
||||
/** |
||||
* {@inheritdoc} |
||||
*/ |
||||
public function buildView(FormView $view, FormInterface $form, array $options) |
||||
{ |
||||
$view->vars['prototypes'] = array(); |
||||
|
||||
foreach ($form->getConfig()->getAttribute('prototypes', array()) as $name => $prototype) { |
||||
$view->vars['prototypes'][$name] = $prototype->createView($view); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* {@inheritdoc} |
||||
*/ |
||||
public function getName() |
||||
{ |
||||
return sprintf('chamilo_%s_extra_field_value', $this->subjectName); |
||||
//return 'chamilo_user_extra_field_value'; |
||||
} |
||||
|
||||
/** |
||||
* Get attributes |
||||
* |
||||
* @param FormBuilderInterface $builder |
||||
* |
||||
* @return AttributeInterface[] |
||||
*/ |
||||
private function getAttributes(FormBuilderInterface $builder) |
||||
{ |
||||
return $builder->get('extraField')->getOption('choice_list')->getChoices(); |
||||
} |
||||
} |
Loading…
Reference in new issue