From 99169dc5af0ba8011612c9a277abc3da6fa02daa Mon Sep 17 00:00:00 2001 From: secretr Date: Fri, 23 Oct 2009 18:08:02 +0000 Subject: [PATCH] e_form: various major code/markup/style improvements, adminlist table almost fully automated, next step - fieldset/form methods & create/edit mod auto-render --- e107_handlers/form_handler.php | 169 ++++++++++++++++++++--------- e107_themes/_blank/admin_style.css | 14 ++- e107_themes/jayya/style.css | 7 +- 3 files changed, 134 insertions(+), 56 deletions(-) diff --git a/e107_handlers/form_handler.php b/e107_handlers/form_handler.php index d54f41bdf..275f4d383 100644 --- a/e107_handlers/form_handler.php +++ b/e107_handlers/form_handler.php @@ -9,9 +9,9 @@ * Form Handler * * $Source: /cvs_backup/e107_0.8/e107_handlers/form_handler.php,v $ - * $Revision: 1.54 $ - * $Date: 2009-10-23 04:25:13 $ - * $Author: e107coders $ + * $Revision: 1.55 $ + * $Date: 2009-10-23 18:08:01 $ + * $Author: secretr $ * */ @@ -356,12 +356,12 @@ class e_form return ""; } - function option($option_name, $value, $selected = false, $options = array()) + function option($option_title, $value, $selected = false, $options = array()) { if(false === $value) $value = ''; $options = $this->format_options('option', '', $options); $options['selected'] = $selected; //comes as separate argument just for convenience - return ""; + return ""; } function option_multi($option_array, $selected = false, $options = array()) @@ -420,9 +420,8 @@ class e_form function admin_button($name, $value, $action = 'submit', $label = '', $options = array()) { - $btype = 'submit'; - if($action == 'action') $btype = 'button'; + if(strpos($action, 'action') === 0) $btype = 'button'; $options = $this->format_options('admin_button', $name, $options); $options['class'] = $action;//shorthand if(empty($label)) $label = $value; @@ -473,6 +472,10 @@ class e_form case 'title': if($optval) $ret .= " title='{$optval}'"; break; + + case 'label': + if($optval) $ret .= " label='{$optval}'"; + break; case 'tabindex': if($optval) $ret .= " tabindex='{$optval}'"; @@ -582,6 +585,7 @@ class e_form 'checked' => false, 'disabled' => false, 'tabindex' => 0, + 'label' => '', 'other' => '' ); @@ -611,7 +615,7 @@ class e_form break; case 'option': - $def_options = array('class' => '', 'selected' => false, 'other' => ''); + $def_options = array('class' => '', 'selected' => false, 'other' => '', 'disabled' => false, 'label' => ''); break; case 'radio': @@ -652,11 +656,11 @@ class e_form { $columnsArray = array_filter($columnsArray); $text = " -
+
" ."select columns" ." -
+
"; unset($columnsArray['options'], $columnsArray['checkboxes']); @@ -678,7 +682,7 @@ class e_form
".$this->admin_button('submit-e-columns', LAN_SAVE, 'update')."
-
+
"; @@ -717,7 +721,11 @@ class e_form if(strpos($querypattern,'&')!==FALSE) { - $tmp = $_GET; // we can assume it's always $_GET since that's what it will generate + // we can assume it's always $_GET since that's what it will generate + // more flexible (e.g. pass default values for order/field when they can't be found in e_QUERY) & secure + $tmp = $requeststr ? $requeststr : str_replace('&', '&', e_QUERY); + parse_str($tmp, $tmp); + $etmp = array(); parse_str($querypattern,$etmp); } @@ -726,12 +734,9 @@ class e_form $tmp = explode(".", ($requeststr ? $requeststr : e_QUERY)); $etmp = explode(".", $querypattern); } - - foreach($etmp as $key => $val) // I'm sure there's a more efficient way to do this, but too tired to see it right now!. { - if($val == "[FIELD]") { $field = $tmp[$key]; @@ -746,22 +751,20 @@ class e_form $fromval = $tmp[$key]; } } - - - if(!varset($fromval)){ $fromval = 0; } $ascdesc = (varset($ascdesc) == 'desc') ? 'asc' : 'desc'; - foreach($fieldarray as $key=>$val) { - if(in_array($key,$columnPref) || $key == "options" || (vartrue($val['forced']))) + if(in_array($key,$columnPref) || $key == 'options' || (vartrue($val['forced']))) { - $cl = (varset($val['thclass'])) ? "class='".$val['thclass']."'" : ""; - $text .= "\n\t"; + $cl = (vartrue($val['thclass'])) ? " class='".$val['thclass']."'" : ""; + $text .= " + + "; - if($querypattern!="" && !varsettrue($val['nosort']) && $key != "options") + if($querypattern!="" && !varsettrue($val['nosort']) && $key != "options" && $key != "checkboxes") { $from = ($key == $field) ? $fromval : 0; $srch = array("[FIELD]","[ASC]","[FROM]"); @@ -769,14 +772,16 @@ class e_form $val['url'] = e_SELF."?".str_replace($srch,$repl,$querypattern); } - $text .= (varset($val['url'])) ? "" : ""; // Really this column-sorting link should be auto-generated, or be autocreated via unobtrusive js. - $text .= $val['title']; + $text .= (vartrue($val['url'])) ? "" : ""; // Really this column-sorting link should be auto-generated, or be autocreated via unobtrusive js. + $text .= vartrue($val['title'], ''); $text .= ($val['url']) ? "" : ""; $text .= ($key == "options") ? $this->columnSelector($fieldarray,$columnPref) : ""; - $text .= ($key == "checkboxes") ? $this->checkbox_toggle('e-column-toggle', $val['toggle']) : ""; + $text .= ($key == "checkboxes") ? $this->checkbox_toggle('e-column-toggle', vartrue($val['toggle'], 'multiselect')) : ""; - $text .= ""; + $text .= " + + "; } } @@ -796,10 +801,20 @@ class e_form foreach ($fieldarray as $field => $data) { //Not found - if(!$data['forced'] && (!in_array($field, $currentlist) || !isset($fieldvalues[$field]))) + if(!$data['forced'] && !in_array($field, $currentlist)) { continue; } + elseif(!$data['forced'] && !isset($fieldvalues[$field])) + { + $ret .= " + + Not Found! + + "; + + continue; + } $tdclass = vartrue($data['class']); if($tdclass) @@ -809,6 +824,13 @@ class e_form $value = $fieldvalues[$field]; + $parms = array(); + if(isset($data['colparms'])) + { + if(!is_array($data['colparms'])) parse_str($data['colparms'], $data['colparms']); + $parms = $data['colparms']; + } + switch($field) { case 'options': @@ -816,7 +838,7 @@ class e_form break; case 'checkboxes': - $value = $this->checkbox($data['toggle'].'[]', $value); + $value = $this->checkbox(vartrue($data['toggle'], 'multiselect').'[]', $value); $data['type'] = 'text'; break; } @@ -830,21 +852,31 @@ class e_form break; case 'datestamp': - $mask = 'short'; - if(is_array($value)) - { - $mask = $value[1]; - $value = $value[0]; - } - $value = e107::getDateConvert()->convert_date($value, $mask); + $value = e107::getDateConvert()->convert_date($value, vartrue($parms['mask'], 'short')); break; case 'userclass': $value = $this->_uc->uc_get_classname($value); break; + case 'user_name': + case 'user_loginname': + case 'user_login': + case 'user_customtitle': + case 'user_email': + $value = get_user_data($value); + if($value) + { + $value = $value[$data['type']] ? $value[$data['type']] : $value['user_name']; + } + else + { + $value = 'not found'; + } + break; + case 'boolean': - $value = $value ? ADMIN_TRUE_ICON : ''; + $value = $value ? ADMIN_TRUE_ICON : '';// TODO - ADMIN_FALSE_ICON break; //TODO - form_userclass, order,... and maybe more types @@ -854,6 +886,16 @@ class e_form break; } + //TODO - this should be done per type! + if(vartrue($parms['truncate'])) + { + $value = e107::getParser()->text_truncate($value, $parms['truncate'], '...'); + } + elseif(vartrue($parms['htmltruncate'])) + { + $value = e107::getParser()->html_truncate($value, $parms['htmltruncate'], '...'); + } + $ret .= ' '.$value.' @@ -940,23 +982,49 @@ class e_form $text = "
- - + ".$this->select_close()." + ".$this->admin_button('trigger_execute_batch', 'trigger_execute_batch', 'submit multi e-hide-if-js', 'Go')."
-  "; + "; + return $text; } } diff --git a/e107_themes/_blank/admin_style.css b/e107_themes/_blank/admin_style.css index bd67c5a57..1ed1be8ac 100644 --- a/e107_themes/_blank/admin_style.css +++ b/e107_themes/_blank/admin_style.css @@ -111,6 +111,10 @@ pre { .adminlist tr.odd {} .adminlist tr.even { background-color:#f6f6f6; } +.adminlist .col-selection-cont { position: relative; float:right; } +.col-selection-cont .col-selection { text-align:left; background-color: #FCFDFF; border: 1px outset black; width:200px; margin-right:0px; overflow:visible; position: absolute; z-index:101; right:0px;} +.col-selection .col-selection-body { padding: 5px; clear: both; } + /* Form elements */ input.input-text, textarea, @@ -163,7 +167,7 @@ div.bbarea.small, .tbox.small, .tbox.helpbox.small { width: 250px !important; } .col-selection { padding:5px; text-align:left; background-color: #FCFDFF; border: 1px outset black; width:200px; margin-right:0px;overflow:visible; position:absolute; z-index:101; right:0px;} - +/* TODO - rename it to adminprefs */ .adminform { width:100%; border:1px solid #ddd;} .adminform th { padding: 5px; font-weight: bold; white-space:nowrap; } @@ -201,7 +205,7 @@ div.bbarea.small, .tbox.small, .tbox.helpbox.small { width: 250px !important; } .adminedit td.control {} -/* Admin Info Table */ +/* Admin Info Table TODO - box model (div) */ .admininfo { width:100%; border:1px solid #ddd;} .admininfo td { padding: 1px 5px; text-align: left} @@ -246,10 +250,10 @@ div.bbarea.small, .tbox.small, .tbox.helpbox.small { width: 250px !important; } .s-message .s-message-title { height: 32px; background: 0 50% no-repeat; padding-left: 42px; font-size: 14px; font-weight: bold; line-height: 32px; } .s-message div.info .s-message-title { background-image: url(images/messagebox_info.png); } -.s-message div.error .s-message-title { background-image: url(images/messagebox_critical.png); } +.s-message div.error .s-message-title { background-image: url(images/messagebox_critical.png); } .s-message div.success .s-message-title { background-image: url(images/ok.png); } .s-message div.warning .s-message-title { background-image: url(images/messagebox_warning.png); } -.s-message div.debug .s-message-title { background-image: url(images/messagebox_info.png); } +.s-message div.debug .s-message-title { background-image: url(images/messagebox_info.png); } .s-message-body { padding-left: 42px; } .s-message-item {} @@ -374,7 +378,7 @@ input.action.edit {} /********** Misc */ .e-pointer { cursor: pointer; } /* Pointer Hand */ .expand-container { padding: 10px; } /* Block with expandable items */ -.nextprev-bar { clear: both; padding: 5px; font-size: 14px; margin: 5px; border:1px solid #ddd; } /* Page NextPrev nabigation block */ +.nextprev-bar { clear: both; padding: 5px; font-size: 14px; margin: 5px; border:1px solid #ddd; } /* Page NextPrev navigation block */ .imgselector-container { clear: both; } /* ImageSelector.sc */ diff --git a/e107_themes/jayya/style.css b/e107_themes/jayya/style.css index 6ff09dfc2..43c5f203b 100644 --- a/e107_themes/jayya/style.css +++ b/e107_themes/jayya/style.css @@ -417,6 +417,10 @@ img.S128 { width: 128px; height: 128px } .adminlist tr.odd {} .adminlist tr.even { background-color:#f6f6f6; } +.adminlist .col-selection-cont { position: relative; float:right; } +.col-selection-cont .col-selection { text-align:left; background-color: #FCFDFF; border: 1px outset black; width:200px; margin-right:0px; overflow:visible; position: absolute; z-index:101; right:0px;} +.col-selection .col-selection-body { padding: 5px; clear: both; } + /* Form elements */ input.input-text, textarea, @@ -461,7 +465,6 @@ label { cursor: pointer; } /* form used for settings */ .col-label { width: 250px; } .col-control {} -.col-selection { padding:5px; text-align:left; background-color: #FCFDFF; border: 1px outset black; width:200px; margin-right:0px;overflow:visible; position:absolute; z-index:101; right:0px;} @@ -502,6 +505,8 @@ label { cursor: pointer; } .adminedit td.control {} + + /* Admin Info Table */ .admininfo { width:100%; border:1px solid #ddd;} .admininfo td { padding: 1px 5px; text-align: left}