| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- // @require variables:
- if ('undefined' === typeof TABLE_AJAX_NODE_ID) throw "Missing TABLE_AJAX_NODE_ID"; // $this->_htmlID,
- if ('undefined' === typeof TABLE_AJAX_LABEL) throw "Missing TABLE_AJAX_LABEL"; // this->getLabelHtml()
- if ('undefined' === typeof URL_HIST_BASE) throw "Missing URL_HIST_BASE"; // 'index-ajax.php?_zasobID={$this->_zasobID}&_cls={__CLASS__}&_hash={$this->_htmlID}&_task=HIST'; // &ID=...
- if ('undefined' === typeof FUNCTION_HIST_ROUTE) throw "Missing FUNCTION_HIST_ROUTE"; // ''
- 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('#' + TABLE_AJAX_NODE_ID).parent();
- cont.hide();
- // remove previous task content
- var taskCnt = jQuery('#' + TABLE_AJAX_NODE_ID + '_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();">' + TABLE_AJAX_LABEL + '</a></li>' +
- '<li class="active">Historia rekordu</li>' +
- '</ul>').appendTo(taskCont);
- var taskCnt = jQuery('<div id="' + TABLE_AJAX_NODE_ID + '_task" class="AjaxTableTaskCnt AjaxTable-loading"></div>').appendTo(taskCont);
- jQuery('<span class="loading-info"> loading ...</span>').appendTo(taskCnt);
- window.fetch(URL_HIST_BASE + '&ID=' + recordID, {
- method: 'GET',
- credentials: 'same-origin',
- }).then(function(response) {
- return response.json()
- }).then(function __route_hist_payload(payload) {
- taskCnt.removeClass('AjaxTable-loading');
- var data = payload;
- 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>Autor</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>' + "\n";
- histAjaxOut += '<th>Data</th>';
- histAjaxOut += '<th>Autor</th>';
- for (j in data['fields']) {
- var fieldName = data['fields'][j];
- histAjaxOut += '<th>' + (data['field_label'][fieldName] || fieldName).replace(/_/g, ' ') + '</th>';
- }
- histAjaxOut += '</tr>' +
- '</thead>' +
- '<tbody>';
- for (i in data['rows']) {
- var row = data['rows'][i];
- histAjaxOut += '<tr>';
- histAjaxOut += '<td><nobr>' + row['_created'] + '</nobr></td>';
- histAjaxOut += '<td>' + row['_author'] + '</td>';
- 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);
- }).catch(function __route_hist_catch(e) {
- taskCnt.removeClass('AjaxTable-loading');
- p5UI__notifyAjaxCallback({
- type: 'error',
- msg: 'Request error ' + e
- });
- })
- }
- global[FUNCTION_HIST_ROUTE] = TableAjax__HIST_Route
|