Skip to content

Commit b68a94c

Browse files
committed
Added support for auto-image resizing via the transform property of fields.ini . Syntax:
transform=fit:400x400 would fit image to 400x400 transform=fill:400x400 would fill image to 400x400 Also added support for -format=xml in new and edit record forms to make it easier to write alternative client librarieswith forms that submit to Xataface.
1 parent 856ddca commit b68a94c

File tree

702 files changed

+2194
-970
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

702 files changed

+2194
-970
lines changed

Dataface/FormTool.php

+313-281
Large diffs are not rendered by default.

Dataface/FormTool/calendar.php

+62-34
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,28 @@ function &buildWidget(&$record, &$field, &$form, $formFieldName, $new=false){
99
/*
1010
* This field uses a calendar widget
1111
*/
12-
12+
1313
$widget =& $field['widget'];
1414
if ( !@$widget['lang'] ){
1515
$widget['lang'] = Dataface_Application::getInstance()->_conf['lang'];
1616
}
1717
$factory =& Dataface_FormTool::factory();
1818
$el =& $factory->addElement('calendar', $formFieldName, $widget['label'], null, $widget);
1919
//$el->setProperties($widget);
20-
20+
if ($form->xml) {
21+
$isDate = $record->table()->isDate($field['name']);
22+
$isTime = $record->table()->isTime($field['name']);
23+
if ($isDate) {
24+
$el->xmlAtts['date'] = 'true';
25+
}
26+
if ($isTime) {
27+
$el->xmlAtts['time'] = 'true';
28+
}
29+
}
30+
2131
return $el;
2232
}
23-
33+
2434
/**
2535
* @brief Added support to transform date values in alternate formats
2636
* as provided by the widget:ifFormat directive.
@@ -32,66 +42,84 @@ function pushValue(&$record, &$field, &$form, &$element, &$metaValues){
3242
$formFieldName = $field['name'];
3343
$val = $element->getValue();
3444
if ( !trim($val) ) return null;
35-
if ( @$field['widget']['ifFormat'] ){
36-
45+
$query = Dataface_Application::getInstance()->getQuery();
46+
if (!@$query['--date-format'] && @$field['widget']['ifFormat'] ){
47+
3748
$ts = $this->strptime($element->getValue(), $field['widget']['ifFormat']);
3849
$ts = mktime($ts['tm_hour'], $ts['tm_min'], $ts['tm_sec'],
3950
$ts['tm_mon']+1, $ts['tm_mday'], ($ts['tm_year'] + 1900));
4051
return date('Y-m-d H:i:s', $ts);
52+
} else if (@$query['--date-format']) {
53+
$fmt = $query['--date-format'];
54+
if ($fmt == 'server') {
55+
return $element->getValue();
56+
} else if ($fmt == 'timestamp') {
57+
return date('Y-m-d H:i:s', intval($element->getValue()));
58+
} else {
59+
return $element->getValue();
60+
}
4161
} else {
4262
return $element->getValue();
4363
}
44-
64+
4565
}
46-
66+
4767
private function strptime($date, $format){
4868
if ( function_exists('strptime') ){
4969
return strptime($date, $format);
5070
} else {
51-
$masks = array(
52-
'%d' => '(?P<d>[0-9]{2})',
53-
'%m' => '(?P<m>[0-9]{2})',
54-
'%Y' => '(?P<Y>[0-9]{4})',
55-
'%H' => '(?P<H>[0-9]{2})',
56-
'%M' => '(?P<M>[0-9]{2})',
71+
$masks = array(
72+
'%d' => '(?P<d>[0-9]{2})',
73+
'%m' => '(?P<m>[0-9]{2})',
74+
'%Y' => '(?P<Y>[0-9]{4})',
75+
'%H' => '(?P<H>[0-9]{2})',
76+
'%M' => '(?P<M>[0-9]{2})',
5777
'%S' => '(?P<S>[0-9]{2})'
58-
);
59-
60-
$rexep = "#".strtr(preg_quote($format), $masks)."#";
61-
if(!preg_match($rexep, $date, $out))
62-
return false;
63-
64-
$ret = array(
65-
"tm_sec" => (int) @$out['S'],
66-
"tm_min" => (int) @$out['M'],
67-
"tm_hour" => (int) @$out['H'],
68-
"tm_mday" => (int) @$out['d'],
69-
"tm_mon" => @$out['m']?@$out['m']-1:0,
70-
"tm_year" => @$out['Y'] > 1900 ? @$out['Y'] - 1900 : 0,
71-
);
72-
return $ret;
73-
78+
);
79+
80+
$rexep = "#".strtr(preg_quote($format), $masks)."#";
81+
if(!preg_match($rexep, $date, $out))
82+
return false;
83+
84+
$ret = array(
85+
"tm_sec" => (int) @$out['S'],
86+
"tm_min" => (int) @$out['M'],
87+
"tm_hour" => (int) @$out['H'],
88+
"tm_mday" => (int) @$out['d'],
89+
"tm_mon" => @$out['m']?@$out['m']-1:0,
90+
"tm_year" => @$out['Y'] > 1900 ? @$out['Y'] - 1900 : 0,
91+
);
92+
return $ret;
93+
7494
}
7595
}
76-
96+
7797
/**
7898
* @brief Added support to transform date values in alternate formats
7999
* as provided by the widget:ifFormat directive.
80100
* http://xataface.com/forum/viewtopic.php?f=4&t=5345
81101
*/
82102
function pullValue(&$record, &$field, &$form, &$element, &$metaValues){
83-
103+
84104
$table =& $record->_table;
85105
$formTool =& Dataface_FormTool::getInstance();
86106
$formFieldName = $field['name'];
87107
$val = $record->strval($formFieldName);
88108
if ( !trim($val) ) return '';
89-
if ( @$field['widget']['ifFormat'] ){
109+
$query = Dataface_Application::getInstance()->getQuery();
110+
if (!@$query['--date-format'] && @$field['widget']['ifFormat'] ){
90111
return strftime($field['widget']['ifFormat'], strtotime($val));
91-
112+
} else if (@$query['--date-format']) {
113+
if ($query['--date-format'] == 'server') {
114+
return $val;
115+
} else if ($query['--date-format'] == 'timestamp') {
116+
return strtotime($val);
117+
} else {
118+
return $val;
119+
}
92120
} else {
93121
return $val;
94122
}
95-
123+
96124
}
97125
}

