table width preference

Discuss MySQL Ajax Table Editor

table width preference

Postby Wurzelsepp » Sat Jan 28, 2012 3:46 pm

Hi,

find below a first draft to allow changing column widths in the show/hide table.
The forum does not allow to upload .diff or .txt, so I enclose it inline.
BTW: I am aware that the user's mate_columns should probably be read all at once when creating the table layout

--- js/ajax_table_editor.js.orig 2012-01-28 14:43:19.000000000 +0100
+++ js/ajax_table_editor.js 2012-01-28 15:05:12.000000000 +0100
@@ -572,6 +572,11 @@
}
}

+function setColumnWidth(inp,col)
+{
+ toAjaxTableEditor('set_column_width',[col,inp.value]);
+}
+
function disableEnableInput(column,cb)
{
if(cb.checked)
--- php/AjaxTableEditor.php.orig 2012-01-28 14:27:32.000000000 +0100
+++ php/AjaxTableEditor.php 2012-01-28 16:26:34.000000000 +0100
@@ -294,6 +294,9 @@
case 'show_hide_columns':
$this->showHideColumns();
break;
+ case 'set_column_width':
+ $this->setColumnWidth();
+ break;
case 'view_row':
$this->viewRow();
break;
@@ -479,7 +482,18 @@
}
return $rv;
}
-
+
+ function columnWidth($column, $width = '')
+ {
+ $query = "select id, col_width from mate_columns where mate_user_id = '$this->mateUserId' and mate_var_prefix = '$this->varPrefix' and mate_column = '$column'";
+ $result = $this->doQuery($query);
+ if($row = mysql_fetch_assoc($result))
+ {
+ $width = $row['col_width'];
+ }
+ return $width;
+ }
function showColumn()
{
if($this->setMateUserId())
@@ -525,7 +539,31 @@
}
}
}
-
+
+ function setColumnWidth()
+ {
+ if($this->setMateUserId())
+ {
+ $column = $this->escapeData($this->info[0]);
+ $val = $this->escapeData($this->info[1]);
+ if(!ereg('^[0-9]+$', $val)) $val = '';
+ $query = "select id from mate_columns where mate_user_id = '$this->mateUserId' and mate_var_prefix = '$this->varPrefix' and mate_column = '$column'";
+ $result = $this->doQuery($query);
+ if($row = mysql_fetch_assoc($result))
+ {
+ $mateColId = $row['id'];
+ $query = "update mate_columns set col_width = '$val' where id = '$mateColId'";
+ $result = $this->doQuery($query);
+ }
+ else
+ {
+ $query = "insert into mate_columns set mate_user_id = '$this->mateUserId', mate_var_prefix = '$this->varPrefix', mate_column = '$column', col_width = '$val', hidden = 'No', date_updated = NOW()";
+ $result = $this->doQuery($query);
+ }
+ $this->showHideColumns();
+ }
+ }
+
function setMateUserId()
{
if(isset($_COOKIE['mate_user_id']) && strlen($_COOKIE['mate_user_id']) > 0)
@@ -554,18 +592,26 @@
{
if($this->setMateUserId())
{
- $html = '<table '.$this->showHideTableInfo.'><tr style="font-weight: bold;"><td>'.$this->langVars->ttlColumn.'</td><td>'.$this->langVars->ttlCheckBox.'</td></tr>';
+ $html = '<table '.$this->showHideTableInfo.'><tr style="font-weight: bold;"><td>'.$this->langVars->ttlColumn.'</td><td>'.$this->langVars->ttlCheckBox.'</td><td>'.$this->langVars->ttlWidth.'</td><td width=\'250\'></td></tr>';
foreach($this->tableColumns as $col => $info)
{
if(stristr($info['perms'],'H') && $col !
= $this->primaryKeyCol)
{
$checked = 'checked="checked"';
$hidden = isset($info['hidden']) ? $info['hidden'] : false;
+ $width = '';
+ if(isset($info['col_header_info']) && ereg('width: *([0-9]+)', $info['col_header_info'], $matches))
+ $width = $matches[1];
+ $width = $this->columnWidth($col
, $width);
+ if(is_numeric($width))
+ $bar = "<div style='width: ${width}px; height: 10px; background-color: red;'> </div>";
+ else
+ $bar = "";
if($this->columnIsHidden($col,$hidden))
{
$checked = '';
}
- $html .= '<tr><td><label for="'.$col.'_hide_cb">'.$info['display_text'].'</label>:</td><td><input type="checkbox" id="'.$col.'_hide_cb" onchange="showHideColumn(this,\''.$col.'\');" '.$checked.' /></tr>';
+ $html .= '<tr><td><label for="'.$col.'_hide_cb">'.$info['display_text'].'</label>:</td><td><input type="checkbox" id="'.$col.'_hide_cb" onchange="showHideColumn(this,\''.$col.'\');" '.$checked
.' /></td><td><input type="text" size="4" id="'.$col.'_colwd" onchange="setColumnWidth(this,\''.$col.'\');" value="'.$width.'" /></td><td>'.$bar.'</td></tr>';
}
}
$html .= '</table>';
@@ -2010,6 +2056,17 @@
if(stristr($info['perms'],'T'))
{
$colHeaderInfo = isset($info['col_header
_info']) ? $info['col_header_info'] : '';
+ $width = $this->columnWidth($col);
+ if(is_numeric($width))
+ { $old = $colHeaderInfo;
+ if(preg_match('/width: *[0-9]+/', $colHeaderInfo))
+ $colHeaderInfo = preg_replace('/width: *[0-9]+/', "width: $width", $colHeaderInfo);
+ else if(preg_match('/width=(\'|")?[0-9]+\1/', $colHeaderInfo))
+ $colHeaderInfo = preg_replace('/(width=(\'|")?)[0-9]+\1/', "\\1$width\\2", $colHeaderInfo);
+ else
+ $colHeaderInfo .= " width='$width'";
+ // user_error("change $old to $colHeaderInfo");
+ }
if($this->orderByColumn == $col)
{
list($oppAscOrDesc,$arrow) = $this->ascOrDesc == 'asc' ? array('desc','&uarr;') : array('asc','&darr;');
--- php/lang/LangVars-en.php.orig 2012-01-28 16:27:32.000000000 +0100
+++ php/lang/LangVars-en.php 2012-01-28 16:27:52.000000000 +0100
@@ -85,6 +85,7 @@
// function showHideColumns
var $ttlColumn = 'Column';
var $ttlCheckBox = 'Display';
+ var $ttlWidth = 'Width';
// function handleFileUpload
var $errFileSize = 'The %s was too big';
var $errFileReq = '%s is a required field';
--- php/lang/LangVars-ge.php.orig 2012-01-28 14:30:39.000000000 +0100
+++ php/lang/LangVars-ge.php 2012-01-28 14:43:59.000000000 +0100
@@ -85,6 +85,7 @@
// function showHideColumns
var $ttlColumn = 'Spalte';
var $ttlCheckBox = 'Anzeige';
+ var $ttlWidth = 'Breite';
// function handleFileUpload
var $errFileSize = '%s war zu groß';
var $errFileReq = '%s ist ein benötigtes Feld';
Wurzelsepp
 
Posts: 9
Joined: Wed Jan 18, 2012 4:53 am

Return to Open Discussion

Who is online

Users browsing this forum: No registered users and 5 guests

cron