|
|
@@ -2368,6 +2368,10 @@ class TableAjax extends ViewAjax {
|
|
|
return publ;
|
|
|
};
|
|
|
|
|
|
+ publ.refresh = function () {
|
|
|
+ publ.loadPage(_currPage);
|
|
|
+ };
|
|
|
+
|
|
|
publ.loadPage = function(page, pageSize) {
|
|
|
var skipCols = true, // skipCols = true - prevent columns delete
|
|
|
resetChecked = false;
|
|
|
@@ -2455,6 +2459,13 @@ class TableAjax extends ViewAjax {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+ $.fn.TableAjaxRefresh = function (page, pageSize) {
|
|
|
+ return this.each(function () {
|
|
|
+ var tblAjax = jQuery(this).data('TableAjax');
|
|
|
+ if (tblAjax) tblAjax.refresh();
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
String.prototype.format = String.prototype.f = function () {
|
|
|
var s = this;
|
|
|
i = arguments.length;
|
|
|
@@ -2785,30 +2796,56 @@ function tableAjaxCopy(args) {
|
|
|
}
|
|
|
|
|
|
var cont = jQuery('#<?php echo $this->_htmlID; ?>').parent();
|
|
|
- //cont.hide();
|
|
|
- //var taskCont = jQuery('#<?php echo $this->_htmlID . '_task'; ?>').parent();
|
|
|
- //taskCont.remove();
|
|
|
|
|
|
- cont.children('.alert').fadeOut('slow');
|
|
|
- var alert = jQuery('<div class="alert fade in"><strong>Kopiuj rekord</strong> ... </div>').prependTo(cont);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
|
|
|
+ var reqData = {};
|
|
|
jQuery.ajax({
|
|
|
+ data: reqData,
|
|
|
+ dataType: 'json',
|
|
|
+ type: "GET",
|
|
|
url: 'index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_hash=<?php echo $this->_htmlID; ?>&_task=COPY&ID=' + recordID,
|
|
|
- type: 'GET',
|
|
|
- dataType: 'text',
|
|
|
- data: '',
|
|
|
- async: true,
|
|
|
- success: function (data) {
|
|
|
- //console.log('data: ', data);
|
|
|
- alert.remove();
|
|
|
- alert = jQuery(data).prependTo(cont);
|
|
|
- alert.alert();
|
|
|
- var con = jQuery('#<?php echo $this->_htmlID; ?>');
|
|
|
- con.TableAjaxLoadPage(0);
|
|
|
- },
|
|
|
- error: function (err) {
|
|
|
- alert.remove();
|
|
|
- if (priv.options.debug) console.log(err);
|
|
|
+ })
|
|
|
+ .done(function(data, textStatus, jqXHR){
|
|
|
+ var con = jQuery('#<?php echo $this->_htmlID; ?>');
|
|
|
+ con.TableAjaxRefresh();
|
|
|
+ notifyAjaxCallback(data);
|
|
|
+ })
|
|
|
+ .fail(function(jqXHR){// jqXHR.fail(function( jqXHR, textStatus, errorThrown ) {});
|
|
|
+ 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');
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
|
|
|
@@ -2873,12 +2910,7 @@ function hidePopover() {
|
|
|
break;
|
|
|
}
|
|
|
case 'COPY': {
|
|
|
- $id = V::get('ID', 0, $_REQUEST, 'int');
|
|
|
- if ($id > 0) {
|
|
|
- $this->sendAjaxCopy($id, $_REQUEST);
|
|
|
- } else {
|
|
|
- echo '404';
|
|
|
- }
|
|
|
+ $this->sendAjaxResponseJson('ajaxCopy', $_REQUEST);
|
|
|
break;
|
|
|
}
|
|
|
case 'CREATE': {
|
|
|
@@ -3664,25 +3696,17 @@ jQuery(document).ready(function(){
|
|
|
return $response;
|
|
|
}
|
|
|
|
|
|
- private function sendAjaxCopy($id, $args) {
|
|
|
- header("Content-type: text/plain");
|
|
|
- sleep(1);// TODO: RMME DBG loading
|
|
|
-
|
|
|
- $dbID = $this->_acl->getDB();
|
|
|
- $db = DB::getDB($dbID);
|
|
|
- if (!$db) {
|
|
|
- header('HTTP/1.0 406 Not Acceptable');
|
|
|
- exit;
|
|
|
+ private function ajaxCopy($args) {
|
|
|
+ $id = V::get('ID', 0, $_REQUEST, 'int');
|
|
|
+ if ($id <= 0) {
|
|
|
+ throw new HttpException("Wrong param ID!", 404);
|
|
|
}
|
|
|
|
|
|
$row = $this->_dataSource->getItem($id);
|
|
|
if (!$row) {
|
|
|
- header('HTTP/1.0 404 Not Found');
|
|
|
- echo "404: No item ID({$rowID})";
|
|
|
- exit;
|
|
|
+ throw new HttpException("Item '{$id}' not exists!", 404);
|
|
|
}
|
|
|
|
|
|
- $tblName = $this->_acl->getName();
|
|
|
$types = $this->_acl->getTypes();
|
|
|
$uniqKeys = $this->_acl->getUniqueKeys();
|
|
|
|
|
|
@@ -3693,35 +3717,32 @@ jQuery(document).ready(function(){
|
|
|
} else if (in_array($kName, array('A_RECORD_UPDATE_AUTHOR','A_RECORD_UPDATE_DATE'))) {
|
|
|
continue;
|
|
|
}
|
|
|
- $sqlObj->{$kName} = V::get($kName, '', $row);
|
|
|
+ $value = V::get($kName, '', $row);
|
|
|
if (in_array($kName, $uniqKeys)) {
|
|
|
- $sqlObj->{$kName} .= '?';
|
|
|
+ $value .= '?';
|
|
|
+ }
|
|
|
+ if ($this->_dataSource->isGeomField($kName)) {
|
|
|
+ $value = "GeomFromText('{$value}')";
|
|
|
}
|
|
|
+ $sqlObj->{$kName} = $value;
|
|
|
}
|
|
|
|
|
|
- $ret = $db->ADD_NEW_OBJ($tblName, $sqlObj);
|
|
|
+ $retID = $this->_dataSource->addItem($sqlObj);
|
|
|
|
|
|
- if ($ret > 0) {
|
|
|
- echo '<div class="alert alert-success">';
|
|
|
- echo '<button type="button" class="close" data-dismiss="alert"><i class="icon-remove"></i></button>';
|
|
|
- echo "Rekord skopiowany pomyślnie - utworzono rekord nr {$ret}";//"Record saved successfully";
|
|
|
- echo '</div>';
|
|
|
- } else if ($ret == 0) {
|
|
|
- echo '<div class="alert alert-error">';
|
|
|
- echo '<button type="button" class="close" data-dismiss="alert"><i class="icon-remove"></i></button>';
|
|
|
- echo "Nie udało się skopiować rekordu";
|
|
|
- if ($db->has_errors()) {
|
|
|
- echo '<br>' . implode("<br>", $db->get_errors());
|
|
|
- }
|
|
|
- echo '</div>';
|
|
|
+ $response = new stdClass();
|
|
|
+ $response->type = '';
|
|
|
+ $response->msg = '';
|
|
|
+ if ($retID > 0) {
|
|
|
+ $response->type = 'success';
|
|
|
+ $response->msg = "Rekord skopiowany pomyślnie - utworzono rekord nr {$retID}";
|
|
|
+ $response->id = $retID;
|
|
|
+ $response->record = $this->_dataSource->getItem($retID);
|
|
|
} else {
|
|
|
- echo '<div class="alert alert-error">';
|
|
|
- echo '<button type="button" class="close" data-dismiss="alert"><i class="icon-remove"></i></button>';
|
|
|
- echo "Błąd bazy danych";
|
|
|
- echo '</div>';
|
|
|
+ $response->type = 'error';
|
|
|
+ $response->msg = "Wystąpiły błędy!";
|
|
|
+ $response->errors = $this->_dataSource->getDbErrors();
|
|
|
}
|
|
|
-
|
|
|
- exit;
|
|
|
+ return $response;
|
|
|
}
|
|
|
|
|
|
private function sendAjaxHistory($id, $args) {
|