Localize status bits

This commit is contained in:
Romain Neutron
2013-06-13 16:05:34 +02:00
parent 1a13d02c2a
commit 906d4ba9c5
14 changed files with 236 additions and 129 deletions

View File

@@ -240,9 +240,9 @@ class Root implements ControllerProviderInterface
$databox = $app['phraseanet.appbox']->get_databox($databox_id);
$databox->saveStructure($domst);
return $app->redirectPath('database_display_stucture', array('sbas_id' => $databox_id, 'success' => 1));
return $app->redirectPath('database_display_stucture', array('databox_id' => $databox_id, 'success' => 1));
} else {
return $app->redirectPath('database_display_stucture', array('sbas_id' => $databox_id, 'success' => 0, 'error' => 'struct'));
return $app->redirectPath('database_display_stucture', array('databox_id' => $databox_id, 'success' => 0, 'error' => 'struct'));
}
})->assert('databox_id', '\d+')
->bind('database_submit_stucture');
@@ -326,7 +326,9 @@ class Root implements ControllerProviderInterface
'printable' => $request->request->get('printable') ? '1' : '0',
'name' => $request->request->get('name', ''),
'labelon' => $request->request->get('label_on', ''),
'labeloff' => $request->request->get('label_off', '')
'labeloff' => $request->request->get('label_off', ''),
'labels_on' => $request->request->get('labels_on', array()),
'labels_off' => $request->request->get('labels_off', array()),
);
\databox_status::updateStatus($app, $databox_id, $bit, $properties);
@@ -423,7 +425,7 @@ class Root implements ControllerProviderInterface
}
}
return $app->redirectPath('database_display_stucture', array('sbas_id' => $databox_id, 'success' => 1));
return $app->redirectPath('database_display_statusbit', array('databox_id' => $databox_id, 'success' => 1));
})->assert('databox_id', '\d+')
->assert('bit', '\d+')
->bind('database_submit_statusbit');

View File

