|
|
@@ -3295,6 +3295,178 @@ var p5UI_TableAjax_generateFunctionNode = function(funObj, rowPK, props) {
|
|
|
$exportFields = $this->_showExportFieldsJson();
|
|
|
?>
|
|
|
<script>
|
|
|
+function TableAjax__HIST_Route(args) {
|
|
|
+ var recordID = args;
|
|
|
+ if (typeof args == 'object') {
|
|
|
+ recordID = args.shift();
|
|
|
+ recordID = parseInt(recordID);
|
|
|
+ }
|
|
|
+ if (typeof recordID !== 'number' || recordID <= 0) {
|
|
|
+ // TODO: msg
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ var cont = jQuery('#<?php echo $this->_htmlID; ?>').parent();
|
|
|
+ cont.hide();
|
|
|
+
|
|
|
+ // remove previous task content
|
|
|
+ var taskCnt = jQuery('#<?php echo $this->_htmlID; ?>_task');
|
|
|
+ taskCnt.parent().remove();
|
|
|
+ taskCnt.remove();
|
|
|
+
|
|
|
+ var taskCont = jQuery('<div class="AjaxTableCont"></div>').insertBefore(cont);
|
|
|
+ jQuery('<ul class="breadcrumb">' +
|
|
|
+ '<li><a href="#" onclick="return tableAjaxBackToTable();"><?php echo $this->getLabelHtml(); ?></a></li>' +
|
|
|
+ '<li class="active">Historia rekordu</li>' +
|
|
|
+ '</ul>').appendTo(taskCont);
|
|
|
+ var taskCnt = jQuery('<div id="<?php echo $this->_htmlID . '_task'; ?>" class="AjaxTableTaskCnt AjaxTable-loading"></div>').appendTo(taskCont);
|
|
|
+ jQuery('<span class="loading-info"> loading ...</span>').appendTo(taskCnt);
|
|
|
+
|
|
|
+ $.ajax({
|
|
|
+ dataType: 'json',
|
|
|
+ type: "GET",
|
|
|
+ url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=HIST&ID=' + recordID,
|
|
|
+ })
|
|
|
+ .done(function(data, textStatus, jqXHR){
|
|
|
+ taskCnt.removeClass('AjaxTable-loading');
|
|
|
+ <?php if(DBG::isActive() && V::get('DBG', '', $_GET)) : ?>console.log('TODO #L.<?= __LINE__; ?> done loading HIST_AJAX - data:', data);<?php endif; ?>
|
|
|
+
|
|
|
+ histAjaxOut = '<fieldset>' +
|
|
|
+ '<legend>' + data['label'] +
|
|
|
+ '<span class="pull-right valign-btns-bottom">';
|
|
|
+ for (i in data['row_functions']) {
|
|
|
+ histAjaxOut += data['row_functions'][i];
|
|
|
+ // TODO: fetch more row functions
|
|
|
+ }
|
|
|
+ histAjaxOut += '</span>' +
|
|
|
+ '</legend>'
|
|
|
+ '</fieldset>';
|
|
|
+ if (!data['rows']) {
|
|
|
+ histAjaxOut += '<div class="alert alert-info">' +
|
|
|
+ '<h4>Brak danych</h4>' +
|
|
|
+ '</div>';
|
|
|
+ } else {
|
|
|
+ histAjaxOut += '<table class="table table-striped table-hover table-bordered table-condensed AjaxTableHist">' +
|
|
|
+ '<thead>' +
|
|
|
+ '<tr>' +
|
|
|
+ '<th>Data</th>' +
|
|
|
+ '<th>User</th>' +
|
|
|
+ '<th>Zmiany</th>' +
|
|
|
+ '</tr>' +
|
|
|
+ '</thead>' +
|
|
|
+ '<tbody>';
|
|
|
+ for (i in data['rows']) {
|
|
|
+ var row = data['rows'][i];
|
|
|
+ histAjaxOut += '<tr data-id_hist="' + row['ID'] + '">' +
|
|
|
+ '<td style="white-space:nowrap">' + row['_created'] + '</td>' +
|
|
|
+ '<td>' + row['_author'] + '</td>' +
|
|
|
+ '<td>';
|
|
|
+ for (j in row['changes']) {
|
|
|
+ var change = row['changes'][j];
|
|
|
+ var fieldName = change['fieldName'];
|
|
|
+ if (['ID', 'A_RECORD_UPDATE_DATE', 'A_RECORD_UPDATE_AUTHOR', 'A_RECORD_CREATE_DATE', 'A_RECORD_CREATE_AUTHOR'].indexOf(fieldName) >= 0) continue;
|
|
|
+ if ('N/S;' == change['value']) continue;
|
|
|
+ histAjaxOut += '<p>' +
|
|
|
+ '<em>' + (data['field_label'][fieldName] || fieldName) + '</em>: ';
|
|
|
+ histAjaxOut += (change['acl_read'])
|
|
|
+ ? change['value']
|
|
|
+ : '<span title="Brak uprawnień do odczytu tego pola">*****</span>'
|
|
|
+ if (change['revert_function_url']) {
|
|
|
+ histAjaxOut += ' <button' +
|
|
|
+ ' class="btn btn-xs btn-default"' +
|
|
|
+ ' onClick="return p5UI__ajaxLinkClick(this, \''+change['revert_function_url']+'\', \''+change['revert_function_data']+'\')"' +
|
|
|
+ ' title="Cofnij dane do tej wartości">' +
|
|
|
+ '<i class="glyphicon glyphicon-floppy-disk"></i> cofnij' +
|
|
|
+ '</button>';
|
|
|
+ }
|
|
|
+ histAjaxOut += '</p>';
|
|
|
+ }
|
|
|
+ histAjaxOut += '</td>' +
|
|
|
+ '</tr>';
|
|
|
+ }
|
|
|
+ histAjaxOut += '</tbody>' +
|
|
|
+ '</table>';
|
|
|
+ }
|
|
|
+
|
|
|
+ {// old view - flat table
|
|
|
+ histAjaxOut += '<div style="overflow-x:scroll; overflow-y:visible; padding-bottom:1px; margin:10px 0;">' +
|
|
|
+ '<table class="table table-striped table-hover table-bordered table-condensed AjaxTableHist">' +
|
|
|
+ '<thead>' +
|
|
|
+ '<tr>';
|
|
|
+ for (j in data['fields']) {
|
|
|
+ var fieldName = data['fields'][j];
|
|
|
+ histAjaxOut += '<th>' + (data['field_label'][fieldName] || fieldName).replace('_', ' ') + '</th>';
|
|
|
+ }
|
|
|
+ histAjaxOut += '</tr>' +
|
|
|
+ '</thead>' +
|
|
|
+ '<tbody>';
|
|
|
+ for (i in data['rows']) {
|
|
|
+ var row = data['rows'][i];
|
|
|
+ histAjaxOut += '<tr>';
|
|
|
+ for (j in data['fields']) {
|
|
|
+ var fieldName = data['fields'][j];
|
|
|
+ histAjaxOut += '<td>';
|
|
|
+ ( (!(fieldName in row['changes']) || row['changes'][fieldName]['value'] == 'N/S;')
|
|
|
+ ? histAjaxOut += '<em>N/S;</em>'
|
|
|
+ : ( (row['changes'][fieldName]['acl_read'])
|
|
|
+ ? histAjaxOut += row['changes'][fieldName]['value']
|
|
|
+ : histAjaxOut += '<span title="Brak uprawnień do odczytu tego pola">*****</span>'
|
|
|
+ )
|
|
|
+ );
|
|
|
+ histAjaxOut += '</td>';
|
|
|
+ }
|
|
|
+ histAjaxOut += '</tr>';
|
|
|
+ }
|
|
|
+ histAjaxOut += '</tbody>' +
|
|
|
+ '</table>' +
|
|
|
+ '</div>';
|
|
|
+ }
|
|
|
+ jQuery(histAjaxOut).appendTo(taskCnt);
|
|
|
+ })
|
|
|
+ .fail(function(jqXHR){// jqXHR.fail(function( jqXHR, textStatus, errorThrown ) {});
|
|
|
+ taskCnt.removeClass('AjaxTable-loading');
|
|
|
+ if (jqXHR.responseJSON) {
|
|
|
+ notifyAjaxCallback(jqXHR.responseJSON);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ var txt = jqXHR.responseText || 'Wystąpiły błędy';
|
|
|
+ if (jqXHR.status == 404) {
|
|
|
+ jQuery.notify(jqXHR.responseText, 'error');
|
|
|
+ } else {
|
|
|
+ jQuery.notify(jqXHR.responseText, 'warn');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ console.log('TODO #L.<?= __LINE__; ?> fail loading HIST_AJAX - jqXHR.responseText:', jqXHR.responseText);
|
|
|
+ });
|
|
|
+
|
|
|
+ function notifyAjaxCallback(data) {
|
|
|
+ var notify = {};
|
|
|
+ notify.type = (data && data.type)? data.type : '';
|
|
|
+ notify.msg = (data && data.msg)? data.msg : '';
|
|
|
+ switch (notify.type) {
|
|
|
+ case 'success':
|
|
|
+ if (!notify.msg) notify.msg = 'OK';
|
|
|
+ break;
|
|
|
+ case 'info':
|
|
|
+ if (!notify.msg) notify.msg = '';
|
|
|
+ break;
|
|
|
+ case 'error':
|
|
|
+ if (!notify.msg) notify.msg = 'Wystąpiły błędy';
|
|
|
+ break;
|
|
|
+ case 'warning':
|
|
|
+ notify.type = 'warn';
|
|
|
+ if (!notify.msg) notify.msg = 'Wystąpiły błędy';
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ notify.msg = 'Nieznany błąd';
|
|
|
+ if (data && data.errorCode) notify.msg += ' ' + data.errorCode;
|
|
|
+ notify.type = '';
|
|
|
+ }
|
|
|
+ jQuery.notify(notify.msg, notify.type);
|
|
|
+ }
|
|
|
+ //return false;
|
|
|
+}
|
|
|
+ </script>
|
|
|
+ <script>
|
|
|
jQuery(document).ready(function(){
|
|
|
jQuery('#<?php echo $this->_htmlID; ?>').TableAjax({
|
|
|
url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>',
|
|
|
@@ -3391,50 +3563,7 @@ jQuery(document).ready(function(){
|
|
|
|
|
|
//return false;
|
|
|
},
|
|
|
- HIST: function(args) {
|
|
|
- var recordID = args;
|
|
|
- if (typeof args == 'object') {
|
|
|
- recordID = args.shift();
|
|
|
- recordID = parseInt(recordID);
|
|
|
- }
|
|
|
- if (typeof recordID !== 'number' || recordID <= 0) {
|
|
|
- // TODO: msg
|
|
|
- return false;
|
|
|
- }
|
|
|
- var cont = jQuery('#<?php echo $this->_htmlID; ?>').parent();
|
|
|
- cont.hide();
|
|
|
-
|
|
|
- // remove previous task content
|
|
|
- var taskCnt = jQuery('#<?php echo $this->_htmlID; ?>_task');
|
|
|
- taskCnt.parent().remove();
|
|
|
- taskCnt.remove();
|
|
|
-
|
|
|
- var taskCont = jQuery('<div class="AjaxTableCont"></div>').insertBefore(cont);
|
|
|
- jQuery('<ul class="breadcrumb">' +
|
|
|
- '<li><a href="#" onclick="return tableAjaxBackToTable();"><?php echo $this->getLabelHtml(); ?></a></li>' +
|
|
|
- '<li class="active">Historia rekordu</li>' +
|
|
|
- '</ul>').appendTo(taskCont);
|
|
|
- var taskCnt = jQuery('<div id="<?php echo $this->_htmlID . '_task'; ?>" class="AjaxTableTaskCnt AjaxTable-loading"></div>').appendTo(taskCont);
|
|
|
- jQuery('<span class="loading-info"> loading ...</span>').appendTo(taskCnt);
|
|
|
-
|
|
|
- jQuery.ajax({
|
|
|
- url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=HIST&ID=' + recordID,
|
|
|
- type: 'GET',
|
|
|
- dataType: 'text',
|
|
|
- data: '',
|
|
|
- async: true,
|
|
|
- success: function(data) {
|
|
|
- taskCnt.removeClass('AjaxTable-loading');
|
|
|
- //console.log('request finished L.<?php echo __LINE__; ?>');
|
|
|
- jQuery(data).appendTo(taskCnt);
|
|
|
- },
|
|
|
- error: function(err) {
|
|
|
- taskCnt.removeClass('AjaxTable-loading');
|
|
|
- //console.log('request error: {0}'.f(err));
|
|
|
- }
|
|
|
- });
|
|
|
- //return false;
|
|
|
- },
|
|
|
+ HIST: TableAjax__HIST_Route,
|
|
|
FILES: function tableAjaxFiles(args) {
|
|
|
var recordID = args;
|
|
|
if (typeof args == 'object') {
|
|
|
@@ -3859,12 +3988,7 @@ function <?php echo $jsToogleFiltrProcesuFunctionName; ?>(n) {
|
|
|
break;
|
|
|
}
|
|
|
case 'HIST': {
|
|
|
- $id = V::get('ID', 0, $_REQUEST, 'int');
|
|
|
- if ($id > 0) {
|
|
|
- $this->sendAjaxHistory($id, $_REQUEST);
|
|
|
- } else {
|
|
|
- echo '404';
|
|
|
- }
|
|
|
+ $this->sendAjaxResponseJson('ajaxHist', $_REQUEST);
|
|
|
break;
|
|
|
}
|
|
|
case 'FILES': {
|
|
|
@@ -4685,108 +4809,65 @@ jQuery(document).ready(function(){
|
|
|
return $response;
|
|
|
}
|
|
|
|
|
|
- private function sendAjaxHistory($id, $args) {
|
|
|
- header("Content-type: text/plain");
|
|
|
-
|
|
|
- $record = $this->_acl->getItem($id);
|
|
|
- if (!$record) {
|
|
|
- header('HTTP/1.0 404 Not Found');
|
|
|
- echo "404: No item ID({$rowID})";
|
|
|
- exit;
|
|
|
- }
|
|
|
+ private function ajaxHist($args) {
|
|
|
+ $jsonResponse = array();
|
|
|
+ $id = V::get('ID', 0, $args, 'int');
|
|
|
+ $acl = $this->_acl;
|
|
|
+ $record = $acl->getItem($id);
|
|
|
+ if (!$record) throw new HttpException("404: No item ID({$id})", 404);
|
|
|
|
|
|
- $visibleCols = $this->_acl->getRealFieldList();
|
|
|
- $rowsHist = $this->_acl->getHistItems($id);
|
|
|
+ $visibleCols = $acl->getRealFieldList();
|
|
|
+ $rowsHist = $acl->getHistItems($id);
|
|
|
|
|
|
- $rowFunctionsOut = $this->_showRowFunctions($record->ID, array('hist', 'cp'), true);
|
|
|
+ $jsonResponse['row_functions'] = $this->_parseRowFunctions($record->ID, array('hist', 'cp'), $showLabel = true);
|
|
|
|
|
|
$visibleColsWithIds = array();
|
|
|
$visibleColsLabels = array();
|
|
|
foreach ($visibleCols as $vColName) {
|
|
|
- $fldId = $this->_acl->getFieldIdByName($vColName);
|
|
|
+ $fldId = $acl->getFieldIdByName($vColName);
|
|
|
if ($fldId) {
|
|
|
$visibleColsWithIds[$fldId] = $vColName;
|
|
|
- $label = $this->_acl->getFieldLabel($fldId);
|
|
|
+ $label = $acl->getFieldLabel($fldId);
|
|
|
$label = (!$label)? $vColName : '<span title="' . "[{$fldId}] {$vColName}" . '">' . $label . '</span>';
|
|
|
$visibleColsLabels[$fldId] = $label;
|
|
|
}
|
|
|
}
|
|
|
+ $jsonResponse['label'] = "Historia rekordu Nr {$id}";
|
|
|
+ $jsonResponse['fields'] = array_values($visibleColsWithIds);
|
|
|
+ $jsonResponse['field_label'] = $visibleColsLabels;
|
|
|
+
|
|
|
+ if (empty($rowsHist)) return $jsonResponse;
|
|
|
+
|
|
|
+ $jsonResponse['rows'] = array();
|
|
|
+ foreach ($rowsHist as $row) {
|
|
|
+ $histItem = array();
|
|
|
+ $histItem['ID'] = $row->ID;
|
|
|
+ $histItem['_created'] = $row->_created;
|
|
|
+ $histItem['_author'] = $row->_author;
|
|
|
+ $histItem['changes'] = array();
|
|
|
+ foreach ($visibleColsWithIds as $fldId => $fieldName) {
|
|
|
+ // if (in_array($fieldName, array('ID', 'A_RECORD_UPDATE_DATE', 'A_RECORD_UPDATE_AUTHOR', 'A_RECORD_CREATE_DATE', 'A_RECORD_CREATE_AUTHOR'))) continue;
|
|
|
+ // if ($row->{$fieldName} == 'N/S;') continue;
|
|
|
+ $changeItem = array();
|
|
|
+ $changeItem['fieldName'] = $fieldName;
|
|
|
+ $changeItem['acl_read'] = $acl->isAllowed($fldId, 'R', $record);
|
|
|
+ if ($changeItem['acl_read']) {
|
|
|
+ $changeItem['value'] = $row->{$fieldName};
|
|
|
+ }
|
|
|
+ if ('the_geom' == $fieldName && $acl->isAllowed($fldId, 'W', $record)) {
|
|
|
+ $sourceName = $acl->getSourceName();
|
|
|
+ if ('default_db' == $sourceName) {
|
|
|
+ $typeName = $acl->getName();
|
|
|
+ $changeItem['revert_function_url'] = Request::getPathUri() . "index.php?_route=ViewTableAjax&typeName=p5_{$sourceName}:{$typeName}&_task=revertFromHistAjax&ID={$id}&idHist={$row->ID}&fieldName={$fieldName}";
|
|
|
+ $changeItem['revert_function_data'] = "ID={$id}&idHist={$row->ID}&fieldName={$fieldName}";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $histItem['changes'][$fieldName] = $changeItem;
|
|
|
+ }
|
|
|
+ $jsonResponse['rows'][] = $histItem;
|
|
|
+ }
|
|
|
|
|
|
- ?>
|
|
|
- <fieldset>
|
|
|
- <legend>Historia rekordu Nr <?php echo $id; ?>
|
|
|
- <span class="pull-right valign-btns-bottom"><?php echo $rowFunctionsOut; ?></span>
|
|
|
- </legend>
|
|
|
- </fieldset>
|
|
|
-
|
|
|
- <?php if (empty($rowsHist)) : ?>
|
|
|
- <div class="alert alert-info">
|
|
|
- <h4>Brak danych</h4>
|
|
|
- </div>
|
|
|
- <?php else: ?>
|
|
|
- <table class="table table-striped table-hover table-bordered table-condensed AjaxTableHist">
|
|
|
- <thead>
|
|
|
- <tr>
|
|
|
- <th>Data</th>
|
|
|
- <th>User</th>
|
|
|
- <th>Zmiany</th>
|
|
|
- </tr>
|
|
|
- </thead>
|
|
|
- <tbody>
|
|
|
- <?php foreach ($rowsHist as $row) : ?>
|
|
|
- <tr>
|
|
|
- <td style="white-space:nowrap"><?php echo $row->_created; ?></td>
|
|
|
- <td><?php echo $row->_author; ?></td>
|
|
|
- <td>
|
|
|
- <?php foreach ($visibleColsWithIds as $fldId => $colName) : ?>
|
|
|
- <?php if (in_array($colName, array('ID', 'A_RECORD_UPDATE_DATE', 'A_RECORD_UPDATE_AUTHOR', 'A_RECORD_CREATE_DATE', 'A_RECORD_CREATE_AUTHOR'))) continue; ?>
|
|
|
- <?php if ($row->$colName == 'N/S;') continue; ?>
|
|
|
- <p><em><?php echo $visibleColsLabels[$fldId]; ?></em>:
|
|
|
- <?php if ($this->_acl->isAllowed($fldId, 'R', $record)) : ?>
|
|
|
- <?php echo $row->$colName; ?>
|
|
|
- <?php else : ?>
|
|
|
- <span title="Brak uprawnień do odczytu tego pola">*****</span>
|
|
|
- <?php endif; ?>
|
|
|
- </p>
|
|
|
- <?php endforeach; ?>
|
|
|
- </td>
|
|
|
- </tr>
|
|
|
- <?php endforeach; ?>
|
|
|
- </tbody>
|
|
|
- </table>
|
|
|
-
|
|
|
- <div style="overflow-x:scroll; overflow-y:visible; padding-bottom:1px; margin:10px 0;">
|
|
|
- <table class="table table-striped table-hover table-bordered table-condensed AjaxTableHist">
|
|
|
- <thead>
|
|
|
- <tr>
|
|
|
- <?php foreach ($visibleColsWithIds as $fldId => $colName) : ?>
|
|
|
- <th><?php echo str_replace('_', ' ', $visibleColsLabels[$fldId]); ?></th>
|
|
|
- <?php endforeach; ?>
|
|
|
- </tr>
|
|
|
- </thead>
|
|
|
- <tbody>
|
|
|
- <?php foreach ($rowsHist as $row) : ?>
|
|
|
- <tr>
|
|
|
- <?php foreach ($visibleColsWithIds as $fldId => $colName) : ?>
|
|
|
- <td>
|
|
|
- <?php if ($row->$colName == 'N/S;') : ?>
|
|
|
- <em>N/S;</em>
|
|
|
- <?php elseif ($this->_acl->isAllowed($fldId, 'R', $record)) : ?>
|
|
|
- <?php echo $row->$colName; ?>
|
|
|
- <?php else : ?>
|
|
|
- <span title="Brak uprawnień do odczytu tego pola">*****</span>
|
|
|
- <?php endif; ?>
|
|
|
- </td>
|
|
|
- <?php endforeach; ?>
|
|
|
- </tr>
|
|
|
- <?php endforeach; ?>
|
|
|
- </tbody>
|
|
|
- </table>
|
|
|
- </div>
|
|
|
- <?php endif; ?>
|
|
|
-
|
|
|
- <?php
|
|
|
- exit;
|
|
|
+ return $jsonResponse;
|
|
|
}
|
|
|
|
|
|
public function ajaxFileUpload($args) {
|