diff --git a/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/DataProfileControllerTest.php b/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/DataProfileControllerTest.php index a6bf4c2c659553764442e1ca718fa7c70c287d33..7821df274d0d1403fc35e033f1cbb52b6c74426e 100644 --- a/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/DataProfileControllerTest.php +++ b/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/DataProfileControllerTest.php @@ -174,14 +174,13 @@ class Cosmo_DataProfileControllerEditPatronsTest extends Cosmo_DataProfileContro /** @test */ public function subscriberSelectedFieldsShouldContainsTwoPrenom() { - $this->assertXPathCount('//div[@id="input_patron_fields"]/div[1]/ul/li[@data-value="PRENOM"]', 2, - $this->_response->getBody()); + $this->assertXPathCount('//div[@id="input_patron_fields"]/div[1]/ul/li[@data-value="PRENOM"]', 2); } /** @test */ public function subscriberAvailableFieldsShouldContainsPrenom() { - $this->assertXPathCount('//div[@id="input_patron_fields"]/div[2]/ul/li[@data-value="PRENOM"]', 1); + $this->assertXPathCount('//div[@id="input_patron_fields"]/div[2]/ul/li[@data-value="PRENOM"]', 1, $this->_response->getBody()); } } @@ -665,7 +664,8 @@ class Cosmo_DataProfileControllerEditPergamePatronsTest extends Cosmo_DataProfil /** @test */ public function inputSubscribersLightShouldContainsFieldsIDABON_ORDREABON_etc() { - $this->assertXPath('//input[@name="patron_fields"][@value="IDABON;ORDREABON;NOM;PRENOM;NAISSANCE;DATE_DEBUT;DATE_FIN;MAIL"]'); + $this->assertXPath('//input[@name="patron_fields"][@value="IDABON;ORDREABON;NOM;PRENOM;NAISSANCE;DATE_DEBUT;DATE_FIN;MAIL"]', + $this->_response->getBody()); } } @@ -721,13 +721,13 @@ class Cosmo_DataProfileControllerEditNanookPatronsRegressionTest extends Cosmo_D /** @test */ - public function inputPatronFieldsShouldContainsIDABON_ID_SIGB_etc() { - $this->assertXPath('//input[@name="patron_fields"][@value="IDABON;ID_SIGB;ORDREABON;NOM;PRENOM;PASSWORD;MAIL"]', $this->_response->getBody()); + public function inputPatronFieldsShouldContainsIDABON_ORDREABON_etc() { + $this->assertXPath('//input[@name="patron_fields"][@value="IDABON;ORDREABON;NOM;PRENOM;PASSWORD;MAIL"]', $this->_response->getBody()); } /** @test */ - public function paragraphForPatronFieldsShouldContainsDateDeNaissance() { + public function paragraphForPatronFieldsShouldContainsPRENOM() { $this->assertXPath('//div[@id="input_patron_fields"]/div[1]/ul/li[@data-value="PRENOM"]', $this->_response->getBody()); } @@ -830,7 +830,7 @@ class Cosmo_DataProfileControllerDispatchLoansProfileTest extends Cosmo_DataProf /** @test */ public function fieldIdLoansShouldBeEmpty() { - $this->assertXPath('//form//input[@id="loans"][@value="PRENOM; NAISSANCE; PRENOM"]'); + $this->assertXPath('//form//input[@id="loans"][@value=""]'); } } @@ -862,7 +862,7 @@ class Cosmo_DataProfileControllerDispatchHoldsProfileTest extends Cosmo_DataProf /** @test */ public function fieldIdHoldsShouldBeEmpty() { - $this->assertXPath('//form//input[@id="holds"][@value="PRENOM; NAISSANCE; PRENOM"]'); + $this->assertXPath('//form//input[@id="holds"][@value=""]'); } } @@ -893,7 +893,7 @@ class Cosmo_DataProfileControllerDispatchBasketsProfileTest extends Cosmo_DataPr /** @test */ public function fieldIdCartShouldBeEmpty() { - $this->assertXPath('//form//input[@id="carts"][@value="PRENOM; NAISSANCE; PRENOM"]'); + $this->assertXPath('//form//input[@id="carts"][@value=""]'); } } @@ -923,8 +923,9 @@ class Cosmo_DataProfileControllerDispatchCSVItemsProfileTest extends Cosmo_DataP /** @test */ - public function fieldIdLightRecordsShouldBeEmpty() { - $this->assertXPath('//form//input[@id="csv_item_fields"][@value="PRENOM; NAISSANCE; PRENOM"]'); + public function inputCsvItemFieldsShouldBeEmpty() { + $this->assertXPath('//form//input[@name="csv_item_fields"][@value=""]', + $this->_response->getBody()); } } diff --git a/library/ZendAfi/View/Helper/FormSortableConnectLists.php b/library/ZendAfi/View/Helper/FormSortableConnectLists.php index 008092080506880aff981efb81acb164534ce1df..38d90a543b995f0f9dc329763c69859ac3243480 100644 --- a/library/ZendAfi/View/Helper/FormSortableConnectLists.php +++ b/library/ZendAfi/View/Helper/FormSortableConnectLists.php @@ -20,64 +20,102 @@ */ class ZendAfi_View_Helper_FormSortableConnectLists extends ZendAfi_View_Helper_BaseHelper { - protected function renderList($title, $values) { - $output = '<div><h2>' . $title . '</h2>'; - $output .= '<ul>'; + const SEPARATOR = ';'; - foreach ($values as $v => $label) { - $output .= '<li data-value="' . trim($v) . '">' . $label . '</li>'; - } - $output .= '</ul>'; - $output .= '</div>'; + protected + $_name, + $_options, + $_labels; + + + public function formSortableConnectLists($name, $value = null, $labels = [], $options = []) { + $this->_labels = $labels; + $this->_name = $name; + $this->_options = array_merge(['selected_label' => $this->view->_('Filtres activés'), + 'available_label' => $this->view->_('Filtres disponibles'), + 'display_inline' => false, + 'sticky_available' => false], + $options); + + $selected_values = $this->_collectValidSelectedValues($labels, $value); + + $available_values = $options['sticky_available'] + ? array_keys($labels) + : array_diff(array_keys($labels), $selected_values); + + return $this->_tag('div', + $this->_renderHTML($available_values, + $selected_values), + ['id' => 'input_' . $this->_name]); + } + + + protected function _renderHTML($available_values, $selected_values) { + $this->_injectHeadScripts($this->_options); + + $output = $this->view->formHidden($this->_name, + implode(static::SEPARATOR, + $selected_values)); + if ($options['display_inline']) + $output .= $this->_renderValueLabelsInline($selected_values); + + $output .= $this->_renderList($this->_options['selected_label'], + $selected_values); + + $output .= $this->_renderList($this->_options['available_label'], + $available_values); return $output; } - public function formSortableConnectLists($name, $value = null, $available_values = [], $options = []) { - $values = explode(';', $value); - $enabled_values = []; + protected function _renderValueLabelsInline($selected_values) { + $selected_labels = array_map( + function($v) { + return $this->_labels[$v]; + }, + $selected_values); + return $this->_tag('p', + implode(', ', $selected_labels), + ['class' => 'show_drag_and_drop']); + } - foreach ($values as $key => $v) { - $v = trim($v); - if(!isset($available_values[$v])) - continue; - if(isset($options['sticky_available']) && $options['sticky_available']) { - $enabled_values[$key . $v] = $available_values[$v]; - continue; - } + protected function _renderList($title, $values) { + $output = '<div><h2>' . $title . '</h2>'; + $output .= '<ul>'; - $enabled_values[$v] = $available_values[$v]; - unset($available_values[$v]); + foreach ($values as $value) { + $output .= sprintf('<li data-value="%s">%s</li>', + $value, + $this->_labels[$value]); } + $output .= '</ul>'; + $output .= '</div>'; - $options = array_merge(['selected_label' => $this->view->_('Filtres activés'), - 'available_label' => $this->view->_('Filtres disponibles'), - 'display_inline' => false, - 'sticky_available' => false], - $options); + return $output; + } - $output = $this->view->formHidden($name, $value); - if($options['display_inline']) - $output .= $this->_tag('p', implode(',', $enabled_values), - ['class' => 'show_drag_and_drop']); + protected function _collectValidSelectedValues($available_values, $value) { + return array_filter(explode(static::SEPARATOR, $value), + function($v) use ($available_values) + { + return isset($available_values[$v]); + }); + } - $output .= - $this->renderList($options['selected_label'], - $enabled_values) . - $this->renderList($options['available_label'], - $available_values); + protected function _injectHeadScripts() { Class_ScriptLoader::getInstance() ->loadJQuery() ->loadJQueryUI() ->addOPACScript('input_connect_list/input_connect_list') ->addOPACStyleSheet('../js/input_connect_list/input_connect_list') - ->addJQueryReady('$("div#input_'.$name.'").inputConnectList(' . json_encode($options) . ')'); - - return $this->_tag('div', $output, ['id' => 'input_' . $name]); + ->addJQueryReady(sprintf('$("div#input_%s").inputConnectList(%s)', + $this->_name, + json_encode($this->_options))); + return $this; } }