@@ -125,8 +125,8 @@ class Edit implements ControllerProviderInterface
if (isset($dbstatus[$databox->get_sbas_id()])) {
foreach ($dbstatus[$databox->get_sbas_id()] as $n => $statbit) {
$status[$n] = array();
$status[$n]['label0'] = $statbit['labeloff'];
$status[$n]['label1'] = $statbit['labelon'];
$status[$n]['label0'] = $statbit['labels_off_i18n'][$app['locale.I18n']];
$status[$n]['label1'] = $statbit['labels_on_i18n'][$app['locale.I18n']];
$status[$n]['img_off'] = $statbit['img_off'];
$status[$n]['img_on'] = $statbit['img_on'];
$status[$n]['_value'] = 0;

View File

@@ -259,11 +259,11 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper
foreach ($status as $bit => $datas) {
$tbits_left[$bit]["nset"] = 0;
$tbits_left[$bit]["name"] = $datas["labeloff"];
$tbits_left[$bit]["name"] = $datas['labels_off_i18n'][$this->app['locale.I18n']];
$tbits_left[$bit]["icon"] = $datas["img_off"];
$tbits_right[$bit]["nset"] = 0;
$tbits_right[$bit]["name"] = $datas["labelon"];
$tbits_right[$bit]["name"] = $datas['labels_on_i18n'][$this->app['locale.I18n']];
$tbits_right[$bit]["icon"] = $datas["img_on"];
}

View File

@@ -2053,6 +2053,12 @@ class API_V1_adapter extends API_V1_Abstract
'bit' => $n,
'label_on' => $datas['labelon'],
'label_off' => $datas['labeloff'],
'labels' => array(
'en' => $datas['labels_on_i18n']['en'],
'fr' => $datas['labels_on_i18n']['fr'],
'de' => $datas['labels_on_i18n']['de'],
'nl' => $datas['labels_on_i18n']['nl'],
),
'img_on' => $datas['img_on'],
'img_off' => $datas['img_off'],
'searchable' => !!$datas['searchable'],

View File

@@ -86,6 +86,20 @@ class databox_status
$this->status[$bit]["labeloff"] = (string) $sb['labelOff'];
$this->status[$bit]["labelon"] = (string) $sb['labelOn'];
foreach ($app['locales.I18n.available'] as $code => $language){
$this->status[$bit]['labels_on'][$code] = null;
$this->status[$bit]['labels_off'][$code] = null;
}
foreach ($sb->label as $label) {
$this->status[$bit]['labels_'.$label['switch']][(string) $label['code']] = (string) $label;
}
foreach ($app['locales.I18n.available'] as $code => $language){
$this->status[$bit]['labels_on_i18n'][$code] = isset($this->status[$bit]['labels_on'][$code]) ? $this->status[$bit]['labels_on'][$code] : $this->status[$bit]["labelon"];
$this->status[$bit]['labels_off_i18n'][$code] = isset($this->status[$bit]['labels_off'][$code]) ? $this->status[$bit]['labels_off'][$code] : $this->status[$bit]["labeloff"];
}
$this->status[$bit]["img_off"] = null;
$this->status[$bit]["img_on"] = null;
@@ -192,6 +206,8 @@ class databox_status
'sbas' => array($sbas_id),
'labeloff' => $props['labeloff'],
'labelon' => $props['labelon'],
'labels_on_i18n' => $props['labels_on_i18n'],
'labels_off_i18n' => $props['labels_off_i18n'],
'imgoff' => $props['img_off'],
'imgon' => $props['img_on']
);
@@ -205,6 +221,8 @@ class databox_status
'sbas' => array($sbas_id),
'labeloff' => $props['labeloff'],
'labelon' => $props['labelon'],
'labels_on_i18n' => $props['labels_on_i18n'],
'labels_off_i18n' => $props['labels_off_i18n'],
'imgoff' => $props['img_off'],
'imgon' => $props['img_on']
)
@@ -309,6 +327,10 @@ class databox_status
$sbit = $statbits->appendChild($doc->createElement("bit"));
if ($n = $sbit->appendChild($doc->createAttribute("n"))) {
$n->value = $bit;
}
if ($labOn = $sbit->appendChild($doc->createAttribute("labelOn"))) {
$labOn->value = $properties['labelon'];
}
@@ -324,6 +346,24 @@ class databox_status
if ($labOff = $sbit->appendChild($doc->createAttribute("labelOff"))) {
$labOff->value = $properties['labeloff'];
}
foreach ($properties['labels_off'] as $code => $label) {
$labelTag = $sbit->appendChild($doc->createElement("label"));
$switch = $labelTag->appendChild($doc->createAttribute("switch"));
$switch->value = 'off';
$codeTag = $labelTag->appendChild($doc->createAttribute("code"));
$codeTag->value = $code;
$labelTag->appendChild($doc->createTextNode($label));
}
foreach ($properties['labels_on'] as $code => $label) {
$labelTag = $sbit->appendChild($doc->createElement("label"));
$switch = $labelTag->appendChild($doc->createAttribute("switch"));
$switch->value = 'on';
$codeTag = $labelTag->appendChild($doc->createAttribute("code"));
$codeTag->value = $code;
$labelTag->appendChild($doc->createTextNode($label));
}
}
$databox->saveStructure($doc);

View File

@@ -430,11 +430,11 @@ class record_adapter implements record_Interface, cache_cacheableInterface
$status .= '<img style="margin:1px;' . $style1 . '" ' .
'class="STAT_' . $this->base_id . '_'
. $this->record_id . '_' . $n . '_1" ' .
'src="' . $source1 . '" title="' . $statbit["labelon"] . '"/>';
'src="' . $source1 . '" title="' . $statbit['labels_on_i18n'][$this->app['locale.I18n']] . '"/>';
$status .= '<img style="margin:1px;' . $style0 . '" ' .
'class="STAT_' . $this->base_id . '_'
. $this->record_id . '_' . $n . '_0" ' .
'src="' . $source0 . '" title="' . $statbit["labeloff"] . '"/>';
'src="' . $source0 . '" title="' . $statbit['labels_off_i18n'][$this->app['locale.I18n']] . '"/>';
}
}

View File

