From: Joey Schulze Date: Mon, 24 Feb 2014 18:53:16 +0000 (+0100) Subject: Add support for popup editing inside a live grid X-Git-Url: https://git.infodrom.org/?p=infodrom%2Fhallinta;a=commitdiff_plain;h=f5fec0fc426069517d53c504ca4bab04b90517c5 Add support for popup editing inside a live grid --- diff --git a/ajax/ajax.php b/ajax/ajax.php index 5a7a1ec..2b84c0b 100644 --- a/ajax/ajax.php +++ b/ajax/ajax.php @@ -528,6 +528,56 @@ function process_file($mask) exit; } +function process_listedit($mask, $action) +{ + global $db; + + if ($_REQUEST['second'] === true) + $list = $mask['second']; + else + $list = $mask['list']; + + $values = array(); + foreach ($_POST as $k => $v) + if (substr($k,0,10) == 'listinput_') + $values[substr($k,10)] = $v; + + switch ($action) { + case 'upd': + $update = sprintf("sys_user='%s', sys_edit=now()", $_SESSION['sys']['login']); + foreach ($values as $c => $v) + $update .= sprintf(", %s = '%s'", $c, $v); + $sql = sprintf("UPDATE %s SET %s WHERE id = %d", + $list['table_edit'], + $update, + $_POST['_k0']); + + $db->query($sql); + break; + } +} + +if (!empty($_REQUEST['_k0'])) { + db_connect(); + + foreach ($_POST as $k => $v) + if (substr($k,0,5) == 'grid_' && substr($k,-8) == '__action') { + $_REQUEST['source'] = substr($k,5,-8); + $action = $v; + } + + if (substr($_REQUEST['source'],-8) == '__second') { + $_REQUEST['source'] = substr($_REQUEST['source'],0,-8); + $_REQUEST['second'] = true; + } else { + $_REQUEST['second'] = false; + } + + if (load_mask($_REQUEST['source']) === false) exit; + process_listedit($mask, $action); + exit; +} + if (empty($_REQUEST['func'])) exit; diff --git a/lib/mask.php b/lib/mask.php index 936f3e0..3879c31 100644 --- a/lib/mask.php +++ b/lib/mask.php @@ -174,15 +174,25 @@ function build_grid($name, $mask, $gridname = false) # $opts[] = 'frozenColumns: ' . count($mask['list']); $opts[] = 'saveColumnInfo: {width: true, filter: true, sort: true}'; + $canEdit = array_key_exists('table_edit', $mask); + if ($canEdit) { + $opts[] = 'canEdit: true'; + $opts[] = "updateURL: 'ajax/ajax.php'"; + } + $ret[] = sprintf('', $name); $ret[] = ' '; $specs = array(); $fields = array(); foreach ($mask['list'] as $field => $data) { $ret[] = sprintf(' ', $data['name']); - $s = array(sprintf("FieldName: 'input_%s'", $field), - sprintf("ColName: 'input_%s'", $data['name'])); - $s = array(); + if ($canEdit && array_key_exists('edit', $data)) { + $s = array(sprintf("FieldName: 'listinput_%s'", $field), + sprintf("ColName: '%s'", $data['name']), + $data['edit']); + } else { + $s = array(); + } if (isset($data['visible']) && $data['visible'] === false) $s[] = 'visible: false'; if (isset($data['width']) && $data['width'] > 0) $s[] = 'width: ' . $data['width']; if (array_key_exists('type', $data)) $s[] = "type: '" . $data['type'] . "'";
%s