Fix readonly fields

This commit is contained in:
Romain Neutron
2012-01-25 15:27:08 +01:00
parent 9852e2077c
commit 1ce52264fb
2 changed files with 104 additions and 91 deletions

View File

@@ -59,9 +59,7 @@ class module_prod_route_records_edit extends module_prod_route_records_abstract
* @var boolean * @var boolean
*/ */
protected $works_on_unique_sbas = true; protected $works_on_unique_sbas = true;
protected $has_thesaurus = false; protected $has_thesaurus = false;
public function __construct(Symfony\Component\HttpFoundation\Request $request) public function __construct(Symfony\Component\HttpFoundation\Request $request)
{ {
@@ -72,7 +70,7 @@ class module_prod_route_records_edit extends module_prod_route_records_abstract
if ($this->is_single_grouping()) if ($this->is_single_grouping())
{ {
$record = array_pop($this->selection->get_elements()); $record = array_pop($this->selection->get_elements());
$children = $record->get_children(); $children = $record->get_children();
foreach ($children as $child) foreach ($children as $child)
{ {
@@ -85,9 +83,9 @@ class module_prod_route_records_edit extends module_prod_route_records_abstract
if ($this->is_possible()) if ($this->is_possible())
{ {
$this->generate_javascript_fields() $this->generate_javascript_fields()
->generate_javascript_sugg_values() ->generate_javascript_sugg_values()
->generate_javascript_status() ->generate_javascript_status()
->generate_javascript_elements(); ->generate_javascript_elements();
} }
return $this; return $this;
@@ -181,19 +179,19 @@ class module_prod_route_records_edit extends module_prod_route_records_abstract
protected function generate_javascript_elements() protected function generate_javascript_elements()
{ {
$_lst = array(); $_lst = array();
$appbox = appbox::get_instance(); $appbox = appbox::get_instance();
$session = $appbox->get_session(); $session = $appbox->get_session();
$user = User_Adapter::getInstance($session->get_usr_id(), $appbox); $user = User_Adapter::getInstance($session->get_usr_id(), $appbox);
$twig = new supertwig(); $twig = new supertwig();
foreach ($this->selection as $record) foreach ($this->selection as $record)
{ {
$indice = $record->get_number(); $indice = $record->get_number();
$_lst[$indice] = array( $_lst[$indice] = array(
'bid' => $record->get_base_id(), 'bid' => $record->get_base_id(),
'rid' => $record->get_record_id(), 'rid' => $record->get_record_id(),
'sselcont_id' => null, 'sselcont_id' => null,
'_selected' => false '_selected' => false
); );
$_lst[$indice]['statbits'] = array(); $_lst[$indice]['statbits'] = array();
@@ -201,12 +199,12 @@ class module_prod_route_records_edit extends module_prod_route_records_abstract
{ {
foreach ($this->javascript_status as $n => $s) foreach ($this->javascript_status as $n => $s)
{ {
$tmp_val = substr(strrev($record->get_status()), $n, 1); $tmp_val = substr(strrev($record->get_status()), $n, 1);
$_lst[$indice]['statbits'][$n]['value'] = ($tmp_val == '1') ? '1' : '0'; $_lst[$indice]['statbits'][$n]['value'] = ($tmp_val == '1') ? '1' : '0';
$_lst[$indice]['statbits'][$n]['dirty'] = false; $_lst[$indice]['statbits'][$n]['dirty'] = false;
} }
} }
$_lst[$indice]['fields'] = array(); $_lst[$indice]['fields'] = array();
$_lst[$indice]['originalname'] = ''; $_lst[$indice]['originalname'] = '';
$_lst[$indice]['originalname'] = $record->get_original_name(); $_lst[$indice]['originalname'] = $record->get_original_name();
@@ -220,22 +218,22 @@ class module_prod_route_records_edit extends module_prod_route_records_abstract
} }
$_lst[$indice]['fields'][$meta_struct_id] = array( $_lst[$indice]['fields'][$meta_struct_id] = array(
'dirty' => false, 'dirty' => false,
'meta_id' => $field->get_meta_id(), 'meta_id' => $field->get_meta_id(),
'meta_struct_id' => $meta_struct_id, 'meta_struct_id' => $meta_struct_id,
'value' => $field->get_value() 'value' => $field->get_value()
); );
} }
$_lst[$indice]['subdefs'] = array('thumbnail' => null, 'preview' => null); $_lst[$indice]['subdefs'] = array('thumbnail' => null, 'preview' => null);
$thumbnail = $record->get_thumbnail(); $thumbnail = $record->get_thumbnail();
$_lst[$indice]['subdefs']['thumbnail'] = array( $_lst[$indice]['subdefs']['thumbnail'] = array(
'url' => $thumbnail->get_url() 'url' => $thumbnail->get_url()
, 'w' => $thumbnail->get_width() , 'w' => $thumbnail->get_width()
, 'h' => $thumbnail->get_height() , 'h' => $thumbnail->get_height()
); );
$_lst[$indice]['preview'] = $twig->render('common/preview.html', array('record' => $record)); $_lst[$indice]['preview'] = $twig->render('common/preview.html', array('record' => $record));
@@ -246,7 +244,7 @@ class module_prod_route_records_edit extends module_prod_route_records_abstract
} }
catch (Exception $e) catch (Exception $e)
{ {
} }
$_lst[$indice]['type'] = $record->get_type(); $_lst[$indice]['type'] = $record->get_type();
} }
@@ -268,16 +266,16 @@ class module_prod_route_records_edit extends module_prod_route_records_abstract
foreach ($this->selection as $record) foreach ($this->selection as $record)
{ {
/* @var $record record_adapter */ /* @var $record record_adapter */
$base_id = $record->get_base_id(); $base_id = $record->get_base_id();
$record_id = $record->get_record_id(); $record_id = $record->get_record_id();
$databox = $record->get_databox(); $databox = $record->get_databox();
if (isset($done[$base_id])) if (isset($done[$base_id]))
continue; continue;
$T_sgval['b' . $base_id] = array(); $T_sgval['b' . $base_id] = array();
$collection = collection::get_from_base_id($base_id); $collection = collection::get_from_base_id($base_id);
if ($sxe = simplexml_load_string($collection->get_prefs())) if ($sxe = simplexml_load_string($collection->get_prefs()))
{ {
$z = $sxe->xpath('/baseprefs/sugestedValues'); $z = $sxe->xpath('/baseprefs/sugestedValues');
@@ -287,7 +285,7 @@ class module_prod_route_records_edit extends module_prod_route_records_abstract
foreach ($z[0] as $ki => $vi) // les champs foreach ($z[0] as $ki => $vi) // les champs
{ {
$field = $databox->get_meta_structure()->get_element_by_name($ki); $field = $databox->get_meta_structure()->get_element_by_name($ki);
if (!$field) if (!$field)
continue; // champ inconnu dans la structure ? continue; // champ inconnu dans la structure ?
@@ -298,12 +296,12 @@ class module_prod_route_records_edit extends module_prod_route_records_abstract
foreach ($vi->value as $oneValue) // les valeurs sug foreach ($vi->value as $oneValue) // les valeurs sug
{ {
$T_sgval['b' . $base_id][$field->get_id()][] = $T_sgval['b' . $base_id][$field->get_id()][] =
(string) $oneValue; (string) $oneValue;
} }
} }
} }
unset($collection); unset($collection);
$done[$base_id] = true; $done[$base_id] = true;
} }
$this->javascript_sugg_values = $T_sgval; $this->javascript_sugg_values = $T_sgval;
@@ -318,9 +316,9 @@ class module_prod_route_records_edit extends module_prod_route_records_abstract
protected function generate_javascript_status() protected function generate_javascript_status()
{ {
$_tstatbits = array(); $_tstatbits = array();
$appbox = appbox::get_instance(); $appbox = appbox::get_instance();
$session = $appbox->get_session(); $session = $appbox->get_session();
$user = User_Adapter::getInstance($session->get_usr_id(), $appbox); $user = User_Adapter::getInstance($session->get_usr_id(), $appbox);
if ($user->ACL()->has_right('changestatus')) if ($user->ACL()->has_right('changestatus'))
{ {
@@ -330,11 +328,11 @@ class module_prod_route_records_edit extends module_prod_route_records_abstract
foreach ($status[$this->get_sbas_id()] as $n => $statbit) foreach ($status[$this->get_sbas_id()] as $n => $statbit)
{ {
$_tstatbits[$n] = array(); $_tstatbits[$n] = array();
$_tstatbits[$n]['label0'] = $statbit['labeloff']; $_tstatbits[$n]['label0'] = $statbit['labeloff'];
$_tstatbits[$n]['label1'] = $statbit['labelon']; $_tstatbits[$n]['label1'] = $statbit['labelon'];
$_tstatbits[$n]['img_off'] = $statbit['img_off']; $_tstatbits[$n]['img_off'] = $statbit['img_off'];
$_tstatbits[$n]['img_on'] = $statbit['img_on']; $_tstatbits[$n]['img_on'] = $statbit['img_on'];
$_tstatbits[$n]['_value'] = 0; $_tstatbits[$n]['_value'] = 0;
} }
} }
} }
@@ -351,11 +349,11 @@ class module_prod_route_records_edit extends module_prod_route_records_abstract
*/ */
protected function generate_javascript_fields() protected function generate_javascript_fields()
{ {
$_tfields = $fields = array(); $_tfields = $fields = array();
$this->has_thesaurus = false; $this->has_thesaurus = false;
$databox = databox::get_instance($this->get_sbas_id()); $databox = databox::get_instance($this->get_sbas_id());
$meta_struct = $databox->get_meta_structure(); $meta_struct = $databox->get_meta_structure();
foreach ($meta_struct as $meta) foreach ($meta_struct as $meta)
@@ -376,19 +374,19 @@ class module_prod_route_records_edit extends module_prod_route_records_abstract
switch ($meta->get_type()) switch ($meta->get_type())
{ {
case 'datetime': case 'datetime':
$format = _('phraseanet::technique::datetime-edit-format'); $format = _('phraseanet::technique::datetime-edit-format');
$explain = _('phraseanet::technique::datetime-edit-explain'); $explain = _('phraseanet::technique::datetime-edit-explain');
break; break;
case 'date': case 'date':
$format = _('phraseanet::technique::date-edit-format'); $format = _('phraseanet::technique::date-edit-format');
$explain = _('phraseanet::technique::date-edit-explain'); $explain = _('phraseanet::technique::date-edit-explain');
break; break;
case 'time': case 'time':
$format = _('phraseanet::technique::time-edit-format'); $format = _('phraseanet::technique::time-edit-format');
$explain = _('phraseanet::technique::time-edit-explain'); $explain = _('phraseanet::technique::time-edit-explain');
break; break;
default: default:
$format = $explain = ""; $format = $explain = "";
break; break;
} }
@@ -398,22 +396,22 @@ class module_prod_route_records_edit extends module_prod_route_records_abstract
$separator = $meta->get_separator(); $separator = $meta->get_separator();
$datas = array( $datas = array(
'meta_struct_id' => $meta->get_id() 'meta_struct_id' => $meta->get_id()
, 'name' => $meta->get_name() , 'name' => $meta->get_name()
, '_status' => 0 , '_status' => 0
, '_value' => '' , '_value' => ''
, '_sgval' => array() , '_sgval' => array()
, 'required' => $meta->is_required() , 'required' => $meta->is_required()
, 'readonly' => $meta->is_readonly() , 'readonly' => $meta->is_readonly()
, 'type' => $meta->get_type() , 'type' => $meta->get_type()
, 'format' => $format , 'format' => $format
, 'explain' => $explain , 'explain' => $explain
, 'tbranch' => $meta->get_tbranch() , 'tbranch' => $meta->get_tbranch()
, 'maxLength' => $meta->get_source()->maxlength() , 'maxLength' => $meta->get_source()->maxlength()
, 'minLength' => $meta->get_source()->minLength() , 'minLength' => $meta->get_source()->minLength()
, 'regfield' => $regfield , 'regfield' => $regfield
, 'multi' => $meta->is_multi() , 'multi' => $meta->is_multi()
, 'separator' => $separator , 'separator' => $separator
); );
if (trim($meta->get_tbranch()) !== '') if (trim($meta->get_tbranch()) !== '')
@@ -435,7 +433,7 @@ class module_prod_route_records_edit extends module_prod_route_records_abstract
{ {
try try
{ {
$reg_record = $this->get_grouping_head(); $reg_record = $this->get_grouping_head();
$reg_sbas_id = $reg_record->get_sbas_id(); $reg_sbas_id = $reg_record->get_sbas_id();
$newsubdef_reg = new record_adapter($reg_sbas_id, $request->get('newrepresent')); $newsubdef_reg = new record_adapter($reg_sbas_id, $request->get('newrepresent'));
@@ -445,7 +443,7 @@ class module_prod_route_records_edit extends module_prod_route_records_abstract
foreach ($newsubdef_reg->get_subdefs() as $name => $value) foreach ($newsubdef_reg->get_subdefs() as $name => $value)
{ {
$pathfile = $value->get_pathfile(); $pathfile = $value->get_pathfile();
$system_file = new system_file($pathfile); $system_file = new system_file($pathfile);
$reg_record->substitute_subdef($name, $system_file); $reg_record->substitute_subdef($name, $system_file);
} }
@@ -457,14 +455,13 @@ class module_prod_route_records_edit extends module_prod_route_records_abstract
} }
if (!is_array($request->get('mds'))) if (!is_array($request->get('mds')))
return $this; return $this;
$sbas_id = (int) $request->get('sbid'); $sbas_id = (int) $request->get('sbid');
$databox = databox::get_instance($sbas_id); $databox = databox::get_instance($sbas_id);
$meta_struct = $databox->get_meta_structure(); $meta_struct = $databox->get_meta_structure();
$write_edit_el = false; $write_edit_el = false;
$date_obj = new DateTime(); $date_obj = new DateTime();
foreach ($meta_struct->get_elements() as $meta_struct_el) foreach ($meta_struct->get_elements() as $meta_struct_el)
{ {
if ($meta_struct_el->get_metadata_namespace() == "PHRASEANET" && $meta_struct_el->get_metadata_tagname() == 'tf-editdate') if ($meta_struct_el->get_metadata_namespace() == "PHRASEANET" && $meta_struct_el->get_metadata_tagname() == 'tf-editdate')
@@ -490,7 +487,7 @@ class module_prod_route_records_edit extends module_prod_route_records_abstract
if (!array_key_exists($key, $elements)) if (!array_key_exists($key, $elements))
continue; continue;
$statbits = $rec['status']; $statbits = $rec['status'];
$editDirty = $rec['edit']; $editDirty = $rec['edit'];
if ($editDirty == '0') if ($editDirty == '0')
@@ -500,7 +497,21 @@ class module_prod_route_records_edit extends module_prod_route_records_abstract
if (is_array($rec['metadatas'])) if (is_array($rec['metadatas']))
{ {
$record->set_metadatas($rec['metadatas']); try
{
$db_field = \databox_field::get_instance($databox, $rec['metadatas']['meta_struct_id']);
if ($db_field->is_readonly())
{
throw new \Exception('Can not write a readonly field');
}
$record->set_metadatas($rec['metadatas']);
}
catch (\Exception $e)
{
}
} }
if ($write_edit_el instanceof databox_field) if ($write_edit_el instanceof databox_field)
@@ -509,22 +520,22 @@ class module_prod_route_records_edit extends module_prod_route_records_abstract
$field = array_pop($fields); $field = array_pop($fields);
$metas = array( $metas = array(
array( array(
'meta_struct_id' => $write_edit_el->get_id() 'meta_struct_id' => $write_edit_el->get_id()
, 'meta_id' => ($field ? $field->get_meta_id() : null) , 'meta_id' => ($field ? $field->get_meta_id() : null)
, 'value' => array($date_obj->format('Y-m-d h:i:s')) , 'value' => array($date_obj->format('Y-m-d h:i:s'))
) )
); );
$record->set_metadatas($metas); $record->set_metadatas($metas);
} }
$newstat = $record->get_status(); $newstat = $record->get_status();
$statbits = ltrim($statbits, 'x'); $statbits = ltrim($statbits, 'x');
if (!in_array($statbits, array('', 'null'))) if (!in_array($statbits, array('', 'null')))
{ {
$mask_and = ltrim(str_replace( $mask_and = ltrim(str_replace(
array('x', '0', '1', 'z'), array('1', 'z', '0', '1'), $statbits), '0'); array('x', '0', '1', 'z'), array('1', 'z', '0', '1'), $statbits), '0');
if ($mask_and != '') if ($mask_and != '')
$newstat = databox_status::operation_and_not($newstat, $mask_and); $newstat = databox_status::operation_and_not($newstat, $mask_and);
@@ -541,14 +552,14 @@ class module_prod_route_records_edit extends module_prod_route_records_abstract
if ($statbits != '') if ($statbits != '')
{ {
$appbox->get_session() $appbox->get_session()
->get_logger($record->get_databox()) ->get_logger($record->get_databox())
->log($record, Session_Logger::EVENT_STATUS, '', ''); ->log($record, Session_Logger::EVENT_STATUS, '', '');
} }
if ($editDirty) if ($editDirty)
{ {
$appbox->get_session() $appbox->get_session()
->get_logger($record->get_databox()) ->get_logger($record->get_databox())
->log($record, Session_Logger::EVENT_EDIT, '', ''); ->log($record, Session_Logger::EVENT_EDIT, '', '');
} }
} }

View File

@@ -69,17 +69,19 @@
{% endif %} {% endif %}
{% for field in editing.get_fields() %} {% for field in editing.get_fields() %}
{% set i = field.get_id() %} {% set i = field.get_id() %}
<div class="edit_field" id="EditFieldBox_{{i}}" onclick="return(edit_mdwn_fld(event, {{i}}, '{{field.get_name()}}'));" > {% if field.is_readonly() is empty %}
<img id="editSGtri_{{i}}" style="visibility:hidden;" src="/skins/prod/{{cssfile}}/images/suggested.gif" /> <div class="edit_field" id="EditFieldBox_{{i}}" onclick="return(edit_mdwn_fld(event, {{i}}, '{{field.get_name()}}'));" >
<img src="/skins/icons/info.gif" tooltipsrc="/prod/tooltip/metas/FieldInfos/{{field.get_databox().get_sbas_id()}}/{{field.get_id()}}/" class="fieldTips" alt=""/> <img id="editSGtri_{{i}}" style="visibility:hidden;" src="/skins/prod/{{cssfile}}/images/suggested.gif" />
{% if field.get_dces_element %} <img src="/skins/icons/info.gif" tooltipsrc="/prod/tooltip/metas/FieldInfos/{{field.get_databox().get_sbas_id()}}/{{field.get_id()}}/" class="fieldTips" alt=""/>
<img src="/skins/icons/dublincore.png" tooltipsrc="/prod/tooltip/DCESInfos/{{field.get_databox().get_sbas_id()}}/{{field.get_id()}}/" alt="{% trans 'Ce champ est decrit comme un element DublinCore' %}" class="DCESTips" alt=""/> {% if field.get_dces_element %}
{% endif %} <img src="/skins/icons/dublincore.png" tooltipsrc="/prod/tooltip/DCESInfos/{{field.get_databox().get_sbas_id()}}/{{field.get_id()}}/" alt="{% trans 'Ce champ est decrit comme un element DublinCore' %}" class="DCESTips" alt=""/>
<span id="spanidEditFieldBox_{{i}}"> {% endif %}
{{field.get_name()}} {% if field.is_required() %}<span style="font-weight:bold;font-size:16px;"> * </span>{% endif %} : <span id="spanidEditFieldBox_{{i}}">
</span> {{field.get_name()}} {% if field.is_required() %}<span style="font-weight:bold;font-size:16px;"> * </span>{% endif %} :
<span class="fieldvalue" id="idEditField_{{i}}" >???</span> </span>
</div> <span class="fieldvalue" id="idEditField_{{i}}" >???</span>
</div>
{% endif %}
{% endfor %} {% endfor %}
{% endmacro %} {% endmacro %}