@@ -42,14 +42,14 @@
{% set statusbit = attribute(status, bit) %}
<td>
{% if statusbit['img_off'] %}
<img title='{{ statusbit['labeloff'] }}' src='{{ statusbit['img_off'] }}' />
<img title='{{ statusbit['labels_off_i18n'][app['locale.I18n']] }}' src='{{ statusbit['img_off'] }}' />
{% endif %}
{{ statusbit['labeloff'] }}
{{ statusbit['labels_off_i18n'][app['locale.I18n']] }}
/
{% if statusbit['img_on'] %}
<img title='{{ statusbit['labelon'] }}' src='{{ statusbit['img_on'] }}' />
<img title='{{ statusbit['labels_on_i18n'][app['locale.I18n']] }}' src='{{ statusbit['img_on'] }}' />
{% endif %}
{{ statusbit['labelon'] }}
{{ statusbit['labels_on_i18n'][app['locale.I18n']] }}
</td>
<td>{{ statusbit['searchable'] is defined and statusbit['searchable'] == '1' ? 'oui'| trans : 'non'| trans }}</td>
<td>{{ statusbit['printable'] is defined and statusbit['printable'] == '1' ? 'oui'| trans : 'non'| trans }}</td>

View File

@@ -5,21 +5,46 @@
</div>
{% endif %}
<h1 style='padding-left:30px;'>{% trans 'status:: numero de bit' %} {{ app['request'].get('bit') }}</h1>
<h1 style='padding-left:30px;'>
{% trans 'status:: numero de bit' %} {{ app['request'].get('bit') }}
</h1>
<form id="fileupload" class="form-horizontal" enctype="multipart/form-data" method="post" action="{{ path('database_submit_statusbit', { 'databox_id' : app['request'].get('databox_id'), 'bit' : app['request'].get('bit') }) }}">
<fieldset>
<div class="span5 well">
<div class="row-fluid">
<div class="span12 well">
<span class="label">{% trans'admin::status: case A'%}</span>
<div class="control-group">
<div class="row-fluid">
<label class="control-label" for="label_off">
{% trans'admin::status: texte a afficher'%}
</label>
<div class="controls">
<input id="name" name="label_off" class="input-xlarge" type="text" value="{{ status['labeloff']|default('') }}">
<input id="label_off" name="label_off" class="input-xlarge" type="text" value="{{ status['labels_off_i18n'][app['locale.I18n']]|default('') }}">
</div>
</div>
<div class="control-group">
<div class="row-fluid">
<label class="control-label">
</label>
<div class="controls">
{% for code, language in app['locales.I18n.available'] %}
<div class="span2">
<h6>{{ language }}</h6>
</div>
{% endfor %}
</div>
</div>
<div class="row-fluid">
<label class="control-label">
{% trans 'Labels'%}
</label>
<div class="controls">
{% for code, language in app['locales.I18n.available'] %}
<div class="span2">
<input name="labels_off[{{ code }}]" value="{{ status['labels_off'][code] }}" class="span12" type="text">
</div>
{% endfor %}
</div>
</div>
<div class="row-fluid">
<label class="control-label" for="image_off">
{% trans'admin::status: symboliser par'%}
</label>
@@ -32,7 +57,7 @@
</div>
</div>
</div>
<div class="control-group">
<div class="row-fluid">
<label class="control-label" for="delete_icon_off">
{% trans'admin::status:: aucun symbole'%}
</label>
@@ -43,17 +68,42 @@
</div>
</div>
</div>
<div class="span5 well">
</div>
<div class="row-fluid">
<div class="span12 well">
<span class="label">{% trans'admin::status: case B'%}</span>
<div class="control-group">
<div class="row-fluid">
<label class="control-label" for="label_on">
{% trans'admin::status: texte a afficher'%}
</label>
<div class="controls">
<input id="label_on" name="label_on" class="input-xlarge" type="text" value="{{ status['labelon']|default('') }}">
<input id="label_on" name="label_on" class="input-xlarge" type="text" value="{{ status['labels_on_i18n'][app['locale.I18n']]|default('') }}">
</div>
</div>
<div class="control-group">
<div class="row-fluid">
<label class="control-label">
</label>
<div class="controls">
{% for code, language in app['locales.I18n.available'] %}
<div class="span2">
<h6>{{ language }}</h6>
</div>
{% endfor %}
</div>
</div>
<div class="row-fluid">
<label class="control-label">
{% trans 'Labels'%}
</label>
<div class="controls">
{% for code, language in app['locales.I18n.available'] %}
<div class="span2">
<input name="labels_on[{{ code }}]" value="{{ status['labels_on'][code] }}" class="span12" type="text">
</div>
{% endfor %}
</div>
</div>
<div class="row-fluid">
<label class="control-label" for="image_on">
{% trans'admin::status: symboliser par'%}
</label>
@@ -66,18 +116,20 @@
</div>
</div>
</div>
<div class="control-group">
<div class="row-fluid">
<label class="control-label" for="delete_icon_on">
{% trans'admin::status:: aucun symbole'%}
</label>
<div class="controls">
<label class="checkbox">
<input id="delete_icon_on" name="delete_icon_on" type="checkbox">
<input id="delete_icon_off" name="delete_icon_on" type="checkbox">
</label>
</div>
</div>
</div>
<div class="span10">
</div>
<div class="row-fluid">
<div class="span12">
<label class="checkbox">
<input id="printable" name="printable" type="checkbox" {{ status['printable'] is defined and status['printable'] == '1' ? "checked" : "" }}>
{% trans'status:: Afficher le status dans les feuilles de reponses pour tous les utilisateurs' %}
@@ -87,19 +139,21 @@
{% trans'status:: retrouver sous forme de filtre dans la recherche' %}
</label>
</div>
<div class=" span10">
</div>
<div class="row-fluid">
<div class=" span12">
<div class="form-actions">
<button id="form_submitter" class="btn btn-primary" type="button">
{% trans 'boutton::valider' %}
</button>
<a style='text-decoration:none;' class="btn" href="{{ path('database_display_statusbit', { 'databox_id' : app['request'].get('databox_id') }) }}">{% trans 'boutton::retour' %}
<a style='text-decoration:none;' class="btn" href="{{ path('database_display_statusbit', { 'databox_id' : app['request'].get('databox_id') }) }}">
{% trans 'boutton::retour' %}
</a>
</div>
</div>
</fieldset>
</div>
</form>
<script type="text/javascript">
$(document).ready(function(){

View File

@@ -203,11 +203,11 @@
<tr>
<td style="width:50%" nowrap>
<input class="checkbox" db="{{ sbasId }}" onchange="checkFilters();" type="checkbox" name="status[]" id="statusfil_{{ sbasId }}_off{{ sbasId }}" value="{{ sbasId }}_of{{ sbasId }}"/>
<label title="{{ data['labeloff'] }}" for="statusfil_{{ sbasId }}_off{{ bit }}">{% if data['img_off'] %}<img src="'{{ datas['img_off'] }}" title="{{ datas['labeloff'] }}" style="width:16px;height:16px;vertical-align:bottom" />{% endif %}{{ data['labeloff'] }}</label>
<label title="{{ data['labels_off_i18n'][app['locale.I18n']] }}" for="statusfil_{{ sbasId }}_off{{ bit }}">{% if data['img_off'] %}<img src="'{{ datas['img_off'] }}" title="{{ datas['labels_off_i18n'][app['locale.I18n']] }}" style="width:16px;height:16px;vertical-align:bottom" />{% endif %}{{ data['labels_off_i18n'][app['locale.I18n']] }}</label>
</td>
<td style="width:50%" nowrap>
<input class="checkbox" db="{{ sbasId }}" onchange="checkFilters();" type="checkbox" name="status[]" id="statusfil_{{ sbasId }}_on{{ sbasId }}" value="{{ sbasId }}_on{{ sbasId }}"/>
<label title="{{ data['labelon'] }}" for="statusfil_{{ sbasId }}_on{{ bit }}">{% if data['img_on']%}<img src="{{ datas['img_on'] }}" title="{{ datas['labelon'] }}" style="width:16px;height:16px;vertical-align:bottom" />{% endif %}{{ data['labelon'] }}</label>
<label title="{{ data['labels_on_i18n'][app['locale.I18n']] }}" for="statusfil_{{ sbasId }}_on{{ bit }}">{% if data['img_on']%}<img src="{{ datas['img_on'] }}" title="{{ datas['labels_on_i18n'][app['locale.I18n']] }}" style="width:16px;height:16px;vertical-align:bottom" />{% endif %}{{ data['labels_on_i18n'][app['locale.I18n']] }}</label>
</td>
</tr>
</table>

View File

@@ -81,7 +81,7 @@
</td>
<td style='text-align:right'>
<label for="status-radio-{{ sbasId ~ "-" ~ bit ~ '-off'}}" {% if inverse == 2 %}style='color:#FF3333'{% endif%}>
{{ values['labeloff']|default('off') }}
{{ values['labels_off_i18n'][app['locale.I18n']]|default('off') }}
</label>
</td>
<td style='text-align:right'>
@@ -92,7 +92,7 @@
</td>
<td style='text-align:left'>
<label for="status-radio-{{ sbasId ~ "-" ~ bit ~ '-on'}}" {% if inverse == 2 %}style='color:#FF3333'{% endif%}>
{{ values['labelon']|default('on') }}
{{ values['labels_on_i18n'][app['locale.I18n']]|default('on') }}
</label>
</td>
<td style='text-align:left'>

View File

@@ -388,24 +388,24 @@
<tr>
<td>
{% if s['imgoff'] %}
<img src="{{s['imgoff']}}" title="{{s['labeloff']}}" />
<img src="{{s['imgoff']}}" title="{{s['labels_off_i18n'][app['locale.I18n']]}}" />
{% endif %}
<label class="checkbox inline">
<input onchange="checkFilters(true);" class="field_switch field_{{s['sbas']|join(' field_')}}"
type="checkbox" value="{{s['sbas']|join(' field_')}}"
n="{{n}}" name="status[{{n}}][off][]" />
{{s['labeloff']}}
{{s['labels_off_i18n'][app['locale.I18n']]}}
</label>
</td>
<td>
{% if s['imgoff'] %}
<img src="{{s['imgon']}}" title="{{s['labelon']}}" />
<img src="{{s['imgon']}}" title="{{s['labels_on_i18n'][app['locale.I18n']]}}" />
{% endif %}
<label class="checkbox inline">
<input onchange="checkFilters(true);" class="field_switch field_{{s['sbas']|join(' field_')}}"
type="checkbox" value="{{s['sbas']|join(' field_')}}"
n="{{n}}" name="status[{{n}}][on][]"/>
{{s['labelon']}}
{{s['labels_on_i18n'][app['locale.I18n']]}}
</label>
</td>
</tr>

View File

@@ -72,12 +72,12 @@
{% if status['img_off'] is not empty %}
<img src="{{ status['img_off'] }}" width="16" height="16" />
{% endif %}
<span>{{ status['labeloff']|default('off') }}</span>
<span>{{ status['labels_off_i18n'][app['locale.I18n']]|default('off') }}</span>
<input type="radio" name="status[{{ collection.get_base_id() }}][{{ bit }}]" value="0" checked="checked"/>
</td>
<td class="status-tab-right">
<input type="radio" name="status[{{ collection.get_base_id() }}][{{ bit }}]" value="1" />
<span for="labelon">{{ status['labelon']|default('on') }}</span>
<span for="labelon">{{ status['labels_on_i18n'][app['locale.I18n']]|default('on') }}</span>
{% if status['img_on'] is not empty %}
<img src="{{ status['img_on'] }}" width="16" height="16" />
{% endif %}

View File

@@ -77,12 +77,12 @@
{% if status['img_off'] is not empty %}
<img src="{{ status['img_off'] }}" width="16" height="16" />
{% endif %}
<span>{{ status['labeloff']|default('off') }}</span>
<span>{{ status['labels_off_i18n'][app['locale.I18n']]|default('off') }}</span>
<input type="radio" name="status[{{ collection.get_base_id() }}][{{ bit }}]" value="0" checked="checked"/>
</td>
<td class="status-tab-right">
<input type="radio" name="status[{{ collection.get_base_id() }}][{{ bit }}]" value="1" />
<span for="labelon">{{ status['labelon']|default('on') }}</span>
<span for="labelon">{{ status['labels_on_i18n'][app['locale.I18n']]|default('on') }}</span>
{% if status['img_on'] is not empty %}
<img src="{{ status['img_on'] }}" width="16" height="16" />
{% endif %}

View File

@@ -686,6 +686,11 @@ abstract class ApiAbstract extends \PhraseanetWebTestCaseAbstract
$this->assertLessThan(65, $status['bit']);
$this->assertArrayHasKey('label_on', $status);
$this->assertArrayHasKey('label_off', $status);
$this->assertArrayHasKey('labels', $status);
$this->assertArrayHasKey('fr', $status['labels']);
$this->assertArrayHasKey('en', $status['labels']);
$this->assertArrayHasKey('de', $status['labels']);
$this->assertArrayHasKey('nl', $status['labels']);
$this->assertArrayHasKey('img_on', $status);
$this->assertArrayHasKey('img_off', $status);
$this->assertArrayHasKey('searchable', $status);