Author: jaimesuez
Date: 2010-04-19 05:22:32 +0200 (Mon, 19 Apr 2010)
New Revision: 29200
Modified:
plugins/sfDoctrineAjaxFormPlugin/lib/widget/sfWidgetFormDinamicEmbeddedForm.class.php
plugins/sfDoctrineAjaxFormPlugin/modules/ajax_form/templates/_add_embedded_form.php
plugins/sfDoctrineAjaxFormPlugin/modules/ajax_form/templates/_autocomplete_with_embedded_forms_default.php
plugins/sfDoctrineAjaxFormPlugin/modules/ajax_form/templates/_embedded_form_js.php
Log:
Opcion WITH_HIDE: Siempre expandidos (No aparece el hide, ni los link)
Opcion MAX_EMBEDDED: Al llegar al maximo desaparece boton para agregar mas
Modified:
plugins/sfDoctrineAjaxFormPlugin/lib/widget/sfWidgetFormDinamicEmbeddedForm.class.php
===================================================================
---
plugins/sfDoctrineAjaxFormPlugin/lib/widget/sfWidgetFormDinamicEmbeddedForm.class.php
2010-04-19 01:35:20 UTC (rev 29199)
+++
plugins/sfDoctrineAjaxFormPlugin/lib/widget/sfWidgetFormDinamicEmbeddedForm.class.php
2010-04-19 03:22:32 UTC (rev 29200)
@@ -1,10 +1,8 @@
<?php
-
class sfWidgetFormDinamicEmbeddedForm extends
sfWidgetFormDoctrineJQueryAutocompleter
{
-
-
+
protected function configure($options = array(), $attributes = array())
{
$this->addOption('model', module_to_class($options['widget_model']));
@@ -17,7 +15,7 @@
//traducción de (form_module_relation - module_relation) ->
foreign_relation
$this->addRequiredOption('foreign_relation');
$foreign_relation = explode('-', $options['foreign_relation']);
- $this->options["form_module_relation"] = $foreign_relation[0] == "none" ?
null : $foreign_relation[0];
+ $this->options["form_module_relation"] = $foreign_relation[0] == "none" ?
null : $foreign_relation[0];
$this->options["module_relation"] = $foreign_relation[1] == "none" ? null
: $foreign_relation[1];
//traduccion embedded_name = widget_name."s"
@@ -25,9 +23,24 @@
$this->options["embedded_name"] = $options["widget_name"] . "s";
//traduccion: sacamos el número embebido del segundo campo de foregin_type
+ $this->addOption('max_embedded', null); #numero grande
$foreign_type = explode('-', $options['foreign_type']);
$this->addRequiredOption('foreign_type');
- $this->options["number_embedded"] = strtolower($foreign_type[1]);
+ if (isset($options["max_embedded"]) && $options["max_embedded"] > 1 &&
strtolower($foreign_type[1]) == "many")
+ {
+ $this->options["number_embedded"] = $options["max_embedded"];
+ }
+ else
+ {
+ if (strtolower($foreign_type[1]) == "many")
+ {
+ $this->options["number_embedded"] = 10000; #numero grande
+ }
+ else
+ {
+ $this->options["number_embedded"] = 1;
+ }
+ }
//traduccion: columns -> widget_columns
$this->addOption('widget_columns', array('nombre'));
@@ -39,7 +52,7 @@
//datos opcionales
$this->addOption('foreign_alias', null); #solo requerido para xxx-MANY
- if(!isset($options["foreign_alias"]))
+ if (!isset($options["foreign_alias"]))
{
$this->options["foreign_alias"] = $this->options["form_module_relation"];
}
@@ -52,54 +65,60 @@
$this->addOption('unset', array());
$this->addOption('thumbnail', null);
+ $this->addOption('with_hide', true);
+ $this->addOption('initial_embedded', 0);
+
+
//se dejan opcionales estas opciones del autocompleter normal (eran
requeridas)
- $this->addOption('url',
sfContext::getInstance()->getController()->genUrl('ajax_form/autocomplete?'.
- 'widget_model='. module_to_class($options['widget_model']) .
- '&widget_columns=' . implode('~', $options['widget_columns'])
+ $this->addOption('url',
sfContext::getInstance()->getController()->genUrl('ajax_form/autocomplete?' .
+ 'widget_model=' . module_to_class($options['widget_model']) .
+ '&widget_columns=' . implode('~', $options['widget_columns'])
));
parent::configure($options, $attributes);
}
-
+
public function render($name, $value = null, $attributes = array(), $errors
= array())
{
//name exploded para obtener widget_name y form_model
- $name_exploded = explode('%', str_replace(array('[',']'), array('%',''),
$name));
+ $name_exploded = explode('%', str_replace(array('[', ']'), array('%', ''),
$name));
//valores que se utilizarán
- $form = $this->getOption('form');
- $module = $this->getOption('module');
- $widget_model = $this->getOption('widget_model');
- $widget_name = $this->getOption('widget_name');
- $embedded_name = $this->getOption('embedded_name');
- $is_autocomplete = $this->getOption('is_autocomplete');
- $number_embedded = $this->getOption('number_embedded');
- $module_relation = $this->getOption('module_relation');
- $form_module_relation = $this->getOption('form_module_relation');
- $foreign_type = $this->getOption('foreign_type');
- $columns = $this->getOption('columns');
- $credentials = $this->getOption('credentials');
- $partial = $this->getOption('partial');
- $create_partial = $this->getOption('create_partial');
- $thumbnail = $this->getOption('thumbnail');
+ $form = $this->getOption('form');
+ $module = $this->getOption('module');
+ $widget_model = $this->getOption('widget_model');
+ $widget_name = $this->getOption('widget_name');
+ $embedded_name = $this->getOption('embedded_name');
+ $is_autocomplete = $this->getOption('is_autocomplete');
+ $number_embedded = $this->getOption('number_embedded');
+ $module_relation = $this->getOption('module_relation');
+ $form_module_relation = $this->getOption('form_module_relation');
+ $foreign_type = $this->getOption('foreign_type');
+ $columns = $this->getOption('columns');
+ $credentials = $this->getOption('credentials');
+ $partial = $this->getOption('partial');
+ $create_partial = $this->getOption('create_partial');
+ $thumbnail = $this->getOption('thumbnail');
+ $with_hide = $this->getOption('with_hide');
+ $initial_embedded = $this->getOption('initial_embedded');
- $hide = (isset ($form[$embedded_name][0]) && $number_embedded == 'one') ?
'$("#autocomplete_'. $module .'_form_'. $widget_name .'").hide(); $("#img_'.
$module .'_form_'. $widget_name .'").hide();' : '';
- $replace_with = !$is_autocomplete ? '$("#autocomplete_'. $module
.'_form_'. $widget_name .'").replaceWith("");$("#img_'. $module .'_form_'.
$widget_name .'").replaceWith("");' : '';
+ $hide = $form[$embedded_name]->count() >= $number_embedded ?
'$("#autocomplete_' . $module . '_form_' . $widget_name . '").hide(); $("#img_'
. $module . '_form_' . $widget_name . '").hide();' : '';
+ $replace_with = !$is_autocomplete? '$("#autocomplete_' . $module .
'_form_' . $widget_name . '").replaceWith("");$("#img_' . $module . '_form_' .
$widget_name . '").replaceWith("");' : '';
$visibleValue = $this->getOption('value_callback') ?
call_user_func($this->getOption('value_callback'), $value) : $value;
return
- $this->renderTag('input', array('type' => 'hidden', 'name' => $name,
'value' => $value)).
- sfWidgetFormInput::render('autocomplete_'.$name, $visibleValue,
$attributes, $errors).
+ $this->renderTag('input', array('type' => 'hidden', 'name' => $name,
'value' => $value)) .
+ sfWidgetFormInput::render('autocomplete_' . $name, $visibleValue,
$attributes, $errors) .
<<<EOHTML
<img id="img_{$this->generateId($name)}" style="width: 20px;"
src="/themeAdmin/images/icons/find.gif"/>
<script type="text/javascript">
jQuery(document).ready(function() {
- jQuery("#{$this->generateId('autocomplete_'.$name)}")
+ jQuery("#{$this->generateId('autocomplete_' . $name)}")
.autocomplete("{$this->getOption('url')}", jQuery.extend({}, {
dataType: "json",
parse: function(data) {
@@ -113,7 +132,7 @@
.result(function(event, data)
{
jQuery("#{$this->generateId($name)}").val(data[1]);
- jQuery("#{$this->generateId('autocomplete_'.$name)}").trigger("blur");
+ jQuery("#{$this->generateId('autocomplete_' . $name)}").trigger("blur");
});
});
@@ -126,26 +145,23 @@
. include_partial($partial, array(
- 'form' => $form,
- 'widget_name' => $widget_name,
- 'module' => $module,
- 'widget_module' => $widget_model,
- 'embedded_name' => $embedded_name,
- 'is_autocomplete' => $is_autocomplete,
- 'number_embedded' => $number_embedded,
- 'module_relation' => $module_relation,
- 'form_module_relation' => $form_module_relation,
- 'foreign_type' => $foreign_type,
- 'columns' => $columns,
- 'credentials' => $credentials,
- 'thumbnail' => $thumbnail,
- 'create_partial' => $create_partial,
+ 'form' => $form,
+ 'widget_name' => $widget_name,
+ 'module' => $module,
+ 'widget_module' => $widget_model,
+ 'embedded_name' => $embedded_name,
+ 'is_autocomplete' => $is_autocomplete,
+ 'number_embedded' => $number_embedded,
+ 'module_relation' => $module_relation,
+ 'form_module_relation' => $form_module_relation,
+ 'foreign_type' => $foreign_type,
+ 'columns' => $columns,
+ 'credentials' => $credentials,
+ 'thumbnail' => $thumbnail,
+ 'create_partial' => $create_partial,
+ "with_hide" => $with_hide,
+ "initial_embedded" => $initial_embedded,
+
));
-
}
-
-
-
-
-
}
Modified:
plugins/sfDoctrineAjaxFormPlugin/modules/ajax_form/templates/_add_embedded_form.php
===================================================================
---
plugins/sfDoctrineAjaxFormPlugin/modules/ajax_form/templates/_add_embedded_form.php
2010-04-19 01:35:20 UTC (rev 29199)
+++
plugins/sfDoctrineAjaxFormPlugin/modules/ajax_form/templates/_add_embedded_form.php
2010-04-19 03:22:32 UTC (rev 29200)
@@ -6,7 +6,6 @@
$widget_module =
class_to_module($form->getWidget($widget_name)->getOption('widget_model'));
$embedded_name = $form->getWidget($widget_name)->getOption('embedded_name');
$is_autocomplete =
$form->getWidget($widget_name)->getOption('is_autocomplete');
-$number_embedded =
$form->getWidget($widget_name)->getOption('number_embedded');
$columns = $form->getWidget($widget_name)->getOption('columns');
$thumbnail = $form->getWidget($widget_name)->getOption('thumbnail');
@@ -45,7 +44,7 @@
id = $(this).attr("class");
$("#" + id).replaceWith('');
- //mostramos el "autocomplete" y el "agregar" por si es "number_embedded
= one" y se borró
+ //mostramos el "autocomplete" y el "agregar" por si es y se borraron
anteriormente
$("#autocomplete_<?php echo $module ?>_form_<?php echo $widget_name
?>").show();
$("#<?php echo $module ?>_form_<?php echo $widget_name ?>_crear").show();
});
Modified:
plugins/sfDoctrineAjaxFormPlugin/modules/ajax_form/templates/_autocomplete_with_embedded_forms_default.php
===================================================================
---
plugins/sfDoctrineAjaxFormPlugin/modules/ajax_form/templates/_autocomplete_with_embedded_forms_default.php
2010-04-19 01:35:20 UTC (rev 29199)
+++
plugins/sfDoctrineAjaxFormPlugin/modules/ajax_form/templates/_autocomplete_with_embedded_forms_default.php
2010-04-19 03:22:32 UTC (rev 29200)
@@ -8,42 +8,48 @@
'addForm'.$widget_name: es el número del formulario embebido
-->
+<?php echo "numero embebidos: " . $form[$embedded_name]->count() ?>
+<?php echo "maximo: " . $number_embedded ?>
+
<!--############################### BOTONES PARA AGREGAR Y FRASES
################################## -->
<div>
<?php if ($is_autocomplete): ?>
<img style="display:none" src="/sfDoctrinePlugin/images/delete.png"
id="<?php echo $module ?>_form_<?php echo $widget_name ?>_delete" />
<?php endif ?>
+ <?php if ($form[$embedded_name]->count() < $number_embedded): ?>
<a id="<?php echo $module ?>_form_<?php echo $widget_name ?>_crear"
style="cursor:pointer;">Crear <?php echo $widget_name ?></a>
+ <?php endif ?>
</div>
<!--############################### LINKS A OBJETOS RELACIONADOS Y EMBEDDED
FORMS ################################## -->
<div class="sf_admin_form_field_<?php echo $widget_name ?>_related_objects"
style="display:none;">
- <!--############################### FIELDS DE "NOMBRES" OBJETOS
RELACIONADOS YA CREADOS ################################## -->
+ <!--############################### LINKS DE "NOMBRES" OBJETOS RELACIONADOS
YA CREADOS ################################## -->
+ <?php if ($with_hide): ?>
<div id="<?php echo $module ?>_form_<?php echo $widget_name
?>_related_objects">
- <?php if ($form[$embedded_name]->count() > 0): ?>
+ <?php if ($form[$embedded_name]->count() > 0): ?>
<div>
- <?php foreach ($form[$embedded_name] as $embedded): ?>
+ <?php foreach ($form[$embedded_name] as $embedded): ?>
<div id="<?php echo $module ?>_form_<?php echo $widget_name
?>_related_object_name_<?php echo $embedded['id']->getValue() ?>"
style="<?php echo $embedded->renderError() != '' ? 'display:none' :
'' ?>" class="content">
<a id="<?php echo $module ?>_form_<?php echo $widget_name
?>_related_object_link_<?php echo $embedded['id']->getValue() ?>"
style="cursor:pointer; font-weight:bold;">
<!-- thumbnail opcional -->
- <?php echo include_partial("ajax_form/thumbnail",
array("thumbnail_info" => $thumbnail, "object" =>
Doctrine::getTable(module_to_class($widget_module))->find($embedded["id"]->getValue())))
?>
+ <?php echo include_partial("ajax_form/thumbnail",
array("thumbnail_info" => $thumbnail, "object" =>
Doctrine::getTable(module_to_class($widget_module))->find($embedded["id"]->getValue())))
?>
- <?php foreach ($columns as $column): ?>
- <?php echo $embedded[$column]->getValue() . ' ' ?>
- <?php endforeach ?>
+ <?php foreach ($columns as $column): ?>
+ <?php echo $embedded[$column]->getValue() . ' ' ?>
+ <?php endforeach ?>
</a>
-
</div>
- <?php endforeach ?>
+ <?php endforeach ?>
</div>
- <?php endif ?>
+ <?php endif ?>
</div>
+ <?php endif ?>
<!--############################### EMBEDDED FORMS
################################## -->
@@ -53,14 +59,16 @@
<?php foreach ($form[$embedded_name] as $embed_key => $embedded): ?>
<div id="<?php echo $module ?>_form_<?php echo $widget_name
?>_related_object_form_<?php echo $embedded['id']->getValue() ?>"
- class="content" style="margin-bottom:6px; <?php echo
$embedded->renderError() != '' ? '' : 'display:none' ?> ">
+ class="content" style="margin-bottom:6px; <?php echo
$embedded->renderError() != '' || $with_hide == false ? '' : 'display:none' ?>
">
<!-- thumbnail opcional -->
<?php echo include_partial("ajax_form/thumbnail",
array("thumbnail_info" => $thumbnail, "object" =>
Doctrine::getTable(module_to_class($widget_module))->find($embedded["id"]->getValue())
)) ?>
<!-- si no hay errores ponemos botones: hide, unlink y delete -->
<?php if ($embedded['id']->getValue() > 0): ?>
- <?php echo
_tag("a#{$module}_form_{$widget_name}_related_object_form_hide_{$embedded['id']->getValue()}.s16_arrow_down
title=Ocultar", 'Ocultar') ?>
+ <?php if ($with_hide): ?>
+ <?php echo
_tag("a#{$module}_form_{$widget_name}_related_object_form_hide_{$embedded['id']->getValue()}.s16_arrow_down
title=Ocultar", 'Ocultar') ?>
+ <?php endif ?>
<?php if (!$credentials ||
sfContext::getInstance()->getUser()->hasCredential($credentials)): ?>
<?php echo
_tag("a#{$module}_form_{$widget_name}_related_object_form_unlink_{$embedded['id']->getValue()}.s21_unlink
title=Quitar asociación", 'Quitar asociación') ?>
<?php echo
_tag("a#{$module}_form_{$widget_name}_related_object_form_delete_{$embedded['id']->getValue()}.s16.s16_delete
title=Borrar", 'Borrar') ?>
@@ -81,6 +89,14 @@
</div>
+<!-- JAVASCRIPT: SI HUBIERON FORM EMBEBIDOS Y SON MAS QUE LO MAXIMO -->
+<?php if ($form[$embedded_name]->count() > $number_embedded): ?>
+<script type="text/javascript">
+ $("#<?php echo $module ?>_form_<?php echo $widget_name ?>_crear").hide();
+</script>
+<?php endif ?>
+
+
<?php
include_partial("ajax_form/embedded_form_js", array(
'form' => $form,
@@ -98,4 +114,5 @@
'thumbnail' => $thumbnail,
'create_partial' => $create_partial,
));
-?>
\ No newline at end of file
+?>
+
Modified:
plugins/sfDoctrineAjaxFormPlugin/modules/ajax_form/templates/_embedded_form_js.php
===================================================================
---
plugins/sfDoctrineAjaxFormPlugin/modules/ajax_form/templates/_embedded_form_js.php
2010-04-19 01:35:20 UTC (rev 29199)
+++
plugins/sfDoctrineAjaxFormPlugin/modules/ajax_form/templates/_embedded_form_js.php
2010-04-19 03:22:32 UTC (rev 29200)
@@ -1,11 +1,4 @@
-<!-- JAVASCRIPT: SI HUBIERON FORM EMBEBIDOS Y SOLO TIENE QUE HABER UNO
OCULTAMOS EL AUTOCOMPLETE -->
-<?php if (isset($embed_key) && $number_embedded == 'one'): ?>
-<script type="text/javascript">
- $("#<?php echo $module ?>_form_<?php echo $widget_name ?>_crear").hide();
-</script>
-<?php endif ?>
-
<!--############################### JAVASCRIPT PARA MOSTRAR UNA EMBEDDED FORM
ESCONDIDA ################################## -->
<script type="text/javascript">
@@ -48,7 +41,7 @@
id = $(this).attr("class").replace("s16_undo","");
$("#" + id).replaceWith('');
- //mostramos el "autocomplete" y el "agregar" por si es "number_embedded
= one" y se borró
+ //mostramos el "autocomplete" y el "agregar" por si se borraron
anteriormente
$(".sf_admin_form_field_<?php echo $widget_name ?>").show();
$("#<?php echo $module ?>_form_<?php echo $widget_name ?>_crear").show();
});
@@ -85,8 +78,8 @@
async: false
}).responseText;
- //si "number_embedded == one" sacamos el autocomplete
- if("<?php echo $number_embedded ?>" == "one")
+ //si iguala el numero maximo de forms embebidas sacamos el autocomplete y
link para crear
+ if(<?php echo 'number' . $widget_name ?> +1 >= parseInt(<?php echo
$number_embedded ?>))
{
$("#autocomplete_<?php echo $module ?>_form_<?php echo $widget_name
?>").hide();
$("#img_<?php echo $module ?>_form_<?php echo $widget_name ?>").hide();
@@ -218,7 +211,7 @@
{
$("#<?php echo $module ?>_form_<?php echo $widget_name
?>_related_object_form_" + embedded_id).replaceWith('');
- //mostramos el "autocomplete" y el "agregar" por si es
"number_embedded = one" y se borró
+ //mostramos el "autocomplete" y el "agregar" por si se borraron
$("#autocomplete_<?php echo $module ?>_form_<?php echo $widget_name
?>").show();
$("#img_<?php echo $module ?>_form_<?php echo $widget_name
?>").show();
$("#<?php echo $module ?>_form_<?php echo $widget_name
?>_crear").show();
@@ -283,7 +276,7 @@
{
$("#<?php echo $module ?>_form_<?php echo $widget_name
?>_related_object_form_" + embedded_id).replaceWith('');
- //mostramos el "autocomplete" y el "agregar" por si es
"number_embedded = one" y se borró
+ //mostramos el "autocomplete" y el "agregar" por si se borraron
$("#autocomplete_<?php echo $module ?>_form_<?php echo $widget_name
?>").show();
$("#img_<?php echo $module ?>_form_<?php echo $widget_name
?>").show();
$("#<?php echo $module ?>_form_<?php echo $widget_name
?>_crear").show();
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.