Index: branches/RC/core/units/custom_fields/custom_fields_config.php
===================================================================
diff -u -r10902 -r10913
--- branches/RC/core/units/custom_fields/custom_fields_config.php (.../custom_fields_config.php) (revision 10902)
+++ branches/RC/core/units/custom_fields/custom_fields_config.php (.../custom_fields_config.php) (revision 10913)
@@ -90,8 +90,20 @@
'Value' => Array('type' => 'string', 'default' => ''),
'OriginalValue' => Array('type' => 'string', 'default' => ''),
'Error' => Array('type' => 'string', 'default' => ''),
- 'DirectOptions' => Array('type' => 'string', 'default' => '')
+ 'DirectOptions' => Array('type' => 'string', 'default' => ''),
+
+ 'SortValues' => Array (
+ 'type' => 'int',
+ 'formatter' => 'kOptionsFormatter',
+ 'options' => Array (1 => 'la_Yes', 0 => 'la_No'), 'use_phrases' => 1,
+ 'default' => 0,
+ ),
+ // for ValueList field editing via "inp_edit_minput" control
+ 'OptionKey' => Array ('type' => 'int', 'not_null' => 1, 'default' => ''),
+ 'OptionTitle' => Array ('type' => 'string', 'not_null' => 1, 'default' => ''),
+ 'Options' => Array ('type' => 'string', 'not_null' => 1, 'default' => ''),
+
),
'Grids' => Array(
Index: branches/RC/core/units/custom_fields/custom_fields_event_handler.php
===================================================================
diff -u -r8929 -r10913
--- branches/RC/core/units/custom_fields/custom_fields_event_handler.php (.../custom_fields_event_handler.php) (revision 8929)
+++ branches/RC/core/units/custom_fields/custom_fields_event_handler.php (.../custom_fields_event_handler.php) (revision 10913)
@@ -83,7 +83,7 @@
$ml_helper =& $this->Application->recallObject('kMultiLanguageHelper');
/* @var $ml_helper kMultiLanguageHelper */
-
+
// call main item config to clone cdata table
$this->Application->getUnitOption($main_prefix, 'TableName');
$ml_helper->deleteField($main_prefix.'-cdata', $event->getEventParam('id'));
@@ -119,7 +119,7 @@
$ml_helper =& $this->Application->recallObject('kMultiLanguageHelper');
/* @var $ml_helper kMultiLanguageHelper */
-
+
// call main item config to clone cdata table
$this->Application->getUnitOption($main_prefix, 'TableName');
$ml_helper->createFields($main_prefix.'-cdata');
@@ -145,5 +145,89 @@
$object =& $event->getObject();
$object->SetDBField('Type', $this->Application->GetVar('cf_type'));
}
+
+ /**
+ * Prepares ValueList field's value as xml for editing
+ *
+ * @param kEvent $event
+ */
+ function OnAfterItemLoad(&$event)
+ {
+ parent::OnAfterItemLoad($event);
+
+ $object =& $event->getObject();
+ /* @var $object kDBItem */
+
+ if (!in_array($object->GetDBField('ElementType'), $this->_getMultiElementTypes())) {
+ return ;
+ }
+
+ $custom_field_helper =& $this->Application->recallObject('InpCustomFieldsHelper');
+ /* @var $custom_field_helper InpCustomFieldsHelper */
+
+ $options = $custom_field_helper->GetValuesHash( $object->GetDBField('ValueList') );
+
+ $records = Array ();
+ foreach ($options as $option_key => $option_title) {
+ if ($option_key > 0) {
+ $records[] = Array ('OptionKey' => $option_key, 'OptionTitle' => $option_title);
+ }
+ }
+
+ $minput_helper =& $this->Application->recallObject('MInputHelper');
+ /* @var $minput_helper MInputHelper */
+
+ $xml = $minput_helper->prepareMInputXML($records, Array ('OptionKey', 'OptionTitle'));
+ $object->SetDBField('Options', $xml);
+ }
+
+ /**
+ * Returns custom field element types, that will use minput control
+ *
+ * @return unknown
+ */
+ function _getMultiElementTypes()
+ {
+ return Array ('select', 'multiselect', 'radio');
+ }
+
+ /**
+ * Saves minput content to ValueList field
+ *
+ * @param kEvent $event
+ */
+ function OnBeforeItemUpdate(&$event)
+ {
+ parent::OnBeforeItemUpdate($event);
+
+ $object =& $event->getObject();
+ /* @var $object kDBItem */
+
+ if (!in_array($object->GetDBField('ElementType'), $this->_getMultiElementTypes())) {
+ return ;
+ }
+
+ $minput_helper =& $this->Application->recallObject('MInputHelper');
+ /* @var $minput_helper MInputHelper */
+
+ $ret = $object->GetDBField('ElementType') == 'multiselect' ? Array () : Array ('' => '=+');
+ $records = $minput_helper->parseMInputXML($object->GetDBField('Options'));
+
+ if ($object->GetDBField('SortValues')) {
+ usort($records, Array (&$this, '_sortValues'));
+ ksort($records);
+ }
+
+ foreach ($records as $record) {
+ $ret[] = $record['OptionKey'] . '=+' . $record['OptionTitle'];
+ }
+
+ $object->SetDBField('ValueList', implode(VALUE_LIST_SEPARATOR, $ret));
+ }
+
+ function _sortValues($record_a, $record_b)
+ {
+ return strcasecmp($record_a['OptionTitle'], $record_b['OptionTitle']);
+ }
}
?>
\ No newline at end of file
Index: branches/RC/core/admin_templates/custom_fields/custom_fields_edit.tpl
===================================================================
diff -u -r10856 -r10913
--- branches/RC/core/admin_templates/custom_fields/custom_fields_edit.tpl (.../custom_fields_edit.tpl) (revision 10856)
+++ branches/RC/core/admin_templates/custom_fields/custom_fields_edit.tpl (.../custom_fields_edit.tpl) (revision 10913)
@@ -67,14 +67,86 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+