Dataface/FormTool/checkbox.php

+45-27
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Dataface_FormTool_checkbox {
66
function &buildWidget(&$record, &$field, &$form, $formFieldName, $new=false){
77
$table =& $record->_table;
88
$widget =& $field['widget'];
9-
9+
1010
if ( !@$widget['separator'] ) $widget['separator'] = '<br />';
1111
$factory =& Dataface_FormTool::factory();
1212
if ( (isset( $field['repeat']) and $field['repeat'] and isset($field['vocabulary']) and $field['vocabulary']) or
@@ -20,7 +20,7 @@ function &buildWidget(&$record, &$field, &$form, $formFieldName, $new=false){
2020
$relationship =& $record->_table->getRelationship($field['relationship']);
2121
$options = $relationship->getAddableValues($record);
2222
$options__classes = array();
23-
23+
2424
// Now let's add the ability to add an option that isn't already there
2525
// but only if the user has permission
2626
if ( !@$widget['suffix'] ) $widget['suffix'] = '';
@@ -29,27 +29,27 @@ function &buildWidget(&$record, &$field, &$form, $formFieldName, $new=false){
2929
import('Dataface/JavascriptTool.php');
3030
$jt = Dataface_JavascriptTool::getInstance();
3131
$jt->import('xataface/widgets/checkbox.js');
32-
32+
3333
// $suffix = '<script type="text/javascript" src="'.DATAFACE_URL.'/js/jquery-ui-1.7.2.custom.min.js"></script>';
3434
//$suffix .= '<script type="text/javascript" src="'.DATAFACE_URL.'/js/RecordDialog/RecordDialog.js"></script>';
35-
$suffix =
36-
'<a
35+
$suffix =
36+
'<a
3737
class="xf-checkbox-widget-other-link"
38-
href="#"
39-
onclick="return false"
38+
href="#"
39+
onclick="return false"
4040
id="'.df_escape($field['name']).'-other"
4141
data-relationship-name="'.df_escape($relationship->getName()).'"
4242
data-table-name="'.df_escape($dtable->tablename).'"
4343
data-field-name="'.df_escape($field['name']).'"
4444
data-keys="'.df_escape(json_encode(array_keys($dtable->keys()))).'"
4545
>Other..</a>';
46-
47-
46+
47+
4848
$widget['suffix'] = $suffix;
4949
}
5050
}
51-
52-
51+
52+
5353
if ( $record and $record->val($field['name']) ){
5454
$vals = $record->val($field['name']);
5555
if ( is_array($vals) ){
@@ -59,21 +59,39 @@ class="xf-checkbox-widget-other-link"
5959
}
6060
}
6161
}
62-
62+
6363
}
6464
$dummyForm = new HTML_QuickForm();
6565
foreach ($options as $opt_val=>$opt_text){
6666
if ( $opt_val === '') continue;
6767
$boxes[] =& $dummyForm->createElement('checkbox',$opt_val , null, $opt_text, array('class'=>'checkbox-of-'.$field['name'].' '.@$options__classes[$opt_val]));
6868
//$boxes[count($boxes)-1]->setValue($opt_val);
69-
69+
70+
}
71+
if (is_array($form->_submitValues)) {
72+
$submitVal = @$form->_submitValues[$field['name']];
73+
if (is_string($submitVal) and strlen($submitVal) > 0 and $submitVal{0} == '[') {
74+
$decoded = json_decode($submitVal, true);
75+
$newVal = array();
76+
foreach ($decoded as $v) {
77+
$newVal[$v] = '1';
78+
}
79+
$form->_submitValues[$field['name']] = $newVal;
80+
}
7081
}
7182
$el =& $factory->addGroup($boxes, $field['name'], $widget['label']);
72-
83+
if ($form->xml) {
84+
$xmlBody = '<vocabulary>';
85+
foreach ($options as $opt_val=>$opt_text) {
86+
$xmlBody .= '<value key="'.xmlentities($opt_val).'">'.xmlentities($opt_text).'</value>';
87+
}
88+
$xmlBody .= '</vocabulary>';
89+
$el->updateAttributes(array('data-xf-xml-body'=> $xmlBody));
90+
}
7391
} else {
74-
75-
76-
92+
93+
94+
7795
$el =& $factory->addElement('advcheckbox', $formFieldName, $widget['label']);
7896
if ( $field['vocabulary'] ){
7997
$yes = '';
@@ -85,20 +103,20 @@ class="xf-checkbox-widget-other-link"
85103
}
86104
return $el;
87105
}
88-
106+
89107
function &pushValue(&$record, &$field, &$form, &$element, &$metaValues){
90108
$table =& $record->_table;
91109
$formTool =& Dataface_FormTool::getInstance();
92110
$formFieldName = $element->getName();
93-
111+
94112
$val = $element->getValue();
95113
if ( $field['repeat'] ){
96-
114+
97115
//print_r(array_keys($val));
98116
// eg value array('value1'=>1, 'value2'=>1, ..., 'valueN'=>1)
99117
if ( is_array($val) ){
100118
$out = array_keys($val);
101-
} else {
119+
} else {
102120
$out = array();
103121
}
104122
//$res =& $s->setValue($fieldname, array_keys($val));
@@ -122,14 +140,14 @@ function &pushValue(&$record, &$field, &$form, &$element, &$metaValues){
122140
}
123141
return $out;
124142
}
125-
143+
126144
function pullValue(&$record, &$field, &$form, &$element, $new=false){
127-
145+
128146
/*
129147
*
130148
* Checkbox widgets store values as associative array $a where
131149
* $a[$x] == 1 <=> element named $x is checked.
132-
* Note: See _buildWidget() for information about how the checkbox widget is
150+
* Note: See _buildWidget() for information about how the checkbox widget is
133151
* created. It is created differently for repeat fields than it is for individual
134152
* fields. For starters, individual fields are advcheckbox widgets, whereas
135153
* repeat fields are just normal checkbox widgets.
@@ -155,14 +173,14 @@ function pullValue(&$record, &$field, &$form, &$element, $new=false){
155173
$val = $v;
156174
} else {
157175
/*
158-
*
176+
*
159177
* If the field is not a repeat, then it is only one value
160178
*
161179
*/
162180
$val = $record->getValueAsString($field['name']);
163181
}
164-
165-
182+
183+
166184
return $val;
167185
}
168186
}

0 commit comments

Comments
 (0)